Class ServiceManager<T>

java.lang.Object
com.jme3.network.service.ServiceManager<T>
Type Parameters:
T - the parent type exposed to managed services
Direct Known Subclasses:
ClientServiceManager, HostedServiceManager

public abstract class ServiceManager<T> extends Object
The base service manager class from which the HostedServiceManager and ClientServiceManager classes are derived. This manages the underlying services and their life cycles.
Author:
Paul Speed
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates a service manager.
  • Method Summary

    Modifier and Type
    Method
    Description
    <S extends Service<T>>
    void
    Adds the specified service and initializes it.
    protected abstract T
    Retrieves the 'parent' of this service manager, usually a more specifically typed version of 'this' but it can be anything the services are expecting.
    <S extends Service<T>>
    S
    getService(Class<S> type)
    Retrieves the first service of the specified type.
    protected List<Service<T>>
    Returns the complete list of services managed by this service manager.
    boolean
    Returns true if this service manager has been started.
    <S extends Service<T>>
    void
    Removes the specified service from this service manager, stopping and terminating it as required.
    void
    Starts this service manager and all services that it contains.
    void
    Stops all services and puts the service manager into a stopped state.
    void
    Terminates all services.
     

    Methods inherited from class Object

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

    • ServiceManager

      protected ServiceManager()
      Creates a service manager.
  • Method Details

    • getParent

      protected abstract T getParent()
      Retrieves the 'parent' of this service manager, usually a more specifically typed version of 'this' but it can be anything the services are expecting.
      Returns:
      the parent object exposed to managed services
    • getServices

      protected List<Service<T>> getServices()
      Returns the complete list of services managed by this service manager. This list is thread safe following the CopyOnWriteArrayList semantics.
      Returns:
      the managed services list
    • start

      public void start()
      Starts this service manager and all services that it contains. Any services added after the service manager has started will have their start() methods called.
    • isStarted

      public boolean isStarted()
      Returns true if this service manager has been started.
      Returns:
      true if the manager is started
    • stop

      public void stop()
      Stops all services and puts the service manager into a stopped state.
    • addService

      public <S extends Service<T>> void addService(S s)
      Adds the specified service and initializes it. If the service manager has already been started then the service will also be started.
      Type Parameters:
      S - the concrete service type
      Parameters:
      s - the service to add
    • removeService

      public <S extends Service<T>> void removeService(S s)
      Removes the specified service from this service manager, stopping and terminating it as required. If this service manager is in a started state then the service will be stopped. After removal, the service will be terminated.
      Type Parameters:
      S - the concrete service type
      Parameters:
      s - the service to remove
    • terminate

      public void terminate()
      Terminates all services. If the service manager has not been stopped yet, then it will be stopped.
    • getService

      public <S extends Service<T>> S getService(Class<S> type)
      Retrieves the first service of the specified type.
      Type Parameters:
      S - the concrete service type
      Parameters:
      type - the service class to look up
      Returns:
      the first matching service, or null if none exists
    • toString

      public String toString()
      Overrides:
      toString in class Object