- java.lang.Object
-
- swim.api.agent.AbstractAgent
-
- All Implemented Interfaces:
Agent
,DownlinkFactory
,LaneFactory
,WarpRef
,Store
,Schedule
,Log
public class AbstractAgent extends Object implements Agent, WarpRef, LaneFactory, Schedule, Store, Log
Abstract base class for allAgents
. This class provides skeletalAgent
lifecycle callback implementations, contextualLane
andStore
creation mechanisms, URI-based addressability, logging, and scheduling, primarily via delegation to its internal, immutableAgentContext
.
-
-
Field Summary
Fields Modifier and Type Field Description protected AgentContext
context
Internal, immutable context that provides contextualLane
andStore
creation mechanisms, URI-based addressability, logging, and scheduling.
-
Constructor Summary
Constructors Constructor Description AbstractAgent()
Creates anAbstractAgent
instance managed bySwimContext.getAgentContext()
.AbstractAgent(AgentContext context)
Creates anAbstractAgent
instance managed bycontext
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AgentContext
agentContext()
Returns theAgentContext
used to manage thisAgent
.Value
agentId()
FingerTrieSeq<Agent>
agents()
Stage
asyncStage()
The multi-threaded executionStage
on which thisAgentContext
can run asynchronous operations.String
cipherSuite()
Returns the cryptographic cipher suite used by the currently executing link, or null if the currently executing link is not secure, or if not currently executing a link callback.void
close()
void
closeAgent(String name)
void
closeAgent(Value id)
void
command(String nodeUri, String laneUri, float prio, Value body)
void
command(String nodeUri, String laneUri, float prio, Value body, Cont<CommandMessage> cont)
void
command(String hostUri, String nodeUri, String laneUri, float prio, Value body)
void
command(String hostUri, String nodeUri, String laneUri, float prio, Value body, Cont<CommandMessage> cont)
void
command(String hostUri, String nodeUri, String laneUri, Value body)
void
command(String hostUri, String nodeUri, String laneUri, Value body, Cont<CommandMessage> cont)
void
command(String nodeUri, String laneUri, Value body)
void
command(String nodeUri, String laneUri, Value body, Cont<CommandMessage> cont)
void
command(Uri nodeUri, Uri laneUri, float prio, Value body)
void
command(Uri nodeUri, Uri laneUri, float prio, Value body, Cont<CommandMessage> cont)
void
command(Uri nodeUri, Uri laneUri, Value body)
void
command(Uri nodeUri, Uri laneUri, Value body, Cont<CommandMessage> cont)
void
command(Uri hostUri, Uri nodeUri, Uri laneUri, float prio, Value body)
void
command(Uri hostUri, Uri nodeUri, Uri laneUri, float prio, Value body, Cont<CommandMessage> cont)
void
command(Uri hostUri, Uri nodeUri, Uri laneUri, Value body)
void
command(Uri hostUri, Uri nodeUri, Uri laneUri, Value body, Cont<CommandMessage> cont)
<V> CommandLane<V>
commandLane()
void
debug(Object message)
Logs a debug-level message.<V> DemandLane<V>
demandLane()
<K,V>
DemandMapLane<K,V>demandMapLane()
void
didClose()
Lifecycle callback invoked immediately after thisAgent
closes.void
didFail(Throwable error)
Lifecycle callback invoked immediately after thisAgent
throwserror
.void
didLoad()
Lifecycle callback invoked immediately after thisAgent
loads, i.e.void
didOpen()
Lifecycle callback invoked immediately after thisAgent
opens, i.e.void
didStart()
Lifecycle callback invoked immediately after thisAgent
starts.void
didStop()
Lifecycle callback invoked immediately after thisAgent
stops, i.e.void
didUnload()
Lifecycle callback invoked immediately after thisAgent
unloads, i.e.EventDownlink<Value>
downlink()
<V> HttpDownlink<V>
downlinkHttp()
ListDownlink<Value>
downlinkList()
MapDownlink<Value,Value>
downlinkMap()
ValueDownlink<Value>
downlinkValue()
<I,O>
WsDownlink<I,O>downlinkWs()
void
error(Object message)
Logs an error-level message.void
fail(Object message)
Logs an fail-level message.SpatialData<Value,R2Shape,Value>
geospatialData(String name)
SpatialData<Value,R2Shape,Value>
geospatialData(Value name)
<K,V>
SpatialLane<K,R2Shape,V>geospatialLane()
<A extends Agent>
AgetAgent(Class<A> agentClass)
Agent
getAgent(String name)
Agent
getAgent(Value id)
Lane
getLane(Uri laneUri)
Value
getProp(String name)
Returns the value ofname
inprops()
.Value
getProp(Value key)
Returns the value ofkey
inprops()
.HostRef
hostRef(String hostUri)
HostRef
hostRef(Uri hostUri)
Uri
hostUri()
ThisAgent
'shostUri
.<V> HttpLane<V>
httpLane()
void
info(Object message)
Logs an info-level message.boolean
isSecure()
Returns true if the currently executing link is secure, or false if the currently executing link is not secure, or if not currently executing a link callback.<L,K,V>
JoinMapLane<L,K,V>joinMapLane()
<K,V>
JoinValueLane<K,V>joinValueLane()
Lane
lane()
Returns the currently executing lane, or null if not currently executing a lane or link callback.LaneRef
laneRef(String nodeUri, String laneUri)
LaneRef
laneRef(String hostUri, String nodeUri, String laneUri)
LaneRef
laneRef(Uri nodeUri, Uri laneUri)
LaneRef
laneRef(Uri hostUri, Uri nodeUri, Uri laneUri)
Link
link()
Returns the currently executing link, or null if not currently executing a link callback.ListData<Value>
listData(String name)
ListData<Value>
listData(Value name)
<V> ListLane<V>
listLane()
InetSocketAddress
localAddress()
Returns the local internet address of the currently executing link, or null if not currently executing a link callback.Collection<Certificate>
localCertificates()
Returns the certificates used to authenticate the local end of the currently executing link; returns an empty collection if the currently executing link has no local certificates, or if not currently executing a link callback.Identity
localIdentity()
Returns the local user identity of the currently executing link, or null if the currently executing link has no local user identity, or if not currently executing a link callback.Principal
localPrincipal()
Returns the principal used to identify the local end of the currently executing link, or null if the currently executing link has no local principal, or if not currently executing a link callback.MapData<Value,Value>
mapData(String name)
MapData<Value,Value>
mapData(Value name)
<K,V>
MapLane<K,V>mapLane()
NodeRef
nodeRef(String nodeUri)
NodeRef
nodeRef(String hostUri, String nodeUri)
NodeRef
nodeRef(Uri nodeUri)
NodeRef
nodeRef(Uri hostUri, Uri nodeUri)
Uri
nodeUri()
ThisAgent
'snodeUri
.<A extends Agent>
AopenAgent(String name, Class<A> agentClass)
<A extends Agent>
AopenAgent(String name, AgentFactory<A> agentFactory)
<A extends Agent>
AopenAgent(Value id, Class<A> agentClass)
<A extends Agent>
AopenAgent(Value id, AgentFactory<A> agentFactory)
<A extends Agent>
AopenAgent(Value id, Value props, Class<A> agentClass)
<A extends Agent>
AopenAgent(Value id, Value props, AgentFactory<A> agentFactory)
Lane
openLane(Uri laneUri, Lane lane)
Value
props()
ARecord
that maps every dynamic property innodeUri()
, as defined byAgentRoute.pattern()
, to its value.InetSocketAddress
remoteAddress()
Returns the remote internet address of the currently executing link, or null if not currently executing a link callback.Collection<Certificate>
remoteCertificates()
Returns the certificates used to authenticate the remote end of the currently executing link; returns an empty collection if the currently executing link has no remote certificates, or if not currently executing a link callback.Identity
remoteIdentity()
Returns the remote user identity of the currently executing link, or null if the currently executing link has no remote user identity, or if not currently executing a link callback.Principal
remotePrincipal()
Returns the principal used to identify the remote end of the currently executing link, or null if the currently executing link has no remote principal, or if not currently executing a link callback.Schedule
schedule()
TheSchedule
that thisAgent
is bound to.String
securityProtocol()
Returns the security protocol used by the currently executing link, or null if the currently executing link is not secure, or if not currently executing a link callback.TimerRef
setTimer(long millis, TimerFunction timer)
Schedulestimer
to execute aftermillis
milliseconds have elapsed.<S> SpatialData<Value,S,Value>
spatialData(String name, Z2Form<S> shapeForm)
<S> SpatialData<Value,S,Value>
spatialData(Value name, Z2Form<S> shapeForm)
<K,S,V>
SpatialLane<K,S,V>spatialLane(Z2Form<S> shapeForm)
Stage
stage()
The single-threaded executionStage
on which thisAgentContext
runs its application logic.<V> SupplyLane<V>
supplyLane()
TimerRef
timer(TimerFunction timer)
Returns an unscheduledTimerRef
bound totimer
, which can later be used to scheduletimer
.void
trace(Object message)
Logs a trace-level message.ValueData<Value>
valueData(String name)
ValueData<Value>
valueData(Value name)
<V> ValueLane<V>
valueLane()
void
warn(Object message)
Logs a warn-level message.void
willClose()
Lifecycle callback invoked immediately before thisAgent
closes.void
willLoad()
Lifecycle callback invoked immediately before thisAgent
loads.void
willOpen()
Lifecycle callback invoked immediately before thisAgent
opens.void
willStart()
Lifecycle callback invoked immediately before thisAgent
starts.void
willStop()
Lifecycle callback invoked immediately before thisAgent
stops.void
willUnload()
Lifecycle callback invoked immediately before thisAgent
unloads.<I,O>
WsLane<I,O>wsLane()
-
-
-
Field Detail
-
context
protected final AgentContext context
Internal, immutable context that provides contextualLane
andStore
creation mechanisms, URI-based addressability, logging, and scheduling.
-
-
Constructor Detail
-
AbstractAgent
public AbstractAgent(AgentContext context)
Creates anAbstractAgent
instance managed bycontext
.
-
AbstractAgent
public AbstractAgent()
Creates anAbstractAgent
instance managed bySwimContext.getAgentContext()
.
-
-
Method Detail
-
agentContext
public AgentContext agentContext()
Description copied from interface:Agent
Returns theAgentContext
used to manage thisAgent
.- Specified by:
agentContext
in interfaceAgent
-
willOpen
public void willOpen()
Description copied from interface:Agent
Lifecycle callback invoked immediately before thisAgent
opens.//@see swim.system.TierBinding#open
-
didOpen
public void didOpen()
Description copied from interface:Agent
Lifecycle callback invoked immediately after thisAgent
opens, i.e. before it loads.//@see swim.system.TierBinding#open //@see swim.system.TierBinding#load
-
willLoad
public void willLoad()
Description copied from interface:Agent
Lifecycle callback invoked immediately before thisAgent
loads.//@see swim.system.TierBinding#load
-
didLoad
public void didLoad()
Description copied from interface:Agent
Lifecycle callback invoked immediately after thisAgent
loads, i.e. before it starts.//@see swim.system.TierBinding#load //@see swim.system.TierBinding#start
-
willStart
public void willStart()
Description copied from interface:Agent
Lifecycle callback invoked immediately before thisAgent
starts.//@see swim.system.TierBinding#start
-
didStart
public void didStart()
Description copied from interface:Agent
Lifecycle callback invoked immediately after thisAgent
starts.//@see swim.system.TierBinding#start
-
willStop
public void willStop()
Description copied from interface:Agent
Lifecycle callback invoked immediately before thisAgent
stops.//@see swim.system.TierBinding#stop
-
didStop
public void didStop()
Description copied from interface:Agent
Lifecycle callback invoked immediately after thisAgent
stops, i.e. before it unloads.//@see swim.system.TierBinding#stop //@see swim.system.TierBinding#unload
-
willUnload
public void willUnload()
Description copied from interface:Agent
Lifecycle callback invoked immediately before thisAgent
unloads.//@see swim.system.TierBinding#unload
- Specified by:
willUnload
in interfaceAgent
-
didUnload
public void didUnload()
Description copied from interface:Agent
Lifecycle callback invoked immediately after thisAgent
unloads, i.e. before it closes.//@see swim.system.TierBinding.unload //@see swim.system.TierBinding.close
-
willClose
public void willClose()
Description copied from interface:Agent
Lifecycle callback invoked immediately before thisAgent
closes.//@see swim.system.TierBinding.close
-
didClose
public void didClose()
Description copied from interface:Agent
Lifecycle callback invoked immediately after thisAgent
closes.//@see swim.system.TierBinding.close
-
didFail
public void didFail(Throwable error)
Description copied from interface:Agent
Lifecycle callback invoked immediately after thisAgent
throwserror
.
-
hostUri
public final Uri hostUri()
ThisAgent
'shostUri
.
-
nodeUri
public final Uri nodeUri()
ThisAgent
'snodeUri
.
-
agentId
public final Value agentId()
-
props
public final Value props()
ARecord
that maps every dynamic property innodeUri()
, as defined byAgentRoute.pattern()
, to its value. An empty result indicates thatnodeUri
contains no dynamic components.
-
stage
public final Stage stage()
The single-threaded executionStage
on which thisAgentContext
runs its application logic.
-
asyncStage
public final Stage asyncStage()
The multi-threaded executionStage
on which thisAgentContext
can run asynchronous operations.
-
lane
public final Lane lane()
Returns the currently executing lane, or null if not currently executing a lane or link callback.
-
link
public final Link link()
Returns the currently executing link, or null if not currently executing a link callback.
-
agents
public FingerTrieSeq<Agent> agents()
-
openAgent
public <A extends Agent> A openAgent(Value id, Value props, AgentFactory<A> agentFactory)
-
openAgent
public <A extends Agent> A openAgent(Value id, AgentFactory<A> agentFactory)
-
openAgent
public <A extends Agent> A openAgent(String name, AgentFactory<A> agentFactory)
-
closeAgent
public void closeAgent(Value id)
-
closeAgent
public void closeAgent(String name)
-
isSecure
public boolean isSecure()
Returns true if the currently executing link is secure, or false if the currently executing link is not secure, or if not currently executing a link callback.
-
securityProtocol
public String securityProtocol()
Returns the security protocol used by the currently executing link, or null if the currently executing link is not secure, or if not currently executing a link callback.
-
cipherSuite
public String cipherSuite()
Returns the cryptographic cipher suite used by the currently executing link, or null if the currently executing link is not secure, or if not currently executing a link callback.
-
localAddress
public InetSocketAddress localAddress()
Returns the local internet address of the currently executing link, or null if not currently executing a link callback.
-
localIdentity
public Identity localIdentity()
Returns the local user identity of the currently executing link, or null if the currently executing link has no local user identity, or if not currently executing a link callback.
-
localPrincipal
public Principal localPrincipal()
Returns the principal used to identify the local end of the currently executing link, or null if the currently executing link has no local principal, or if not currently executing a link callback.
-
localCertificates
public Collection<Certificate> localCertificates()
Returns the certificates used to authenticate the local end of the currently executing link; returns an empty collection if the currently executing link has no local certificates, or if not currently executing a link callback.
-
remoteAddress
public InetSocketAddress remoteAddress()
Returns the remote internet address of the currently executing link, or null if not currently executing a link callback.
-
remoteIdentity
public Identity remoteIdentity()
Returns the remote user identity of the currently executing link, or null if the currently executing link has no remote user identity, or if not currently executing a link callback.
-
remotePrincipal
public Principal remotePrincipal()
Returns the principal used to identify the remote end of the currently executing link, or null if the currently executing link has no remote principal, or if not currently executing a link callback.
-
remoteCertificates
public Collection<Certificate> remoteCertificates()
Returns the certificates used to authenticate the remote end of the currently executing link; returns an empty collection if the currently executing link has no remote certificates, or if not currently executing a link callback.
-
commandLane
public final <V> CommandLane<V> commandLane()
- Specified by:
commandLane
in interfaceLaneFactory
-
demandLane
public final <V> DemandLane<V> demandLane()
- Specified by:
demandLane
in interfaceLaneFactory
-
demandMapLane
public final <K,V> DemandMapLane<K,V> demandMapLane()
- Specified by:
demandMapLane
in interfaceLaneFactory
-
httpLane
public final <V> HttpLane<V> httpLane()
- Specified by:
httpLane
in interfaceLaneFactory
-
joinMapLane
public final <L,K,V> JoinMapLane<L,K,V> joinMapLane()
- Specified by:
joinMapLane
in interfaceLaneFactory
-
joinValueLane
public final <K,V> JoinValueLane<K,V> joinValueLane()
- Specified by:
joinValueLane
in interfaceLaneFactory
-
listLane
public final <V> ListLane<V> listLane()
- Specified by:
listLane
in interfaceLaneFactory
-
mapLane
public final <K,V> MapLane<K,V> mapLane()
- Specified by:
mapLane
in interfaceLaneFactory
-
spatialLane
public final <K,S,V> SpatialLane<K,S,V> spatialLane(Z2Form<S> shapeForm)
- Specified by:
spatialLane
in interfaceLaneFactory
-
geospatialLane
public final <K,V> SpatialLane<K,R2Shape,V> geospatialLane()
- Specified by:
geospatialLane
in interfaceLaneFactory
-
supplyLane
public final <V> SupplyLane<V> supplyLane()
- Specified by:
supplyLane
in interfaceLaneFactory
-
valueLane
public final <V> ValueLane<V> valueLane()
- Specified by:
valueLane
in interfaceLaneFactory
-
wsLane
public final <I,O> WsLane<I,O> wsLane()
- Specified by:
wsLane
in interfaceLaneFactory
-
spatialData
public final <S> SpatialData<Value,S,Value> spatialData(Value name, Z2Form<S> shapeForm)
- Specified by:
spatialData
in interfaceStore
-
spatialData
public final <S> SpatialData<Value,S,Value> spatialData(String name, Z2Form<S> shapeForm)
- Specified by:
spatialData
in interfaceStore
-
geospatialData
public final SpatialData<Value,R2Shape,Value> geospatialData(Value name)
- Specified by:
geospatialData
in interfaceStore
-
geospatialData
public final SpatialData<Value,R2Shape,Value> geospatialData(String name)
- Specified by:
geospatialData
in interfaceStore
-
downlink
public final EventDownlink<Value> downlink()
- Specified by:
downlink
in interfaceDownlinkFactory
-
downlinkList
public final ListDownlink<Value> downlinkList()
- Specified by:
downlinkList
in interfaceDownlinkFactory
-
downlinkMap
public final MapDownlink<Value,Value> downlinkMap()
- Specified by:
downlinkMap
in interfaceDownlinkFactory
-
downlinkValue
public final ValueDownlink<Value> downlinkValue()
- Specified by:
downlinkValue
in interfaceDownlinkFactory
-
downlinkHttp
public final <V> HttpDownlink<V> downlinkHttp()
- Specified by:
downlinkHttp
in interfaceDownlinkFactory
-
downlinkWs
public final <I,O> WsDownlink<I,O> downlinkWs()
- Specified by:
downlinkWs
in interfaceDownlinkFactory
-
command
public final void command(Uri hostUri, Uri nodeUri, Uri laneUri, float prio, Value body, Cont<CommandMessage> cont)
-
command
public final void command(String hostUri, String nodeUri, String laneUri, float prio, Value body, Cont<CommandMessage> cont)
-
command
public final void command(Uri hostUri, Uri nodeUri, Uri laneUri, Value body, Cont<CommandMessage> cont)
-
command
public final void command(String hostUri, String nodeUri, String laneUri, Value body, Cont<CommandMessage> cont)
-
command
public final void command(Uri nodeUri, Uri laneUri, float prio, Value body, Cont<CommandMessage> cont)
-
command
public final void command(String nodeUri, String laneUri, float prio, Value body, Cont<CommandMessage> cont)
-
command
public final void command(Uri nodeUri, Uri laneUri, Value body, Cont<CommandMessage> cont)
-
command
public final void command(String nodeUri, String laneUri, Value body, Cont<CommandMessage> cont)
-
command
public final void command(String hostUri, String nodeUri, String laneUri, float prio, Value body)
-
trace
public void trace(Object message)
Description copied from interface:Log
Logs a trace-level message.
-
debug
public void debug(Object message)
Description copied from interface:Log
Logs a debug-level message.
-
info
public void info(Object message)
Description copied from interface:Log
Logs an info-level message.
-
warn
public void warn(Object message)
Description copied from interface:Log
Logs a warn-level message.
-
error
public void error(Object message)
Description copied from interface:Log
Logs an error-level message.
-
fail
public void fail(Object message)
Description copied from interface:Log
Logs an fail-level message.
-
timer
public final TimerRef timer(TimerFunction timer)
Description copied from interface:Schedule
Returns an unscheduledTimerRef
bound totimer
, which can later be used to scheduletimer
.
-
setTimer
public final TimerRef setTimer(long millis, TimerFunction timer)
Description copied from interface:Schedule
Schedulestimer
to execute aftermillis
milliseconds have elapsed. Returns aTimerRef
that can be used to check the status of, reschedule, and canceltimer
.
-
-