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


Java Disruptor.shutdown方法代碼示例

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


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

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

示例2: stop

import com.lmax.disruptor.dsl.Disruptor; //導入方法依賴的package包/類
public static void stop() {
    final Disruptor<RingBufferLogEvent> temp = disruptor;

    // Must guarantee that publishing to the RingBuffer has stopped
    // before we call disruptor.shutdown()
    disruptor = null; // client code fails with NPE if log after stop = OK
    temp.shutdown();

    // wait up to 10 seconds for the ringbuffer to drain
    final RingBuffer<RingBufferLogEvent> ringBuffer = temp.getRingBuffer();
    for (int i = 0; i < MAX_DRAIN_ATTEMPTS_BEFORE_SHUTDOWN; i++) {
        if (ringBuffer.hasAvailableCapacity(ringBuffer.getBufferSize())) {
            break;
        }
        try {
            // give ringbuffer some time to drain...
            Thread.sleep(HALF_A_SECOND);
        } catch (final InterruptedException e) {
            // ignored
        }
    }
    executor.shutdown(); // finally, kill the processor thread
}
 
開發者ID:OuZhencong,項目名稱:log4j2,代碼行數:24,代碼來源:AsyncLogger.java

示例3: shouldProxy

import com.lmax.disruptor.dsl.Disruptor; //導入方法依賴的package包/類
@SuppressWarnings("StatementWithEmptyBody")
@Test
public void shouldProxy()
{
    final Disruptor<ProxyMethodInvocation> disruptor = createDisruptor(Executors.newSingleThreadExecutor(), 1024);
    final RingBufferProxyGeneratorFactory generatorFactory = new RingBufferProxyGeneratorFactory();
    final RingBufferProxyGenerator ringBufferProxyGenerator = generatorFactory.newProxy(generatorType);

    final ListenerImpl implementation = new ListenerImpl();
    final Listener listener = ringBufferProxyGenerator.createRingBufferProxy(Listener.class, disruptor, OverflowStrategy.DROP, implementation);
    disruptor.start();

    for(int i = 0; i < 3; i++)
    {
        listener.onString("single string " + i);
        listener.onFloatAndInt((float) i, i);
        listener.onVoid();
        listener.onObjectArray(new Double[]{(double) i});
        listener.onMixedMultipleArgs(0, 1, "a", "b", 2);
    }

    RingBuffer<ProxyMethodInvocation> ringBuffer = disruptor.getRingBuffer();
    while (ringBuffer.getMinimumGatingSequence() != ringBuffer.getCursor())
    {
        // Spin
    }

    disruptor.shutdown();
    Executors.newSingleThreadExecutor().shutdown();

    assertThat(implementation.getLastStringValue(), is("single string 2"));
    assertThat(implementation.getLastFloatValue(), is((float) 2));
    assertThat(implementation.getLastIntValue(), is(2));
    assertThat(implementation.getVoidInvocationCount(), is(3));
    assertThat(implementation.getMixedArgsInvocationCount(), is(3));
    assertThat(implementation.getLastDoubleArray(), is(equalTo(new Double[] {(double) 2})));
}
 
開發者ID:LMAX-Exchange,項目名稱:disruptor-proxy,代碼行數:38,代碼來源:AbstractRingBufferProxyGeneratorTest.java

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

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

示例6: qndMultiThreads

import com.lmax.disruptor.dsl.Disruptor; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
static void qndMultiThreads(int numItems, int numThreads) throws InterruptedException {
    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();
    final int numItemsPerThread = numItems / numThreads;
    final Thread[] THREADS = new Thread[numThreads];
    for (int i = 0; i < THREADS.length; i++) {
        THREADS[i] = new Thread() {
            public void run() {
                for (int i = 0; i < numItemsPerThread; i++) {
                    disruptor.publishEvent((event, seq) -> event.set(seq));
                }
            }
        };
        THREADS[i].start();
    }
    for (Thread thread : THREADS) {
        thread.join();
    }

    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,代碼行數:36,代碼來源:QndDisruptor2.java

示例7: removeEventFlow

import com.lmax.disruptor.dsl.Disruptor; //導入方法依賴的package包/類
public void removeEventFlow(HandlerProcessor queryStreamProcessor) {
    streamReceivers.remove(queryStreamProcessor);
    if (disruptorEnabled) {
        for (Disruptor disruptor : queryStreamProcessor.getDisruptors()) {
            disruptor.shutdown();
        }
    }
}
 
開發者ID:sacjaya,項目名稱:siddhi-3,代碼行數:9,代碼來源:StreamJunction.java

示例8: removeEventFlows

import com.lmax.disruptor.dsl.Disruptor; //導入方法依賴的package包/類
public void removeEventFlows() {
    for(StreamReceiver queryStreamProcessor:streamReceivers){
        streamReceivers.remove(queryStreamProcessor);
        if (disruptorEnabled) {
            for (Disruptor disruptor : queryStreamProcessor.getDisruptors()) {
                disruptor.shutdown();
            }
        }
    }
}
 
開發者ID:sacjaya,項目名稱:siddhi-3,代碼行數:11,代碼來源:StreamJunction.java

示例9: release

import com.lmax.disruptor.dsl.Disruptor; //導入方法依賴的package包/類
/**
 * Decreases the reference count. If the reference count reached zero, the
 * Disruptor and its associated thread are shut down and their references
 * set to {@code null}.
 */
synchronized static void release() {
    if (--count > 0) {
        LOGGER.trace("AsyncLoggerConfigHelper: not shutting down disruptor: ref count is {}.", count);
        return;
    }
    final Disruptor<Log4jEventWrapper> temp = disruptor;
    if (temp == null) {
        LOGGER.trace("AsyncLoggerConfigHelper: disruptor already shut down: ref count is {}.", count);
        return; // disruptor was already shut down by another thread
    }
    LOGGER.trace("AsyncLoggerConfigHelper: shutting down disruptor: ref count is {}.", count);

    // Must guarantee that publishing to the RingBuffer has stopped
    // before we call disruptor.shutdown()
    disruptor = null; // client code fails with NPE if log after stop = OK
    temp.shutdown();

    // wait up to 10 seconds for the ringbuffer to drain
    final RingBuffer<Log4jEventWrapper> ringBuffer = temp.getRingBuffer();
    for (int i = 0; i < MAX_DRAIN_ATTEMPTS_BEFORE_SHUTDOWN; i++) {
        if (ringBuffer.hasAvailableCapacity(ringBuffer.getBufferSize())) {
            break;
        }
        try {
            // give ringbuffer some time to drain...
            Thread.sleep(HALF_A_SECOND);
        } catch (final InterruptedException e) {
            // ignored
        }
    }
    executor.shutdown(); // finally, kill the processor thread
    executor = null; // release reference to allow GC
}
 
開發者ID:OuZhencong,項目名稱:log4j2,代碼行數:39,代碼來源:AsyncLoggerConfigHelper.java

示例10: run

import com.lmax.disruptor.dsl.Disruptor; //導入方法依賴的package包/類
/**
 * Create a pool of consumers, all reading from a ring buffer to process events.
 *
 * @param NUM_THREADS total number of consumers to create in the pool
 * @param totalEventsToPublish total events to publish to the queue
 * @param ringConsumers the placeholder for creating consumers
 * @throws InterruptedException if there is a problem talking to the blocking queue
 */
public void run(int NUM_THREADS, int totalEventsToPublish, RingEventHandlerConsumer<T>[] ringConsumers) throws InterruptedException {
    final int RING_BUFFER_SIZE = 1024;

    ExecutorService executor;
    if(NUM_THREADS == 1) {
        executor = Executors.newSingleThreadExecutor();
    } else {
        executor = Executors.newFixedThreadPool(NUM_THREADS);
    }

    Disruptor<T> disruptor =
            new Disruptor<>(disruptorEventFactory, RING_BUFFER_SIZE, executor,
                    ProducerType.SINGLE,
                    new YieldingWaitStrategy());

    for(int i = 0; i < NUM_THREADS; i++) {
        ringConsumers[i] = new RingEventHandlerConsumer<T>(i, NUM_THREADS, consumerFactory.createConsumer(i, NUM_THREADS));
    }

    disruptor.handleEventsWith(ringConsumers);

    RingBuffer<T> eventRingBuffer = disruptor.start();

    final long startTime = System.currentTimeMillis();
    publishEvents(totalEventsToPublish, eventRingBuffer);

    disruptor.shutdown();
    executor.shutdown();
    final long endTime = System.currentTimeMillis();
    logger.info("It took " + (endTime - startTime) + "ms to process " + totalEventsToPublish + " messages.");
    for(RingEventHandlerConsumer consumer : ringConsumers) {
        logger.info("Processed " + consumer.getMessagesProcessed() + " messages.");
    }
}
 
開發者ID:4BitBen,項目名稱:disruptor-vs-queue,代碼行數:43,代碼來源:EventHandlerRunner.java

示例11: shutdown

import com.lmax.disruptor.dsl.Disruptor; //導入方法依賴的package包/類
@Override
public void shutdown() {
    LOG.info(format("shutting down the (Disruptor)ThreadBoundExecutor[%s]",threadFactory.toString()));
    if (shuttingDown.compareAndSet(false, true)) {
        for (Disruptor<ThreadBoundEventWrapper> disruptor : disruptors) {
            // @todo: we may want to have a timeout here
            disruptor.shutdown();
        }
    }
    LOG.info(format("(Disruptor)ThreadBoundExecutor[%s] shut down completed",threadFactory.toString()));
}
 
開發者ID:elasticsoftwarefoundation,項目名稱:elasticactors,代碼行數:12,代碼來源:ThreadBoundExecutorImpl.java

示例12: testDisruptor

import com.lmax.disruptor.dsl.Disruptor; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void testDisruptor() {
    ExecutorService exec = Executors.newCachedThreadPool();
    // Preallocate RingBuffer with 1024 MetricEvents
    Disruptor<ByteArrayHolder> disruptor = new Disruptor<ByteArrayHolder>(ByteArrayHolder.EVENT_FACTORY, 1024, exec);
    final EventHandler<ByteArrayHolder> handler = new EventHandler<ByteArrayHolder>() {
        // event will eventually be recycled by the Disruptor after it wraps
        public void onEvent(final ByteArrayHolder event, final long sequence, final boolean endOfBatch) throws Exception {
            System.out.println("Sequence: " + sequence);
            System.out.println("MetricEvent: " + event.getValue());
        }
    };
    // Build dependency graph
    disruptor.handleEventsWith(handler);
    RingBuffer<ByteArrayHolder> ringBuffer = disruptor.start();

    for (long i = 10; i < 2000; i++) {

        MetricPB metricToReport = MetricPB.newBuilder()
                .setKey("test.metric")
                .setTimestamp(123456789l)
                .setValue(1.93f)
                .build();

        String uuid = UUID.randomUUID().toString();
        // Two phase commit. Grab one of the 1024 slots
        long seq = ringBuffer.next();
        ByteArrayHolder valueEvent = ringBuffer.get(seq);
        byte[] bytes = new byte[8];
        //valueEvent.setValue(uuid);
        valueEvent.setValue(metricToReport.toByteArray());
        ringBuffer.publish(seq);
    }
    disruptor.shutdown();
    exec.shutdown();
}
 
開發者ID:kavehg,項目名稱:raider,代碼行數:38,代碼來源:Simple.java

示例13: shouldNotifyOnPreAndPostPublish

import com.lmax.disruptor.dsl.Disruptor; //導入方法依賴的package包/類
@Test
public void shouldNotifyOnPreAndPostPublish() throws Exception
{
    final Disruptor<ProxyMethodInvocation> disruptor = createDisruptor(Executors.newSingleThreadExecutor(), 1024);
    final RingBufferProxyGeneratorFactory generatorFactory = new RingBufferProxyGeneratorFactory();
    final RingBufferProxyGenerator ringBufferProxyGenerator = generatorFactory.newProxy(generatorType,
            new ConfigurableValidator(NO_ANNOTATION, NOT_REQUIRED), dropListener, messagePublicationListener);

    final ListenerImpl implementation = new ListenerImpl();
    final Listener listener = ringBufferProxyGenerator.createRingBufferProxy(Listener.class, disruptor, OverflowStrategy.DROP, implementation);
    disruptor.start();

    for(int i = 0; i < 3; i++)
    {
        listener.onVoid();
    }

    RingBuffer<ProxyMethodInvocation> ringBuffer = disruptor.getRingBuffer();
    while (ringBuffer.getMinimumGatingSequence() != ringBuffer.getCursor())
    {
        // Spin
    }

    disruptor.shutdown();
    Executors.newSingleThreadExecutor().shutdown();

    assertThat(messagePublicationListener.getPreCount(), is(3));
    assertThat(messagePublicationListener.getPostCount(), is(3));
}
 
開發者ID:LMAX-Exchange,項目名稱:disruptor-proxy,代碼行數:30,代碼來源:AbstractRingBufferProxyGeneratorTest.java

示例14: shouldDropMessagesIfRingBufferIsFull

import com.lmax.disruptor.dsl.Disruptor; //導入方法依賴的package包/類
@Test
public void shouldDropMessagesIfRingBufferIsFull() throws Exception
{
    final Disruptor<ProxyMethodInvocation> disruptor = createDisruptor(Executors.newSingleThreadExecutor(), 4);
    final RingBufferProxyGeneratorFactory generatorFactory = new RingBufferProxyGeneratorFactory();
    final RingBufferProxyGenerator ringBufferProxyGenerator = generatorFactory.newProxy(generatorType, new ConfigurableValidator(false, true), dropListener);

    final CountDownLatch latch = new CountDownLatch(1);
    final BlockingOverflowTest implementation = new BlockingOverflowTest(latch);
    final OverflowTest listener = ringBufferProxyGenerator.createRingBufferProxy(OverflowTest.class, disruptor, OverflowStrategy.DROP, implementation);
    disruptor.start();

    for(int i = 0; i < 8; i++)
    {
        listener.invoke();
    }

    latch.countDown();

    Thread.sleep(250L);

    disruptor.shutdown();
    Executors.newSingleThreadExecutor().shutdown();

    assertThat(implementation.getInvocationCount(), is(4));
    assertThat(dropListener.getDropCount(), is(4));
}
 
開發者ID:LMAX-Exchange,項目名稱:disruptor-proxy,代碼行數:28,代碼來源:AbstractRingBufferProxyGeneratorTest.java

示例15: shouldReportBatchSize

import com.lmax.disruptor.dsl.Disruptor; //導入方法依賴的package包/類
@Test
public void shouldReportBatchSize() throws Exception
{

    final Disruptor<ProxyMethodInvocation> disruptor = createDisruptor(Executors.newSingleThreadExecutor(), 8);
    final RingBufferProxyGeneratorFactory generatorFactory = new RingBufferProxyGeneratorFactory();
    final RingBufferProxyGenerator ringBufferProxyGenerator =
            generatorFactory.newProxy(generatorType, new ConfigurableValidator(false, true), dropListener);

    final CountDownLatch latch1 = new CountDownLatch(1);
    final CountDownLatch latch2 = new CountDownLatch(1);
    final BatchSizeTrackingHandler batchSizeTracker = new BatchSizeTrackingHandler(latch1, latch2);
    final OverflowTest listener = ringBufferProxyGenerator.createRingBufferProxy(OverflowTest.class, disruptor, OverflowStrategy.BLOCK, batchSizeTracker);
    disruptor.start();

    for(int i = 0; i < 8; i++)
    {
        listener.invoke();
        latch1.await();
    }

    latch2.countDown();

    Thread.sleep(250L);

    disruptor.shutdown();
    Executors.newSingleThreadExecutor().shutdown();

    assertThat(batchSizeTracker.getInvocationCount(), is(8));
    assertThat(batchSizeTracker.getMaxBatchSize(), is(7));
}
 
開發者ID:LMAX-Exchange,項目名稱:disruptor-proxy,代碼行數:32,代碼來源:AbstractRingBufferProxyGeneratorTest.java


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