當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。