BugLighter
asked on
RMI and Anonymous Classes
Hi experts,
I have encountered the following problem:
Using SDK 1.2.2 and the RMI mechanism.
I want to send a remote interface implementaion as an anonymous class to a stub Ithink that an example will be clearer:
interface R_Task extends Remote
{
public Object execute();
}
public class TaskWrap
{
private Object _object;
private R_Compute compute_stub;
/.. intializes the compute_stub which is an RMI stub
Object remotedRetValue = compute_stub.executeTask( new R_Task(){
public Obeject execute()
{ return TaskWrap.this._object;
}
});
//... doing some thing with this remotedRetValue
}
Now this did not work. I guess that is due to the Object overidings that one should have done, commonly with UniCastRemoteObject. How can one accomplish this within an anonymous class. I have tried to define an AbsTask that extends UniCastRemoteObject and implements Task
but then when I have created an anonymous class out of the AbsTask the compiler shouted that I don't catch a RemoteException and I could not figure how to do that.
Now the questions are:
- Does RMI handles anonymous classes? If yes then how?
- Is anonymous class is just one that initiates an interface?
If any one would help I would be greatful.
I have encountered the following problem:
Using SDK 1.2.2 and the RMI mechanism.
I want to send a remote interface implementaion as an anonymous class to a stub Ithink that an example will be clearer:
interface R_Task extends Remote
{
public Object execute();
}
public class TaskWrap
{
private Object _object;
private R_Compute compute_stub;
/.. intializes the compute_stub which is an RMI stub
Object remotedRetValue = compute_stub.executeTask( new R_Task(){
public Obeject execute()
{ return TaskWrap.this._object;
}
});
//... doing some thing with this remotedRetValue
}
Now this did not work. I guess that is due to the Object overidings that one should have done, commonly with UniCastRemoteObject. How can one accomplish this within an anonymous class. I have tried to define an AbsTask that extends UniCastRemoteObject and implements Task
but then when I have created an anonymous class out of the AbsTask the compiler shouted that I don't catch a RemoteException and I could not figure how to do that.
Now the questions are:
- Does RMI handles anonymous classes? If yes then how?
- Is anonymous class is just one that initiates an interface?
If any one would help I would be greatful.
your question is quite unclear ... to me :)
ASKER
OK I'll try again,
1)Does anonymous class term relate to
interface instantiation only?
2)Is it possible to instantiate an anonymous class that implements a <code>Remote</code> interface and deliver it as a stub parameter to a remotely invoked method? If the answer is no (due to the RemoteObject) is it possible to overcome this or one should not mix anonymous classes and RMI?
Thanks,
-BugLighter
1)Does anonymous class term relate to
interface instantiation only?
2)Is it possible to instantiate an anonymous class that implements a <code>Remote</code> interface and deliver it as a stub parameter to a remotely invoked method? If the answer is no (due to the RemoteObject) is it possible to overcome this or one should not mix anonymous classes and RMI?
Thanks,
-BugLighter
anonymous class is just a quick way to extend some class or implement some interface (but not both).
you should use named class (internal or external) instead.
(if you don't extend UnicastRemoteObjec t, you'll have to implement a lot of things yourself.)
1. what's the problem when you
'define an AbsTask that extends UniCastRemoteObject and implements Task. ' ?
2. why do you need 'anonymous class' ? :)
you should use named class (internal or external) instead.
(if you don't extend UnicastRemoteObjec t, you'll have to implement a lot of things yourself.)
1. what's the problem when you
'define an AbsTask that extends UniCastRemoteObject and implements Task. ' ?
2. why do you need 'anonymous class' ? :)
ASKER
Hi hey_hey,
1. I've defined
public abstract AbsTask extends UniCastRemoteObject implements Task
{
public AbsTask() throws RemoteException
{ /*.. I have told that this is a MAST (is it?) ..*/
}
public abstract Object execute();
}
now when I instiate an anonymous class
out of the AbsTask I got Error:should catch or throw the RemoteException and
I did not find a way to over come this error.
2. thought of using anonymous class just to make the code clearer, otherwise I'll use inners classes instead, faced a problem and just wanna know if I am missing an important concept.
Thanks hey_hey,
BugLighter.
1. I've defined
public abstract AbsTask extends UniCastRemoteObject implements Task
{
public AbsTask() throws RemoteException
{ /*.. I have told that this is a MAST (is it?) ..*/
}
public abstract Object execute();
}
now when I instiate an anonymous class
out of the AbsTask I got Error:should catch or throw the RemoteException and
I did not find a way to over come this error.
2. thought of using anonymous class just to make the code clearer, otherwise I'll use inners classes instead, faced a problem and just wanna know if I am missing an important concept.
Thanks hey_hey,
BugLighter.
1. all methods from the Remote interface should throw RemoteException, but you don't need to throw Exception from your constructor at all.
2. anonymous classes are just inner classes that does not have name ... but anonymous classes definition syntax is less powerfull than normal class definition.
2. anonymous classes are just inner classes that does not have name ... but anonymous classes definition syntax is less powerfull than normal class definition.
ASKER
Thanks heyhey_,
I would like to share the points with you. Please send am answer so I'll be able to do so.
-BugLighter
I would like to share the points with you. Please send am answer so I'll be able to do so.
-BugLighter
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.