如何使用我的hashmap lmax disruptor中的数据来实现ringbuffer

时间:2018-04-10 18:52:47

标签: java disruptor-pattern lmax

实际上,在阅读并使用一个简单的破坏性示例后,我无法找到如何在我的hash buffer中使用来自我的hashmap的数据来满足来自eventHandler,翻译器或来自哪个组件的数据? / p>

1 个答案:

答案 0 :(得分:2)

你应该在你的bean或包含你的业务流程的地方做最简单的测试方法是在你的主类中

 public static void main () {

    // Executor that will be used to construct new threads for consumers
        Executor executor = Executors.newCachedThreadPool();

        // The factory for the event
        LogEventFactory factory = new LogEventFactory();

        // Specify the size of the ring buffer, must be power of 2.
        int bufferSize = 262144;

        // Construct the Disruptor
        Disruptor<LogEvent> disruptor = new Disruptor<LogEvent>(factory, bufferSize, executor);

        // Connect the handler
        disruptor.handleEventsWith(new LogEventHandler());

        // Start the Disruptor, starts all threads running
        disruptor.start();

        // Get the ring buffer from the Disruptor to be used for publishing.
        RingBuffer<LogEvent> ringBuffer = disruptor.getRingBuffer();

        LongEventProducerWithTranslator producer = new LongEventProducerWithTranslator(ringBuffer);

        **for (String name : cache.keySet()) {



            String key = name.toString();
            String value = cache.get(name).toString();

            producer.onData(cache.get(name));
            //Thread.sleep(2000);
            //System.out.println("key:" + key + " " + "//value:" + cache.get(name).getTags());

        }**

遍历它,你的翻译类应该通过循环传递对象