DomainModel.java
001 /*
002  *
003  * Licensed to the Apache Software Foundation (ASF) under one
004  * or more contributor license agreements.  See the NOTICE file
005  * distributed with this work for additional information
006  * regarding copyright ownership.  The ASF licenses this file
007  * to you under the Apache License, Version 2.0 (the
008  * "License"); you may not use this file except in compliance
009  * with the License.  You may obtain a copy of the License at
010  *
011  *   http://www.apache.org/licenses/LICENSE-2.0
012  *
013  * Unless required by applicable law or agreed to in writing,
014  * software distributed under the License is distributed on an
015  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016  * KIND, either express or implied.  See the License for the
017  * specific language governing permissions and limitations
018  * under the License.
019  *
020  */
021 package org.apache.qpid.management.domain.model;
022 
023 import java.util.Date;
024 import java.util.HashMap;
025 import java.util.List;
026 import java.util.Map;
027 import java.util.UUID;
028 
029 import org.apache.qpid.management.domain.handler.impl.IMethodInvocationListener;
030 import org.apache.qpid.management.domain.handler.impl.MethodOrEventDataTransferObject;
031 import org.apache.qpid.management.domain.model.type.Binary;
032 
033 /**
034  * Broker domain model.
035  * This is the local representation of a remote broker domain model.
036  
037  @author Andrea Gazzarini
038  */
039 public class DomainModel
040 {
041     private final UUID _id;
042     
043     /** Here the known packages of the remote broker are stored. */
044     Map<String,QpidPackage> _packages = new HashMap<String, QpidPackage>();
045 
046     private Date _lastRefreshDate = new Date();
047     
048     private IMethodInvocationListener _methodInvocationListener;
049     
050     /**
051      * Builds a new domain model with the given broker identifier.
052      
053      @param brokerId the broker identifier.
054      */
055     public DomainModel(UUID brokerId)
056     {
057         this._id = brokerId;
058     }
059 
060     /**
061      * Returns the identifier of the broker associated with this domain model.
062      
063      @return the identifier of the broker associated with this domain model.
064      */
065     public UUID getBrokerId()
066     {
067         return _id;
068     }
069     
070     /**
071      * Adds the specified schema to this domain model.
072      
073      @param packageName the package name.
074      @param className the class name.
075      @param classHash the class schema hash.
076      @param properties the class properties.
077      @param statistics the class statistics.
078      @param methods the class methods.
079      @throws UnableToBuildFeatureException 
080      */
081     public void addSchema(
082             String packageName, 
083             String className, 
084             Binary classHash,
085             List<Map<String, Object>> properties,
086             List<Map<String, Object>> statistics,
087             List<MethodOrEventDataTransferObject> methodsthrows UnableToBuildFeatureException
088     {
089         QpidPackage qpidPackage = getPackageByName(packageName);
090         qpidPackage.addClassDefinition(className,classHash,properties,statistics,methods);
091     }
092     
093     /**
094      * Updates the last refresh date.
095      */
096     public void updateLastRefreshDate() 
097     {
098       this._lastRefreshDate = new Date();
099     }
100     
101     /**
102      * Returns the last refresh date.
103      
104      @return the last refresh date.
105      */
106     public Date getLastRefreshDate()
107     {
108       return _lastRefreshDate;
109     }
110     
111     /**
112      * Adds the specified schema to this domain model.
113      
114      @param packageName the package name.
115      @param className the class name.
116      @param classHash the class schema hash.
117      @param properties the class properties.
118      @param statistics the class statistics.
119      @param methods the class methods.
120      @throws UnableToBuildFeatureException 
121      */
122     public void addEventSchema(
123             String packageName, 
124             String className, 
125             Binary classHash,
126             List<Map<String, Object>> argumentsthrows UnableToBuildFeatureException
127     {
128         QpidPackage qpidPackage = getPackageByName(packageName);
129         qpidPackage.addEventDefinition(className,classHash,arguments);
130     }
131 
132     /**
133      * Gets the package with the specified name.
134      * Note that if the package doesn't exist a new one will be created and returned.
135      
136      @param packageName the name of the package.
137      @return the package.
138      */
139     QpidPackage getPackageByName (String packageName)
140     {
141         QpidPackage qpidPackage = _packages.get(packageName);
142         if (qpidPackage == null
143         {
144             qpidPackage = new QpidPackage(packageName,this);
145             _packages.put(packageName, qpidPackage);
146         
147         return qpidPackage;
148     }
149 
150     /**
151      * Returns true if a package with the specified name already exists on this domain model.
152      
153      @param packageName the name of the package.
154      @return true if the package exists, false otherwise.
155      */
156     boolean containsPackage (String packageName)
157     {
158         return _packages.containsKey(packageName);
159     }
160 
161     /**
162      * Adds the given instrumentation data (raw format) to this domain model.
163      * Note that this data is belonging to a specific object instance.
164      
165      @param packageName the name of the ower package.
166      @param className the name of the owner class.
167      @param classHash the schema hash for this class.
168      @param objectId the object instance identifier.
169      @param rawData the instrumentation data.
170      */
171     public void addInstrumentationRawData (String packageName, String className,Binary classHash, Binary objectId, byte[] rawData)
172     {
173         QpidPackage qpidPackage = getPackageByName(packageName);
174         qpidPackage.setObjectInstanceInstrumentationRawData(className,classHash,objectId,rawData);
175     }
176     
177     public void addEventRawData (
178         String packageName, 
179         String eventName, 
180         Binary eventHash, 
181         byte[] rawData,
182         long currentTimestamp, 
183         int severity)
184     {
185         QpidPackage qpidPackage = getPackageByName(packageName);
186         qpidPackage.setEventInstanceRawData(eventName,eventHash,rawData,currentTimestamp,severity);
187     }
188     
189     /**
190      * Adds the given configuration data (raw format) to this domain model.
191      * Note that this data is belonging to a specific object instance.
192      
193      @param packageName the name of the ower package.
194      @param className the name of the owner class.
195      @param classHash the schema hash for this class.
196      @param objectId the object instance identifier.
197      @param rawData the configuration data.
198      */
199     public void addConfigurationRawData (String packageName, String className, Binary classHash,Binary objectId, byte[] rawData)
200     {
201         QpidPackage qpidPackage = getPackageByName(packageName);
202         qpidPackage.setObjectInstanceConfigurationRawData(className,classHash,objectId,rawData);
203     }
204 
205     /**
206      * Removes the object instance associated to the given parameters.
207      
208      @param packageName the owner package.
209      @param className the class definition of the object instance.
210      @param classHash the class hash
211      @param objectId the object identifier.
212      */
213     public void removeObjectInstance (String packageName, String className, Binary classHash, Binary objectId)
214     {
215         QpidPackage qpidPackage = getPackageByName(packageName);
216         qpidPackage.removeObjectInstance(className, classHash, objectId);
217     }
218 
219     /**
220      * Releases all the resources kept by domain model entitiies.
221      */
222     public void releaseResources()
223     {
224         for (QpidPackage qpidPackage : _packages.values())
225         {
226             qpidPackage.releaseResources();
227         }
228     }
229 
230     public void setMethodInvocationListener(IMethodInvocationListener listener)
231     {
232         this._methodInvocationListener = listener;
233     }
234     
235     IMethodInvocationListener getMethodInvocationListener ()
236     {
237         return _methodInvocationListener;
238     }
239 }