[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 405
  • Last Modified:

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.
0
BugLighter
Asked:
BugLighter
  • 4
  • 3
1 Solution
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now