本文整理汇总了Java中com.lmax.disruptor.dsl.Disruptor.handleEventsWith方法的典型用法代码示例。如果您正苦于以下问题:Java Disruptor.handleEventsWith方法的具体用法?Java Disruptor.handleEventsWith怎么用?Java Disruptor.handleEventsWith使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lmax.disruptor.dsl.Disruptor
的用法示例。
在下文中一共展示了Disruptor.handleEventsWith方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDisruptor
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
/**
* create a disruptor
*
* @param name The title of the disruptor
* @param ringBufferSize The size of ringBuffer
*/
public void createDisruptor(String name, int ringBufferSize) {
if (DISRUPTOR_MAP.keySet().contains(name)) {
throw new NulsRuntimeException(ErrorCode.FAILED, "create disruptor faild,the name is repetitive!");
}
Disruptor<DisruptorEvent> disruptor = new Disruptor<DisruptorEvent>(EVENT_FACTORY,
ringBufferSize, new NulsThreadFactory(ModuleService.getInstance().getModuleId(EventBusModuleBootstrap.class),name), ProducerType.SINGLE,
new SleepingWaitStrategy());
disruptor.handleEventsWith(new EventHandler<DisruptorEvent>() {
@Override
public void onEvent(DisruptorEvent disruptorEvent, long l, boolean b) throws Exception {
Log.debug(disruptorEvent.getData() + "");
}
});
DISRUPTOR_MAP.put(name, disruptor);
}
示例2: Source
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
/**
* Create a new source.
* <p>This method will prepare the instance with some needed variables
* in order to be started later with the start method (implemented by children).
*
* @param parsersManager Instance of ParserManager that will serve parsers to this source instance
* @param eventHandler Instance of EventHandler that will receive the events generated by this source instance
* @param properties Map of properties associated with this source
*/
public Source(ParsersManager parsersManager, EventHandler eventHandler, Map<String, Object> properties) {
// Save the references for later use
this.parsersManager = parsersManager;
this.properties = properties;
// Create the ring buffer for this topic and start it
Disruptor<MapEvent> disruptor = new Disruptor<>(new MapEventFactory(), ConfigData.getRingBufferSize(), Executors.newCachedThreadPool());
disruptor.handleEventsWith(eventHandler);
disruptor.start();
// Create the event producer that will receive the events produced by
// this source instance
eventProducer = new EventProducer(disruptor.getRingBuffer());
prepare();
}
示例3: qndSingleThread
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
static void qndSingleThread(int numItems) {
final AtomicLong COUNTER_RECEIVED = new AtomicLong(0);
final Disruptor<LongEvent> disruptor = new Disruptor<>(LongEvent.FACTORY, 128,
Executors.defaultThreadFactory(), ProducerType.MULTI, new YieldingWaitStrategy());
disruptor.handleEventsWith(
(event, sequence, endOfBatch) -> COUNTER_RECEIVED.incrementAndGet());
disruptor.start();
final long t = System.currentTimeMillis();
for (int i = 0; i < numItems; i++) {
disruptor.publishEvent((event, seq) -> event.set(seq));
}
long d = System.currentTimeMillis() - t;
NumberFormat nf = NumberFormat.getInstance();
System.out.println("========== qndSingleThread:");
System.out.println("Sent: " + nf.format(numItems) + " / Received: "
+ nf.format(COUNTER_RECEIVED.get()) + " / Duration: " + d + " / Speed: "
+ NumberFormat.getInstance().format((numItems * 1000.0 / d)) + " items/sec");
disruptor.shutdown();
}
示例4: createDisruptor
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
protected Disruptor<BaseEvent> createDisruptor(Class<?> eventClass, List<RegistedEventHandler> registedEventHandlers) {
WaitStrategy waitStrategy = new BlockingWaitStrategy();
// load the customized event bufferSize.
int bufferSize = EventUtils.getEventBufferSize(eventClass);
Disruptor<BaseEvent> disruptor =new Disruptor<BaseEvent>(new BaseEventFactory(),
bufferSize, Executors.newCachedThreadPool(), ProducerType.SINGLE, waitStrategy);
List<BaseEventHandler> baseEventHandlers = Lists.newArrayList();
EventType eventType = EventUtils.getEventType(eventClass);
if(EventType.ORDER.equals(eventType)) {
List<RegistedEventHandler> orderingHandlers = orderingRegistedEventHandlers(registedEventHandlers);
baseEventHandlers.add(new BaseEventHandler(EventType.ORDER, orderingHandlers.toArray(new RegistedEventHandler[0])));
} else if(EventType.CONCURRENCY.equals(eventType)) {
for(RegistedEventHandler registedEventHandler : registedEventHandlers) {
baseEventHandlers.add(new BaseEventHandler(EventType.CONCURRENCY, registedEventHandler));
}
} else {
throw new RuntimeException("The definition of event type is not correct.");
}
disruptor.handleEventsWith(baseEventHandlers.toArray(new BaseEventHandler[0]));
disruptor.start();
return disruptor;
}
示例5: main
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static void main(String[] args) throws InterruptedException {
//Executor that will be used to construct new threads for consumers
Executor executor = Executors.newCachedThreadPool();
//Specify the size of the ring buffer, must be power of 2.
int bufferSize = 1024;
//Disruptor<ObjectEvent> disruptor = new Disruptor<>(ObjectEvent::new, bufferSize, executor);
Disruptor<ObjectEvent> disruptor = new Disruptor<>(ObjectEvent::new, bufferSize, executor,
ProducerType.SINGLE, new LiteBlockingWaitStrategy());
disruptor.handleEventsWith(App::handleEvent1);
disruptor.handleEventsWith(App::handleEvent2);
//disruptor.handleEventsWith((event, sequence, endOfBatch) -> System.out.println("Event: " + event.getObject()));
disruptor.start();
produceEvents(disruptor);
}
示例6: createWorker
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
public static Worker createWorker(File conf, EventHandler<KinesisEvent> handler, String appName)throws IOException{
Executor executor = Executors.newCachedThreadPool();
Disruptor<KinesisEvent> disruptor = new Disruptor<>(KinesisEvent.EVENT_FACTORY, 128, executor);
disruptor.handleEventsWith(handler);
RingBuffer<KinesisEvent> buffer = disruptor.start();
Properties props = new Properties();
props.load(new FileReader(conf));
// Generate a unique worker ID
String workerId = InetAddress.getLocalHost().getCanonicalHostName() + ":" + UUID.randomUUID();
String accessid = props.getProperty("aws-access-key-id");
String secretkey = props.getProperty("aws-secret-key");
String streamname = props.getProperty("aws-kinesis-stream-name");
BasicAWSCredentials creds = new BasicAWSCredentials(accessid, secretkey);
CredProvider credprovider = new CredProvider(creds);
KinesisClientLibConfiguration config = new KinesisClientLibConfiguration(appName, streamname, credprovider, workerId);
Worker worker = new Worker(new RecordProcessorFactory(buffer), config, new MetricsFactory());
return worker;
}
示例7: createRingBufferProxy
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public <T> T createRingBufferProxy(final Class<T> proxyInterface, final Disruptor<ProxyMethodInvocation> disruptor, final OverflowStrategy overflowStrategy, final T implementation)
{
validator.validateAll(disruptor, proxyInterface);
disruptor.handleEventsWith(createSingleImplementationHandlerChain(implementation));
final ArgumentHolderGenerator argumentHolderGenerator = new ArgumentHolderGenerator(classPool);
argumentHolderGenerator.createArgumentHolderClass(proxyInterface);
prefillArgumentHolderObjects(disruptor.getRingBuffer(), argumentHolderGenerator);
final Map<Method, Invoker> methodToInvokerMap = createMethodToInvokerMap(proxyInterface, argumentHolderGenerator);
return generateProxy(proxyInterface, disruptor.getRingBuffer(), methodToInvokerMap, overflowStrategy, argumentHolderGenerator);
}
示例8: createRingBufferProxy
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public <T> T createRingBufferProxy(final Class<T> proxyInterface, final Disruptor<ProxyMethodInvocation> disruptor,
final OverflowStrategy overflowStrategy, final T implementation)
{
validator.validateAll(disruptor, proxyInterface);
final ReflectiveRingBufferInvocationHandler invocationHandler =
createInvocationHandler(proxyInterface, disruptor, overflowStrategy, dropListener,
messagePublicationListener);
preallocateArgumentHolders(disruptor.getRingBuffer());
disruptor.handleEventsWith(createSingleImplementationHandlerChain(implementation));
return generateProxy(proxyInterface, invocationHandler);
}
示例9: create
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
/**
* 得到返回的结果后, 必须执行 {@link DisruptorJmsMessageSender#getDisruptor()}.start() 才可以使用
*
* @param session
* @param messageProducer
* @param dupMessageDetectStrategy
* @param ringBufferSize 必须是2的次方
* @return
* @throws JMSException
*/
public static DisruptorJmsMessageSender create(
Session session,
MessageProducer messageProducer,
DupMessageDetectStrategy dupMessageDetectStrategy,
int ringBufferSize
) throws JMSException {
Disruptor<PayloadEvent> disruptor = new Disruptor<>(
PayloadEvent::new,
ringBufferSize,
Executors.defaultThreadFactory()
);
PayloadEventProducer payloadEventProducer = new PayloadEventProducer(disruptor.getRingBuffer());
DisruptorJmsMessageSender messageSender = new DisruptorJmsMessageSender();
messageSender.setSession(session);
messageSender.setMessageProducer(messageProducer);
messageSender.setPayloadEventProducer(payloadEventProducer);
if (dupMessageDetectStrategy != null) {
messageSender.setDupMessageDetectStrategy(dupMessageDetectStrategy);
}
disruptor.handleEventsWith(messageSender);
messageSender.setDisruptor(disruptor);
return messageSender;
}
示例10: main
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
public static void main(String[] args) {
ExecutorService executor = Executors.newCachedThreadPool();
int bufferSize = 1024;
WaitStrategy ws = new BlockingWaitStrategy();
Disruptor<CpuUsageEvent> disruptor = new Disruptor<>(factory, bufferSize, executor, ProducerType.SINGLE, ws);
disruptor.handleEventsWith(handler);
RingBuffer<CpuUsageEvent> ringBuffer = disruptor.start();
publishEvents(ringBuffer);
disruptor.shutdown();
executor.shutdown();
}
示例11: main
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
public static void main(String[] args) {
EventFactory<HelloEvent> eventFactory = new HelloEventFactory();
int ringBufferSize = 1024 * 1024; // RingBuffer 大小,必须是 2 的 N 次方;
Disruptor<HelloEvent> disruptor = new Disruptor<HelloEvent>(
eventFactory, ringBufferSize, Executors.defaultThreadFactory(),
ProducerType.SINGLE, new YieldingWaitStrategy());
EventHandler<HelloEvent> eventHandler = new HelloEventHandler();
disruptor.handleEventsWith(eventHandler, eventHandler);
disruptor.start();
}
示例12: initialValue
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
@Override
protected Disruptor<ConcurrentEvent> initialValue() {
Disruptor<ConcurrentEvent> disruptor = new Disruptor<>(
ConcurrentEventFactory.DEFAULT, DEFAULT_RING_BUFFER_SIZE, CACHED_THREAD_POOL, ProducerType.SINGLE, new BlockingWaitStrategy());
disruptor.handleEventsWith(new ConcurrentHandler());
// disruptor.handleExceptionsWith();
disruptor.start();
return disruptor;
}
示例13: main
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Executor executor = Executors.newCachedThreadPool();
LongEventFactory eventFactory = new LongEventFactory();
int bufferSize = 1024;
// Disruptor<LongEvent> disruptor = new Disruptor<LongEvent>(eventFactory, bufferSize, executor);
// disruptor.handleEventsWith(new LongEventHandler());
// disruptor.start();
Disruptor<LongEvent> disruptor = new Disruptor<>(LongEvent::new, bufferSize, executor);
disruptor.handleEventsWith((event, sequence, endOfBatch) -> {System.out.println("Event: " + event);
System.out.println("CurrentThreadName:" + Thread.currentThread().getName());
});
disruptor.start();
RingBuffer<LongEvent> ringBuffer = disruptor.getRingBuffer();
LongEventProducer producer = new LongEventProducer(ringBuffer);
ByteBuffer bb = ByteBuffer.allocate(8);
for (long l = 0; true; l++) {
bb.putLong(0, l);
ringBuffer.publishEvent((event, sequence, buffer) -> event.set(buffer.getLong(0)), bb);
// producer.onData(bb);
//Thread.sleep(1000);
}
}
示例14: OneToOneTranslatorThroughputTest
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public OneToOneTranslatorThroughputTest()
{
Disruptor<ValueEvent> disruptor =
new Disruptor<ValueEvent>(
ValueEvent.EVENT_FACTORY,
BUFFER_SIZE, executor,
ProducerType.SINGLE,
new YieldingWaitStrategy());
disruptor.handleEventsWith(handler);
this.ringBuffer = disruptor.start();
}
示例15: initialise
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private TestEventHandler[] initialise(Disruptor<TestEvent> disruptor, TestEventHandler[] testEventHandlers)
{
for (int i = 0; i < testEventHandlers.length; i++)
{
TestEventHandler handler = new TestEventHandler();
disruptor.handleEventsWith(handler);
testEventHandlers[i] = handler;
}
return testEventHandlers;
}