Re: Distributed Computing confusion

"From: Bill Hibbard " wrote:
> 
> > - The client application needs to get some data values (doubles) from
> > the server. When I run the server as part of the same JVM (using none of
> > the Remote stuff) I can use the DataReference getData method and cast
> > that to a FieldImpl and call its getValues method. Running remotely, I
> > can't seem to cast the results of the (remote)DataReference getData
> > method to something like RemoteFieldImpl so I can call a getValues
> > method. Do I need a RemoteFieldImpl on the server?
> 
> If the argument to DataReference.setData(Data d) on the server
> is a FieldImpl, then you should be able to cast the return value
> of DataReference.getData() to FieldImpl.  That is, moving data
> from the server to the client does not change its class to
> Remote*.
> 

What you said reaffirms what I thought, but it's not working in
practice. Here's some sample code that shows the problem. I get the
problem on both Linux and NT.

Thanks,
Doug

-------------------------------------- Server code ----------------

import java.rmi.Naming;
import java.rmi.RemoteException;

import visad.*;

public class Server
{
  public Server()
        throws Exception
  {

    RealType xtype = new RealType("x",null,null);
    RealType ytype = new RealType("y",null,null);
    FunctionType ftype = new FunctionType(xtype,ytype);

    Set set = new Integer1DSet(1);
    FieldImpl field = new FlatField(ftype,set);
    double[][] data = {{1.0}};
    field.setSamples(data);
    DataReferenceImpl ref = new DataReferenceImpl("ref");
    ref.setData(field);

    // create RemoteDataReferenceImpl's
    RemoteDataReferenceImpl[] rem_data_refs;
    rem_data_refs = new RemoteDataReferenceImpl[1];
    rem_data_refs[0] = new RemoteDataReferenceImpl(ref);

    RemoteServerImpl rem_srv = new RemoteServerImpl(rem_data_refs);
    Naming.rebind("//:/RemoteServerTest", rem_srv);

    System.out.println("RemoteServer bound in registry");

  }

  public static void main(String args[])
        throws Exception
  {
    Server s = new Server();
  }
}

-------------------------------------- Client code ----------------

import java.rmi.Naming;
import java.rmi.RemoteException;

import visad.*;

public class Client
{
  public Client()
        throws Exception
  {

    String domain = "//:/RemoteServerTest";
    RemoteServer remote_obj = (RemoteServer) Naming.lookup(domain);

    DataReference ref = remote_obj.getDataReference(0);
    System.out.println(ref.getType().toString()); // works
    FieldImpl field = (FieldImpl) ref.getData();  // ClassCastException
    double[][] data = field.getValues();

    System.out.println(""+data[0][0]);

  }

  public static void main(String args[])
        throws Exception
  {
    Client c = new Client();
  }

}

--------------------------------------- jdb output ---------------

Uncaught exception: java.lang.ClassCastException:
visad.RemoteFieldImpl_Stub
        at Client.<init>(Client.java:17)
        at Client.main(Client.java:27)
        at sun.tools.agent.MainThread.runMain(Native Method)
        at sun.tools.agent.MainThread.run(MainThread.java:49)

-- 
*----------------------------------------------------------------------*
| Doug Lindholm, Software Engineer          |  E-mail: lind@xxxxxxxx   |
| Research Applications Program             |   Phone: 303-497-8374    |
| National Center for Atmospheric Research  |                          |
| P.O. Box 3000                             |     There's no place     |
| Boulder, Colorado 80307-3000              |        like $HOME        |
*----------------------------------------------------------------------*