TrabalhosGratuitos.com - Trabalhos, Monografias, Artigos, Exames, Resumos de livros, Dissertações
Pesquisar

Projeto Servidor de Nomes - Código Fonte

Por:   •  19/7/2015  •  Projeto de pesquisa  •  7.900 Palavras (32 Páginas)  •  272 Visualizações

Página 1 de 32

Projeto Servidor de Nomes

CAIO DE LIMA SABRA - RA 20369904

CAROLINA CRUZ SOUZA - RA 20165035

DENIS WILSON EVANGELISTA - RA 20350052

RAFAEL DE SOUSA SILVA PONZIO – 20350649

Código Fonte:

import java.rmi.Naming;

import java.util.ArrayList;

import java.util.List;

import libs.MaiorNumeroServiceInterface;

import libs.MediaServiceInterface;

import libs.ServerNameInterface;

public class HelloClient {

        static String message = "blank";

        static ServerNameInterface obj = null;

        public static void main(String args[]) {

                try {

                        

                        System.out.println("Lista de numeros : " + getList());

                        obj = (ServerNameInterface) Naming.lookup("//" + "localhost:1099" + "/ServerNameInterface");                        

                                                

                        //Executa Média

                        String mediaUrl = obj.getUrlServicos("Media");

                        MediaServiceInterface mediaService = (MediaServiceInterface) Naming.lookup(mediaUrl);                        

                        double a = mediaService.calculaMedia(getList());                        

                        System.out.println("Media : " + a);

                        

                        //Executa Maior numero

                        String maiorNumeroUrl = obj.getUrlServicos("MaiorNumero");

                        MaiorNumeroServiceInterface maiorService = (MaiorNumeroServiceInterface) Naming.lookup(maiorNumeroUrl);                                double b = maiorService.calculaMaiorNumero(getList());                

                        System.out.println("O maior numero é: "+ b);

                                

                } catch (Exception e) {

                        System.out.println("HelloClient exception: " + e.getMessage());

                        e.printStackTrace();

                }

        }

        private static List getList(){

                List list = new ArrayList();

                list.add(new Double(2L));

                list.add(new Double(8L));

                list.add(new Double(10L));

                list.add(new Double(20L));

                return list;

                

        }

}

package libs;

import java.rmi.Remote;

import java.rmi.RemoteException;

import java.util.List;

public interface MaiorNumeroServiceInterface extends Remote {

        double calculaMaiorNumero(List list)throws RemoteException; ;

}

package libs;

import java.rmi.Remote;

import java.rmi.RemoteException;

import java.util.List;

public interface MediaServiceInterface extends Remote {

        double calculaMedia(List list)throws RemoteException; ;

}

package libs;

import java.rmi.Remote;

import java.rmi.RemoteException;

/* Classname: Hello Comment: The remote interface. */

public interface ServerNameInterface extends Remote {

        String Hello() throws RemoteException;

        void addServidor(Servidor servidor) throws RemoteException;                

        String removeServidor(String serverName)throws RemoteException;

        String getUrlServicos(String nomeServico)throws RemoteException;

}

package libs;

import java.io.Serializable;

public class Servidor implements Serializable{

        private static final long serialVersionUID = -823154043318387242L;

        private String nome;

        private String url;

        private boolean ativo;

        

        public String getNome() {

                return nome;

        }

        public void setNome(String nome) {

                this.nome = nome;

        }

        public String getUrl() {

                return url;

        }

        public void setUrl(String url) {

                this.url = url;

        }

        public boolean isAtivo() {

                return ativo;

        }

        public void setAtivo(boolean ativo) {

                this.ativo = ativo;

        }

}


package model;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

import java.util.List;

import libs.Servidor;

public class DB {

        private Connection getConnection() throws SQLException {

                Connection conn = DriverManager.getConnection("jdbc:h2:~/test", "sa","");

...

Baixar como (para membros premium)  txt (20.6 Kb)   pdf (103.1 Kb)   docx (18.2 Kb)  
Continuar por mais 31 páginas »
Disponível apenas no TrabalhosGratuitos.com