|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| package com.agical.rmock.core.hub; |
|
5 |
| |
|
6 |
| import java.util.ArrayList; |
|
7 |
| import java.util.Iterator; |
|
8 |
| import java.util.List; |
|
9 |
| |
|
10 |
| class MultiplexingProxyConnectionPoint implements ConnectionPoint { |
|
11 |
| private final Class consumableInterface; |
|
12 |
| private final List consumables; |
|
13 |
| private final List consumers; |
|
14 |
| private final ConnectionStrategy assigner; |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
276
| public MultiplexingProxyConnectionPoint(Class consumableInterface, ConnectionStrategy assigner){
|
|
19 |
276
| super();
|
|
20 |
276
| this.consumableInterface = consumableInterface;
|
|
21 |
276
| this.assigner = assigner;
|
|
22 |
276
| this.consumers = new ArrayList();
|
|
23 |
276
| this.consumables = new ArrayList();
|
|
24 |
| } |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
12146
| public void disconnectConsumable(Object consumable) {
|
|
30 |
12146
| this.consumables.remove(consumable);
|
|
31 |
12146
| for (Iterator iter = consumers.iterator(); iter.hasNext();) {
|
|
32 |
8153
| Object consumer = (Object) iter.next();
|
|
33 |
8153
| assigner.disconnectFromConsumer(consumer, consumable);
|
|
34 |
| } |
|
35 |
| } |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
8971
| public void connectConsumable(Object consumable) {
|
|
41 |
8971
| for (Iterator iter = consumers.iterator(); iter.hasNext();) {
|
|
42 |
1648
| Object consumer = (Object) iter.next();
|
|
43 |
1648
| assigner.connectToConsumer(consumer, consumable);
|
|
44 |
| } |
|
45 |
8971
| this.consumables.add(consumable);
|
|
46 |
| |
|
47 |
| } |
|
48 |
| |
|
49 |
10491
| public void connectConsumer(Object consumer) {
|
|
50 |
10491
| for (Iterator iter = consumables.iterator(); iter.hasNext();) {
|
|
51 |
13148
| Object consumable = (Object) iter.next();
|
|
52 |
13148
| assigner.connectToConsumer(consumer, consumable);
|
|
53 |
| } |
|
54 |
10491
| consumers.add(consumer);
|
|
55 |
| } |
|
56 |
| |
|
57 |
12663
| public void disconnectConsumer(Object consumer) {
|
|
58 |
12663
| consumers.remove(consumer);
|
|
59 |
12663
| for (Iterator iter = consumables.iterator(); iter.hasNext();) {
|
|
60 |
11207
| Object consumable = (Object) iter.next();
|
|
61 |
11207
| assigner.disconnectFromConsumer(consumer, consumable);
|
|
62 |
| } |
|
63 |
| } |
|
64 |
| } |