Skip to content

Commit 4ae5f29

Browse files
committed
working on better integration in SNM.
1 parent 6fe24f0 commit 4ae5f29

File tree

8 files changed

+78
-15
lines changed

8 files changed

+78
-15
lines changed

makeASAPHubJar.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cd target/classes/
1+
cd out/production/main/
22
jar -cvf ASAPHub.jar net
3-
mv ASAPHub.jar ../../ASAPHub.jar
4-
cd ../../
3+
mv ASAPHub.jar ../../../ASAPHub.jar
4+
cd ../../../

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ public abstract class BasicHubConnectionManager implements HubConnectionManager
2626

2727
private long lastSync = System.currentTimeMillis();
2828

29-
public long getLastSyncTime() {
30-
return this.lastSync;
31-
}
32-
3329
/**
3430
* Hub manager can be asked to connect to or disconnect from hubs. We send a list of hubs which are to be
3531
* connected. Connection establishment can take a while, though. It is a wish list on application side for a while.

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@ public interface HubConnectionManager extends NewHubConnectionListenerManagement
1919

2020
/**
2121
*
22-
* @return time when last sync with hubs happened.
22+
* @return time when last sync with hubs happened. Is -1 if never synced
2323
*/
2424
long getLastSyncTime();
2525

26+
/**
27+
* Force a new synchronization with all connected hubs. Use this method carefully. We do not want
28+
* to produce unnecessary traffic.
29+
*/
30+
void forceSync();
31+
2632
/**
2733
* Connect a hub
2834
* @param hcd Hub description

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ public void removeNewConnectedHubListener(NewHubConnectedListener connectedHubLi
6767
}
6868
}
6969

70+
public long getLastSyncTime() {
71+
if(this.hubManager == null) return -1;
72+
return this.hubManager.getLastSynchedWithConnectedHubs();
73+
}
74+
75+
public void forceSync() {
76+
if(this.hubManager != null) {
77+
this.hubManager.forceSyncWithHubs();
78+
}
79+
}
80+
7081
public HubConnectionManagerImpl(
7182
ASAPEncounterManager encounterManager, ASAPPeer asapPeer, int waitIntervalInSeconds) {
7283
this.asapPeer = asapPeer;

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ public void removeHub(HubConnector hubConnector) {
8484
*/
8585
private void forceNewRound() {
8686
if(this.alarmClock != null) {
87-
Log.writeLog(this, this.toString(), "kill old alarm");
87+
//Log.writeLog(this, this.toString(), "kill old alarm");
8888
this.alarmClock.kill();
8989
}
90-
Log.writeLog(this, this.toString(), "set new alarm");
90+
//Log.writeLog(this, this.toString(), "set new alarm");
9191
this.alarmClock = new AlarmClock(forceNewRoundWaitingPeriod, FORCE_NEW_ROUND_KEY, this);
9292
this.alarmClock.start();
9393
}
@@ -260,14 +260,21 @@ public void forceSyncWithHubs() {
260260

261261
private boolean managerThreadStopped = false;
262262

263+
private long lastSyncStatusWithConnectedHubs = -1;
264+
265+
public long getLastSynchedWithConnectedHubs() {
266+
return this.lastSyncStatusWithConnectedHubs;
267+
}
268+
263269
@Override
264270
public void run() {
265271
this.managerThread = Thread.currentThread();
266272
Log.writeLog(this, this.toString(), "hub manager thread started");
267273

268274
while (!this.managerThreadStopped) {
269-
Log.writeLog(this, this.toString(),"start a new round");
275+
Log.writeLog(this, this.toString(),"start a new sync round");
270276

277+
this.lastSyncStatusWithConnectedHubs = System.currentTimeMillis();
271278
for(HubConnector hubConnector : this.hubConnectors) {
272279
Log.writeLog(this, this.toString(), "check hub connection");
273280
hubConnector.addStatusListener(this);
@@ -288,7 +295,7 @@ public void run() {
288295
Thread.sleep(sleepingTime);
289296
} catch (InterruptedException e) {
290297
if(!this.managerThreadStopped) {
291-
Log.writeLog(this, this.toString(), "interrupted - make next round earlier");
298+
Log.writeLog(this, this.toString(), "interrupted - make next sync round now");
292299
}
293300
}
294301
}

src/main/main.iml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/java" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="library" name="ASAPJava" level="project" />
11+
<orderEntry type="module" module-name="test" />
12+
</component>
13+
</module>

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
import org.junit.Test;
1414

1515
import java.io.IOException;
16-
import java.util.ArrayList;
17-
import java.util.Arrays;
18-
import java.util.Collection;
1916
import java.util.Collections;
2017

2118
import static net.sharksystem.hub.TestConstants.*;

src/test/test.iml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/java" isTestSource="true" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="library" name="ASAPJava" level="project" />
11+
<orderEntry type="module" module-name="main" />
12+
<orderEntry type="module-library" scope="TEST">
13+
<library name="JUnit4">
14+
<CLASSES>
15+
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.13.1/junit-4.13.1.jar!/" />
16+
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
17+
</CLASSES>
18+
<JAVADOC />
19+
<SOURCES />
20+
</library>
21+
</orderEntry>
22+
<orderEntry type="module-library" scope="TEST">
23+
<library name="JUnit4">
24+
<CLASSES>
25+
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.13.1/junit-4.13.1.jar!/" />
26+
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
27+
</CLASSES>
28+
<JAVADOC />
29+
<SOURCES />
30+
</library>
31+
</orderEntry>
32+
</component>
33+
</module>

0 commit comments

Comments
 (0)