Search in sources :

Example 86 with Future

use of java.util.concurrent.Future in project eureka by Netflix.

the class InstanceInfoReplicator method start.

public void start(int initialDelayMs) {
    if (started.compareAndSet(false, true)) {
        // for initial register
        instanceInfo.setIsDirty();
        Future next = scheduler.schedule(this, initialDelayMs, TimeUnit.SECONDS);
        scheduledPeriodicRef.set(next);
    }
}
Also used : Future(java.util.concurrent.Future)

Example 87 with Future

use of java.util.concurrent.Future in project eureka by Netflix.

the class InstanceInfoReplicator method run.

public void run() {
    try {
        discoveryClient.refreshInstanceInfo();
        Long dirtyTimestamp = instanceInfo.isDirtyWithTime();
        if (dirtyTimestamp != null) {
            discoveryClient.register();
            instanceInfo.unsetIsDirty(dirtyTimestamp);
        }
    } catch (Throwable t) {
        logger.warn("There was a problem with the instance info replicator", t);
    } finally {
        Future next = scheduler.schedule(this, replicationIntervalSeconds, TimeUnit.SECONDS);
        scheduledPeriodicRef.set(next);
    }
}
Also used : Future(java.util.concurrent.Future)

Example 88 with Future

use of java.util.concurrent.Future in project eureka by Netflix.

the class AsyncResolver method doWarmUp.

/* visible for testing */
boolean doWarmUp() {
    Future future = null;
    try {
        future = threadPoolExecutor.submit(updateTask);
        // block until done or timeout
        future.get(warmUpTimeoutMs, TimeUnit.MILLISECONDS);
        return true;
    } catch (Exception e) {
        logger.warn("Best effort warm up failed", e);
    } finally {
        if (future != null) {
            future.cancel(true);
        }
    }
    return false;
}
Also used : Future(java.util.concurrent.Future)

Example 89 with Future

use of java.util.concurrent.Future in project ribbon by Netflix.

the class PrimeConnections method primeConnectionsAsync.

/*
    private void makeConnectionsASync() {
        Callable<Void> ft = new Callable<Void>() {
            public Void call() throws Exception {
                logger.info("primeConnections ...");
                makeConnections();
                return null;
            }
        };
        outerExecutorService.submit(ft);
    }
    */
/**
     * Prime servers asynchronously.
     * 
     * @param servers
     * @param listener
     */
public List<Future<Boolean>> primeConnectionsAsync(final List<Server> servers, final PrimeConnectionListener listener) {
    if (servers == null) {
        return Collections.emptyList();
    }
    List<Server> allServers = new ArrayList<Server>();
    allServers.addAll(servers);
    if (allServers.size() == 0) {
        logger.debug("RestClient:" + name + ". No nodes/servers to prime connections");
        return Collections.emptyList();
    }
    logger.info("Priming Connections for RestClient:" + name + ", numServers:" + allServers.size());
    List<Future<Boolean>> ftList = new ArrayList<Future<Boolean>>();
    for (Server s : allServers) {
        // prevent the server to be used by load balancer
        // will be set to true when priming is done
        s.setReadyToServe(false);
        if (aSync) {
            Future<Boolean> ftC = null;
            try {
                ftC = makeConnectionASync(s, listener);
                ftList.add(ftC);
            } catch (RejectedExecutionException ree) {
                logger.error("executor submit failed", ree);
            } catch (Exception e) {
                logger.error("general error", e);
            // It does not really matter if there was an exception,
            // the goal here is to attempt "priming/opening" the route
            // in ec2 .. actual http results do not matter
            }
        } else {
            connectToServer(s, listener);
        }
    }
    return ftList;
}
Also used : Server(com.netflix.loadbalancer.Server) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 90 with Future

use of java.util.concurrent.Future in project newts by OpenNMS.

the class CassandraSampleRepository method delete.

@Override
public void delete(Context context, Resource resource) {
    /**
         * Check for ttl value > 0
         */
    if (m_ttl > 0) {
        /**
             * Delete exactly from (now - ttl) till now
             */
        final Timestamp start = Timestamp.now().minus(m_ttl, TimeUnit.SECONDS);
        final Timestamp end = Timestamp.now();
        final Duration resourceShard = m_contextConfigurations.getResourceShard(context);
        final List<Future<ResultSet>> futures = Lists.newArrayList();
        for (Timestamp partition : new IntervalGenerator(start.stepFloor(resourceShard), end.stepFloor(resourceShard), resourceShard)) {
            BoundStatement bindStatement = m_deleteStatement.bind();
            bindStatement.setString(SchemaConstants.F_CONTEXT, context.getId());
            bindStatement.setInt(SchemaConstants.F_PARTITION, (int) partition.asSeconds());
            bindStatement.setString(SchemaConstants.F_RESOURCE, resource.getId());
            futures.add(m_session.executeAsync(bindStatement));
        }
        for (final Future<ResultSet> future : futures) {
            try {
                future.get();
            } catch (final InterruptedException | ExecutionException e) {
                throw Throwables.propagate(e);
            }
        }
    } else {
        // Choose (now - one year) till now...
        Timestamp end = Timestamp.now();
        Timestamp start = end.minus(DELETION_INTERVAL, TimeUnit.DAYS);
        // ... and check whether samples exist for this period of time.
        while (cassandraSelect(context, resource, start, end).hasNext()) {
            // Now delete the samples...
            final Duration resourceShard = m_contextConfigurations.getResourceShard(context);
            final List<Future<ResultSet>> futures = Lists.newArrayList();
            for (Timestamp partition : new IntervalGenerator(start.stepFloor(resourceShard), end.stepFloor(resourceShard), resourceShard)) {
                BoundStatement bindStatement = m_deleteStatement.bind();
                bindStatement.setString(SchemaConstants.F_CONTEXT, context.getId());
                bindStatement.setInt(SchemaConstants.F_PARTITION, (int) partition.asSeconds());
                bindStatement.setString(SchemaConstants.F_RESOURCE, resource.getId());
                futures.add(m_session.executeAsync(bindStatement));
            }
            for (final Future<ResultSet> future : futures) {
                try {
                    future.get();
                } catch (final InterruptedException | ExecutionException e) {
                    throw Throwables.propagate(e);
                }
            }
            // ...set end to start and start to (end - one year)
            end = start;
            start = end.minus(DELETION_INTERVAL, TimeUnit.DAYS);
        // and start over again until no more samples are found
        }
    }
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) Future(java.util.concurrent.Future) Duration(org.opennms.newts.api.Duration) IntervalGenerator(org.opennms.newts.aggregate.IntervalGenerator) ExecutionException(java.util.concurrent.ExecutionException) Timestamp(org.opennms.newts.api.Timestamp) BoundStatement(com.datastax.driver.core.BoundStatement)

Aggregations

Future (java.util.concurrent.Future)1138 ArrayList (java.util.ArrayList)479 ExecutorService (java.util.concurrent.ExecutorService)445 Test (org.junit.Test)413 ExecutionException (java.util.concurrent.ExecutionException)264 Callable (java.util.concurrent.Callable)206 IOException (java.io.IOException)177 ParallelTest (com.hazelcast.test.annotation.ParallelTest)148 QuickTest (com.hazelcast.test.annotation.QuickTest)148 HashMap (java.util.HashMap)92 List (java.util.List)84 CountDownLatch (java.util.concurrent.CountDownLatch)71 LinkedList (java.util.LinkedList)67 TimeoutException (java.util.concurrent.TimeoutException)63 HashSet (java.util.HashSet)62 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)59 Map (java.util.Map)58 ICompletableFuture (com.hazelcast.core.ICompletableFuture)57 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)53 File (java.io.File)46