Package org.apache.vinci.transport
Class VinciServer
java.lang.Object
org.apache.vinci.transport.BaseServer
org.apache.vinci.transport.VinciServer
"Standard" service container for a VinciServable. This extends BaseServer with functions allowing
port negotiation via interaction with VNS. It also provides rudimentary support for service
control and monitoring by responding to vinci:SHUTDOWN and vinci:PING.
Note that this server class directs requests to a single VinciServable. For many applications it
may be desirable to have one server accept requests that get delegated to multiple services, not
just a single service. For such applications consider using the MultiplexedServer. You can also
implement a VinciServable that implements its own sub-service delegation scheme.
-
Constructor Summary
ConstructorDescriptionVinciServer
(String service_name, String host_name, VinciServable servable) Create a new server.VinciServer
(String service_name, String host_name, VinciServable servable, int myPriority) VinciServer
(String service_name, String host_name, VinciServable servable, int myPriority, int myInstance) Create a new server.VinciServer
(String service_name, VinciServable servable) Create a new server that reports the current machine's IP address as the host.VinciServer
(String service_name, VinciServable servable, int myPriority) VinciServer
(String service_name, VinciServable servable, int myPriority, int myInstance) VinciServer
(VinciServable servable) servable ! -
Method Summary
Modifier and TypeMethodDescriptionstatic Transportable
createShutdownCommand
(String shutdown_message) Factory method for creating a shutdown message.Get the context associated with this server.int
protected int
getPort()
int
protected Runnable
getRunnable
(Socket client) Get a runnable object to run within a pooled thread that will handle the request.int
After invoking serve() or startServing(), this method can be used to determine the port which was negotiated with VNS on which to serve requests.void
serve()
Serve requests until a clean shutdown is triggered.void
Set the VinciContext to be used by this server.boolean
This method is called by the server when a remote shutdown request is received.void
Start a new thread that will serve requests until a clean shutdown is triggered.Methods inherited from class org.apache.vinci.transport.BaseServer
cleanExit, createServerSocket, eval, getServable, getServerSocket, handleRequest, handleRequests, makeTransportable, serve, setSocketTimeout, setThreadPoolSize, shutdownServing, startServing
-
Constructor Details
-
VinciServer
Create a new server. If an incorrect hostname is provided, this server will not be reachable.- Parameters:
service_name
- -host_name
- The DNS hostname of the machine running this server.servable
- -
-
VinciServer
Create a new server that reports the current machine's IP address as the host. This should not be used for DHCP-based hosts since IP address can change.- Parameters:
service_name
- -servable
- -- Throws:
UnknownHostException
- If there is an error determining machine IP address.
-
VinciServer
public VinciServer(String service_name, String host_name, VinciServable servable, int myPriority, int myInstance) Create a new server.- Parameters:
service_name
- -host_name
- -servable
- -myPriority
- -myInstance
- -
-
VinciServer
- Parameters:
service_name
- -host_name
- -servable
- -myPriority
- -
-
VinciServer
public VinciServer(String service_name, VinciServable servable, int myPriority) throws UnknownHostException - Parameters:
service_name
- -servable
- -myPriority
- -- Throws:
UnknownHostException
- -
-
VinciServer
public VinciServer(String service_name, VinciServable servable, int myPriority, int myInstance) throws UnknownHostException - Parameters:
service_name
- -servable
- -myPriority
- -myInstance
- -- Throws:
UnknownHostException
- -
-
VinciServer
servable != null- Parameters:
servable
- -
-
-
Method Details
-
getContext
Get the context associated with this server. By default clients use the global Vinci context, though this can be overridden.- Returns:
- -
-
getPriority
public int getPriority() -
getServiceName
-
getInstance
public int getInstance() -
getHostName
-
getServingPort
public int getServingPort()After invoking serve() or startServing(), this method can be used to determine the port which was negotiated with VNS on which to serve requests.- Returns:
- -
- Since:
- 2.0.15
-
setContext
Set the VinciContext to be used by this server. Set to null if you wish the global context to be used.- Parameters:
c
- -
-
serve
Serve requests until a clean shutdown is triggered. Note that all three exceptions thrown by this method are IOExceptions so a single IOException catch phrase is sufficient unless it is important to determine the particular failure.- Throws:
ServiceDownException
- Thrown if there was a failure to contact VNS for port negotiation.VNSException
- Typically thrown if VNS does not recognize the service provided by this server.IOException
- Thrown if there was some problem with the server socket.IllegalStateException
- if VNS host is not specified.
-
startServing
Start a new thread that will serve requests until a clean shutdown is triggered. Note that all three exceptions thrown by this method are IOExceptions so a single IOException catch phrase is sufficient unless it is important to determine the particular failure. If this method returns without throwing an exception then the port has been determined and a new thread has been launched.- Throws:
ServiceDownException
- Thrown if there was a failure to contact VNS for port negotiation.VNSException
- Typically thrown if VNS does not recognize the service provided by this server.IOException
- Thrown if there was some problem with the server socket.IllegalStateException
- if VNS host is not specified.- Since:
- 2.0.15
-
getRunnable
Description copied from class:BaseServer
Get a runnable object to run within a pooled thread that will handle the request.- Overrides:
getRunnable
in classBaseServer
- Parameters:
client
- -- Returns:
- -
-
createShutdownCommand
Factory method for creating a shutdown message. Send the returned object to any server, and if it is programmed to respond to shutdown, it will do so.- Parameters:
shutdown_message
- Should be used to pass a message explaining the shutdown, or in the future it may also include authentication information for password-protected shutdown.- Returns:
- -
-
shutdown
This method is called by the server when a remote shutdown request is received. In general if you want to stop the server call shutdownServing() -- this method should have probably been declared "protected". You can override this method if you want the shutdown message to be ignored in certain cases.- Parameters:
shutdown_message
- -- Returns:
- -
-
getPort
- Returns:
- -
- Throws:
ServiceDownException
- -VNSException
- -IllegalStateException
- if VNS host isn't specified.
-