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.
BugLighterAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

heyhey_Commented:
your question is quite unclear ... to me :)
0
BugLighterAuthor Commented:
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
0
heyhey_Commented:
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' ? :)
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

BugLighterAuthor Commented:
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.
0
heyhey_Commented:
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.
0
BugLighterAuthor Commented:
Thanks heyhey_,
I would like to share the points with you. Please send am answer so I'll be able to do so.

-BugLighter
0
heyhey_Commented:
Thanks :)
I'm glad that you've solved the problem.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.