netbula.ORPC

Class Svc

Known Direct Subclasses:
Pmapsvc

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.

Field Summary

static int
TCPSVC
static int
UDPSVC
int
prog
int
vers

Constructor Summary

Svc(int p, int v)

Method Summary

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)

Field Details

TCPSVC

public static final int TCPSVC
Field Value:
0

UDPSVC

public static final int UDPSVC
Field Value:
1

prog

public int prog

vers

public int vers

Constructor Details

Svc

public Svc(int p,
           int v)
Parameters:
p - program number
v - version number

Method Details

auth

public OpaAuth auth(int proc,
                    OpaAuth cred,
                    OpaAuth verf,
                    InetAddress client_add)
            throws rpc_err
Authenticate 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.
Parameters:
proc - procedue number for the incoming call
cred - credential of the incoming call
verf - verifier of the incoming call
client_add - address of the client

getAsyncReply

public XDT getAsyncReply(int proc)
Override this function to enable no wait RPC.
Parameters:
proc - Procedure number
Returns:
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()
Returns:
previous value of keep alive time

getNoReply

public boolean getNoReply(int proc)
Override this function to enable no reply RPC.
Parameters:
proc - Procedure number
Returns:
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
Parameters:
type - Svc.TCPSVC or Svc.UDPSVC
Returns:
The Server object

proc_call

public abstract XDT proc_call(int proc,
                              XDR inXDR)
            throws XDRError
RPC dispatch function. The jrpcgen compiler generates this method from the IDL file.

run

public void run()
            throws rpc_err
Create 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_err
Create 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.
Parameters:

run

public void run(int tcp_server_port,
                int udp_server_port)
            throws rpc_err
Create 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.
Parameters:
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_err
Create 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.
Parameters:

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)
Parameters:
millis - Keep alive time in milli-seconds

svc_create

public Server svc_create(int portn,
                         int type)
            throws rpc_err
Create 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()
Parameters:
portn - specify port number for the server, 0 for any port
type - Svc.TCPSVC or Svc.UDPSVC
Returns:
The newly created Server object

svc_reg

public boolean svc_reg(int type)
            throws rpc_err
Register 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.
Parameters:
Returns:
true on success, false on failure.

svc_run

public void svc_run()
            throws rpc_err
Run the created servers in their own threads, return immediately.

svc_tcp_sock_create

public Server svc_tcp_sock_create(ServerSocket ss)
            throws rpc_err
Create a TCP server from a bound server socket. This just calls the constructor in the TCPServer class.
Parameters:
ss - the server socket, a SSLServerSocket may be used.
Returns:
The new created TCPServer object

svc_unreg

public boolean svc_unreg()
            throws rpc_err
Unregister both servers (TCP and UDP)