Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

RMI - Aiuto

0 views
Skip to first unread message

Mr. Deckard

unread,
Mar 9, 2003, 12:14:45 PM3/9/03
to
Ciao ragazzi,
sto cercando di studiare RMI, al di là della mera teoria che a livello
generale, mi sembra di aver più o meno compreso, ho dei grossi sul piano
applicativo.
Come testo di riferimento sto utilizzando Thinking In Java (Apogeo), e come
codice d'esempio ho utilizzato la piccola applicazione PerfectTime.
Le classi sono:
PerfectTimeI (L'Interfaccia Remota)
PerfectTime (Il Server che implementa PerfectTimeI)
DispalyPerfectTime (Il client)

Ecco di seguito i codici:

//: c15:rmi:PerfectTimeI.java
// From 'Thinking in Java, 2nd ed.' by Bruce Eckel
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
// The PerfectTime remote interface.
package netinventions;
import java.rmi.*;

public interface PerfectTimeI extends Remote {
long getPerfectTime() throws RemoteException;
} ///:~

//: c15:rmi:PerfectTime.java
// From 'Thinking in Java, 2nd ed.' by Bruce Eckel
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
// The implementation of
// the PerfectTime remote object.
package netinventions;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.net.*;

public class PerfectTime
extends UnicastRemoteObject
implements PerfectTimeI {
// Implementation of the interface:
public long getPerfectTime()
throws RemoteException {
return System.currentTimeMillis();
}
// Must implement constructor
// to throw RemoteException:
public PerfectTime() throws RemoteException {
// super(); // Called automatically
}
// Registration for RMI serving. Throw
// exceptions out to the console.
public static void main(String[] args)
throws Exception {
System.setSecurityManager(
new RMISecurityManager());
PerfectTime pt = new PerfectTime();
Naming.bind(
"//pegaso:1099/PerfectTime", pt);
System.out.println("Ready to do time");
}
} ///:~


//: c15:rmi:DisplayPerfectTime.java
// From 'Thinking in Java, 2nd ed.' by Bruce Eckel
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
// Uses remote object PerfectTime.
package netinventions;
import java.rmi.*;
import java.rmi.registry.*;

public class DisplayPerfectTime {
public static void main(String[] args)
throws Exception {
System.setSecurityManager(
new RMISecurityManager());
PerfectTimeI t =
(PerfectTimeI)Naming.lookup(
"//pegaso:1099/PerfectTime");
for(int i = 0; i < 10; i++)
System.out.println("Perfect time = " +
t.getPerfectTime());
}
} ///:~

Ma compilando e avviando il "server" (PerfectTime) oottengo i seguenti
errori:

java.rmi.ServerException: Server RemoteException; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested
exception is:
java.lang.ClassNotFoundException: netinventions.PerfectTime_Stub
at
sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteC
all.java:247)
at
sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:350)
at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
at java.rmi.Naming.bind(Naming.java:111)
at netinventions.PerfectTime.main(PerfectTime.java:32)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments;
nested exception is:
java.lang.ClassNotFoundException: netinventions.PerfectTime_Stub
Caused by: java.lang.ClassNotFoundException: netinventions.PerfectTime_Stub

Compliando e avviando invece il "client" (DisplayPerfectTime) ottengo mi
seguenti errori:

java.security.AccessControlException: access denied
(java.net.SocketPermission pegaso resolve)
at
java.security.AccessControlContext.checkPermission(AccessControlContext.java
:270)
at
java.security.AccessController.checkPermission(AccessController.java:401)
at
java.lang.SecurityManager.checkPermission(SecurityManager.java:542)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1042)
at java.net.InetAddress.getAllByName0(InetAddress.java:937)
at java.net.InetAddress.getAllByName0(InetAddress.java:918)
at java.net.InetAddress.getAllByName(InetAddress.java:912)
at java.net.InetAddress.getByName(InetAddress.java:832)
at java.net.InetSocketAddress.<init>(InetSocketAddress.java:109)
at java.net.Socket.<init>(Socket.java:119)
at
sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketF
actory.java:22)
at
sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketF
actory.java:128)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:562)
at
sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
at
sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:313)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:84)
at netinventions.DisplayPerfectTime.main(DisplayPerfectTime.java:14)
Exception in thread "main"

Come ambiente di sviluppo utilizzo NetBeans 3.4
Inoltre mi sembra che non venga prodotto il PerfectTime_skel.class
Insomma ho bisogno di qualche dritta, credo di essere fuori strada con
questo tema della programmazione.
Grazie a tutti.
Mr. Dekcard


0 new messages