public abstract class BaseAgentEndpoint extends BaseAgent implements AgentEndpoint
BaseAgentEndpoint
defines the basic functionality of any Device Agent.Modifier and Type | Class and Description |
---|---|
static class |
BaseAgentEndpoint.Connected
The
BaseAgentEndpoint.Connected object describes the current status and configuration of an AgentEndpoint . |
AgentEndpoint.Status
Modifier and Type | Field and Description |
---|---|
static AgentEndpoint.Status |
NOT_CONNECTED |
Constructor and Description |
---|
BaseAgentEndpoint() |
Modifier and Type | Method and Description |
---|---|
void |
connectToMatcher(Session session)
Connects this
AgentEndpoint instance to a MatcherEndpoint . |
void |
deactivate() |
java.lang.String |
getAgentId() |
java.lang.String |
getDesiredParentId() |
BidUpdate |
getLastBidUpdate() |
AgentEndpoint.Status |
getStatus() |
void |
handlePriceUpdate(PriceUpdate priceUpdate)
|
protected void |
init(java.lang.String agentId,
java.lang.String desiredParentId)
This method should always be called during activation of the agent.
|
void |
matcherEndpointDisconnected(Session session)
|
protected BidUpdate |
publishBid(Bid newBid)
Publishes a new bid to its matcher by creating a new
BidUpdate using a generated bidnumber. |
addObserver, now, publishEvent, removeObserver, setContext
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
setContext
public static final AgentEndpoint.Status NOT_CONNECTED
public java.lang.String getAgentId()
getAgentId
in interface Agent
Agent
.public java.lang.String getDesiredParentId()
getDesiredParentId
in interface AgentEndpoint
Agent
.public AgentEndpoint.Status getStatus()
getStatus
in interface Agent
getStatus
in interface AgentEndpoint
Agent.Status
of the Agent
. This returns a snapshot of the state that won't change.
If used at a later time, the snapshot should be refreshed.protected void init(java.lang.String agentId, java.lang.String desiredParentId)
agentId
- The agentId that should be used by this BaseAgent
. This will be returned when the
getAgentId()
is called.desiredParentId
- The agentId that should be used by this BaseAgentEndpoint
when determining the desired parent.
This will be returned when the getDesiredParentId()
is called.java.lang.IllegalArgumentException
- when either the agentId or the desiredParentId is null or is an empty string.public void connectToMatcher(Session session)
AgentEndpoint
instance to a MatcherEndpoint
.connectToMatcher
in interface AgentEndpoint
session
- the Session
that will link this AgentEndpoint
with a MatcherEndpoint
.public void matcherEndpointDisconnected(Session session)
matcherEndpointDisconnected
in interface AgentEndpoint
session
- the Session
that used to link the MatcherEndpoint
with this AgentEndpoint
.public void deactivate()
public final BidUpdate getLastBidUpdate()
protected final BidUpdate publishBid(Bid newBid)
BidUpdate
using a generated bidnumber. The call will
be ignored if the Agent is not connected.newBid
- The new bid that is to be sent to the connected matcherBidUpdate
that has been set or null
if not connected.public void handlePriceUpdate(PriceUpdate priceUpdate)
MatcherEndpoint
via the Session
to update the Price
used by this
AgentEndpoint
instance.
This base implementation checks if the PriceUpdate
is valid and publishes the
IncomingPriceUpdateEvent
.handlePriceUpdate
in interface AgentEndpoint
priceUpdate
- The new Price
, wrapped in a PriceUpdate
, along with the id of the Bid
it was
based on.