本文整理匯總了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);
}
}
}