Package org.jboss.remoting

Examples of org.jboss.remoting.Client


      InvokerLocator serverLocator = new InvokerLocator(locatorURI);
      log.info("Connecting to: " + serverLocator);
      HashMap config = new HashMap();
      config.put(InvokerLocator.FORCE_REMOTE, "true");
      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();
     
      DelayedCallbackHandler callbackHandler1 = new DelayedCallbackHandler();
      client.addListener(callbackHandler1, new InvokerLocator(callbackLocatorURI));
      DelayedCallbackHandler callbackHandler2 = new DelayedCallbackHandler();
      client.addListener(callbackHandler2, new InvokerLocator(callbackLocatorURI));
      assertEquals(2, invocationHandler.callbackHandlers.size());
      log.info("clients added callback handler");
     
      Iterator it = invocationHandler.callbackHandlers.iterator();
      ServerInvokerCallbackHandler serverInvokerCallbackHandler1 = (ServerInvokerCallbackHandler) it.next();
      ServerInvokerCallbackHandler serverInvokerCallbackHandler2 = (ServerInvokerCallbackHandler) it.next();
      Client callbackClient1 = serverInvokerCallbackHandler1.getCallbackClient();
      Client callbackClient2 = serverInvokerCallbackHandler2.getCallbackClient();
      assertNotSame(callbackClient1, callbackClient2);
      ClientInvoker clientInvoker1 = callbackClient1.getInvoker();
      assertTrue(clientInvoker1 instanceof BisocketClientInvoker);
      ClientInvoker clientInvoker2 = callbackClient2.getInvoker();
      assertTrue(clientInvoker2 instanceof BisocketClientInvoker);
      assertNotSame(clientInvoker1, clientInvoker2);
     
      Field field = MicroSocketClientInvoker.class.getDeclaredField("pool");
      field.setAccessible(true);
View Full Code Here


      InvokerLocator serverLocator = new InvokerLocator(locatorURI);
      log.info("Connecting to: " + serverLocator);
      HashMap config = new HashMap();
      config.put(InvokerLocator.FORCE_REMOTE, "true");
      addExtraClientConfig(config);
      Client client1 = new Client(serverLocator, config);
      client1.connect();
      Client client2 = new Client(serverLocator, config);
      client2.connect();
      log.info("clients are connected");
      assertTrue(client1.getInvoker() instanceof BisocketClientInvoker);
      assertTrue(client2.getInvoker() instanceof BisocketClientInvoker);
     
      String callbackLocatorURI1 = getTransport() + "://" + host + ":1";
      config.put(Bisocket.IS_CALLBACK_SERVER, "true");
      Connector callbackConnector1 = new Connector(callbackLocatorURI1, config);
      callbackConnector1.start();
      String callbackLocatorURI2 = getTransport() + "://" + host + ":2";
      Connector callbackConnector2 = new Connector(callbackLocatorURI2, config);
      callbackConnector2.start();
     
      DelayedCallbackHandler callbackHandler = new DelayedCallbackHandler();
      client1.addListener(callbackHandler, new InvokerLocator(callbackLocatorURI1));
      client2.addListener(callbackHandler, new InvokerLocator(callbackLocatorURI2));
      assertEquals(2, invocationHandler.callbackHandlers.size());
      log.info("clients added callback handler");
     
      Iterator it = invocationHandler.callbackHandlers.iterator();
      ServerInvokerCallbackHandler serverInvokerCallbackHandler1 = (ServerInvokerCallbackHandler) it.next();
      ServerInvokerCallbackHandler serverInvokerCallbackHandler2 = (ServerInvokerCallbackHandler) it.next();
      Client callbackClient1 = serverInvokerCallbackHandler1.getCallbackClient();
      Client callbackClient2 = serverInvokerCallbackHandler2.getCallbackClient();
      assertNotSame(callbackClient1, callbackClient2);
      ClientInvoker clientInvoker1 = callbackClient1.getInvoker();
      assertTrue(clientInvoker1 instanceof BisocketClientInvoker);
      ClientInvoker clientInvoker2 = callbackClient2.getInvoker();
      assertTrue(clientInvoker2 instanceof BisocketClientInvoker);
      assertNotSame(clientInvoker1, clientInvoker2);
     
      Field field = MicroSocketClientInvoker.class.getDeclaredField("pool");
      field.setAccessible(true);
View Full Code Here

      InvokerLocator serverLocator = new InvokerLocator(locatorURI);
      log.info("Connecting to: " + serverLocator);
      HashMap config = new HashMap();
      config.put(InvokerLocator.FORCE_REMOTE, "true");
      addExtraClientConfig(config);
      Client client = new Client(serverLocator, config);
      client.connect();
      log.info("client is connected");
      assertTrue(client.getInvoker() instanceof BisocketClientInvoker);
     
      String callbackLocatorURI1 = getTransport() + "://" + host + ":1";
      config.put(Bisocket.IS_CALLBACK_SERVER, "true");
      Connector callbackConnector1 = new Connector(callbackLocatorURI1, config);
      callbackConnector1.start();
      String callbackLocatorURI2 = getTransport() + "://" + host + ":2";
      Connector callbackConnector2 = new Connector(callbackLocatorURI2, config);
      callbackConnector2.start();
     
      DelayedCallbackHandler callbackHandler1 = new DelayedCallbackHandler();
      client.addListener(callbackHandler1, new InvokerLocator(callbackLocatorURI1));
      DelayedCallbackHandler callbackHandler2 = new DelayedCallbackHandler();
      client.addListener(callbackHandler2, new InvokerLocator(callbackLocatorURI2));
      assertEquals(2, invocationHandler.callbackHandlers.size());
      log.info("clients added callback handler");
     
      Iterator it = invocationHandler.callbackHandlers.iterator();
      ServerInvokerCallbackHandler serverInvokerCallbackHandler1 = (ServerInvokerCallbackHandler) it.next();
      ServerInvokerCallbackHandler serverInvokerCallbackHandler2 = (ServerInvokerCallbackHandler) it.next();
      Client callbackClient1 = serverInvokerCallbackHandler1.getCallbackClient();
      Client callbackClient2 = serverInvokerCallbackHandler2.getCallbackClient();
      assertNotSame(callbackClient1, callbackClient2);
      ClientInvoker clientInvoker1 = callbackClient1.getInvoker();
      assertTrue(clientInvoker1 instanceof BisocketClientInvoker);
      ClientInvoker clientInvoker2 = callbackClient2.getInvoker();
      assertTrue(clientInvoker2 instanceof BisocketClientInvoker);
      assertNotSame(clientInvoker1, clientInvoker2);
     
      Field field = MicroSocketClientInvoker.class.getDeclaredField("pool");
      field.setAccessible(true);
View Full Code Here

      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);
      DelayedCallbackHandler callbackHandler = new DelayedCallbackHandler();
      client.addListener(callbackHandler, new HashMap());
      log.info("client added callback handler");
      client.invoke(CALLBACK_TEST);
      client.invoke(CALLBACK_TEST);
      client.invoke(CALLBACK_TEST);
     
      Thread.sleep(500);
      assertEquals(3, callbackHandler.callbackCounter);
     
      Field field = Client.class.getDeclaredField("callbackConnectors");
      field.setAccessible(true);
      Map callbackConnectors = (Map) field.get(client);
      assertEquals(1, callbackConnectors.size());
      Set callbackConnectorSet = (Set) callbackConnectors.values().iterator().next();
      assertEquals(1, callbackConnectorSet.size());
      Connector callbackConnector = (Connector) callbackConnectorSet.iterator().next();
      BisocketServerInvoker invoker = (BisocketServerInvoker) callbackConnector.getServerInvoker();
      field = BisocketServerInvoker.class.getDeclaredField("controlConnectionThreadMap");
      field.setAccessible(true);
      Map controlConnectionThreadMap = (Map) field.get(invoker);
      assertEquals(1, controlConnectionThreadMap.size());
      Thread t = (Thread) controlConnectionThreadMap.values().iterator().next();
      Class[] classes = BisocketServerInvoker.class.getDeclaredClasses();
      Class invokerClass = null;
      for (int i = 0; i < classes.length; i++)
      {
         log.info(classes[i]);
         String fqn = classes[i].getName();
         String className = fqn.substring(fqn.lastIndexOf('.') + 1);
         log.info(className);
         if ("BisocketServerInvoker$ControlConnectionThread".equals(className))
         {
            invokerClass = classes[i];
            break;
         }
      }
     
      assertTrue(invokerClass != null);
      field = invokerClass.getDeclaredField("lastPing");
      field.setAccessible(true);
      int pingFrequency = Integer.parseInt(TEST_PING_FREQUENCY_STRING);
      Thread.sleep(2 * pingFrequency);
      Long lastPing = (Long) field.get(t);
      log.info("current: " + System.currentTimeMillis() + ", lastPing: " + lastPing);
      assertTrue((System.currentTimeMillis() - lastPing.longValue()) < pingFrequency);
     
      client.removeListener(callbackHandler);
      client.disconnect();
   }
View Full Code Here

      InvokerLocator clientLocator = new InvokerLocator(locatorURI);
      HashMap clientConfig = new HashMap();
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
      clientConfig.put("numberOfCallRetries", "1");
      addExtraClientConfig(clientConfig);
      Client client = new Client(clientLocator, clientConfig);
      client.connect();
      log.info("client is connected");
     
      // Verify invocation can complete.
      assertEquals("abc", client.invoke("abc"));
     
      // Verify ServerThread was discarded.
      SocketServerInvoker serverInvoker = (SocketServerInvoker) connector.getServerInvoker();
      assertEquals(0, serverInvoker.getCurrentClientPoolSize());
      assertEquals(0, serverInvoker.getCurrentThreadPoolSize());
     
      client.disconnect();
      shutdownServer();
      log.info(getName() + " PASSES");
   }
View Full Code Here

      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);
      DelayedCallbackHandler callbackHandler = new DelayedCallbackHandler();
      client.addListener(callbackHandler, new HashMap());
      log.info("client added callback handler");
      client.invoke(CALLBACK_TEST);
      assertEquals(1, callbackHandler.callbackCounter);
     
      ServerInvoker serverInvoker = connector.getServerInvoker();
      assertTrue(serverInvoker instanceof BisocketServerInvoker);
      Field field = ServerInvoker.class.getDeclaredField("callbackHandlers");
      field.setAccessible(true);
      Map callbackHandlers = (Map) field.get(serverInvoker);
      assertEquals(1, callbackHandlers.size());
      ServerInvokerCallbackHandler serverInvokerCallbackHandler;
      serverInvokerCallbackHandler = (ServerInvokerCallbackHandler) callbackHandlers.values().toArray()[0];
      Client callbackClient = serverInvokerCallbackHandler.getCallbackClient();
      assertTrue(callbackClient.getInvoker() instanceof BisocketClientInvoker);
      MicroSocketClientInvoker clientInvoker = (MicroSocketClientInvoker) callbackClient.getInvoker();
      field = BisocketClientInvoker.class.getDeclaredField("controlSocket");
      field.setAccessible(true);
      Socket controlSocket = (Socket) field.get(clientInvoker);
      controlSocket.close();
      log.info("CLOSED CONTROL SOCKET");
View Full Code Here

      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);
      DelayedCallbackHandler callbackHandler = new DelayedCallbackHandler();
      client.addListener(callbackHandler, new HashMap());
      log.info("client added callback handler");
      client.invoke(CALLBACK_TEST);
      assertEquals(1, callbackHandler.callbackCounter);
     
      Iterator it = invocationHandler.callbackHandlers.iterator();
      ServerInvokerCallbackHandler serverInvokerCallbackHandler = (ServerInvokerCallbackHandler) it.next();
      Client callbackClient = serverInvokerCallbackHandler.getCallbackClient();
      assertTrue(callbackClient.getInvoker() instanceof BisocketClientInvoker);
      BisocketClientInvoker clientInvoker = (BisocketClientInvoker) callbackClient.getInvoker();
      Field field = BisocketClientInvoker.class.getDeclaredField("controlSocket");
      field.setAccessible(true);
      Socket serverSideControlSocket = (Socket) field.get(clientInvoker);
     
      field = Client.class.getDeclaredField("callbackConnectors");
View Full Code Here

      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);
      DelayedCallbackHandler callbackHandler = new DelayedCallbackHandler();
      client.addListener(callbackHandler, new HashMap());
      log.info("client added callback handler");
     
      // Shut down control connection on client side, so that pings can't be sent
      // from server.
      Field field = Client.class.getDeclaredField("callbackConnectors");
      field.setAccessible(true);
      Map callbackConnectors = (Map) field.get(client);
      assertEquals(1, callbackConnectors.size());
      Set callbackConnectorSet = (Set) callbackConnectors.values().iterator().next();
      assertEquals(1, callbackConnectorSet.size());
      Connector callbackConnector = (Connector) callbackConnectorSet.iterator().next();
      ServerInvoker cbsi = callbackConnector.getServerInvoker();
      assertTrue(cbsi instanceof BisocketServerInvoker);
      field = BisocketServerInvoker.class.getDeclaredField("controlConnectionThreadMap");
      field.setAccessible(true);
      Map controlConnectionThreadMap = (Map) field.get(cbsi);
      assertEquals(1, controlConnectionThreadMap.size());
      Thread t = (Thread) controlConnectionThreadMap.values().iterator().next();
      Class[] classes = BisocketServerInvoker.class.getDeclaredClasses();
      Class controlConnectionThreadClass = null;
     
      for (int i = 0; i < classes.length; i++)
      {
         log.info(classes[i]);
         String fqn = classes[i].getName();
         String className = fqn.substring(fqn.lastIndexOf('.') + 1);
         log.info(className);
         if ("BisocketServerInvoker$ControlConnectionThread".equals(className))
         {
            controlConnectionThreadClass = classes[i];
            break;
         }
      }
     
      assertNotNull(controlConnectionThreadClass);
      assertEquals(t.getClass(), controlConnectionThreadClass);
      field = controlConnectionThreadClass.getDeclaredField("controlSocket");
      field.setAccessible(true);
      Socket controlSocket = (Socket) field.get(t);
      assertNotNull(controlSocket);
      controlSocket.close();
      log.info("CLOSED CONTROL SOCKET");
     
      // Shut down the only existing ServerThread on the server side, and therefore
      // the only existing pooled connection on the client side, forcing the
      // next invocation to depend on the creation of a new control connection.
      field = SocketServerInvoker.class.getDeclaredField("clientpool");
      field.setAccessible(true);
      ServerInvoker serverInvoker = connector.getServerInvoker();
      assertTrue(serverInvoker instanceof BisocketServerInvoker);
      LRUPool clientpool = (LRUPool) field.get(serverInvoker);
      Set serverThreads = clientpool.getContents();
      assertEquals(1, serverThreads.size());
      ((ServerThread)serverThreads.iterator().next()).shutdown();
      HashMap metadata = new HashMap();
      metadata.put(COUNTER, new Integer(0));
      client.invoke(INVOCATION_TEST, metadata);
     
      field = controlConnectionThreadClass.getDeclaredField("MAX_INITIAL_ATTEMPTS");
      field.setAccessible(true);
      int MAX_INITIAL_ATTEMPTS = ((Integer) field.get(null)).intValue();
     
      Thread.sleep(TEST_PING_FREQUENCY * MAX_INITIAL_ATTEMPTS);
      log.info("**********************  EXCEPTION EXPECTED ****************************");
      client.invoke(CALLBACK_TEST);
      log.info("***********************************************************************");
      // Callback should not be possible because contol connection is disabled.
      assertEquals(0, callbackHandler.callbackCounter);
     
      Thread.sleep(TEST_PING_FREQUENCY * MAX_INITIAL_ATTEMPTS);
      client.invoke(CALLBACK_TEST);
      // Callback should be possible because control connection has been replaced.
      assertEquals(1, callbackHandler.callbackCounter);
     
      client.removeListener(callbackHandler);
      client.disconnect();
   }
View Full Code Here

      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");
     
      Iterator it = invocationHandler.callbackHandlers.iterator();
      ServerInvokerCallbackHandler serverInvokerCallbackHandler = (ServerInvokerCallbackHandler) it.next();
      Client callbackClient = serverInvokerCallbackHandler.getCallbackClient();
      assertTrue(callbackClient.getInvoker() instanceof BisocketClientInvoker);
      MicroSocketClientInvoker clientInvoker = (MicroSocketClientInvoker) callbackClient.getInvoker();
      Field field = BisocketClientInvoker.class.getDeclaredField("controlSocket");
      field.setAccessible(true);
      Socket controlSocketBefore = (Socket) field.get(clientInvoker);

      Thread.sleep(4 * TEST_PING_FREQUENCY);
 
View Full Code Here

      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);
     
      // Wait until a failure has been detected on the control connection.
      Thread.sleep(TEST_PING_FREQUENCY * 5);
     
      // 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

TOP

Related Classes of org.jboss.remoting.Client

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.