Re: Help in JavaSpaces Calculator

Dan Creswell <[email protected]> Tue, 26 Sep 2006 10:13:19 +0100
Newsgroups gmane.comp.java.sun.javaspaces
Message-ID <[email protected]>
Hi, response below............

Tatiana Pereira Filgueiras wrote:
> Hi!
> I'm new on JavaSpaces Tecnology and I'm trying to make a Calculator.
> But I don't understand why errors below... anybody can help me? Anybody have
> a Calculator Code example? (in this structure: client --- javaspace --
> calculator server)
> thx
> Tatiana
>
> My errors:(the same is for Cliente.java)
>
> C:\Documents and Settings\Tati\Desktop\Pesquisas\pratica\Tentativa2>java -classp
> ath .\;"C:\Arquivos de programas\jini2_1\lib\jini-ext.jar";"C:\Documents and Set
> tings\Tati\Desktop\Pesquisas\pratica\pac.jar";"C:\Arquivos de programas\jini2_1\
> lib\reggie.jar";"C:\Arquivos de programas\jini2_1\lib\outrigger.jar";"C:\Arquivo
> s de programas\jini2_1\lib\jini-core.jar" Servidor
>
> Localizando JavaSpace...
>
> JavaSpace localizado.
>
> Registrying object notify...
>
> Error!
>
> java.rmi.ServerException: RemoteException in server thread; nested exception is:
>
>         java.rmi.UnmarshalException: unmarshalling method/arguments; nested exce
> ption is:
>         java.lang.ClassNotFoundException: Servidor
>         at net.jini.jeri.BasicInvocationDispatcher.dispatch(BasicInvocationDispa
> tcher.java:644)
>         at com.sun.jini.jeri.internal.runtime.ObjectTable$6.run(ObjectTable.java
> :597)
>         at net.jini.export.ServerContext.doWithServerContext(ServerContext.java:
> 103)
>         at com.sun.jini.jeri.internal.runtime.ObjectTable$Target.dispatch0(Objec
> tTable.java:595)
>         at com.sun.jini.jeri.internal.runtime.ObjectTable$Target.access$700(Obje
> ctTable.java:212)
>         at com.sun.jini.jeri.internal.runtime.ObjectTable$5.run(ObjectTable.java
> :568)
>         at com.sun.jini.start.AggregatePolicyProvider$6.run(AggregatePolicyProvi
> der.java:527)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at com.sun.jini.jeri.internal.runtime.ObjectTable$Target.dispatch(Object
> Table.java:565)
>         at com.sun.jini.jeri.internal.runtime.ObjectTable$Target.dispatch(Object
> Table.java:540)
>         at com.sun.jini.jeri.internal.runtime.ObjectTable$RD.dispatch(ObjectTabl
> e.java:778)
>         at net.jini.jeri.connection.ServerConnectionManager$Dispatcher.dispatch(
> ServerConnectionManager.java:148)
>         at com.sun.jini.jeri.internal.mux.MuxServer$2.run(MuxServer.java:244)
>         at com.sun.jini.start.AggregatePolicyProvider$5.run(AggregatePolicyProvi
> der.java:513)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at com.sun.jini.jeri.internal.mux.MuxServer$1.run(MuxServer.java:241)
>         at com.sun.jini.thread.ThreadPool$Worker.run(ThreadPool.java:136)
>         at java.lang.Thread.run(Thread.java:595)
>         at com.sun.jini.jeri.internal.runtime.Util.__________EXCEPTION_RECEIVED_
> FROM_SERVER__________(Util.java:108)
>         at com.sun.jini.jeri.internal.runtime.Util.exceptionReceivedFromServer(U
> til.java:101)
>         at net.jini.jeri.BasicInvocationHandler.unmarshalThrow(BasicInvocationHa
> ndler.java:1303)
>         at net.jini.jeri.BasicInvocationHandler.invokeRemoteMethodOnce(BasicInvo
> cationHandler.java:832)
>         at net.jini.jeri.BasicInvocationHandler.invokeRemoteMethod(BasicInvocati
> onHandler.java:659)
>         at net.jini.jeri.BasicInvocationHandler.invoke(BasicInvocationHandler.ja
> va:528)
>         at com.sun.jini.outrigger.$Proxy1.notify(Unknown Source)
>         at com.sun.jini.outrigger.SpaceProxy2.notify(SpaceProxy2.java:507)
>         at Servidor.main(Servidor.java:34)
> Caused by: java.rmi.UnmarshalException: unmarshalling method/arguments; nested e
> xception is:
>         java.lang.ClassNotFoundException: Servidor
>         at net.jini.jeri.BasicInvocationDispatcher.dispatch(BasicInvocationDispa
> tcher.java:619)
>         at com.sun.jini.jeri.internal.runtime.ObjectTable$6.run(ObjectTable.java
> :597)
>         at net.jini.export.ServerContext.doWithServerContext(ServerContext.java:
> 103)
>         at com.sun.jini.jeri.internal.runtime.ObjectTable$Target.dispatch0(Objec
> tTable.java:595)
>         at com.sun.jini.jeri.internal.runtime.ObjectTable$Target.access$700(Obje
> ctTable.java:212)
>         at com.sun.jini.jeri.internal.runtime.ObjectTable$5.run(ObjectTable.java
> :568)
>         at com.sun.jini.start.AggregatePolicyProvider$6.run(AggregatePolicyProvi
> der.java:527)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at com.sun.jini.jeri.internal.runtime.ObjectTable$Target.dispatch(Object
> Table.java:565)
>         at com.sun.jini.jeri.internal.runtime.ObjectTable$Target.dispatch(Object
> Table.java:540)
>         at com.sun.jini.jeri.internal.runtime.ObjectTable$RD.dispatch(ObjectTabl
> e.java:778)
>         at net.jini.jeri.connection.ServerConnectionManager$Dispatcher.dispatch(
> ServerConnectionManager.java:148)
>         at com.sun.jini.jeri.internal.mux.MuxServer$2.run(MuxServer.java:244)
>         at com.sun.jini.start.AggregatePolicyProvider$5.run(AggregatePolicyProvi
> der.java:513)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at com.sun.jini.jeri.internal.mux.MuxServer$1.run(MuxServer.java:241)
>         at com.sun.jini.thread.ThreadPool$Worker.run(ThreadPool.java:136)
>         at java.lang.Thread.run(Thread.java:595)
> Caused by: java.lang.ClassNotFoundException: Servidor
>         at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
>         at net.jini.loader.pref.PreferredClassLoader.loadClass(PreferredClassLoa
> der.java:922)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
>         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
>         at java.lang.Class.forName0(Native Method)
>         at java.lang.Class.forName(Class.java:242)
>         at net.jini.loader.pref.PreferredClassProvider.loadClass(PreferredClassP
> rovider.java:613)
>         at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:247)
>         at net.jini.loader.ClassLoading.loadClass(ClassLoading.java:138)
>         at net.jini.io.MarshalInputStream.resolveClass(MarshalInputStream.java:2
> 96)
>         at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:154
> 4)
>         at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1466)
>         at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1
> 699)
>         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1305)
>         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)
>         at com.sun.jini.jeri.internal.runtime.Util.unmarshalValue(Util.java:221)
>
>         at net.jini.jeri.BasicInvocationDispatcher.unmarshalArguments(BasicInvoc
> ationDispatcher.java:1049)
>         at net.jini.jeri.BasicInvocationDispatcher.dispatch(BasicInvocationDispa
> tcher.java:599)
>         ... 17 more
> Pressione qualquer tecla para continuar. . .
>
>
> This is my codes:
>
> Cliente.java
>
> import Calculadora2App.*;
>
> import java.io.Serializable;
> import java.util.Scanner;
> import net.jini.space.JavaSpace;
> import net.jini.core.lease.Lease;
> import net.jini.core.event.RemoteEvent;
> import net.jini.core.event.RemoteEventListener;
> import java.lang.*;
>
> public class Cliente implements RemoteEventListener,Serializable{
>
>  private JavaSpace space;
>
>  public Cliente(){}
>
>  public Cliente(JavaSpace space){
>   this.space = space;
>   }
>
>  public static void main(String[] args){
>
>  try {
>   // ************* Fazendo Lookup para achar o espaço ***********************
>
>   Utilidades conexao = new Utilidades();
>   JavaSpace space = conexao.conecta();
>   Cliente setar = new Cliente(space);
>   // ************** Registrando cliente para receber notificação de
> resultado **************
>
>   Cliente usuario = new Cliente();
>   Resultado template = new Resultado();
>   space.notify(template, null,usuario, Lease.FOREVER, null);
>
>   //
> ***************************************************************************************
>
>   Scanner sc = new Scanner(System.in);
>         CalcEntry msg = new CalcEntry(); // Entry de requisição de calculos
>
>
>    System.out.println("************************************************\n");
>    System.out.println("Digite o numero da operacao desejada:\n");
>    System.out.println("1. Adicao\n");
>    System.out.println("2. Subtracao:\n");
>    System.out.println("3. Multiplicacao\n");
>    System.out.println("4. Divisao\n");
>    System.out.println("************************************************\n");
>
>
> //****************************************************************************************
>
>
>   msg.operacao = new Integer(sc.nextInt());
>   System.out.println("Digite o primeiro numero: ");
>   msg.op1 = new Integer(sc.nextInt());
>   System.out.println("\nDigite o segundo numero:");
>   msg.op2 = new Integer(sc.nextInt());
>
>   //****************************** Usando write para escrever no espaço
> *********************
>   conexao.escreve(msg,space);
>
>     }
>     catch (Exception e){
>          e.printStackTrace();
>          }
>  }
> // ************************************** Usar take para retirar do espaço
> **************************
>
>  public void notify(RemoteEvent evento){
>
>   System.out.println("Evento recebido. Tentando retirar do espaco........\n");
>
>   Resultado resulEntry = new Resultado();
>
>   //loop para tirar todas as entrys do espaço
>   while(resulEntry == null){
>    try{
>    resulEntry = (Resultado)space.take(resulEntry,null,Long.MAX_VALUE);
>    System.out.println("\nResultado da operacao:
> "+resulEntry.resultado.intValue());
>    }
>   catch(Exception e){
>    System.err.println("Erro ao retirar do espaço\n");
>    e.printStackTrace();
>   }
>  }
>  }
>  //
> **************************************************************************************************
> }
>
>
> Servidor.java
>
> import Calculadora2App.*;
>
> import java.io.Serializable;
> import java.util.Scanner;
> import net.jini.space.JavaSpace;
> import net.jini.core.lease.Lease;
> import net.jini.core.event.RemoteEvent;
> import net.jini.core.event.RemoteEventListener;
> import java.lang.*;
>
> public class Servidor implements RemoteEventListener,Serializable{
>
>  private JavaSpace space;
>
>  public Servidor(){}
>
>  public Servidor(JavaSpace space){
>   this.space = space;
>   }
>
>  public static void main(String[] args){
>
>  try {
>   // ************* Fazendo Lookup para achar o espaço ***********************
>
>   Utilidades conexao = new Utilidades();
>   JavaSpace space = conexao.conecta();
>   Servidor setar = new Servidor(space);
>
>   // ************** Registrando servidor para receber solicitações
> **************
>   System.out.println("Registrando objeto notify...\n");
>   Servidor calculadora = new Servidor();
>   CalcEntry solicitacao = new CalcEntry();
>   space.notify(solicitacao, null,calculadora, Lease.FOREVER, null);

This is your problem  ^^^^^^^^^^^^^^

You are passing an instance of your server to notify and you need to
pass a remote reference to your server.

You will need to read up on net.jini.jeri.Exporter and friends.


Dan.

===========================================================================
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