public abstract class Server extends Object
Writable as a
parameter, and return a Writable as their value. A service runs on
a port and is defined by a parameter class and a value class.Client| Modifier and Type | Field and Description |
|---|---|
static ByteBuffer |
HEADER |
static org.apache.commons.logging.Log |
LOG |
| Modifier | Constructor and Description |
|---|---|
protected |
Server(String bindAddress,
int port,
Class<? extends IOReadableWritable> paramClass,
int handlerCount) |
protected |
Server(String bindAddress,
int port,
Class<? extends IOReadableWritable> invocationClass,
int handlerCount,
String serverName)
Constructs a server listening on the named port and address.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
bind(ServerSocket socket,
InetSocketAddress address,
int backlog)
A convenience method to bind to a given address and report
better exceptions if the address is not a valid host.
|
abstract IOReadableWritable |
call(Class<?> protocol,
IOReadableWritable param,
long receiveTime)
Called for each call.
|
static Server |
get()
Returns the server instance called under or null.
|
int |
getCallQueueLen()
The number of rpc calls in the queue.
|
InetSocketAddress |
getListenerAddress()
Return the socket (ip+port) on which the RPC server is listening to.
|
int |
getNumOpenConnections()
The number of open RPC conections
|
static String |
getRemoteAddress()
Returns remote address as a string when invoked inside an RPC.
|
static InetAddress |
getRemoteIp()
Returns the remote side ip address when invoked inside an RPC
Returns null incase of an error.
|
void |
join()
Wait for the server to be stopped.
|
static <T> T |
newInstance(Class<T> theClass) |
void |
setSocketSendBufSize(int size)
Sets the socket buffer size used for responding to RPCs
|
void |
start()
Starts the service.
|
void |
stop()
Stops the service.
|
public static final org.apache.commons.logging.Log LOG
public static final ByteBuffer HEADER
protected Server(String bindAddress, int port, Class<? extends IOReadableWritable> paramClass, int handlerCount) throws IOException
IOExceptionprotected Server(String bindAddress, int port, Class<? extends IOReadableWritable> invocationClass, int handlerCount, String serverName) throws IOException
handlerCount determines
the number of handler threads that will be used to process calls.IOExceptionpublic static Server get()
#call(Writable, long)
implementations, and under Writable methods of paramters and return values. Permits applications to
access
the server context.public static InetAddress getRemoteIp()
public static String getRemoteAddress()
public static void bind(ServerSocket socket, InetSocketAddress address, int backlog) throws IOException
socket - the socket to bindaddress - the address to bind tobacklog - the number of connections allowed in the queueBindException - if the address can't be boundUnknownHostException - if the address isn't a valid host nameIOException - other random errors from bindpublic void setSocketSendBufSize(int size)
public void start()
throws IOException
IOExceptionpublic void stop()
public void join()
throws InterruptedException
stop().InterruptedExceptionpublic InetSocketAddress getListenerAddress()
public abstract IOReadableWritable call(Class<?> protocol, IOReadableWritable param, long receiveTime) throws IOException
IOExceptionpublic int getNumOpenConnections()
public int getCallQueueLen()
public static <T> T newInstance(Class<T> theClass)
Copyright © 2014 The Apache Software Foundation. All rights reserved.