Skip to content

Commit 7776f84

Browse files
committed
moved era calculation to a central (algebra) class.
1 parent 1c06d2d commit 7776f84

6 files changed

Lines changed: 25 additions & 24 deletions

File tree

src/net/sharksystem/asap/ASAP.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package net.sharksystem.asap;
2+
3+
public class ASAP {
4+
public static int nextEra(int workingEra) {
5+
if(workingEra == Integer.MAX_VALUE) {
6+
return 0;
7+
}
8+
9+
return workingEra+1;
10+
}
11+
12+
public static int previousEra(int workingEra) {
13+
if(workingEra == 0) {
14+
return Integer.MAX_VALUE;
15+
}
16+
17+
return workingEra-1;
18+
}
19+
}

src/net/sharksystem/asap/ASAPChunkStorageFS.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public ASAPMessages getASAPChunkCache(CharSequence uri, int toEra) throws IOExce
131131
// go back 1000 eras
132132
int fromEra = toEra;
133133
for(int i = 0; i < 1000; i++) {
134-
fromEra = ASAPEngine.previousEra(fromEra);
134+
fromEra = ASAP.previousEra(fromEra);
135135
}
136136

137137
return this.getASAPChunkCache(uri, fromEra, toEra);

src/net/sharksystem/asap/ASAPEngine.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -678,30 +678,14 @@ public void setDropDeliveredChunks(boolean drop) throws IOException {
678678
this.saveStatus();
679679
}
680680

681-
static int nextEra(int workingEra) {
682-
if(workingEra == Integer.MAX_VALUE) {
683-
return 0;
684-
}
685-
686-
return workingEra+1;
687-
}
688-
689681
@Override
690682
public int getNextEra(int workingEra) {
691-
return ASAPEngine.nextEra(workingEra);
683+
return ASAP.nextEra(workingEra);
692684
}
693685

694-
static int previousEra(int workingEra) {
695-
if(workingEra == 0) {
696-
return Integer.MAX_VALUE;
697-
}
698-
699-
return workingEra-1;
700-
}
701-
702686
@Override
703687
public int getPreviousEra(int workingEra) {
704-
return ASAPEngine.previousEra(workingEra);
688+
return ASAP.previousEra(workingEra);
705689
}
706690

707691
private int getEraStartSync(String peer) {

src/net/sharksystem/asap/ASAPInMemoMessages.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import net.sharksystem.asap.apps.ASAPMessages;
44
import net.sharksystem.asap.util.Log;
5-
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
65

76
import java.io.IOException;
87
import java.util.ArrayList;
@@ -89,7 +88,7 @@ private void syncChunkList() throws IOException {
8988
if (finalLoop) {
9089
anotherLoop = false;
9190
} else {
92-
thisEra = ASAPEngine.nextEra(thisEra);
91+
thisEra = ASAP.nextEra(thisEra);
9392
finalLoop = thisEra == this.toEra;
9493
}
9594
}

src/net/sharksystem/asap/MultiASAPEngineFS_Impl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,6 @@ public void sendOnlineASAPAssimilateMessage(CharSequence format, CharSequence ur
513513
asapOnlineMessageSender.sendASAPAssimilateMessage(format, urlTarget, recipients, messageAsBytes, era);
514514
}
515515

516-
517516
private Collection<ASAPEngine> getEngines() {
518517
Collection<ASAPEngine> engineList = new ArrayList<>();
519518

test/net/sharksystem/asap/Point2PointTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ public void usageWithImmediateSync() throws IOException, ASAPException, Interrup
431431
Assert.assertEquals(BOB2ALICE_MESSAGE, aliceReceivedMessage);
432432

433433
// #2 is in another era
434-
aliceReceivedChunk = aliceIncomingBobStorage.getChunk(ALICE_BOB_CHAT_URL, ASAPEngine.nextEra(bobInitialEra));
434+
aliceReceivedChunk = aliceIncomingBobStorage.getChunk(ALICE_BOB_CHAT_URL, ASAP.nextEra(bobInitialEra));
435435
aliceReceivedMessages = aliceReceivedChunk.getMessages();
436436
aliceReceivedMessage = aliceReceivedMessages.next();
437437
Assert.assertEquals(BOB2ALICE_MESSAGE2, aliceReceivedMessage);
@@ -446,7 +446,7 @@ public void usageWithImmediateSync() throws IOException, ASAPException, Interrup
446446
Assert.assertEquals(ALICE2BOB_MESSAGE, bobReceivedMessage);
447447

448448
// #2 - in next era
449-
bobReceivedChunk = bobIncomingAliceStorage.getChunk(ALICE_BOB_CHAT_URL, ASAPEngine.nextEra(aliceInitialEra));
449+
bobReceivedChunk = bobIncomingAliceStorage.getChunk(ALICE_BOB_CHAT_URL, ASAP.nextEra(aliceInitialEra));
450450
bobReceivedMessages = bobReceivedChunk.getMessages();
451451
bobReceivedMessage = bobReceivedMessages.next();
452452
Assert.assertEquals(ALICE2BOB_MESSAGE2, bobReceivedMessage);

0 commit comments

Comments
 (0)