1 package rydeen;
2
3 import java.util.Collections;
4 import java.util.Iterator;
5 import java.util.LinkedHashMap;
6 import java.util.Map;
7
8 import rydeen.spi.ProcessorService;
9
10
11
12
13
14
15
16 public class ProcessorServicePool implements Iterable<ProcessorService>{
17 private Map<String, ProcessorService> services = new LinkedHashMap<String, ProcessorService>();
18
19
20
21
22 public ProcessorServicePool(){
23 }
24
25
26
27
28
29 public ProcessorServicePool(ProcessorServicePool pool){
30 services.putAll(pool.services);
31 }
32
33
34
35
36 @Override
37 public Iterator<ProcessorService> iterator(){
38 return Collections.unmodifiableCollection(services.values()).iterator();
39 }
40
41
42
43
44
45
46
47
48
49
50
51 public void addProvider(ProcessorService service){
52 services.put(service.getProcessorName(), service);
53 }
54
55
56
57
58
59
60
61
62
63 public boolean contains(String processorName){
64 return services.containsKey(processorName);
65 }
66
67
68
69
70
71
72
73
74
75 public boolean contains(ProcessorService service){
76 return services.containsValue(service);
77 }
78
79
80
81
82
83
84
85
86
87
88
89 public boolean removeProvider(ProcessorService service){
90 return services.remove(service.getProcessorName()) != null;
91 }
92
93
94
95
96
97
98
99
100 public int getServiceCount(){
101 return services.size();
102 }
103
104
105
106
107
108
109
110
111
112 public ProcessorService getService(String processorName){
113 return services.get(processorName);
114 }
115 }