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);
}
}
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);
}
}
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;
}
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;
}
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
}
}
}
Aggregations