public abstract class Auto extends DataService
Auto
class is different to a Service
in the sense that it should try to
run more independently. It can run its own thread to periodically execute its own behaviour.
The Auto service can also manage conversations with other services by storing separate communication
IDs for each conversation thread. This is not the strict agent-based protocols, but entirely
arbitrary to the service itself. If you want to use an AutonomicManager
with your service,
then you must load an Auto-derived class and not a Service-derived class.
When a service is loaded, the server
automatically adds an empty Autonomic Manager
to any Auto-derived service, as a wrapper object. If you then start an Auto derived class’s
thread and execute behaviours; if any monitoring modules are added, they can process the behaviour
results. If you just want to use the more advanced features of an Auto class, you do not need to
add anything else.
The behaviour thread's run
loop implements the main control loop that links with
the empty MAPE slots and so you can use them if needed, by adding specific functionality
to the modules that you might require. Looking at the Auto class should show what methods
you need to implement yourself to create your own autonomic service. The other option is to
invoke the behaviour directly through the invokeBehaviour
method. this can only be
used if the main thread is not running.
The Auto
class is still abstract however, where you must extend it to add specific
behaviour functionality and implement a number of additional methods. See the LinkService
,
for example.
Modifier and Type | Field and Description |
---|---|
protected AutoEngine |
autoEngine
Auto engine for this service, not the autonomic manager.
|
protected AutonomicManager |
autoManager
The autonomic manager monitoring this service
|
protected BehaviourModule |
bm
Module to manage the actions of the behaviour.
|
protected long |
iterations
Number of behaviour events to execute, then shut-down the service.
|
protected long |
sleepTime
Time period between behaviour events.
|
dataCompare, dataMethod, resultObj
canAccessMeta, canAccessNested, dm, finalised, isRemoteCall, messageStore, serviceAdmin, serviceGrade, serviceInitialise, serviceLinks, serviceState, sm, toLoadScript
shutDown
passwordHandler, service, serviceType
jarFile, syncOn, uuid
Constructor and Description |
---|
Auto()
Creates a new instance of Auto.
|
Auto(java.lang.String thisPassword,
java.lang.String thisAdminKey)
Creates a new instance of Auto.
|
Auto(java.lang.String thisPassword,
java.lang.String thisAdminKey,
org.licas_xml.abs.Element adminXml)
Creates a new instance of Auto.
|
Modifier and Type | Method and Description |
---|---|
void |
autoAction(java.lang.String action,
java.lang.String adminKey)
This allows the autonomic manager to ask the parent service to perform some action.
|
MessageInfo |
autoQueueMessage(org.dcs.query_process.model.activity.Script_Auto scriptAuto,
java.lang.String adminKey)
Retrieve and remove the first message on the auto manager's queue with the
specified condition - method name, timestamp, etc.
|
protected abstract MessageInfo |
behaviourAction(MessageInfo messageInfo)
Execute a behaviour, such as an evaluation and result.
|
protected AutoEngine |
getAutoEngine()
Get the auto engine.
|
protected java.lang.Object |
getInstanceValue(java.lang.String varName)
Get the value of the specified variable if it exists.
|
protected java.lang.String |
getMessageState(java.lang.Object message)
Calculate the current state for the message and related conversation.
|
boolean |
interrupt(java.lang.String adminKey)
You must call this method to interrupt the thread.
|
java.lang.Object |
invokeBehaviour(MessageInfo messageInfo)
This can be used to execute a single invocation of the service's
evaluateBehaviour method. |
boolean |
messageReply(java.lang.Object message)
This can be used as part of a conversation, for example, to reply to some other method invocation, or even
to start a conversation.
|
protected void |
removeCommunicationID(java.lang.String commID)
Remove the communication ID reference.
|
void |
run()
This is the default method to start the service thread.
|
protected void |
setAutoEngine()
Initialise and create the auto engine.
|
protected void |
setAutonomicManager(AutonomicManager thisAutoManager)
Set a reference to the autonomic manager monitoring this service.
|
protected void |
setBehaviourModule()
Set the type of behaviour that the control loop uses to evaluate the service.
|
protected void |
setInstanceValues(org.licas_xml.abs.Element instanceValues)
Set actual values for variable instances if they are defined.
|
boolean |
setProcessScript(org.licas_xml.abs.Element theScript,
java.lang.String adminKey)
Set or update the auto engine
AiConst .PROCESS script to execute
a (business) process through the script description. |
protected void |
setSerializeValues(org.licas_xml.abs.Element serializeXml)
Set actual values for serialized variable instances if they are defined.
|
createEvaluateData, createEvaluateData, dataTypeOK, dataXmlBM, dataXmlBM, dataXmlDH, dataXmlDH, evaluate, getData, getData, getDataType, getResultObj, resetValues, setData, setData, setFixedDataValue, setGenData, setResultObj
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
getShutDown, setShutDown, setShutDown
canAccess, getPasswordHandler, getServicePassword, getServiceType, isAdminKey, setServiceDetails, setServiceType
getJarFile, getUUID, loadObject, setJarFile, setUUID, threadAliveState
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
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
setData
getUUID, setJarFile, setUUID
protected long sleepTime
ServiceConst
.BEHAVIOURLOOPSLEEP
milliseconds.protected long iterations
iterations <= 0
then execute continuously.protected BehaviourModule bm
protected AutoEngine autoEngine
protected AutonomicManager autoManager
public Auto() throws java.lang.Exception
anon
by default.java.lang.Exception
- any error.public Auto(java.lang.String thisPassword, java.lang.String thisAdminKey) throws java.lang.Exception
thisPassword
- password to invoke this service.thisAdminKey
- admin key for this service.java.lang.Exception
- any error.public Auto(java.lang.String thisPassword, java.lang.String thisAdminKey, org.licas_xml.abs.Element adminXml) throws java.lang.Exception
thisPassword
- password to invoke this service.thisAdminKey
- admin key for this service.adminXml
- the admin info or description of this service.java.lang.Exception
- any error.protected void setBehaviourModule() throws java.lang.Exception
java.lang.Exception
- any error.protected void setAutoEngine()
protected AutoEngine getAutoEngine()
protected void setInstanceValues(org.licas_xml.abs.Element instanceValues) throws java.lang.Exception
NOTE:
you must add this method to your own derived class if you use it,
so that the private variables in that class can be accessed. It is ignored
unless it gets called through the script initialisation process.
setInstanceValues
in class DataService
instanceValues
- the admin script part that defines instance values.java.lang.Exception
- any error.protected java.lang.Object getInstanceValue(java.lang.String varName) throws java.lang.Exception
NOTE:
you must add this method to your own derived class if you use it,
so that the private variables in that class can be accessed. It is ignored
unless it gets called through the script initialisation process.
getInstanceValue
in class DataService
varName
- the name of the variable to check for.java.lang.Exception
- any error.protected void setSerializeValues(org.licas_xml.abs.Element serializeXml) throws java.lang.Exception
NOTE:
you must add this method to your own derived class if you
use it, so that the private variables in that class can be accessed.
setSerializeValues
in class DataService
serializeXml
- the admin script part that defines serialize instance
values.java.lang.Exception
- any error.public boolean setProcessScript(org.licas_xml.abs.Element theScript, java.lang.String adminKey) throws java.lang.Exception
AiConst
.PROCESS
script to execute
a (business) process through the script description.theScript
- the auto engine script to execute.adminKey
- the admin key for the service.java.lang.Exception
- any error.protected abstract MessageInfo behaviourAction(MessageInfo messageInfo) throws java.lang.Exception
messageInfo
- the message to evaluate.java.lang.Exception
- any error.public java.lang.Object invokeBehaviour(MessageInfo messageInfo) throws ServiceException, java.lang.Exception
evaluateBehaviour
method.
This is correct if the service is waiting to be invoked and is not running on a thread.messageInfo
- the message with data to evaluate. This is only the values
related to the evaluation result, not the whole set of service values.evaluateBehaviour
MessageInfo
reply object. If this is not one of the basic types, a parser needs to be added to parse
the complex object to/from XML.ServiceException
- if this service's main thread is currently running.java.lang.Exception
- and error.public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public MessageInfo autoQueueMessage(org.dcs.query_process.model.activity.Script_Auto scriptAuto, java.lang.String adminKey) throws PasswordException
scriptAuto
- the script element with a single condition to use.adminKey
- the admin key for this service.PasswordException
- if the admin key is incorrect.public void autoAction(java.lang.String action, java.lang.String adminKey) throws PasswordException, ServiceException, java.lang.Exception
action
- to action to perform.adminKey
- the admin key for this service.PasswordException
- if the admin key is incorrect.ServiceException
- if a licas service problem occurs.java.lang.Exception
- any other error.protected void removeCommunicationID(java.lang.String commID)
removeCommunicationID
in class Service
commID
- the communication ID.public boolean messageReply(java.lang.Object message) throws java.lang.Exception
message
object is added to the service queue, wrapped in a MessageInfo
object, with optional states and conversation protocol. It is also used internally by the communication system to
queue the CallObject
MethodInfo
requests. When accessed through the communication mechanism,
a communicationID
from the client has already been looked for in the (MethodInfo) message object.
That could then be used to identify this particular message, or as part of conversation.
If used internally, the MethodInfo
message is re-packaged with some state information,
before being queued in the AutonomicManager
. The messages are then lifted off the queue in order,
as part of an asynchronous
process. If the parameter is a MessageInfo object itself, it is queued as
is and so its state and other values can be set. This would allow for a conversation protocol, for example.
The AutonomicManagerDefault
now records some basic stats for the messages that are received,
such as number of calls or message size, as would be the case for any server. It is
stored locally to this service, not globally in the server, but the server can query it.
There is no other monitoring as default and so messages just get added and removed in order,
without any consideration of their state or content. The state variables are
therefore ignored by the default system and the message object is simply stored and
returned again. For example, the evaluateBehaviour
method calls autoManager.getMessage
to retrieve the next message Object to evaluate. You can change any of this in a derived class.
One final important option is in fact to ask the system not to queue the message.
If the message parameter is a MessageInfo
object and has a message state
of
AiConst
.NOACTION
already added, then it is not added to the message queue.
You could add service-specific code to process it further, where this allows for an
immediate response, such as setting a variable value, on the service itself.
message
- an object representing the result of the task. Can be null.java.lang.Exception
- any error.protected java.lang.String getMessageState(java.lang.Object message)
messageReply
method, for example.
This default 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 thread state for this service.
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.protected void setAutonomicManager(AutonomicManager thisAutoManager) throws java.lang.Exception
thisAutoManager
- the autonomic manager.java.lang.Exception
- any error.public boolean interrupt(java.lang.String adminKey)