-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImplPolyPaypal.java
128 lines (113 loc) · 4.34 KB
/
ImplPolyPaypal.java
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.Hashtable;
/*
* ImplPolyPaypal.java
*
* Created on April 4, 2007, 10:44 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author Yann
*/
public class ImplPolyPaypal extends UnicastRemoteObject implements InterfacePolyPaypal{
/** Creates a new instance of ImplPolyPaypal */
private Hashtable<String,InterfaceClient> mesClients;
private InterfacePolyEbay remoteEbay; //Interface PolyEbay
private InterfaceCreditCheck remoteCreditCheck; //Interface CreditCheck
private ImplPolyPaypal serveurPolyPaypal;
static private String ipCreditCheck;
public ImplPolyPaypal() throws RemoteException {
mesClients = new Hashtable<String,InterfaceClient>();
try{
java.rmi.registry.LocateRegistry.createRegistry(5000);
System.out.println("Registre cree sur le port 5000 pour le serveur PolyPaypal");
} catch(Exception e) {
e.printStackTrace();
}
try {
java.rmi.registry.Registry reg = java.rmi.registry.LocateRegistry.getRegistry(5000);
System.out.println("Registre utilise sur le port 5000 pour le serveur PolyPaypal");
} catch (Exception e) {
System.out.println("Error: " + e);
e.printStackTrace();
}
// Créer et installer le gestionnaire de sécurité.
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
try {
Naming.rebind("rmi://" + "localhost:5000/POLYPAYPAL", this);
connectCreditCheck();
} catch (RemoteException e1) {
e1.printStackTrace();
System.out.println("Serveur POLYPAYPAL ne peut etre lance.");
System.out.println("Veuillez reessayer la connection ulterieurement");
System.exit(0);
} catch (MalformedURLException e) {
e.printStackTrace();
System.out.println("Serveur POLYPAYPAL ne peut etre lance.");
System.out.println("Veuillez reessayer la connection ulterieurement");
System.exit(0);
}
}
/**
* Fonction permettant à un client de se connecter au serveur PolyPayPal
*
* @param InterfaceClient - l'interface du client voulant se connecter
* @return double - Valeur du credit du client, -1 si le client n'a plus d'argent
*/
public float connect(String c) throws RemoteException {
float f = remoteCreditCheck.getClientCredit(c);
if(f>0){
//mesClients.put(c.toString());
return remoteCreditCheck.getClientCredit(c);} else
return -1;
}
public void disconnect(String c) throws RemoteException {
}
public InterfacePolyEbay getEbay() throws RemoteException {
return remoteEbay;
}
public void setEbay(InterfacePolyEbay ebay) throws RemoteException {
remoteEbay = ebay;
}
public float checkCredit(String c) throws RemoteException {
return(remoteCreditCheck.getClientCredit(c));
}
public float updateCredit(String c, float d) throws RemoteException {
return remoteCreditCheck.updateClientCredit(c,d);
}
public static void main(String args[]) {
try {
if(args[0]!=null)
ipCreditCheck = args[0];
new ImplPolyPaypal();
} catch (RemoteException ex) {
ex.printStackTrace();
}
}
private void connectCreditCheck() {
try {
System.out.println("Connection @ " + ipCreditCheck);
remoteCreditCheck = (InterfaceCreditCheck) Naming.lookup("//" + ipCreditCheck + ":4600" + "/" + "CREDITCHECK");
System.out.println("Connection au serveur CREDITCHECK etablie.");
}
catch (RemoteException ex) {
ex.printStackTrace();
} catch (MalformedURLException ex) {
ex.printStackTrace();
} catch (NotBoundException ex) {
ex.printStackTrace();
}
}
}