org.licas.service

## Class ServiceMediator

- java.lang.Object
- - java.lang.Thread
  - - org.licas.module.LicasModule
    - - org.licas.module.FrameworkModule
      - - org.licas.module.ServiceModule
        - - org.licas.Service
          - - org.licas.service.ServiceMediator

- All Implemented Interfaces:
    java.lang.AutoCloseable, java.lang.Runnable, ServiceDef
  Direct Known Subclasses:
    InformationMediator

      public abstract class ServiceMediator
      extends Service

  This is the base class for mediating between the services that are created and running on a single server. It provides capabilities for evaluating centrally, the information sources and any related problem solver classes. There is a default implementation called `InformationMediator` and you should use the `DefaultSolverFactory.createMediator` method to return an instance of the service.
  Author:
    Kieran Greer

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class java.lang.Thread

      `java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.lang.String` | `serverIP` Only the server ip address, for example, 'http://123.4.5.6:8888'
    `protected org.licas_xml.abs.Element` | `serverUri` The server url address
    `protected ServiceSpec` | `serviceSpec` The service specification
    `protected java.lang.Object` | `syncOn` To synchronize on

    - ### Fields inherited from class org.licas.Service

      `canAccessMeta, canAccessNested, dm, finalised, isRemoteCall, messageStore, serviceAdmin, serviceGrade, serviceInitialise, serviceLinks, serviceState, sm, toLoadScript`

    - ### Fields inherited from class org.licas.module.ServiceModule

      `shutDown`

    - ### Fields inherited from class org.licas.module.FrameworkModule

      `passwordHandler, service, serviceType`

    - ### Fields inherited from class org.licas.module.LicasModule

      `jarFile, uuid`

    - ### Fields inherited from class java.lang.Thread

      `MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ServiceMediator(PasswordHandler thePasswordHandler)` Create a new instance of ServiceMediator.
    `ServiceMediator(java.lang.String thisPassword, java.lang.String thisAdminKey, PasswordHandler thePasswordHandler)` Creates a new instance of ServiceMediator.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `createAssociationLinks(java.util.HashMap<java.lang.String,java.util.ArrayList<java.util.ArrayList<java.lang.String>>> serviceGroups)` Create association links between each key service and the list it is related to.
    `void` | `createPermanentLinks(java.util.HashMap<java.lang.String,java.util.ArrayList<java.util.ArrayList<java.lang.String>>> serviceGroups)` Create permanent links between each key service and the list it is related to.
    `abstract void` | `createServices(java.lang.String serviceType)` Create the services and initialise as defined by the script.
    `org.licas_xml.abs.Element` | `dynamicLinksToXml()` Get the list of all dynamic links created on each service.
    `java.util.ArrayList<java.lang.String>` | `getLinkedServiceUuids()` Get the list of uuids only of all services currently linked to through dynamic links, with the `source` uuid added only once, but the `linked to` uuid added the number of times it occurs.
    `void` | `initialiseInfo(ServiceSpec theServiceSpec)` Initialise the information mediator with password details.
    `abstract boolean` | `initialiseServerInfo(ServiceSpec serviceSpec)` Initialise the solver mediator with the server details.
    `abstract void` | `initialiseServices(java.lang.String serviceType)` Initialise the services, primarily adding and initialising linking structures if they are included.
    `void` | `startServices(java.lang.String serviceType)` Start the threads of all services of the specified service type.
    `void` | `updateDynamicLinks(java.util.HashMap<java.lang.String,java.util.ArrayList<java.util.ArrayList<java.lang.String>>> serviceGroups, boolean toPermanent)` Update dynamic links for the services that are grouped together.

    - ### Methods inherited from class org.licas.Service

      `addCommunicationID, addDefaultService, addDefaultService, addDefaultService, addDefaultService, addLinkFromService, addLinkToService, addMessageMetrics, addService, addService, addService, addService, addServiceAssociation, addServicePassword, addTempPassword, allowAddService, canAccess, canAccess, canAccess, canAccess, canAccessMeta, canAccessNested, canAccessTemp, canRun, classNameOK, clearServiceLinks, clearServices, clearServices, close, createMetaForRepos, createMetaFull, createPermanentLinkTo, createServiceWrapper, defaultAdminToRemove, dynamicLinkQuery, dynamicLinksToPermanent, dynamicLinksToXml, execute, finaliseInitialisation, finaliseInitialisation, finaliseModule, finaliseThisConfig, GET, getAllLinkToService, getAllowAddService, getAutonomicManagerConfig, getCommunicationClientURI, getData, getData, getDescription, getFullPath, getInstanceValue, getIsRemoteCall, getLinkFromService, getLinkToService, getLocalRemoteID, getParent, getParent, getPassword, getPassword, getPassword, getPasswordHandler, getPrivateMethods, getPublicMethods, getPublicServiceClassname, getServerPassword, getService, getService, getServiceAdmin, getServiceClasses, getServiceGrade, getServiceLinks, getServiceNames, getServiceNames, getServiceNames, getServiceNumber, getServiceOrWrapper, getServiceState, getServiceType, getServiceTypes, handshake, hasCommunicationID, hasLinkTo, hasServerPassword, hasService, hasServiceType, interrupt, isCorrectPassword, isPrivateMethod, isPublicMethod, isStarted, linksToXml, passwordsStateToXml, permanentLinksToXml, reflectionMethods, reflectionObject, removeAllLinksTo, removeAllServices, removeAllServices, removeCommunicationID, removeLinkFromService, removeLinkToService, removePermanentLinkTo, removeServiceAssociation, removeServiceID, removeServicePath, removeServicePath, removeTempPassword, serviceNegotiate, serviceToXml, serviceToXml, setAdminInfo, setCanAccessMeta, setCanAccessNested, setData, setDataModule, setDataModule, setDescription, setInstanceValues, setIsRemoteCall, setOtherMeta, setParent, setParent, setSerializeValues, setServerPassword, setServiceGrade, setServiceModule, setServiceState, startAllThreads, startThread, stopAllThreads, syncToAsync, syncToAsyncReply, syncToAsyncTransit, xmlToDynamicLinks, xmlToService`

    - ### Methods inherited from class org.licas.module.ServiceModule

      `getShutDown, setShutDown, setShutDown`

    - ### Methods inherited from class org.licas.module.FrameworkModule

      `canAccess, getPasswordHandler, getServicePassword, getServiceType, isAdminKey, setServiceDetails, setServiceType`

    - ### Methods inherited from class org.licas.module.LicasModule

      `getJarFile, getUUID, loadObject, setJarFile, setUUID, threadAliveState`

    - ### Methods inherited from class java.lang.Thread

      `activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield`

    - ### Methods inherited from class java.lang.Object

      `equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface org.licas.def.ServiceDef

      `getUUID, setJarFile, setUUID`

- - ### Field Detail

    - #### serverIP

          protected java.lang.String serverIP

      Only the server ip address, for example, 'http://123.4.5.6:8888'

    - #### serverUri

          protected org.licas_xml.abs.Element serverUri

      The server url address

    - #### serviceSpec

          protected ServiceSpec serviceSpec

      The service specification

    - #### syncOn

          protected final java.lang.Object syncOn

      To synchronize on

  - ### Constructor Detail

    - #### ServiceMediator

          public ServiceMediator(PasswordHandler thePasswordHandler)
                          throws java.lang.Exception

      Create a new instance of ServiceMediator.
      Parameters:
        `thePasswordHandler` - the password handler.
      Throws:
        `java.lang.Exception` - any error.

    - #### ServiceMediator

          public ServiceMediator(java.lang.String thisPassword,
                                 java.lang.String thisAdminKey,
                                 PasswordHandler thePasswordHandler)
                          throws java.lang.Exception

      Creates a new instance of ServiceMediator.
      Parameters:
        `thisPassword` - the component password.
        `thisAdminKey` - the unique service key.
        `thePasswordHandler` - the password handler.
      Throws:
        `java.lang.Exception` - any error.

  - ### Method Detail

    - #### initialiseServerInfo

          public abstract boolean initialiseServerInfo(ServiceSpec serviceSpec)
                                                throws java.lang.Exception

      Initialise the solver mediator with the server details. Also clear the network of any existing services and the password handler for this service.
      Parameters:
        `serviceSpec` - the service spec or test script, with all of the config details.
      Returns:
        true if initialised OK, false otherwise. Most likely, it would be missing server initialisation information.
      Throws:
        `java.lang.Exception` - any error.

    - #### createServices

          public abstract void createServices(java.lang.String serviceType)
                                       throws java.lang.Exception

      Create the services and initialise as defined by the script.
      Parameters:
        `serviceType` - the type to assign to each main or base service.
      Throws:
        `java.lang.Exception` - any error.

    - #### initialiseServices

          public abstract void initialiseServices(java.lang.String serviceType)
                                           throws java.lang.Exception

      Initialise the services, primarily adding and initialising linking structures if they are included. The initialisation could be application specific and so it is done in each version of this class.
      Parameters:
        `serviceType` - the type of service to initialise.
      Throws:
        `java.lang.Exception` - any error.

    - #### initialiseInfo

          public void initialiseInfo(ServiceSpec theServiceSpec)
                              throws java.lang.Exception

      Initialise the information mediator with password details.
      Parameters:
        `theServiceSpec` - the spec with all of the related config info.
      Throws:
        `java.lang.Exception` - any error.

    - #### startServices

          public void startServices(java.lang.String serviceType)
                             throws java.lang.Exception

      Start the threads of all services of the specified service type.
      Parameters:
        `serviceType` - the service type or unique id.
      Throws:
        `java.lang.Exception` - any error.

    - #### createPermanentLinks

          public void createPermanentLinks(java.util.HashMap<java.lang.String,java.util.ArrayList<java.util.ArrayList<java.lang.String>>> serviceGroups)
                                    throws java.lang.Exception

      Create permanent links between each key service and the list it is related to.
      Parameters:
        `serviceGroups` - the groups of services that are clustered together. The key would be a service ID and value a list of other services related to it. The entries can be either IDs or String-based full URI descriptions.
      Throws:
        `java.lang.Exception` - any error.

    - #### createAssociationLinks

          public void createAssociationLinks(java.util.HashMap<java.lang.String,java.util.ArrayList<java.util.ArrayList<java.lang.String>>> serviceGroups)
                                      throws java.lang.Exception

      Create association links between each key service and the list it is related to.
      Parameters:
        `serviceGroups` - the groups of services that are clustered together. The key would be a service ID and value a list of other services related to it.
      Throws:
        `java.lang.Exception` - any error.

    - #### updateDynamicLinks

          public void updateDynamicLinks(java.util.HashMap<java.lang.String,java.util.ArrayList<java.util.ArrayList<java.lang.String>>> serviceGroups,
                                         boolean toPermanent)
                                  throws java.lang.Exception

      Update dynamic links for the services that are grouped together.
      Parameters:
        `serviceGroups` - the groups of services that are clustered together. The key would be a service ID and value a list of other services related to it. This can either be a `ArrayList` that includes more groups, or a list of service names.
        `toPermanent` - if true, convert any dynamic links at the link level into permanent links, or remove permanent links now moved down a level.
      Throws:
        `java.lang.Exception` - any error.

    - #### getLinkedServiceUuids

          public java.util.ArrayList<java.lang.String> getLinkedServiceUuids()
                                                                      throws java.lang.Exception

      Get the list of uuids only of all services currently linked to through dynamic links, with the `source` uuid added only once, but the `linked to` uuid added the number of times it occurs.
      Returns:
        a list with service uuids only.
      Throws:
        `java.lang.Exception` - any error.

    - #### dynamicLinksToXml

          public org.licas_xml.abs.Element dynamicLinksToXml()
                                                      throws java.lang.Exception

      Get the list of all dynamic links created on each service.
      Overrides:
        `dynamicLinksToXml` in class `Service`
      Returns:
        the list of all dynamic links as an XML-based description.
      Throws:
        `java.lang.Exception` - any error.