Package com.jme3.network.service
Class AbstractHostedConnectionService
java.lang.Object
com.jme3.network.service.AbstractService<HostedServiceManager>
com.jme3.network.service.AbstractHostedService
com.jme3.network.service.AbstractHostedConnectionService
- All Implemented Interfaces:
ConnectionListener
,HostedService
,Service<HostedServiceManager>
- Direct Known Subclasses:
RpcHostedService
Convenient base class for HostedServices providing some default HostedService
interface implementations as well as a few convenience methods
such as getServiceManager() and getService(type). This implementation
enhances the default capabilities provided by AbstractHostedService by
adding automatic connection management.
Subclasses must at least override the onInitialize(), startHostingOnConnection(), and stopHostingOnConnection() methods to handle service and connection initialization.
An autoHost flag controls whether startHostingOnConnection() is called automatically when new connections are detected. If autoHost is false then it is up to the implementation or application to specifically start hosting at some point.
-
Constructor Summary
ModifierConstructorDescriptionprotected
Creates a new HostedService that will autohost connections when detected.protected
AbstractHostedConnectionService
(boolean autoHost) Creates a new HostedService that will automatically host connections only if autoHost is true. -
Method Summary
Modifier and TypeMethodDescriptionvoid
connectionAdded
(Server server, HostedConnection hc) Called internally when a new connection is detected for the server.void
connectionRemoved
(Server server, HostedConnection hc) Called internally when an existing connection is leaving the server.boolean
Returns true if this service automatically attaches hosting capabilities to new connections.void
setAutoHost
(boolean b) When set to true, all new connections will automatically have hosting services attached to them by calling startHostingOnConnection().abstract void
Performs implementation specific connection hosting setup.abstract void
Performs implementation specific connection tear-down.Methods inherited from class com.jme3.network.service.AbstractHostedService
getServer
Methods inherited from class com.jme3.network.service.AbstractService
getService, getServiceManager, initialize, onInitialize, start, stop, terminate, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.jme3.network.service.HostedService
initialize, start, stop, terminate
-
Constructor Details
-
AbstractHostedConnectionService
protected AbstractHostedConnectionService()Creates a new HostedService that will autohost connections when detected. -
AbstractHostedConnectionService
protected AbstractHostedConnectionService(boolean autoHost) Creates a new HostedService that will automatically host connections only if autoHost is true.
-
-
Method Details
-
setAutoHost
public void setAutoHost(boolean b) When set to true, all new connections will automatically have hosting services attached to them by calling startHostingOnConnection(). If this is set to false then it is up to the application or other services to eventually call startHostingOnConnection().Reasons for doing this vary but usually would be because the client shouldn't be allowed to perform any service-related calls until it has provided more information... for example, logging in.
-
getAutoHost
public boolean getAutoHost()Returns true if this service automatically attaches hosting capabilities to new connections. -
startHostingOnConnection
Performs implementation specific connection hosting setup. Generally this involves setting up some handlers or session attributes on the connection. If autoHost is true then this method is called automatically during connectionAdded() processing. -
stopHostingOnConnection
Performs implementation specific connection tear-down. This will be called automatically when the connectionRemoved() event occurs... whether the application has already called it or not. -
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:
connectionAdded
in interfaceConnectionListener
- Overrides:
connectionAdded
in classAbstractHostedService
-
connectionRemoved
Called internally when an existing connection is leaving the server. This method always calls stopHostingOnConnection(hc). Implementations should be aware that if they stopHostingOnConnection() early that they will get a second call when the connection goes away.- Specified by:
connectionRemoved
in interfaceConnectionListener
- Overrides:
connectionRemoved
in classAbstractHostedService
-