1 Reply Latest reply on Feb 3, 2006 3:35 PM by tom.elrod

    MBean as a Listener

    vassilk

      I have a weird problem. I have an MBean in JBoss AS. This MBean connects to a server and receives data from the server. The server _pushes_ the data to the MBean as soon as it arrives.

      Thus, the MBean acts as a client by creating a local Connector (callback server), which acts as the local server accepting the pushed data. Then the MBean creates a Client which connects to the remote server, and adds a listener on the callback servers' invoker locator.

      My problem is that even when I stop the MBean, the callback server (Connector) and the client (Client), I continue to receive data from the remote server.

      Here is how I connect to the server (sans catch/try):
      =====================================================
      callbackServerURI = "socket://" + localhost + ":" + port;
      callbackServer = new Connector();
      callbackServer.setInvokerLocator(callbackServerURI);
      callbackServer.start();
      callbackServer.getServerInvoker().addInvocationHandler("S1", new DataProviderServerInvocationHelper());

      client = new Client( new InvokerLocator(serverLocatorURI), "S1");
      client.connect();
      listener = new DataProviderCallbackHandlerImpl();
      client.addListener(listener, new InvokerLocator(callbackServerURI));
      =====================================================


      Here is how I disconnect:
      =====================================================
      listener.stop();
      callbackServer.getServerInvoker().removeInvocationHandler(
      callbackServer.getServerInvoker().getInvocationHandlers()[0].toString()
      );
      callbackServer.stop();
      callbackServer.destroy();
      client.removeListener(listener);
      client.disconnect();
      =====================================================


      The variables listener, callbackServer, and client a stored in the MBean. Is there anything wrong with this configuration? Why doesn't the client disconnect at the end (the local socket is also not freed up)?

      I'll be very greatful for your help.


        • 1. Re: MBean as a Listener

          First off am not sure why you are not seeing an exception when making the following call:

          client.removeListener(listener);

          Upon making this call on the client, the client will remove the listener from the callback server and the target server. Since the callback server has been destroyed, should get a org.jboss.remoting.CannotConnectException thrown.

          Just to make sure there wasn't a bug with disconnecting callbacks, I wrote a test case to verify that once callback listener is removed and the callback server is destroyed, that no more callbacks are delivered (based off the code you posted in the forum).

          The test classes are org.jboss.test.remoting.callback.push.disconnect.CallbackTestClient and org.jboss.test.remoting.callback.push.disconnect.CallbackTestServer.

          The test passes on my machine with latest remoting codebase. Also, was able to debug to make sure that there were no threads left over that shouldn't be and there were not.

          If you still think this is an issue, please open a jira issue and supply a test case demonstrating the bug.

          Thanks.

          -Tom