List of usage examples for com.google.common.util.concurrent SettableFuture create
public static <V> SettableFuture<V> create()
From source file:edu.umich.si.inteco.minuku.dao.LocationDataRecordDAO.java
@Override public Future<List<LocationDataRecord>> getLast(int N) throws DAOException { final SettableFuture<List<LocationDataRecord>> settableFuture = SettableFuture.create(); final Date today = new Date(); final List<LocationDataRecord> lastNRecords = Collections .synchronizedList(new ArrayList<LocationDataRecord>()); getLastNValues(N, myUserEmail, today, lastNRecords, settableFuture); return settableFuture; }
From source file:com.microsoft.windowsazure.mobileservices.zumoe2etestapp.framework.log.DaylightLogger.java
private static ListenableFuture<HttpURLConnection> execute(final HttpEntityEnclosingRequestBase request) { final SettableFuture<HttpURLConnection> result = SettableFuture.create(); AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() { @Override/*from ww w .j av a2 s. c o m*/ protected Void doInBackground(Void... params) { try { result.set(createHttpURLConnection(request)); } catch (Throwable t) { result.setException(t); } return null; } }; execute(task); return result; }
From source file:edu.umich.si.inteco.minuku.dao.SemanticLocationDataRecordDAO.java
@Override public Future<List<SemanticLocationDataRecord>> getLast(int N) throws DAOException { final SettableFuture<List<SemanticLocationDataRecord>> settableFuture = SettableFuture.create(); final Date today = new Date(); final List<SemanticLocationDataRecord> lastNRecords = Collections .synchronizedList(new ArrayList<SemanticLocationDataRecord>()); getLastNValues(N, myUserEmail, today, lastNRecords, settableFuture); return settableFuture; }
From source file:com.griddynamics.jagger.master.AbstractDistributor.java
@Override public Service distribute(final ExecutorService executor, final String sessionId, final String taskId, final Multimap<NodeType, NodeId> availableNodes, final Coordinator coordinator, final T task, final DistributionListener listener) { Set<Qualifier<?>> qualifiers = getQualifiers(); final Map<NodeId, RemoteExecutor> remotes = Maps.newHashMap(); for (NodeId nodeId : availableNodes.get(NodeType.KERNEL)) { boolean canRunTheCommand = coordinator.canExecuteCommands(nodeId, qualifiers); if (canRunTheCommand) { remotes.put(nodeId, coordinator.getExecutor(nodeId)); } else {/*w ww . j ava2 s . c o m*/ log.debug("command type {} are not supported by kernel {}", qualifiers, nodeId); } } if (remotes.isEmpty()) { throw new NodeNotFound("Nodes not found to distribute the task"); } final Service service = performDistribution(executor, sessionId, taskId, task, remotes, availableNodes, coordinator); return new ForwardingService() { @Override public ListenableFuture<State> start() { ListenableFuture<Nothing> runListener = Futures .makeListenable(executor.submit(new Callable<Nothing>() { @Override public Nothing call() { listener.onDistributionStarted(sessionId, taskId, task, remotes.keySet()); return Nothing.INSTANCE; } })); return Futures.chain(runListener, new Function<Nothing, ListenableFuture<State>>() { @Override public ListenableFuture<State> apply(Nothing input) { return doStart(); } }); } private ListenableFuture<State> doStart() { return super.start(); } @Override protected Service delegate() { return service; } @Override public ListenableFuture<State> stop() { ListenableFuture<State> stop = super.stop(); return Futures.chain(stop, new Function<State, ListenableFuture<State>>() { @Override public ListenableFuture<State> apply(final State input) { final SettableFuture<State> result = SettableFuture.create(); executor.execute(new Runnable() { @Override public void run() { try { listener.onTaskDistributionCompleted(sessionId, taskId, task); } finally { result.set(input); } } }); return result; } }); } }; }
From source file:org.apache.heron.statemgr.localfs.LocalFileSystemStateManager.java
protected ListenableFuture<Boolean> setData(String path, byte[] data, boolean overwrite) { final SettableFuture<Boolean> future = SettableFuture.create(); boolean ret = FileUtils.writeToFile(path, data, overwrite); safeSetFuture(future, ret);/*from w w w. ja va 2 s . c om*/ return future; }
From source file:org.opendaylight.ofconfig.southbound.impl.OdlOfconfigApiServiceImpl.java
@Override public Future<RpcResult<Void>> syncCapcableSwitch(SyncCapcableSwitchInput input) { SettableFuture<RpcResult<Void>> resultFuture = SettableFuture.create(); NodeId nodeId = new NodeId(new Uri(input.getNodeId())); NodeKey nodeKey = new NodeKey(nodeId); InstanceIdentifier<Node> iid = InstanceIdentifier.builder(NetworkTopology.class) .child(Topology.class, new TopologyKey(OfconfigConstants.OFCONFIG_CAPABLE_TOPOLOGY_ID)) .child(Node.class, nodeKey).build(); ReadWriteTransaction rwTx = dataBroker.newReadWriteTransaction(); Node node = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, iid, dataBroker); if (node == null) { RpcResult<Void> result = RpcResultBuilder.<Void>failed() .withError(ErrorType.APPLICATION, input.getNodeId() + " capable switch node dosen't exist") .build();// w w w. ja v a 2s . c om resultFuture.set(result); } else { String netconfId = node.getAugmentation(OfconfigCapableSwitchAugmentation.class) .getOfconfigCapableSwitchAttributes().getNetconfTopologyNodeId(); try { helper.createOfconfigNode(new NodeId(netconfId)); RpcResult<Void> result = RpcResultBuilder.<Void>success().build(); resultFuture.set(result); } catch (Exception e) { LOG.error("Error sync Capcable Switch,capableNodeId:{}, {}", input.getNodeId(), e); RpcResult<Void> result = RpcResultBuilder.<Void>failed() .withError(ErrorType.APPLICATION, input.getNodeId() + " sync capcable switch fail").build(); resultFuture.set(result); } } return resultFuture; }
From source file:io.prestosql.execution.buffer.OutputBufferMemoryManager.java
public synchronized ListenableFuture<?> getBufferBlockedFuture() { if ((isBufferFull() || isBlockedOnMemory()) && bufferBlockedFuture.isDone()) { bufferBlockedFuture = SettableFuture.create(); }//from w ww .ja v a 2 s .c o m return bufferBlockedFuture; }
From source file:io.airlift.drift.client.DriftInvocationHandler.java
private static ListenableFuture<Object> unwrapUserException(ListenableFuture<Object> future) { SettableFuture<Object> result = SettableFuture.create(); Futures.addCallback(future, new FutureCallback<Object>() { @Override/*from ww w.java2s . co m*/ public void onSuccess(Object value) { result.set(value); } @Override public void onFailure(Throwable t) { result.setException(unwrapUserException(t)); } }, directExecutor()); return result; }
From source file:io.crate.executor.transport.AlterTableOperation.java
public ListenableFuture<Long> executeAlterTableAddColumn(final AddColumnAnalyzedStatement analysis) { final SettableFuture<Long> result = SettableFuture.create(); if (analysis.newPrimaryKeys() || analysis.hasNewGeneratedColumns()) { TableIdent ident = analysis.table().ident(); String stmt = String.format(Locale.ENGLISH, "SELECT COUNT(*) FROM \"%s\".\"%s\"", ident.schema(), ident.name());/* w w w . j a v a2 s . com*/ SQLOperations.Session session = sqlOperations.createSession(ident.schema(), Option.NONE, 1); try { session.parse(SQLOperations.Session.UNNAMED, stmt, Collections.<DataType>emptyList()); session.bind(SQLOperations.Session.UNNAMED, SQLOperations.Session.UNNAMED, Collections.emptyList(), null); session.execute(SQLOperations.Session.UNNAMED, 1, new ResultSetReceiver(analysis, result)); session.sync(); } catch (Throwable t) { result.setException(t); } } else { addColumnToTable(analysis, result); } return result; }
From source file:org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator.java
private NetconfDeviceCommunicator(final RemoteDeviceId id, final RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> remoteDevice, final Optional<UserPreferences> overrideNetconfCapabilities, final int rpcMessageLimit) { this.concurentRpcMsgs = rpcMessageLimit; this.id = id; this.remoteDevice = remoteDevice; this.overrideNetconfCapabilities = overrideNetconfCapabilities; this.firstConnectionFuture = SettableFuture.create(); this.semaphore = rpcMessageLimit > 0 ? new Semaphore(rpcMessageLimit) : null; }