Class KristenHttpServer
- java.lang.Object
-
- com.kristensoft.kdc.Server
-
- com.kristensoft.kdc.KristenHttpServer
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Runnable
public class KristenHttpServer extends Server
Provides a KDC server for receiving and processing agents using the HTTP protocol.The server creates a default HTTP context using the path configured by
KristenHttpServerParameters. Additional contexts may be created usingcreateContext(String).Received agents are deserialized and dispatched to the APIs configured for the server.
- Author:
- Charles B. Kozoyed
- See Also:
Server,KristenHttpServerParameters,KristenHttpClient
-
-
Constructor Summary
Constructors Constructor Description KristenHttpServer(KristenHttpServerParameters parameters)Creates an HTTP server using the specified parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Removes all pending requests from the HTTP server request queue.voidclose()Closes this HTTP server, allowing up to one second for current HTTP exchanges to complete.com.sun.net.httpserver.HttpContextcreateContext(String path)Creates an HTTP context for the specified path.voiddeleteContext(com.sun.net.httpserver.HttpContext context)Removes the specified HTTP context from this server.voiddeleteContext(String path)Removes the HTTP context associated with the specified path from this server.voidflushMetrics()Flushes the accumulated latency metrics for this communication entity.AgentSerializergetAgentSerializer()Returns the agent serializer used by this communication entity.com.sun.net.httpserver.HttpContextgetDefaultContext()Returns the default HTTP context for this server.KristenHttpServerParametersgetKristenHttpServerParameters()Returns the parameters used to configure this HTTP server.InetSocketAddressgetLocalAddress()Returns the local address of this HTTP server.voidhalt()Halts this HTTP server by closing it.booleanisRunning()Determines whether this communication entity is currently running.voidrun()Starts this HTTP server.voidstart()Starts this HTTP server.voidstop(int delay)Stops this HTTP server.-
Methods inherited from class com.kristensoft.kdc.Server
getBacklog, getHub, sendAsync, stop
-
-
-
-
Constructor Detail
-
KristenHttpServer
public KristenHttpServer(KristenHttpServerParameters parameters) throws com.kristensoft.kdc.license.runtime.LicenseException, KristenCommsException
Creates an HTTP server using the specified parameters.The server is started automatically if automatic startup is enabled in the supplied parameters.
- Parameters:
parameters- the parameters used to configure the HTTP server- Throws:
IllegalArgumentException- ifparametersisnullcom.kristensoft.kdc.license.runtime.LicenseException- if the server cannot be created due to a licensing errorKristenCommsException- if a KDC communications error occurs- See Also:
KristenHttpServerParameters
-
-
Method Detail
-
getKristenHttpServerParameters
public KristenHttpServerParameters getKristenHttpServerParameters()
Returns the parameters used to configure this HTTP server.- Returns:
- the HTTP server parameters
-
run
public void run()
Starts this HTTP server.
-
start
public void start()
Starts this HTTP server.Creates the underlying HTTP server, configures its request executor and default context, and begins accepting HTTP requests. If the server is already started, this method returns without taking further action.
-
clear
public void clear()
Removes all pending requests from the HTTP server request queue.
-
stop
public void stop(int delay)
Stops this HTTP server.The specified delay allows current HTTP exchanges time to complete before the underlying server is stopped. If the server is not started, this method returns without taking further action.
- Parameters:
delay- the maximum time, in seconds, to wait for current exchanges to complete- Throws:
IllegalArgumentException- ifdelayis less than zeroIllegalStateException- if the underlying HTTP server is not available
-
createContext
public com.sun.net.httpserver.HttpContext createContext(String path)
Creates an HTTP context for the specified path.Agents received through the context are processed using the APIs configured for this server.
- Parameters:
path- the path for the HTTP context- Returns:
- the created HTTP context
- Throws:
IllegalStateException- if the HTTP server is not started or the underlying HTTP server is not availableIllegalArgumentException- ifpathisnull
-
deleteContext
public void deleteContext(com.sun.net.httpserver.HttpContext context)
Removes the specified HTTP context from this server.- Parameters:
context- the HTTP context to remove- Throws:
IllegalStateException- if the HTTP server is not started or the underlying HTTP server is not availableIllegalArgumentException- ifcontextisnull
-
deleteContext
public void deleteContext(String path)
Removes the HTTP context associated with the specified path from this server.- Parameters:
path- the path of the HTTP context to remove- Throws:
IllegalStateException- if the HTTP server is not started or the underlying HTTP server is not availableIllegalArgumentException- ifpathisnull
-
getDefaultContext
public com.sun.net.httpserver.HttpContext getDefaultContext()
Returns the default HTTP context for this server.- Returns:
- the default HTTP context, or
nullif the server has not been started
-
getLocalAddress
public InetSocketAddress getLocalAddress()
Returns the local address of this HTTP server.- Returns:
- the local server address, or
nullif the underlying HTTP server has not been created
-
close
public void close()
Closes this HTTP server, allowing up to one second for current HTTP exchanges to complete.
-
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
-
-