當前位置: 首頁>>代碼示例>>Java>>正文


Java Disruptor.handleEventsWith方法代碼示例

本文整理匯總了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);
}
 
開發者ID:nuls-io,項目名稱:nuls,代碼行數:23,代碼來源:DisruptorUtil.java

示例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();
}
 
開發者ID:redBorder,項目名稱:cep,代碼行數:26,代碼來源:Source.java

示例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();
}
 
開發者ID:DDTH,項目名稱:ddth-queue,代碼行數:23,代碼來源:QndDisruptor2.java

示例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;
}
 
開發者ID:Coralma,項目名稱:smart-cqrs,代碼行數:23,代碼來源:EventBus.java

示例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);
}
 
開發者ID:smallnest,項目名稱:DisruptorBootstrap,代碼行數:19,代碼來源:App.java

示例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;
}
 
開發者ID:InformaticaCorp,項目名稱:Surf,代碼行數:22,代碼來源:Util.java

示例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);
}
 
開發者ID:LMAX-Exchange,項目名稱:disruptor-proxy,代碼行數:21,代碼來源:GeneratedRingBufferProxyGenerator.java

示例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);
}
 
開發者ID:LMAX-Exchange,項目名稱:disruptor-proxy,代碼行數:20,代碼來源:ReflectiveRingBufferProxyGenerator.java

示例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;

}
 
開發者ID:bighector,項目名稱:-artemis-disruptor-miaosha,代碼行數:41,代碼來源:DisruptorJmsMessageSenderFactory.java

示例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();
}
 
開發者ID:kogupta,項目名稱:scala-playground,代碼行數:15,代碼來源:Main.java

示例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();

}
 
開發者ID:walle-liao,項目名稱:jaf-examples,代碼行數:15,代碼來源:Main.java

示例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;
        }
 
開發者ID:ogcs,項目名稱:Okra-Ax,代碼行數:10,代碼來源:DisruptorAdapterHandler.java

示例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);
        }
    }
 
開發者ID:compasses,項目名稱:elastic-rabbitmq,代碼行數:29,代碼來源:LongEventMain.java

示例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();
}
 
開發者ID:winwill2012,項目名稱:disruptor-code-analysis,代碼行數:13,代碼來源:OneToOneTranslatorThroughputTest.java

示例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;
}
 
開發者ID:winwill2012,項目名稱:disruptor-code-analysis,代碼行數:13,代碼來源:DisruptorStressTest.java


注:本文中的com.lmax.disruptor.dsl.Disruptor.handleEventsWith方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。