com.almende.eve.agent.example
Class ChatAgent

java.lang.Object
  extended by com.almende.eve.agent.Agent
      extended by com.almende.eve.agent.example.ChatAgent
All Implemented Interfaces:
AgentInterface

public class ChatAgent
extends Agent


Constructor Summary
ChatAgent()
           
 
Method Summary
 void connect(String url)
          connect two agents with each other
 void disconnect()
          Disconnect this agent from all other agents in the chat room
 List<String> getConnections()
          Retrieve the urls of all agents that are connected
 String getDescription()
          Retrieve a description of the agents functionality
 String getUsername()
          Get the username
 String getVersion()
          Retrieve the agents version number
 void post(String message)
          Post a message to all registered agents (including itself).
 void receive(String url, String username, String message)
          Receive a message from an agent
 void removeConnection(String url)
          Remove an agent from connections list
 void setUsername(String username)
          Set the username, used for displaying messages
 
Methods inherited from class com.almende.eve.agent.Agent
clear, create, createAgentProxy, delete, destroy, finalize, getAgentFactory, getContext, getId, getMethods, getScheduler, getState, getType, getUrls, init, onSubscribe, onTrigger, onUnsubscribe, send, send, send, send, sendAsync, sendAsync, setAgentFactory, setState, subscribe, toString, trigger, unsubscribe, unsubscribe
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ChatAgent

public ChatAgent()
Method Detail

getUsername

public String getUsername()
                   throws Exception
Get the username

Returns:
Throws:
Exception

setUsername

public void setUsername(String username)
Set the username, used for displaying messages

Parameters:
username -

post

public void post(String message)
          throws Exception
Post a message to all registered agents (including itself).

Parameters:
message -
Throws:
Exception
JSONException
IOException
RuntimeException

receive

public void receive(String url,
                    String username,
                    String message)
             throws Exception
Receive a message from an agent

Parameters:
url -
username -
message -
Throws:
Exception

connect

public void connect(String url)
             throws Exception
connect two agents with each other

Parameters:
url - Url of an ChatAgent
Throws:
Exception

disconnect

public void disconnect()
                throws Exception
Disconnect this agent from all other agents in the chat room

Throws:
Exception

removeConnection

public void removeConnection(String url)
                      throws Exception
Remove an agent from connections list

Parameters:
url - Url of a connected ChatAgent
Throws:
Exception

getConnections

public List<String> getConnections()
Retrieve the urls of all agents that are connected

Returns:

getDescription

public String getDescription()
Description copied from interface: AgentInterface
Retrieve a description of the agents functionality

Specified by:
getDescription in interface AgentInterface
Specified by:
getDescription in class Agent
Returns:
description

getVersion

public String getVersion()
Description copied from interface: AgentInterface
Retrieve the agents version number

Specified by:
getVersion in interface AgentInterface
Specified by:
getVersion in class Agent
Returns:
version


Copyright © 2013 Almende BV. All Rights Reserved.