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

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


   private void doConcurrentCreationTest(boolean prepopulateParent) throws Exception
   {
      if (prepopulateParent) cache.put("/parent/dummy", "k", "v");

      final List exceptions = new LinkedList();
      final Latch latch = new Latch();

      class ConcurrentCreator extends Thread
      {
         private String name;
         public ConcurrentCreator(String name)
         {
            this.name = name;
         }

         public void run()
         {
            try
            {
               cache.getTransactionManager().begin();
               cache.put("/parent/child" + name, "key", "value");
               latch.acquire();
               cache.getTransactionManager().commit();
            }
            catch (Exception e)
            {
               e.printStackTrace();
               exceptions.add(e);
            }
         }
      }

      Thread one = new ConcurrentCreator("one");
      Thread two = new ConcurrentCreator("two");

      one.start();
      two.start();

      latch.release();

      one.join();
      two.join();

      assertTrue("Should not have caught any exceptions!!", exceptions.isEmpty());
View Full Code Here


        this.sm = selectorManager;
        this.tp = threadPool;
        this.cp = clockPool;

        closed = new SynchronizedBoolean(false);
        startLatch = new Latch();

/*
        ControlServerProtocolStack templateStack = new ControlServerProtocolStack();
*/
        SocketProtocol spt = new SocketProtocol();
View Full Code Here

     */
    protected GTransportChannel(WireFormat wireFormat, ThreadPool tp) {
        this.wireFormat = wireFormat;
        closed = new SynchronizedBoolean(false);
        started = new SynchronizedBoolean(false);
        dispatchLatch = new Latch();
        threadPool = tp;
    }
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

        session.close();
        assertDemandChange(false, 2000);
    }

    public void assertDemandChange(final boolean value, long timeout) {
        final Latch change = new Latch();
        try {
            new Thread() {
                public void run() {
                    try {
                        inDemand.whenEqual(value, new Runnable() {
                            public void run() {
                                change.release();
                            }
                        });
                    } catch (InterruptedException e) {
                    }                   
                }
            }.start();
            assertTrue("Demand did not change to: "+value, change.attempt(timeout));
        } catch (InterruptedException e) {
            fail("Interuppted: "+e);
        }
    }
View Full Code Here

        synchChannelServer.dispose();
    }

    private void createAsynchObjects(String bindURI) throws IOException, URISyntaxException, InterruptedException {
        asynchChannelServer = factory.bindAsynchChannel(new URI(bindURI));
        final Latch accepted = new Latch();
        asynchChannelServer.setAcceptListener(new AcceptListener() {
            public void onAccept(Channel channel) {
                serverAsynchChannel = SynchToAsynchChannelAdapter.adapt(channel);
                channel.dispose();
                accepted.release();
            }
            public void onAcceptError(IOException error) {
                error.printStackTrace();
            }
        });
        asynchChannelServer.start();
        clientAsynchChannel = factory.openAsynchChannel(asynchChannelServer.getConnectURI());
        accepted.attempt(1000*10);
        clientAsynchChannel.dispose();       
        asynchChannelServer.dispose();
    }
View Full Code Here

           
            if( journal == null )
                throw new IllegalStateException("Journal is closed.");
           
            // Do the checkpoint asynchronously?
            Latch latch=null;
            if( sync ) {
                latch = new Latch();
                checkpointRequests.put(latch);
            } else {
                checkpointRequests.put(Boolean.TRUE);
            }
           
            checkpointExecutor.execute(new Runnable() {
                public void run() {

                    ArrayList listners = new ArrayList();
                   
                    try {
                        // Avoid running a checkpoint too many times in a row.
                        // Consume any queued up checkpoint requests.
                        try {
                            boolean requested = false;
                            Object t;
                            while ((t=checkpointRequests.poll(0)) != null) {
                                if( t.getClass()==Latch.class )
                                    listners.add(t);
                                requested = true;
                            }
                            if (!requested) {
                                return;
                            }
                        }
                        catch (InterruptedException e1) {
                            return;
                        }
   
                        log.debug("Checkpoint started.");
                        RecordLocation newMark = null;
   
                        Iterator iterator = messageStores.values().iterator();
                        while (iterator.hasNext()) {
                            try {
                                JournalMessageStore ms = (JournalMessageStore) iterator.next();
                                RecordLocation mark = ms.checkpoint();
                                if (mark != null && (newMark == null || newMark.compareTo(mark) < 0)) {
                                    newMark = mark;
                                }
                            }
                            catch (Exception e) {
                                log.error("Failed to checkpoint a message store: " + e, e);
                            }
                        }
                       
                        iterator = topicMessageStores.values().iterator();
                        while (iterator.hasNext()) {
                            try {
                                JournalTopicMessageStore ms = (JournalTopicMessageStore) iterator.next();
                                RecordLocation mark = ms.checkpoint();
                                if (mark != null && (newMark == null || newMark.compareTo(mark) < 0)) {
                                    newMark = mark;
                                }
                            }
                            catch (Exception e) {
                                log.error("Failed to checkpoint a message store: " + e, e);
                            }
                        }
                       
                        try {
                            if (newMark != null) {
                                journal.setMark(newMark, true);
                            }
                        }
                        catch (Exception e) {
                            log.error("Failed to mark the Journal: " + e, e);
                        }
                        log.debug("Checkpoint done.");
                    } finally {
                        for (Iterator iter = listners.iterator(); iter.hasNext();) {
                            Latch latch = (Latch) iter.next();
                            latch.release();
                        }
                    }
                }
            });

            if( sync ) {
                latch.acquire();
            }
        }
        catch (InterruptedException e) {
            log.warn("Request to start checkpoint failed: " + e, e);
        }
View Full Code Here

        }
    }

    public void start() throws IOException {
        if( running.commit(false, true) ) {
            doneLatch = new Latch();
            requestNextRead();
        }
    }
View Full Code Here

    private void flush(long timeout) throws InterruptedIOException {
        try {
            if( timeout == NO_WAIT_TIMEOUT ) {
                dispatcher.add(FLUSH_COMMAND);
            } else if( timeout == WAIT_FOREVER_TIMEOUT ) {
                Latch l = new Latch();
                dispatcher.add(l);
                l.acquire();
            } else {
                Latch l = new Latch();
                dispatcher.add(l);
                l.attempt(timeout);
            }
        } catch (InterruptedException e) {
            throw new InterruptedIOException();
        }
    }
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.