1, an abstract IPC service. IPC calls take a single {@link writable} as a parameter, and return a {@link writable} as their value. A service runs on a port and was defined by a parameter class and a value class.
2, a total of 5 internal class Exceptionshandler,call,listener,responder,connection,handler
3, many internal properties, the location is more scattered
Private final Boolean authorize;
Private Boolean issecurityenabled;
Private Exceptionshandler Exceptionshandler = new Exceptionshandler ();
Private String bindaddress;
private int port; Port We listen on
private int handlercount; Number of handler threads
private int readthreads; Number of Read threads
Private class<? Extends writable> Paramclass; Class of call parameters
private int maxidletime; The maximum idle time after which a client is disconnected
private int thresholdidleconnections; The number of the idle connections after which we'll start cleaning up idle connections
int Maxconnectionstonuke; The max number of connections to nuke during a cleanup
protected Rpcinstrumentation rpcmetrics;
Private Configuration conf;
Private secretmanager<tokenidentifier> Secretmanager;
private int maxqueuesize;
private final int maxrespsize;
private int socketsendbuffersize;
Private Final Boolean tcpnodelay; If T then disable Nagle ' s algorithm
Volatile private Boolean running = true; True while server runs
Private blockingqueue<call> Callqueue; Queued calls
Private list<connection> connectionlist =
Collections.synchronizedlist (New linkedlist<connection> ());
Maintain a list of client connections
Private Listener Listener = null;
Private Responder Responder = null;
private int numconnections = 0;
Private handler[] handlers = null;
4, this call and the client inside the call is not the same,
A Call queued for handling.
Private writable param; The parameter passed
Private Connection Connection; Connection to Client
private long timestamp; The time received when response was null; the time served when response was not NULL
Private Bytebuffer response; The response for this call
5, Connection
Reads calls from a connection and queues them for handling.
Private Boolean rpcheaderread = false; If initial RPC header is read
Private Boolean headerread = false; If the connection header that follows version is read.
Private Socketchannel channel;
Private Bytebuffer data;
Private Bytebuffer Datalengthbuffer;
Private linkedlist<call> ResponseQueue;
private volatile int rpccount = 0; Number of outstanding RPCs
Private long lastcontact;
private int datalength;
Private Socket socket;//Cache the remote host & port info So even if the Socket is disconnected, we can say wher E It used to connect to.
Private String hostaddress;
private int remoteport;
Private InetAddress addr;
Connectionheader Header = new Connectionheader ();
Class<?> Protocol;
Boolean USESASL;
Saslserver Saslserver;
Private Authmethod Authmethod;
Private Boolean saslcontextestablished;
Private Boolean Skipinitialsaslhandshake;
Private Bytebuffer Rpcheaderbuffer;
Private Bytebuffer Unwrappeddata;
Private Bytebuffer Unwrappeddatalengthbuffer;
Usergroupinformation user = null;
Public usergroupinformation attemptinguser = null; User name before Auth
Fake ' call ' for failed authorization response
Private final int authroization_failed_callid =-1;
Private Final Call Authfailedcall =
New Call (Authroization_failed_callid, NULL, this);
Private Bytearrayoutputstream authfailedresponse = new Bytearrayoutputstream ();
Fake ' call ' for SASL context Setup
private static final int sasl_callid =-33;
Private Final Call Saslcall = new call (Sasl_callid, NULL, this);
Private final Bytearrayoutputstream saslresponse = new Bytearrayoutputstream ();
Private Boolean usewrap = false;
6, Exceptionshandler manages Exception groups for special handling e.g., terse Exception Group for concise logging messages
7, Handles queued calls.
8, listens on the socket. Creates jobs for the handler threads
Inside the listener there is an inner class, Reader
The corresponding properties are
Private Serversocketchannel acceptchannel = null; The Accept Channel
Private Selector Selector = null; The selector that we use for the server
Private reader[] readers = null;
private int currentreader = 0;
Private inetsocketaddress address; The address we bind at
Private random Rand = new Random ();
Private long lastcleanupruntime = 0; The last time when a cleanup connec-
-tion (for idle connections) ran
Private long cleanupinterval = 10000; The minimum interval between
Cleanup runs
private int backloglength = Conf.getint ("Ipc.server.listen.queue.size", 128);
Private Executorservice Readpool;
9, Responder
Sends responses of RPC back to clients
The corresponding properties are
Private Selector Writeselector;
private int pending; Connections Waiting to register
Final static int purge_interval = 900000; 15mins
Stepping on the footprints of the predecessors to learn HADOOP--IPC in the server