Package org.jboss.remoting

Examples of org.jboss.remoting.Client$InvokerDestructionTimerTask


      HashMap config = new HashMap();
      config.put(InvokerLocator.FORCE_REMOTE, "true");
      config.put(Bisocket.IS_CALLBACK_SERVER, "true");
      config.put(Bisocket.PING_FREQUENCY, TEST_PING_FREQUENCY_STRING);
      addExtraClientConfig(config);
      Client client = new Client(serverLocator, config);
      client.connect();
      log.info("client is connected");
      assertTrue(client.getInvoker() instanceof BisocketClientInvoker);
      SimpleCallbackHandler callbackHandler = new SimpleCallbackHandler();
      client.addListener(callbackHandler, new HashMap());
      log.info("client added callback handler");
      client.invoke(CALLBACK_TEST);
      assertEquals(1, callbackHandler.callbackCounter);
     
      Connector oldConnector = connector;
      SocketServerInvoker invoker = (SocketServerInvoker) connector.getServerInvoker();
      Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
      field.setAccessible(true);
      LRUPool clientpool = (LRUPool) field.get(invoker);
      Set threads = clientpool.getContents();
      for (Iterator it = threads.iterator(); it.hasNext(); )
      {
         ServerThread t = (ServerThread) it.next();
         field = ServerThread.class.getDeclaredField("socketWrapper");
         field.setAccessible(true);
         SocketWrapper socketWrapper = (SocketWrapper) field.get(t);
         socketWrapper.close();
      }
      connector.stop();
      log.info("STOPPED CONNECTOR");
     
      internalSetUp(port);
      log.info("RESTARTED CONNECTOR");
      assertNotSame(connector, oldConnector);
     
      // It is beyond the scope of Remoting to fail over to a new server,
      // complete with registered callback handlers.
      log.info("adding callback handler");
      client.addListener(callbackHandler, new HashMap());
      log.info("client added callback handler");
     
      client.invoke(CALLBACK_TEST);
      assertEquals(2, callbackHandler.callbackCounter);

      client.removeListener(callbackHandler);
      client.disconnect();
     
      // The ControlMonitorTimerTask from the first callback handler tries to recreate
      // its control connection, which adds an entry to
      // BisocketClientInvoker.listenerIdToSocketsMap which cannot be removed, which
      // interferes with testForLeaks().
View Full Code Here


      config.put(Bisocket.IS_CALLBACK_SERVER, "true");
      config.put(Bisocket.PING_FREQUENCY, TEST_PING_FREQUENCY_STRING);
      int MAX_RETRIES = 3;
      config.put(Bisocket.MAX_CONTROL_CONNECTION_RESTARTS, Integer.toString(MAX_RETRIES));
      addExtraClientConfig(config);
      Client client = new Client(serverLocator, config);
      client.connect();
      log.info("client is connected");
      assertTrue(client.getInvoker() instanceof BisocketClientInvoker);
     
      String callbackLocatorURI = getTransport() + "://" + host + ":1";
      config.put(Bisocket.IS_CALLBACK_SERVER, "true");
      Connector callbackConnector = new Connector(callbackLocatorURI, config);
      callbackConnector.start();
      SimpleCallbackHandler callbackHandler = new SimpleCallbackHandler();
      client.addListener(callbackHandler, new InvokerLocator(callbackLocatorURI));
      log.info("client added callback handler");
      client.invoke(CALLBACK_TEST);
      assertEquals(1, callbackHandler.callbackCounter);
     
      SocketServerInvoker invoker = (SocketServerInvoker) connector.getServerInvoker();
      Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
      field.setAccessible(true);
      LRUPool clientpool = (LRUPool) field.get(invoker);
      Set threads = clientpool.getContents();
      for (Iterator it = threads.iterator(); it.hasNext(); )
      {
         ServerThread t = (ServerThread) it.next();
         field = ServerThread.class.getDeclaredField("socketWrapper");
         field.setAccessible(true);
         SocketWrapper socketWrapper = (SocketWrapper) field.get(t);
         socketWrapper.close();
      }
      connector.stop();
      log.info("STOPPED CONNECTOR");
      internalSetUp(port);
      log.info("RESTARTED CONNECTOR");
     
      // Wait until a failure has been detected on the control connection.
      Thread.sleep(TEST_PING_FREQUENCY * MAX_RETRIES * 8);
     
      ServerInvoker callbackServerInvoker = callbackConnector.getServerInvoker();
      field = BisocketServerInvoker.class.getDeclaredField("controlConnectionThreadMap");
      field.setAccessible(true);
      Map controlConnectionThreadMap = (Map) field.get(callbackServerInvoker);
      assertEquals(0, controlConnectionThreadMap.size());
     
      client.setDisconnectTimeout(0);
      client.removeListener(callbackHandler);
      client.disconnect();
   }
View Full Code Here

      config.put(InvokerLocator.FORCE_REMOTE, "true");
      config.put(Bisocket.IS_CALLBACK_SERVER, "true");
      config.put(Bisocket.PING_FREQUENCY, TEST_PING_FREQUENCY_STRING);
     
      addExtraClientConfig(config);
      Client client = new Client(serverLocator, config);
      client.connect();
      log.info("client is connected");
      assertTrue(client.getInvoker() instanceof BisocketClientInvoker);
     
      int CALLBACK_HANDLER_COUNT = 5;
      SimpleCallbackHandler[] callbackHandlers = new SimpleCallbackHandler[CALLBACK_HANDLER_COUNT];
      for (int i = 0; i < CALLBACK_HANDLER_COUNT; i++)
      {
         callbackHandlers[i] = new SimpleCallbackHandler();
         client.addListener(callbackHandlers[i], new HashMap());
      }

      client.invoke(CALLBACK_TEST);
      for (int i = 0; i < CALLBACK_HANDLER_COUNT; i++)
      {
         assertEquals(1, callbackHandlers[i].callbackCounter);
      }
     
      // Static fields.
      Field field = BisocketServerInvoker.class.getDeclaredField("listenerIdToServerInvokerMap");
      field.setAccessible(true);
      Map listenerIdToServerInvokerMap = (Map) field.get(null);
      field = BisocketClientInvoker.class.getDeclaredField("listenerIdToClientInvokerMap");
      field.setAccessible(true);
      Map listenerIdToClientInvokerMap = (Map) field.get(null);
      field = BisocketClientInvoker.class.getDeclaredField("listenerIdToCallbackClientInvokerMap");
      field.setAccessible(true);
      Map listenerIdToCallbackClientInvokerMap = (Map) field.get(null);
      field = BisocketClientInvoker.class.getDeclaredField("listenerIdToSocketsMap");
      field.setAccessible(true);
      Map listenerIdToSocketsMap = (Map) field.get(null);
     
      // Non-static fields.
      field = Client.class.getDeclaredField("callbackConnectors");
      field.setAccessible(true);
      Map callbackConnectors = (Map) field.get(client);
      assertEquals(CALLBACK_HANDLER_COUNT, callbackConnectors.size());
      ServerInvoker[] serverInvokers = new ServerInvoker[CALLBACK_HANDLER_COUNT];
      Map[] listenerIdToInvokerLocatorMaps = new Map[CALLBACK_HANDLER_COUNT];
      Map[] controlConnectionThreadMaps = new Map[CALLBACK_HANDLER_COUNT];

      int i = 0;
      Iterator it = callbackConnectors.values().iterator();
      while (it.hasNext())
      {
         Set set = (Set) it.next();
         assertEquals(1, set.size());
         Connector c = (Connector) set.iterator().next();
         serverInvokers[i] = c.getServerInvoker();
         assertTrue(serverInvokers[i] instanceof BisocketServerInvoker);
         field = BisocketServerInvoker.class.getDeclaredField("listenerIdToInvokerLocatorMap");
         field.setAccessible(true);
         listenerIdToInvokerLocatorMaps[i] = (Map) field.get(serverInvokers[i]);
         field = BisocketServerInvoker.class.getDeclaredField("controlConnectionThreadMap");
         field.setAccessible(true);
         controlConnectionThreadMaps[i] = (Map) field.get(serverInvokers[i]);
         i++;
      }
     
      assertEquals(CALLBACK_HANDLER_COUNT, listenerIdToServerInvokerMap.size());
      assertEquals(CALLBACK_HANDLER_COUNT, listenerIdToClientInvokerMap.size());
      assertEquals(CALLBACK_HANDLER_COUNT, listenerIdToCallbackClientInvokerMap.size());
      assertEquals(CALLBACK_HANDLER_COUNT, listenerIdToSocketsMap.size());
     
      for (int j = 0; j < CALLBACK_HANDLER_COUNT; j++)
      {
         assertEquals(1, listenerIdToInvokerLocatorMaps[j].size());
         assertEquals(1, controlConnectionThreadMaps[j].size());
         field = BisocketServerInvoker.class.getDeclaredField("controlMonitorTimerTask");
         field.setAccessible(true);
         assertNotNull(field.get(serverInvokers[j]));
      }
     
      for (int j = 0; j < CALLBACK_HANDLER_COUNT; j++)
      {
         client.removeListener(callbackHandlers[j]);
      }
     
      assertEquals(0, listenerIdToServerInvokerMap.size());
      assertEquals(0, listenerIdToClientInvokerMap.size());
      assertEquals(0, listenerIdToCallbackClientInvokerMap.size());
      assertEquals(0, listenerIdToSocketsMap.size());
     
      Class[] classes = BisocketServerInvoker.class.getDeclaredClasses();
      Class controlMonitorTimerTaskClass = null;
      for (int j = 0; j < classes.length; j++)
      {
         log.info(classes[j]);
         String fqn = classes[j].getName();
         String className = fqn.substring(fqn.lastIndexOf('.') + 1);
         log.info(className);
         if ("BisocketServerInvoker$ControlMonitorTimerTask".equals(className))
         {
            controlMonitorTimerTaskClass = classes[j];
            break;
         }
      }
      assertNotNull(controlMonitorTimerTaskClass);
     
      for (int j = 0; j < CALLBACK_HANDLER_COUNT; j++)
      {
         assertEquals("server invoker: " + j, 0, listenerIdToInvokerLocatorMaps[j].size());
         assertEquals("server invoker: " + j, 0, controlConnectionThreadMaps[j].size());
        
         field = BisocketServerInvoker.class.getDeclaredField("controlMonitorTimerTask");
         field.setAccessible(true);
         Object controlMonitorTimerTask = field.get(serverInvokers[j]);
         field = controlMonitorTimerTaskClass.getDeclaredField("listenerIdToInvokerLocatorMap");
         field.setAccessible(true);
         assertNull("server invoker: " + j, field.get(controlMonitorTimerTask));
         field = controlMonitorTimerTaskClass.getDeclaredField("controlConnectionThreadMap");
         field.setAccessible(true);
         assertNull("server invoker: " + j, field.get(controlMonitorTimerTask));   
      }
     
      client.disconnect();
   }
View Full Code Here

      config.put(InvokerLocator.FORCE_REMOTE, "true");
      config.put(Bisocket.IS_CALLBACK_SERVER, "true");
      config.put(Bisocket.PING_FREQUENCY, TEST_PING_FREQUENCY_STRING);
     
      addExtraClientConfig(config);
      Client client = new Client(serverLocator, config);
      client.connect();
      log.info("client is connected");
      assertTrue(client.getInvoker() instanceof BisocketClientInvoker);
     
      int CALLBACK_HANDLER_COUNT = 5;
      SimpleCallbackHandler[] callbackHandlers = new SimpleCallbackHandler[CALLBACK_HANDLER_COUNT];
      for (int i = 0; i < CALLBACK_HANDLER_COUNT; i++)
      {
         callbackHandlers[i] = new SimpleCallbackHandler();
         client.addListener(callbackHandlers[i], new HashMap());
      }

      client.invoke(CALLBACK_TEST);
      for (int i = 0; i < CALLBACK_HANDLER_COUNT; i++)
      {
         assertEquals(1, callbackHandlers[i].callbackCounter);
      }
     
      // Static fields.
      Field field = BisocketServerInvoker.class.getDeclaredField("listenerIdToServerInvokerMap");
      field.setAccessible(true);
      Map listenerIdToServerInvokerMap = (Map) field.get(null);
      field = BisocketClientInvoker.class.getDeclaredField("listenerIdToClientInvokerMap");
      field.setAccessible(true);
      Map listenerIdToClientInvokerMap = (Map) field.get(null);
     
      // Non-static fields.
      field = Client.class.getDeclaredField("callbackConnectors");
      field.setAccessible(true);
      Map callbackConnectors = (Map) field.get(client);
      assertEquals(CALLBACK_HANDLER_COUNT, callbackConnectors.size());
      ServerInvoker[] serverInvokers = new ServerInvoker[CALLBACK_HANDLER_COUNT];
      Map[] listenerIdToInvokerLocatorMaps = new Map[CALLBACK_HANDLER_COUNT];
      Map[] controlConnectionThreadMaps = new Map[CALLBACK_HANDLER_COUNT];

      int i = 0;
      Iterator it = callbackConnectors.values().iterator();
      while (it.hasNext())
      {
         Set set = (Set) it.next();
         assertEquals(1, set.size());
         Connector c = (Connector) set.iterator().next();
         serverInvokers[i] = c.getServerInvoker();
         assertTrue(serverInvokers[i] instanceof BisocketServerInvoker);
         field = BisocketServerInvoker.class.getDeclaredField("listenerIdToInvokerLocatorMap");
         field.setAccessible(true);
         listenerIdToInvokerLocatorMaps[i] = (Map) field.get(serverInvokers[i]);
         field = BisocketServerInvoker.class.getDeclaredField("controlConnectionThreadMap");
         field.setAccessible(true);
         controlConnectionThreadMaps[i] = (Map) field.get(serverInvokers[i]);
         i++;
      }
     
      assertEquals(CALLBACK_HANDLER_COUNT, listenerIdToServerInvokerMap.size());
      assertEquals(CALLBACK_HANDLER_COUNT, listenerIdToClientInvokerMap.size());
     
      for (int j = 0; j < CALLBACK_HANDLER_COUNT; j++)
      {
         assertEquals(1, listenerIdToInvokerLocatorMaps[j].size());
         assertEquals(1, controlConnectionThreadMaps[j].size());
         field = BisocketServerInvoker.class.getDeclaredField("controlMonitorTimerTask");
         field.setAccessible(true);
         assertNotNull(field.get(serverInvokers[j]));
      }
     
      client.setDisconnectTimeout(0);
     
      for (int j = 0; j < CALLBACK_HANDLER_COUNT; j++)
      {
         client.removeListener(callbackHandlers[j]);
      }
     
      assertEquals(0, listenerIdToServerInvokerMap.size());
      assertEquals(0, listenerIdToClientInvokerMap.size());
     
      Class[] classes = BisocketServerInvoker.class.getDeclaredClasses();
      Class controlMonitorTimerTaskClass = null;
      for (int j = 0; j < classes.length; j++)
      {
         log.info(classes[j]);
         String fqn = classes[j].getName();
         String className = fqn.substring(fqn.lastIndexOf('.') + 1);
         log.info(className);
         if ("BisocketServerInvoker$ControlMonitorTimerTask".equals(className))
         {
            controlMonitorTimerTaskClass = classes[j];
            break;
         }
      }
      assertNotNull(controlMonitorTimerTaskClass);
     
      for (int j = 0; j < CALLBACK_HANDLER_COUNT; j++)
      {
         assertEquals("server invoker: " + j, 0, listenerIdToInvokerLocatorMaps[j].size());
         assertEquals("server invoker: " + j, 0, controlConnectionThreadMaps[j].size());
        
         field = BisocketServerInvoker.class.getDeclaredField("controlMonitorTimerTask");
         field.setAccessible(true);
         Object controlMonitorTimerTask = field.get(serverInvokers[j]);
         field = controlMonitorTimerTaskClass.getDeclaredField("listenerIdToInvokerLocatorMap");
         field.setAccessible(true);
         assertNull("server invoker: " + j, field.get(controlMonitorTimerTask));
         field = controlMonitorTimerTaskClass.getDeclaredField("controlConnectionThreadMap");
         field.setAccessible(true);
         assertNull("server invoker: " + j, field.get(controlMonitorTimerTask));   
      }
     
      client.disconnect();
   }
View Full Code Here

      InvokerLocator clientLocator = new InvokerLocator(locatorURI);
      HashMap clientConfig = new HashMap();
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
      addExtraClientConfig(clientConfig);
      System.setProperty(Remoting.CLASSLOADING_PARENT_FIRST_DELEGATION_PROP, "false");
      Client client = new Client(clientLocator, clientConfig);
      client.connect();
      log.info("client is connected");
     
      TestClassLoader tcl = new TestClassLoader();
      setContextClassLoader(tcl);
     
      // Test connection.
      client.invoke("abc");
      log.info("connection is good");
     
      // Verify that TestClassLoader has been queried.
      assertTrue(tcl.visited);
      log.info("context classloader has been queried");
     
      client.disconnect();
      shutdownServer();
      log.info(getName() + " PASSES");
   }
View Full Code Here

      connector.addInvocationHandler("test", handler);
      connector.start();
     
      HashMap clientConfig = new HashMap();
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
      Client client = new Client(locator, clientConfig);
      client.connect();
     
      Object response = client.invoke(FAST);
      assertEquals(FAST, response);
     
      long start = System.currentTimeMillis();
     
      // This invocation should run in pooled thread 1.
      log.info("making 1st oneway invocation");
      client.invokeOneway(SLOW + "1", null, false);
      poolCounter++;
     
      // Wait for the connection to return to the pool.
      Thread.sleep(500);
     
      // This invocation should run in pooled thread 2.
      log.info("making 2nd oneway invocation");
      client.invokeOneway(SLOW + "2", null, false);
     
      // Wait for the connection to return to the pool.
      Thread.sleep(500);
     
      // This invocation should use the pooled connection and go into the queue.
      log.info("making 3rd oneway invocation");
      client.invokeOneway(SLOW + "3", null, false);
     
      // Wait for the connection to return to the pool.
      Thread.sleep(500);
     
      // This invocation should use the pooled connection and get run by the
      // ServerThread.  The connection should go back into the pool but the
      // ServerThread will be busy for the next 5 seconds.
      log.info("making 4th oneway invocation");
      client.invokeOneway(SLOW + "4", null, false);
     
      // Wait for the connection to return to the pool.
      Thread.sleep(500);
     
      // This invocation should use the pooled connection and have to wait
      // for 5 seconds.
      log.info("making 5th oneway invocation");
      client.invokeOneway(SLOW + "5", null, false);
     
      assertTrue((System.currentTimeMillis() - start < 3000));
      assertEquals(4, handler.startedCount);
     
      // It's necessary to wait for more than 5000 ms here because one or two
      // of the invocations might go out over preexisting pooled connections
      // and have to wait for the handler to finish the previous invocation.
      Thread.sleep(6000);
      assertEquals(6, handler.startedCount);
     
      client.disconnect();
      connector.stop();
      log.info(getName() + " PASSES");
   }
View Full Code Here

      try
      {
         InvokerLocator locator = new InvokerLocator(httpTargetURL);
         Map config = new HashMap();
         config.put(Client.ENABLE_LEASE, "false");
         client = new Client(locator, config);
         client.connect();
      }
      catch(Exception e)
      {
         e.printStackTrace();
View Full Code Here

   {
      System.out.println("*******************************************************");
      System.out.println("*****           EXCEPTIONS ARE EXPECTED           *****");
      System.out.println("*******************************************************");
      log.info("entering setUp() for " + getName());
      Client client = null;
     
      // Ask server to create a Connector.
      try
      {
         String host = InetAddress.getLocalHost().getHostAddress();
         int mainPort = QuickDisconnectServerParent.port;
         String locatorURI = getTransport() + "://" + host + ":" + mainPort;
         InvokerLocator locator = new InvokerLocator(locatorURI);
         client = new Client(locator);
         client.connect();
         Object response = client.invoke(QuickDisconnectServerParent.START_SERVER);
         port = ((Integer) response).intValue();
         Thread.sleep(1000);
         log.info("leaving setUp() for " + getName());
      }
      catch (Throwable e)
View Full Code Here

      HashMap config = new HashMap();
      config.put(InvokerLocator.FORCE_REMOTE, "true");
      config.put(ServerInvoker.TIMEOUT, "60000");
      config.put(Client.ENABLE_LEASE, "true");
      addClientConfig(config);
      final Client client = new Client(locator, config);
      try
      {
         client.connect();
      }
      catch (Exception e)
      {
         e.printStackTrace();
      }
      log.info("making first invocation");
      Object response = client.invoke("test");
      assertEquals("test", response);
      log.info("first invocation succeeds");
     
     
      new Thread()
      {
         public void run()
         {
            try
            {
               // Wait for the server to be disabled.
               Thread.sleep(10000);
              
               try
               {
               // This invocation may use up a listening connection,
               // depending on transport.
                  HashMap metadata = new HashMap();
                  metadata.put("timeout", shortTimeoutString());
                  log.info("making invocation");
                  client.invoke("test", metadata);
                  log.info("made invocation");
               }
               catch (Exception e)
               {
                  log.info("client.invoke(\"test\") failed (that's OK)");
               }
              
              
               // Set disconnectTimeout to 0.
               log.info("calling client.disconnect()");
               client.setDisconnectTimeout(0);
               client.disconnect();
               log.info("returned from client.disconnect()");
            }
            catch (Throwable e)
            {
               log.info("error in client.disconnect()", e);
            }
         }
      }.start();
     
      // It should take the Client a little while for LeasePinger's attempts to contact
      // the server to time out.  Wait for about 4 seconds after the call to
      // Client.disconnect() and then verify that the Client has successfully
      // disconnected even though the server is disabled.
      Thread.sleep(16000);
      assertFalse(client.isConnected());
      log.info(getName() + " PASSES");
   }
View Full Code Here

      connector.addInvocationHandler("test", handler);
      connector.start();
     
      HashMap clientConfig = new HashMap();
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
      Client client = new Client(locator, clientConfig);
      client.connect();
     
      // CoyoteInvoker defaults to 200 threads.
      int INVOCATIONS = 300;
      OnewayThread[] threads = new OnewayThread[INVOCATIONS];
     
      for (int i = 0; i < INVOCATIONS; i++)
      {
         threads[i] = new OnewayThread(client, i, false);
         threads[i].start();
      }
     
      go = true;
      poolCounter++;
      Thread.sleep(5000);
     
      // Verify INVOCATIONS invocations were received.
      assertEquals(INVOCATIONS, handler.startedCount);
     
      for (int i = 0; i < INVOCATIONS; i++)
      {
         assertTrue("failure in thread: " + i, threads[i].ok);
      }
     
      client.disconnect();
      connector.stop();
      log.info(getName() + " PASSES");
   }
View Full Code Here

TOP

Related Classes of org.jboss.remoting.Client$InvokerDestructionTimerTask

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.