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

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


    public void setStoppedRoutingTimeout(long stoppedRoutingTimeout) {
        this.stoppedRoutingTimeout = stoppedRoutingTimeout;
    }

    private Sync createNewRouterLock() {
        Latch lock = new Latch();
        return new TimeoutSync(lock, stoppedRoutingTimeout);
    }
View Full Code Here


    }

    public Protocol cloneProtocol() throws CloneNotSupportedException {
        GSSAPIServerProtocol result = (GSSAPIServerProtocol) super.clone();

        result.startupLatch = new Latch();
        try {
            GSSManager manager = GSSManager.getInstance();
            result.context = manager.createContext((GSSCredential) null);
            result.context.requestMutualAuth(mutualAuth);
            result.context.requestConf(confidential);
View Full Code Here

     
      // Delivery is asynch - need to give enough time to get to the consumer
      Thread.sleep(2000);

      // start the receiver thread
      final Latch latch = new Latch();
      Thread receiverThread = new Thread(new Runnable()
      {
         public void run()
         {
            try
            {
               expectedMessage = queueConsumer.receive(100);
            }
            catch(Exception e)
            {
               log.trace("receive() exits with an exception", e);
            }
            finally
            {
               latch.release();
            }
         }
      }, "receiver thread");
      receiverThread.start();

      latch.acquire();
      assertNull(expectedMessage);
   }
View Full Code Here

   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);
               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

 
        conn.start();
 
        final List received = new ArrayList();
        final List received2 = new ArrayList();
        final Latch latch = new Latch();
        final Latch latch2 = new Latch();
 
        new Thread(new Runnable()
        {
           public void run()
           {
              try
              {
                 while(true)
                 {
                    Message m = c.receive(1000);
                    if (m != null)
                    {
                       received.add(m);
                    }
                    else
                    {
                       latch.release();
                       return;
                    }
                 }
              }
              catch(Exception e)
              {
                 log.error("receive failed", e);
              }
           }
        }, "consumer thread 1").start();
 
        new Thread(new Runnable()
        {
           public void run()
           {
              try
              {
                 while(true)
                 {
                    Message m = c2.receive(1000);
                    if (m != null)
                    {
                       received2.add(m);
                    }
                    else
                    {
                       latch2.release();
                       return;
                    }
                 }
              }
              catch(Exception e)
              {
                 log.error("receive failed", e);
              }
           }
        }, "consumer thread 2").start();
 
        latch.acquire();
        latch2.acquire();
 
        assertEquals(5, received.size());
        for(Iterator i = received.iterator(); i.hasNext(); )
        {
           Message m = (Message)i.next();
View Full Code Here

            return null;
        }
    }

    public void setUp() throws Exception {
        startLatch = new Latch();
        shutdownLatch = new Latch();
        stopLatch = new Latch();
        try {
            properties = new Properties();
            try {
                properties.load(new File(System.getProperty("user.home") + "/login.properties").toURI().toURL().openStream());
            } catch (IOException e) {
View Full Code Here

    }

    public Protocol cloneProtocol() throws CloneNotSupportedException {
        GSSAPIServerProtocol result = (GSSAPIServerProtocol) super.clone();

        result.startupLatch = new Latch();
        try {
            GSSManager manager = GSSManager.getInstance();
            result.context = manager.createContext((GSSCredential) null);
            result.context.requestMutualAuth(mutualAuth);
            result.context.requestConf(confidential);
View Full Code Here

    public void setStoppedRoutingTimeout(long stoppedRoutingTimeout) {
        this.stoppedRoutingTimeout = stoppedRoutingTimeout;
    }

    private Sync createNewRouterLock() {
        Latch lock = new Latch();
        return new TimeoutSync(lock, stoppedRoutingTimeout);
    }
View Full Code Here

    /**
   * @see org.apache.geronimo.network.protocol.ProtocolStack#cloneProtocol()
   */
  public Protocol cloneProtocol() throws CloneNotSupportedException {
    ControlClientProtocolKitchen p = (ControlClientProtocolKitchen) super.cloneProtocol();
    p.sendLatch = new Latch();
    return p;
  }
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.