当前位置: 首页>>代码示例>>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;未经允许,请勿转载。