Examples of Future


Examples of java.util.concurrent.Future

     */
    @Test
    public void testFireUntilHaltWithAccumulateAndExpires() throws Exception {
        // thread for firing until halt
        final ExecutorService executor = Executors.newSingleThreadExecutor();
        final Future sessionFuture = executor.submit(new Runnable() {

            public void run() {
                statefulSession.fireUntilHalt();
            }
        });

        try {
            for (int iteration = 0; iteration < 100; iteration++) {
                this.populateSessionWithStocks();
            }
            // let the engine finish its job
            Thread.sleep(2000);

        } finally {
            statefulSession.halt();
            // not to swallow possible exception
            sessionFuture.get();
        }
    }
View Full Code Here

Examples of java.util.concurrent.Future

        m_timer = new ResettableTimer(task, 100, TimeUnit.MILLISECONDS);
        m_timer.schedule();

        TimeUnit.MILLISECONDS.sleep(75);
       
        Future f = m_timer.schedule();
        f.get();

        assertEquals(1, m_counter.get());
    }
View Full Code Here

Examples of java.util.concurrent.Future

            }
        };

        m_timer = new ResettableTimer(task, 100, TimeUnit.MILLISECONDS);
       
        Future f = m_timer.schedule();
        f.get();

        f = m_timer.schedule();
        f.get();

        assertEquals(2, m_counter.get());
    }
View Full Code Here

Examples of java.util.concurrent.Future

public class JGroupsChannelTest {

    @Test (enabled = false)
    public void broadcastsClusteredMessage() throws Exception {
        Broadcaster broadcaster = mock(Broadcaster.class);
        Future broadcastedMessage = mock(Future.class);
       
        when(broadcaster.getID()).thenReturn("/topic");
        when(broadcaster.broadcast("message")).thenReturn(broadcastedMessage);
       
        JChannel channel1 = new JChannel();
View Full Code Here

Examples of java.util.concurrent.Future

        return command;
    }

    @Override
    public void process(final Exchange exchange) throws Exception {
        Future f = executor.submit(new RunCommand(exchange));
        f.get();
    }
View Full Code Here

Examples of java.util.concurrent.Future

     
      // lock the connection for the period of submission and waiting
      // in order to bound the # of threads in the executor by the number
      // of connections
      synchronized (sendParamsLock) {
        Future senderFuture = SEND_PARAMS_EXECUTOR.submit(new Runnable() {
          @Override
          public void run() {
            DataOutputBuffer d = null;

            synchronized (Connection.this.out) {
              try {
                if (shouldCloseConnection.get()) {
                  return;
                }
                if (LOG.isDebugEnabled()) {
                  LOG.debug(getName() + " sending #" + call.id);
                }

                //for serializing the
                //data to be written
                d = new DataOutputBuffer();
                d.writeInt(call.id);
                call.param.write(d);
                byte[] data = d.getData();
                int dataLength = d.getLength();
                out.writeInt(dataLength);      //first put the data length
                out.write(data, 0, dataLength);//write the data
                out.flush();

              } catch (IOException e) {
                markClosed(e);
              } finally {
                //the buffer is just an in-memory buffer, but it is still polite to
                // close early
                IOUtils.closeStream(d);
              }
            }
          }
        });

        try {
          senderFuture.get();
        } catch (ExecutionException e) {
          Throwable cause = e.getCause();

          // cause should only be a RuntimeException as the Runnable above
          // catches IOException
View Full Code Here

Examples of java.util.concurrent.Future

                logger.fine("Spawning service to download asset " + assetURI);
                Asset asset = assetFactory.assetFactory(AssetType.FILE, assetID);
               
                AssetLoader loader = new AssetLoader(asset, factory);
                loadingAssets.put(assetID, loader);
                Future f = downloadService.submit(loader);
                loader.setFuture(f);

                // record time
                long submitTime = System.currentTimeMillis() - startTime;
                getStatsProvider().assetStatistic(assetURI, AssetStat.SUBMIT, submitTime);
View Full Code Here

Examples of java.util.concurrent.Future

    // Copy-pasted from the thrift CassandraServer, using the factory methods to create exceptions.
    // helper method to apply migration on the migration stage. typical migration failures will throw an
    // InvalidRequestException. atypical failures will throw a RuntimeException.
    private static void applyMigrationOnStage(final Migration m) throws InvalidRequestException
    {
        Future f = StageManager.getStage(Stage.MIGRATION).submit(new Callable()
        {
            public Object call() throws Exception
            {
                m.apply();
                m.announce();
                return null;
            }
        });
        try
        {
            f.get();
        }
        catch (InterruptedException e)
        {
            throw new RuntimeException(e);
        }
View Full Code Here

Examples of java.util.concurrent.Future

   
    // helper method to apply migration on the migration stage. typical migration failures will throw an
    // InvalidRequestException. atypical failures will throw a RuntimeException.
    private static void applyMigrationOnStage(final Migration m)
    {
        Future f = StageManager.getStage(Stage.MIGRATION).submit(new Callable()
        {
            public Object call() throws Exception
            {
                m.apply();
                m.announce();
                return null;
            }
        });
        try
        {
            f.get();
        }
        catch (InterruptedException e)
        {
            throw new AssertionError(e);
        }
View Full Code Here

Examples of java.util.concurrent.Future

    public void finished(PendingFile remoteFile, PendingFile localFile) throws IOException
    {
        if (logger.isDebugEnabled())
            logger.debug("Finished {}. Sending ack to {}", remoteFile, this);

        Future future = CompactionManager.instance.submitSSTableBuild(localFile.desc);
        buildFutures.add(future);

        files.remove(remoteFile);
        if (remoteFile.equals(current))
            current = null;
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.