Removido arquivos temporários

This commit is contained in:
Luiz F Picolo 2022-10-23 22:53:29 -04:00
parent 7e62ed2a88
commit 27fae412d0
22 changed files with 286 additions and 50 deletions

6
.classpath Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

100
.gitignore vendored
View File

@ -1,4 +1,96 @@
bin/*.class
.classpath
.project
.settings
# Created by https://www.toptal.com/developers/gitignore/api/eclipse,java
# Edit at https://www.toptal.com/developers/gitignore?templates=eclipse,java
### Eclipse ###
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# PyDev specific (Python IDE for Eclipse)
*.pydevproject
# CDT-specific (C/C++ Development Tooling)
.cproject
# CDT- autotools
.autotools
# Java annotation processor (APT)
.factorypath
# PDT-specific (PHP Development Tools)
.buildpath
# sbteclipse plugin
.target
# Tern plugin
.tern-project
# TeXlipse plugin
.texlipse
# STS (Spring Tool Suite)
.springBeans
# Code Recommenders
.recommenders/
# Annotation Processing
.apt_generated/
.apt_generated_test/
# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet
# Uncomment this line if you wish to ignore the project description file.
# Typically, this file would be tracked if it contains build/dependency configurations:
#.project
### Eclipse Patch ###
# Spring Boot Tooling
.sts4-cache/
### Java ###
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
# End of https://www.toptal.com/developers/gitignore/api/eclipse,java

28
.project Normal file
View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>VOTACAO-JAVA-RMI</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1666374968243</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>

9
Dockerfile Normal file
View File

@ -0,0 +1,9 @@
FROM openjdk:8
WORKDIR /app
COPY /src /app/src
RUN cd /app/src/ && javac Servidor.java
EXPOSE 8899

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

9
docker-compose.yml Normal file
View File

@ -0,0 +1,9 @@
version: '3.8'
services:
servidor:
build:
context: .
container_name: votation_server_tcp
ports:
- 8899:8899
command: java -classpath /app/src Servidor

Binary file not shown.

View File

@ -7,10 +7,10 @@ import interfaces.VotacaoInterface;
public class Cliente {
static int porta = 1099;
static int porta = 8898;
public static void main(String[] args) throws Exception {
String objName = "rmi://localhost:" + porta + "/server";
String objName = "//localhost:" + porta + "/server";
VotacaoInterface votacao = (VotacaoInterface) Naming.lookup(objName);
List<CandidatoImpl> candidatos = votacao.listarCandidatos();
@ -19,12 +19,12 @@ public class Cliente {
System.out.println(x.getNome() + " " + x.getNumero());
});
@SuppressWarnings("resource")
Scanner entrada = new Scanner(System.in);
System.out.println("Digite seu voto");
String numero_candidato = entrada.nextLine();
int posicao = votacao.buscarCandidato(numero_candidato);
System.out.println("Seu voto foi: " + candidatos.get(posicao).getNome());
votacao.apuracao();
}
}

33
src/ServidorApuracao.java Normal file
View File

@ -0,0 +1,33 @@
import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
import java.util.List;
import implementacoes.ApuracaoImpl;
import implementacoes.CandidatoImpl;
import implementacoes.VotacaoImpl;
import interfaces.ApuracaoInterface;
import interfaces.VotacaoInterface;
public class ServidorApuracao {
static List<CandidatoImpl> candidatos;
static ApuracaoInterface apuracao;
static int porta = 8899;
public static void main(String[] args) {
try {
System.out.println("Registrando o objeto no RMIRegistry...");
LocateRegistry.createRegistry(porta);
//votacaoImpl = new VotacaoImpl(candidatos);
apuracao = new ApuracaoImpl();
Naming.rebind("//localhost:" + porta + "/server", apuracao);
System.out.println("Servidor de Apuração. Aguardando Clientes na porta " + porta + "!");
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,27 +1,30 @@
import java.rmi.Naming;
import java.rmi.Remote;
import java.rmi.registry.LocateRegistry;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import implementacoes.CandidatoImpl;
import implementacoes.IsEvenImpl;
import implementacoes.VotacaoImpl;
import interfaces.ApuracaoInterface;
import interfaces.VotacaoInterface;
public class Servidor {
public class ServidorVotacao {
static List<CandidatoImpl> candidatos;
static VotacaoInterface votacaoImpl;
static int porta = 1099;
static int porta_servidor_votacao = 8898;
static int porta_servidor_apuracao = 8899;
static List<Integer> votos = new ArrayList<>();
public static void main(String[] args) {
try {
//IsEvenImpl x = new IsEvenImpl();
String objName = "rmi://localhost:" + porta + "/server";
System.out.println("Registrando o objeto no RMIRegistry...");
LocateRegistry.createRegistry(porta);
LocateRegistry.createRegistry(porta_servidor_votacao);
ApuracaoInterface apuracao = (ApuracaoInterface) Naming.lookup("//localhost:" + porta_servidor_apuracao + "/server");
// Lista de Candidatos
candidatos = new ArrayList<>();
@ -35,10 +38,23 @@ public class Servidor {
votacaoImpl = new VotacaoImpl(candidatos);
Naming.rebind(objName, votacaoImpl);
//Naming.rebind(objName, x);
Naming.rebind("//localhost:" + porta_servidor_votacao + "/server", votacaoImpl);
System.out.println("Aguardando Clientes na porta " + porta + "!");
System.out.println("Servidor de votação. Aguardando Clientes na porta " + porta_servidor_votacao + "!");
while (true) {
System.out.println("Aperte Enter para ver a apuração");
Scanner entrada = new Scanner(System.in);
entrada.nextLine();
votos.clear();
votacaoImpl.getVotos().forEach(x -> {
votos.add(x.getCandidato().getNumero());
});
votacaoImpl.mostrar_apuracao(apuracao.calcularVotos(votos));
}
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -0,0 +1,30 @@
package implementacoes;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import interfaces.ApuracaoInterface;
public class ApuracaoImpl extends UnicastRemoteObject implements ApuracaoInterface {
private static final long serialVersionUID = 1L;
public ApuracaoImpl() throws RemoteException {
super();
}
private Map<Integer, Integer> quantidade = new HashMap<>();
@Override
public Map<Integer, Integer> calcularVotos(List<Integer> votos) {
votos.forEach(voto -> {
int count = (int) votos.stream().filter(p -> p.equals(voto)).count();
quantidade.put(voto, ((100 * count) / votos.size()));
});
return quantidade;
}
}

View File

@ -1,24 +0,0 @@
package implementacoes;
import java.rmi.server.UnicastRemoteObject;
import interfaces.IsEvenInterface;
import java.rmi.RemoteException;
public class IsEvenImpl extends UnicastRemoteObject implements IsEvenInterface {
public IsEvenImpl() throws RemoteException {
super();
}
private static final long serialVersionUID = 1L;
@Override
public boolean is_even(int x) throws RemoteException {
System.out.println("Conectado. Parâmetro enviado é " + x);
if((x & 1) == 0) {
return true;
} else {
return false;
}
}
}

View File

@ -26,6 +26,11 @@ public class VotacaoImpl extends UnicastRemoteObject implements VotacaoInterface
public List<CandidatoImpl> listarCandidatos() throws RemoteException {
return this.candidatos;
}
@Override
public List<VotoImpl> getVotos(){
return this.votos;
}
@Override
public int salvarVoto(int posicao) throws RemoteException {
@ -48,6 +53,16 @@ public class VotacaoImpl extends UnicastRemoteObject implements VotacaoInterface
}
}
@Override
public void mostrar_apuracao(Map<Integer, Integer> quantidade) {
final String format = "O candidato %d possui %d votos";
final Set<Integer> chaves = quantidade.keySet();
System.out.println("Apuração dos votos");
for (final Integer chave : chaves) {
System.out.println(String.format(format, chave, quantidade.get(chave)));
}
}
@Override
public int buscarCandidato(String numero) throws RemoteException {
for(int i = 0; i < this.candidatos.size(); i++) {

View File

@ -1,9 +1,12 @@
package implementacoes;
import java.io.Serializable;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class VotoImpl extends UnicastRemoteObject {
import interfaces.VotoInterface;
public class VotoImpl extends UnicastRemoteObject implements Serializable, VotoInterface {
private static final long serialVersionUID = 1L;
@ -16,10 +19,12 @@ public class VotoImpl extends UnicastRemoteObject {
this.identificador = identificador;
}
@Override
public CandidatoImpl getCandidato() {
return candidato;
}
@Override
public String getIdentificador() {
return identificador;
}

View File

@ -0,0 +1,10 @@
package interfaces;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.List;
import java.util.Map;
public interface ApuracaoInterface extends Remote {
public Map<Integer, Integer> calcularVotos(List<Integer> votos) throws RemoteException;
}

View File

@ -1,7 +0,0 @@
package interfaces;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface IsEvenInterface extends Remote {
public boolean is_even(int x) throws RemoteException;
}

View File

@ -3,12 +3,16 @@ package interfaces;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.List;
import java.util.Map;
import implementacoes.CandidatoImpl;
import implementacoes.VotoImpl;
public interface VotacaoInterface extends Remote {
public List<CandidatoImpl> listarCandidatos() throws RemoteException;
public int salvarVoto(int posicao) throws RemoteException;
public int buscarCandidato(String numero) throws RemoteException;
public void apuracao() throws RemoteException;
public List<VotoImpl> getVotos() throws RemoteException;
public void mostrar_apuracao(Map<Integer, Integer> apuracao) throws RemoteException;
}

View File

@ -0,0 +1,10 @@
package interfaces;
import java.rmi.RemoteException;
import implementacoes.CandidatoImpl;
public interface VotoInterface {
public CandidatoImpl getCandidato() throws RemoteException;;
public String getIdentificador() throws RemoteException;;
}