View Javadoc

1   package org.catacomb.druid.market;
2   
3   import org.catacomb.interlish.structure.*;
4   import org.catacomb.interlish.util.JUtil;
5   
6   import java.util.HashMap;
7   
8   
9   
10  public class HookupBoard implements Marketplace {
11  
12      static HookupBoard globalBoard;
13      static int nextBoardNo = 0;
14  
15      String id;
16  
17      HashMap<String, ProducerConsumerBoard> boards;
18  
19  
20      public HookupBoard() {
21          boards = new HashMap<String, ProducerConsumerBoard>();
22          nextBoardNo += 1;
23          id = "HB_" + nextBoardNo;
24      }
25  
26      public String toString() {
27          return "Mkt " + id;
28      }
29  
30  
31  
32      public Marketplace global() {
33          if (globalBoard == null) {
34              globalBoard = new HookupBoard();
35  //         E.info("made global board " + globalBoard);
36          }
37          return globalBoard;
38      }
39  
40  
41      public void addProducer(String modality, Producer p, String flavor) {
42          getPCBoard(modality).addProducer(p, flavor);
43      }
44  
45  
46      public void addConsumer(String modality, Consumer c, String flavor) {
47          getPCBoard(modality).addConsumer(c, flavor);
48      }
49  
50  
51      public void addProvider(String modality, Provider p, String flavor) {
52          getPCBoard(modality).addProvider(p, flavor);
53      }
54  
55  
56  
57      public void addReceiver(String modality, Receiver rec, String flavor) {
58          getPCBoard(modality).addReceiver(rec, flavor);
59      }
60  
61  
62      // supplier will get you the flavor you ask for
63      public void addSupplier(String modality, Supplier sup) {
64          getPCBoard(modality).addSupplier(sup);
65      }
66  
67  
68  
69      public void addVisible(String modality, Visible vbl, String flavor) {
70          getPCBoard(modality).addVisible(vbl, flavor);
71      }
72  
73  
74      public void addViewer(String modality, Viewer vwr, String flavor) {
75          getPCBoard(modality).addViewer(vwr, flavor);
76      }
77  
78  
79  
80      private ProducerConsumerBoard getPCBoard(String modality) {
81          ProducerConsumerBoard ret = null;
82  
83          if (boards.containsKey(modality)) {
84              ret = (boards.get(modality));
85  
86          } else {
87              ret = makePCBoard(modality);
88              //      E.info("made board " + modality);
89              boards.put(modality, ret);
90          }
91          return ret;
92      }
93  
94  
95  
96      private ProducerConsumerBoard makePCBoard(String modality) {
97          // TODO refac to direct class ref;
98          String scnm = "org.catacomb.druid.market." + modality + "Board";
99          Object ret = JUtil.newInstance(scnm);
100         ProducerConsumerBoard pcb = (ProducerConsumerBoard)ret;
101         pcb.setModality(modality);
102         return pcb;
103     }
104 
105 
106 
107     public void logUnresolved() {
108         if (boards != null) {
109             for (ProducerConsumerBoard pcb : boards.values()) {
110                 pcb.logUnresolved(id);
111             }
112         }
113     }
114 
115 
116 
117 }