net.sbbi.upnp.remote
Class UnicastRemoteObject

java.lang.Object
  extended by java.rmi.server.RemoteObject
      extended by java.rmi.server.RemoteServer
          extended by net.sbbi.upnp.remote.UnicastRemoteObject
All Implemented Interfaces:
Serializable, Remote
Direct Known Subclasses:
HelloWorld

public class UnicastRemoteObject
extends RemoteServer

This class can be used for remote objects that need to work behind an NAT firewall compatible with IGD UPNP specifications. The following system properties let you setup this class :
net.sbbi.upnp.remote.deviceUDN=someUPNPDeviceUDN, the device identifier to be used when multiple IGD upnp devices are on the network
net.sbbi.upnp.remote.failWhenNoDeviceFound=true|false, Property to throw an exception when the object is exported and no UPNP device is found, default to false
net.sbbi.upnp.remote.failWhenDeviceCommEx=true|false, Property to throw an exception when the object is exported and an error occurs during com with device, default to false
net.sbbi.upnp.remote.discoveryTimeout=4000, timeout in ms to discover upnp devices default to 1500, try to increase this timeout if you can't find a present device on the network
Each instance of this class can create a shutdown hook trigered during JVM shutdown to make sure that the port opened with UPNP is closed. The hook is created as soon as the port is opened on the UPNP device.
Migration for distributed objects is quite simple : change the standard java.rmi.server.UnicastRemoteObject class extends to this class and you're done.
If you have trouble to make the objects available from behind your router/firewall make sure that you have correctly set the java.rmi.server.hostname system property with an hostname matching your router/firewall IP.
Make also sure that your RMI Registry port is opened on the router otherwise nothing will work. You can use a urn:schemas-upnp-org:device:InternetGatewayDevice:1 device just like this class to automate the job.

Version:
1.0
Author:
SuperBonBon
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Constructor Summary
protected UnicastRemoteObject()
          Creates and exports a new UnicastRemoteObject object using an anonymous port.
protected UnicastRemoteObject(int port)
          Creates and exports a new UnicastRemoteObject object using the particular supplied port.
protected UnicastRemoteObject(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf)
          Creates and exports a new UnicastRemoteObject object using the particular supplied port and socket factories.
 
Method Summary
 Object clone()
          Returns a clone of the remote object that is distinct from the original.
 void closePort()
          Closes the port on the UPNP router
static RemoteStub exportObject(Remote obj)
          Exports the remote object to make it available to receive incoming calls using an anonymous port.
static Remote exportObject(Remote obj, int port)
          Exports the remote object to make it available to receive incoming calls, using the particular supplied port.
static Remote exportObject(Remote obj, int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf)
          Exports the remote object to make it available to receive incoming calls, using a transport specified by the given socket factory.
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UnicastRemoteObject

protected UnicastRemoteObject()
                       throws RemoteException
Creates and exports a new UnicastRemoteObject object using an anonymous port.

Throws:
RemoteException - if failed to export object

UnicastRemoteObject

protected UnicastRemoteObject(int port)
                       throws RemoteException
Creates and exports a new UnicastRemoteObject object using the particular supplied port.

Parameters:
port - the port number on which the remote object receives calls (if port is zero, an anonymous port is chosen)
Throws:
RemoteException - if failed to export object

UnicastRemoteObject

protected UnicastRemoteObject(int port,
                              RMIClientSocketFactory csf,
                              RMIServerSocketFactory ssf)
                       throws RemoteException
Creates and exports a new UnicastRemoteObject object using the particular supplied port and socket factories.

Parameters:
port - the port number on which the remote object receives calls (if port is zero, an anonymous port is chosen)
csf - the client-side socket factory for making calls to the remote object
ssf - the server-side socket factory for receiving remote calls
Throws:
RemoteException - if failed to export object
Method Detail

clone

public Object clone()
             throws CloneNotSupportedException
Returns a clone of the remote object that is distinct from the original.

Overrides:
clone in class Object
Returns:
the new remote object
Throws:
CloneNotSupportedException - if clone failed due to a RemoteException.

exportObject

public static RemoteStub exportObject(Remote obj)
                               throws RemoteException
Exports the remote object to make it available to receive incoming calls using an anonymous port.

Parameters:
obj - the remote object to be exported
Returns:
remote object stub
Throws:
RemoteException - if export fails

exportObject

public static Remote exportObject(Remote obj,
                                  int port)
                           throws RemoteException
Exports the remote object to make it available to receive incoming calls, using the particular supplied port.

Parameters:
obj - the remote object to be exported
port - the port to export the object on
Returns:
remote object stub
Throws:
RemoteException - if export fails

exportObject

public static Remote exportObject(Remote obj,
                                  int port,
                                  RMIClientSocketFactory csf,
                                  RMIServerSocketFactory ssf)
                           throws RemoteException
Exports the remote object to make it available to receive incoming calls, using a transport specified by the given socket factory.

Parameters:
obj - the remote object to be exported
port - the port to export the object on
csf - the client-side socket factory for making calls to the remote object
ssf - the server-side socket factory for receiving remote calls
Returns:
remote object stub
Throws:
RemoteException - if export fails

closePort

public void closePort()
Closes the port on the UPNP router



Copyright © 2010. All Rights Reserved.