mx4j/src/tools/mx4j/tools/remote/local ServerSubjectInvoker.java,1.1,1.2 ServerInvoker.java,1.1,1.2 LocalConnectionImpl.java,1.2,1.3 LocalConnection.java,1.2,1.3

[email protected]
Newsgroups gmane.comp.java.mx4j.cvs
Message-ID <[email protected]>
Update of /cvsroot/mx4j/mx4j/src/tools/mx4j/tools/remote/local
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32118/tools/mx4j/tools/remote/local

Modified Files:
	ServerSubjectInvoker.java ServerInvoker.java 
	LocalConnectionImpl.java LocalConnection.java 
Log Message:
Implemented the semantic of cancellation of listeners in case of JMXConnector.close()

Index: ServerSubjectInvoker.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/tools/mx4j/tools/remote/local/ServerSubjectInvoker.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ServerSubjectInvoker.java	7 Sep 2003 18:18:07 -0000	1.1
--- ServerSubjectInvoker.java	2 Mar 2004 14:01:34 -0000	1.2
***************
*** 22,26 ****
  
  /**
-  *
   * @author <a href="mailto:[email protected]">Simone Bordet</a>
   * @version $Revision$
--- 22,25 ----
***************
*** 47,50 ****
--- 46,52 ----
     public Object invoke(Object proxy, final Method method, final Object[] args) throws Throwable
     {
+       String name = method.getName();
+       if ("close".equals(name)) return chain(method, args);
+ 
        Subject delegate = (Subject)args[args.length - 1];
        return MX4JRemoteUtils.subjectInvoke(subject, delegate, context, new PrivilegedExceptionAction()
***************
*** 52,67 ****
           public Object run() throws Exception
           {
!             try
!             {
!                return method.invoke(target, args);
!             }
!             catch (InvocationTargetException x)
!             {
!                Throwable xx =  x.getTargetException();
!                if (xx instanceof Exception) throw (Exception)xx;
!                throw new JMXServerErrorException("", (Error)xx);
!             }
           }
        });
     }
  }
--- 54,74 ----
           public Object run() throws Exception
           {
!             return chain(method, args);
           }
        });
     }
+ 
+    private Object chain(Method method, Object[] args) throws Exception
+    {
+       try
+       {
+          return method.invoke(target, args);
+       }
+       catch (InvocationTargetException x)
+       {
+          Throwable xx =  x.getTargetException();
+          if (xx instanceof Exception) throw (Exception)xx;
+          throw new JMXServerErrorException("Error thrown during invocation", (Error)xx);
+       }
+    }
  }

Index: ServerInvoker.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/tools/mx4j/tools/remote/local/ServerInvoker.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ServerInvoker.java	7 Sep 2003 18:18:07 -0000	1.1
--- ServerInvoker.java	2 Mar 2004 14:01:34 -0000	1.2
***************
*** 11,14 ****
--- 11,15 ----
  import java.io.IOException;
  import java.util.Set;
+ import java.util.HashSet;
  
  import javax.management.Attribute;
***************
*** 33,36 ****
--- 34,39 ----
  import javax.security.auth.Subject;
  
+ import mx4j.remote.NotificationTuple;
+ 
  /**
   *
***************
*** 40,43 ****
--- 43,47 ----
  class ServerInvoker implements LocalConnection
  {
+    private final Set listeners = new HashSet();
     private final MBeanServer server;
  
***************
*** 47,50 ****
--- 51,78 ----
     }
  
+    public void close() throws IOException
+    {
+       NotificationTuple[] tuples = null;
+       synchronized (listeners)
+       {
+          tuples = (NotificationTuple[])listeners.toArray(new NotificationTuple[listeners.size()]);
+          listeners.clear();
+       }
+       for (int i = 0; i < tuples.length; i++)
+       {
+          NotificationTuple tuple = tuples[i];
+          try
+          {
+             server.removeNotificationListener(tuple.getObjectName(), tuple.getNotificationListener(), tuple.getNotificationFilter(), tuple.getHandback());
+          }
+          catch (InstanceNotFoundException ignored)
+          {
+          }
+          catch (ListenerNotFoundException ignored)
+          {
+          }
+       }
+    }
+ 
     public ObjectInstance createMBean(String className, ObjectName name, Object[] params, String[] signature, Subject delegate)
             throws ReflectionException,
***************
*** 185,188 ****
--- 213,221 ----
             throws InstanceNotFoundException, IOException
     {
+       NotificationTuple tuple = new NotificationTuple(observed, listener, filter, handback);
+       synchronized (listeners)
+       {
+          listeners.add(tuple);
+       }
        server.addNotificationListener(observed, listener, filter, handback);
     }
***************
*** 191,194 ****
--- 224,232 ----
             throws InstanceNotFoundException, ListenerNotFoundException, IOException
     {
+       NotificationTuple tuple = new NotificationTuple(observed, listener);
+       synchronized (listeners)
+       {
+          listeners.remove(tuple);
+       }
        server.removeNotificationListener(observed, listener);
     }
***************
*** 197,200 ****
--- 235,243 ----
             throws InstanceNotFoundException, ListenerNotFoundException, IOException
     {
+       NotificationTuple tuple = new NotificationTuple(observed, listener, filter, handback);
+       synchronized (listeners)
+       {
+          listeners.remove(tuple);
+       }
        server.removeNotificationListener(observed, listener, filter, handback);
     }

Index: LocalConnectionImpl.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/tools/mx4j/tools/remote/local/LocalConnectionImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** LocalConnectionImpl.java	22 Sep 2003 17:40:22 -0000	1.2
--- LocalConnectionImpl.java	2 Mar 2004 14:01:34 -0000	1.3
***************
*** 53,56 ****
--- 53,57 ----
        if (closed) return;
        closed = true;
+       target.close();
        super.close();
     }

Index: LocalConnection.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/tools/mx4j/tools/remote/local/LocalConnection.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** LocalConnection.java	7 Sep 2003 18:15:11 -0000	1.2
--- LocalConnection.java	2 Mar 2004 14:01:34 -0000	1.3
***************
*** 38,41 ****
--- 38,43 ----
  interface LocalConnection
  {
+    public void close() throws IOException;
+ 
     public ObjectInstance createMBean(String className, ObjectName name, Object[] params, String[] signature, Subject delegate)
             throws ReflectionException,



-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.