-
Notifications
You must be signed in to change notification settings - Fork 0
/
BrokerImpl.java
101 lines (92 loc) · 2.78 KB
/
BrokerImpl.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
/**
* Class Implementing Stocks of the Share Market
*
* @author Yoan Ribeiro
*/
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.Naming;
import java.rmi.RMISecurityManager;
import java.util.Map;
import java.util.HashMap;
public class BrokerImpl extends UnicastRemoteObject implements Broker
{
public Map <String, Stock> market;
public StockFactoryManager manager;
public BrokerImpl( StockFactoryManager manager ) throws RemoteException
{
// Where all the Stocks are stored
this.market = new HashMap< String, Stock >();
// With Remote factorys responsable for creating Stock objects
this.manager = manager;
}
/**
* Method responsable for retreving the Stock corresponding to the given symbol
* @param String Symbol
* @return Stock object.
* @exception RemoteException.
* @see IOException
*/
/*
*/
public Stock lookup ( String symbol ) throws RemoteException
{
synchronized(this.market)
{
Stock s = market.get( symbol );
if( s == null )
{
try
{
s = manager.create( );
}
catch (Exception e) { System.out.println("exception: " + e.getMessage()); }
market.put( symbol, s );
return s;
}
else
return s;
}
}
/**
* Without factorys
public Stock lookup ( String symbol )
{
synchronized(this.market)
{
Stock s = market.get( symbol );
if( s == null )
{
try
{
s = new StockImpl();
}
catch (Exception e) { System.out.println("exception: " + e.getMessage()); }
market.put( symbol, s );
return s;
}
else
return s;
}
}
*/
/*
public BrokerImpl( ) throws RemoteException { }
public synchronized Stock lookup ( String symbol )
{
if (System.getSecurityManager() == null)
System.setSecurityManager(new RMISecurityManager());
try
{
Stock s = (Stock)Naming.lookup( symbol );
if( s == null )
{
s = new StockImpl();
Naming.rebind("//localhost/"+symbol, s);
return s;
}
else
return s;
} catch (Exception e) { System.out.println("exception: " + e.getMessage()); }
}*/
}