11package net .sharksystem .asap ;
22
3+ import net .sharksystem .Utils ;
34import net .sharksystem .asap .apps .ASAPMessages ;
45import net .sharksystem .asap .util .Log ;
56
67import java .io .IOException ;
7- import java .util .ArrayList ;
8- import java .util .Iterator ;
9- import java .util .List ;
10- import java .util .NoSuchElementException ;
8+ import java .util .*;
119
1210/**
1311 * @author thsc
@@ -40,9 +38,13 @@ public ASAPInMemoMessages(ASAPChunkStorageFS chunkStorage,
4038 this .toEra = toEra ;
4139 this .maxCacheLen = maxCacheLen ;
4240
43- Log .writeLog (this , "format: " + format + " | uri: " + uri
41+ Log .writeLog (this , this .toString ());
42+ }
43+
44+ public String toString () {
45+ return "format: " + format + " | uri: " + uri
4446 + " | rootDir: " + chunkStorage .getRootDirectory ()
45- + " | fromEra: " + fromEra + " | toEra: " + toEra ) ;
47+ + " | fromEra: " + fromEra + " | toEra: " + toEra ;
4648 }
4749
4850 public ASAPInMemoMessages (ASAPChunkStorageFS chunkStorage ,
@@ -59,31 +61,42 @@ private void initialize() throws IOException {
5961 this .initialized = true ;
6062 }
6163 }
62-
64+
6365 private void syncChunkList () throws IOException {
6466 // get all chunks in chronological order
65-
67+ Collection <Integer > erasInFolder = Utils .getErasInFolder (this .chunkStorage .getRootDirectory ());
68+ if (erasInFolder .isEmpty ()) return ;
69+
70+ Collection <Integer > erasToUse = Utils .getErasInRange (erasInFolder , this .fromEra , this .toEra );
71+ if (erasToUse .isEmpty ()) return ;
72+
73+ /*
6674 // current era in following loop
6775 int thisEra = this.fromEra;
68-
76+
6977 // do we need more than one loop?
7078 boolean anotherLoop = this.fromEra != this.toEra;
7179
7280 // are we in the final loop?
7381 boolean finalLoop = !anotherLoop;
82+ */
7483
7584 // drop old vunk list - if any
7685 this .chunkList = new ArrayList <>();
7786
78- do {
87+ // do {
88+ for (Integer thisEra : erasToUse ) {
7989 // check if chunk exists - don't create on
80- if (this .chunkStorage .existsChunk (this .uri , thisEra )) {
90+ Log .writeLog (this , "reached era: " + thisEra );
91+ if (erasInFolder .contains (thisEra ) && this .chunkStorage .existsChunk (this .uri , thisEra )) {
8192 // is there - get it
93+ Log .writeLog (this , "getChunk with era: " + thisEra );
8294 ASAPChunk chunk = this .chunkStorage .getChunk (this .uri , thisEra );
8395 this .chunkList .add (chunk );
8496 this .numberOfMessages += chunk .getNumberMessage ();
8597 }
8698
99+ /*
87100 if (anotherLoop) {
88101 if (finalLoop) {
89102 anotherLoop = false;
@@ -93,6 +106,8 @@ private void syncChunkList() throws IOException {
93106 }
94107 }
95108 } while (anotherLoop);
109+ */
110+ }
96111 }
97112
98113 public int size () throws IOException {
0 commit comments