EntityLifecycleNotification.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.jmx;
022 
023 import javax.management.Notification;
024 import javax.management.ObjectName;
025 
026 import org.apache.qpid.management.Names;
027 import org.apache.qpid.management.domain.services.SequenceNumberGenerator;
028 
029 /**
030  * Q-Man JMX entity lifecycle notification.
031  * A notification is sent to interested listener by Q-Man on the following scenarios :
032  
033  <br> - A schema (class / event) has been requested (Schema request); 
034  <br> - A schema (class / event) has been injected (Schema response); 
035  <br> - A schema cannot be parsed (probably it is malformed);
036  <br> - An object instance has been created (Instrumentation / Configuration response); 
037  <br> - An event instance has been created (Instrumentation / Configuration response); 
038  <br> - An object instance has been removed (Instrumentation / Configuration response); 
039  
040  @author Andrea Gazzarini
041  */
042 public class EntityLifecycleNotification extends Notification
043 {
044   private static final long serialVersionUID = -7755773156742412161L;
045   
046   public static final String SCHEMA_INJECTED_NOTIFICATION_TYPE = "org.apache.qpid.management.lifecycle.entity.schema.injected";
047   public static final String SCHEMA_REQUESTED_NOTIFICATION_TYPE = "org.apache.qpid.management.lifecycle.entity.schema.requested";
048   public static final String MALFORMED_SCHEMA_NOTIFICATION_TYPE = "org.apache.qpid.management.lifecycle.error.schema";
049   
050   public static final String INSTANCE_ADDED_NOTIFICATION_TYPE = "qman.lifecycle.entity.instance.created";
051   public static final String INSTANCE_REMOVED_NOTIFICATION_TYPE = "qman.lifecycle.entity.instance.removed";
052   
053   private String _packageName = Names.NOT_AVAILABLE;
054   private String _className = Names.NOT_AVAILABLE;
055   private String _classKind = Names.NOT_AVAILABLE;
056   
057   private ObjectName _objectName;
058   
059   /**
060    * Builds a new notification with the given parameters.
061    
062    @param type the notification type.
063    @param sequenceNumber the sequence number.
064    @param packageName the package name.
065    @param className the class name.
066    @param classKind the class kind (i.e. class or event)
067    @param objectName the object name of the affected mbean.
068    */
069   public EntityLifecycleNotification(
070       String type,
071       String packageName, 
072       String className, 
073       String classKind, 
074       ObjectName objectName
075   {
076     super(
077         type,
078         Names.APPLICATION_NAME,
079         SequenceNumberGenerator.getNextSequenceNumber());
080     
081     this._className = className;
082     this._packageName = packageName;
083     this._classKind = classKind;
084     this._objectName = objectName;
085   }
086   
087   /**
088    * Returns the package name of object contained in this notification.
089    
090    @return the package name of object contained in this notification.
091    */
092   public String getPackageName()
093   {
094     return _packageName;
095   }
096   
097   /**
098    * Returns the class name of object contained in this notification.
099    
100    @return the class name of object contained in this notification.
101    */
102   public String getClassName()
103   {
104     return _className;
105   }
106   
107   /**
108    * Returns the class kind of object contained in this notification.
109    
110    @return the class kind of object contained in this notification.
111    @see Names#CLASS
112    @see Names#EVENT
113    */
114   public String getClassKind()
115   {
116     return _classKind;
117   }
118   
119   /**
120    * Returns the object name of object contained in this notification.
121    
122    @return the object name of object contained in this notification.
123    */
124   public ObjectName getObjectName()
125   {
126     return _objectName;
127   }
128   
129   /**
130    * Returns a string representation of this notification.
131    
132    @return a string representation of this notification.
133    */
134   @Override
135   public String toString()
136   {
137     return new StringBuilder()
138       .append(getType())
139       .append(':')
140       .append(_packageName)
141       .append('.')
142       .append(_className)
143       .append('@')
144       .append(_objectName)
145       .toString();
146   }
147 }