Package com.yahoo.messagebus.network
Class NetworkMultiplexer
- java.lang.Object
-
- com.yahoo.messagebus.network.NetworkMultiplexer
-
- All Implemented Interfaces:
NetworkOwner
public class NetworkMultiplexer extends java.lang.Object implements NetworkOwner
A bridge between the reusable, singleton RPC network, and the generational message bus which uses this. The RPC network is required to be singular because of its unique resources, such as sockets. This is complicated by the message bus potentially existing in different graph generation at any point in time, with all copies potential users of the network interface, but where each message bus-registered session should belong to a single message bus. This class solves these problems by tracking which sessions are active in which message bus instance, and by (de)registering only when a session is registered to (no) message bus instances. In time, this should allow us to get rid of the shared-this-and-that in the container, too ...- Author:
- jonmv
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
attach(NetworkOwner owner)
Attach the network owner to this, allowing this to forward messages to it.static NetworkMultiplexer
dedicated(Network net)
Returns a network multiplexer with a singleNetworkOwner
, which shuts down when this owner detaches.void
deliverMessage(Message message, java.lang.String session)
All messages that arrive in the network layer is passed to its owner through this function.void
detach(NetworkOwner owner)
Detach the network owner from this, no longer allowing messages to it, and shutting down this is ownerless.void
disown()
Signal that external ownership of this is relinquished, allowing destruction on last owner detachment.Protocol
getProtocol(com.yahoo.text.Utf8Array name)
All messages are sent across the network with its accompanying protocol name so that it can be decoded at the receiving end.Network
net()
void
registerSession(java.lang.String session, NetworkOwner owner, boolean broadcast)
static NetworkMultiplexer
shared(Network net)
Returns a network multiplexer which will be shared between severalNetworkOwner
s, and will shut down when all these have detached, anddisown()
has been called, in any order.java.lang.String
toString()
void
unregisterSession(java.lang.String session, NetworkOwner owner, boolean broadcast)
-
-
-
Method Detail
-
shared
public static NetworkMultiplexer shared(Network net)
Returns a network multiplexer which will be shared between severalNetworkOwner
s, and will shut down when all these have detached, anddisown()
has been called, in any order.
-
dedicated
public static NetworkMultiplexer dedicated(Network net)
Returns a network multiplexer with a singleNetworkOwner
, which shuts down when this owner detaches.
-
registerSession
public void registerSession(java.lang.String session, NetworkOwner owner, boolean broadcast)
-
unregisterSession
public void unregisterSession(java.lang.String session, NetworkOwner owner, boolean broadcast)
-
getProtocol
public Protocol getProtocol(com.yahoo.text.Utf8Array name)
Description copied from interface:NetworkOwner
All messages are sent across the network with its accompanying protocol name so that it can be decoded at the receiving end. The network queries its owner through this function to resolve the protocol from its name.- Specified by:
getProtocol
in interfaceNetworkOwner
- Parameters:
name
- The name of the protocol to return.- Returns:
- The named protocol.
-
deliverMessage
public void deliverMessage(Message message, java.lang.String session)
Description copied from interface:NetworkOwner
All messages that arrive in the network layer is passed to its owner through this function.- Specified by:
deliverMessage
in interfaceNetworkOwner
- Parameters:
message
- The message that just arrived from the network.session
- The name of the session that is the recipient of the request.
-
attach
public void attach(NetworkOwner owner)
Attach the network owner to this, allowing this to forward messages to it.
-
detach
public void detach(NetworkOwner owner)
Detach the network owner from this, no longer allowing messages to it, and shutting down this is ownerless.
-
disown
public void disown()
Signal that external ownership of this is relinquished, allowing destruction on last owner detachment.
-
net
public Network net()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-