Example 11 - Working in Remote Workspaces
Agents can join workspaces that are hosted on remote nodes, by means of a
joinRemoteWorkspace
action (provided by the NodeArtifact
.
As soon as the join succeed, the interaction within remote workspaces is the same as local workspace.
In the following example, a Jason agent joins the default workspace of a CArtAgO node running on localhost.
The following Java program installs a CArtAgO node on localhost, to make it reachable (also) by remote agents:
Highlights: %package examples; import cartago.*; import cartago.util.BasicLogger; public class Ex00a_HelloRemoteWorld { public static void main(String[] args) throws Exception { CartagoService.startNode(); CartagoService.installInfrastructureLayer("default"); CartagoService.startInfrastructureService("default"); CartagoService.registerLogger("default",new BasicLogger()); System.out.println("CArtAgO Node Ready."); } }
startNode
service of CartagoService
.
The node functions as virtual machine for running workspaces and artifacts, it does
not include any infrastructural (network) support.installInfrastructureLayer
,
specifying the protocol(s) to be used (default
means the default protocol of
the platform, which is RMI in the case of Java SE desktop environments).startInfrastructureService
, again specifying the protocol.TheMAS example11_remote { environment: c4jason.CartagoEnvironment agents: voyager agentArchClass c4jason.CAgentArch; classpath: "../../../lib/cartago.jar";"../../../lib/c4jason.jar"; }
voyager
agent boots in the standalone node, then it joins a remote
workspace, where he creates and uses an artifact.
Highlights:!test_remote. +!test_remote <- ?current_wsp(Id,_,_); +default_wsp(Id); println("testing remote.."); joinRemoteWorkspace("default","localhost",WspID2); ?current_wsp(_,WName,_); println("hello there ",WName); !use_remote; quitWorkspace. +!use_remote <- makeArtifact("c0","examples.Counter",[],Id); focus(Id); inc; inc. +count(V) <- ?default_wsp(Id); println("count changed: ",V)[wsp_id(Id)]. -!use_remote [makeArtifactFailure("artifact_already_present",_)] <- ?default_wsp(WId); println("artifact already created ")[wsp_id(WId)]; lookupArtifact("c0",Id); focus(Id); inc.
c4jason.CartagoEnvironment
definition inside the
Jason mas2j
file:
c4jason.CartagoEnvironment("standalone", protocol(ProtName), ...)
: analogous
to the default installation except for the declaration of one (or more)
infrastructure layers that specify the protocols used for working with remote
workspaces (ex: c4jason.CartagoEnvironment("standalone",protocol(lipermi))
.c4jason.CartagoEnvironment("infrastructure",protocol(ProtName), ..., service(ServName))
:
installs a CArtAgO node accessible through the network. The default service protocol
supported by the node is RMI, other service protocols can be installed specifying one
or more service
attributes. RMI is installed as the default protocol
for joining remote workspaces but other protocols can be installed as well
using the protocol
attribute
(ex: c4jason.CartagoEnvironment("infrastructure", service("lipermi"), protocol("lipermi"))
).{c4jason.CartagoEnvironment("remote", WspName, WspAddress, protocol(ProtName, Address), ...)
: does not install any node - agents directly join the specified remote workspace.
As usual RMI is installed by default and further protocols can be specified using the protocol
attribute
(ex: c4jason.CartagoEnvironment("remote", "myWsp", "localhost", protocol("lipermi"))
).c4jason.CartagoEnvironment("local",WspName)
does not install any node -- agents directly join the specified local workspace (or the default workspace if no workspace name is specified) (ex: c4jason.CartagoEnvironment("local", "WspName")).