Package com.yahoo.messagebus.network.rpc
Class RPCNetwork
- java.lang.Object
-
- com.yahoo.messagebus.network.rpc.RPCNetwork
-
- All Implemented Interfaces:
com.yahoo.jrt.MethodHandler
,Network
- Direct Known Subclasses:
TestServer.VersionedRPCNetwork
public class RPCNetwork extends java.lang.Object implements Network, com.yahoo.jrt.MethodHandler
An RPC implementation of the Network interface.- Author:
- Haavard Pettersen
-
-
Constructor Summary
Constructors Constructor Description RPCNetwork(RPCNetworkParams params)
Create an RPCNetwork.RPCNetwork(RPCNetworkParams params, SlobrokConfigSubscriber slobrokConfig)
Create an RPCNetwork.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
allocServiceAddress(RoutingNode recipient)
Resolves the service address of the recipient referenced by the given routing node.void
attach(NetworkOwner owner)
Attach the network layer to the given ownerboolean
destroy()
Sets the destroyed flag to true.protected void
flushTargetPool()
The network uses a cache of RPC targets (seeRPCTargetPool
) that allows it to save time by reusing open connections.void
freeServiceAddress(RoutingNode recipient)
Frees the service address from the given routing node.java.lang.String
getConnectionSpec()
Returns a string that represents the connection specs of this network.Identity
getIdentity()
Returns the identity of this network.com.yahoo.jrt.slobrok.api.IMirror
getMirror()
Returns a reference to a name server mirror.int
getPort()
Obtain the port number this network listens toRPCSendAdapter
getSendAdapter(com.yahoo.component.Version version)
Determines and returns the send adapter that is compatible with the given version.protected com.yahoo.component.Version
getVersion()
Returns the version of this network.void
invoke(com.yahoo.jrt.Request request)
void
registerSession(java.lang.String session)
Register a session name with the network layer.Error
resolveServiceAddress(RoutingNode recipient, java.lang.String serviceName)
Resolves and assigns a service address for the given recipient using the given address.void
send(Message msg, java.util.List<RoutingNode> recipients)
Send a message to the given recipients.void
shutdown()
Shuts down the network.void
sync()
Synchronize with internal threads.void
unregisterSession(java.lang.String session)
Unregister a session name with the network layer.boolean
waitUntilReady(double seconds)
Waits for at most the given number of seconds for all dependencies to become ready.
-
-
-
Constructor Detail
-
RPCNetwork
public RPCNetwork(RPCNetworkParams params, SlobrokConfigSubscriber slobrokConfig)
Create an RPCNetwork. The servicePrefix is combined with session names to create service names. If the service prefix is 'a/b' and the session name is 'c', the resulting service name that identifies the session on the message bus will be 'a/b/c'- Parameters:
params
- A complete set of parameters.slobrokConfig
- subscriber for slobroks config
-
RPCNetwork
public RPCNetwork(RPCNetworkParams params)
Create an RPCNetwork. The servicePrefix is combined with session names to create service names. If the service prefix is 'a/b' and the session name is 'c', the resulting service name that identifies the session on the message bus will be 'a/b/c'- Parameters:
params
- A complete set of parameters.
-
-
Method Detail
-
flushTargetPool
protected void flushTargetPool()
The network uses a cache of RPC targets (seeRPCTargetPool
) that allows it to save time by reusing open connections. It works by keeping a set of the most recently used targets open. Calling this method forces all unused connections to close immediately.
-
waitUntilReady
public boolean waitUntilReady(double seconds)
Description copied from interface:Network
Waits for at most the given number of seconds for all dependencies to become ready.- Specified by:
waitUntilReady
in interfaceNetwork
- Parameters:
seconds
- The timeout.- Returns:
- True if ready.
-
allocServiceAddress
public boolean allocServiceAddress(RoutingNode recipient)
Description copied from interface:Network
Resolves the service address of the recipient referenced by the given routing node. If a recipient can not be resolved, this method tags the node with an error. If this method succeeds, you need to invokeNetwork.freeServiceAddress(RoutingNode)
once you are done with the service address.- Specified by:
allocServiceAddress
in interfaceNetwork
- Parameters:
recipient
- The node whose service address to allocate.- Returns:
- True if a service address was allocated.
-
freeServiceAddress
public void freeServiceAddress(RoutingNode recipient)
Description copied from interface:Network
Frees the service address from the given routing node. This allows the network layer to track and close connections as required.- Specified by:
freeServiceAddress
in interfaceNetwork
- Parameters:
recipient
- The node whose service address to free.
-
attach
public void attach(NetworkOwner owner)
Description copied from interface:Network
Attach the network layer to the given owner
-
registerSession
public void registerSession(java.lang.String session)
Description copied from interface:Network
Register a session name with the network layer. This will make the session visible to other nodes.- Specified by:
registerSession
in interfaceNetwork
- Parameters:
session
- the session name
-
unregisterSession
public void unregisterSession(java.lang.String session)
Description copied from interface:Network
Unregister a session name with the network layer. This will make the session unavailable for other nodes.- Specified by:
unregisterSession
in interfaceNetwork
- Parameters:
session
- session name
-
sync
public void sync()
Description copied from interface:Network
Synchronize with internal threads. This method will handshake with all internal threads. This has the implicit effect of waiting for all active callbacks. Note that this method should never be invoked from a callback since that would make the thread wait for itself... forever. This method is typically used to untangle during session shutdown.
-
shutdown
public void shutdown()
Description copied from interface:Network
Shuts down the network. This is a blocking call that waits for all scheduled tasks to complete.
-
getConnectionSpec
public java.lang.String getConnectionSpec()
Description copied from interface:Network
Returns a string that represents the connection specs of this network. It is in not a complete address since it know nothing of the sessions that run on it.- Specified by:
getConnectionSpec
in interfaceNetwork
- Returns:
- The connection string.
-
getMirror
public com.yahoo.jrt.slobrok.api.IMirror getMirror()
Description copied from interface:Network
Returns a reference to a name server mirror.
-
invoke
public void invoke(com.yahoo.jrt.Request request)
- Specified by:
invoke
in interfacecom.yahoo.jrt.MethodHandler
-
send
public void send(Message msg, java.util.List<RoutingNode> recipients)
Description copied from interface:Network
Send a message to the given recipients. ARoutingNode
contains all the necessary context for sending.
-
destroy
public boolean destroy()
Sets the destroyed flag to true. The very first time this method is called, it cleans up all its dependencies. Even if you retain a reference to this object, all of its content is allowed to be garbage collected.- Returns:
- True if content existed and was destroyed.
-
getVersion
protected com.yahoo.component.Version getVersion()
Returns the version of this network. This gets called when the "mbus.getVersion" method is invoked on this network, and is separated into its own function so that unit tests can override it to simulate other versions than current.- Returns:
- The version to claim to be.
-
resolveServiceAddress
public Error resolveServiceAddress(RoutingNode recipient, java.lang.String serviceName)
Resolves and assigns a service address for the given recipient using the given address. This is called by theallocServiceAddress(RoutingNode)
method. The target allocated here is released when the routing node callsfreeServiceAddress(RoutingNode)
.- Parameters:
recipient
- The recipient to assign the service address to.serviceName
- The name of the service to resolve.- Returns:
- Any error encountered, or null.
-
getSendAdapter
public RPCSendAdapter getSendAdapter(com.yahoo.component.Version version)
Determines and returns the send adapter that is compatible with the given version. If no adapter can be found, this method returns null.- Parameters:
version
- The version for which to return an adapter.- Returns:
- The compatible adapter.
-
getIdentity
public Identity getIdentity()
Returns the identity of this network.- Returns:
- The identity.
-
getPort
public int getPort()
Obtain the port number this network listens to- Returns:
- listening port number
-
-