当前位置: 首页>>代码示例>>Java>>正文


Java EventHandler.onEvent方法代码示例

本文整理汇总了Java中com.lmax.disruptor.EventHandler.onEvent方法的典型用法代码示例。如果您正苦于以下问题:Java EventHandler.onEvent方法的具体用法?Java EventHandler.onEvent怎么用?Java EventHandler.onEvent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.lmax.disruptor.EventHandler的用法示例。


在下文中一共展示了EventHandler.onEvent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: consumeBatchToCursor

import com.lmax.disruptor.EventHandler; //导入方法依赖的package包/类
private void consumeBatchToCursor(long cursor, EventHandler<Object> handler) {
    for(long curr = _consumer.get() + 1; curr <= cursor; curr++) {
        try {
            MutableObject mo = _buffer.get(curr);
            Object o = mo.o;
            mo.setObject(null);
            if(o==FLUSH_CACHE) {
                Object c = null;
                while(true) {                        
                    c = _cache.poll();
                    if(c==null) break;
                    else handler.onEvent(c, curr, true);
                }
            } else if(o==INTERRUPT) {
                throw new InterruptedException("Disruptor processing interrupted");
            } else {
                handler.onEvent(o, curr, curr == cursor);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    //TODO: only set this if the consumer cursor has changed?
    _consumer.set(cursor);
}
 
开发者ID:metamx,项目名称:incubator-storm,代码行数:26,代码来源:DisruptorQueue.java

示例2: shouldNotifyBatchListenerOnEndOfBatch

import com.lmax.disruptor.EventHandler; //导入方法依赖的package包/类
@Test
public void shouldNotifyBatchListenerOnEndOfBatch() throws Exception
{
    final BatchAwareListenerImpl batchAwareListener = new BatchAwareListenerImpl();
    final EventHandler<ProxyMethodInvocation> eventHandler = createSingleImplementationHandlerChain(batchAwareListener);
    final ProxyMethodInvocation proxyMethodInvocation = new ProxyMethodInvocation();
    proxyMethodInvocation.setArgumentHolder(new StubResetable());
    proxyMethodInvocation.setInvoker(new NoOpInvoker());

    eventHandler.onEvent(proxyMethodInvocation, 17L, true);

    assertThat(batchAwareListener.getBatchCount(), is(1));
}
 
开发者ID:LMAX-Exchange,项目名称:disruptor-proxy,代码行数:14,代码来源:HandlersTest.java

示例3: shouldNotNotifyNonBatchListenerOnEndOfBatch

import com.lmax.disruptor.EventHandler; //导入方法依赖的package包/类
@Test
public void shouldNotNotifyNonBatchListenerOnEndOfBatch() throws Exception
{
    final ListenerImpl nonBatchAwareListener = new ListenerImpl();
    final EventHandler<ProxyMethodInvocation> eventHandler = createSingleImplementationHandlerChain(nonBatchAwareListener);
    final ProxyMethodInvocation proxyMethodInvocation = new ProxyMethodInvocation();
    proxyMethodInvocation.setArgumentHolder(new StubResetable());
    proxyMethodInvocation.setInvoker(new NoOpInvoker());

    eventHandler.onEvent(proxyMethodInvocation, 17L, true);
}
 
开发者ID:LMAX-Exchange,项目名称:disruptor-proxy,代码行数:12,代码来源:HandlersTest.java

示例4: asyncConsumeBatchToCursor

import com.lmax.disruptor.EventHandler; //导入方法依赖的package包/类
public void asyncConsumeBatchToCursor(EventHandler<Object> handler) throws AlertException, InterruptedException, TimeoutException {
    List<Object> batch = getConsumeBatch();
    if (batch == null)
        return;

    for (int i = 0; i < batch.size(); i++) {
        try {
            handler.onEvent(batch.get(i), 0, i == (batch.size() - 1));
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
            throw new RuntimeException(e);
        }
    }
}
 
开发者ID:alibaba,项目名称:jstorm,代码行数:15,代码来源:DisruptorQueueImpl.java


注:本文中的com.lmax.disruptor.EventHandler.onEvent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。