Hi,
I think there is a bug in the RMIConnectorImpl class
related to the management of the Client Notification
Listener list.
When a RMI notification listener is registered, a new
MBean is created (i.e. JMX:id=xxxxxxxx,type=listener).
When the listener is unregistered, the MBean is
destroyed.
If you repeat the operation a second time with the same
parameter (same target MBean and same Notification
Listener), the MBean is created but not destroyed after
the unregistration of the listener.
In org.jboss.jmx.connector.rmi.RMIConnectorImpl, the
listeners list is correctly managed when an add occured,
but there is no removal when a remove occured.
I can't provide a diff, so here is the method to change.
I have also provide a test to reproduce the bug.
Regards
public void removeNotificationListener(
ObjectName pName,
NotificationListener pListener
) throws
InstanceNotFoundException,
ListenerNotFoundException
{
ClientNotificationListener lCheck = new
SearchClientNotificationListener( pName, pListener );
int i = mListeners.indexOf( lCheck );
if( i >= 0 ) {
ClientNotificationListener lListener =
(ClientNotificationListener) mListeners.get( i );
lListener.removeNotificationListener( this );
### Line to add ###
mListeners.remove(i);
###
}
}
import java.util.Vector;
import javax.management.Notification;
import javax.management.NotificationListener;
import javax.management.ObjectName;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
import org.jboss.jmx.connector.rmi.RMIConnectorImpl;
public class Test
{
public static void main(String[] args)
throws Exception
{
InitialContext context = new InitialContext();
Object ref = context.lookup("jmx:<yourhost>:rmi");
RMIAdaptor adaptor = (RMIAdaptor)
PortableRemoteObject.narrow(ref,
RMIAdaptor.class);
RMIConnectorImpl connector = new
RMIConnectorImpl(adaptor);
System.out.println("Got a connector " + connector);
NotificationListener listener =
new NotificationListener()
{
public void handleNotification(Notification
notification, Object
object)
{
System.out.println("Got a notification " +
notification + "
from " + object);
}
};
ObjectName on = new
ObjectName
("JMImplementation:type=MBeanServerDelegate");
connector.addNotificationListener(on, listener,
null, "DUMMY");
System.out.println("Listener registered");
connector.removeNotificationListener(on, listener);
System.out.println("Listener unregistered");
connector.addNotificationListener(on, listener,
null, "DUMMY");
System.out.println("Listener registered");
connector.removeNotificationListener(on, listener);
System.out.println("Listener unregistered");
}
}