|
2 | 2 |
|
3 | 3 | import net.sharksystem.SharkException;
|
4 | 4 | import net.sharksystem.asap.*;
|
5 |
| -import net.sharksystem.hub.Connector; |
| 5 | +import net.sharksystem.hub.*; |
6 | 6 | import net.sharksystem.utils.AlarmClock;
|
7 | 7 | import net.sharksystem.utils.AlarmClockListener;
|
8 | 8 | import net.sharksystem.utils.Log;
|
|
11 | 11 | import java.io.IOException;
|
12 | 12 | import java.util.*;
|
13 | 13 |
|
14 |
| -public class ASAPHubManagerImpl implements ASAPHubManager, Runnable, NewConnectionListener, AlarmClockListener, |
| 14 | +public class ASAPHubManagerImpl implements ASAPHubManager, NewHubConnectionListenerManagement, |
| 15 | + Runnable, NewConnectionListener, AlarmClockListener, |
15 | 16 | HubConnectorStatusListener {
|
16 | 17 | private static final int FORCE_NEW_ROUND_KEY = 1;
|
17 | 18 | private final ASAPEncounterManager asapEncounterManager;
|
@@ -135,6 +136,29 @@ public HubConnector getHubConnector(HubConnectorDescription hcd) throws SharkExc
|
135 | 136 | throw new SharkException("no connection to described hub available");
|
136 | 137 | }
|
137 | 138 |
|
| 139 | + //////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 140 | + // new hub connector listener management // |
| 141 | + //////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 142 | + private Set<NewHubConnectedListener> connectedHubListenerList = new HashSet<>(); |
| 143 | + public void addNewConnectedHubListener(NewHubConnectedListener connectedHubListener) { |
| 144 | + this.connectedHubListenerList.add(connectedHubListener); |
| 145 | + } |
| 146 | + |
| 147 | + public void removeNewConnectedHubListener(NewHubConnectedListener connectedHubListener) { |
| 148 | + this.connectedHubListenerList.remove(connectedHubListener); |
| 149 | + } |
| 150 | + |
| 151 | + private void notifyNewHubConnectionListener(HubConnectorDescription hcd) { |
| 152 | + for(NewHubConnectedListener connectedHubListener : this.connectedHubListenerList) { |
| 153 | + connectedHubListener.newHubConnected(hcd); |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + private void hubConnectorStarted(HubConnectorDescription hcd) { |
| 158 | + this.runningConnectorDescriptions.add(hcd); |
| 159 | + this.notifyNewHubConnectionListener(hcd); |
| 160 | + } |
| 161 | + |
138 | 162 | public void connectASAPHubs(Collection<HubConnectorDescription> descriptions,
|
139 | 163 | ASAPPeer asapPeer, boolean killConnectionIfNotInList) {
|
140 | 164 | // for each description
|
@@ -164,7 +188,8 @@ public void run() {
|
164 | 188 | Log.writeLog(ASAPHubManagerImpl.this,ASAPHubManagerImpl.this.toString(),
|
165 | 189 | "hub connector initialized: " + hcd);
|
166 | 190 | // remember - it is running now
|
167 |
| - ASAPHubManagerImpl.this.runningConnectorDescriptions.add(hcd); |
| 191 | +// ASAPHubManagerImpl.this.runningConnectorDescriptions.add(hcd); |
| 192 | + ASAPHubManagerImpl.this.hubConnectorStarted(hcd); |
168 | 193 | } catch (IOException | ASAPException e) {
|
169 | 194 | Log.writeLog(ASAPHubManagerImpl.this,ASAPHubManagerImpl.this.toString(),
|
170 | 195 | "cannot create hub connector: " + e.getLocalizedMessage());
|
|
0 commit comments