@Override public void handleError(Exception exception) { jobManagerFuture = Futures.failed(exception); }
@Override public Future<byte[]> recover(Throwable failure) throws Throwable { if (failure instanceof UnknownKvStateID || failure instanceof UnknownKvStateKeyGroupLocation || failure instanceof UnknownKvStateLocation || failure instanceof ConnectException) { // These failures are likely to be caused by out-of-sync // KvStateLocation. Therefore we retry this query and // force look up the location. return getKvState( jobId, queryableStateName, keyHashCode, serializedKeyAndNamespace, true); } else { return Futures.failed(failure); } } }, executionContext);
@Override public Future<Object> recover(Throwable failure) throws Throwable { if (tries > 0) { LOG.debug("Query state failed with {}. Try to recover. #{} left.", failure, tries - 1); return queryStateFutureWithFailover(tries - 1, queryState); } else { return Futures.failed(failure); } } }, executor);
@Override public Future<ActorSelection> readyTransaction() { LOG.debug("Tx {} readyTransaction called, failure: {}", getIdentifier(), failure); return akka.dispatch.Futures.failed(failure); }
@Override public Future<Object> directCommit() { LOG.debug("Tx {} directCommit called, failure: {}", getIdentifier(), failure); return akka.dispatch.Futures.failed(failure); }
/** * Returns a future holding the serialized request result. * * <p>If the channel has been established, forward the call to the * established channel, otherwise queue it for when the channel is * handed in. * * @param kvStateId ID of the KvState instance to query * @param serializedKeyAndNamespace Serialized key and namespace to query KvState instance * with * @return Future holding the serialized result */ public Future<byte[]> getKvState(KvStateID kvStateId, byte[] serializedKeyAndNamespace) { synchronized (connectLock) { if (failureCause != null) { return Futures.failed(failureCause); } else if (closed) { return Futures.failed(new ClosedChannelException()); } else { if (established != null) { return established.getKvState(kvStateId, serializedKeyAndNamespace); } else { // Queue this and handle when connected PendingRequest pending = new PendingRequest(kvStateId, serializedKeyAndNamespace); queuedRequests.add(pending); return pending.promise.future(); } } } }
private Future<Object> initiateCommit(final boolean immediate) { if(operationError != null) { return Futures.failed(operationError); } final ReadyLocalTransaction message = new ReadyLocalTransaction(transaction.getIdentifier(), modification, immediate); return actorContext.executeOperationAsync(leader, message, actorContext.getTransactionCommitOperationTimeout()); }
return Futures.failed(new IllegalStateException("Shut down"));
public Future<ActorRef> getActorRefFuture(K key) { final int partitionNumber = retrievalService.getPartitionID(key); synchronized (cacheLock) { ActorRef result = cache.get(partitionNumber); if(result != null) { return Futures.successful(result); } } LOG.debug("Retrieve actor URL from retrieval service."); String actorURL = retrievalService.retrieveActorURL(key); if (actorURL == null) { return Futures.failed(new Exception("Could not retrieve actor.")); } else { ActorSelection selection = getContext().system().actorSelection(actorURL); LOG.debug("Resolve actor URL to ActorRef."); Future<ActorRef> actorRefFuture = selection.resolveOne(lookupTimeout); actorRefFuture.onSuccess(new OnSuccess<ActorRef>() { @Override public void onSuccess(ActorRef result) throws Throwable { synchronized (cacheLock) { cache.put(partitionNumber, result); } } }, executor); return actorRefFuture; } }
@Test(expected = SchemaSourceException.class) public void getNonExistingSchemaSource() throws Exception { Futures.failed(new Exception("halo")); Mockito.when(mockedRemoteSchemaRepository.getYangTextSchemaSource(ID)).thenReturn( Futures.failed( new SchemaSourceException("Source not provided"))); CheckedFuture<?, ?> sourceFuture = remoteSchemaProvider.getSource(ID); assertTrue(sourceFuture.isDone()); sourceFuture.checkedGet(); } }
public EmailSenderActor(EmailSender emailSender) { receive(ReceiveBuilder.match(EmailSenderMsg.class, msg -> { try { emailSender.send(msg.to, msg.cc, msg.ci, msg.object, msg.content, msg.htmlContent, msg.attachments); } catch (RuntimeException e) { LOGGER.error("Unable to sent email to '{}', with subject '{}': {}", Arrays.toString(msg.to.toArray()), msg.object, e); sender().tell(Futures.failed(e), self()); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Email sent to '{}' with subject '{}'", Arrays.toString(msg.to.toArray()), msg.object); } getContext().stop(self()); }).matchAny(this::unhandled).build()); }
@Override public Future<byte[]> apply(KvStateLocation lookup) { int keyGroupIndex = KeyGroupRangeAssignment.computeKeyGroupForKeyHash(keyHashCode, lookup.getNumKeyGroups()); KvStateServerAddress serverAddress = lookup.getKvStateServerAddress(keyGroupIndex); if (serverAddress == null) { return Futures.failed(new UnknownKvStateKeyGroupLocation()); } else { // Query server KvStateID kvStateId = lookup.getKvStateID(keyGroupIndex); return kvStateClient.getKvState(serverAddress, kvStateId, serializedKeyAndNamespace); } } }, executionContext);