netbula.ORPC
Class Svc
public abstract class Svc
extends java.lang.Object
Class that represents an RPC service.
An RPC service provides the functions, a Server provides the transport.
For convenience, the Svc class also provides methods to create TCPServer or UDPServer.
OpaAuth | auth(int proc, OpaAuth cred, OpaAuth verf, InetAddress client_add)- Authenticate client on RPC call.
|
XDT | getAsyncReply(int proc)- Override this function to enable no wait RPC.
|
int | getKeepAliveTime()
|
boolean | getNoReply(int proc)- Override this function to enable no reply RPC.
|
Server | getServer(int type)- Obtain handle to Server object
|
abstract XDT | proc_call(int proc, XDR inXDR)- RPC dispatch function.
|
void | run()- Create both TCP and UDP server and run them.
|
void | run(int type, ExecutorService exec)- Create both TCP or UDP server and run it with the ExecutorService.
|
void | run(int tcp_server_port, int udp_server_port)- Create both TCP and UDP server and run them.
|
void | runThreadPool(int type, int nThreads)- Create TCP or UDP server and run it with the a number of threads.
|
void | setKeepAliveTime(int millis)- If this service is runing in a TCP server, call this function
to set the KeepAlive time for the client/server connection.
|
Server | svc_create(int portn, int type)- Create a server.
|
boolean | svc_reg(int type)- Register a server, can be called only after svc_create().
|
void | svc_run()- Run the created servers in their own threads,
return immediately.
|
Server | svc_tcp_sock_create(ServerSocket ss)- Create a TCP server from a bound server socket.
|
boolean | svc_unreg()- Unregister both servers (TCP and UDP)
|
TCPSVC
public static final int TCPSVC
UDPSVC
public static final int UDPSVC
Svc
public Svc(int p,
int v)p - program numberv - version number
auth
public OpaAuth auth(int proc,
OpaAuth cred,
OpaAuth verf,
InetAddress client_add)
throws rpc_errAuthenticate client on RPC call.
This method is called before the RPC implementation function is entered.
To indicate failed authentication, it should throw an rpc_err exception.
The default action is simply return new OpaAuth(), a service which wants authentication
check should override this method.
proc - procedue number for the incoming callcred - credential of the incoming callverf - verifier of the incoming callclient_add - address of the client
getAsyncReply
public XDT getAsyncReply(int proc)
Override this function to enable no wait RPC.
- an XDT if this procedure is a no wait function, which sends the XDT back as soon as request is received. Default is to return null, indicating the procedure is a synchronous call.
getKeepAliveTime
public int getKeepAliveTime()
- previous value of keep alive time
getNoReply
public boolean getNoReply(int proc)
Override this function to enable no reply RPC.
- true if this procedure does not send a reply to the caller. Default is to return false.
getServer
public Server getServer(int type)
Obtain handle to Server object
type - Svc.TCPSVC or Svc.UDPSVC
proc_call
public abstract XDT proc_call(int proc,
XDR inXDR)
throws XDRErrorRPC dispatch function.
The jrpcgen compiler generates this method from the IDL file.
run
public void run()
throws rpc_errCreate both TCP and UDP server and run them.
This is a convenience function. It creates a UDP and a TCP server,
unregister previously registered servers,
registered the new servers, run TCP server in a new thread and the UDP server
in current thread. Never returns if sucessful.
run
public void run(int type,
ExecutorService exec)
throws rpc_errCreate both TCP or UDP server and run it with the ExecutorService.
This is a convenience function. It creates a UDP or a TCP server,
unregister previously registered servers,
registered the new servers, run the server with an ExecutorService.
Never returns if sucessful.
run
public void run(int tcp_server_port,
int udp_server_port)
throws rpc_errCreate both TCP and UDP server and run them.
This is a convenience function. It creates a UDP and a TCP server,
unregister previously registered servers,
registered the new servers, run TCP server in a new thread and the UDP server
in current thread. Never returns if sucessful.
tcp_server_port - Port number of the TCP server, if <320, then TCP server is not created.udp_server_port - Port number of the UDP server, if <320, then UDP server is not created.
runThreadPool
public void runThreadPool(int type,
int nThreads)
throws rpc_errCreate TCP or UDP server and run it with the a number of threads.
This is a convenience function. It creates a UDP or a TCP server,
unregister previously registered servers,
registered the new servers, run the server with a specified number of threads.
Never returns if sucessful.
setKeepAliveTime
public void setKeepAliveTime(int millis)
If this service is runing in a TCP server, call this function
to set the KeepAlive time for the client/server connection. Server
will close connection if the client is idle for a period longer than
the keep alive time (default value is 1 hour, 3600*1000)
millis - Keep alive time in milli-seconds
svc_create
public Server svc_create(int portn,
int type)
throws rpc_errCreate a server.
This convenience function creates a server with given port and type, the Svc class
has two private members to hold the created Server object. The server must be started
by calling other functions, such as svc_run()
portn - specify port number for the server, 0 for any porttype - Svc.TCPSVC or Svc.UDPSVC
- The newly created Server object
svc_reg
public boolean svc_reg(int type)
throws rpc_errRegister a server, can be called only after svc_create().
When svc_create() is called, the newly created Server object is
created but not registered, this method
simply call the register() method on the corresponding Server object.
- true on success, false on failure.
svc_run
public void svc_run()
throws rpc_errRun the created servers in their own threads,
return immediately.
svc_tcp_sock_create
public Server svc_tcp_sock_create(ServerSocket ss)
throws rpc_errCreate a TCP server from a bound server socket.
This just calls the constructor in the TCPServer class.
ss - the server socket, a SSLServerSocket may be used.
- The new created TCPServer object
svc_unreg
public boolean svc_unreg()
throws rpc_errUnregister both servers (TCP and UDP)