private Task<NodeAddress> locateActiveActor(final RemoteReference<?> actorReference) { final NodeAddress address = localAddressCache.getIfPresent(actorReference); if (address != null && activeNodes.containsKey(address)) { return Task.fromValue(address); } // try to locate the actor in the distributed directory // this can be expensive, less that activating the actor, though return Task.fromValue(getDistributedDirectory().get(createRemoteKey(actorReference))); }
@Override public List<NodeAddress> getAllNodes() { if (hosting == null) { return Collections.emptyList(); } return hosting.getAllNodes(); }
/** * Uses consistent hashing to determine this node is the "owner" of a certain key. * * @param key * @return true if this node is assigned to "own" the key. */ public boolean isConsistentHashOwner(final String key) { final NodeAddress owner = getConsistentHashOwner(key); return clusterPeer.localAddress().equals(owner); }
hosting = new Hosting(localAddressCacheMaximumSize, localAddressCacheTTL); }); hosting.setNodeType(mode == StageMode.HOST ? NodeCapabilities.NodeTypeEnum.SERVER : NodeCapabilities.NodeTypeEnum.CLIENT); execution.setRuntime(this); execution.setObjects(objects); hosting.setStage(this); hosting.setClusterPeer(clusterPeer); .findFirst() .orElse(new RandomSelectorExtension()); hosting.setNodeSelector(nodeSelector); hosting.setTargetPlacementGroups(Collections.singleton(placementGroup)); messaging.start(); logger.debug("Starting hosting..."); hosting.start(); logger.debug("Starting execution..."); execution.start();
private Task<NodeAddress> locateAndActivateActor(final RemoteReference<?> actorReference) final RemoteKey remoteKey = createRemoteKey(actorReference); if (shouldPlaceLocally(interfaceClass)) return selectNode(interfaceClass.getName()); final ConcurrentMap<RemoteKey, NodeAddress> distributedDirectory = getDistributedDirectory(); if (shouldPlaceLocally(interfaceClass)) Task<NodeAddress> nodeAddressTask = nodeAddress != null ? Task.fromValue(nodeAddress) : selectNode(interfaceClass.getName());
for (int i = 0; i < 10; i++) final String hash = getHash(addrHexStr + ":" + i); newHashes.put(hash, nodeInfo); updateServerNodes();
waitForServers(); waitForServers(); final NodeInfo nodeInfo = nodeSelector.select(interfaceClassName, getNodeAddress(), suitableNodes); return Task.fromValue(nodeInfo.address);
private Task onInvocation(final HandlerContext ctx, final Invocation invocation) final NodeAddress localAddress = getNodeAddress(); return locateActor(invocation.getToReference(), true) .whenComplete((r, e) -> { if (e != null)
public List<NodeAddress> getServerNodes() { if (hosting == null) { return Collections.emptyList(); } return hosting.getServerNodes(); }
@Override public NodeAddress getLocalAddress() { return hosting.getNodeAddress(); }
/** * Uses consistent hashing to determine the "owner" of a certain key. * * @param key * @return the NodeAddress of the node that's supposed to own the key. */ public NodeAddress getConsistentHashOwner(final String key) { final String keyHash = getHash(key); final TreeMap<String, NodeInfo> currentHashes = consistentHashNodeTree; Map.Entry<String, NodeInfo> info = currentHashes.ceilingEntry(keyHash); if (info == null) { info = currentHashes.firstEntry(); } return info.getValue().address; }
hosting.actorDeactivated(actorEntry.getRemoteReference());
stage.getHosting().canActivate(c.getName()).join();
public boolean canActivateActor(final String interfaceName) { if (getState() != NodeCapabilities.NodeState.RUNNING) { // todo, improve this if (hosting.getServerNodes().size() > 1) { return false; } } Class<Actor> aInterface = InternalUtils.classForName(interfaceName, true); if (aInterface == null) { return false; } final Class<?> concreteClass = finder.findActorImplementation(aInterface); return concreteClass != null; }
@Override public <T extends ActorObserver> T registerObserver(Class<T> iClass, String id, final T observer) { final RemoteReference<T> reference = objects.getOrAddLocalObjectReference(hosting.getNodeAddress(), iClass, id, observer); RemoteReference.setRuntime(reference, this); //noinspection unchecked return iClass != null ? iClass.cast(reference) : (T) reference; }
public void actorDeactivated(RemoteReference remoteReference) { // removing the reference from the cluster directory and local caches getDistributedDirectory().remove(createRemoteKey(remoteReference), clusterPeer.localAddress()); localAddressCache.invalidate(remoteReference); if(stage.getBroadcastActorDeactivations()) { for (final NodeInfo info : activeNodes.values()) { if (!info.address.equals(clusterPeer.localAddress()) && info.state == NodeState.RUNNING) { info.nodeCapabilities.remove(remoteReference); } } } }