Método de Shutdown usando RMI

1 resposta
A

Pessoal, preciso criar o método shutdown, para ele finalizar o servidor assim que o cálculo for terminado.
Se alguem puder me ajudar.


import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

import java.util.;
import javax.swing.
;

public class SomaClient {

private SomaClient() {}

public static void main(String[] args) {
int x,y,z;

String host = (args.length < 1) ? null : args[0]; // interface 
try {
    Registry registry = LocateRegistry.getRegistry(host);
    Soma stub = (Soma) registry.lookup("Soma");
    
    String opc1=JOptionPane.showInputDialog("Digite a o valor 1 com peso 3");
    x= Integer.parseInt(opc1);
    String opc2=JOptionPane.showInputDialog("Digite a o valor 2 com peso 3");
    y= Integer.parseInt(opc2);
    String opc3=JOptionPane.showInputDialog("Digite a o valor 3 com peso 4");
    z= Integer.parseInt(opc3);
    int response = stub.soma(x,y);

    System.out.println("resposta: " + response);
	
} catch (Exception e) {
    System.err.println("Exceção do Cliente: " + e.toString());
    e.printStackTrace();
}
}

}

1 Resposta

A

O código de antes é o Client e este é o Server…

import java.rmi.registry.Registry; //comunica remotamente sabe quem é cliente e servidor…sempre importar
import java.rmi.registry.LocateRegistry; // sempre importar
import java.rmi.RemoteException; // sempre importar
import java.rmi.server.UnicastRemoteObject; // sempre importar

public class SomaServer implements Soma{

public SomaServer() {}   // construtor da classe 

public int soma(int x,int y, int z)
{
return ((x*3)+(y*3)+(z*4))/10;
}

public static void main(String args[]) {

try {
    SomaServer obj = new SomaServer();
    Soma stub = (Soma) UnicastRemoteObject.exportObject(obj, 0); // chama a interface no caso Soma 

    // Bind the remote object's stub in the registry
    Registry registry = LocateRegistry.getRegistry(); // tipo do dado com o novo dado de uma nova instancia
    registry.bind("Soma", stub);	// variavel que liga Soma com o stub

    System.err.println("Servidor Pronto");
} catch (Exception e) {
    System.err.println("Exceção do Servidor: " + e.toString());
    e.printStackTrace();
}
}

}

Criado 28 de maio de 2008
Ultima resposta 28 de mai. de 2008
Respostas 1
Participantes 1