protected AbstractActor() { this.createDefaultState(); }
@Override public Task<?> deactivateAsync() { local.values().forEach(r -> r.dispose()); local.clear(); return super.deactivateAsync(); } }
/** * Creates a default state representation for this actor */ @SuppressWarnings({ "PMD.LooseCoupling", "unchecked" }) protected void createDefaultState() { final Class<?> c = getStateClass(); try { final Object newState = c.newInstance(); this.state = (T) newState; } catch (final Exception e) { throw new UncheckedException(e); } }
await(actor.readState()); await(actor.activateAsync());
@Override public Task<?> activateAsync() { getLogger().debug("activated"); // registering the local timers. return super.activateAsync().thenRun( () -> state.reminders.forEach(r -> registerLocalTimer(r))); }
/** * Registers a single shot timer for the current actor. The timer is automatically disposed on deactivation. * The timer calls will not keep the actor active. Timer calls are serialized according to the actor policy. * Each stateless actor activation has it's on set of timers. * * @param futureCallable a callable that returns a Task * @param dueTime Time to the first timer call * @param timeUnit Time unit for dueTime and period * @return A registration object that allows the actor to cancel the timer. */ protected Registration registerTimer(Callable<Task<?>> futureCallable, long dueTime, TimeUnit timeUnit) { return registerTimer(futureCallable, dueTime, 0L, timeUnit); }
@Override public Task<?> activateAsync() { if (getLogger().isDebugEnabled()) { getLogger().debug("Activating stream: {}", getIdentity()); } await(super.activateAsync()); int size = state().subscribers.size(); // check if each subscriber is still alive. await(Task.allOf(state().subscribers.entrySet().stream() .map(entry -> checkAlive(entry.getKey(), entry.getValue())))); if (size != state().subscribers.size()) { return writeState(); } return Task.done(); }
/** * Registers a single shot timer for the current actor. The timer is automatically disposed on deactivation. * The timer calls will not keep the actor active. Timer calls are serialized according to the actor policy. * Each stateless actor activation has it's on set of timers. * * @param futureCallable a callable that returns a Task * @param dueTime Time to the first timer call * @param timeUnit Time unit for dueTime and period * @return A registration object that allows the actor to cancel the timer. */ protected Registration registerTimer(Callable<Task<?>> futureCallable, long dueTime, TimeUnit timeUnit) { return registerTimer(futureCallable, dueTime, 0L, timeUnit); }
@Override public Task<?> deactivateAsync() { await(super.deactivateAsync()); /* int size = state().subscribers.size(); // check if each subscriber is still alive. await(Task.allOf(state().subscribers.entrySet().stream() .map(entry -> checkAlive(entry.getKey(), entry.getValue())))); if (state().subscribers.isEmpty()) { return clearState(); } else if (size != state().subscribers.size()) { return writeState(); } */ if (state().subscribers.isEmpty()) { return clearState(); } return Task.done(); }
protected AbstractActor() { this.createDefaultState(); }
/** * Creates a default state representation for this actor */ @SuppressWarnings({ "PMD.LooseCoupling", "unchecked" }) protected void createDefaultState() { final Class<?> c = getStateClass(); try { final Object newState = c.newInstance(); this.state = (T) newState; } catch (final Exception e) { throw new UncheckedException(e); } }
protected Task<Void> deactivate(final T actor) { await(Task.allOf(runtime.getAllExtensions(LifetimeExtension.class).stream().map(v -> v.preDeactivation(actor)))); try { await(actor.deactivateAsync()); } catch (final Throwable ex) { getLogger().error("Error on actor " + reference + " deactivation", ex); } clearTimers(); await(clearStreamSubscriptions()); await(Task.allOf(runtime.getAllExtensions(LifetimeExtension.class).stream().map(v -> v.postDeactivation(actor)))); return Task.done(); }