Class RmiHostedService
- All Implemented Interfaces:
ConnectionListener,HostedService,Service<HostedServiceManager>
Objects are shared by adding them to the RmiRegistry with one of the share() methods. Shared objects must have a separate interface and implementation. The interface is what the other end of the connection will use to interact with the object and that interface class must be available on both ends of the connection. The implementing class need only be on the sharing end.
Shared objects can be accessed on the other end of the connection by using one of the RmiRegistry's getRemoteObject() methods. These can be used to lookup an object by class if it is a shared singleton or by name if it was registered with a name.
On the hosting side, a special shardGlobal() method is provided that will register shared objects that will automatically be provided to every new joining client and they will all be calling the same server-side instance. Normally, shared objects themselves are connection specific and handled at the connection layer. The shareGlobal() space is a way to have global resources passed directly though the need is relatively rare.
Note: This RMI implementation is not as advanced as Java's regular RMI as it won't marshall shared references, ie: you can't pass a shared objects as an argument to another shared object's method.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionRmiHostedService(byte defaultChannel) RmiHostedService(short rmiId, byte defaultChannel, boolean autoHost) -
Method Summary
Modifier and TypeMethodDescriptionvoidconnectionAdded(Server server, HostedConnection hc) Called internally when a new connection is detected for the server.voidconnectionRemoved(Server server, HostedConnection hc) Called internally when an existing connection is leaving the server.booleanReturns true if RMI hosting is automatically started for all new connections.Returns the RMI registry for the specific HostedConnection.protected voidCalled during initialize() for the subclass to perform implementation specific initialization.voidsetAutoHost(boolean b) Set to true if all new connections should automatically have RMI hosting started.<T> voidshareGlobal(byte channel, String name, T object, Class<? super T> type) Shares a server-wide object associated with the specified name over the specified channel.<T> voidshareGlobal(String name, T object, Class<? super T> type) Shares a server-wide object associated with the specified name.<T> voidshareGlobal(T object, Class<? super T> type) Shares a server-wide object associated with the specified type.voidSets up RMI hosting services for the hosted connection allowing getRmiRegistry() to return a valid RmiRegistry object.voidRemoves any RMI hosting services associated with the specified connection.Methods inherited from class com.jme3.network.service.AbstractHostedService
getServerMethods inherited from class com.jme3.network.service.AbstractService
getService, getServiceManager, initialize, start, stop, terminate, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.jme3.network.service.HostedService
initialize, start, stop, terminate
-
Field Details
-
ATTRIBUTE_NAME
- See Also:
-
-
Constructor Details
-
RmiHostedService
public RmiHostedService() -
RmiHostedService
public RmiHostedService(byte defaultChannel) -
RmiHostedService
public RmiHostedService(short rmiId, byte defaultChannel, boolean autoHost)
-
-
Method Details
-
setAutoHost
public void setAutoHost(boolean b) Set to true if all new connections should automatically have RMI hosting started. Set to false if the game-specific connection setup will call startHostingOnConnection() after some connection setup is done (for example, logging in). Note: generally is safe to autohost RMI as long as callers are careful about what they've added using shareGlobal(). One reasonable use-case is to shareGlobal() some kind of login service and nothing else. All other shared objects would then be added as connection-specific objects during successful login processing. -
getAutoHost
public boolean getAutoHost()Returns true if RMI hosting is automatically started for all new connections. -
getRmiRegistry
Returns the RMI registry for the specific HostedConnection. Each connection has its own registry with its own connection-specific shared objects. -
startHostingOnConnection
Sets up RMI hosting services for the hosted connection allowing getRmiRegistry() to return a valid RmiRegistry object. This method is called automatically for all new connections if autohost is set to true. -
stopHostingOnConnection
Removes any RMI hosting services associated with the specified connection. Calls to getRmiRegistry() will return null for this connection. This method is called automatically for all leaving connections if autohost is set to true. -
onInitialize
Description copied from class:AbstractServiceCalled during initialize() for the subclass to perform implementation specific initialization.- Specified by:
onInitializein classAbstractService<HostedServiceManager>
-
connectionAdded
Called internally when a new connection is detected for the server. If the current autoHost property is true then startHostingOnConnection(hc) is called.- Specified by:
connectionAddedin interfaceConnectionListener- Overrides:
connectionAddedin classAbstractHostedService
-
connectionRemoved
Called internally when an existing connection is leaving the server. If the current autoHost property is true then stopHostingOnConnection(hc) is called.- Specified by:
connectionRemovedin interfaceConnectionListener- Overrides:
connectionRemovedin classAbstractHostedService