• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Method invocation _after_ ending of another method

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys,

I have an interesting problem with programming my RMI application in Java.
I'll just put it in a simple way:
- I've a method with return value. This method is invoked from the remote VM.
- What I need is to invoke another method _after_ the method in the previous point returns the value.

Note: If you know Aspect Oriented Programming (e.g. AspectJ), you can see that the solution to my problem could be something like pointcut and advice constructs in AOP. But I'm limited to using the pure Java, so I cannot use AspectJ.
Perhaps some _lightweight_ framework enabling the usage of cross-cutting could also help me. So if you know any one, post it here, please.

I hope you aren't confused too much - I really cannot explain things

C.
 
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about starting a separate thread just before you return your method.

Also I can't see how using AOP (e.g Aspectj) helps in this.
 
Ctirad Kr�l�k
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes - actually I have considered the separate thread with some delay, but I also wanted to know if there is anything else...

AspectJ could (maybe) help like this:
1) I would define a new aspect with a pointcut that catches the calling of the remote method
2) In the same aspect I would define an advice "after()" and I would put the "reacting" method's call here.
I guess it would work...

Thank you for the answer
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its effectively a post condition of the original method...Why dont you wrap the RMI interface in a local proxy which implements a POJO interface with methods matching those of the RMI interface. You can delegate the RMI call to the RMI stub and then invoke the reactive method from there yourself? For example, if the remote method returns a random int, would the following work:




Does this help in any way? I think you should try to do stuff as simply as possible, so use AOP only if it makes sense. I think one of the main reasons for using aspects is a separation of concerns, in that you dont want part A of a system doing things that part B should be doing e.g. the DB access module should only be accessing the DB, raher than first ensuring the user is authenticated and then accessing the DB etc. The authentication can invoked as a before advice on the DB access for example..
[ November 23, 2008: Message edited by: Tom Johnson ]
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tom, isn't the RMIWrapper the RMI client?

I was under the impression that the the other method was to be executed in the RMI server..
 
Tom Johnson
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Gamini,
I wasn't entirely sure where he wanted the "after" method to execute (client or server JVM), so I chose that way. The Reactor.react() could be replaced with a call to an "after" method on the RMI server (if OP doesn't mind the performance overhead of a second remote call).

Alternatively, the RMI server implementation could use the above pattern and upon returning from invoking the getNumber() method (locally on the RMI server), it could invoke the "after" method itself, before returning to the client JVM....
 
Ctirad Kr�l�k
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys,

actually I have something very similar to the code above. The only nasty thing is that I want to execute the react() method after the "return randomValue". And this is the problem in Java...
I think that I'll solve it as follows:
The Reactor.react() method will run a new thread which will implement the wanted operation, but after some delay. I'll rely that the result of the getNumber() is already returned to the client.

Nevertheless - thank you very much for your answers!

have a nice time
C.
 
reply
    Bookmark Topic Watch Topic
  • New Topic