You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by da...@apache.org on 2003/09/05 04:40:08 UTC
cvs commit: incubator-geronimo/modules/core/src/java/org/apache/geronimo/management AbstractManagedObject.java
dain 2003/09/04 19:40:08
Modified: modules/core/src/java/org/apache/geronimo/management
AbstractManagedObject.java
Log:
Cleaned up notification code.
Revision Changes Path
1.4 +45 -11 incubator-geronimo/modules/core/src/java/org/apache/geronimo/management/AbstractManagedObject.java
Index: AbstractManagedObject.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/management/AbstractManagedObject.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AbstractManagedObject.java 21 Aug 2003 14:44:25 -0000 1.3
+++ AbstractManagedObject.java 5 Sep 2003 02:40:08 -0000 1.4
@@ -61,12 +61,15 @@
import java.util.List;
import java.util.Set;
import javax.management.InstanceNotFoundException;
+import javax.management.ListenerNotFoundException;
import javax.management.MBeanNotificationInfo;
import javax.management.MBeanRegistration;
import javax.management.MBeanServer;
import javax.management.MBeanServerNotification;
import javax.management.Notification;
import javax.management.NotificationBroadcasterSupport;
+import javax.management.NotificationEmitter;
+import javax.management.NotificationFilter;
import javax.management.NotificationFilterSupport;
import javax.management.NotificationListener;
import javax.management.ObjectName;
@@ -94,11 +97,11 @@
/**
* Abstract implementation of JSR77 StateManageable.
* Implementors of StateManageable may use this class and simply provide
- * doStart, doStop and doNotification methods.
+ * doStart, doStop and sendNotification methods.
*
* @version $Revision$ $Date$
*/
-public abstract class AbstractManagedObject extends NotificationBroadcasterSupport implements ManagedObject, StateManageable, EventProvider, NotificationListener, MBeanRegistration {
+public abstract class AbstractManagedObject implements ManagedObject, StateManageable, EventProvider, NotificationListener, MBeanRegistration, NotificationEmitter {
protected final Log log = LogFactory.getLog(getClass());
/**
@@ -140,6 +143,17 @@
// objects check if each other are in one state or another (i.e., classic A calls B while B calls A)
private volatile State state = State.STOPPED;
+ public AbstractManagedObject() {
+ for (int i = 0; i < NotificationType.TYPES.length; i++) {
+ notificationTypes.add(NotificationType.TYPES[i]);
+ }
+ }
+
+ /**
+ * The broadcaster for notifications
+ */
+ protected final NotificationBroadcasterSupport notificationBroadcaster = new NotificationBroadcasterSupport();
+
/**
* Check if component can start. Dependencies in the dependency service have already been
* checked at this point.
@@ -252,6 +266,18 @@
notificationTypes.add(eventType);
}
+ public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) {
+ notificationBroadcaster.addNotificationListener(listener, filter, handback);
+ }
+
+ public void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException {
+ notificationBroadcaster.removeNotificationListener(listener);
+ }
+
+ public void removeNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) throws ListenerNotFoundException {
+ notificationBroadcaster.removeNotificationListener(listener, filter, handback);
+ }
+
/**
* Sends the specified MBean notification.
*
@@ -261,9 +287,14 @@
*
* @param type the notification type to send
*/
- private final void doNotification(String type) {
+ public final void sendNotification(String type) {
assert !Thread.holdsLock(this): "This method cannot be called while holding a syncrhonized lock on this";
- sendNotification(new Notification(type, objectName, sequenceNumber++));
+ notificationBroadcaster.sendNotification(new Notification(type, objectName, sequenceNumber++));
+ }
+
+ public void sendNotification(Notification notification) {
+ assert !Thread.holdsLock(this): "This method cannot be called while holding a syncrhonized lock on this";
+ notificationBroadcaster.sendNotification(notification);
}
public synchronized final long getStartTime() {
@@ -291,7 +322,7 @@
}
setStateInstance(State.STARTING);
}
- doNotification(State.STARTING.getEventTypeValue());
+ sendNotification(State.STARTING.getEventTypeValue());
State newState = null;
try {
@@ -317,7 +348,7 @@
}
} finally {
if (newState != null) {
- doNotification(newState.getEventTypeValue());
+ sendNotification(newState.getEventTypeValue());
}
}
}
@@ -343,7 +374,7 @@
}
setStateInstance(State.STOPPING);
}
- doNotification(State.STOPPING.getEventTypeValue());
+ sendNotification(State.STOPPING.getEventTypeValue());
// Don't try to stop dependents from within a synchronized block... this should reduce deadlocks
@@ -389,7 +420,7 @@
}
} finally {
if (newState != null) {
- doNotification(newState.getEventTypeValue());
+ sendNotification(newState.getEventTypeValue());
}
}
}
@@ -475,7 +506,7 @@
}
}
- public final int getState() {
+ public int getState() {
return state.toInt();
}
@@ -615,7 +646,7 @@
}
} finally {
if (newState != null) {
- doNotification(newState.getEventTypeValue());
+ sendNotification(newState.getEventTypeValue());
}
}
}
@@ -734,6 +765,9 @@
}
public String toString() {
+ if (objectName == null) {
+ return super.toString();
+ }
return objectName.toString();
}
}