Re: RMI data duplication

Niclas Hedhman <[email protected]> Sun, 21 Dec 2008 13:14:47 +0800
Newsgroups gmane.comp.java.sun.rmi
Message-ID <[email protected]>
On Sat, Dec 20, 2008 at 7:45 PM, firewall <[email protected]> wrote:
> - the primary server should create an instance (object) of the backup server
> as well an interface of the method implemented by the backup server(which
> returns void since with RMI there's always a 'return' to the client).
> - call the backup server's method on the object created in the primary
> server
> - pass it the data held on the prmary server ass a parameter

Sorry, I can't really follow your steps here. Let me clarify;

You have something like;

public interface Habba extends Remote
{
    Result doSomething( ArgumentA arg1, ArgumentB arg2 )
        throws RemoteException;
}

And you will have an implementation that implements doSomething;

public class HabbaServerImpl extends UnicastRemoteObject
{
    public void initialize()
        throws RemoteException
    {
        Registry reg = getRegistry( "127.0.0.1" );
        reg.bind( this, "habba" );
    }

    public Result doSomething( ArgumentA arg1, ArgumentB arg2 )
    {
        // do stuff
    }
}

And you have some client code

public class HabbaClient
    implements Habba
{
    private Habba server;

    public HabbaClient( String serverName )
        throws RemoteException
    {
        Registry reg = getRegistry( serverName );
        server = (Habba) reg.lookup( "habba" );
    }
}
right??

Now, change in the HabbaServerImpl;

    public void initialize( boolean primaryServer )
        throws RemoteException
    {
        Registry reg = getRegistry( "127.0.0.1" );
        reg.bind( this, "habba" );
        if( primaryServer )
        {
            Registry reg = getRegistry( serverName );
            backupServer = (Habba) reg.lookup( "habba" );
        }
    }

    public Result doSomething( ArgumentA arg1, ArgumentB arg2 )
    {
        // do stuff
        if( backupServer != null )
            Result backupResult = backupServer.doSomething( arg1, arg2 );
    }


The devil in the details, so don't expect the code above to work
outright. Just for illustrative purposes.


Cheers
Niclas

===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff RMI-USERS".  For general help, send email to
[email protected] and include in the body of the message "help".

For a list of frequently asked RMI questions please refer to:
http://java.sun.com/j2se/1.3/docs/guide/rmi/faq.html

To view past RMI-USERS postings, please see:
http://archives.java.sun.com/archives/rmi-users.html