org.licas.service.sci

## Class LinkService

- java.lang.Object
- - java.lang.Thread
  - - org.licas.module.LicasModule
    - - org.licas.module.FrameworkModule
      - - org.licas.module.ServiceModule
        - - org.licas.Service
          - - org.licas.service.DataService
            - - org.licas.Auto
              - - org.licas.service.sci.LinkService

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

      public class LinkService
      extends Auto

  This class can be used for running a behaviour that evaluates data and creates links between services based on the result. As such, it uses the autonomous capabilities of the framework and therefore extends the `Auto` class.

  Through the `evaluateBehaviour` method, a service id is removed after only 1 evaluation with it and so the dataset values would be retrieved and compared only once.

  This service can be used as part of the problem solving package and can be used with the clustering services there, for example.

  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 inherited from class org.licas.Auto

      `autoEngine, autoManager, bm, iterations, sleepTime`

    - ### Fields inherited from class org.licas.service.DataService

      `dataCompare, dataMethod, resultObj`

    - ### 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, syncOn, uuid`

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

      `MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `LinkService()` Create a new instance of LinkService.
    `LinkService(java.lang.String thisPassword, java.lang.String thisAdminKey)` Creates a new instance of LinkService.
    `LinkService(java.lang.String thisPassword, java.lang.String thisAdminKey, org.licas_xml.abs.Element adminXml)` Creates a new instance of LinkService.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.util.ArrayList<?>` | `addDynamicLink(org.licas_xml.abs.Element serviceUri)` Add a dynamic link for the service with an empty path description.
    `java.util.ArrayList<?>` | `addDynamicLinks(java.util.ArrayList<?> sourceList, java.util.ArrayList<java.lang.String> conceptList)` Add related sources to the dynamic linking service of this service.
    `void` | `addPermanentLink(org.licas_xml.abs.Element serviceUri)` Add a permanent link between this service and the service specified.
    `protected MessageInfo` | `behaviourAction(MessageInfo messageInfo)` This behaviour compares service data and tries to cluster them.
    `org.licas_xml.abs.Element` | `createProcessScript()` Create the policy description that can be used as a default script for initialising the auto engine of this service.
    `org.ai_heuristic.eval.metric.MetricDataset` | `getDataRandomID()` Randomly retrieve the next dataset for evaluation.
    `protected java.lang.String` | `getMessageState(java.lang.String communicationID, java.lang.Object message)` Calculate the current state for the message and related conversation.
    `void` | `removeAllPermanentLinks()` Remove all of the permanent links from this service.
    `void` | `removePermanentLink(java.lang.String serviceUuid)` Remove a permanent link between this service and the service specified.
    `void` | `resetValues()` Reset variables for another test run.
    `void` | `updateDynamicLinks(java.util.ArrayList<java.lang.String> conceptList, java.util.ArrayList<?> serviceGroups, boolean toPermanent, java.lang.String adminKey)` Update dynamic links for the services that are grouped together.

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

      `autoAction, autoQueueMessage, getAutoEngine, getInstanceValue, getMessageState, interrupt, invokeBehaviour, messageReply, removeCommunicationID, run, setAutoEngine, setAutonomicManager, setBehaviourModule, setInstanceValues, setProcessScript, setSerializeValues`

    - ### Methods inherited from class org.licas.service.DataService

      `createEvaluateData, createEvaluateData, dataTypeOK, dataXmlBM, dataXmlBM, dataXmlDH, dataXmlDH, evaluate, getData, getData, getDataType, getResultObj, setData, setData, setFixedDataValue, setGenData, setResultObj`

    - ### 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, dynamicLinksToXml, execute, finaliseInitialisation, finaliseInitialisation, finaliseModule, finaliseThisConfig, GET, getAllLinkToService, getAllowAddService, getAutonomicManagerConfig, getCommunicationClientURI, getDescription, getFullPath, 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, isCorrectPassword, isPrivateMethod, isPublicMethod, isStarted, linksToXml, passwordsStateToXml, permanentLinksToXml, reflectionMethods, reflectionObject, removeAllLinksTo, removeAllServices, removeAllServices, removeLinkFromService, removeLinkToService, removePermanentLinkTo, removeServiceAssociation, removeServiceID, removeServicePath, removeServicePath, removeTempPassword, serviceNegotiate, serviceToXml, serviceToXml, setAdminInfo, setCanAccessMeta, setCanAccessNested, setData, setDataModule, setDataModule, setDescription, setIsRemoteCall, setOtherMeta, setParent, setParent, 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, 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.DataServiceDef

      `setData`

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

      `getUUID, setJarFile, setUUID`

- - ### Constructor Detail

    - #### LinkService

          public LinkService()
                      throws java.lang.Exception

      Create a new instance of LinkService.
      Throws:
        `java.lang.Exception` - any error.

    - #### LinkService

          public LinkService(java.lang.String thisPassword,
                             java.lang.String thisAdminKey)
                      throws java.lang.Exception

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

    - #### LinkService

          public LinkService(java.lang.String thisPassword,
                             java.lang.String thisAdminKey,
                             org.licas_xml.abs.Element adminXml)
                      throws java.lang.Exception

      Creates a new instance of LinkService.
      Parameters:
        `thisPassword` - the component password.
        `thisAdminKey` - the unique service key.
        `adminXml` - the admin info or description of this service.
      Throws:
        `java.lang.Exception` - any error.

  - ### Method Detail

    - #### resetValues

          public void resetValues()

      Reset variables for another test run.
      Specified by:
        `resetValues` in interface `DataServiceDef`
      Overrides:
        `resetValues` in class `DataService`

    - #### behaviourAction

          protected MessageInfo behaviourAction(MessageInfo messageInfo)
                                         throws java.lang.Exception

      This behaviour compares service data and tries to cluster them. It then creates links with services that it is closest to. Each service is asked to send its data and it gets compared with the local dataset. The result is also sent to a `Behaviour Mediator` service for viewing. The evaluation result is then returned as the method result.
      Specified by:
        `behaviourAction` in class `Auto`
      Parameters:
        `messageInfo` - the message to evaluate. This service uses a `DataQueryModel`-derived object that is configured in the method before being evaluated. If a DataQuery object is passed as the message object, then it is updated in the method. If not, then the message object is ignored and a new DataQuery object is created internally.
      Returns:
        the result of executing the behaviour.
      Throws:
        `java.lang.Exception` - any error.

    - #### getMessageState

          protected java.lang.String getMessageState(java.lang.String communicationID,
                                                     java.lang.Object message)

      Calculate the current state for the message and related conversation. If this service is involved in conversations with several other services, for example, each conversation can be at a different stage, resulting in a different state for each conversation process. This method should be used to return the current state for the specified conversation. It should be implemented by any derived class, but only called internally, inside the `messageReply` method, for example.

      This link service version checks if the message parameter is a `MessageInfo` object. If it is, it returns its `getMessageState` method call. If it is not, then it returns the `AiConst`.`ACTION` value.

      Parameters:
        `communicationID` - the communication ID. This defines the communication thread and therefore the conversation.
        `message` - an object representing a result from the other service in the conversation. This can represent the result of the last conversation task, or can be null if no information is required.
      Returns:
        the state of this service relating to the selected conversation.

    - #### addDynamicLink

          public java.util.ArrayList<?> addDynamicLink(org.licas_xml.abs.Element serviceUri)
                                                throws java.lang.Exception

      Add a dynamic link for the service with an empty path description.
      Parameters:
        `serviceUri` - the full uri path for the service.
      Returns:
        a list of the sources that have been added.
      Throws:
        `java.lang.Exception` - any error.

    - #### addDynamicLinks

          public java.util.ArrayList<?> addDynamicLinks(java.util.ArrayList<?> sourceList,
                                                        java.util.ArrayList<java.lang.String> conceptList)
                                                 throws java.lang.Exception

      Add related sources to the dynamic linking service of this service. This is probably the easiest way to update dynamic links, where this default version retrieves the linking service called `ServiceConst.LINKER` on this service. This version no longer sends any information to a mediator.
      Parameters:
        `sourceList` - the list of source uris to add. This is the list of source links to update.
        `conceptList` - the list of concepts that would make up the linking path.
      Returns:
        a list of the sources that have been added.
      Throws:
        `java.lang.Exception` - any error.

    - #### updateDynamicLinks

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

      Update dynamic links for the services that are grouped together. This calls `addDynamicLinks` on the linker utility service and also checks if reliable links should be made permanent.
      Parameters:
        `conceptList` - the path concept list, of any description.
        `serviceGroups` - the groups of services that are clustered together. Each list element can be a service, where the value is a list of other services related to it, as in `ArrayList<String>`. The value is therefore a list of related 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.
        `adminKey` - the service admin key.
      Throws:
        `java.lang.Exception` - any error.

    - #### addPermanentLink

          public void addPermanentLink(org.licas_xml.abs.Element serviceUri)

      Add a permanent link between this service and the service specified.
      Parameters:
        `serviceUri` - the path to the service to add a permanent link to.

    - #### removePermanentLink

          public void removePermanentLink(java.lang.String serviceUuid)

      Remove a permanent link between this service and the service specified.
      Parameters:
        `serviceUuid` - the uuid of the service to remove the permanent link to.

    - #### removeAllPermanentLinks

          public void removeAllPermanentLinks()

      Remove all of the permanent links from this service.

    - #### getDataRandomID

          public org.ai_heuristic.eval.metric.MetricDataset getDataRandomID()
                                                                     throws java.lang.Exception

      Randomly retrieve the next dataset for evaluation. This is from any service on the current list. This then also removes the service from the list. Use `resetServiceIDs` to reset to the full list of other services again. This version calls `getValue` that uses the `EvaluateBase.valueFromString` method to try to parse a string-based representation of a value into a Java object, which will only automatically work for simple types, or XML.
      Returns:
        the retrieved data as a MetricDataset object.
      Throws:
        `java.lang.Exception` - and error.

    - #### createProcessScript

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

      Create the policy description that can be used as a default script for initialising the auto engine of this service. This is for the service itself, not any related autonomic manager.
      Returns:
        a policy script to initialise the service with.
      Throws:
        `java.lang.Exception` - any error.