本文整理汇总了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);
}
示例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));
}
示例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);
}
示例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);
}
}
}