2727import com .github .benmanes .caffeine .cache .*;
2828import elf4j .Level ;
2929import elf4j .Logger ;
30+ import jakarta .annotation .Nullable ;
3031import java .time .Duration ;
3132import java .util .*;
3233import java .util .stream .Collectors ;
33- import javax .annotation .Nullable ;
3434import javax .annotation .concurrent .NotThreadSafe ;
3535import javax .annotation .concurrent .ThreadSafe ;
3636import lombok .Data ;
@@ -48,7 +48,7 @@ public final class ChunkStitcher implements Stitcher {
4848 private static final int DEFAULT_MAX_STITCHED_BYTE_SIZE = Integer .MAX_VALUE ;
4949 private static final long DEFAULT_MAX_STITCHING_GROUPS = Long .MAX_VALUE ;
5050 private static final long DEFAULT_MAX_STITCH_TIME_NANOS = Long .MAX_VALUE ;
51- private static final Logger logger = Logger .instance ();
51+ private static final Logger log = Logger .instance ();
5252 private final Cache <UUID , ChunkStitchingGroup > chunkGroups ;
5353 private final Duration maxStitchTime ;
5454 private final int maxStitchedByteSize ;
@@ -80,8 +80,8 @@ private ChunkStitcher(@NonNull Builder builder) {
8080 * the group, or an empty Optional otherwise.
8181 */
8282 @ Override
83- public Optional <byte []> stitch (@ NonNull Chunk chunk ) {
84- logger . atTrace (). log (() -> "Received: " + chunk );
83+ public @ NonNull Optional <byte []> stitch (@ NonNull Chunk chunk ) {
84+ log . trace (() -> "Received: " + chunk );
8585 StitchedBytesHolder stitchedBytesHolder = new StitchedBytesHolder ();
8686 chunkGroups .asMap ().compute (chunk .groupId (), (k , group ) -> {
8787 if (group == null ) {
@@ -107,13 +107,11 @@ private void checkStitchingGroupByteSize(Chunk chunk, ChunkStitchingGroup group)
107107 return ;
108108 }
109109 if (chunk .bytes ().length + group .getCurrentGroupByteSize () > maxStitchedByteSize ) {
110- logger
111- .atWarn ()
112- .log (
113- "By adding {}, stitching group {} would have exceeded safe-guarding byte size {}" ,
114- chunk ,
115- chunk .groupId (),
116- maxStitchedByteSize );
110+ log .warn (
111+ "By adding {}, stitching group {} would have exceeded safe-guarding byte size {}" ,
112+ chunk ,
113+ chunk .groupId (),
114+ maxStitchedByteSize );
117115 throw new IllegalArgumentException ("Stitched bytes in group exceeding configured max size" );
118116 }
119117 }
@@ -239,13 +237,13 @@ private static int totalByteSizeOf(@NonNull Collection<Chunk> chunks) {
239237 * @return A byte array containing the stitched chunks if the chunk is the last one expected by
240238 * the group, or null otherwise.
241239 */
242- @ Nullable public byte [] addAndStitch (Chunk chunk ) {
240+ public @ Nullable byte [] addAndStitch (Chunk chunk ) {
243241 if (!chunks .add (chunk )) {
244- logger . atWarn (). log ("Duplicate chunk {} received and ignored" , chunk );
242+ log . warn ("Duplicate chunk {} received and ignored" , chunk );
245243 return null ;
246244 }
247245 if (getCurrentChunkTotal () == getExpectedChunkTotal ()) {
248- logger . atDebug (). log (() -> "Stitching all " + chunks .size () + " chunks in group " + this );
246+ log . debug (() -> "Stitching all " + chunks .size () + " chunks in group " + this );
249247 return stitchToBytes (chunks );
250248 }
251249 return null ;
@@ -328,22 +326,18 @@ public void onRemoval(
328326 UUID groupId , ChunkStitchingGroup chunkStitchingGroup , @ NonNull RemovalCause cause ) {
329327 switch (cause ) {
330328 case EXPIRED ->
331- logger
332- .atWarn ()
333- .log (
334- "chunk group [{}] took too long to stitch and expired after [{}], expecting [{}] chunks but only received [{}] when expired" ,
335- groupId ,
336- maxStitchTime ,
337- chunkStitchingGroup .getExpectedChunkTotal (),
338- chunkStitchingGroup .getCurrentChunkTotal ());
329+ log .warn (
330+ "chunk group [{}] took too long to stitch and expired after [{}], expecting [{}] chunks but only received [{}] when expired" ,
331+ groupId ,
332+ maxStitchTime ,
333+ chunkStitchingGroup .getExpectedChunkTotal (),
334+ chunkStitchingGroup .getCurrentChunkTotal ());
339335 case SIZE ->
340- logger
341- .atWarn ()
342- .log (
343- "chunk group [{}] was removed due to exceeding max group count [{}]" ,
344- groupId ,
345- maxStitchingGroups );
346- default -> logger .atLevel (Level .OFF ).log ("Manual removals logging is OFF" );
336+ log .warn (
337+ "chunk group [{}] was removed due to exceeding max group count [{}]" ,
338+ groupId ,
339+ maxStitchingGroups );
340+ default -> log .atLevel (Level .OFF ).log ("Manual removals logging is OFF" );
347341 }
348342 }
349343 }
0 commit comments