List of usage examples for com.google.common.util.concurrent FutureCallback FutureCallback
FutureCallback
From source file:org.opendaylight.mdsal.dom.broker.DOMDataBrokerTransactionChainImpl.java
@Override public CheckedFuture<Void, TransactionCommitFailedException> submit( final DOMDataTreeWriteTransaction transaction, final Collection<DOMStoreThreePhaseCommitCohort> cohorts) { checkNotFailed();/*from w ww.ja va 2 s . com*/ checkNotClosed(); final CheckedFuture<Void, TransactionCommitFailedException> ret = broker.submit(transaction, cohorts); COUNTER_UPDATER.incrementAndGet(this); Futures.addCallback(ret, new FutureCallback<Void>() { @Override public void onSuccess(final Void result) { transactionCompleted(); } @Override public void onFailure(final Throwable t) { transactionFailed(transaction, t); } }); return ret; }
From source file:org.opendaylight.nemo.user.vnspacemanager.structurestyle.deleteintent.DeleteOperation.java
private void DeleteOperationInstance(UserId userId, OperationId operationId) { WriteTransaction t = dataBroker.newWriteOnlyTransaction(); UserKey userKey = new UserKey(userId); OperationKey operationKey = new OperationKey(operationId); InstanceIdentifier<Operation> operationid = InstanceIdentifier.builder(Users.class) .child(User.class, userKey).child(Operations.class).child(Operation.class, operationKey).build(); t.delete(LogicalDatastoreType.CONFIGURATION, operationid); CheckedFuture<Void, TransactionCommitFailedException> f = t.submit(); Futures.addCallback(f, new FutureCallback<Void>() { @Override/* ww w .j a v a 2s. c o m*/ public void onFailure(Throwable t) { LOG.error("Could not write endpoint base container", t); } @Override public void onSuccess(Void result) { } }); }
From source file:org.opendaylight.mdsal.mount.cache.impl.CachedMountPointTopology.java
/** * Invoke by blueprint/*ww w . j a va 2 s . co m*/ */ public void init() { // Init datastores final WriteTransaction wtx = broker.newWriteOnlyTransaction(); TopologyHelper.initTopology(wtx); Futures.addCallback(wtx.submit(), new FutureCallback<Void>() { @Override public void onSuccess(Void result) { LOG.info("topology initialization successful"); } @Override public void onFailure(Throwable t) { LOG.error("Unable to initialize netconf-topology, {}", t); } }); // Register listener datastoreListenerRegistration = broker .registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, TopologyHelper.CACHED_MOUNT_POINT_TOPOLOGY.child(Node.class)), this); }
From source file:org.opendaylight.nemo.user.vnspacemanager.structurestyle.updateintent.UpdateFlow.java
public String FlowHandling(UserId userId, Flow flow) { String errorDefinition = flowDefinitionCheck.CheckDefinition(flow); String errorInstance = flowInstanceCheck.checkFlowInstance(userId, flow); if (errorDefinition != null) { return errorDefinition; }//from w w w. ja v a2 s.co m if (errorInstance != null) { return errorInstance; } else { WriteTransaction t = dataBroker.newWriteOnlyTransaction(); if (userId != null && flow != null) { // FlowBuilder flowBuilder = new FlowBuilder(); // flowBuilder.setFlowId(flow.getFlowId()); // flowBuilder.setFlowName(flow.getFlowName()); // flowBuilder.setMatchItem(flow.getMatchItem()); // flowBuilder.setProperty(flow.getProperty()); // // Flow flow1 = flowBuilder.build(); Flow flow1 = new FlowBuilder(flow).build(); FlowKey flowKey = new FlowKey(flow.getFlowId()); UserKey userKey = new UserKey(userId); InstanceIdentifier<Flow> flowid = InstanceIdentifier.builder(Users.class).child(User.class, userKey) .child(Objects.class).child(Flow.class, flowKey).build(); t.put(LogicalDatastoreType.CONFIGURATION, flowid, flow1, true); CheckedFuture<Void, TransactionCommitFailedException> f = t.submit(); Futures.addCallback(f, new FutureCallback<Void>() { @Override public void onFailure(Throwable t) { LOG.error("Could not write endpoint base container", t); } @Override public void onSuccess(Void result) { } }); } } return null; }
From source file:google.registry.tools.LoadSnapshotCommand.java
/** * Block on the completion of the load jobs in the provided map, printing out information on * each job's success or failure./*w ww. j av a 2s .c o m*/ */ private void waitForLoadJobs(Map<String, ListenableFuture<?>> loadJobs) throws Exception { final long startTime = System.currentTimeMillis(); System.err.println("Waiting for load jobs..."); // Add callbacks to each load job that print information on successful completion or failure. for (final String jobId : loadJobs.keySet()) { final String jobName = "load-" + jobId; Futures.addCallback(loadJobs.get(jobId), new FutureCallback<Object>() { private double elapsedSeconds() { return (System.currentTimeMillis() - startTime) / 1000.0; } @Override public void onSuccess(Object unused) { System.err.printf("Job %s succeeded (%.3fs)\n", jobName, elapsedSeconds()); } @Override public void onFailure(Throwable error) { System.err.printf("Job %s failed (%.3fs): %s\n", jobName, elapsedSeconds(), error.getMessage()); } }); } // Block on the completion of all the load jobs. List<?> results = Futures.successfulAsList(loadJobs.values()).get(); int numSucceeded = FluentIterable.from(results).filter(notNull()).size(); System.err.printf("All load jobs have terminated: %d/%d successful.\n", numSucceeded, loadJobs.size()); }
From source file:org.opendaylight.nemo.user.vnspacemanager.structurestyle.deleteintent.DeleteConnection.java
private void DeleteConnInstance(UserId userId, ConnectionId connectionId) { WriteTransaction t = dataBroker.newWriteOnlyTransaction(); UserKey userKey = new UserKey(userId); ConnectionKey connectionKey = new ConnectionKey(connectionId); InstanceIdentifier<Connection> connectionid = InstanceIdentifier.builder(Users.class) .child(User.class, userKey).child(Objects.class).child(Connection.class, connectionKey).build(); t.delete(LogicalDatastoreType.CONFIGURATION, connectionid); CheckedFuture<Void, TransactionCommitFailedException> f = t.submit(); Futures.addCallback(f, new FutureCallback<Void>() { @Override//from w w w . j a va 2s. c o m public void onFailure(Throwable t) { LOG.error("Could not write endpoint base container", t); } @Override public void onSuccess(Void result) { } }); }
From source file:org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.didm.vendor.extreme.rev150211.ExtremeModule.java
protected static void removeDeviceTypeInfo(DataBroker dataBroker, InstanceIdentifier<DeviceTypeInfo> path) { LOG.debug("registerDeviceTypeInfo -> " + dataBroker); WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction(); writeTx.delete(LogicalDatastoreType.CONFIGURATION, path); CheckedFuture<Void, TransactionCommitFailedException> future = writeTx.submit(); Futures.addCallback(future, new FutureCallback<Void>() { public void onSuccess(Void result) { LOG.info("registerDeviceTypeInfo onSuccess"); }/*from ww w .j a v a 2s .c o m*/ public void onFailure(Throwable t) { LOG.error("registerDeviceTypeInfo onFailure -> " + t); } }); }
From source file:c5db.regionserver.RegionServerHandler.java
private void mutate(ChannelHandlerContext ctx, Call call) throws RegionNotFoundException, IOException { final MutateRequest mutateIn = call.getMutate(); if (mutateIn == null) { throw new IOException("Poorly specified mutate. There is no actual get data in the RPC"); }//from www .j a va 2 s.c om final Region region = regionServerService.getOnlineRegion(call.getMutate().getRegion()); if (mutateIn.getMutation().getMutateType().equals(MutationProto.MutationType.PUT) && (mutateIn.getCondition() == null || mutateIn.getCondition().getRow() == null)) { Futures.addCallback(region.batchMutate(mutateIn.getMutation()), new FutureCallback<Boolean>() { @Override public void onSuccess(Boolean result) { MutateResponse mutateResponse = new MutateResponse(new c5db.client.generated.Result(), true); final Response response = new Response(Response.Command.MUTATE, call.getCommandId(), null, mutateResponse, null, null); ctx.writeAndFlush(response); } @Override public void onFailure(Throwable t) { t.toString(); } }); //TODO check success } else { boolean success = region.mutate(mutateIn.getMutation(), mutateIn.getCondition()); //TODO check success MutateResponse mutateResponse = new MutateResponse(new c5db.client.generated.Result(), success); final Response response = new Response(Response.Command.MUTATE, call.getCommandId(), null, mutateResponse, null, null); ctx.writeAndFlush(response); } }
From source file:com.google.cloud.bigtable.grpc.async.RpcThrottler.java
/** * Add a callback to a Future representing an RPC call with the given * operation id that will clean upon completion and reclaim any utilized resources. * This method must be paired with every call to {@code registerOperationWithHeapSize}. * * @param future a {@link com.google.common.util.concurrent.ListenableFuture} object. * @param id a long.//from ww w .j a v a 2 s . c o m * @return a {@link com.google.common.util.concurrent.FutureCallback} object. * @param <T> a T object. */ public <T> FutureCallback<T> addCallback(ListenableFuture<T> future, final long id) { FutureCallback<T> callback = new FutureCallback<T>() { @Override public void onSuccess(T result) { onRpcCompletion(id); } @Override public void onFailure(Throwable t) { onRpcCompletion(id); } }; Futures.addCallback(future, callback); return callback; }
From source file:org.opendaylight.ocpplugin.impl.services.SalObjectStateMgmtServiceImpl.java
@Override public Future<RpcResult<ModifyStateOutput>> modifyState(final ModifyStateInput input) { ListenableFuture<RpcResult<org.opendaylight.yang.gen.v1.urn.opendaylight.ocp.protocol.rev150811.ModifyStateOutput>> future = modifyState .handleServiceCall(input);/* www . j a va2 s . c o m*/ final SettableFuture<RpcResult<ModifyStateOutput>> finalFuture = SettableFuture.create(); Futures.addCallback(future, new FutureCallback<RpcResult<org.opendaylight.yang.gen.v1.urn.opendaylight.ocp.protocol.rev150811.ModifyStateOutput>>() { @Override public void onSuccess( final RpcResult<org.opendaylight.yang.gen.v1.urn.opendaylight.ocp.protocol.rev150811.ModifyStateOutput> result) { org.opendaylight.yang.gen.v1.urn.opendaylight.ocp.protocol.rev150811.ModifyStateOutput output = result .getResult(); ModifyStateOutputBuilder builder = new ModifyStateOutputBuilder(); builder.setObjId(output.getObjId()); builder.setStateType(output.getStateType()); builder.setStateValue(output.getStateValue()); builder.setResult(output.getResult()); RpcResultBuilder<ModifyStateOutput> rpcResultBuilder = RpcResultBuilder.success(builder); finalFuture.set(rpcResultBuilder.build()); } @Override public void onFailure(final Throwable t) { RpcResultBuilder<ModifyStateOutput> rpcResultBuilder = RpcResultBuilder.failed(); finalFuture.set(rpcResultBuilder.build()); } }); return finalFuture; }