public abstract class

AbstractParticipant

extends Object
implements EnvironmentServiceProvider Participant
java.lang.Object
   ↳ uk.ac.imperial.presage2.util.participant.AbstractParticipant

Class Overview

This implements the core of a Participant to manage the majority of the mundane functions allowing the user to start writing the agent's behaviours sooner. It implements EnvironmentServiceProvider to provide an interface to EnvironmentServices that are available to the agent

Summary

Nested Classes
class AbstractParticipant.State<T>  
Fields
protected UUID authkey This Participant's authkey obtained when registering with the environment.
protected EnvironmentConnector environment Connector to the environment the participant is in.
protected Queue<Object> inputQueue FIFO queue of inputs to be processed.
protected final Logger logger Logger for this agent.
protected PersistentAgent persist Persistence of this agent into the database.
protected final Set<EnvironmentService> services Set of EnvironmentServices available to the agent.
Public Constructors
AbstractParticipant(UUID id, String name)

Basic Participant constructor.

Public Methods
void act(Action a)
void enqueueInput(Object input)
Adds a new input to be processed by this participant.
void enqueueInput(Collection<? extends Object> inputs)
Adds multiple new inputs to be processed by this participant.
<T extends EnvironmentService> T getEnvironmentService(Class<T> type)
UUID getID()
Returns the participant's unique ID.
String getName()
Returns a unique string identifier for this participant.
void initialise()

The initialisation process for the AbstractParticipant involves the following:

  • Registering with the environment.
void persistParticipant(StorageService storage)
String toString()
Protected Methods
Set<ParticipantSharedState> getSharedState()
Get the set of shared states that this Participant has.
void initialiseInputQueue()
Initialises inputQueue which will be a FIFO queue for Inputs received by the Participant.
void processEnvironmentServices(Set<EnvironmentService> services)

Process the EnvironmentServices from environment registration.

[Expand]
Inherited Methods
From class java.lang.Object
From interface uk.ac.imperial.presage2.core.environment.EnvironmentServiceProvider
From interface uk.ac.imperial.presage2.core.participant.Participant

Fields

protected UUID authkey

This Participant's authkey obtained when registering with the environment.

protected EnvironmentConnector environment

Connector to the environment the participant is in.

protected Queue<Object> inputQueue

FIFO queue of inputs to be processed.

protected final Logger logger

Logger for this agent.

protected PersistentAgent persist

Persistence of this agent into the database.

protected final Set<EnvironmentService> services

Set of EnvironmentServices available to the agent.

Public Constructors

public AbstractParticipant (UUID id, String name)

Basic Participant constructor.

Requires environment & network to be injected by field injection. This can be done either by creating this object with a guice injector or by using on-demand injection:

 Injector injector = Guice.createInjector(...);
 
 RealParticipant participant = new RealParticipant(...);
 injector.injectMembers(participant);
 

Public Methods

public void act (Action a)

public void enqueueInput (Object input)

Adds a new input to be processed by this participant.

public void enqueueInput (Collection<? extends Object> inputs)

Adds multiple new inputs to be processed by this participant.

public T getEnvironmentService (Class<T> type)

public UUID getID ()

Returns the participant's unique ID.

Returns
  • This participant's unique UUID

public String getName ()

Returns a unique string identifier for this participant. This is used purely for a human readable identifier of the agent so the unique requirement is not mandatory. However it is convenient.

Returns
  • unique string identifier for this participant

public void initialise ()

The initialisation process for the AbstractParticipant involves the following:

  • Registering with the environment.
  • Creating a Queue for incoming Inputs
We split these up into protected function calls in case the implementor wishes to override only certain parts of this process.

public void persistParticipant (StorageService storage)

public String toString ()

Since: API Level

Protected Methods

protected Set<ParticipantSharedState> getSharedState ()

Get the set of shared states that this Participant has. Used for the environment registration request for this participant.

protected void initialiseInputQueue ()

Initialises inputQueue which will be a FIFO queue for Inputs received by the Participant.

protected void processEnvironmentServices (Set<EnvironmentService> services)

Process the EnvironmentServices from environment registration.

This will probably involve looking for ones you can use, pulling them out, and casting them to the correct type.