Class KristenHttpClient
- java.lang.Object
-
- com.kristensoft.kdc.Client
-
- com.kristensoft.kdc.KristenHttpClient
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Runnable
public class KristenHttpClient extends Client implements Closeable
Provides a KDC client for sending agents using the HTTP protocol.Agents are sent to a
KristenHttpServerusing HTTP POST requests. Both asynchronous and synchronous agent operations are supported. Synchronous operations receive aReplyfrom the server.Instances are configured using
KristenHttpClientParameters.- Author:
- Charles B. Kozoyed
- See Also:
Client,KristenHttpClientParameters,KristenHttpServer
-
-
Constructor Summary
Constructors Constructor Description KristenHttpClient(KristenHttpClientParameters parameters)Creates an HTTP client using the specified parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes this HTTP client.voidconnect()Attempts to establish a connection to the configured HTTP server.voidflushMetrics()Flushes the accumulated latency metrics for this communication entity.AgentSerializergetAgentSerializer()Returns the agent serializer used by this communication entity.KristenHttpClientParametersgetKristenHttpClientParameters()Returns the parameters used to configure this HTTP client.booleanisRunning()Determines whether this communication entity is currently running.Agentreceive()Receiving an agent directly is not supported by the HTTP client.voidsend(byte[] bytes)Sends the specified bytes using the synchronous HTTP send operation.voidsendAsync(Agent agent)Sends an agent asynchronously to the configured HTTP server.ReplysendSync(Agent agent)Sends an agent synchronously to the configured HTTP server and waits for a reply.-
Methods inherited from class com.kristensoft.kdc.Client
getClientParameters, getServerHub, halt, nextReply, peekReply, pollReply, pollReply, replyAvailable, run, start, stop, takeReply
-
-
-
-
Constructor Detail
-
KristenHttpClient
public KristenHttpClient(KristenHttpClientParameters parameters) throws com.kristensoft.kdc.license.runtime.LicenseException
Creates an HTTP client using the specified parameters.- Parameters:
parameters- the parameters used to configure the HTTP client- Throws:
IllegalArgumentException- ifparametersisnullcom.kristensoft.kdc.license.runtime.LicenseException- if the client cannot be created due to a licensing error- See Also:
KristenHttpClientParameters
-
-
Method Detail
-
getKristenHttpClientParameters
public KristenHttpClientParameters getKristenHttpClientParameters()
Returns the parameters used to configure this HTTP client.- Returns:
- the HTTP client parameters
-
receive
public Agent receive()
Receiving an agent directly is not supported by the HTTP client.- Returns:
null
-
connect
public void connect()
Attempts to establish a connection to the configured HTTP server.The result of the connection attempt is reported to the configured
KristenHttpClientEventHandlerinstances.
-
sendAsync
public void sendAsync(Agent agent) throws IOException, KristenCommsException
Sends an agent asynchronously to the configured HTTP server.- Overrides:
sendAsyncin classClient- Parameters:
agent- the agent to send- Throws:
IllegalArgumentException- ifagentisnullIOException- if an I/O error occurs while sending the agentKristenCommsException- if a KDC communications error occurs- See Also:
Agent.getClient()
-
sendSync
public Reply sendSync(Agent agent) throws IOException, com.kristensoft.ko.KristenObjectsException, KristenCommsException
Sends an agent synchronously to the configured HTTP server and waits for a reply.- Parameters:
agent- the agent to send- Returns:
- the reply received from the HTTP server, or
nullif a reply cannot be obtained - Throws:
IllegalArgumentException- ifagentisnullIOException- if an I/O error occurs while sending or receivingcom.kristensoft.ko.KristenObjectsException- if an object serialization or deserialization error occursKristenCommsException- if a KDC communications error occurs
-
close
public final void close()
Closes this HTTP client.No explicit cleanup is required because HTTP connections and their underlying resources are managed by the HTTP implementation.
-
send
public void send(byte[] bytes)
Sends the specified bytes using the synchronous HTTP send operation.- Parameters:
bytes- the bytes to send
-
isRunning
public boolean isRunning()
Determines whether this communication entity is currently running.- Returns:
trueif this communication entity is running;falseotherwise
-
flushMetrics
public void flushMetrics()
Flushes the accumulated latency metrics for this communication entity.This method may be used to report any currently accumulated metrics without waiting for the configured latency reporting interval.
-
getAgentSerializer
public AgentSerializer getAgentSerializer()
Returns the agent serializer used by this communication entity.The serializer may be used to inspect or modify serialization settings at runtime, including compression and encryption settings.
- Returns:
- the agent serializer used by this communication entity
-
-