public class ServiceDispatcher extends StoppableThread
Modifier and Type | Class and Description |
---|---|
static class |
ServiceDispatcher.ExecutingRunnable |
static class |
ServiceDispatcher.ExecutingService
A service that is run immediately in a thread allocated to it.
|
class |
ServiceDispatcher.LazyQueuingService
A queuing service that starts the thread that services the requests
lazily, upon first request and terminates the thread when the service is
unregistered.
|
class |
ServiceDispatcher.QueuingService
A service where requests are simply added to the supplied queue.
|
static class |
ServiceDispatcher.Response
The response to a service request.
|
static class |
ServiceDispatcher.ServiceConnectFailedException |
envImpl
Constructor and Description |
---|
ServiceDispatcher(java.net.InetSocketAddress socketAddress)
Convenience overloading for when the dispatcher is created without a
replicated environment, e.g.
|
ServiceDispatcher(java.net.InetSocketAddress socketAddress,
RepImpl repImpl)
Create a ServiceDispatcher listening on a specific socket for service
requests.
|
Modifier and Type | Method and Description |
---|---|
void |
cancel(java.lang.String serviceName)
Cancels the registration of a service.
|
static void |
doServiceHandshake(java.nio.channels.SocketChannel channel,
java.lang.String serviceName)
A variation on the method above.
|
protected java.util.logging.Logger |
getLogger() |
static java.io.OutputStream |
getServiceOutputStream(java.net.Socket socket,
java.lang.String serviceName)
Used by the client to establish an output stream for the service on the
socket.
|
java.net.InetSocketAddress |
getSocketAddress()
Returns the socket associated with the dispatcher
|
protected int |
initiateSoftShutdown()
Threads that use shutdownThread() must define this method.
|
boolean |
isRegistered(java.lang.String serviceName) |
void |
preShutdown()
Stop accepting new connections, while the individual services quiesce
and shut themselves down.
|
void |
register(com.sleepycat.je.rep.utilint.ServiceDispatcher.Service service) |
void |
register(java.lang.String serviceName,
java.util.concurrent.BlockingQueue<java.nio.channels.SocketChannel> serviceQueue)
Registers a service queue with the ServiceDispatcher.
|
void |
run()
The central run method.
|
void |
setSimulateIOException(java.lang.String serviceName,
boolean simulateException) |
void |
shutdown()
Shuts down the dispatcher, so that it's no longer listening for service
requests.
|
java.nio.channels.SocketChannel |
takeChannel(java.lang.String serviceName,
boolean blocking,
int soTimeout)
Returns the next socketChannel created in response to a request for the
service.
|
cleanup, getSavedShutdownException, getTotalCpuTime, getTotalUserTime, isShutdown, saveShutdownException, setExceptionListener, shutdownDone, shutdownThread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
public ServiceDispatcher(java.net.InetSocketAddress socketAddress, RepImpl repImpl) throws java.io.IOException
socketAddress
- the socket on which it listens for service requestsjava.io.IOException
- if the socket could not be bound.public ServiceDispatcher(java.net.InetSocketAddress socketAddress) throws java.io.IOException
java.io.IOException
ServiceDispatcher(InetSocketAddress, RepImpl)
public void preShutdown()
public void shutdown()
protected int initiateSoftShutdown()
StoppableThread
initiateSoftShutdown
in class StoppableThread
protected java.util.logging.Logger getLogger()
getLogger
in class StoppableThread
StoppableThread.getLogger()
public static java.io.OutputStream getServiceOutputStream(java.net.Socket socket, java.lang.String serviceName) throws java.io.IOException, ServiceDispatcher.ServiceConnectFailedException
socket
- the connected socket that will be the basis for the streamserviceName
- the service running on the streamjava.io.IOException
- if the output stream could not be establishedServiceDispatcher.ServiceConnectFailedException
- if the connection could not be
made.public static void doServiceHandshake(java.nio.channels.SocketChannel channel, java.lang.String serviceName) throws java.io.IOException, ServiceDispatcher.ServiceConnectFailedException
channel
- the channel that is the basis for the serviceserviceName
- the service running on the channelServiceDispatcher.ServiceConnectFailedException
- if the connection could not be
made.java.io.IOException
public java.nio.channels.SocketChannel takeChannel(java.lang.String serviceName, boolean blocking, int soTimeout) throws java.lang.InterruptedException
serviceName
- the service for which the channel must be created.blocking
- true if the channel must be configured to blocksoTimeout
- the timeout for the underlying socketjava.lang.InterruptedException
public java.net.InetSocketAddress getSocketAddress()
public void register(java.lang.String serviceName, java.util.concurrent.BlockingQueue<java.nio.channels.SocketChannel> serviceQueue)
serviceName
- the name of the service being requestedserviceQueue
- the queue that will be used to hold channels
established for the service.public void register(com.sleepycat.je.rep.utilint.ServiceDispatcher.Service service)
public boolean isRegistered(java.lang.String serviceName)
public void setSimulateIOException(java.lang.String serviceName, boolean simulateException)
public void cancel(java.lang.String serviceName)
serviceName
- the name of the service being cancelledpublic void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
Copyright (c) 2004-2012 Oracle. All rights reserved.