-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEstadoOffline
93 lines (81 loc) · 3.42 KB
/
EstadoOffline
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package socius.state;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.UnknownHostException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import socius.dispositivos.Computador;
import socius.excecoes.FalhaNaConexaoComServidorException;
import socius.excecoes.SistemaOperacionalNaoSuportadoException;
import socius.stream.Transferencia;
import socius.adapter.Arquivo;
/**
*
* @author Ana Caroline Ferreira
*/
public class EstadoOffline implements EstadoComputador {
private Computador computador;
private String estado="offline";
private ObservableList<Arquivo> arquivos=FXCollections.observableArrayList();
public EstadoOffline(Computador computador) {
this.computador = computador;
}
public String compartilhados() throws RemoteException, SistemaOperacionalNaoSuportadoException{
if(!computador.getArquivos().isEmpty()) {
return "Lista de Arquivos:";
}else{
return "Nenhum Arquivo Compartilhado no momento";
}
}
@Override
public void conectar() throws FalhaNaConexaoComServidorException {
// Scanner tc = new Scanner(System.in);
// System.out.println("Deseja se conectar?(y/n)");
// String ans = tc.nextLine();
// if(ans.equalsIgnoreCase("y")){
try {
//disponibiliza pc
Naming.rebind("Computador", computador);
//busca servidor
Remote remote=Naming.lookup("Compartilha");
Transferencia iServidor=(Transferencia) remote;
//muda de estado
computador.setEstado(computador.getOnline());
System.out.println(computador.getEstado());
//retorna mensagem ao servidor
iServidor.setmensagemServidor("Seja Bem Vindo! \n Novo Estado:"+computador.getEstado());
System.out.println(computador.getHost()+":"+computador.getArquivos());
//retorna lista de arquivos deste computador e o ip do mesmo
iServidor.setlista(computador.getHost(), computador.getArquivos());
} catch (RemoteException ex) {
Logger.getLogger(EstadoOffline.class.getName()).log(Level.SEVERE, null, ex);
} catch (MalformedURLException ex) {
Logger.getLogger(EstadoOffline.class.getName()).log(Level.SEVERE, null, ex);
} catch (NotBoundException ex) {
Logger.getLogger(EstadoOffline.class.getName()).log(Level.SEVERE, null, ex);
} catch (SistemaOperacionalNaoSuportadoException ex) {
Logger.getLogger(EstadoOffline.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
public void desconectar() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String toString() {
return "EstadoOffline{" + "estado=" + estado + ", arquivos=" + arquivos + '}';
}
public ObservableList<Arquivo> getArquivos() {
return arquivos;
}
}