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

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


        } else {
            FutureResult[] futures = new FutureResult[commands.length];
            for (int i = 0; i < commands.length; i++) {
                final Command c = commands[i];
                futures[i] = new FutureResult();
                Runnable r = futures[i].setter(new Callable() {
                    public Object call() throws Exception {
                        return c.call();
                    }
                });
                try {
View Full Code Here


    public TextExtractorJob(final TextExtractor extractor,
                            final InputStream stream,
                            final String type,
                            final String encoding) {
        this.type = type;
        this.cmd = setter(new Callable() {
            public Object call() throws Exception {
                Reader r = extractor.extractText(stream, type, encoding);
                if (r != null) {
                    if (discarded) {
                        r.close();
View Full Code Here

        } else {
            FutureResult[] futures = new FutureResult[commands.length];
            for (int i = 0; i < commands.length; i++) {
                final Command c = commands[i];
                futures[i] = new FutureResult();
                Runnable r = futures[i].setter(new Callable() {
                    public Object call() throws Exception {
                        return c.call();
                    }
                });
                try {
View Full Code Here

         FutureResult[] futures = new FutureResult[commands.length];
         for (int i = 0; i < commands.length; i++)
         {
            final Command c = commands[i];
            futures[i] = new FutureResult();
            Runnable r = futures[i].setter(new Callable()
            {
               public Object call() throws Exception
               {
                  return c.call();
               }
View Full Code Here

      closeAllSuckers();     
     
      //Note we use a timed callable since remoting has a habit of hanging on attempting to close
      //We do not want this to hang the system - especially failover
     
      Callable callable = new Callable() { public Object call()
      {
        try
        {
          connection.close();
        }
        catch (JMSException ignore)
        {         
        }
        return null;
        } };
     
      Callable timedCallable = new TimedCallable(callable, CLOSE_TIMEOUT);
     
      try
      {
        timedCallable.call();
      }
      catch (Throwable t)
      {
        //Ignore - the server might have already closed - so this is ok
      }
View Full Code Here

         synchronized (this)
         {
            if (!started)
               return;

            Callable callable = new Callable()
            {
               public Object call()
               {
                  try
                  {
                     connection.close();
                  }
                  catch (JMSException ignore)
                  {
                  }
                  return null;
               }
            };

            Callable timedCallable = new TimedCallable(callable, CLOSE_TIMEOUT);

            try
            {
               timedCallable.call();
            }
            catch (Throwable t)
            {
               // Ignore - the server might have already closed - so this is ok
            }
View Full Code Here

            sucker.suspend();
         }

         final JBossConnection copy = connection;
        
         Callable callable = new Callable() { public Object call()
         {
            try
            {
               copy.close();
            }
            catch (JMSException ignore)
            {             
            }
            return null;
          } };
        
         Callable timedCallable = new TimedCallable(callable, CLOSE_TIMEOUT);
        
         try
         {
            timedCallable.call();
         }
         catch (Throwable t)
         {
            //Ignore - the server might have already closed - so this is ok
         }
View Full Code Here

      closeAllSuckers();     
     
      //Note we use a timed callable since remoting has a habit of hanging on attempting to close
      //We do not want this to hang the system - especially failover
     
      Callable callable = new Callable() { public Object call()
      {
        try
        {
          connection.close();
        }
        catch (JMSException ignore)
        {         
        }
        return null;
        } };
     
      Callable timedCallable = new TimedCallable(callable, CLOSE_TIMEOUT);
     
      try
      {
        timedCallable.call();
      }
      catch (Throwable t)
      {
        //Ignore - the server might have already closed - so this is ok
      }
View Full Code Here

            MessageSucker sucker = (MessageSucker)iter.next();
           
            sucker.suspend();
         }

         Callable callable = new Callable() { public Object call()
         {
            try
            {
               connection.close();
            }
            catch (JMSException ignore)
            {             
            }
            return null;
          } };
        
         Callable timedCallable = new TimedCallable(callable, CLOSE_TIMEOUT);
        
         try
         {
            timedCallable.call();
         }
         catch (Throwable t)
         {
            //Ignore - the server might have already closed - so this is ok
         }
View Full Code Here

        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;
            }
        };
       
        final Throwable workerError[] = new Throwable[1];
        for( int i=0; i < PRODUCER_COUNT; i++ ) {
            new Thread("Producer:"+i) {
                public void run() {
                    try {
                        producer.call();
                    } catch (Throwable e) {
                        e.printStackTrace();
                        workerError[0] = e;
                    }
                }
            }.start();
        }

        for( int i=0; i < CONSUMER_COUNT; i++ ) {
            new Thread("Consumer:"+i) {
                public void run() {
                    try {
                        consumer.call();
                    } catch (Throwable e) {
                        workerError[0] = e;
                    }
                }
            }.start();
View Full Code Here

TOP

Related Classes of EDU.oswego.cs.dl.util.concurrent.Callable

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.