diff options
| author | sebright <sebright@google.com> | 2018-05-11 22:45:50 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-05-11 22:45:50 -0700 |
| commit | 539b80256b1c0d0084a023875ed4986828100531 (patch) | |
| tree | ff34a2f1a41a52b80e6f4afb3d92f1da349099f9 | |
| parent | 83fd63784edaed486e43be5570549143375fdefc (diff) | |
| parent | ed3347839996c2f0be4efeb9cdd56e0fdfed5ab7 (diff) | |
| download | platform_external_opencensus-java-539b80256b1c0d0084a023875ed4986828100531.tar.gz platform_external_opencensus-java-539b80256b1c0d0084a023875ed4986828100531.tar.bz2 platform_external_opencensus-java-539b80256b1c0d0084a023875ed4986828100531.zip | |
Merge pull request #1192 from sebright/fix-disruptor-warnings
Remove warning suppression in DisruptorEventQueue.
| -rw-r--r-- | impl/src/main/java/io/opencensus/impl/internal/DisruptorEventQueue.java | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/impl/src/main/java/io/opencensus/impl/internal/DisruptorEventQueue.java b/impl/src/main/java/io/opencensus/impl/internal/DisruptorEventQueue.java index 5145ca3b..a0445b53 100644 --- a/impl/src/main/java/io/opencensus/impl/internal/DisruptorEventQueue.java +++ b/impl/src/main/java/io/opencensus/impl/internal/DisruptorEventQueue.java @@ -98,7 +98,7 @@ public final class DisruptorEventQueue implements EventQueue { // large a queue. private static final int DISRUPTOR_BUFFER_SIZE = 8192; // The single instance of the class. - private static final DisruptorEventQueue eventQueue = new DisruptorEventQueue(); + private static final DisruptorEventQueue eventQueue = create(); // The event queue is built on this {@link Disruptor}. private final Disruptor<DisruptorEvent> disruptor; @@ -108,24 +108,32 @@ public final class DisruptorEventQueue implements EventQueue { private volatile DisruptorEnqueuer enqueuer; // Creates a new EventQueue. Private to prevent creation of non-singleton instance. - // Suppress warnings for disruptor.handleEventsWith. - @SuppressWarnings({"unchecked", "nullness"}) - private DisruptorEventQueue() { + private DisruptorEventQueue( + Disruptor<DisruptorEvent> disruptor, + RingBuffer<DisruptorEvent> ringBuffer, + DisruptorEnqueuer enqueuer) { + this.disruptor = disruptor; + this.ringBuffer = ringBuffer; + this.enqueuer = enqueuer; + } + + // Creates a new EventQueue. Private to prevent creation of non-singleton instance. + private static DisruptorEventQueue create() { // Create new Disruptor for processing. Note that Disruptor creates a single thread per // consumer (see https://github.com/LMAX-Exchange/disruptor/issues/121 for details); // this ensures that the event handler can take unsynchronized actions whenever possible. - disruptor = + Disruptor<DisruptorEvent> disruptor = new Disruptor<>( DisruptorEventFactory.INSTANCE, DISRUPTOR_BUFFER_SIZE, new DaemonThreadFactory("OpenCensus.Disruptor"), ProducerType.MULTI, new SleepingWaitStrategy()); - disruptor.handleEventsWith(DisruptorEventHandler.INSTANCE); + disruptor.handleEventsWith(new DisruptorEventHandler[] {DisruptorEventHandler.INSTANCE}); disruptor.start(); - ringBuffer = disruptor.getRingBuffer(); + final RingBuffer<DisruptorEvent> ringBuffer = disruptor.getRingBuffer(); - enqueuer = + DisruptorEnqueuer enqueuer = new DisruptorEnqueuer() { @Override public void enqueue(Entry entry) { @@ -138,6 +146,7 @@ public final class DisruptorEventQueue implements EventQueue { } } }; + return new DisruptorEventQueue(disruptor, ringBuffer, enqueuer); } /** |
