use of com.google.common.util.concurrent.SettableFuture in project genius by opendaylight.
the class AlivenessMonitor method monitorStop.
@Override
public Future<RpcResult<Void>> monitorStop(MonitorStopInput input) {
LOG.debug("Monitor Stop operation for monitor id - {}", input.getMonitorId());
SettableFuture<RpcResult<Void>> result = SettableFuture.create();
final Long monitorId = input.getMonitorId();
Optional<MonitoringInfo> optInfo = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, getMonitoringInfoId(monitorId));
if (optInfo.isPresent()) {
// Stop the monitoring task
stopMonitoringTask(monitorId);
String monitorKey = monitorIdKeyCache.getUnchecked(monitorId);
// Cleanup the Data store
Futures.addCallback(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
if (monitorKey != null) {
tx.delete(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey));
monitorIdKeyCache.invalidate(monitorId);
}
tx.delete(LogicalDatastoreType.OPERATIONAL, getMonitoringInfoId(monitorId));
}), new FutureCallbackImpl(String.format("Delete monitor state with Id %d", monitorId)), MoreExecutors.directExecutor());
MonitoringInfo info = optInfo.get();
String interfaceName = getInterfaceName(info.getSource().getEndpointType());
if (interfaceName != null) {
removeMonitorIdFromInterfaceAssociation(monitorId, interfaceName);
}
releaseIdForMonitoringInfo(info);
if (monitorKey != null) {
lockMap.remove(monitorKey);
}
result.set(RpcResultBuilder.<Void>success().build());
} else {
String errorMsg = String.format("Do not have monitoring information associated with key %d", monitorId);
LOG.error("Delete monitoring operation Failed - {}", errorMsg);
result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, errorMsg).build());
}
return result;
}
use of com.google.common.util.concurrent.SettableFuture in project vertexium by visallo.
the class Elasticsearch5SearchIndex method addActionRequestBuilderForFlush.
private void addActionRequestBuilderForFlush(String elementId, String rowId, UpdateRequestBuilder updateRequestBuilder) {
Future future;
try {
future = updateRequestBuilder.execute();
} catch (Exception ex) {
LOGGER.debug("Could not execute update: %s", ex.getMessage());
future = SettableFuture.create();
((SettableFuture) future).setException(ex);
}
flushObjectQueue.add(elementId, rowId, updateRequestBuilder, future);
}
use of com.google.common.util.concurrent.SettableFuture in project jesos by groupon.
the class ExecutorDriverContext method setStateMachine.
//
// State machine management
//
synchronized void setStateMachine(final Status status) {
final Status oldStatus = stateMachine.getAndSet(status);
if (status != oldStatus) {
final List<SettableFuture<Status>> settableFutures = new ArrayList<>(stateMachineFutures.size());
stateMachineFutures.drainTo(settableFutures);
for (final SettableFuture<Status> future : settableFutures) {
future.set(status);
}
}
}
use of com.google.common.util.concurrent.SettableFuture in project druid by druid-io.
the class SeekableStreamIndexTaskRunner method publishAndRegisterHandoff.
private void publishAndRegisterHandoff(SequenceMetadata<PartitionIdType, SequenceOffsetType> sequenceMetadata) {
log.debug("Publishing segments for sequence [%s].", sequenceMetadata);
final ListenableFuture<SegmentsAndCommitMetadata> publishFuture = Futures.transform(driver.publish(sequenceMetadata.createPublisher(this, toolbox, ioConfig.isUseTransaction()), sequenceMetadata.getCommitterSupplier(this, stream, lastPersistedOffsets).get(), Collections.singletonList(sequenceMetadata.getSequenceName())), (Function<SegmentsAndCommitMetadata, SegmentsAndCommitMetadata>) publishedSegmentsAndMetadata -> {
if (publishedSegmentsAndMetadata == null) {
throw new ISE("Transaction failure publishing segments for sequence [%s]", sequenceMetadata);
} else {
return publishedSegmentsAndMetadata;
}
});
publishWaitList.add(publishFuture);
// Create a handoffFuture for every publishFuture. The created handoffFuture must fail if publishFuture fails.
final SettableFuture<SegmentsAndCommitMetadata> handoffFuture = SettableFuture.create();
handOffWaitList.add(handoffFuture);
Futures.addCallback(publishFuture, new FutureCallback<SegmentsAndCommitMetadata>() {
@Override
public void onSuccess(SegmentsAndCommitMetadata publishedSegmentsAndCommitMetadata) {
log.info("Published %s segments for sequence [%s] with metadata [%s].", publishedSegmentsAndCommitMetadata.getSegments().size(), sequenceMetadata.getSequenceName(), Preconditions.checkNotNull(publishedSegmentsAndCommitMetadata.getCommitMetadata(), "commitMetadata"));
log.infoSegments(publishedSegmentsAndCommitMetadata.getSegments(), "Published segments");
sequences.remove(sequenceMetadata);
publishingSequences.remove(sequenceMetadata.getSequenceName());
try {
persistSequences();
} catch (IOException e) {
log.error(e, "Unable to persist state, dying");
handoffFuture.setException(e);
throw new RuntimeException(e);
}
Futures.transform(driver.registerHandoff(publishedSegmentsAndCommitMetadata), new Function<SegmentsAndCommitMetadata, Void>() {
@Nullable
@Override
public Void apply(@Nullable SegmentsAndCommitMetadata handoffSegmentsAndCommitMetadata) {
if (handoffSegmentsAndCommitMetadata == null) {
log.warn("Failed to hand off %s segments", publishedSegmentsAndCommitMetadata.getSegments().size());
log.warnSegments(publishedSegmentsAndCommitMetadata.getSegments(), "Failed to hand off segments");
}
handoffFuture.set(handoffSegmentsAndCommitMetadata);
return null;
}
});
}
@Override
public void onFailure(Throwable t) {
log.error(t, "Error while publishing segments for sequenceNumber[%s]", sequenceMetadata);
handoffFuture.setException(t);
}
});
}
use of com.google.common.util.concurrent.SettableFuture in project pentaho-kettle by pentaho.
the class KettleEnvironmentIT method resetKettleEnvironmentInitializationFlag.
private void resetKettleEnvironmentInitializationFlag() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, InstantiationException {
Field f = KettleEnvironment.class.getDeclaredField("initialized");
f.setAccessible(true);
f.set(null, new AtomicReference<SettableFuture<Boolean>>(null));
Constructor<KettleVFS> constructor;
constructor = KettleVFS.class.getDeclaredConstructor();
constructor.setAccessible(true);
KettleVFS KVFS = constructor.newInstance();
f = KVFS.getClass().getDeclaredField("kettleVFS");
f.setAccessible(true);
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(f, f.getModifiers() & ~Modifier.FINAL | Modifier.VOLATILE);
f.set(null, KVFS);
f = KVFS.getClass().getDeclaredField("defaultVariableSpace");
f.setAccessible(true);
modifiersField.setInt(f, f.getModifiers() & ~Modifier.FINAL);
Variables var = new Variables();
var.initializeVariablesFrom(null);
f.set(null, var);
}
Aggregations