25 |
25 |
26 package jdk.jfr.api.consumer.streaming; |
26 package jdk.jfr.api.consumer.streaming; |
27 |
27 |
28 import java.time.Instant; |
28 import java.time.Instant; |
29 import java.util.concurrent.CountDownLatch; |
29 import java.util.concurrent.CountDownLatch; |
|
30 import java.util.concurrent.atomic.AtomicInteger; |
30 |
31 |
31 import jdk.jfr.Event; |
32 import jdk.jfr.Event; |
32 import jdk.jfr.Recording; |
33 import jdk.jfr.Recording; |
33 import jdk.jfr.consumer.EventStream; |
34 import jdk.jfr.consumer.EventStream; |
34 |
35 |
50 } |
51 } |
51 |
52 |
52 static class EndEvent extends Event { |
53 static class EndEvent extends Event { |
53 } |
54 } |
54 |
55 |
55 static long count; |
56 private final static AtomicInteger count = new AtomicInteger(0); |
56 |
57 |
57 public static void main(String... args) throws Exception { |
58 public static void main(String... args) throws Exception { |
58 |
59 |
59 CountDownLatch gap = new CountDownLatch(1); |
60 CountDownLatch gap = new CountDownLatch(1); |
|
61 CountDownLatch receivedEvent = new CountDownLatch(1); |
|
62 |
60 try (EventStream s = EventStream.openRepository()) { |
63 try (EventStream s = EventStream.openRepository()) { |
61 try (Recording r1 = new Recording()) { |
64 try (Recording r1 = new Recording()) { |
62 s.setStartTime(Instant.EPOCH); |
65 s.setStartTime(Instant.EPOCH); |
63 s.onEvent(e -> { |
66 s.onEvent(e -> { |
64 System.out.println(e); |
67 System.out.println(e); |
|
68 receivedEvent.countDown(); |
65 try { |
69 try { |
66 gap.await(); |
70 gap.await(); |
67 } catch (InterruptedException e1) { |
71 } catch (InterruptedException e1) { |
68 e1.printStackTrace(); |
72 e1.printStackTrace(); |
69 } |
73 } |
70 count++; |
74 count.incrementAndGet(); |
71 if (e.getEventType().getName().equals(EndEvent.class.getName())) { |
75 if (e.getEventType().getName().equals(EndEvent.class.getName())) { |
72 s.close(); |
76 s.close(); |
73 } |
77 } |
74 }); |
78 }); |
75 s.startAsync(); |
79 s.startAsync(); |
76 |
|
77 r1.enable(StartEvent.class); |
|
78 r1.start(); |
80 r1.start(); |
79 StartEvent event1 = new StartEvent(); |
81 StartEvent event1 = new StartEvent(); |
80 event1.commit(); |
82 event1.commit(); |
|
83 receivedEvent.await(); |
81 r1.stop(); |
84 r1.stop(); |
82 |
85 |
83 // create chunk that is removed |
86 // create chunk that is removed |
84 try (Recording r2 = new Recording()) { |
87 try (Recording r2 = new Recording()) { |
85 r2.enable(TestGapEvent.class); |
88 r2.enable(TestGapEvent.class); |