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

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


                throw new IllegalStateException("AcceptListener must be set before object can be started.");

            synchChannelServer.start();
           
            try {
                doneLatch = new Latch();
                executor.execute(this);
            } catch (InterruptedException e) {
                throw new InterruptedIOException(e.getMessage());
            }
        }
View Full Code Here


                throw new IllegalStateException("UpPacketListener must be set before object can be started.");
           
            synchChannel.start();

            try {
                doneLatch = new Latch();
                executor.execute(this);
            } catch (InterruptedException e) {
                throw new InterruptedIOException(e.getMessage());
            }
View Full Code Here

        try {
           
            activeConnectionsCounter.reset();
            echoedBytesCounter.reset();
           
            shutdownLatch = new Latch();
               
            ChannelFactory factory = new ChannelFactory();
            AsynchChannelServer server = factory.bindAsynchChannel(url);
            System.out.println("Server accepting connections on: "+server.getConnectURI());
            server.setAcceptListener(this);
View Full Code Here

            appendInProgress = true;
        }
       
       
        if( force && writeDoneLatch==null)
            writeDoneLatch = new Latch();
       
        record.read(packet);

        // if we fit the record in this batch
        if ( !record.hasRemaining() ) {
View Full Code Here

    public void run() {
        ArrayList clients = new ArrayList();
        try {

            shutdownLatch = new Latch();
            activeConnectionsCounter.reset();
            echoedBytesCounter.reset();

            new Thread("Sampler") {
                public void run() {
View Full Code Here

            }
        }

        private void sendRequest() throws IOException, InterruptedException {
           
            final Latch done = new Latch();
           
            // Read the data async to avoid dead locks due buffers being to small for
            // data being sent.
            threadPool.execute(new Runnable() {
                public void run() {
                    try {
                        int c = 0;
                        while (c < packet.remaining()) {
                            Packet p = synchChannel.read(1000*5);
                            if( p==null ) {
                                continue;
                            }
                            if( p == EOSPacket.EOS_PACKET ) {
                                System.out.println("Peer disconnected.");
                                dispose();
                            }
                            c += p.remaining();
                        }
                        done.release();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            });

            synchChannel.write(packet.duplicate());
            synchChannel.flush();
            done.acquire();
           
        }
View Full Code Here

        final int CONSUMER_COUNT=Integer.parseInt(System.getProperty("CONSUMER_COUNT","10"));
       
        final ProgressPrinter pp = new ProgressPrinter(MESSAGE_COUNT*2, 5);

        final Semaphore connectionsEstablished = new Semaphore(1-(CONSUMER_COUNT+PRODUCER_COUNT));
        final Latch startTest = new Latch();
        final Semaphore testsFinished = new Semaphore(1-(CONSUMER_COUNT+PRODUCER_COUNT));
       
        final Callable producer = new Callable() {
            public Object call() throws JMSException, InterruptedException {
                Connection connection = connectionFactory.createConnection();
                Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                MessageProducer producer = session.createProducer(dest);
                producer.setDeliveryMode(DeliveryMode.PERSISTENT);
                BytesMessage message = session.createBytesMessage();
                message.writeBytes(new byte[1024]);
                connection.start();
               
                connectionsEstablished.release();
               
                startTest.acquire();               
                final int msgs = (MESSAGE_COUNT/PRODUCER_COUNT)+1;
                for (int i = 0; i < msgs; i++) {
                    pp.increment();
                    producer.send(message);
                }               
               
                testsFinished.release();               
                connection.close();
                return null;
            }
        };
       
        final Callable consumer = new Callable() {
            public Object call() throws JMSException, InterruptedException {
                final Latch doneLatch = new Latch();               
                Connection connection = connectionFactory.createConnection();               
                Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                MessageConsumer consumer = session.createConsumer(dest);

                connectionsEstablished.release();
                startTest.acquire();

                final int msgs = (MESSAGE_COUNT/CONSUMER_COUNT)-1;
                consumer.setMessageListener(new MessageListener(){
                    int counter=0;
                    public void onMessage(Message msg) {               
                        pp.increment();
                        counter++;
                        if( counter >= msgs ) {
                            doneLatch.release();
                        }
                    }
                });
                connection.start();
                doneLatch.acquire();

                testsFinished.release();               
                connection.close();
                return null;
            }
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

        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

       Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      
       final MessageConsumer topicConsumer = consumerSession.createConsumer(topic1);
         
        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(1500));
 
        // wait for the closing thread to finish
        latch.acquire();
     }
     finally
     {
       if (consumerConnection != null)
       {
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.