@Test void testFetchSegments() { tokenStore.initializeTokenSegments("processor1", 3); tokenStore.initializeTokenSegments("processor2", 1); assertArrayEquals(new int[]{0, 1, 2}, tokenStore.fetchSegments("processor1")); assertArrayEquals(new int[]{0}, tokenStore.fetchSegments("processor2")); assertArrayEquals(new int[0], tokenStore.fetchSegments("processor3")); }
@Override public int[] fetchSegments(String processorName) { ArrayList<Integer> segments = mongoTemplate.trackingTokensCollection() .find(eq("processorName", processorName)) .sort(ascending("segment")) .projection(fields(include("segment"), excludeId())) .map(d -> d.get("segment", Integer.class)) .into(new ArrayList<>()); int[] ints = new int[segments.size()]; for (int i = 0; i < ints.length; i++) { ints[i] = segments.get(i); } return ints; }
MongoTokenStore implements TokenStore { @Override public int[] fetchSegments(String processorName) { ArrayList<Integer> segments = mongoTemplate.trackingTokensCollection() .find(eq("processorName", processorName)) .sort(ascending("segment")) .projection(fields(include("segment"), excludeId())) .map(d -> d.get("segment", Integer.class)) .into(new ArrayList<>()); int[] ints = new int[segments.size()]; for (int i = 0; i < ints.length; i++) { ints[i] = segments.get(i); } return ints; } }
MongoTokenStore implements TokenStore { @Override public int[] fetchSegments(String processorName) { ArrayList<Integer> segments = mongoTemplate.trackingTokensCollection() .find(eq("processorName", processorName)) .sort(ascending("segment")) .projection(fields(include("segment"), excludeId())) .map(d -> d.get("segment", Integer.class)) .into(new ArrayList<>()); int[] ints = new int[segments.size()]; for (int i = 0; i < ints.length; i++) { ints[i] = segments.get(i); } return ints; } protected  MongoTokenStore(Builder builder); }
MongoTokenStore implements TokenStore { @Override public int[] fetchSegments(String processorName) { ArrayList<Integer> segments = mongoTemplate.trackingTokensCollection() .find(eq("processorName", processorName)) .sort(ascending("segment")) .projection(fields(include("segment"), excludeId())) .map(d -> d.get("segment", Integer.class)) .into(new ArrayList<>()); int[] ints = new int[segments.size()]; for (int i = 0; i < ints.length; i++) { ints[i] = segments.get(i); } return ints; } protected  MongoTokenStore(Builder builder); static Builder builder(); @Override void storeToken(TrackingToken token, String processorName, int segment); @Override void initializeTokenSegments(String processorName, int segmentCount); @Override void initializeTokenSegments(String processorName,
                                        int segmentCount,
                                        TrackingToken initialToken); @Override TrackingToken fetchToken(String processorName, int segment); @Override void extendClaim(String processorName, int segment); @Override void releaseClaim(String processorName, int segment); @Override void initializeSegment(TrackingToken token,
                                  String processorName,
                                  int segment); @Override void deleteToken(String processorName, int segment); @Override boolean requiresExplicitSegmentInitialization(); @Override int[] fetchSegments(String processorName); @Deprecated void ensureIndexes(); }
MongoTokenStore implements TokenStore { @Override public int[] fetchSegments(String processorName) { ArrayList<Integer> segments = mongoTemplate.trackingTokensCollection() .find(eq("processorName", processorName)) .sort(ascending("segment")) .projection(fields(include("segment"), excludeId())) .map(d -> d.get("segment", Integer.class)) .into(new ArrayList<>()); int[] ints = new int[segments.size()]; for (int i = 0; i < ints.length; i++) { ints[i] = segments.get(i); } return ints; } protected  MongoTokenStore(Builder builder); static Builder builder(); @Override void storeToken(TrackingToken token, String processorName, int segment); @Override void initializeTokenSegments(String processorName, int segmentCount); @Override void initializeTokenSegments(String processorName,
                                        int segmentCount,
                                        TrackingToken initialToken); @Override TrackingToken fetchToken(String processorName, int segment); @Override void extendClaim(String processorName, int segment); @Override void releaseClaim(String processorName, int segment); @Override void initializeSegment(TrackingToken token,
                                  String processorName,
                                  int segment); @Override void deleteToken(String processorName, int segment); @Override boolean requiresExplicitSegmentInitialization(); @Override int[] fetchSegments(String processorName); @Deprecated void ensureIndexes();  }