cartago
Class Artifact

java.lang.Object
  extended by cartago.Artifact
Direct Known Subclasses:
AgentBodyArtifact, ManRepoArtifact, NodeArtifact, WorkspaceArtifact

public abstract class Artifact
extends java.lang.Object

Base class for defining artifacts.

Author:
aricci

Nested Class Summary
 class Artifact.AbstractAsyncProcess
           
 
Field Summary
protected  double observabilityRadius
           
protected  AbstractWorkspacePoint position
           
protected  OpId thisOpId
           
 
Constructor Summary
Artifact()
           
 
Method Summary
protected  void await_time(long dt)
          Blocks the execution of current operation until the specified amount of time has passed.
protected  void await(IBlockingCmd cmd)
          Blocks the execution of current operation until the specified blocking command has been executed.
protected  void await(java.lang.String guardName, java.lang.Object... params)
          Blocks the execution of current operation until the condition specified by the guard is satisfied.
protected  void commit()
           
protected  void defineObsProperty(java.lang.String name, java.lang.Object... values)
          Add an observable property
protected  void defineOp(IArtifactOp op, IArtifactGuard guard)
          Defining a new artifact operation
protected  void delay(long ms)
          Delay the execution of next instruction of the specified amount of time Note that this operation blocks the artifact access
protected  void dispose()
          Method automatically called when the artifact is disposed.
protected  void dispose(ArtifactId aid)
          Dispose an artifact
protected  void execInternalOp(java.lang.String opName, java.lang.Object... params)
          Start the execution of an internal operation.
protected  void execLinkedOp(ArtifactId aid, java.lang.String opName, java.lang.Object... params)
          Execute a linked operation, given the artifact id
protected  void execLinkedOp(java.lang.String outPortName, java.lang.String opName, java.lang.Object... params)
          Execute a linked operation
protected  void failed(java.lang.String reason)
          Terminate current operation with a failure
protected  void failed(java.lang.String reason, java.lang.String tupleDesc, java.lang.Object... params)
          Terminate current operation with a failure
protected  AgentId getCreatorId()
           
protected  ArtifactId getId()
          Get the artifact unique identifier
static java.lang.String getManualSrcFile(java.lang.String artType)
          Get the name of the file containing the manual for the specified artifact template, by accessing to ARTIFACT_INFO annotation.
protected  double getObservabilityRadius()
           
protected  ObsProperty getObsProperty(java.lang.String name)
           
protected  ObsProperty getObsPropertyByTemplate(java.lang.String name, java.lang.Object... values)
           
static java.lang.String getOpKey(java.lang.String opName, int nargs)
          Get the key of an operation, given its name and n args.
protected  ArtifactId getOpUserBody()
          Get the identifier of the current user artifact body (if available)
protected  AgentId getOpUserId()
          Get the identifier of the current user
protected  java.lang.String getOpUserName()
          Get the name of the current user
protected  AbstractWorkspacePoint getPosition()
           
protected  boolean hasObsProperty(java.lang.String name)
           
protected  boolean hasObsPropertyByTemplate(java.lang.String name, java.lang.Object... values)
           
protected  boolean isLinked(java.lang.String outPortName)
          Check if an artifact is linked to a port
protected  void log(java.lang.String msg)
          Log the information on standard output.
protected  ArtifactId lookupArtifact(java.lang.String name)
          Lookup an artifact
protected  ArtifactId makeArtifact(java.lang.String name, java.lang.String type, ArtifactConfig params)
          Create an artifact from another artifact.
protected  void removeObsProperty(java.lang.String name)
          Remove an observable property
protected  void removeObsPropertyByTemplate(java.lang.String name, java.lang.Object... values)
          Remove an observable property
protected  void setupOperations()
          Set up artifact operations.
protected  void setupPosition(AbstractWorkspacePoint pos, double observabilityRadius)
           
protected  void signal(AgentId target, java.lang.String type, java.lang.Object... objs)
          Primitive to generate an event.
protected  void signal(java.lang.String type, java.lang.Object... objs)
          Primitive to generate an event.
protected  void updateObservabilityRadius(double radius)
           
protected  void updateObsProperty(java.lang.String name, java.lang.Object... values)
          For compatibility reason...
protected  void updatePosition(AbstractWorkspacePoint pos)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

thisOpId

protected OpId thisOpId

position

protected AbstractWorkspacePoint position

observabilityRadius

protected double observabilityRadius
Constructor Detail

Artifact

public Artifact()
Method Detail

setupOperations

protected void setupOperations()
                        throws CartagoException
Set up artifact operations. Method called during artifact initialization to set up operations. By default, reflection is used to link operations to annotated methods.

Throws:
CartagoException

getManualSrcFile

public static java.lang.String getManualSrcFile(java.lang.String artType)
                                         throws UnknownArtifactException
Get the name of the file containing the manual for the specified artifact template, by accessing to ARTIFACT_INFO annotation.

Parameters:
artType - artifact template
Returns:
file name
Throws:
UnknownArtifactException

getOpKey

public static java.lang.String getOpKey(java.lang.String opName,
                                        int nargs)
Get the key of an operation, given its name and n args. The key is used in maps.

Parameters:
opName - op name
nargs - number of parameters

getId

protected ArtifactId getId()
Get the artifact unique identifier


getOpUserId

protected AgentId getOpUserId()
Get the identifier of the current user


getOpUserBody

protected ArtifactId getOpUserBody()
Get the identifier of the current user artifact body (if available)


getOpUserName

protected java.lang.String getOpUserName()
Get the name of the current user


commit

protected void commit()

signal

protected void signal(java.lang.String type,
                      java.lang.Object... objs)
Primitive to generate an event.


signal

protected void signal(AgentId target,
                      java.lang.String type,
                      java.lang.Object... objs)
Primitive to generate an event.


failed

protected void failed(java.lang.String reason)
Terminate current operation with a failure

Parameters:
reason - description of the failure

failed

protected void failed(java.lang.String reason,
                      java.lang.String tupleDesc,
                      java.lang.Object... params)
Terminate current operation with a failure

Parameters:
reason - description of the failure
tupleDesc - functor of a machine readable tuple describing the failure
params - parameters of a machine readable tuple describing the failure

defineObsProperty

protected void defineObsProperty(java.lang.String name,
                                 java.lang.Object... values)
Add an observable property

Parameters:
name - name of the property
values - values of the property

removeObsProperty

protected void removeObsProperty(java.lang.String name)
Remove an observable property

Parameters:
name - name of the property

removeObsPropertyByTemplate

protected void removeObsPropertyByTemplate(java.lang.String name,
                                           java.lang.Object... values)
Remove an observable property

Parameters:
name - name of the property
values - arguments of the property

getObsProperty

protected ObsProperty getObsProperty(java.lang.String name)

hasObsProperty

protected boolean hasObsProperty(java.lang.String name)

getObsPropertyByTemplate

protected ObsProperty getObsPropertyByTemplate(java.lang.String name,
                                               java.lang.Object... values)

hasObsPropertyByTemplate

protected boolean hasObsPropertyByTemplate(java.lang.String name,
                                           java.lang.Object... values)

updateObsProperty

protected void updateObsProperty(java.lang.String name,
                                 java.lang.Object... values)
For compatibility reason...


await

protected void await(java.lang.String guardName,
                     java.lang.Object... params)
Blocks the execution of current operation until the condition specified by the guard is satisfied. By calling await the execution of current atomic operation step is completed.

Parameters:
guardName - - name of the boolean method implementing the guard
params - - parameters of the method

await_time

protected void await_time(long dt)
Blocks the execution of current operation until the specified amount of time has passed. By calling await the execution of current atomic operation step is completed.

Parameters:
dt - - amount of time in milliseconds

await

protected void await(IBlockingCmd cmd)
Blocks the execution of current operation until the specified blocking command has been executed. By calling await the execution of current atomic operation step is completed.

Parameters:
cmd - - the command to be executed

execInternalOp

protected void execInternalOp(java.lang.String opName,
                              java.lang.Object... params)
Start the execution of an internal operation. The execution/success semantics of the new operation is completely independent from current operation.

Parameters:
op - - the operation to be executed

execLinkedOp

protected void execLinkedOp(java.lang.String outPortName,
                            java.lang.String opName,
                            java.lang.Object... params)
                     throws OperationException
Execute a linked operation

Parameters:
outPortName - name of the out port
opName - name of the operation to execute
params - parameters of the operation
Throws:
OperationException

isLinked

protected boolean isLinked(java.lang.String outPortName)
Check if an artifact is linked to a port

Parameters:
outPortName -
Returns:

execLinkedOp

protected void execLinkedOp(ArtifactId aid,
                            java.lang.String opName,
                            java.lang.Object... params)
                     throws OperationException
Execute a linked operation, given the artifact id

Parameters:
aid - artifact identifier
opName - name of the operation to execute
params - parameters of the operation
Throws:
OperationException

makeArtifact

protected ArtifactId makeArtifact(java.lang.String name,
                                  java.lang.String type,
                                  ArtifactConfig params)
                           throws OperationException
Create an artifact from another artifact.

Parameters:
name - name of the artifact
type - template
params - parameters - use ArtifactConfig.DEFAULT_CONFIG for default configuration
Returns:
artifact id
Throws:
OperationException

dispose

protected void dispose(ArtifactId aid)
                throws OperationException
Dispose an artifact

Parameters:
aid - artifact id
Throws:
OperationException

lookupArtifact

protected ArtifactId lookupArtifact(java.lang.String name)
                             throws OperationException
Lookup an artifact

Parameters:
name - artifact name
Returns:
artifact id
Throws:
OperationException

delay

protected void delay(long ms)
Delay the execution of next instruction of the specified amount of time Note that this operation blocks the artifact access

Parameters:
ms - amount of time in milliseconds

log

protected void log(java.lang.String msg)
Log the information on standard output.


defineOp

protected void defineOp(IArtifactOp op,
                        IArtifactGuard guard)
Defining a new artifact operation

Parameters:
op - operation
guard - guard

dispose

protected void dispose()
Method automatically called when the artifact is disposed. To be overridden by derived Artifact classes. Dual method with respect to init.


setupPosition

protected void setupPosition(AbstractWorkspacePoint pos,
                             double observabilityRadius)

updatePosition

protected void updatePosition(AbstractWorkspacePoint pos)

updateObservabilityRadius

protected void updateObservabilityRadius(double radius)

getPosition

protected final AbstractWorkspacePoint getPosition()

getObservabilityRadius

protected final double getObservabilityRadius()

getCreatorId

protected AgentId getCreatorId()


>DEIS - University of Bologna