@SuppressWarnings("unchecked") public static <T> T cast(Class<T> remoteInterface, Actor actor) { return (T) Proxy.newProxyInstance(DefaultDescriptorFactory.class.getClassLoader(), new Class[]{ remoteInterface }, (proxy, method, args) -> { // TODO: throw proper exceptions for the expected error scenarios (non task return), final int methodId = instance.dynamicReferenceFactory.getMethodId(method); return ActorRuntime.getRuntime() .invoke(RemoteReference.from(actor), method, method.isAnnotationPresent(OneWay.class), methodId, args); }); } }
public static Task<Void> flushAll(Actor actor) { final List<NodeAddress> nodes = ActorRuntime.getRuntime().getAllNodes(); return Task.allOf(nodes.stream() .map(nodeAddress -> DefaultDescriptorFactory.observerRef(nodeAddress, ExecutionCacheFlushObserver.class, "").flush(actor))); } }
/** * Requests the global actor count across the cluster. * * @return A task indicating containing the total actor count across the cluster. */ static Task<Long> getClusterActorCount() { final List<Task<Long>> countList = ActorRuntime.getRuntime().getAllNodes().stream() .map(address -> { final RuntimeActions runtimeActions = DefaultDescriptorFactory.observerRef(address, RuntimeActions.class, ""); return runtimeActions.getActorCount(); }) .collect(Collectors.toList()); await(Task.allOf(countList)); final Long actorCount = countList.stream() .mapToLong(Task<Long>::join) .sum(); return Task.fromValue(actorCount); }
private Task<Boolean> checkAlive(final String handle, final SimpleStreamProxy subscriber) { final ActorRuntime runtime = ActorRuntime.getRuntime(); final NodeAddress r = await(runtime.locateActor((Addressable) subscriber, false)); if (r == null) { state().subscribers.remove(handle); return Task.fromValue(Boolean.FALSE); } return Task.fromValue(Boolean.TRUE); }
private void registerLocalTimer(final ReminderEntry reminderEntry) { // adjusting start date. long dueTime = reminderEntry.getStartAt().getTime() - ActorRuntime.getRuntime().clock().millis(); if (dueTime < 0) { dueTime = reminderEntry.getPeriod() + (dueTime % reminderEntry.getPeriod()); } final Registration localData = registerTimer(() -> callRemainder(reminderEntry), dueTime, reminderEntry.getPeriod(), TimeUnit.MILLISECONDS); local.put(reminderEntry, localData); }
/** * Requests the deactivation of an actor * * @param actor the actor which you want to deactivate. * @return A task indicating the state of the request. Immediately resolved if actor is not activated. */ static Task deactivate(final Actor actor) { final NodeAddress address = await(ActorRuntime.getRuntime().locateActor(RemoteReference.from(actor), false)); if(address != null) { final RuntimeActions runtimeActions = DefaultDescriptorFactory.observerRef(address, RuntimeActions.class, ""); return runtimeActions.deactivateActor(actor); } return Task.done(); }
@Override public Object copy(Kryo kryo, Object original) { if (original instanceof RemoteReference) { final RemoteReference<?> remoteReference = (RemoteReference<?>) original; if (RemoteReference.getRuntime(remoteReference) != null) { return DefaultDescriptorFactory.get().getReference(null, RemoteReference.getAddress(remoteReference), RemoteReference.getInterfaceClass(remoteReference), RemoteReference.getId(remoteReference)); } return original; } return ActorRuntime.getRuntime().registerObserver(null, (ActorObserver) original); }
@SuppressWarnings("unchecked") public static <T> T cast(Class<T> remoteInterface, Actor actor) { return (T) Proxy.newProxyInstance(DefaultDescriptorFactory.class.getClassLoader(), new Class[]{ remoteInterface }, (proxy, method, args) -> { // TODO: throw proper exceptions for the expected error scenarios (non task return), final int methodId = instance.dynamicReferenceFactory.getMethodId(method); return ActorRuntime.getRuntime() .invoke(RemoteReference.from(actor), method, method.isAnnotationPresent(OneWay.class), methodId, args); }); } }
public static Task<Void> flushAll(Actor actor) { final List<NodeAddress> nodes = ActorRuntime.getRuntime().getAllNodes(); return Task.allOf(nodes.stream() .map(nodeAddress -> DefaultDescriptorFactory.observerRef(nodeAddress, ExecutionCacheFlushObserver.class, "").flush(actor))); } }
/** * Requests the global actor count across the cluster. * * @return A task indicating containing the total actor count across the cluster. */ static Task<Long> getClusterActorCount() { final List<Task<Long>> countList = ActorRuntime.getRuntime().getAllNodes().stream() .map(address -> { final RuntimeActions runtimeActions = DefaultDescriptorFactory.observerRef(address, RuntimeActions.class, ""); return runtimeActions.getActorCount(); }) .collect(Collectors.toList()); await(Task.allOf(countList)); final Long actorCount = countList.stream() .mapToLong(Task<Long>::join) .sum(); return Task.fromValue(actorCount); }
/** * Requests the deactivation of an actor * * @param actor the actor which you want to deactivate. * @return A task indicating the state of the request. Immediately resolved if actor is not activated. */ static Task deactivate(final Actor actor) { final NodeAddress address = await(ActorRuntime.getRuntime().locateActor(RemoteReference.from(actor), false)); if(address != null) { final RuntimeActions runtimeActions = DefaultDescriptorFactory.observerRef(address, RuntimeActions.class, ""); return runtimeActions.deactivateActor(actor); } return Task.done(); }