Services in AgentScape

New in AgentScape 2.0 is the concept of services. Not to be confused with system services, these services can be directly accessed by agents (and other services) whenever they need to.

The main differences between services and agents are:

  • Services cannot migrate
  • Services may have additional privileges

Services can be used to provide (mediated) access to resources on a certain AgentScape host. For example, agents are not allowed to directly access resources like databases etc. However, a service can be installed which has access to the resource. It can then mediate access from agents to the resources using the service framework.

  • Agent connections to SqlService
  • The SqlService connects to database

The service framework allows agents to connect to services using AOS sockets internally. This allows services to be accessed from the local AgentScape host as well as from a remote host. Each service can be configured to allow different kinds of access modifiers, being:

  • From the same host (host access)
  • From the same location (location access)
  • Anywhere from the world (world access)
  • Restricted to certain clients (authenticated)

Some services are only allowed to be accessed from the same host, whereas others may be accessed from a remote host in the same location, or even from outside the location.

For an example, see the following picture:

In this example, Location A consists of 2 hosts. Host A1 offers a directory service (only to its local agents) whereas Host A2 offers both a servlet service and a blackboard. Each agent from within location A can use the servlet service (though it cannot be accessed from location B). The blackboard, however, can be accessed from each location in the world.

Service Broker

Both agents and services have access to other services. They can request access to a certain type of service by using an AgentScape-provided Service Broker (org.iids.aos.service.ServiceBroker). The service broker allows the following method for service access.

  public <T extends Service> T bind (Class<T> clazz) throws Exception;

A client can use this service broker to request access to a service in the following way:

class MyAgent extends Agent
{
  public void run ()
  {
    // bind to a local directory service
    ServiceBroker sb = getServiceBroker();
    DirectoryService ds = sb.getService(DirectoryService.class);
 
    // create a directory record in the service, etc..
    ds.createRecord(...);
  }
}

However, this service broker method can only bind to services on the local host. It does not perform any discovery of services on remote hosts. For more advanced access we can use the directory service to perform service discovery.

Service Discovery

To access remote services, we can use the directory service we bound to in the previous step. This directory service contains information published by other services. Based on the service descriptions in the directory records, a ServiceID for the desired service can be obtained. This service ID can be used by the service broker to connect to a specific instance of a service. For more information about the directory service, have a look at the blackboard_service page.

  public <T extends Service> T bind (Class<T> clazz, ServiceID id) throws Exception;

Once the appropriate service ID is found, the client can connect to the specific service, as shown in the following example.

class MyAgent extends Agent
{
  public void run ()
  {
    // first connect to the directory via the broker
 
    ServiceBroker sb = getServiceBroker();
    DirectoryService ds = sb.getService(DirectoryService.class);
 
    // obtain the desired ServiceID from the directory
    // once we have that, request a binding from the broker
 
    ServiceID servletServiceId = findServletService (ds);
    ServletService servlets = sb.getService(ServletService.class, servletServiceId);
 
    // we are now connected to a (remote) servlet service
    // publish a servlet which displays some information
 
    servlets.publishServlet (new MyServlet());
  }
 
  private ServiceID findServletService (DirectoryService ds)
  {
    // inspect ds and find an appropriate service ID
  }
}

please note that not all of the milestone releases provide the same functionality. Service discovery is only provided from AgentScape 2.0 Milestone 2 and up. Some details form the final release may be different.

development/service/services.txt · Last modified: 2010/10/07 16:12 by reinier