File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Distributed Java and the fly likes RMI Callback using socket pools Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Distributed Java
Reply Bookmark "RMI Callback using socket pools" Watch "RMI Callback using socket pools" New topic
Author

RMI Callback using socket pools

Bruce Rosenthal
Greenhorn

Joined: Oct 24, 2004
Posts: 3
I have an application with client and server making numerous RMI callbacks as events occur and are posted to the server.

The client registers with the server to be notified when these events occur, and the server can invoke remote methods on the client.

The client and server are seperated by a firewall which is blocking the callback mechanism - this is a new infrastructure deployment within the last 30 days.

What I would like to try is to have a customized socket factory that is invoked when an event occurs that will create a socket with a specific TCP port. Since there are multiple events that are being posted from the server to the client (upwards to 100 per client/server interactions depending on the information context) I would also like a method to close a given port after the callback mechanism has completed and close that socket returning it to the available pool.

Has anybody done this type of distributed communications programming?


Bruce Rosenthal<br />Chief Architect, Infrastructure Analytics<br />Transtrophe Solutions
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

I think there's an example of creating a special RMISocketFactory for HTTP tunnelling in the O'Reilly "Java RMI" book...

There's a tutorial on Sun's website about How to use custom socket factories in RMI.

You could easily make the socket factory pull the socket from a pool, but I don't think there is a way for the socket factory itself to know when it is time to put the socket back in the pool... only the client using the socket will know when it is done and it is time to put the socket back (I suppose you could wrap this somehow with another class that the client uses that has a reference to the same socket pool.), and there may be problems with sockets timing out and not being returned to the pool...

Sorry I couldn't help you more, but hopefully this gives you some information that can help you out.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Bruce Rosenthal
Greenhorn

Joined: Oct 24, 2004
Posts: 3
Thanks Nathan.

HTTP tunneling will not work here because the events that the server-side are posting back to client GUI are each running in their own thread.

That's why I need the pool of sockets which I will have the firewall opened for.

Here is what I have come up with so far if you would like to look at it and give me your initial feed-back:

public class FixedPortRMISocketFactory extends RMISocketFactory {

public static Integer pv;
public static int clPort = 6051;
public static int svPort = 6000;
/**
* Creates a client socket connected to the specified host and port and writes out debugging info
* @param host the host name
* @param port the port number
* @return a socket connected to the specified host and port.
* @exception IOException if an I/O error occurs during socket creation
*/
public Socket createSocket(String host, int port)
throws IOException {

InetAddress ip = InetAddress.getLocalHost();
synchronized (this) {

//return new Socket(host, port);
System.out.println (" Thread : " + Thread.currentThread());
try {
Socket clSock = new Socket(host, port, ip, clPort);
System.out.println("created client socket to host : " + host + " on serverport " + port + " localip " + ip.getHostAddress() + " localPort " + clPort);
return clSock;
}
catch (Exception e){
System.out.println("Cannot create Client socket at port " + clPort + " : " + e.toString());
throw new IOException();
}
}
}

/**
* Create a server socket on the specified port (port 0 indicates
* an anonymous port) and writes out some debugging info
* @param port the port number
* @return the server socket pool for array access of sockets by the event thread caller
* @exception IOException if an I/O error occurs during server socket
* creation
*/
public ServerSocket createServerSocket(int port)
throws IOException {
port = (port == 0 ? svPort : port);
ServerSocket svSockPool[] = new ServerSocket[50];

for ( sockID = port; sockID < 6051 ; sockID++ )
{

ServerSocket svSock;

try {
svSockPool[sockID] = new ServerSocket(sockID);
svSock = svSockPool[sockID];
System.out.println("created ServerSocket on serverport " + sockID);
svPort ++ ;
if(svPort == 6050)
svPort = 6000;
/* svPort pool at end of range so reset to 6000 */

}
catch (Exception e){
System.out.println("Cannot create Server socket at port " + port + ": " + e.toString());
throw new IOException();
}
return (ServerSocket)svSockPool[];
}
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RMI Callback using socket pools
 
Similar Threads
Stopping DataServer using socket connection
How to close server socket for incoming RMI requests from client
Callbacks in RMI and Corba
How to close server socket for incoming RMI requests from client
RMI Server problem