use of akka.actor.Address in project controller by opendaylight.
the class RemoteRpcRegistryMXBeanImpl method findRpcByName.
@Override
public Map<String, String> findRpcByName(final String name) {
RoutingTable localTable = getLocalData();
// Get all RPCs from local bucket
Map<String, String> rpcMap = new HashMap<>(getRpcMemberMapByName(localTable, name, LOCAL_CONSTANT));
// Get all RPCs from remote bucket
Map<Address, Bucket<RoutingTable>> buckets = getRemoteBuckets();
for (Entry<Address, Bucket<RoutingTable>> entry : buckets.entrySet()) {
RoutingTable table = entry.getValue().getData();
rpcMap.putAll(getRpcMemberMapByName(table, name, entry.getKey().toString()));
}
log.debug("list of RPCs {} searched by name {}", rpcMap, name);
return rpcMap;
}
use of akka.actor.Address in project controller by opendaylight.
the class BucketStoreActor method getBucketsByMembers.
/**
* Helper to collect buckets for requested members.
*
* @param members requested members
*/
private void getBucketsByMembers(final Collection<Address> members) {
Map<Address, Bucket<T>> buckets = new HashMap<>();
// first add the local bucket if asked
if (members.contains(selfAddress)) {
buckets.put(selfAddress, getLocalBucket().snapshot());
}
// then get buckets for requested remote nodes
for (Address address : members) {
if (remoteBuckets.containsKey(address)) {
buckets.put(address, remoteBuckets.get(address));
}
}
getSender().tell(buckets, getSelf());
}
use of akka.actor.Address in project controller by opendaylight.
the class BucketStoreActor method actorTerminated.
private void actorTerminated(final Terminated message) {
LOG.info("Actor termination {} received", message);
for (Address addr : watchedActors.removeAll(message.getActor())) {
versions.remove(addr);
final Bucket<T> bucket = remoteBuckets.remove(addr);
if (bucket != null) {
LOG.debug("Source actor dead, removing bucket {} from ", bucket, addr);
onBucketRemoved(addr, bucket);
}
}
}
use of akka.actor.Address in project controller by opendaylight.
the class BucketStoreActor method updateRemoteBuckets.
/**
* Update local copy of remote buckets where local copy's version is older.
*
* @param receivedBuckets buckets sent by remote
* {@link org.opendaylight.controller.remote.rpc.registry.gossip.Gossiper}
*/
@VisibleForTesting
void updateRemoteBuckets(final Map<Address, Bucket<?>> receivedBuckets) {
LOG.debug("{}: receiveUpdateRemoteBuckets: {}", selfAddress, receivedBuckets);
if (receivedBuckets == null || receivedBuckets.isEmpty()) {
// nothing to do
return;
}
final Map<Address, Bucket<T>> newBuckets = new HashMap<>(receivedBuckets.size());
for (Entry<Address, Bucket<?>> entry : receivedBuckets.entrySet()) {
final Address addr = entry.getKey();
if (selfAddress.equals(addr)) {
// Remote cannot update our bucket
continue;
}
@SuppressWarnings("unchecked") final Bucket<T> receivedBucket = (Bucket<T>) entry.getValue();
if (receivedBucket == null) {
LOG.debug("Ignoring null bucket from {}", addr);
continue;
}
// update only if remote version is newer
final long remoteVersion = receivedBucket.getVersion();
final Long localVersion = versions.get(addr);
if (localVersion != null && remoteVersion <= localVersion.longValue()) {
LOG.debug("Ignoring down-versioned bucket from {} ({} local {} remote)", addr, localVersion, remoteVersion);
continue;
}
newBuckets.put(addr, receivedBucket);
versions.put(addr, remoteVersion);
final Bucket<T> prevBucket = remoteBuckets.put(addr, receivedBucket);
// Deal with DeathWatch subscriptions
final Optional<ActorRef> prevRef = prevBucket != null ? prevBucket.getWatchActor() : Optional.empty();
final Optional<ActorRef> curRef = receivedBucket.getWatchActor();
if (!curRef.equals(prevRef)) {
prevRef.ifPresent(ref -> removeWatch(addr, ref));
curRef.ifPresent(ref -> addWatch(addr, ref));
}
LOG.debug("Updating bucket from {} to version {}", entry.getKey(), remoteVersion);
}
LOG.debug("State after update - Local Bucket [{}], Remote Buckets [{}]", localBucket, remoteBuckets);
onBucketsUpdated(newBuckets);
}
use of akka.actor.Address in project flink by apache.
the class BootstrapTools method startWebMonitorIfConfigured.
/**
* Starts the web frontend.
* @param config The Flink config.
* @param actorSystem The ActorSystem to start the web frontend in.
* @param logger Logger for log output
* @return WebMonitor instance.
* @throws Exception
*/
public static WebMonitor startWebMonitorIfConfigured(Configuration config, ActorSystem actorSystem, ActorRef jobManager, Logger logger) throws Exception {
// this ensures correct values are present in the web frontend
final Address address = AkkaUtils.getAddress(actorSystem);
config.setString(ConfigConstants.JOB_MANAGER_IPC_ADDRESS_KEY, address.host().get());
config.setString(ConfigConstants.JOB_MANAGER_IPC_PORT_KEY, address.port().get().toString());
if (config.getInteger(ConfigConstants.JOB_MANAGER_WEB_PORT_KEY, 0) >= 0) {
logger.info("Starting JobManager Web Frontend");
LeaderRetrievalService leaderRetrievalService = LeaderRetrievalUtils.createLeaderRetrievalService(config, jobManager);
// start the web frontend. we need to load this dynamically
// because it is not in the same project/dependencies
WebMonitor monitor = WebMonitorUtils.startWebRuntimeMonitor(config, leaderRetrievalService, actorSystem);
// start the web monitor
if (monitor != null) {
String jobManagerAkkaURL = AkkaUtils.getAkkaURL(actorSystem, jobManager);
monitor.start(jobManagerAkkaURL);
}
return monitor;
} else {
return null;
}
}
Aggregations