当前位置: 首页>>代码示例>>Java>>正文


Java SleepingWaitStrategy类代码示例

本文整理汇总了Java中com.lmax.disruptor.SleepingWaitStrategy的典型用法代码示例。如果您正苦于以下问题:Java SleepingWaitStrategy类的具体用法?Java SleepingWaitStrategy怎么用?Java SleepingWaitStrategy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SleepingWaitStrategy类属于com.lmax.disruptor包,在下文中一共展示了SleepingWaitStrategy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: SharedMessageStore

import com.lmax.disruptor.SleepingWaitStrategy; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public SharedMessageStore(MessageDao messageDao, int bufferSize, int maxDbBatchSize) {

    pendingMessages = new ConcurrentHashMap<>();
    ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
            .setNameFormat("DisruptorMessageStoreThread-%d").build();

    disruptor = new Disruptor<>(DbOperation.getFactory(),
            bufferSize, namedThreadFactory, ProducerType.MULTI, new SleepingWaitStrategy());

    disruptor.setDefaultExceptionHandler(new LogExceptionHandler());

    disruptor.handleEventsWith(new DbEventMatcher(bufferSize))
            .then(new DbWriter(messageDao, maxDbBatchSize))
            .then((EventHandler<DbOperation>) (event, sequence, endOfBatch) -> event.clear());
    disruptor.start();
    this.messageDao = messageDao;
}
 
开发者ID:wso2,项目名称:message-broker,代码行数:19,代码来源:SharedMessageStore.java

示例2: createWaitStrategy

import com.lmax.disruptor.SleepingWaitStrategy; //导入依赖的package包/类
private static WaitStrategy createWaitStrategy() {
    final String strategy = System.getProperty("AsyncLogger.WaitStrategy");
    LOGGER.debug("property AsyncLogger.WaitStrategy={}", strategy);
    if ("Sleep".equals(strategy)) {
        LOGGER.debug("disruptor event handler uses SleepingWaitStrategy");
        return new SleepingWaitStrategy();
    } else if ("Yield".equals(strategy)) {
        LOGGER.debug("disruptor event handler uses YieldingWaitStrategy");
        return new YieldingWaitStrategy();
    } else if ("Block".equals(strategy)) {
        LOGGER.debug("disruptor event handler uses BlockingWaitStrategy");
        return new BlockingWaitStrategy();
    }
    LOGGER.debug("disruptor event handler uses SleepingWaitStrategy");
    return new SleepingWaitStrategy();
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:17,代码来源:AsyncLogger.java

示例3: DisruptorEventQueue

import com.lmax.disruptor.SleepingWaitStrategy; //导入依赖的package包/类
@SuppressWarnings({"deprecation", "unchecked", "varargs"})
private DisruptorEventQueue() {
  // Create new Disruptor for processing. Note that this uses a single thread for processing; this
  // ensures that the event handler can take unsynchronized actions whenever possible.
  disruptor =
      new Disruptor<DisruptorEvent>(
          new DisruptorEventFactory(),
          DISRUPTOR_BUFFER_SIZE,
          Executors.newSingleThreadExecutor(new DaemonThreadFactory("OpenCensus.Disruptor")),
          ProducerType.MULTI,
          new SleepingWaitStrategy());
  disruptor.handleEventsWith(new DisruptorEventHandler());
  disruptor.start();
  ringBuffer = disruptor.getRingBuffer();
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:16,代码来源:DisruptorEventQueue.java

示例4: HttpRequestRecordManager

import com.lmax.disruptor.SleepingWaitStrategy; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public HttpRequestRecordManager() {
    this.disruptor = new Disruptor<>(new HttpRequestRecordEventFactory(), 1024, Executors.defaultThreadFactory(),
            ProducerType.MULTI, new SleepingWaitStrategy());
    this.recordStorage = new HttpRequestRecordMemoryStorage();
    this.eventStat = new HttpRequestRecordEventStat();
    this.consumer = new HttpRequestRecordEventHandler(this.recordStorage, this.eventStat);
    this.disruptor.handleEventsWith(this.consumer);
    this.logEntryManager = new LogEntryManager();
}
 
开发者ID:JerryXia,项目名称:BizHttpRequestTest,代码行数:11,代码来源:HttpRequestRecordManager.java

示例5: LogEntryManager

import com.lmax.disruptor.SleepingWaitStrategy; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public LogEntryManager() {
    this.disruptor = new Disruptor<>(new LogEntryEventFactory(), 1024, Executors.defaultThreadFactory(),
            ProducerType.MULTI, new SleepingWaitStrategy());
    this.logEntryStorage = new LogEntryMemoryStorage();
    this.logEntryEventStat = new LogEntryEventStat();
    this.consumer = new LogEntryEventHandler(this.logEntryStorage, this.logEntryEventStat);
    this.disruptor.handleEventsWith(consumer);
}
 
开发者ID:JerryXia,项目名称:BizHttpRequestTest,代码行数:10,代码来源:LogEntryManager.java

示例6: main

import com.lmax.disruptor.SleepingWaitStrategy; //导入依赖的package包/类
public static void main(String[] args) {
	
	final List<ValueEventHandler1PMC> handlers = new ArrayList<>(NUMBER_CONSUMERS);
			
	RingBuffer<ValueEvent> ringBuffer = RingBuffer.createSingleProducer(
			ValueEvent.EVENT_FACTORY, RING_SIZE, new SleepingWaitStrategy());

	start = System.nanoTime();

	//Create consumers
	for(int i = 0;  i < NUMBER_CONSUMERS; i++) {
		ValueEventHandler1PMC handler = new ValueEventHandler1PMC(start, handlers);
		handlers.add(handler);
		SequenceBarrier barrier = ringBuffer.newBarrier();
		BatchEventProcessor<ValueEvent> eventProcessor = new BatchEventProcessor<ValueEvent>(
				ringBuffer,	barrier, handler);
		ringBuffer.addGatingSequences(eventProcessor.getSequence());

		// Each EventProcessor can run on a separate thread
		EXECUTOR.submit(eventProcessor);
	}
	
	for(int i = 0;  i  < SAMPLES_SIZE; i++) {
		// Publishers claim events in sequence
		long sequence = ringBuffer.next();
		ValueEvent event = ringBuffer.get(sequence);

		event.setValue(i); // this could be more complex with multiple fields
		
		// make the event available to EventProcessors
		ringBuffer.publish(sequence);   
	}

}
 
开发者ID:iproduct,项目名称:low-latency-high-throughput,代码行数:35,代码来源:Demo1PMC.java

示例7: test_All_WaitStrategies

import com.lmax.disruptor.SleepingWaitStrategy; //导入依赖的package包/类
@Test
public void test_All_WaitStrategies() {
	assertTrue(WaitStrategyType.BLOCKING.instance() instanceof BlockingWaitStrategy);
	assertTrue(WaitStrategyType.BUSY_SPIN.instance() instanceof BusySpinWaitStrategy);
	assertTrue(WaitStrategyType.LITE_BLOCKING.instance() instanceof LiteBlockingWaitStrategy);
	assertTrue(WaitStrategyType.SLEEPING_WAIT.instance() instanceof SleepingWaitStrategy);
	assertTrue(WaitStrategyType.YIELDING.instance() instanceof YieldingWaitStrategy);
}
 
开发者ID:anair-it,项目名称:disruptor-spring-manager,代码行数:9,代码来源:WaitStrategyTypeTest.java

示例8: createFromType

import com.lmax.disruptor.SleepingWaitStrategy; //导入依赖的package包/类
public static WaitStrategy createFromType(String name) {
    if ("BusySpin".equalsIgnoreCase(name)) {
        return new BusySpinWaitStrategy();
    } else if ("Blocking".equalsIgnoreCase(name)) {
        return new BlockingWaitStrategy();
    } else if ("Yielding".equalsIgnoreCase(name)) {
        return new YieldingWaitStrategy();
    } else if ("Sleeping".equalsIgnoreCase(name)) {
        return new SleepingWaitStrategy();
    } else {
        throw new IllegalArgumentException("Invalid or unsupported wait strategy type '" + name + "'");
    }
}
 
开发者ID:trautonen,项目名称:logback-ext,代码行数:14,代码来源:WaitStrategyFactory.java

示例9: startProcessing

import com.lmax.disruptor.SleepingWaitStrategy; //导入依赖的package包/类
public synchronized void startProcessing() {
    if (!receivers.isEmpty()) {

        Boolean asyncEnabled = null;
        try {
            Element element = AnnotationHelper.getAnnotationElement(SiddhiConstants.ANNOTATION_CONFIG,
                    SiddhiConstants.ANNOTATION_ELEMENT_ASYNC,
                    streamDefinition.getAnnotations());

            if (element != null) {
                asyncEnabled = SiddhiConstants.TRUE.equalsIgnoreCase(element.getValue());
            }

        } catch (DuplicateAnnotationException e) {
            throw new QueryCreationException(e.getMessage() + " for the same Stream Definition " +
                    streamDefinition.toString());
        }

        if (asyncEnabled != null && asyncEnabled || asyncEnabled == null && publishers.size() > 1) {

            ProducerType producerType = ProducerType.SINGLE;
            if (publishers.size() > 1) {
                producerType = ProducerType.MULTI;
            }

            disruptor = new Disruptor<Event>(new SiddhiEventFactory(streamDefinition.getAttributeList().size()),
                    bufferSize, executorService, producerType, new SleepingWaitStrategy());

            for (Receiver receiver : receivers) {
                disruptor.handleEventsWith(new StreamHandler(receiver));
            }

            ringBuffer = disruptor.start();

        }
    }
}
 
开发者ID:sacjaya,项目名称:siddhi-3,代码行数:38,代码来源:StreamJunction.java

示例10: startProcessing

import com.lmax.disruptor.SleepingWaitStrategy; //导入依赖的package包/类
public synchronized void startProcessing() {

        Boolean asyncEnabled = null;
        try {
            Element element = AnnotationHelper.getAnnotationElement(SiddhiConstants.ANNOTATION_CONFIG,
                    SiddhiConstants.ANNOTATION_ELEMENT_CALLBACK_ASYNC,
                    query.getAnnotations());

            if (element != null) {
                asyncEnabled = SiddhiConstants.TRUE.equalsIgnoreCase(element.getValue());
            }

        } catch (DuplicateAnnotationException e) {
            throw new QueryCreationException(e.getMessage() + " for the same Query " +
                    query.toString());
        }

        if (asyncEnabled != null && asyncEnabled || asyncEnabled == null) {

            disruptor = new Disruptor<EventHolder>(new EventHolderFactory(), siddhiContext.getDefaultEventBufferSize(),
                    siddhiContext.getExecutorService(), ProducerType.SINGLE, new SleepingWaitStrategy());

            asyncEventHandler = new AsyncEventHandler(this);
            disruptor.handleEventsWith(asyncEventHandler);
            ringBuffer = disruptor.start();
        }
    }
 
开发者ID:sacjaya,项目名称:siddhi-3,代码行数:28,代码来源:QueryCallback.java

示例11: createWaitStrategy

import com.lmax.disruptor.SleepingWaitStrategy; //导入依赖的package包/类
private static WaitStrategy createWaitStrategy() {
    final String strategy = System
            .getProperty("AsyncLoggerConfig.WaitStrategy");
    LOGGER.debug("property AsyncLoggerConfig.WaitStrategy={}", strategy);
    if ("Sleep".equals(strategy)) {
        return new SleepingWaitStrategy();
    } else if ("Yield".equals(strategy)) {
        return new YieldingWaitStrategy();
    } else if ("Block".equals(strategy)) {
        return new BlockingWaitStrategy();
    }
    return new SleepingWaitStrategy();
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:14,代码来源:AsyncLoggerConfigHelper.java

示例12: DisruptorWorker

import com.lmax.disruptor.SleepingWaitStrategy; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public DisruptorWorker() {
	QueuedMapEventCollectionFactory factory = new QueuedMapEventCollectionFactory();
	QueuedMapEventCollectionHandler handler = new QueuedMapEventCollectionHandler();

	this.disruptor = new Disruptor<QueuedMapEventCollection>(factory, EXECUTOR, 
					new MultiThreadedClaimStrategy(RING_SIZE),
					new SleepingWaitStrategy());
	this.disruptor.handleEventsWith(handler);
	
	this.ringBuffer = disruptor.start();
}
 
开发者ID:52North,项目名称:SES,代码行数:13,代码来源:DisruptorWorker.java

示例13: useSensibleDefaults

import com.lmax.disruptor.SleepingWaitStrategy; //导入依赖的package包/类
private void useSensibleDefaults() {
  ringBufferSize = 2048;
  producerType = ProducerType.MULTI;
  waitStrategy = new SleepingWaitStrategy();
}
 
开发者ID:aol,项目名称:vulcan,代码行数:6,代码来源:AvroWriterBuilder.java

示例14: verifyDisruptorDefaults

import com.lmax.disruptor.SleepingWaitStrategy; //导入依赖的package包/类
private void verifyDisruptorDefaults() throws Exception {
  verifyNew(Disruptor.class).withArguments(any(AvroEventFactory.class), eq(2048), any(ExecutorService.class),
                                           eq(ProducerType.MULTI), isA(SleepingWaitStrategy.class));
}
 
开发者ID:aol,项目名称:vulcan,代码行数:5,代码来源:DisruptorAvroFileWriterBuilderTest.java

示例15: main

import com.lmax.disruptor.SleepingWaitStrategy; //导入依赖的package包/类
public static void main(String[] args) {
				
		RingBuffer<ValueEvent> ringBuffer = RingBuffer.createSingleProducer(
				ValueEvent.EVENT_FACTORY, RING_SIZE, new SleepingWaitStrategy());

		start = System.nanoTime();

		//Create first consumer
		ValueEventHandler1PMCSequenceFirst handler = new ValueEventHandler1PMCSequenceFirst(start);
		SequenceBarrier barrier;
		barrier = ringBuffer.newBarrier();
		BatchEventProcessor<ValueEvent> firstEventProcessor = new BatchEventProcessor<ValueEvent>(
				ringBuffer,	barrier, handler);
//		ringBuffer.addGatingSequences(firstEventProcessor.getSequence());
		
		// Each EventProcessor can run on a separate thread
		EXECUTOR.submit(firstEventProcessor);

		//Create second consumer
		ValueEventHandler1PMCSequenceSecond handler2 = new ValueEventHandler1PMCSequenceSecond(start);
		SequenceBarrier barrier2 = ringBuffer.newBarrier(firstEventProcessor.getSequence());
		BatchEventProcessor<ValueEvent> secondEventProcessor = new BatchEventProcessor<ValueEvent>(
				ringBuffer,	barrier2, handler2);
		ringBuffer.addGatingSequences(secondEventProcessor.getSequence());
		
		// Each EventProcessor can run on a separate thread
		EXECUTOR.submit(secondEventProcessor);

		
		for(int i = 0;  i  < SAMPLES_SIZE; i++) {
			// Publishers claim events in sequence
			long sequence = ringBuffer.next();
			ValueEvent event = ringBuffer.get(sequence);

			event.setValue(i); // this could be more complex with multiple fields
			
			// make the event available to EventProcessors
			ringBuffer.publish(sequence);   
		}

	}
 
开发者ID:iproduct,项目名称:low-latency-high-throughput,代码行数:42,代码来源:Demo1PMCSequence.java


注:本文中的com.lmax.disruptor.SleepingWaitStrategy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。