Package EDU.oswego.cs.dl.util.concurrent

Examples of EDU.oswego.cs.dl.util.concurrent.Latch


   public void testReceiveTimeoutPreservation() throws Exception
   {
      final long timeToWaitForReceive = 5000;

      final Latch receiverLatch = new Latch();

      // start the receiver thread
      Thread receiverThread = new Thread(new Runnable()
      {
         public void run()
         {
            try
            {
               long t1 = System.currentTimeMillis();
               expectedMessage = queueConsumer.receive(timeToWaitForReceive);
               //Thread.sleep(10);
               effectiveReceiveTime = System.currentTimeMillis() - t1;
            }
            catch(Exception e)
            {
               log.trace("receive() exits with an exception", e);
            }
            finally
            {
               receiverLatch.release();
            }
         }
      }, "receiver thread");
      receiverThread.start();

      final Latch senderLatch = new Latch();

      // start the sender thread
      Thread senderThread = new Thread(new Runnable()
      {
         public void run()
         {
            try
            {
               // wait for 3 secs
               Thread.sleep(3000);

               // send an expired message
               Message m = queueProducerSession.createMessage();
               queueProducer.send(m, DeliveryMode.NON_PERSISTENT, 4, -1);

               JBossMessage jbm = ((MessageProxy)m).getMessage();
              
               if (!jbm.isExpired())
               {
                  log.error("The message " + m + " should have expired");
                  testFailed = true;
                  return;
               }
            }
            catch(Exception e)
            {
               log.error("This exception will fail the test", e);
               testFailed = true;
            }
            finally
            {
               senderLatch.release();
            }
         }
      }, "sender thread");
      senderThread.start();


      senderLatch.acquire();
      receiverLatch.acquire();

      if (testFailed)
      {
         fail("Test failed by the sender thread. Watch for exception in logs");
View Full Code Here


      Thread.sleep(3000);
     
      //When a consumer is closed while a receive() is in progress it will make the
      //receive return with null

      final Latch latch = new Latch();
      // blocking read for a while to make sure I don't get anything, not even a null
      Thread receiverThread = new Thread(new Runnable()
      {
         public void run()
         {
            try
            {
               log.trace("Attempting to receive");
               expectedMessage = queueConsumer.receive();
              
               //NOTE on close, the receive() call will return with null
               log.trace("Receive exited without exception:" + expectedMessage);
            }
            catch(Exception e)
            {
               log.trace("receive() exits with an exception", e);
               fail();
            }
            catch(Throwable t)
            {
               log.trace("receive() exits with an throwable", t);
               fail();
            }
            finally
            {
               latch.release();
            }
         }
      }, "receiver thread");
      receiverThread.start();

      Thread.sleep(3000);
      receiverThread.interrupt();

      // wait for the reading thread to conclude
      latch.acquire();

      log.trace("Expected message:" + expectedMessage);
     
      assertNull(expectedMessage);     
   }
View Full Code Here

     * Verifies that the client is notified when the server is shut down.
     *
     * @throws Exception for any error
     */
    public void testServerDisconnect() throws Exception {
        final Latch latch = new Latch();
        CallerListener listener = new CallerListener() {
            public void disconnected(Caller caller) {
                latch.release();
            }
        };
        ORB client = getClientORB();
        client.addCallerListener(getServerURI(), listener);

        ORB server = getORB();
        server.getRegistry();

        // get the registry proxy. This will establish a connection to the
        // server.
        Registry registry = getRegistry();
        assertNotNull(registry);

        server.shutdown();

        if (!latch.attempt(10 * 1000)) {
            fail("CallerListener not notified of disconnection");
        }
    }
View Full Code Here

     * Verifies that the server is notified when the client is shut down.
     *
     * @throws Exception for any error
     */
    public void testClientDisconnect() throws Exception {
        Latch latch = new Latch();
        ORB server = getORB();
        CallbackServer serviceImpl = new CallbackServer(server, latch);

        Proxy proxy = server.exportObject(serviceImpl);
        server.getRegistry().bind("service", proxy);

        ORB client = getClientORB();
        Registry registry = client.getRegistry(getConnectionProperties());
        CallbackService service = (CallbackService) registry.lookup("service");

        LoggingCallback callback = new LoggingCallback();
        Callback callbackProxy = (Callback) client.exportObjectTo(callback,
                                                                  getServerURI());
        service.addCallback(callbackProxy);

        assertNull(serviceImpl.getException());
        client.shutdown();

        if (!latch.attempt(10 * 1000)) {
            fail("CallerListener not notified of disconnection");
        }
        assertNull(serviceImpl.getException());
    }
View Full Code Here

     * through inactivity.
     *
     * @throws Exception for any error
     */
    public void testInactive() throws Exception {
        final Latch latch = new Latch();
        CallerListener listener = new CallerListener() {
            public void disconnected(Caller caller) {
                latch.release();
            }
        };

        ORB server = getORB();
        CallbackServer serviceImpl = new CallbackServer(server, latch);

        Proxy proxy = server.exportObject(serviceImpl);
        server.getRegistry().bind("service", proxy);

        ORB client = getClientORB();
        client.addCallerListener(getServerURI(), listener);

        Registry registry = getRegistry(); // will establish a connection
        assertNotNull(registry);
        CallbackService service = (CallbackService) registry.lookup("service");
        assertNotNull(service);

        // make sure the connection isn't reaped through inactivity
        // while there are proxies associated with it.
        for (int i = 0; i < 10; ++i) {
            Runtime.getRuntime().gc();
            if (latch.attempt(1000)) {
                break;
            }
        }
        if (latch.attempt(0)) {
            fail("Connection terminated when there were active proxies");
        }

        // clear registry proxy and ensure the connection isn't reaped.
        // Registry proxy is constructed differently to those serialized
        // over the wire.

        registry = null;
        for (int i = 0; i < 10; ++i) {
            Runtime.getRuntime().gc();
            if (latch.attempt(1000)) {
                break;
            }
        }
        if (latch.attempt(0)) {
            fail("Connection terminated when there were active proxies");
        }

        // clear proxy reference so the connection can be GC'ed
        service = null;

        // wait for the notification. Need to force the GC to run...
        for (int i = 0; i < 10; ++i) {
            Runtime.getRuntime().gc();
            if (latch.attempt(1000)) {
                break;
            }
        }
        if (!latch.attempt(0)) {
            fail("CallerListener not notified of disconnection");
        }
    }
View Full Code Here

         Session sessCons = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

         MessageConsumer cons = sessCons.createConsumer(queue[0]);

         Latch latch = new Latch();
        
         MyListener list = new MyListener(latch);

         cons.setMessageListener(list);
View Full Code Here

                if (activeWriter == null
                        || !hasDependency(activeWriter.changes, id)) {
                    readLockMap.addLock(id);
                    return new ReadLockImpl(id);
                } else {
                    signal = new Latch();
                    waitingReaders.add(signal);
                }
            } finally {
                shared.release();
            }
View Full Code Here

                        && !readLockMap.hasDependency(changeLog)) {
                    activeWriter = new WriteLockImpl(changeLog);
                    activeWriterThread = Thread.currentThread();
                    return activeWriter;
                } else {
                    signal = new Latch();
                    waitingWriters.add(signal);
                }
            } finally {
                exclusive.release();
            }
View Full Code Here

* */
public class SyncWorkExecutor implements WorkExecutor {

    public void doExecute(WorkerContext work, GeronimoExecutor executor)
            throws WorkException, InterruptedException {
        Latch latch = work.provideEndLatch();
        executor.execute("A J2EE Connector", work);
        latch.acquire();
    }
View Full Code Here

* */
public class StartWorkExecutor implements WorkExecutor {

    public void doExecute(WorkerContext work, GeronimoExecutor executor)
            throws WorkException, InterruptedException {
        Latch latch = work.provideStartLatch();
        executor.execute("A J2EE Connector", work);
        latch.acquire();
    }
View Full Code Here

TOP

Related Classes of EDU.oswego.cs.dl.util.concurrent.Latch

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.