Class DistributedPubSubMediator
- java.lang.Object
- 
- akka.cluster.pubsub.DistributedPubSubMediator
 
- 
- All Implemented Interfaces:
- Actor,- ActorLogging,- PerGroupingBuffer
 
 public class DistributedPubSubMediator extends java.lang.Object implements Actor, ActorLogging, PerGroupingBuffer This actor manages a registry of actor references and replicates the entries to peer actors among all cluster nodes or a group of nodes tagged with a specific role.The DistributedPubSubMediatoractor is supposed to be started on all nodes, or all nodes with specified role, in the cluster. The mediator can be started with theDistributedPubSubextension or as an ordinary actor.Changes are only performed in the own part of the registry and those changes are versioned. Deltas are disseminated in a scalable way to other nodes with a gossip protocol. The registry is eventually consistent, i.e. changes are not immediately visible at other nodes, but typically they will be fully replicated to all other nodes after a few seconds. You can send messages via the mediator on any node to registered actors on any other node. There is three modes of message delivery. 1. DistributedPubSubMediator.Send- The message will be delivered to one recipient with a matching path, if any such exists in the registry. If several entries match the path the message will be sent via the suppliedroutingLogic(default random) to one destination. The sender of the message can specify that local affinity is preferred, i.e. the message is sent to an actor in the same local actor system as the used mediator actor, if any such exists, otherwise route to any other matching entry. A typical usage of this mode is private chat to one other user in an instant messaging application. It can also be used for distributing tasks to registered workers, like a cluster aware router where the routees dynamically can register themselves.2. DistributedPubSubMediator.SendToAll- The message will be delivered to all recipients with a matching path. Actors with the same path, without address information, can be registered on different nodes. On each node there can only be one such actor, since the path is unique within one local actor system. Typical usage of this mode is to broadcast messages to all replicas with the same path, e.g. 3 actors on different nodes that all perform the same actions, for redundancy.3. DistributedPubSubMediator.Publish- Actors may be registered to a named topic instead of path. This enables many subscribers on each node. The message will be delivered to all subscribers of the topic. For efficiency the message is sent over the wire only once per node (that has a matching topic), and then delivered to all subscribers of the local topic representation. This is the true pub/sub mode. A typical usage of this mode is a chat room in an instant messaging application.4. DistributedPubSubMediator.Publishwith sendOneMessageToEachGroup - Actors may be subscribed to a named topic with an optional propertygroup. If subscribing with a group name, each message published to a topic with thesendOneMessageToEachGroupflag is delivered via the suppliedroutingLogic(default random) to one actor within each subscribing group. If all the subscribed actors have the same group name, then this works just likeDistributedPubSubMediator.Sendand all messages are delivered to one subscribe. If all the subscribed actors have different group names, then this works like normalDistributedPubSubMediator.Publishand all messages are broadcast to all subscribers.You register actors to the local mediator with DistributedPubSubMediator.PutorDistributedPubSubMediator.Subscribe.Putis used together withSendandSendToAllmessage delivery modes. TheActorRefinPutmust belong to the same local actor system as the mediator.Subscribeis used together withPublish. Actors are automatically removed from the registry when they are terminated, or you can explicitly remove entries withDistributedPubSubMediator.RemoveorDistributedPubSubMediator.Unsubscribe.Successful SubscribeandUnsubscribeis acknowledged withDistributedPubSubMediator.SubscribeAckandDistributedPubSubMediator.UnsubscribeAckreplies.Not intended for subclassing by user code. 
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from interface akka.actor.ActorActor.emptyBehavior$, Actor.ignoringBehavior$
 
- 
 - 
Constructor SummaryConstructors Constructor Description DistributedPubSubMediator(DistributedPubSubSettings settings)
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidakka$actor$Actor$_setter_$context_$eq(ActorContext x$1)Scala API: Stores the context for this actor, including self, and sender.protected voidakka$actor$Actor$_setter_$self_$eq(ActorRef x$1)The 'self' field holds the ActorRef for this actor.Clustercluster()scala.collection.immutable.Iterable<akka.cluster.pubsub.DistributedPubSubMediator.Internal.Bucket>collectDelta(scala.collection.immutable.Map<Address,java.lang.Object> otherVersions)ActorContextcontext()Scala API: Stores the context for this actor, including self, and sender.longdeltaCount()voiddeltaCount_$eq(long x$1)static DistributedPubSubMediator.CountgetCountInstance()Java API: Send this message to the mediator and it will reply with anIntegerof the number of subscribers.scala.collection.immutable.Set<java.lang.String>getCurrentTopics()static DistributedPubSubMediator.GetTopicsgetTopicsInstance()Java API: Send this message to the mediator and it will reply withDistributedPubSubMediator.CurrentTopicscontaining the names of the (currently known) registered topic names.voidgossip()Gossip to peer nodes.CancellablegossipTask()voidgossipTo(Address address)booleanmatchingRole(Member m)java.lang.StringmkKey(ActorPath path)java.lang.StringmkKey(ActorRef ref)scala.collection.immutable.Map<Address,java.lang.Object>myVersions()ActorRefnewTopicActor(java.lang.String encTopic)scala.Function0<java.lang.Object>nextVersion()scala.collection.immutable.Set<Address>nodes()voidnodes_$eq(scala.collection.immutable.Set<Address> x$1)booleanotherHasNewerVersions(scala.collection.immutable.Map<Address,java.lang.Object> otherVersions)voidpostStop()User overridable callback.voidpreStart()User overridable callback.static Propsprops(DistributedPubSubSettings settings)Scala API: Factory method forDistributedPubSubMediatorProps.voidprune()scala.concurrent.duration.FiniteDurationpruneInterval()CancellablepruneTask()voidpublish(java.lang.String path, java.lang.Object msg, boolean allButSelf)booleanpublish$default$3()voidpublishToEachGroup(java.lang.String path, java.lang.Object msg)voidput(java.lang.String key, scala.Option<ActorRef> valueOption)scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit>receive()Scala API: This defines the initial actor behavior, it must return a partial function with the actor logic.voidregisterTopic(ActorRef ref)scala.collection.immutable.Map<Address,akka.cluster.pubsub.DistributedPubSubMediator.Internal.Bucket>registry()voidregistry_$eq(scala.collection.immutable.Map<Address,akka.cluster.pubsub.DistributedPubSubMediator.Internal.Bucket> x$1)longremovedTimeToLiveMillis()scala.Option<Address>selectRandomNode(scala.collection.immutable.IndexedSeq<Address> addresses)ActorRefself()The 'self' field holds the ActorRef for this actor.- 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface akka.actor.ActoraroundPostRestart, aroundPostStop, aroundPreRestart, aroundPreStart, aroundReceive, postRestart, preRestart, sender, supervisorStrategy, unhandled
 - 
Methods inherited from interface akka.actor.ActorLogging_log_$eq, log
 - 
Methods inherited from interface akka.cluster.pubsub.PerGroupingBufferbufferOr, forwardMessages, forwardMessages, initializeGrouping, recreateAndForwardMessagesIfNeeded
 
- 
 
- 
- 
- 
Constructor Detail- 
DistributedPubSubMediatorpublic DistributedPubSubMediator(DistributedPubSubSettings settings) 
 
- 
 - 
Method Detail- 
propspublic static Props props(DistributedPubSubSettings settings) Scala API: Factory method forDistributedPubSubMediatorProps.
 - 
getTopicsInstancepublic static DistributedPubSubMediator.GetTopics getTopicsInstance() Java API: Send this message to the mediator and it will reply withDistributedPubSubMediator.CurrentTopicscontaining the names of the (currently known) registered topic names.
 - 
getCountInstancepublic static DistributedPubSubMediator.Count getCountInstance() Java API: Send this message to the mediator and it will reply with anIntegerof the number of subscribers.
 - 
contextpublic ActorContext context() Description copied from interface:ActorScala API: Stores the context for this actor, including self, and sender. It is implicit to support operations such asforward.WARNING: Only valid within the Actor itself, so do not close over it and publish it to other threads! ActorContextis the Scala API.getContextreturns aAbstractActor.ActorContext, which is the Java API of the actor context.
 - 
selfpublic final ActorRef self() Description copied from interface:ActorThe 'self' field holds the ActorRef for this actor. Can be used to send messages to itself:self ! message 
 - 
akka$actor$Actor$_setter_$context_$eqprotected void akka$actor$Actor$_setter_$context_$eq(ActorContext x$1) Description copied from interface:ActorScala API: Stores the context for this actor, including self, and sender. It is implicit to support operations such asforward.WARNING: Only valid within the Actor itself, so do not close over it and publish it to other threads! ActorContextis the Scala API.getContextreturns aAbstractActor.ActorContext, which is the Java API of the actor context.- Specified by:
- akka$actor$Actor$_setter_$context_$eqin interface- Actor
 
 - 
akka$actor$Actor$_setter_$self_$eqprotected final void akka$actor$Actor$_setter_$self_$eq(ActorRef x$1) Description copied from interface:ActorThe 'self' field holds the ActorRef for this actor. Can be used to send messages to itself:self ! message - Specified by:
- akka$actor$Actor$_setter_$self_$eqin interface- Actor
 
 - 
clusterpublic Cluster cluster() 
 - 
removedTimeToLiveMillispublic long removedTimeToLiveMillis() 
 - 
gossipTaskpublic Cancellable gossipTask() 
 - 
pruneIntervalpublic scala.concurrent.duration.FiniteDuration pruneInterval() 
 - 
pruneTaskpublic Cancellable pruneTask() 
 - 
registrypublic scala.collection.immutable.Map<Address,akka.cluster.pubsub.DistributedPubSubMediator.Internal.Bucket> registry() 
 - 
registry_$eqpublic void registry_$eq(scala.collection.immutable.Map<Address,akka.cluster.pubsub.DistributedPubSubMediator.Internal.Bucket> x$1) 
 - 
nodespublic scala.collection.immutable.Set<Address> nodes() 
 - 
nodes_$eqpublic void nodes_$eq(scala.collection.immutable.Set<Address> x$1) 
 - 
deltaCountpublic long deltaCount() 
 - 
deltaCount_$eqpublic void deltaCount_$eq(long x$1) 
 - 
nextVersionpublic scala.Function0<java.lang.Object> nextVersion() 
 - 
preStartpublic void preStart() Description copied from interface:ActorUser overridable callback. Is called when an Actor is started. Actors are automatically started asynchronously when created. Empty default implementation.
 - 
postStoppublic void postStop() Description copied from interface:ActorUser overridable callback. Is called asynchronously after 'actor.stop()' is invoked. Empty default implementation.
 - 
matchingRolepublic boolean matchingRole(Member m) 
 - 
receivepublic scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receive() Description copied from interface:ActorScala API: This defines the initial actor behavior, it must return a partial function with the actor logic.
 - 
publishpublic void publish(java.lang.String path, java.lang.Object msg, boolean allButSelf)
 - 
publish$default$3public boolean publish$default$3() 
 - 
publishToEachGrouppublic void publishToEachGroup(java.lang.String path, java.lang.Object msg)
 - 
putpublic void put(java.lang.String key, scala.Option<ActorRef> valueOption)
 - 
getCurrentTopicspublic scala.collection.immutable.Set<java.lang.String> getCurrentTopics() 
 - 
registerTopicpublic void registerTopic(ActorRef ref) 
 - 
mkKeypublic java.lang.String mkKey(ActorRef ref) 
 - 
mkKeypublic java.lang.String mkKey(ActorPath path) 
 - 
myVersionspublic scala.collection.immutable.Map<Address,java.lang.Object> myVersions() 
 - 
collectDeltapublic scala.collection.immutable.Iterable<akka.cluster.pubsub.DistributedPubSubMediator.Internal.Bucket> collectDelta(scala.collection.immutable.Map<Address,java.lang.Object> otherVersions) 
 - 
otherHasNewerVersionspublic boolean otherHasNewerVersions(scala.collection.immutable.Map<Address,java.lang.Object> otherVersions) 
 - 
gossippublic void gossip() Gossip to peer nodes.
 - 
gossipTopublic void gossipTo(Address address) 
 - 
selectRandomNodepublic scala.Option<Address> selectRandomNode(scala.collection.immutable.IndexedSeq<Address> addresses) 
 - 
prunepublic void prune() 
 - 
newTopicActorpublic ActorRef newTopicActor(java.lang.String encTopic) 
 
- 
 
-