private void scheduleTimeoutMessage(ActorContext context, TimeoutMessage message, long delay) { context.system() .scheduler() .scheduleOnce( Duration.create(delay, TimeUnit.MILLISECONDS), context.self(), message, context.dispatcher(), context.self()); }
private void applyRedirectionRule(RedirectionRule body) { context() .system() .scheduler() .scheduleOnce(Duration.create(body.ruleTTL, TimeUnit.MILLISECONDS), self(), new RuleTimeoutMessage(body.getRuleId()), context().dispatcher(), self()); redirectionRules.put(body.getRuleId(), body); }
void scheduleTimeoutMessage(ActorContext context, EndpointEvent event) { context.system() .scheduler() .scheduleOnce(Duration.create(getTtl(event), TimeUnit.MILLISECONDS), context.self(), new EndpointEventTimeoutMessage(event), context.dispatcher(), context.self()); }
/** * Returns the execution context associated with this actor. To be used by futures. In unit tests, should be mocked * by a SimpleExecutionContext. * * @return Execution context. */ @Nonnull public ExecutionContext executionContext() { return context.dispatcher(); }
@Override public void onSuccess(Void result) { LOG.warn("Delete part of update succesfull, triggering create"); // trigger create on all nodes Futures.addCallback(selfProxy.onNodeCreated(nodeId, node), new FutureCallback<Node>() { @Override public void onSuccess(Node result) { createFuture.set(result); } @Override public void onFailure(Throwable t) { createFuture.setException(t); } }, context.dispatcher()); }
@Override public Future<Long> doAsyncReadHighestSequenceNr( final String processorId, long fromSequenceNr ) { return Futures.future( new Callable<Long>() { @Override public Long call() throws Exception { TreeMap<Long, PersistentRepr> map = (TreeMap<Long, PersistentRepr>) persistentMap( processorId ); if ( map.isEmpty() ) { return 0L; } return map.lastKey(); } }, context().dispatcher() ); }
@Override public Future<Void> doAsyncReplayMessages( final String processorId, final long fromSequenceNr, final long toSequenceNr, final long max, final Procedure<PersistentRepr> replayCallback ) { return Futures.future( new Callable<Void>() { @Override public Void call() throws Exception { Map<Long, PersistentRepr> replayMap = Maps.filterValues( persistentMap( processorId ), new Predicate<PersistentRepr>() { @Override public boolean apply( PersistentRepr message ) { if ( message.sequenceNr() >= fromSequenceNr && message.sequenceNr() <= toSequenceNr ) { return true; } return false; } } ); int count = 0; for ( PersistentRepr message : replayMap.values() ) { if ( count++ < max ) { replayCallback.apply( message ); } } return null; } }, context().dispatcher() ); }
@Override public void saveSnapshot() { final String simpleName = getClass().getSimpleName(); log.info("{} Saving snapshot for event {}", simpleName, latestJournalidReceived); final byte[] data = serializeData(); log.info("{} serialized data, storing to db", simpleName); context().dispatcher().execute(() -> { try { MongoCollection<Document> collection = mongodatabase.getCollection("snapshot"); if (latestJournalidReceived != null) { final String fileid = UUID.randomUUID().toString(); collection.updateOne(new Document("_id", getId()), new Document("$set", new Document("jid", latestJournalidReceived).append("dataVersion", getSnapshotDataVersion()).append("projectionId", simpleName).append("fileid", fileid)), new UpdateOptions().upsert(true)); saveDataToGridFS(data, fileid); log.info("{} Saved snapshot for event {}", simpleName, latestJournalidReceived); } } catch (Exception e) { log.error("Failed to write snapshot", e); } }); }
@Override public void saveSnapshot() { final String simpleName = getClass().getSimpleName(); log.info("{} Saving snapshot for event {}", simpleName, latestJournalidReceived); final byte[] data = serializeData(); log.info("{} serialized data, storing to db", simpleName); context().dispatcher().execute(() -> { try { MongoCollection<Document> collection = mongodatabase.getCollection("snapshot"); if (latestJournalidReceived != 0) { final String fileid = UUID.randomUUID().toString(); collection.updateOne(new Document("_id", getId()), new Document("$set", new Document("jid", latestJournalidReceived).append("dataVersion", getSnapshotDataVersion()).append("projectionId", simpleName).append("fileid", fileid)), new UpdateOptions().upsert(true)); saveDataToGridFS(data, fileid); log.info("{} Saved snapshot for event {}", simpleName, latestJournalidReceived); } } catch (Exception e) { log.error("Failed to write snapshot", e); } }); }
}, TypedActor.context().dispatcher());
LOG.warn("Delete part of update failed, {}", t); }, context.dispatcher()); return createFuture;
private void scheduleCheckForThingActivity() { log.debug("Scheduling for activity check in <{}> seconds.", activityCheckInterval.getSeconds()); // send a message to ourself: activityChecker = context().system().scheduler() .scheduleOnce(Duration.create(activityCheckInterval.getSeconds(), TimeUnit.SECONDS), self(), new CheckForActivity(sequenceNumber), context().dispatcher(), null); }
private void scheduleCheckForThingActivity() { log.debug("Scheduling for activity check in <{}> seconds.", activityCheckInterval.getSeconds()); // send a message to ourself: activityChecker = context().system().scheduler() .scheduleOnce(Duration.create(activityCheckInterval.getSeconds(), TimeUnit.SECONDS), self(), new CheckForActivity(sequenceNumber), context().dispatcher(), null); }
private Cancellable scheduleOnce(final FiniteDuration when, final Object message, final ActorRef sender) { return persistenceActor.context() .system() .scheduler() .scheduleOnce(when, persistenceActor.self(), message, persistenceActor.context().dispatcher(), sender); }
private Cancellable scheduleOnce(final FiniteDuration when, final Object message, final ActorRef sender) { return persistenceActor.context() .system() .scheduler() .scheduleOnce(when, persistenceActor.self(), message, persistenceActor.context().dispatcher(), sender); }
private <T> Future<T> transform(final Future<Object> future) { final Promise<T> promise = new scala.concurrent.impl.Promise.DefaultPromise<>(); future.onComplete(new OnComplete<Object>() { @Override public void onComplete(final Throwable failure, final Object success) { if (success instanceof Throwable) { promise.failure((Throwable) success); return; } if (success == Void.TYPE) { promise.success(null); return; } promise.success((T) success); } }, context().dispatcher()); return promise.future(); }
}, context().dispatcher());
}, context().dispatcher());
}, context().dispatcher());
}, context().dispatcher());