-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImplCreditCheck.java
93 lines (88 loc) · 3.13 KB
/
ImplCreditCheck.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
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
import java.util.Hashtable;
/*
* ImplCreditCheck.java
*
* Created on April 4, 2007, 10:46 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author Yann
*/
public class ImplCreditCheck extends UnicastRemoteObject implements InterfaceCreditCheck{
private Hashtable<String, Float> mesClients = new Hashtable<String, Float>();
private ImplCreditCheck serveurCreditCheck;
/**
* Creates a new instance of ImplCreditCheck
*
* The ImplCreditCheck can be later used to verify credit of a client
*
* @param void
*/
public ImplCreditCheck() throws RemoteException {
//Mise en marche du CreditCheck
try{
java.rmi.registry.LocateRegistry.createRegistry(4600);
System.out.println("Registre cree sur le port 4600 pour CreditCheck");
java.rmi.registry.Registry reg = java.rmi.registry.LocateRegistry.getRegistry(4600);
System.out.println("Registre du port 4600 utilise par CreditCheck");
// Créer et installer le gestionnaire de sécurité.
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
Naming.rebind("rmi://" + "localhost:4600" + "/" + "CREDITCHECK", this);
System.out.println("Serveur CREDITCHECK est pret.");
} catch (Exception e1) {
e1.printStackTrace();
System.out.println("Probleme d'initialisation du serveur CreditCheck.");
}
for(int i = 0; i<3; i++)
mesClients.put("Client"+i,new Float(50.0));
}
/**
* Returns the credit of specified client
*
*
* @param String c - the name of the client
* @return float - the value of the client's credit
*/
public float getClientCredit(String c) throws RemoteException {
System.out.println("Verification du credit du client " + c + " : " + mesClients.get(c).floatValue());
return (mesClients.get(c)).floatValue();
}
/**
* Updates the credit of specified client
*
*
* @param float d - the variation of the client's credit
* @return void
*/
public synchronized float updateClientCredit(String c, float d) throws RemoteException{
float a, f = mesClients.get(c);
a = f;
if(d > f)
{
System.out.println("Client " + c + " : mise illegale. Mise de " + d + " avec credit de " + f + "." );
System.out.println("Client " + c + " : Penalite de 10$." );
f-=10;
}
else
{
f -= d;
}
mesClients.put(c, new Float(f));
System.out.println("Mise a jour du credit du client " + c + " : " + a + " -> " + mesClients.get(c).floatValue());
return mesClients.get(c).floatValue();
}
public static void main(String args[]) {
try {
new ImplCreditCheck();
} catch (RemoteException ex) {
ex.printStackTrace();
}
}
}