Stub File
Paulo Melo <[email protected]>
| Newsgroups | gmane.comp.java.sun.rmi |
|---|---|
| Message-ID | <[email protected]> |
In the API Documentation from RMI Tiger says that I
don't need pregenerated the stub file from the Remote
Object class,
but in my application when i run the server(that is
the remote object) the JVM request the _stub file.
What will be?
Bellow the source code:
-----------------------------------------------
Servidor.java
-----------------------------------------------
import java.io.Serializable;
public class MeuBean implements Serializable{
private int iCodigo;
private String sDescricao;
public MeuBean(){}
public MeuBean(int codigo, String descricao){
iCodigo = codigo;
sDescricao = descricao;
}
public void setCodigo(int codigo){
iCodigo = codigo;
}
public int getCodigo(){
return iCodigo;
}
public void setDescricao(String descricao){
sDescricao = descricao;
}
public String getDescricao(){
return sDescricao;
}
}
-----------------------------------------------
Servidor.java
-----------------------------------------------
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Servidor extends Remote{
public MeuBean getBean() throws RemoteException;
}
-----------------------------------------------
ServidorImpl.java
-----------------------------------------------
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.AlreadyBoundException;
import java.rmi.server.UnicastRemoteObject;
import java.io.IOException;
public class ServidorImpl implements Servidor{
private MeuBean obj;
public ServidorImpl(){
obj = new MeuBean(1, "Hello RMI!!");
inicia();
}
public MeuBean getBean(){
System.out.println("Requisitado!!");
return obj;
}
public void inicia(){
try{
//Exporta o objeto remoto
Servidor stub = (Servidor)
UnicastRemoteObject.exportObject(this);
//Liga o stub do objeto remoto no registro
Registry registry =
LocateRegistry.getRegistry(1000);
//Dá um nome pra ele no registro
registry.bind("Servidor", stub);
System.out.println("Servidor rodando...");
}catch(RemoteException Re){
System.out.println(Re.getMessage());
}catch(AlreadyBoundException ABe){
System.out.println(ABe.getMessage());
}catch(IOException IOe){
System.out.println(IOe.getMessage());
}
}
public static void main(String args[]){
new ServidorImpl();
}
}
-----------------------------------------------
Cliente .java
-----------------------------------------------
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.RemoteException;
import java.rmi.NotBoundException;
public class Cliente {
private Cliente() {}
public static void main(String[] args){
MeuBean bean;
try{
Registry registry =
LocateRegistry.getRegistry("localhost", 1000);
Servidor stub = (Servidor)
registry.lookup("Servidor");
bean = stub.getBean();
System.out.println("Resposta: " +
bean.getDescricao());
}catch(RemoteException Re){
System.out.println(Re.getMessage());
}catch(NotBoundException NBe){
System.out.println(NBe.getMessage());
}
}
}
A Paz!!
Paulo Henrique
_______________________________________________________
Yahoo! Acesso Grátis - Instale o discador do Yahoo! agora. http://br.acesso.yahoo.com/ - Internet rápida e grátis
===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff RMI-USERS". For general help, send email to
[email protected] and include in the body of the message "help".
For a list of frequently asked RMI questions please refer to:
http://java.sun.com/j2se/1.3/docs/guide/rmi/faq.html
To view past RMI-USERS postings, please see:
http://archives.java.sun.com/archives/rmi-users.html