188 /** |
188 /** |
189 * Reads an event and returns null when segment or chunk ends. |
189 * Reads an event and returns null when segment or chunk ends. |
190 * |
190 * |
191 * @param awaitNewEvents wait for new data. |
191 * @param awaitNewEvents wait for new data. |
192 */ |
192 */ |
193 RecordedEvent readStreamingEvent(boolean awaitNewEvents) throws IOException { |
193 RecordedEvent readStreamingEvent() throws IOException { |
194 long absoluteChunkEnd = chunkHeader.getEnd(); |
194 long absoluteChunkEnd = chunkHeader.getEnd(); |
195 while (true) { |
195 RecordedEvent event = readEvent(); |
196 RecordedEvent event = readEvent(); |
196 if (event != null) { |
197 if (event != null) { |
197 return event; |
198 return event; |
198 } |
199 } |
199 long lastValid = absoluteChunkEnd; |
200 if (!awaitNewEvents) { |
200 long metadataPosition = chunkHeader.getMetataPosition(); |
201 return null; |
201 long contantPosition = chunkHeader.getConstantPoolPosition(); |
202 } |
202 chunkFinished = awaitUpdatedHeader(absoluteChunkEnd, configuration.filterEnd); |
203 long lastValid = absoluteChunkEnd; |
203 if (chunkFinished) { |
204 long metadataPoistion = chunkHeader.getMetataPosition(); |
204 Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "At chunk end"); |
205 long contantPosition = chunkHeader.getConstantPoolPosition(); |
205 return null; |
206 chunkFinished = awaitUpdatedHeader(absoluteChunkEnd, configuration.filterEnd); |
206 } |
207 if (chunkFinished) { |
207 absoluteChunkEnd = chunkHeader.getEnd(); |
208 Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "At chunk end"); |
208 // Read metadata and constant pools for the next segment |
209 return null; |
209 if (chunkHeader.getMetataPosition() != metadataPosition) { |
210 } |
210 Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Found new metadata in chunk. Rebuilding types and parsers"); |
211 absoluteChunkEnd = chunkHeader.getEnd(); |
211 MetadataDescriptor metadata = chunkHeader.readMetadata(previousMetadata); |
212 // Read metadata and constant pools for the next segment |
212 ParserFactory factory = new ParserFactory(metadata, constantLookups, timeConverter); |
213 if (chunkHeader.getMetataPosition() != metadataPoistion) { |
213 parsers = factory.getParsers(); |
214 Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Found new metadata in chunk. Rebuilding types and parsers"); |
214 typeMap = factory.getTypeMap(); |
215 MetadataDescriptor metadata = chunkHeader.readMetadata(previousMetadata); |
215 updateConfiguration(); |
216 ParserFactory factory = new ParserFactory(metadata, constantLookups, timeConverter); |
216 } |
217 parsers = factory.getParsers(); |
217 if (contantPosition != chunkHeader.getConstantPoolPosition()) { |
218 typeMap = factory.getTypeMap(); |
218 Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Found new constant pool data. Filling up pools with new values"); |
219 updateConfiguration();; |
219 constantLookups.forEach(c -> c.getLatestPool().setAllResolved(false)); |
220 } |
220 fillConstantPools(contantPosition + chunkHeader.getAbsoluteChunkStart()); |
221 if (contantPosition != chunkHeader.getConstantPoolPosition()) { |
221 constantLookups.forEach(c -> c.getLatestPool().setResolving()); |
222 Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Found new constant pool data. Filling up pools with new values"); |
222 constantLookups.forEach(c -> c.getLatestPool().resolve()); |
223 constantLookups.forEach(c -> c.getLatestPool().setAllResolved(false)); |
223 constantLookups.forEach(c -> c.getLatestPool().setResolved()); |
224 fillConstantPools(contantPosition + chunkHeader.getAbsoluteChunkStart()); |
224 } |
225 constantLookups.forEach(c -> c.getLatestPool().setResolving()); |
225 input.position(lastValid); |
226 constantLookups.forEach(c -> c.getLatestPool().resolve()); |
226 return null; |
227 constantLookups.forEach(c -> c.getLatestPool().setResolved()); |
|
228 } |
|
229 input.position(lastValid); |
|
230 } |
|
231 } |
227 } |
232 |
228 |
233 /** |
229 /** |
234 * Reads an event and returns null when the chunk ends |
230 * Reads an event and returns null when the chunk ends |
235 */ |
231 */ |