Package org.jboss.remoting.transport.socket

Examples of org.jboss.remoting.transport.socket.LRUPool


      }
     
      // Test worker threads priority.
      field = SocketServerInvoker.class.getDeclaredField("clientpool");
      field.setAccessible(true);
      LRUPool clientpool = (LRUPool) field.get((SocketServerInvoker) connector.getServerInvoker());
      Iterator it = clientpool.getContents().iterator();
      while (it.hasNext())
      {
         Thread t = (Thread) it.next();
         log.info(t + " priority: " + t.getPriority());
         assertEquals(Thread.NORM_PRIORITY, t.getPriority());
View Full Code Here


      }
     
      // Test worker threads priority.
      field = SocketServerInvoker.class.getDeclaredField("clientpool");
      field.setAccessible(true);
      LRUPool clientpool = (LRUPool) field.get((SocketServerInvoker) connector.getServerInvoker());
      Iterator it = clientpool.getContents().iterator();
      while (it.hasNext())
      {
         Thread t = (Thread) it.next();
         log.info(t + " priority: " + t.getPriority());
         assertEquals(Thread.NORM_PRIORITY, t.getPriority());
View Full Code Here

      // Get clientpool from server.
      assertTrue(connector.getServerInvoker() instanceof SocketServerInvoker);
      SocketServerInvoker serverInvoker = (SocketServerInvoker) connector.getServerInvoker();
      Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
      field.setAccessible(true);
      LRUPool clientpool = (LRUPool) field.get(serverInvoker);
      assertEquals(2, clientpool.size());
     
      // Now make another invocation that with a Client with a
      // separate connection pool.  It will create a new connection,
      // which will require an eviction from the clientpool.
      String newLocatorURI = locatorURI + "/?timeout=10000";
      InvokerLocator clientLocator2 = new InvokerLocator(newLocatorURI);
      HashMap clientConfig2 = new HashMap();
      clientConfig2.put(InvokerLocator.FORCE_REMOTE, "true");
      addExtraClientConfig(clientConfig2);
      Client client2 = new Client(clientLocator2, clientConfig2);
      client2.connect();
      ConnectThread ct3 = new ConnectThread(client2, 0, "ct3");
      ct3.start();
     
      // Verify that eviction succeeded.
      Thread.sleep(2000);
      assertTrue(ct3.ok);
     
      // Verify that clientpool is the same, i.e., that a ServerThread
      // was reused.
      LRUPool newClientpool = (LRUPool) field.get(serverInvoker);
      assertEquals(clientpool, newClientpool);

      client1.disconnect();
      client2.disconnect();
      shutdownServer();
View Full Code Here

      // Get clientpool from server.
      assertTrue(connector.getServerInvoker() instanceof SocketServerInvoker);
      SocketServerInvoker serverInvoker = (SocketServerInvoker) connector.getServerInvoker();
      Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
      field.setAccessible(true);
      LRUPool clientpool = (LRUPool) field.get(serverInvoker);
      assertEquals(2, clientpool.size());
     
      // Now make another invocation that with a Client with a
      // separate connection pool.  It will create a new connection,
      // which will require an eviction from the clientpool.
      String newLocatorURI = locatorURI + "/?timeout=10000";
      InvokerLocator clientLocator2 = new InvokerLocator(newLocatorURI);
      HashMap clientConfig2 = new HashMap();
      clientConfig2.put(InvokerLocator.FORCE_REMOTE, "true");
      clientConfig2.put(SocketServerInvoker.CHECK_CONNECTION_KEY, "true");
      addExtraClientConfig(clientConfig2);
      Client client2 = new Client(clientLocator2, clientConfig2);
      client2.connect();
      ConnectThread ct3 = new ConnectThread(client2, 0, "ct3");
      ct3.start();
     
      // Verify that eviction succeeded.
      Thread.sleep(2000);
      assertTrue(ct3.ok);
     
      // Verify that clientpool is the same, i.e., that a ServerThread
      // was reused.
      LRUPool newClientpool = (LRUPool) field.get(serverInvoker);
      assertEquals(clientpool, newClientpool);

      client1.disconnect();
      client2.disconnect();
      shutdownServer();
View Full Code Here

      // Get clientpool from server.
      assertTrue(connector.getServerInvoker() instanceof SocketServerInvoker);
      SocketServerInvoker serverInvoker = (SocketServerInvoker) connector.getServerInvoker();
      Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
      field.setAccessible(true);
      LRUPool clientpool = (LRUPool) field.get(serverInvoker);
      assertEquals(2, clientpool.size());
     
      // Now make another invocation that with a Client with a
      // separate connection pool.  It will create a new connection,
      // which will require an eviction from the clientpool.
      String newLocatorURI = locatorURI + "/?timeout=10000";
      InvokerLocator clientLocator2 = new InvokerLocator(newLocatorURI);
      HashMap clientConfig2 = new HashMap();
      clientConfig2.put(InvokerLocator.FORCE_REMOTE, "true");
      clientConfig2.put(SocketServerInvoker.CHECK_CONNECTION_KEY, "true");
      addExtraClientConfig(clientConfig2);
      Client client2 = new Client(clientLocator2, clientConfig2);
      client2.connect();
      ConnectThread ct3 = new ConnectThread(client2, 0, "ct3");
      ct3.start();
     
      // Verify that eviction succeeded.
      Thread.sleep(2000);
      assertTrue(ct3.ok);
     
      // Verify that clientpool is the same, i.e., that a ServerThread
      // was reused.
      LRUPool newClientpool = (LRUPool) field.get(serverInvoker);
      assertEquals(clientpool, newClientpool);

      client1.disconnect();
      client2.disconnect();
      shutdownServer();
View Full Code Here

      // Get clientpool from server.
      assertTrue(connector.getServerInvoker() instanceof SocketServerInvoker);
      SocketServerInvoker serverInvoker = (SocketServerInvoker) connector.getServerInvoker();
      Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
      field.setAccessible(true);
      LRUPool clientpool = (LRUPool) field.get(serverInvoker);
     
      // Use up server's threadpool.
      ConnectThread ct1 = new ConnectThread(client, 16000, "ct1");
      ConnectThread ct2 = new ConnectThread(client, 16000, "ct2");
      ConnectThread ct3 = new ConnectThread(client, 16000, "ct3");
      ConnectThread ct4 = new ConnectThread(client, 0, "ct4");
      ct1.start();
      Thread.sleep(2000); // +2000
      List threads = clientpool.getContentsByAscendingAge();
      assertEquals(1, threads.size());
      Thread thread0 = (Thread) threads.get(0);
     
      ct2.start();
      Thread.sleep(2000); // +4000
      threads = clientpool.getContentsByAscendingAge();
      assertEquals(2, threads.size());
      assertEquals(thread0, threads.get(1));
      Thread thread1 = (Thread) threads.get(0);
     
      ct3.start();
      Thread.sleep(2000); // +6000
      ct4.start();
      Thread.sleep(2000); // +8000
      threads = clientpool.getContentsByAscendingAge();
      assertEquals(4, threads.size());
      assertEquals(thread0, threads.get(3));
      assertEquals(thread1, threads.get(2));
      Thread thread2 = (Thread) threads.get(1);
     
      // Verify newest thread gets evicted.
      Thread.sleep(4000); // +12000
      clientpool.evict();
      Thread.sleep(2000); // +14000
      threads = clientpool.getContentsByAscendingAge();
      assertEquals(3, threads.size());
      assertEquals(thread0, threads.get(2));
      assertEquals(thread1, threads.get(1));
      assertEquals(thread2, threads.get(0));
     
      // Verify none of the other threads is ready to be evicted.
      clientpool.evict();
      threads = clientpool.getContentsByAscendingAge();
      assertEquals(3, threads.size());
      assertEquals(thread0, threads.get(2));
      assertEquals(thread1, threads.get(1));
      assertEquals(thread2, threads.get(0));
     
      // Wait until all of the threads are done and verify that
      // the oldest one gets evicted first.
      Thread.sleep(12000); // +26000
      threads = clientpool.getContentsByAscendingAge();
      assertEquals(2, threads.size());
      assertEquals(thread1, threads.get(1));
      assertEquals(thread2, threads.get(0));
     
      clientpool.evict();
      Thread.sleep(2000); // +29000
      threads = clientpool.getContentsByAscendingAge();
      assertEquals(1, threads.size());
      assertEquals(thread2, threads.get(0));
     
      clientpool.evict();
      Thread.sleep(2000); // +30000
      threads = clientpool.getContentsByAscendingAge();
      assertEquals(0, threads.size());
     
      client.disconnect();
      shutdownServer();
      log.info(getName() + " PASSES");
View Full Code Here

     
      // Get ServerThread.
      SocketServerInvoker invoker = (SocketServerInvoker) connector.getServerInvoker();
      Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
      field.setAccessible(true);
      LRUPool clientpool = (LRUPool) field.get(invoker);
      assertEquals(1, clientpool.size());
      Set s =  clientpool.getContents();
      ServerThread serverThread1 = (ServerThread) s.iterator().next();
     
      // Get threadpool.
      field = SocketServerInvoker.class.getDeclaredField("threadpool");
      field.setAccessible(true);
      LinkedList threadpool = (LinkedList) field.get(invoker);
      assertEquals(0, threadpool.size());
     
      // Wait for ServerThread to time out.
      Thread.sleep(6000);
      for (int i = 0; i < 5; i++)
      {
         Thread.sleep(2000);
         if (clientpool.size() == 0) break;
      }
     
      if (clientpool.size() > 0)
      {
         fail("expect clientpool.size() == 0");
      }
     
      // Verify original ServerThread was returned to threadpool.
      assertEquals(1, threadpool.size());
      assertEquals(serverThread1, threadpool.iterator().next());
     
      // Make another invocation and verify ServerThread was reused.
      client.invoke("xyz");
      assertEquals(1, clientpool.size());
      s =  clientpool.getContents();
      ServerThread serverThread2 = (ServerThread) s.iterator().next();
      assertEquals(serverThread1, serverThread2);
     
      client.disconnect();
      shutdownServer();
View Full Code Here

     
      // Get clientpool and ServerThread.
      SocketServerInvoker invoker = (SocketServerInvoker) connector.getServerInvoker();
      Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
      field.setAccessible(true);
      LRUPool clientpool = (LRUPool) field.get(invoker);
      assertEquals(1, clientpool.size());
      Set clientpoolContents =  clientpool.getContents();
      ServerThread serverThread1 = (ServerThread) clientpoolContents.iterator().next();
     
      // Get threadpool.
      field = SocketServerInvoker.class.getDeclaredField("threadpool");
      field.setAccessible(true);
      LinkedList threadpool = (LinkedList) field.get(invoker);
      assertEquals(0, threadpool.size());
     
      // Wait for ServerThread to time out.
      Thread.sleep(8000);
     
      // Verify original ServerThread remains in clientpool.
      assertEquals(0, threadpool.size());
      assertEquals(1, clientpool.size());
      clientpoolContents =  clientpool.getContents();
      assertEquals(serverThread1, clientpoolContents.iterator().next());
     
      // Make another invocation and verify ServerThread was reused.
      client.invoke("xyz");
      assertEquals(1, clientpool.size());
      clientpoolContents =  clientpool.getContents();
      ServerThread serverThread2 = (ServerThread) clientpoolContents.iterator().next();
      assertEquals(serverThread1, serverThread2);
     
      client.disconnect();
      shutdownServer();
View Full Code Here

         SocketServerInvoker invoker = (SocketServerInvoker) connector.getServerInvoker();
         Field clientpoolField = SocketServerInvoker.class.getDeclaredField("clientpool");
         clientpoolField.setAccessible(true);
         Field socketWrapperField = ServerThread.class.getDeclaredField("socketWrapper");
         socketWrapperField.setAccessible(true);
         LRUPool clientpool = (LRUPool) clientpoolField.get(invoker);
         Set threads = clientpool.getContents();
         threads = new HashSet(threads);
         log.info("NUMBER of SERVER THREADS: " + threads.size());
         Iterator it = threads.iterator();
         while (it.hasNext())
         {
View Full Code Here

      Field field = SocketServerInvoker.class.getDeclaredField("threadpool");
      field.setAccessible(true);
      List threadpool = (List) field.get(invoker);
      field = SocketServerInvoker.class.getDeclaredField("clientpool");
      field.setAccessible(true);
      LRUPool clientpool = (LRUPool) field.get(invoker);
      assertEquals(0, threadpool.size());
      assertEquals(1, clientpool.size());
     
      // Kill worker thread's socket.
      Set clientpoolContents = clientpool.getContents();
      ServerThread serverThread1 = (ServerThread) clientpoolContents.iterator().next();
      field = ServerThread.class.getDeclaredField("socket");
      field.setAccessible(true);
      Socket socket = (Socket) field.get(serverThread1);
      socket.close();
      Thread.sleep(4000);
      assertEquals(1, threadpool.size());
      assertEquals(0, clientpool.size());
     
      // Make second callback and verify that worker thread gets reused.
      client.invoke("callback");
      assertEquals(2, callbackHandler.counter);
      log.info("second callback successful");
      assertEquals(0, threadpool.size());
      assertEquals(1, clientpool.size());
      clientpoolContents = clientpool.getContents();
      ServerThread serverThread2 = (ServerThread) clientpoolContents.iterator().next();
      assertEquals(serverThread2, serverThread1);
      log.info("ServerThread was reused");
     
      client.removeListener(callbackHandler);
View Full Code Here

TOP

Related Classes of org.jboss.remoting.transport.socket.LRUPool

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.