Re: problem with distribuited events

Holger Hoffstätte <[email protected]> Sat, 12 Apr 2008 14:13:45 +0200
Newsgroups gmane.comp.java.sun.javaspaces
Message-ID <[email protected]>
Bulzan Stefan wrote:
> I'm new in using Javaspaces. So, please help :)
> 
> I have the next class:
> 
> public class Listener implements RemoteEventListener  {
>     private JavaSpace space;
> 
>     public Listener(JavaSpace space) throws RemoteException {
>         this.space = space;
>         UnicastRemoteObject.exportObject(this);
>     }
> 
>     public void notify(RemoteEvent ev) { ... }
> }
> 
> an java.rmi.StubNotFoundException: Stub class not found: main.Listener_Stub
> is thrown.
> 
> What should I do to publish this class as a distributed event listener?
> Should I make a stub with rmic ? 
> Please tell me the process for setting up the Remote event listener.

Unless I misunderstand what you are trying to do you should be able to 
simply use space.notify() with an appropriate template. In your listener 
notify() method you can then also get the eventSource from the received 
event, which will be the notifing space; that way you do not have to store 
the reference (which may become stale) in the instance variable.

Btw you should try to avoid registering the listener in the constructor, 
as that is known as "unsafe publication" and may lead to obscure 
(thread-related) problems. Let the caller of the constructor do the 
registration.

hth
Holger

===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff JAVASPACES-USERS".  For general help, send email to
[email protected] and include in the body of the message "help".

To view past JAVASPACES-USERS postings, please see:
http://archives.java.sun.com/archives/javaspaces-users.html