com.distinct.rpc
Class JRPCServer

java.lang.Object
  |
  +--com.distinct.rpc.JRPCServer
All Implemented Interfaces:
java.lang.Runnable, java.io.Serializable
Direct Known Subclasses:
Portmapper, RPCBind

public abstract class JRPCServer
extends java.lang.Object
implements java.lang.Runnable, java.io.Serializable

All JRPC servers are derived from this abstract class. It declares the methods for initializing a server and for registering it at the portmapper.

See Also:
Serialized Form

Constructor Summary
JRPCServer(int prog, int vers, boolean do_portmap)
          Creates a RPC server and starts a portmapper thread if requested.
 
Method Summary
 Auth DoAuth(int proc, Auth cred, Auth verf)
          Overwrite this method only if you want your server to check authentication (by default there is no check).
 boolean DoCall(int proc, XDRStream xin, XDRStream xout)
          Dispatch routine which interprets the call requests of a server.
 boolean DoVersionCheck(int vers)
          Overwrite this method only if you want your server to check compatibility of program versions in a user-defined way (by default it simply checks whether it is the same version as given in the constructor).
 java.net.Socket[] EnumerateConnections()
          Returns an array with the sockets of the currently active TCP clients.
 java.net.InetAddress getAddress()
          Determines the host address of the sender of the currently processed RPC request.
 int getCallVersion()
          Determines the version number of the currently processed RPC request.
 java.lang.Object getClientData()
          Gets client-specific data for this server thread.
 int GetConnectionState()
          Returns the number of currently active TCP clients.
 int getPort()
          Determines the port number of the sender of the currently processed RPC request.
 int getVersion()
          Returns the version number of the server object.
 boolean IsBatched(int proc)
          Overwrite this method only if you want to implement batched RPCs.
 boolean isMultithreaded()
          Determines whether the server can serve multiple requests concurrently.
 boolean isTCPServer()
          Determines whether the current thread serves a TCP or a UDP request.
 boolean RegisterServer(int port, boolean stream)
          Registers the RPC server in the local portmapper.
 boolean RegisterServer(int vers, int port, boolean stream)
          Registers the RPC server in the local portmapper.
 void run()
          The TCP server thread.
 void setClientData(java.lang.Object data)
          Sets client-specific data for this server thread.
 void setMultithreaded(boolean s, int udpservers)
          Selects whether the server can serve multiple requests concurrently.
 void setStreamed(boolean s)
          Switches between the different TCP server implementations.
 int StartTCP(int port)
          Starts the TPC server and its thread.
 int StartTCP(java.net.ServerSocket sock)
          Starts the TPC server and its thread.
 int StartUDP(java.net.DatagramSocket sock)
          Starts the UDP server and its thread.
 int StartUDP(int port)
          Starts the UDP server and its thread.
 void Stop(boolean stop_portmap)
          Stops the server.
 boolean UnregisterServer()
          Unregisters the RPC server in the local portmapper.
 boolean UnregisterServer(int vers)
          Unregisters the RPC server in the local portmapper.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JRPCServer

public JRPCServer(int prog,
                  int vers,
                  boolean do_portmap)
Creates a RPC server and starts a portmapper thread if requested.

Parameters:
prog - The program ID of the server as defined in the .x IDL file.
vers - The program version of the server as defined in the .x IDL file.
do_portmap - If true, it tries to start a portmapper.
Method Detail

DoCall

public boolean DoCall(int proc,
                      XDRStream xin,
                      XDRStream xout)
Dispatch routine which interprets the call requests of a server. Overwritten by derived classes that implement the actual interface.

Parameters:
proc - The index of the requested function.
xin - Read the input parameter from this XDR stream.
xout - Write the return parameter to this XDR stream.
Returns:
True if the function with the index proc can be served, false otherwise.

DoVersionCheck

public boolean DoVersionCheck(int vers)
Overwrite this method only if you want your server to check compatibility of program versions in a user-defined way (by default it simply checks whether it is the same version as given in the constructor).

Parameters:
vers - The version of the server as requested by the incoming call.
Returns:
True if the version matches and the call should be further processed, false if the call should be rejected with a JRPC.kPROG_MISMATCH error.

DoAuth

public Auth DoAuth(int proc,
                   Auth cred,
                   Auth verf)
            throws RPCError
Overwrite this method only if you want your server to check authentication (by default there is no check). Throw an RPCAuthError exception to indicate an authentication failure.

Parameters:
proc - The ID of the requested function.
cred - Authentication parameter provided by the client.
verf - Verifier parameter provided by the client.
Returns:
Verifier to send back to the client with the response ("null" means AuthNull).
Throws:
RPCError - If the authentication fails.

getVersion

public int getVersion()
Returns the version number of the server object.

Returns:
Version number of the server.

RegisterServer

public boolean RegisterServer(int vers,
                              int port,
                              boolean stream)
Registers the RPC server in the local portmapper.

Parameters:
vers - A version number of the program of the server.
port - The port on which the server waits for requests.
stream - true for a TCP server, false for UDP.
Returns:
true if the registration was successful.

RegisterServer

public boolean RegisterServer(int port,
                              boolean stream)
Registers the RPC server in the local portmapper.

Parameters:
port - The port on which the server waits for requests.
stream - true for a TCP server, false for UDP.
Returns:
true if the registration was successful.

run

public final void run()
The TCP server thread.

Specified by:
run in interface java.lang.Runnable

StartTCP

public int StartTCP(int port)
             throws RPCError
Starts the TPC server and its thread.

Parameters:
port - The port on which the server waits for requests. If 0 an arbitrary port is chosen.
Returns:
portnumber of the selected port.
Throws:
RPCError - If the server could not be started.

StartTCP

public int StartTCP(java.net.ServerSocket sock)
             throws RPCError
Starts the TPC server and its thread.

Parameters:
sock - The socket on which the server waits for requests.
Returns:
portnumber of the selected port.
Throws:
RPCError - If the server could not be started.

StartUDP

public int StartUDP(int port)
             throws RPCError
Starts the UDP server and its thread.

Parameters:
port - The port on which the server should wait for requests. If 0 an arbitrary port is chosen.
Returns:
portnumber of the selected port.
Throws:
RPCError - If the server could not be started.

StartUDP

public int StartUDP(java.net.DatagramSocket sock)
             throws RPCError
Starts the UDP server and its thread.

Parameters:
sock - The socket on which the server waits for requests.
Returns:
portnumber of the selected port.
Throws:
RPCError - If the server could not be started.

Stop

public void Stop(boolean stop_portmap)
Stops the server.

Parameters:
stop_portmap - If "true" a RPC Portmapper that was started by this server is stoped as well.

UnregisterServer

public boolean UnregisterServer(int vers)
Unregisters the RPC server in the local portmapper.

Parameters:
vers - A version number of the program of the server.
Returns:
true if the deletion was successful.

UnregisterServer

public boolean UnregisterServer()
Unregisters the RPC server in the local portmapper.

Returns:
true if the deletion was successful.

IsBatched

public boolean IsBatched(int proc)
Overwrite this method only if you want to implement batched RPCs. Return true for all procedures that are called in batched mode (i.e. no reply message).

Parameters:
proc - The ID of the executed function.
Returns:
true if the procedure is called in batched mode.

setClientData

public void setClientData(java.lang.Object data)
Sets client-specific data for this server thread. Use this function if necessary to transfer data between DoAuth(), DoCall(), and IsBatched().

Parameters:
data - Any Java object.

getClientData

public java.lang.Object getClientData()
Gets client-specific data for this server thread. Use this function if necessary to transfer data between DoAuth(), DoCall(), and IsBatched().

Returns:
The Java object previously stored with setClientData().

isTCPServer

public boolean isTCPServer()
Determines whether the current thread serves a TCP or a UDP request.

Returns:
true if the current thread serves a TCP request, false for UDP.

getAddress

public java.net.InetAddress getAddress()
Determines the host address of the sender of the currently processed RPC request.

Returns:
Host address of the sender.

getPort

public int getPort()
Determines the port number of the sender of the currently processed RPC request.

Returns:
Port number of the sender.

getCallVersion

public int getCallVersion()
Determines the version number of the currently processed RPC request.

Returns:
Version number of the request.

setStreamed

public void setStreamed(boolean s)
Switches between the different TCP server implementations.

Parameters:
s - true: use XDRRecordSreams (no buffering, recommended for huge data only). false: use internal buffering (default)

setMultithreaded

public void setMultithreaded(boolean s,
                             int udpservers)
Selects whether the server can serve multiple requests concurrently.

Parameters:
s - true: use multithreading. false: do not use multithreading (default)
udpservers - Minimum number of concurrently active server threads for UDP requests (default: 1).

isMultithreaded

public boolean isMultithreaded()
Determines whether the server can serve multiple requests concurrently.

Returns:
true if the the server can serve multiple requests concurrently, false otherwise.

EnumerateConnections

public java.net.Socket[] EnumerateConnections()
Returns an array with the sockets of the currently active TCP clients. Only sockets of currently open connections will be shown. The main server socket 'ssock' is not shown here. It does not belong to any connection.


GetConnectionState

public int GetConnectionState()
Returns the number of currently active TCP clients.