org.rhq.core.domain.resource
Class Agent

java.lang.Object
  extended by org.rhq.core.domain.resource.Agent
All Implemented Interfaces:
Serializable

public class Agent
extends Object
implements Serializable

A JON agent.

See Also:
Serialized Form

Field Summary
static String QUERY_COUNT_ALL
           
static String QUERY_FIND_ALL
           
static String QUERY_FIND_ALL_SUSPECT_AGENTS
           
static String QUERY_FIND_BY_ADDRESS_AND_PORT
           
static String QUERY_FIND_BY_AGENT_TOKEN
           
static String QUERY_FIND_BY_NAME
           
static String QUERY_FIND_BY_RESOURCE_ID
           
static String QUERY_FIND_RESOURCE_IDS_FOR_AGENT
           
static long serialVersionUID
           
 
Constructor Summary
protected Agent()
          Creates a new instance of Agent
  Agent(String name, String address, int port, String remoteEndpoint, String agentToken)
          Constructor for Agent.
 
Method Summary
 boolean equals(Object obj)
           
static String generateRandomToken(String seed)
          Generates a string of up to 100 chars of a (generally) random token.
 String getAddress()
          Returns the machine address that is used to connect to the agent.
 String getAgentToken()
          Returns the token string that allows the agent to talk back to the server.
 long getCreatedTime()
          Returns when this agent object was initially created.
 int getId()
           
 Date getLastAvailabilityReport()
          Returns the timestamp when this agent last returned an availability report.
 long getModifiedTime()
          Returns when this agent object was modified - usually when it receives a new security token.
 String getName()
          The agent's name will usually, but is not required to, be the fully qualified domain name of the machine where the agent is running.
 int getPort()
          Returns the port number that the agent is listening to when accepting messages from the server.
 String getRemoteEndpoint()
          The remote endpoint is the full connection string that is to be used to connect to the agent.
 int hashCode()
           
 void setAddress(String address)
           
 void setAgentToken(String agentToken)
           
 void setId(int id)
           
 void setLastAvailabilityReport(Date lastAvailabilityReport)
          Sets the timestamp when this agent last returned an availability report.
 void setName(String name)
           
 void setPort(int port)
           
 void setRemoteEndpoint(String locatorUri)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

public static final long serialVersionUID
See Also:
Constant Field Values

QUERY_FIND_BY_NAME

public static final String QUERY_FIND_BY_NAME
See Also:
Constant Field Values

QUERY_FIND_BY_ADDRESS_AND_PORT

public static final String QUERY_FIND_BY_ADDRESS_AND_PORT
See Also:
Constant Field Values

QUERY_FIND_BY_AGENT_TOKEN

public static final String QUERY_FIND_BY_AGENT_TOKEN
See Also:
Constant Field Values

QUERY_FIND_BY_RESOURCE_ID

public static final String QUERY_FIND_BY_RESOURCE_ID
See Also:
Constant Field Values

QUERY_FIND_ALL

public static final String QUERY_FIND_ALL
See Also:
Constant Field Values

QUERY_COUNT_ALL

public static final String QUERY_COUNT_ALL
See Also:
Constant Field Values

QUERY_FIND_RESOURCE_IDS_FOR_AGENT

public static final String QUERY_FIND_RESOURCE_IDS_FOR_AGENT
See Also:
Constant Field Values

QUERY_FIND_ALL_SUSPECT_AGENTS

public static final String QUERY_FIND_ALL_SUSPECT_AGENTS
See Also:
Constant Field Values
Constructor Detail

Agent

protected Agent()
Creates a new instance of Agent


Agent

public Agent(@NotNull
             String name,
             String address,
             int port,
             String remoteEndpoint,
             String agentToken)
Constructor for Agent.

Parameters:
name -
address -
port -
remoteEndpoint -
agentToken -
Method Detail

getId

public int getId()

setId

public void setId(int id)

getName

@NotNull
public String getName()
The agent's name will usually, but is not required to, be the fully qualified domain name of the machine where the agent is running. In other words, the address. However, there is no technical reason why you cannot have an agent with a name such as "foo". In fact, there are use-cases where the agent name is not the same as the address (e.g. perhaps you expect the machine to periodically change hostnames due to DNS name changes and so you want to name it something more permanent).

Agent names must be unique - no two agents can have the same name.

Returns:
the agent's unique name

setName

public void setName(@NotNull
                    String name)

getAddress

@NotNull
public String getAddress()
Returns the machine address that is used to connect to the agent. This can be either an IP address or a fully qualified host name.

Returns:
the name of the host where the agent is located

setAddress

public void setAddress(@NotNull
                       String address)

getPort

public int getPort()
Returns the port number that the agent is listening to when accepting messages from the server.

Returns:
server socket port being listened to by the agent

setPort

public void setPort(int port)

getAgentToken

@NotNull
public String getAgentToken()
Returns the token string that allows the agent to talk back to the server. If the agent provides an agent token different that this, the server will ignore the agent's messages. The agent gets a new token whenever it registers with the server.

Returns:
agent token string

setAgentToken

public void setAgentToken(@NotNull
                          String agentToken)

getRemoteEndpoint

public String getRemoteEndpoint()
The remote endpoint is the full connection string that is to be used to connect to the agent. If null, a default protocol mechanism will be used. The remote endpoint will usually have both the address and port encoded in it.

Returns:
the endpoint describing where and how to communicate with the agent

setRemoteEndpoint

public void setRemoteEndpoint(String locatorUri)

getCreatedTime

public long getCreatedTime()
Returns when this agent object was initially created.

Returns:
creation time

getModifiedTime

public long getModifiedTime()
Returns when this agent object was modified - usually when it receives a new security token. Other times an agent will be modified is when it registers a new remote endpoint (in the case when the agent changes the port it is listening to, for example).

Returns:
modified time

getLastAvailabilityReport

public Date getLastAvailabilityReport()
Returns the timestamp when this agent last returned an availability report. If null, then this agent has yet to send its very first availability report.

Returns:
timestamp when the last availability report was received from this agent

setLastAvailabilityReport

public void setLastAvailabilityReport(Date lastAvailabilityReport)
Sets the timestamp when this agent last returned an availability report.

Parameters:
lastAvailabilityReport - when the last availability report was received from this agent

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

generateRandomToken

public static String generateRandomToken(String seed)
Generates a string of up to 100 chars of a (generally) random token. You can then pass the generated string into setAgentToken(String) if you need to assign the agent a new token.

Parameters:
seed - a string to help seed the random number generator - try to make this as unique as possible so as not to collide with other agents (agent name would be a good candidate)
Returns:
a random token string


Copyright © 2008 RHQ Project Advisory Board (Red Hat, Inc. and Hyperic, Inc.). All Rights Reserved.