Package org.jboss.remoting.transport

Examples of org.jboss.remoting.transport.Connector


      String locatorURI = "socket://" + host + ":" + port;
      InvokerLocator locator = new InvokerLocator(locatorURI);
      HashMap serverConfig = new HashMap();
      serverConfig.put(ServerInvoker.MAX_NUM_ONEWAY_THREADS_KEY, "2");
      serverConfig.put(ServerInvoker.MAX_ONEWAY_THREAD_POOL_QUEUE_SIZE, "1");
      Connector connector = new Connector(locator, serverConfig);
      connector.create();
      TestHandler handler = new TestHandler();
      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


      String locatorURI = "http://" + host + ":" + port;
      InvokerLocator locator = new InvokerLocator(locatorURI);
      HashMap serverConfig = new HashMap();
      serverConfig.put(ServerInvoker.MAX_NUM_ONEWAY_THREADS_KEY, "100");
      serverConfig.put(ServerInvoker.MAX_ONEWAY_THREAD_POOL_QUEUE_SIZE, "100");
      Connector connector = new Connector(locator);
      connector.create();
      TestHandler handler = new TestHandler();
      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

   public void testCallbacks() throws Throwable
   {

      // Start the callback server
      InvokerLocator callbackServerLocator = new InvokerLocator("socket://localhost:2222");
      Connector callbackConnector = new Connector();
      callbackConnector.setInvokerLocator(callbackServerLocator.getLocatorURI());
      callbackConnector.start();

      // Start the target server
      InvokerLocator targetServerLocator = new InvokerLocator("socket://localhost:3456");
      Connector connector = new Connector();
      connector.setInvokerLocator(targetServerLocator.getLocatorURI());
      connector.create();
      connector.addInvocationHandler("MySubsystem", new ServerInvocationHandlerImpl());
      connector.start();


      Client client = new Client(targetServerLocator);
      client.connect();

      InvokerCallbackHandler callbackHandler1 = new InvokerCallbackHandlerImpl("ONE");
      InvokerCallbackHandler callbackHandler2 = new InvokerCallbackHandlerImpl("TWO");

      client.addListener(callbackHandler1, callbackServerLocator);

      client.invoke("call back " + value1);

      assertEquals(1, callbacks.size());
      callbacks.clear();

      client.addListener(callbackHandler2, callbackServerLocator);

      client.invoke("call back " + value2);

      assertEquals(2, callbacks.size());
      callbacks.clear();

      client.removeListener(callbackHandler1);

      client.invoke("call back " + value3);

      assertEquals(1, callbacks.size());
      callbacks.clear();

      client.removeListener(callbackHandler2);

      connector.stop();
      callbackConnector.stop();

      connector.destroy();
      callbackConnector.destroy();
   }
View Full Code Here

      String locatorURI = "socket://" + host + ":" + port;
      InvokerLocator locator = new InvokerLocator(locatorURI);
      HashMap serverConfig = new HashMap();
      serverConfig.put(ServerInvoker.MAX_NUM_ONEWAY_THREADS_KEY, "100");
      serverConfig.put(ServerInvoker.MAX_ONEWAY_THREAD_POOL_QUEUE_SIZE, "100");
      Connector connector = new Connector(locator, serverConfig);
      connector.create();
      TestHandler handler = new TestHandler();
      connector.addInvocationHandler("test", handler);
      connector.start();
     
      HashMap clientConfig = new HashMap();
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
      Client client = new Client(locator, clientConfig);
      client.connect();
     
      int INVOCATIONS = 1000;
      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(10000);
     
      // Verify INVOCATION invocations were received.
      assertEquals(INVOCATIONS, handler.startedCount);
     
      for (int i = 0; i < INVOCATIONS; i++)
      {
         assertTrue("failure in thread: " + i, threads[i].ok);
      }
     
      // Verify only one thread pool was created.
      Field field = ServerInvoker.class.getDeclaredField("onewayThreadPool");
      field.setAccessible(true);
      Object pool = field.get(connector.getServerInvoker());
      assertTrue(pool instanceof BasicThreadPool);
      BasicThreadPool basicThreadPool = (BasicThreadPool) pool;
      assertEquals(poolCounter, basicThreadPool.getPoolNumber());
     
      client.disconnect();
      connector.stop();
      log.info(getName() + " PASSES");
   }
View Full Code Here

      serverLocator = new InvokerLocator(locatorURI);
      log.info("Starting remoting server with locator uri of: " + locatorURI);
      HashMap config = new HashMap();
      config.put(InvokerLocator.FORCE_REMOTE, "true");
      addExtraServerConfig(config);
      connector = new Connector(serverLocator, config);
      connector.create();
      invocationHandler = new TestInvocationHandler();
      connector.addInvocationHandler("test", invocationHandler);
      connector.start();
   }
View Full Code Here

      String locatorURI = getTransport() + "://" + host + ":" + port;
      InvokerLocator locator = new InvokerLocator(locatorURI);
      HashMap serverConfig = new HashMap();
      serverConfig.put(InvokerLocator.FORCE_REMOTE, "true");
      addExtraServerConfig(serverConfig);
      Connector connector = new Connector(locator, serverConfig);
      connector.create();
      connector.addInvocationHandler("test", new TestHandler());
      connector.start();
     
      HashMap clientConfig = new HashMap();
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
      addExtraClientConfig(clientConfig);
      Client client = new Client(locator, clientConfig);
      client.connect();
      TestCallbackHandler callbackHandler = new TestCallbackHandler();
      client.addListener(callbackHandler, null, null, true);
     
      Object response = client.invoke(INVOKE);
      assertEquals(INVOKE, response);
      log.info("invocation succeeded");

      client.invoke(CALLBACK);
      assertTrue(callbackHandler.receivedCallback);
      log.info("received first callback");
     
      Thread.sleep(ServerInvoker.DEFAULT_TIMEOUT_PERIOD + 5000);

      callbackHandler.receivedCallback = false;
      client.invoke(CALLBACK);
      assertTrue(callbackHandler.receivedCallback);
      log.info("received second callback");
     
      client.disconnect();
      connector.stop();
      log.info(getName() + " PASSES");
   }
View Full Code Here

     
      // Connection checking is no longer necessary since ClientSocketWrapper
      // implements OpenConnectionChecker.
//      serverConfig.put(SocketServerInvoker.CHECK_CONNECTION_KEY, "true");
      addExtraServerConfig(serverConfig);
      Connector connector = new Connector(locator, serverConfig);
      connector.create();
      connector.addInvocationHandler("test", new TestHandler());
      connector.start();
     
      HashMap clientConfig = new HashMap();
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
//      clientConfig.put(SocketServerInvoker.CHECK_CONNECTION_KEY, "true");
      clientConfig.put(SocketClientInvoker.SO_TIMEOUT_FLAG, "1000");
      addExtraClientConfig(clientConfig);
      Client client = new Client(locator, clientConfig);
      client.connect();
      TestCallbackHandler callbackHandler = new TestCallbackHandler();
      client.addListener(callbackHandler, null, null, true);
     
      Object response = client.invoke(INVOKE);
      assertEquals(INVOKE, response);
      log.info("invocation succeeded");

      client.invoke(CALLBACK_ONEWAY);
      Thread.sleep(1000);
      assertTrue(callbackHandler.receivedCallback);
      log.info("received first callback");
     
      Thread.sleep(ServerInvoker.DEFAULT_TIMEOUT_PERIOD + 5000);

      log.info("waking up");
      callbackHandler.receivedCallback = false;
      client.invoke(CALLBACK_ONEWAY);
      log.info("sent second invocation");
      Thread.sleep(1000);
      assertTrue(callbackHandler.receivedCallback);
      log.info("received second callback");
     
      client.disconnect();
      connector.stop();
      log.info(getName() + " PASSES");
   }
View Full Code Here

      int port = PortUtil.findFreePort(host);
      String locatorURI = getTransport() + "://" + host + ":" + port;
      InvokerLocator locator = new InvokerLocator(locatorURI);
      HashMap serverConfig = new HashMap();
      addServerConfig(serverConfig);
      final Connector connector = new Connector(locator, serverConfig);
      connector.create();
      connector.addInvocationHandler("test", new TestHandler());
      connector.start();
     
      // Disable the server so that the client will need to create a new socket, and
      // so that the creation of the socket wrapper will fail.
      new Thread()
      {
         public void run()
         {
            try
            {
               // Give the client a chance to connect to the server, then
               // disable the server.
               Thread.sleep(2000);
               ServerInvoker si = connector.getServerInvoker();
               assertTrue(si instanceof SocketServerInvoker);
               SocketServerInvoker ssi = (SocketServerInvoker) si;
               Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
               field.setAccessible(true);
               LRUPool clientpool = (LRUPool) field.get(ssi);
               Set threads = clientpool.getContents();
               Iterator it = threads.iterator();
               while (it.hasNext())
               {
                  ServerThread t = (ServerThread) it.next();
                  t.shutdown();
               }

               ssi.setMaxPoolSize(0);
               log.info("server is disabled");
            }
            catch (Exception e)
            {
               log.info(e);
            }
         }
      }.start();

      HashMap clientConfig = new HashMap();
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
      clientConfig.put(ServerInvoker.TIMEOUT, "20000");
      clientConfig.put(Client.ENABLE_LEASE, "true");
      addClientConfig(clientConfig);
      final Client client = new Client(locator, clientConfig);
      client.connect();
      Object response = client.invoke("test 1");
      assertEquals("test 1", response);
     
      class BooleanHolder {public boolean value;}
      final BooleanHolder timedOut = new BooleanHolder();
      timedOut.value = false;
     
      new Thread()
      {
         public void run()
         {
            try
            {
               // Wait for the server to be disabled.
               Thread.sleep(4000);
              
               // This invocation will cause the ServerThread to shut down.
               client.invoke("test 2");
               log.debug("calling client.disconnect()");
              
               // This invocation will require the creation of a new socket, which
               // should promptly time out.
               HashMap metadata = new HashMap();
               metadata.put(ServerInvoker.TIMEOUT, "1000");
               client.invoke("test 3", metadata);
               fail("failed to time out");
            }
            catch (Throwable e)
            {
               timedOut.value = true;
               log.info("time out", e);
            }
         }
      }.start();
     
      // It should take the Client a little while for LeasePinger's attempts to contact
      // the server to time out.  Wait for 4 seconds after the call to Client.invoke()
      // and then verify that the Client has timed out according to the temporary timeout
      // value 1000 instead of the configureed value 20000.
      Thread.sleep(8000);
      assertTrue(timedOut.value);
     
      client.disconnect();
      connector.stop();
      log.info(getName() + " PASSES");
   }
View Full Code Here

      serverLocator = new InvokerLocator(locatorURI);
      log.info("Starting remoting server with locator uri of: " + locatorURI);
      HashMap config = new HashMap();
      config.put(InvokerLocator.FORCE_REMOTE, "true");
      addExtraServerConfig(config);
      connector = new Connector(serverLocator, config);
      connector.create();
      invocationHandler = new TestInvocationHandler();
      connector.addInvocationHandler("test", invocationHandler);
      connector.start();
   }
View Full Code Here

      log.info("Starting remoting server with locator uri of: " + locatorURI);
      HashMap config = new HashMap();
      config.put(InvokerLocator.FORCE_REMOTE, "true");
      config.put("clientLeasePeriod", "1000");
      addExtraServerConfig(config);
      connector = new Connector(serverLocator, config);
      connector.create();
      invocationHandler = new TestInvocationHandler();
      connector.addInvocationHandler("test", invocationHandler);
      connector.addConnectionListener(new TestConnectionListener());
      connector.start();
View Full Code Here

TOP

Related Classes of org.jboss.remoting.transport.Connector

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.