Re: Example code for JavaSpace05??

"John McClain - Sun Microsystems, Inc." <[email protected]>
Newsgroups gmane.comp.java.sun.javaspaces
Message-ID <[email protected]>
Jim Goodwin wrote:
> Hello,
>
> I'm brand-new to JavaSpaces, Jini, and RMI. I'm trying to use JavaSpaces in
> the context of the Eclipse 3.1 PDE (Plugin Development Environment -- which
> I am using because I am trying to use RCP, the Rich Client framework, which
> requires PDE). I'm using the IncaX CE plugin for Eclipse too (version 4.3.0).
>
> It's been a sweat. PDE has its own ideas about classloading and I was
> getting the identical class loaded on two class loaders, so they were not
> seen as identical, causing failures. I think I have that fixed, by setting
> the current thread's context-class-loader to the one PDE uses, before
> attempting any JavaSpaces operations. This causes JavaSpaces and RMI to use
> the PDE class loader, which they seem to work fine with. Read/write work ok,
> and I've used MatchSet successfully too, against an instance of JavaSpace05.
> But I paid dearly for that knowledge, and would be interested in hearing
> from anybody else who knows more about the gory details.

I would be **VERY** interested in hearing about your experience (good
and bad) with MatchSet. [I know a lot about the gory details, but I have
already taken my best shot at explaining MatchSet so without more
background on what you had trouble with I am not sure I can add much in
the form of general explanation, more then willing to answer questions
though....]

> But now I cannot get notification working, either the old or the new '05
> way. I really don't understand what I'm doing.
>
> Question 1: Are there any code examples using the '05 notification spec?
>
> Question 2: Am I supposed to be doing UnUnicast.exportObject() on my
> listener? It's supposed to handle stub-generateion automagically, right?
> This is failing with no class def found (for the stub class).

What version of Java are you using? In 1.4 and earlier you have to run
rmic to create the stubs. In 1.5 there is automagic stub generation
(java.lang.reflect.Proxy), but it (apparently) only works if you don't
use the one arg version of UnicastRemoteObject.exportObject (looking at
your code I am guessing this is what you are running into).

Aside, you might want to consider using the net.jini.export.Exporter
model for exporting your listener. This would allow you to plug in
different RMI implementations at run/config time, including JERI which
always uses dynamic proxies and supports a robust network security model.

> So:
>
> Question 2A: Am I supposed to do any setup before calling Unicast, e.g.
> starting some server process or setting a mode or initializing something?
> I have the processes running (under Inca X) that were necessary for read and
> write, but haven't done any other setup.

I haven't used JRMP in 1.5, but I don't think you need to do anything
else besides call UnicastRemoteObject.exportObject.

> Question 2B: Does the automatic stub generation actually produce files on
> the disk somewhere and then load them? So I could go see if that was really
> happening? Or is it all in-process and on-the-fly?

In 1.5 it is using dynamic proxies for the "stubs", so there isn't any
class file as such. In 1.4 and before there is the stubs classes created
by rmic.

> Question 2C: Is there any log data I produced by the export operation or its
> failure that I should look for? There's nothing in the Inca X Console. The
> stackdump in the regular Eclipse/Java console is appended below.

Don't know off the top of my head

Hope this helps

> Thanks in advance for any help
>
> Jim Goodwin
>
> My test program. Note this is a straight Java App in Eclipse, not a PDE app,
> and I determined from a breakpoint that it's got the normal context class
> loader.
>
> package com.mak.test3;
>
> import java.rmi.RemoteException;
> import java.rmi.server.UnicastRemoteObject;
>
> import net.jini.core.event.*;
>
> public class Test3 {
>
>  public static void main(String[] args) throws RemoteException {
>   RemoteEventListener dummy = new RemoteEventListener() {
>    public void notify(RemoteEvent arg0) throws UnknownEventException,
> RemoteException {
>     System.out.println("An event!");
>    }
>   };
>   UnicastRemoteObject.exportObject(dummy);
>   System.out.print("Exported!");
>  }
> }
>
>
> The result:
>
> Exception in thread "main" java.rmi.StubNotFoundException: Stub class not
> found: com.mak.test3.Test3$1_Stub; nested exception is:
>  java.lang.ClassNotFoundException: com.mak.test3.Test3$1_Stub
>  at sun.rmi.server.Util.createStub(Unknown Source)
>  at sun.rmi.server.Util.createProxy(Unknown Source)
>  at sun.rmi.server.UnicastServerRef.exportObject(Unknown Source)
>  at java.rmi.server.UnicastRemoteObject.exportObject(Unknown Source)
>  at java.rmi.server.UnicastRemoteObject.exportObject(Unknown Source)
>  at com.mak.test3.Test3.main(Test3.java:16)
> Caused by: java.lang.ClassNotFoundException: com.mak.test3.Test3$1_Stub
>  at java.net.URLClassLoader$1.run(Unknown Source)
>  at java.security.AccessController.doPrivileged(Native Method)
>  at java.net.URLClassLoader.findClass(Unknown Source)
>  at java.lang.ClassLoader.loadClass(Unknown Source)
>  at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
>  at java.lang.ClassLoader.loadClass(Unknown Source)
>  at java.lang.ClassLoader.loadClassInternal(Unknown Source)
>  at java.lang.Class.forName0(Native Method)
>  at java.lang.Class.forName(Unknown Source)
>  ... 6 more
>
> ===========================================================================
> 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


--
BTW, if you want to reply to this message, please direct your reply
to the list, thanks

John McClain                                    [email protected]
Sun Microsystems, Inc.
Burlington, MA

no files, just services

===========================================================================
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.