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


Java Disruptor.start方法代碼示例

本文整理匯總了Java中com.lmax.disruptor.dsl.Disruptor.start方法的典型用法代碼示例。如果您正苦於以下問題:Java Disruptor.start方法的具體用法?Java Disruptor.start怎麽用?Java Disruptor.start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.lmax.disruptor.dsl.Disruptor的用法示例。


在下文中一共展示了Disruptor.start方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import com.lmax.disruptor.dsl.Disruptor; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException
{
    Disruptor<ObjectBox> disruptor = new Disruptor<ObjectBox>(
        ObjectBox.FACTORY, RING_SIZE, Executors.newCachedThreadPool(), ProducerType.MULTI,
        new BlockingWaitStrategy());
    disruptor.handleEventsWith(new Consumer()).then(new Consumer());
    final RingBuffer<ObjectBox> ringBuffer = disruptor.getRingBuffer();
    Publisher p = new Publisher();
    IMessage message = new IMessage();
    ITransportable transportable = new ITransportable();
    String streamName = "com.lmax.wibble";
    System.out.println("publishing " + RING_SIZE + " messages");
    for (int i = 0; i < RING_SIZE; i++)
    {
        ringBuffer.publishEvent(p, message, transportable, streamName);
        Thread.sleep(10);
    }
    System.out.println("start disruptor");
    disruptor.start();
    System.out.println("continue publishing");
    while (true)
    {
        ringBuffer.publishEvent(p, message, transportable, streamName);
        Thread.sleep(10);
    }
}
 
開發者ID:winwill2012,項目名稱:disruptor-code-analysis,代碼行數:27,代碼來源:MultiProducerWithTranslator.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: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: main

import com.lmax.disruptor.dsl.Disruptor; //導入方法依賴的package包/類
public static void main(String[] args)
{
    Executor executor = Executors.newFixedThreadPool(4);
    Disruptor<DataEvent> disruptor = new Disruptor<DataEvent>(
        DataEvent.FACTORY, 1024, DaemonThreadFactory.INSTANCE);

    TransformingHandler handler1 = new TransformingHandler(0);
    TransformingHandler handler2 = new TransformingHandler(1);
    TransformingHandler handler3 = new TransformingHandler(2);
    CollatingHandler collator = new CollatingHandler();

    disruptor.handleEventsWith(handler1, handler2, handler3).then(collator);

    disruptor.start();
}
 
開發者ID:winwill2012,項目名稱:disruptor-code-analysis,代碼行數:16,代碼來源:ThreeToOneDisruptor.java

示例13: main

import com.lmax.disruptor.dsl.Disruptor; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException
{
    ExecutorService executor = Executors.newCachedThreadPool(DaemonThreadFactory.INSTANCE);

    // Build a disruptor and start it.
    Disruptor<StubEvent> disruptor = new Disruptor<StubEvent>(
        StubEvent.EVENT_FACTORY, 1024, DaemonThreadFactory.INSTANCE);
    RingBuffer<StubEvent> ringBuffer = disruptor.start();

    // Construct 2 batch event processors.
    DynamicHandler handler1 = new DynamicHandler();
    BatchEventProcessor<StubEvent> processor1 =
        new BatchEventProcessor<StubEvent>(ringBuffer, ringBuffer.newBarrier(), handler1);

    DynamicHandler handler2 = new DynamicHandler();
    BatchEventProcessor<StubEvent> processor2 =
        new BatchEventProcessor<StubEvent>(ringBuffer, ringBuffer.newBarrier(processor1.getSequence()), handler2);

    // Dynamically add both sequences to the ring buffer
    ringBuffer.addGatingSequences(processor1.getSequence(), processor2.getSequence());

    // Start the new batch processors.
    executor.execute(processor1);
    executor.execute(processor2);

    // Remove a processor.

    // Stop the processor
    processor2.halt();
    // Wait for shutdown the complete
    handler2.awaitShutdown();
    // Remove the gating sequence from the ring buffer
    ringBuffer.removeGatingSequence(processor2.getSequence());
}
 
開發者ID:winwill2012,項目名稱:disruptor-code-analysis,代碼行數:35,代碼來源:DynamiclyAddHandler.java

示例14: main

import com.lmax.disruptor.dsl.Disruptor; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException {
		long beginTime=System.currentTimeMillis();
		
		int bufferSize=1024;
		ExecutorService executor=Executors.newFixedThreadPool(4);
		//������캯�����������������˽�����2��demo֮��Ϳ��¾������ˣ���������~
		Disruptor<TradeTransaction> disruptor=new Disruptor<TradeTransaction>(new EventFactory<TradeTransaction>() {
			@Override
			public TradeTransaction newInstance() {
				return new TradeTransaction();
			}
		}, bufferSize, executor, ProducerType.SINGLE, new BusySpinWaitStrategy());
		
		//ʹ��disruptor������������C1,C2
		EventHandlerGroup<TradeTransaction> handlerGroup=disruptor.handleEventsWith(new TradeTransactionVasConsumer(),new TradeTransactionInDBHandler());
		
		TradeTransactionJMSNotifyHandler jmsConsumer=new TradeTransactionJMSNotifyHandler();
		//������C1,C2����֮��ִ��JMS��Ϣ���Ͳ��� Ҳ���������ߵ�C3
		handlerGroup.then(jmsConsumer);
		
		
		disruptor.start();//����
		CountDownLatch latch=new CountDownLatch(1);
		//������׼��
		executor.submit(new TradeTransactionPublisher(latch, disruptor));
		latch.await();//�ȴ�����������.
		disruptor.shutdown();
		executor.shutdown();
		
		System.out.println("�ܺ�ʱ:"+(System.currentTimeMillis()-beginTime));
//		long tt= System.currentTimeMillis();
//		for (int i = 0; i < 1000; i++) {
//			int j=i;
//		}
//		System.out.println("�ܺ�ʱ:"+(System.currentTimeMillis()-tt));
		
	}
 
開發者ID:wujh88,項目名稱:disruptorDemo,代碼行數:38,代碼來源:Demo3.java

示例15: start

import com.lmax.disruptor.dsl.Disruptor; //導入方法依賴的package包/類
private void start() throws Exception {
    LOGGER.debug("Starting disruptor {}", this);
    Disruptor<ExchangeEvent> newDisruptor = createDisruptor();

    newDisruptor.start();

    if (executor != null) {
        //and use our delayed executor to really really execute the event handlers now
        delayedExecutor.executeDelayedCommands(executor);
    }

    //make sure all event handlers are correctly started before we continue
    for (final LifecycleAwareExchangeEventHandler handler : handlers) {
        boolean eventHandlerStarted = false;
        while (!eventHandlerStarted) {
            try {
                //The disruptor start command executed above should have triggered a start signal to all
                //event processors which, in their death, should notify our event handlers. They respond by
                //switching a latch and we want to await that latch here to make sure they are started.
                if (!handler.awaitStarted(10, TimeUnit.SECONDS)) {
                    //we wait for a relatively long, but limited amount of time to prevent an application using
                    //this component from hanging indefinitely
                    //Please report a bug if you can reproduce this
                    LOGGER.error("Disruptor/event handler failed to start properly, PLEASE REPORT");
                }
                eventHandlerStarted = true;
            } catch (InterruptedException e) {
                //just retry
            }
        }
    }

    publishBufferedExchanges(newDisruptor);

    disruptor.set(newDisruptor, false);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:37,代碼來源:DisruptorReference.java


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