Examples of Latch


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

      final LatchHolder startSignal;

      // Register the return value / Exception listener ...
      if (expectingResponse) {
         //startSignal = new Latch(); // defaults to false
         startSignal = addLatch(new Latch()); //synchronized (this.latchSet) { this.latchSet.add(startSignal); } // remember all blocking threads for release on shutdown
         if (!hasConnection()) return null;
         addResponseListener(requestId, new I_ResponseListener() {
            public void incomingMessage(String reqId, Object responseObj) {
               if (log.isLoggable(Level.FINE)) log.fine("RequestId=" + reqId + ": return value arrived ...");
               response[0] = responseObj;
View Full Code Here

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

   public void testReceiveOnClose() throws Exception
   {
      if (log.isTraceEnabled()) log.trace("testReceiveOnClose");
      consumerConnection.start();
      final Latch latch = new Latch();
      Thread closerThread = new Thread(new Runnable()
      {
         public void run()
         {
            try
            {
               // this is needed to make sure the main thread has enough time to block
               Thread.sleep(1000);
               topicConsumer.close();
            }
            catch(Exception e)
            {
               log.error(e);
            }
            finally
            {
               latch.release();
            }
         }
      }, "closing thread");
      closerThread.start();

      assertNull(topicConsumer.receive(3000));

      // wait for the closing thread to finish
      latch.acquire();
   }
View Full Code Here

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

      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

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

        
         MessageProducer prod = sess.createProducer(queue);
        
         MessageConsumer cons = sess2.createConsumer(queue);
        
         Latch latch = new Latch();
        
         final int NUM_MESSAGES = 2000;
                 
         MyListener listener = new MyListener(latch, NUM_MESSAGES);
        
         cons.setMessageListener(listener);
        
         conn.start();
        
         for (int i = 0; i < NUM_MESSAGES; i++)
         {
            TextMessage tm = sess.createTextMessage("message" + i);
           
            prod.send(tm);
           
            if (i % 10 == 0)
            {
               sess.commit();
            }
         }

         // need extra commit for cases in which the last message index is not a multiple of 10
         sess.commit();

         latch.acquire();
        
         if (listener.failed)
         {
            fail("listener failed: " + listener.getError());
         }
View Full Code Here

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

     
      // 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

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

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

      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

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

* */
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

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

* */
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

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

                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
TOP
Copyright © 2018 www.massapi.com. 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.