public class RRServer
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
CLIENT_ID
The client id
|
protected java.nio.channels.SocketChannel |
clientChannel
the client channel,
|
protected java.util.List<java.nio.channels.SocketChannel> |
connectedChannels
We keep track of connected channels here to make sure we close them
|
protected ConnectHandler |
connectHandler
Connection handler
|
protected Progress |
loop
The loop that executes the selector
|
protected java.util.Map<java.lang.String,Message.Builder> |
messageBuilders
Message type name to builder
|
protected int |
pendingSendCount
We keep track of pending send count to determine weather all the sends are completed
|
protected java.util.Map<RequestID,java.nio.channels.SocketChannel> |
requestChannels
Keep track of the requests
|
protected java.util.Map<java.lang.String,MessageHandler> |
requestHandlers
Keep track of the request handler using protocol buffer message types
|
protected Server |
server |
protected int |
serverID
Job Master ID
|
protected <any> |
workerChannels
worker channels with workerIDs
|
Constructor and Description |
---|
RRServer(Config cfg,
java.lang.String host,
int port,
Progress looper,
int serverID,
ConnectHandler cHandler,
int backLog) |
Modifier and Type | Method and Description |
---|---|
java.util.Set<java.lang.Integer> |
getConnectedWorkers() |
void |
registerRequestHandler(Message.Builder builder,
MessageHandler handler) |
void |
removeWorkerChannel(int workerID)
remove the channel when the worker is removed
|
boolean |
sendMessage(Message message,
int targetID)
Send a non-response message to a worker or to the client
|
protected TCPMessage |
sendMessage(Message message,
RequestID requestID,
java.nio.channels.SocketChannel channel) |
boolean |
sendResponse(RequestID requestID,
Message message)
Send a response to a request id
|
void |
start() |
void |
stop() |
void |
stopGraceFully(long waitTime) |
protected Server server
protected java.util.List<java.nio.channels.SocketChannel> connectedChannels
protected <any> workerChannels
protected java.nio.channels.SocketChannel clientChannel
protected java.util.Map<java.lang.String,MessageHandler> requestHandlers
protected java.util.Map<java.lang.String,Message.Builder> messageBuilders
protected java.util.Map<RequestID,java.nio.channels.SocketChannel> requestChannels
protected int serverID
public static final int CLIENT_ID
protected ConnectHandler connectHandler
protected Progress loop
protected int pendingSendCount
public RRServer(Config cfg, java.lang.String host, int port, Progress looper, int serverID, ConnectHandler cHandler, int backLog)
public void registerRequestHandler(Message.Builder builder, MessageHandler handler)
public void start()
public void stop()
public void stopGraceFully(long waitTime)
public java.util.Set<java.lang.Integer> getConnectedWorkers()
public boolean sendResponse(RequestID requestID, Message message)
requestID
- request idmessage
- messagepublic boolean sendMessage(Message message, int targetID)
message
- messageprotected TCPMessage sendMessage(Message message, RequestID requestID, java.nio.channels.SocketChannel channel)
public void removeWorkerChannel(int workerID)
workerID
-