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

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


                        && !readLockMap.hasDependency(changeLog)) {
                    activeWriter = new WriteLockImpl(changeLog);
                    activeWriterId = getCurrentThreadId();
                    return activeWriter;
                } else {
                    signal = new Latch();
                    waitingWriters.add(signal);
                }
            } finally {
                exclusive.release();
            }
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

                        || !hasDependency(activeWriter.changes, id)) {
                    readerCount.incrementAndGet();
                    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);
                    activeWriterId = getCurrentThreadId();
                    return activeWriter;
                } else {
                    signal = new Latch();
                    waitingWriters.add(signal);
                }
            } finally {
                exclusive.release();
            }
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

* */
public class SyncWorkExecutor implements WorkExecutor {

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

* */
public class StartWorkExecutor implements WorkExecutor {

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

        ActiveMQActivationSpec as = new ActiveMQActivationSpec();
        as.setDestination("TEST");
        as.setDestinationType(Queue.class.getName());
            ActivationSpecWrapper asWrapper = new ActivationSpecWrapper(as, raWrapper);

        final Latch messageDelivered = new Latch();
        MessageEndpointFactory messageEndpointFactory = new MessageEndpointFactory() {
            public MessageEndpoint createEndpoint(XAResource resource) throws UnavailableException {
                return new StubMessageEndpoint(etm, resource) {
                    public void onMessage(Message message) {
                        super.onMessage(message);
                        messageDelivered.release();
                    }

                    ;
                };
            }

            public boolean isDeliveryTransacted(Method method) throws NoSuchMethodException {
                return true;
            }
        };

        asWrapper.activate(messageEndpointFactory);

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(new ActiveMQQueue("TEST"));
        producer.send(session.createTextMessage("Hello"));

        assertTrue(messageDelivered.attempt(1000 * 5));
    }
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

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.