Class AbstractService<S extends ServiceManager>

java.lang.Object
com.jme3.network.service.AbstractService<S>
Type Parameters:
S - the service manager type
All Implemented Interfaces:
Service<S>
Direct Known Subclasses:
AbstractClientService, AbstractHostedService

public abstract class AbstractService<S extends ServiceManager> extends Object implements Service<S>
Base class providing some default Service interface implementations as well as a few convenience methods such as getServiceManager() and getService(type). Subclasses must at least override the onInitialize() method to handle service initialization.
Author:
Paul Speed
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates an uninitialized service.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected <T extends Service<S>>
    T
    getService(Class<T> type)
    Retrieves the first sibling service of the specified type.
    protected S
    Returns the ServiceManager that was passed to initialize() during service initialization.
    final void
    initialize(S serviceManager)
    Initializes this service by keeping a reference to the service manager and calling onInitialize().
    protected abstract void
    onInitialize(S serviceManager)
    Called during initialize() for the subclass to perform implementation specific initialization.
    void
    Default implementation does nothing.
    void
    Default implementation does nothing.
    void
    terminate(S serviceManager)
    Default implementation does nothing.
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • AbstractService

      protected AbstractService()
      Creates an uninitialized service.
  • Method Details

    • getServiceManager

      protected S getServiceManager()
      Returns the ServiceManager that was passed to initialize() during service initialization.
      Returns:
      the owning service manager, or null if not yet initialized
    • getService

      protected <T extends Service<S>> T getService(Class<T> type)
      Retrieves the first sibling service of the specified type.
      Type Parameters:
      T - the requested service type
      Parameters:
      type - the class of the service to look up
      Returns:
      the first matching sibling service, or null if none is registered
    • initialize

      public final void initialize(S serviceManager)
      Initializes this service by keeping a reference to the service manager and calling onInitialize().
      Specified by:
      initialize in interface Service<S extends ServiceManager>
      Parameters:
      serviceManager - the manager that is initializing this service
    • onInitialize

      protected abstract void onInitialize(S serviceManager)
      Called during initialize() for the subclass to perform implementation specific initialization.
      Parameters:
      serviceManager - the service manager initializing this service
    • start

      public void start()
      Default implementation does nothing. Implementations can override this to perform custom startup behavior.
      Specified by:
      start in interface Service<S extends ServiceManager>
    • stop

      public void stop()
      Default implementation does nothing. Implementations can override this to perform custom stop behavior.
      Specified by:
      stop in interface Service<S extends ServiceManager>
    • terminate

      public void terminate(S serviceManager)
      Default implementation does nothing. Implementations can override this to perform custom termination behavior.
      Specified by:
      terminate in interface Service<S extends ServiceManager>
      Parameters:
      serviceManager - the manager that is terminating this service
    • toString

      public String toString()
      Overrides:
      toString in class Object