本文整理汇总了Java中scala.concurrent.Promise.failure方法的典型用法代码示例。如果您正苦于以下问题:Java Promise.failure方法的具体用法?Java Promise.failure怎么用?Java Promise.failure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scala.concurrent.Promise
的用法示例。
在下文中一共展示了Promise.failure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: moveToLocation
import scala.concurrent.Promise; //导入方法依赖的package包/类
@Override
final protected void moveToLocation(Promise<Void> v, double latitude, double longitude, double altitude) {
synchronized (navigationLock) {
if (navigationState.getRawValue() == NavigationState.IN_PROGRESS) {
v.failure(new DroneException("Already navigating to " + getNavigator().getGoal() + ", abort this first."));
} else if (navigationState.getRawValue() == NavigationState.UNAVAILABLE) {
v.failure(new DroneException("Unable to navigate to goal"));
} else if (!gpsFix.getRawValue()) {
v.failure(new DroneException("No GPS fix yet."));
} else {
getNavigator().setCurrentLocation(location.getRawValue());
getNavigator().setGoal(new Location(latitude, longitude, altitude));
setNavigationState(NavigationState.IN_PROGRESS, NavigationStateReason.REQUESTED);
v.success(null);
}
}
}
示例2: prematureExit
import scala.concurrent.Promise; //导入方法依赖的package包/类
private <T> boolean prematureExit(Promise<T> p) {
if(connectionLost) {
return true;
}
if(!initialized) {
p.failure(new DroneException("Failed to send command. Not initialized yet."));
return true;
}
if(crashed) {
p.failure(new DroneException("Drone crashed, unable to execute commands"));
return true;
}
return false;
}
示例3: sendCommand
import scala.concurrent.Promise; //导入方法依赖的package包/类
private void sendCommand(Promise<Void> p, Serializable command) {
if (sendMessage(command)) {
p.success(null);
} else {
p.failure(new DroneException("Failed to send command. Not initialized yet."));
}
}
示例4: takeOff
import scala.concurrent.Promise; //导入方法依赖的package包/类
@Override
protected void takeOff(Promise<Void> p) {
//TODO: only return when status changes to taking off promises
if (sendMessage(new TakeOffCommand())) {
p.success(null);
} else {
p.failure(new DroneException("Failed to send command. Not initialized yet."));
}
}
示例5: move3d
import scala.concurrent.Promise; //导入方法依赖的package包/类
@Override
protected void move3d(Promise<Void> p, double vx, double vy, double vz, double vr) {
if (sendMessage(new MoveCommand(vx, vy, vz, vr))) {
p.success(null); //ack the command
} else {
p.failure(new DroneException("Failed to send command. Not initialized yet."));
}
}
示例6: setMaxTilt
import scala.concurrent.Promise; //导入方法依赖的package包/类
@Override
protected void setMaxTilt(Promise<Void> p, float degrees) {
if (sendMessage(new SetMaxTiltCommand(degrees))) {
p.success(null);
} else {
p.failure(new DroneException("Failed to send command. Not initialized yet."));
}
}
示例7: setOutdoor
import scala.concurrent.Promise; //导入方法依赖的package包/类
@Override
protected void setOutdoor(Promise<Void> p, boolean outdoor) {
if (sendMessage(new SetOutdoorCommand(outdoor))) {
p.success(null);
} else {
p.failure(new DroneException("Failed to send command. Not initialized yet."));
}
}
示例8: flatTrim
import scala.concurrent.Promise; //导入方法依赖的package包/类
@Override
protected void flatTrim(Promise<Void> p) {
if (sendMessage(new FlatTrimCommand())) {
p.success(null);
} else {
p.failure(new DroneException("Failed to send command. Not initialized yet."));
}
}
示例9: flip
import scala.concurrent.Promise; //导入方法依赖的package包/类
@Override
protected void flip(Promise<Void> p, FlipType type) {
if (sendMessage(new FlipCommand(type))) {
p.success(null);
} else {
p.failure(new DroneException("Failed to send command. Not initialized yet."));
}
}
示例10: initVideo
import scala.concurrent.Promise; //导入方法依赖的package包/类
@Override
protected void initVideo(Promise<Void> p) {
if(sendMessage(new InitVideoCommand())){
p.success(null);
} else {
p.failure(new DroneException("Failed to send command. Not initialized yet."));
}
}
示例11: emergency
import scala.concurrent.Promise; //导入方法依赖的package包/类
@Override
protected void emergency(Promise<Void> p) {
if (connectionLost) return;
// Land
p.failure(new DroneException("action not implemented"));
}
示例12: notifyWaitersOfFailure
import scala.concurrent.Promise; //导入方法依赖的package包/类
protected void notifyWaitersOfFailure(Throwable exception) {
for (Promise<Object> waiter: awaitListeners){
if (!waiter.isCompleted()){
waiter.failure(exception);
}
}
taskList.clear();
}
示例13: handleCallbackException
import scala.concurrent.Promise; //导入方法依赖的package包/类
private void handleCallbackException(final String field,
final SetterFailure onFailure, Throwable exception, Promise<Object> promise) {
if (onFailure != null) {
onFailure.handleFailure(getThis(), field, exception, promise);
} else {
getLogger().error(exception, "Failed without failure handler, falling back.");
}
if (!promise.isCompleted()){
promise.failure(exception);
}
}
示例14: findPrimaryShard
import scala.concurrent.Promise; //导入方法依赖的package包/类
/**
* This method is overridden to ensure the previous Tx's ready operations complete
* before we initiate the next Tx in the chain to avoid creation failures if the
* previous Tx's ready operations haven't completed yet.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected Future<PrimaryShardInfo> findPrimaryShard(final String shardName, final TransactionIdentifier txId) {
// Read current state atomically
final State localState = currentState;
// There are no outstanding futures, shortcut
Future<?> previous = localState.previousFuture();
if (previous == null) {
return combineFutureWithPossiblePriorReadOnlyTxFutures(parent.findPrimaryShard(shardName, txId), txId);
}
final String previousTransactionId;
if (localState instanceof Pending) {
previousTransactionId = ((Pending) localState).getIdentifier().toString();
LOG.debug("Tx: {} - waiting for ready futures with pending Tx {}", txId, previousTransactionId);
} else {
previousTransactionId = "";
LOG.debug("Waiting for ready futures on chain {}", getHistoryId());
}
previous = combineFutureWithPossiblePriorReadOnlyTxFutures(previous, txId);
// Add a callback for completion of the combined Futures.
final Promise<PrimaryShardInfo> returnPromise = Futures.promise();
final OnComplete onComplete = new OnComplete() {
@Override
public void onComplete(final Throwable failure, final Object notUsed) {
if (failure != null) {
// A Ready Future failed so fail the returned Promise.
LOG.error("Tx: {} - ready future failed for previous Tx {}", txId, previousTransactionId);
returnPromise.failure(failure);
} else {
LOG.debug("Tx: {} - previous Tx {} readied - proceeding to FindPrimaryShard",
txId, previousTransactionId);
// Send the FindPrimaryShard message and use the resulting Future to complete the
// returned Promise.
returnPromise.completeWith(parent.findPrimaryShard(shardName, txId));
}
}
};
previous.onComplete(onComplete, getActorContext().getClientDispatcher());
return returnPromise.future();
}
示例15: testJobClientRecovery
import scala.concurrent.Promise; //导入方法依赖的package包/类
/**
* Tests whether the JobClientActor can connect to a newly elected leading job manager to obtain
* the JobExecutionResult. The submitted job blocks for the first execution attempt. The
* leading job manager will be killed so that the second job manager will be elected as the
* leader. The newly elected leader has to retrieve the checkpointed job from ZooKeeper
* and continue its execution. This time, the job does not block and, thus, can be finished.
* The execution result should be sent to the JobClientActor which originally submitted the
* job.
*
* @throws Exception
*/
@Test
public void testJobClientRecovery() throws Exception {
File rootFolder = tempFolder.getRoot();
Configuration config = ZooKeeperTestUtils.createZooKeeperHAConfig(
zkServer.getConnectString(),
rootFolder.getPath());
config.setInteger(ConfigConstants.LOCAL_NUMBER_JOB_MANAGER, 2);
config.setInteger(ConfigConstants.LOCAL_NUMBER_TASK_MANAGER, 1);
final TestingCluster cluster = new TestingCluster(config);
cluster.start();
JobVertex blockingVertex = new JobVertex("Blocking Vertex");
blockingVertex.setInvokableClass(BlockingTask.class);
blockingVertex.setParallelism(1);
final JobGraph jobGraph = new JobGraph("Blocking Test Job", blockingVertex);
final Promise<JobExecutionResult> promise = new scala.concurrent.impl.Promise.DefaultPromise<>();
Deadline deadline = new FiniteDuration(2, TimeUnit.MINUTES).fromNow();
try {
Thread submitter = new Thread(new Runnable() {
@Override
public void run() {
try {
JobExecutionResult result = cluster.submitJobAndWait(jobGraph, false);
promise.success(result);
} catch (Exception e) {
promise.failure(e);
}
}
});
submitter.start();
synchronized (BlockingTask.waitLock) {
while (BlockingTask.HasBlockedExecution < 1 && deadline.hasTimeLeft()) {
BlockingTask.waitLock.wait(deadline.timeLeft().toMillis());
}
}
if (deadline.isOverdue()) {
Assert.fail("The job has not blocked within the given deadline.");
}
ActorGateway gateway = cluster.getLeaderGateway(deadline.timeLeft());
gateway.tell(TestingJobManagerMessages.getDisablePostStop());
gateway.tell(PoisonPill.getInstance());
// if the job fails then an exception is thrown here
Await.result(promise.future(), deadline.timeLeft());
} finally {
cluster.stop();
}
}