How to pass back object to client?

Forgive me if i ask too stupid question, but I really confuse what is really happen when it is not working.

Firstly, client A pass several objects to the server one by one, and the server will have to wait untill another client (let call it client b) able to process this object, and pass it back to the client a.

This object include some data that need to compute and save the result back to the object.

In this case, I have write the code to enable the server to callback client a, when the object is processed. Rather then put it in a while loop to wait the result coming back.

But I have difficult to trace back the original client. It cannot find client A and update the object.

I already read the Stock, Time example (which is in Sun website), and follow it to develop my program, but I still cannot get it right.

Does anyone know have any reference that I can look at or give some suggestion that can help.

Thank in advance and wish you have a good day.

Regards,

Tai Tan

[1040 byte] By [ttl7] at [2007-9-27 19:36:07]
# 1
Just ask once again.Maybe someone can help?Thank you.
ttl7 at 2007-7-6 22:43:13 > top of Java-index,Core,Core APIs...
# 2
one way is perhaps to use exportObject
mchan0 at 2007-7-6 22:43:13 > top of Java-index,Core,Core APIs...
# 3

I already try that, but it link to different object.

This is the code that i think the problem is.

jobClient is the client that extend UnicastRemoteObject. it call getJob(jb) which is in serverImpl.java to process the job. jb is an object that extends Serialization.

//serverImpl.java

public static void getJob(jb)

{

jobClient jc = new jobClient(jb); //How can i get back the class that submit this object (jb) ?

System.out.println(tempJob.jobNo + ", " +jc.toString());

}

//In getJob : it print

//2, jobClient[RemoteStub [ref: [endpoint:[144.6.41.218:4102]local),objID:[2]]]]

//

//in jobClient.java

public static submit(jb)

{

jobClient jc = new jobClient(jb);

System.out.println(tempJob.jobNo + ", " +jc.toString());

getJob(jb);

}

//in jobClient.java, it print

//2, jobClient[RemoteStub [ref: [endpoint:[144.6.41.218:4107](local),objID:[1]]]]

It seem that I can't link back to the original source, can anyone tell me the reason, or point me to a document that can solve this.

Thank you very much. And thank mchan0 for your suggest.

ttl7 at 2007-7-6 22:43:13 > top of Java-index,Core,Core APIs...
# 4
perhaps if you post a working skeleton of the whole client and server programs.
mchan0 at 2007-7-6 22:43:13 > top of Java-index,Core,Core APIs...
# 5
Sorry, may I know what is mean skeleton?
ttl7 at 2007-7-6 22:43:13 > top of Java-index,Core,Core APIs...
# 6
a representative, working, stripped down, base set of code from what you are working on.
mchan0 at 2007-7-6 22:43:13 > top of Java-index,Core,Core APIs...
# 7

It is a bit difficult for me to do that, becuase i not really understand what I am doing now.

Anyway, let me ask this question.

After the client export the object. In this case,

[code]

Remote serverStub;

try

{

jc1 = new jobClient(jb1);

serverStub = UnicastRemoteObject.exportObject(jc1);

mytemp.submitJob(jb1);

}

catch(java.rmi.RemoteException re)

{

System.out.println(re.getMessage());

}

[code]

What I should write in mainServerImp to create this stub (remote object) which is based on the object that the method submitJob(jb1) get?

ttl7 at 2007-7-6 22:43:13 > top of Java-index,Core,Core APIs...
# 8
q&d skeletal code, http://www.geocities.com/rmlchan/hw.txt
mchan0 at 2007-7-6 22:43:13 > top of Java-index,Core,Core APIs...
# 9

Really thank you for your help.

But i still unable to get it right.

Can I ask you few more questions. thank.

Can I know what the 'this' in the your example mean?

try

{

UnicastRemoteObject.exportObject( this ); //what is 'this' mean?

obj = (Hello)Naming.lookup("//" + ser + ":5000/Server");

message = obj.sayHello( this ); //what is 'this' mean?

}

catch (Exception e)

{

System.out.println("HelloApplet exception: " +

e.getMessage());

e.printStackTrace();

}

because the client program is not extends Applet, so if i put 'this' in the above 2 lines, it will not accept by the compiler.

one more question, I put the client class in the first 'this' means:

UnicastRemoteObject.exportObject( jobClient jc );

and passing second object in the second 'this':

//message = obj.sayHello( this );

mytemp.submitJob(jb1);

// Note: mytemp is : 'static mainServer mytemp';

// which is a remote object of the server

So, is this the correct way to export the stub and object?

(In the example that you give, the 'this' is the same. But in my program, the second 'this', I have to call submitJob(jb1) in the server, and passing the jb1 ( is a serialize object name call jobThread.)

Thank again and sorry for giving you such trouble.

ttl7 at 2007-7-6 22:43:13 > top of Java-index,Core,Core APIs...
# 10

mchan0 ,

Finally, I get my program working now.

I have to export both the "export object" and the "object" (passing object ) that i want to sent to the server, and put inside a hashtable.

so, if i want to do that, the code will seem like this..

[code]

try

{

myclass a = new myclass();

UnicastRemoteObject.exportObject( a );

obj = (Hello)Naming.lookup("//" + ser + ":5000/Server");

message = obj.sayHello( a, obj );

}

catch (Exception e)

{

System.out.println("HelloApplet exception: " +e.getMessage());

e.printStackTrace();

}

[code]

Thank for your kindly help and sorry for giving you trouble.

Regards,

Tai Tan

ttl7 at 2007-7-6 22:43:13 > top of Java-index,Core,Core APIs...
# 11
?!> I have to export both the "export object" and the> "object" (passing object ) that i want to sent to the> server, and put inside a hashtable.
mchan0 at 2007-7-6 22:43:13 > top of Java-index,Core,Core APIs...
# 12

(this is the code for client, it have to pass the obj to the server to get process and send back to the client (but the time for processing is unknow, so it have apply callback...right? ha..ha)

try

{

myclass a = new myclass();

UnicastRemoteObject.exportObject( a ); //<--export the stub of this class..

obj = (Hello)Naming.lookup("//" + ser + ":5000/Server");

message = obj.sayHello( a, obj ); //<-send it both to the server..

}

catch (Exception e)

{

System.out.println("HelloApplet exception: " +e.getMessage());

e.printStackTrace();

}

callback(obj)

{

saved(obj);

}

In server side,

HashTable table = new Hashtable();

sayHello(a, obj)

{

table.put(a, obj)

}

After processing

returnToClient(obj)

{

//code look back the stub and object and invoke the client method callback

//to pass back the result.

a.callback(obj);

}

Is it the correct way to do it? Or you think there is another better way to do that?

Regards,

Tai Tan

ttl7 at 2007-7-6 22:43:13 > top of Java-index,Core,Core APIs...