@@ -105,16 +105,37 @@ public void flush() {
105105 String json =
106106 SERVICE_VERSION_ADAPTER .toJson (
107107 new ServiceVersion (serviceName , env , version , "JAVA" , scopesToSerialize ));
108- if (json .length () > maxPayloadSize ) {
109- LOGGER .debug (
110- "Upload split is required for {} scopes: {}/{}" ,
111- scopesToSerialize .size (),
112- json .length (),
113- maxPayloadSize );
114- splitAndSend (scopesToSerialize );
108+ updateStats (scopesToSerialize , json );
109+ doUpload (scopesToSerialize , json );
110+ }
111+
112+ private void doUpload (List <Scope > scopesToSerialize , String json ) {
113+ byte [] jsonBytes = json .getBytes (StandardCharsets .UTF_8 );
114+ byte [] payload = null ;
115+ if (isCompressed ) {
116+ payload = compressPayload (jsonBytes );
117+ }
118+ if (payload == null ) {
119+ if (json .length () > maxPayloadSize ) {
120+ LOGGER .warn ("Payload is too big: {}/{}" , json .length (), maxPayloadSize );
121+ splitAndSend (scopesToSerialize );
122+ return ;
123+ }
124+ symbolUploader .uploadAsMultipart (
125+ "" ,
126+ event ,
127+ new BatchUploader .MultiPartContent (jsonBytes , "file" , "file.json" , APPLICATION_JSON ));
115128 } else {
116- LOGGER .debug ("Sending {} jar scopes size={}" , scopesToSerialize .size (), json .length ());
117- doUpload (scopesToSerialize , json );
129+ if (payload .length > maxPayloadSize ) {
130+ LOGGER .warn ("Compressed payload is too big: {}/{}" , payload .length , maxPayloadSize );
131+ splitAndSend (scopesToSerialize );
132+ return ;
133+ }
134+ LOGGER .debug ("Sending {} jar scopes size={}" , scopesToSerialize .size (), payload .length );
135+ symbolUploader .uploadAsMultipart (
136+ "" ,
137+ event ,
138+ new BatchUploader .MultiPartContent (payload , "file" , "file.gz" , APPLICATION_GZIP ));
118139 }
119140 }
120141
@@ -146,16 +167,6 @@ private void splitAndSend(List<Scope> scopesToSerialize) {
146167 SERVICE_VERSION_ADAPTER .toJson (
147168 new ServiceVersion (
148169 serviceName , env , version , "JAVA" , Collections .singletonList (scope )));
149- if (json .length () > maxPayloadSize ) {
150- // this jar scope is still too big, split it by classes
151- LOGGER .debug (
152- "Upload split is required for jar scope {}: {}/{}" ,
153- scope .getName (),
154- json .length (),
155- maxPayloadSize );
156- splitAndSend (Collections .singletonList (scope ));
157- continue ;
158- }
159170 LOGGER .debug ("Sending {} jar scope size={}" , scope .getName (), json .length ());
160171 doUpload (Collections .singletonList (scope ), json );
161172 }
@@ -168,22 +179,10 @@ private void splitAndSend(List<Scope> scopesToSerialize) {
168179 String jsonFirstHalf =
169180 SERVICE_VERSION_ADAPTER .toJson (
170181 new ServiceVersion (serviceName , env , version , "JAVA" , firstHalf ));
171- if (jsonFirstHalf .length () > maxPayloadSize ) {
172- LOGGER .warn (
173- "Cannot split jar scope list in 2, first half is too big: {}" ,
174- jsonFirstHalf .length ());
175- return ;
176- }
177182 doUpload (firstHalf , jsonFirstHalf );
178183 String jsonSecondHalf =
179184 SERVICE_VERSION_ADAPTER .toJson (
180185 new ServiceVersion (serviceName , env , version , "JAVA" , secondHalf ));
181- if (jsonSecondHalf .length () > maxPayloadSize ) {
182- LOGGER .warn (
183- "Cannot split jar scope list in 2, second half is too big: {}" ,
184- jsonSecondHalf .length ());
185- return ;
186- }
187186 doUpload (secondHalf , jsonSecondHalf );
188187 }
189188 } else {
@@ -213,31 +212,6 @@ private void splitAndSend(List<Scope> scopesToSerialize) {
213212 }
214213 }
215214
216- private void doUpload (List <Scope > scopes , String json ) {
217- updateStats (scopes , json );
218- byte [] jsonBytes = json .getBytes (StandardCharsets .UTF_8 );
219- byte [] payload = null ;
220- if (isCompressed ) {
221- payload = compressPayload (jsonBytes );
222- }
223- if (payload == null ) {
224- if (jsonBytes .length > maxPayloadSize ) {
225- LOGGER .warn ("Compressed payload is too big: {}/{}" , payload .length , maxPayloadSize );
226- splitAndSend (scopes );
227- return ;
228- }
229- symbolUploader .uploadAsMultipart (
230- "" ,
231- event ,
232- new BatchUploader .MultiPartContent (jsonBytes , "file" , "file.json" , APPLICATION_JSON ));
233- } else {
234- symbolUploader .uploadAsMultipart (
235- "" ,
236- event ,
237- new BatchUploader .MultiPartContent (payload , "file" , "file.gz" , APPLICATION_GZIP ));
238- }
239- }
240-
241215 private static Scope createJarScope (String jarName , List <Scope > classScopes ) {
242216 return Scope .builder (ScopeType .JAR , jarName , 0 , 0 ).name (jarName ).scopes (classScopes ).build ();
243217 }
0 commit comments