Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

RMI in java

  Asked By: Kent    Date: Dec 02    Category: Java    Views: 2842
  

i'm newly in java.I have project about RMI(Remote Method Invocation).
i run some samples successfully but all of them was in same computer
and same JVM.i want to network two computer(laptop) and run the samples
again.could any one help me plz?

Share: 

 

8 Answers Found

 
Answer #1    Answered By: Clayton Richardson     Answered On: Dec 02

there is no difference except you have to do the remote addressing to download the stub to client machine,
alternatively, you can generate stubs and make it accessible to the client locally,

either way, you also need remote addressing for the stub to find the server,

 
Answer #2    Answered By: Adelinda Fischer     Answered On: Dec 02

i think that we shouldn't make stubs being available to clients locally.i used Dynamic class loading method  and i want them(clients) to download stubs from server.
i also has another problem.could you inform me about using threads in rmi.i want two have more than one client.

 
Answer #3    Answered By: Tamara Nguyen     Answered On: Dec 02

regarding how to access the stub, as I said, the choice is yours,

regarding the thread, my knowledge on RMI is dusty, so I hope the flashback diverts to accurate data. Clients will have concurrent access to single server instance so you do not need explicit threading functionality, each thread will be created by the server once a client connection has established, however you need "synchronization" over the shared data or instance "variables" and that is because server provides point-to-point communication to the bounded server object. how you do that is up to yourself, but there are plenty of examples on the web, but once again, that threading is done by the server to allow multiple simultaneous client calls, (if server is configured to do so, which I guess, that is the default configuration)

 
Answer #4    Answered By: Hehet Chalthoum     Answered On: Dec 02

during running a rmi  code i encountered this problem
java.rmi.MarshalException: error marshalling a
rguments; nested exception is:
java.io.NotSerializableException: BankManagerImpl


could anyone help  me plz?

 
Answer #5    Answered By: Sean Grant     Answered On: Dec 02

the class BankManagerImpl is not serializable. Have you declared java.io.Serializable on this class?

 
Answer #6    Answered By: Huette Miller     Answered On: Dec 02

It seems that BankManagerImpl class is not Serializable, so make it
Serializable by implementing java.io.Serializable:

public class BankManagerImpl implements java.io.Serializable { ... }

 
Answer #7    Answered By: Maria Miller     Answered On: Dec 02

Another Problem:
you shouldn't expose xxxxxImp classes remotely.
you probably have something like this:
public interface BankManager{
public void deduct(int account_id,int amount);
}

public class BankManagerImp implements BankManager{
public void deduct(int account_id,int amount){
// some implementation code
}
}

u usually want to expose the interface(BankManager) on rmi  and not
BankManagerImp.
the imp class does stuff like talking to DB(hibernate, jdbc, jpa,etc) and should
run on the container...
implementing serializable will make the first error go away, but u'll probably
run into other problems.

 
Answer #8    Answered By: Elias Turner     Answered On: Dec 02

i have this classes

//TableTalk.java -- a remote interface
package tabletalking;

import java.rmi.*;

public interface TableTalk extends Remote {
public String getTopic() throws RemoteException;
}


//TableTalkImpl.java -- a remote object
package tabletalking;

import java.rmi.*;

public class TableTalkImpl implements TableTalk {
private String[] questions = {"What is your favorite time of the
day?",
"What is your favorite fruit or
vegetable?",
"Talk about something beautiful you saw this week.",
"What I like best about our family
is ... ",
"Tell about a mistake you have made
recently.",
"Tell about a time when you felt happy.",
"How do you react when someone
crowds in line in front of you?",
"Talk about a special gift that you
remember.",
"If your family received a gift of
$5,000, how would you like your family to spend it?",
"Tell about a family tradition that
you enjoy."
};
private int idx = 0;

public String getTopic() throws RemoteException {
idx = (int)(Math.random()*questions.length);
return questions[idx];
}
}



//TableTalkSetup.java -- a set-up program
package tabletalking;

import java.rmi.*;
import java.rmi.activation.*;
import java.util.Properties;

public class TableTalkSetup {

public static void main(String[] args) throws Exception {

System.setSecurityManager(new RMISecurityManager());

Properties props = new Properties();
props.put("java.security.policy", "/myrmi/myrmi.policy");

ActivationGroupDesc.CommandEnvironment ace = null;
ActivationGroupDesc exampleGroup = new ActivationGroupDesc(props, ace);

ActivationGroupID agi =
ActivationGroup.getSystem().registerGroup(exampleGroup);


String location = "file:/myrmi/tabletalking/";

MarshalledObject data = null;

ActivationDesc desc = new ActivationDesc
(agi, "tabletalking.Migration", location, data);

TableTalk tt = (TableTalk)Activatable.register(desc);
System.out.println("Got the stub for the TableTalkImpl");

Naming.rebind("Topic", tt);
System.out.println("Exported a table-talking object");

System.exit(0);
}
}


//Migration.java -- migrate an existing remote object
package tabletalking;

import java.rmi.*;
import java.rmi.activation.*;

public class Migration implements TableTalk{
private TableTalkImpl tti = new TableTalkImpl();

public Migration(ActivationID id, MarshalledObject data) throws
RemoteException {
Activatable.exportObject(this,id, 0);
}
public String getTopic() throws RemoteException {//adaptee
return tti.getTopic();

}
}


//TableTalkClient.java -- test the remote object
package tabletalking;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class TableTalkClient {
private static TableTalk stub = null;

private TableTalkClient() {}

public static void main(String[] args) {

try {
Registry reg = LocateRegistry.getRegistry();
stub = (TableTalk) reg.lookup("Topic");
System.out.println("What is the topic for dinner table?
\n" + stub.getTopic());
} catch (Exception e) {
System.err.println("Client exception thrown: " + e.toString());
e.printStackTrace();
}
}
}



grant {
// Allow everything for now
permission java.security.AllPermission;
};


i compile and run  this way.but in runnig a clien i encountered problem.
could any one help  me plz,plz,plz.....

C:\myrmi>set classpath=

C:\myrmi>start rmiregistry

C:\myrmi>start rmid -J-Djava.security.policy=C:\myrmi\policy/

C:\myrmi>java -Djava.security.policy=C:\myrmi\policy/
tabletalking.TableTalkSetup
Got the stub for the TableTalkImpl
Exported a table-talking object

C:\myrmi>java -Djava.security.policy=C:\myrmi\policy/
tabletalking.TableTalkClient

Client exception thrown: java.rmi.UnmarshalException: Error
unmarshaling return
header; nested exception is:
java.io.EOFException
java.rmi.UnmarshalException: Error unmarshaling return header; nested
exception
is:
java.io.EOFException
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at sun.rmi.server.ActivatableRef.invoke(Unknown Source)
at
java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unkn
own Source)
at
java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
at $Proxy0.getTopic(Unknown Source)
at tabletalking.TableTalkClient.main(TableTalkClient.java:17)
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(Unknown Source)
... 7 more

C:\myrmi>

 
Didn't find what you were looking for? Find more on RMI in java Or get search suggestion and latest updates.




Tagged: