Skip to content

Commit 7c10ad4

Browse files
committed
working on better hub integration in shark messenger.
1 parent b45d18b commit 7c10ad4

File tree

6 files changed

+35
-3
lines changed

6 files changed

+35
-3
lines changed

src/main/java/net/sharksystem/hub/HubConnectionManager.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.sharksystem.hub;
22

33
import net.sharksystem.SharkException;
4+
import net.sharksystem.hub.peerside.HubConnector;
45
import net.sharksystem.hub.peerside.HubConnectorDescription;
56

67
import java.io.IOException;
@@ -39,6 +40,14 @@ public interface HubConnectionManager {
3940
List<HubConnectorDescription> getConnectedHubs();
4041
List<FailedConnectionAttempt> getFailedConnectionAttempts();
4142

43+
/**
44+
* Produce a hub connector by its description
45+
* @param hcd
46+
* @return
47+
* @throws SharkException if no connection exists
48+
*/
49+
HubConnector getHubConnector(HubConnectorDescription hcd) throws SharkException;
50+
4251
interface FailedConnectionAttempt {
4352
HubConnectorDescription getHubConnectorDescription();
4453
long getTimeStamp();

src/main/java/net/sharksystem/hub/HubConnectionManagerImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import net.sharksystem.asap.ASAPEncounterManager;
55
import net.sharksystem.asap.ASAPPeer;
66
import net.sharksystem.hub.peerside.ASAPHubManagerImpl;
7+
import net.sharksystem.hub.peerside.HubConnector;
78
import net.sharksystem.hub.peerside.HubConnectorDescription;
89

910
import java.io.IOException;
@@ -33,6 +34,11 @@ public void disconnectHub(HubConnectorDescription hcd) throws SharkException, IO
3334
this.connectionChanged(hcd, false);
3435
}
3536

37+
@Override
38+
public HubConnector getHubConnector(HubConnectorDescription hcd) throws SharkException {
39+
return this.hubManager.getHubConnector(hcd);
40+
}
41+
3642
public HubConnectionManagerImpl(ASAPEncounterManager encounterManager, ASAPPeer asapPeer) {
3743
this.asapPeer = asapPeer;
3844
this.hubManager = new ASAPHubManagerImpl(encounterManager);

src/main/java/net/sharksystem/hub/peerside/ASAPHubManager.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.sharksystem.hub.peerside;
22

3+
import net.sharksystem.SharkException;
34
import net.sharksystem.asap.ASAPPeer;
45

56
import java.util.Collection;
@@ -30,6 +31,14 @@ public interface ASAPHubManager {
3031
*/
3132
void connectASAPHubs(Collection<HubConnectorDescription> descriptions, ASAPPeer asapPeer, boolean killNotDescribed);
3233

34+
/**
35+
* Produce a hub connector by its description
36+
* @param hcd
37+
* @return
38+
* @throws SharkException if no connection exists
39+
*/
40+
HubConnector getHubConnector(HubConnectorDescription hcd) throws SharkException;
41+
3342
/**
3443
* Produce a list of running connections. Note: Chronologically order can change after each call.
3544
* @return

src/main/java/net/sharksystem/hub/peerside/ASAPHubManagerImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.sharksystem.hub.peerside;
22

3+
import net.sharksystem.SharkException;
34
import net.sharksystem.asap.*;
45
import net.sharksystem.hub.Connector;
56
import net.sharksystem.utils.AlarmClock;
@@ -126,6 +127,14 @@ public synchronized List<HubConnectorDescription> getRunningConnectorDescription
126127
return this.runningConnectorDescriptions;
127128
}
128129

130+
public HubConnector getHubConnector(HubConnectorDescription hcd) throws SharkException {
131+
for(HubConnector runningHc : this.hubConnectors) {
132+
if(runningHc.isSame(hcd)) return runningHc;
133+
}
134+
135+
throw new SharkException("no connection to described hub available");
136+
}
137+
129138
public void connectASAPHubs(Collection<HubConnectorDescription> descriptions,
130139
ASAPPeer asapPeer, boolean killNotDescribed) {
131140
// for each description

src/main/java/net/sharksystem/hub/peerside/HubTester.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import net.sharksystem.SharkException;
44
import net.sharksystem.asap.*;
55
import net.sharksystem.asap.apps.testsupport.ASAPTestPeerFS;
6+
import net.sharksystem.fs.FSUtils;
67
import net.sharksystem.hub.HubConnectionManager;
78
import net.sharksystem.hub.HubConnectionManagerImpl;
8-
import net.sharksystem.utils.fs.FSUtils;
99

1010
import java.io.FileNotFoundException;
1111
import java.io.IOException;

src/test/java/net/sharksystem/hub/HubUsageTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
import net.sharksystem.asap.ASAPEncounterManagerImpl;
55
import net.sharksystem.asap.ASAPException;
66
import net.sharksystem.asap.apps.testsupport.ASAPTestPeerFS;
7-
import net.sharksystem.asap.engine.ASAPEngineFS;
7+
import net.sharksystem.fs.FSUtils;
88
import net.sharksystem.hub.peerside.*;
99
import net.sharksystem.hub.hubside.ASAPTCPHub;
10-
import net.sharksystem.utils.fs.FSUtils;
1110
import net.sharksystem.utils.testsupport.TestHelper;
1211
import org.junit.Assert;
1312
import org.junit.Test;

0 commit comments

Comments
 (0)