NotificationListener

View: New views
2 Messages — Rating Filter:   Alert me  

NotificationListener

by DARVEAU Manuel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Bonjour,

 

I have a question about NotificationListeners and network failure.

 

If I bind a NotificationListener on an MBean and the connection between the listener and the MBean drop, will the NotificationListener still be called when the connection return?

 

When I create the JMXConnector, I add a ConnectionNotificationListener:

JMXConnector jmxc;

private void createConnection(JMXServiceURL url){

   jmxc = JMXConnectorFactory.connect(url, null);

   jmxc.addConnectionNotificationListener(this, null, this);

}

 

 

When I get a notification that the connection dropped, I reset the old connection and create a new one:

public void handleNotification(Notification notification, Object handback) {

   String notificationType = notification.getType();

   if (notificationType.equals(JMXConnectionNotification.CLOSED) || notificationType.equals(JMXConnectionNotification.FAILED)) {       

      // Remove the listener to avoid infinite recursion

jmxc.removeConnectionNotificationListener(JmxContext.this);

      try {

         jmxc.close();

      } catch (IOException e) {

         // Don’t care

}

 

if(the connection should really be closed){

   return;

}

 

// Create the new connection

createConnection();

   }

}

 

So back to the question, If somebody added a MBean NotificationListener using:

mbsc.addNotificationListener(new ObjectName(name), listener, null, null);

 

and the connection drop. When the connectionNotificationListener recreate the connection, will the NotificationListener on the MBean will still be valid? Will it continue to receive notifications?

If not, will this create a NotificationListener leak on the server side?

 

Thank you very much.

 

Manuel

 

P.S.: Do you have any documentation on how the connection failures are handled by JMX or the rmi connector?

=========================================================================== For information on the Java Management extensions (JMX), please visit our home page at http://java.sun.com/products/JavaManagement/ The JMX-FORUM archives are accessible at http://archives.java.sun.com To unsubscribe, send email to listserv@... and include in the body of the message "signoff JMX-FORUM". For general help, send email to listserv@... and include in the body of the message "help".

Parent Message unknown Re: NotificationListener

by eamonn.mcmanus :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Bonjour Manuel,

First of all, you shouldn't need to call jmxc.close() when you get a CLOSED
or FAILED notification.  The connector is already dead at that point.

If somebody does mbsc.addNotificationListener(name, listener, null, null)
then the connector has a reference to the listener only as long as the
connection is alive.  So unless something else is referencing the listener,
it will be ready for garbage collection as soon as the connector fails or is
closed.

Regards,
Éamonn McManus  --  JMX Spec Lead  --  http://weblogs.java.net/blog/emcmanus

On Thu, 31 May 2007 11:15:25 -0400, DARVEAU Manuel <mdarveau@...> wrote:

>Bonjour,
>
>
>
>I have a question about NotificationListeners and network failure.
>
>
>
>If I bind a NotificationListener on an MBean and the connection between
>the listener and the MBean drop, will the NotificationListener still be
>called when the connection return?
>
>
>
>When I create the JMXConnector, I add a ConnectionNotificationListener:
>
>JMXConnector jmxc;
>
>private void createConnection(JMXServiceURL url){
>
>   jmxc = JMXConnectorFactory.connect(url, null);
>
>   jmxc.addConnectionNotificationListener(this, null, this);
>
>}
>
>
>
>
>
>When I get a notification that the connection dropped, I reset the old
>connection and create a new one:
>
>public void handleNotification(Notification notification, Object
>handback) {
>
>   String notificationType = notification.getType();
>
>   if (notificationType.equals(JMXConnectionNotification.CLOSED) ||
>notificationType.equals(JMXConnectionNotification.FAILED)) {
>
>      // Remove the listener to avoid infinite recursion
>
>jmxc.removeConnectionNotificationListener(JmxContext.this);
>
>      try {
>
>         jmxc.close();
>
>      } catch (IOException e) {
>
>         // Don't care
>
>}
>
>
>
>if(the connection should really be closed){
>
>   return;
>
>}
>
>
>
>// Create the new connection
>
>createConnection();
>
>   }
>
>}
>
>
>
>So back to the question, If somebody added a MBean NotificationListener
>using:
>
>mbsc.addNotificationListener(new ObjectName(name), listener, null,
>null);
>
>
>
>and the connection drop. When the connectionNotificationListener
>recreate the connection, will the NotificationListener on the MBean will
>still be valid? Will it continue to receive notifications?
>
>If not, will this create a NotificationListener leak on the server side?
>
>
>
>Thank you very much.
>
>
>
>Manuel
>
>
>
>P.S.: Do you have any documentation on how the connection failures are
>handled by JMX or the rmi connector?

===========================================================================
For information on the Java Management extensions (JMX), please visit
our home page at http://java.sun.com/products/JavaManagement/
The JMX-FORUM archives are accessible at http://archives.java.sun.com
To unsubscribe, send email to listserv@... and include in the body
of the message "signoff JMX-FORUM".  For general help, send email to
listserv@... and include in the body of the message "help".