136136@ ApplicationScoped
137137public class RecordingHelper {
138138
139+ private static final int S3_API_PART_LIMIT = 10_000 ;
140+ private static final int MIB = 1024 * 1024 ;
141+
139142 public static final String JFR_MIME = HttpMimeType .JFR .mime ();
140143
141144 private static final Pattern TEMPLATE_PATTERN =
@@ -473,7 +476,7 @@ public Uni<ActiveRecording> createSnapshot(Target target) {
473476 try (InputStream snapshot =
474477 remoteRecordingStreamFactory .open (connection , target , desc )) {
475478 if (!snapshotIsReadable (target , snapshot )) {
476- connection . getService (). close ( desc );
479+ safeCloseRecording ( connection , desc );
477480 throw new SnapshotCreationException (
478481 "Snapshot was not readable - are there any source recordings?" );
479482 }
@@ -570,24 +573,20 @@ public Uni<ActiveRecording> stopRecording(ActiveRecording recording) throws Exce
570573 }
571574
572575 public Uni <ActiveRecording > deleteRecording (ActiveRecording recording ) {
573- var closed =
574- connectionManager .executeConnectedTask (
575- recording .target ,
576- conn -> {
577- var desc = getDescriptorById (conn , recording .remoteId );
578- if (desc .isEmpty ()) {
579- throw new NotFoundException ();
580- }
581- conn .getService ().close (desc .get ());
582- return recording ;
583- });
576+ connectionManager .executeConnectedTask (
577+ recording .target ,
578+ conn -> {
579+ getDescriptorById (conn , recording .remoteId )
580+ .ifPresent (d -> safeCloseRecording (conn , d ));
581+ return null ;
582+ });
584583 return QuarkusTransaction .joiningExisting ()
585584 .call (
586585 () -> {
587- closed .target .activeRecordings .remove (recording );
588- closed .target .persist ();
589- closed .delete ();
590- return Uni .createFrom ().item (closed );
586+ recording .target .activeRecordings .remove (recording );
587+ recording .target .persist ();
588+ recording .delete ();
589+ return Uni .createFrom ().item (recording );
591590 });
592591 }
593592
@@ -818,14 +817,13 @@ public ArchivedRecording archiveRecording(
818817 if (StringUtils .isBlank (savename )) {
819818 savename = filename ;
820819 }
821- int mib = 1024 * 1024 ;
822820 String key = archivedRecordingKey (recording .target .jvmId , filename );
823821 String multipartId = null ;
824822 List <Pair <Integer , String >> parts = new ArrayList <>();
825823 long accum = 0 ;
826824 try (var stream = getActiveInputStream (recording );
827825 var ch = Channels .newChannel (stream )) {
828- ByteBuffer buf = ByteBuffer .allocate (20 * mib );
826+ ByteBuffer buf = ByteBuffer .allocate (20 * MIB );
829827 CreateMultipartUploadRequest .Builder builder =
830828 CreateMultipartUploadRequest .builder ()
831829 .bucket (archiveBucket )
@@ -840,7 +838,7 @@ public ArchivedRecording archiveRecording(
840838 CreateMultipartUploadRequest request = builder .build ();
841839 multipartId = storage .createMultipartUpload (request ).uploadId ();
842840 int read = 0 ;
843- for (int i = 1 ; i <= 10_000 ; i ++) {
841+ for (int i = 1 ; i <= S3_API_PART_LIMIT ; i ++) {
844842 read = ch .read (buf );
845843
846844 if (read == 0 ) {
@@ -868,7 +866,7 @@ public ArchivedRecording archiveRecording(
868866 parts .add (Pair .of (i , eTag ));
869867 buf .clear ();
870868 // S3 API limit
871- if (i == 10_000 ) {
869+ if (i == S3_API_PART_LIMIT ) {
872870 throw new IndexOutOfBoundsException ("Exceeded S3 maximum part count" );
873871 }
874872 }
0 commit comments