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


Java BlockingWaitStrategy类代码示例

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


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

示例1: configure

import com.lmax.disruptor.BlockingWaitStrategy; //导入依赖的package包/类
@Override
protected void configure() {
    switch (config.getWaitStrategyEnum()) {
    // A low-cpu usage Disruptor configuration for using in local/test environments
    case LOW_CPU:
         bind(WaitStrategy.class).annotatedWith(Names.named("PersistenceStrategy")).to(BlockingWaitStrategy.class);
         bind(WaitStrategy.class).annotatedWith(Names.named("ReplyStrategy")).to(BlockingWaitStrategy.class);
         bind(WaitStrategy.class).annotatedWith(Names.named("RetryStrategy")).to(BlockingWaitStrategy.class);
         break;
    // The default high-cpu usage Disruptor configuration for getting high throughput on production environments
    case HIGH_THROUGHPUT:
    default:
         bind(WaitStrategy.class).annotatedWith(Names.named("PersistenceStrategy")).to(BusySpinWaitStrategy.class);
         bind(WaitStrategy.class).annotatedWith(Names.named("ReplyStrategy")).to(BusySpinWaitStrategy.class);
         bind(WaitStrategy.class).annotatedWith(Names.named("RetryStrategy")).to(YieldingWaitStrategy.class);
         break;
    }
    bind(RequestProcessor.class).to(RequestProcessorImpl.class).in(Singleton.class);
    bind(PersistenceProcessor.class).to(PersistenceProcessorImpl.class).in(Singleton.class);
    bind(ReplyProcessor.class).to(ReplyProcessorImpl.class).in(Singleton.class);
    bind(RetryProcessor.class).to(RetryProcessorImpl.class).in(Singleton.class);

}
 
开发者ID:apache,项目名称:incubator-omid,代码行数:24,代码来源:DisruptorModule.java

示例2: testPersistenceWithHALeaseManagerPreservingLease

import com.lmax.disruptor.BlockingWaitStrategy; //导入依赖的package包/类
private void testPersistenceWithHALeaseManagerPreservingLease(TSOServerConfig tsoConfig) throws Exception {

        // Init a HA lease manager
        LeaseManager simulatedHALeaseManager = mock(LeaseManager.class);

        ObjectPool<Batch> batchPool = spy(new BatchPoolModule(tsoConfig).getBatchPool());

        PersistenceProcessorHandler[] handlers = configureHandlers (tsoConfig, simulatedHALeaseManager, batchPool);

        // Component under test
        PersistenceProcessorImpl proc = new PersistenceProcessorImpl(tsoConfig, new BlockingWaitStrategy(), commitTable, batchPool,
                                                                     panicker, handlers, metrics);

        // Test: Configure the lease manager to return true always
        doReturn(true).when(simulatedHALeaseManager).stillInLeasePeriod();
        proc.addCommitToBatch(ANY_ST, ANY_CT, mock(Channel.class), mock(MonitoringContext.class));
        proc.triggerCurrentBatchFlush();
        verify(simulatedHALeaseManager, timeout(1000).times(2)).stillInLeasePeriod();
        verify(batchPool, times(2)).borrowObject();
    }
 
开发者ID:apache,项目名称:incubator-omid,代码行数:21,代码来源:TestPersistenceProcessor.java

示例3: testPersistenceWithHALeaseManagerFailingToPreserveLease1

import com.lmax.disruptor.BlockingWaitStrategy; //导入依赖的package包/类
private void testPersistenceWithHALeaseManagerFailingToPreserveLease1(TSOServerConfig tsoConfig) throws Exception {

        // Init a HA lease manager
        LeaseManager simulatedHALeaseManager = mock(LeaseManager.class);

        ObjectPool<Batch> batchPool = spy(new BatchPoolModule(tsoConfig).getBatchPool());

        PersistenceProcessorHandler[] handlers = configureHandlers (tsoConfig, simulatedHALeaseManager, batchPool);

        // Component under test
        PersistenceProcessorImpl proc = new PersistenceProcessorImpl(tsoConfig, new BlockingWaitStrategy(), commitTable, batchPool,
                                                                     panicker, handlers, metrics);

        // Test: Configure the lease manager to return true first and false later for stillInLeasePeriod
        doReturn(true).doReturn(false).when(simulatedHALeaseManager).stillInLeasePeriod();
        proc.addCommitToBatch(ANY_ST, ANY_CT, mock(Channel.class), mock(MonitoringContext.class));
        proc.triggerCurrentBatchFlush();
        verify(simulatedHALeaseManager, timeout(1000).times(2)).stillInLeasePeriod();
        verify(batchPool, times(2)).borrowObject();
    }
 
开发者ID:apache,项目名称:incubator-omid,代码行数:21,代码来源:TestPersistenceProcessor.java

示例4: testPersistenceWithHALeaseManagerFailingToPreserveLease2

import com.lmax.disruptor.BlockingWaitStrategy; //导入依赖的package包/类
private void testPersistenceWithHALeaseManagerFailingToPreserveLease2(TSOServerConfig tsoConfig) throws Exception {

        // Init a HA lease manager
        LeaseManager simulatedHALeaseManager = mock(LeaseManager.class);

        ObjectPool<Batch> batchPool = spy(new BatchPoolModule(tsoConfig).getBatchPool());

        PersistenceProcessorHandler[] handlers = configureHandlers (tsoConfig, simulatedHALeaseManager, batchPool);

        // Component under test
        PersistenceProcessorImpl proc = new PersistenceProcessorImpl(tsoConfig, new BlockingWaitStrategy(), commitTable, batchPool,
                                                                     panicker, handlers, metrics);

        // Test: Configure the lease manager to return false for stillInLeasePeriod
        doReturn(false).when(simulatedHALeaseManager).stillInLeasePeriod();
        proc.addCommitToBatch(ANY_ST, ANY_CT, mock(Channel.class), mock(MonitoringContext.class));
        proc.triggerCurrentBatchFlush();
        verify(simulatedHALeaseManager, timeout(1000).times(1)).stillInLeasePeriod();
        verify(batchPool, times(2)).borrowObject();
    }
 
开发者ID:apache,项目名称:incubator-omid,代码行数:21,代码来源:TestPersistenceProcessor.java

示例5: testPersistenceWithHALeaseManagerFailingToPreserveLease3

import com.lmax.disruptor.BlockingWaitStrategy; //导入依赖的package包/类
private void testPersistenceWithHALeaseManagerFailingToPreserveLease3(TSOServerConfig tsoConfig) throws Exception {

        // Init a HA lease manager
        LeaseManager simulatedHALeaseManager = mock(LeaseManager.class);

        ObjectPool<Batch> batchPool = spy(new BatchPoolModule(tsoConfig).getBatchPool());

        PersistenceProcessorHandler[] handlers = configureHandlers (tsoConfig, simulatedHALeaseManager, batchPool);

        // Component under test
        PersistenceProcessorImpl proc = new PersistenceProcessorImpl(tsoConfig, new BlockingWaitStrategy(), commitTable, batchPool,
                                                                     panicker, handlers, metrics);

        // Test: Configure the lease manager to return true first and false later for stillInLeasePeriod and raise
        // an exception when flush
        // Configure mock writer to flush unsuccessfully
        doThrow(new IOException("Unable to write")).when(mockWriter).flush();
        doReturn(true).doReturn(false).when(simulatedHALeaseManager).stillInLeasePeriod();
        proc.addCommitToBatch(ANY_ST, ANY_CT, mock(Channel.class), mock(MonitoringContext.class));
        proc.triggerCurrentBatchFlush();
        verify(simulatedHALeaseManager, timeout(1000).times(1)).stillInLeasePeriod();
        verify(batchPool, times(2)).borrowObject();

    }
 
开发者ID:apache,项目名称:incubator-omid,代码行数:25,代码来源:TestPersistenceProcessor.java

示例6: configureHandlers

import com.lmax.disruptor.BlockingWaitStrategy; //导入依赖的package包/类
private PersistenceProcessorHandler[] configureHandlers(TSOServerConfig tsoConfig,
                                                        LeaseManager leaseManager,
                                                        ObjectPool<Batch> batchPool)
        throws Exception {
    PersistenceProcessorHandler[] handlers = new PersistenceProcessorHandler[tsoConfig.getNumConcurrentCTWriters()];
    for (int i = 0; i < tsoConfig.getNumConcurrentCTWriters(); i++) {
        handlers[i] = new PersistenceProcessorHandler(metrics,
                                                      "localhost:1234",
                                                      leaseManager,
                                                      commitTable,
                                                      new ReplyProcessorImpl(new BlockingWaitStrategy(), metrics, panicker, batchPool),
                                                      retryProcessor,
                                                      new RuntimeExceptionPanicker());
    }
    return handlers;
}
 
开发者ID:apache,项目名称:incubator-omid,代码行数:17,代码来源:TestPersistenceProcessor.java

示例7: createDisruptor

import com.lmax.disruptor.BlockingWaitStrategy; //导入依赖的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

示例8: createWaitStrategy

import com.lmax.disruptor.BlockingWaitStrategy; //导入依赖的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

示例9: initNettyServer

import com.lmax.disruptor.BlockingWaitStrategy; //导入依赖的package包/类
private IConnection initNettyServer(int port) {
    ConcurrentHashMap<Integer, DisruptorQueue> deserializeQueues = new ConcurrentHashMap<Integer, DisruptorQueue>();
    //ConcurrentHashMap<Integer, DisruptorQueue> deserializeCtrlQueues = new ConcurrentHashMap<Integer, DisruptorQueue>();

    WaitStrategy wait = (WaitStrategy)Utils.newInstance("com.lmax.disruptor.TimeoutBlockingWaitStrategy", 5, TimeUnit.MILLISECONDS);
    DisruptorQueue recvControlQueue = DisruptorQueue.mkInstance("Dispatch-control", ProducerType.MULTI,
            256, wait, false, 0, 0);
    Set<Integer> taskSet = new HashSet<Integer>();
    taskSet.add(1);
    IConnection server = context.bind(null, port, deserializeQueues, recvControlQueue, true, taskSet);

    WaitStrategy waitStrategy = new BlockingWaitStrategy();
    DisruptorQueue recvQueue = DisruptorQueue.mkInstance("NettyUnitTest", ProducerType.SINGLE, 1024, waitStrategy, false, 0, 0);
    server.registerQueue(task, recvQueue);

    return server;
}
 
开发者ID:alibaba,项目名称:jstorm,代码行数:18,代码来源:NettyUnitTest.java

示例10: initialValue

import com.lmax.disruptor.BlockingWaitStrategy; //导入依赖的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

示例11: testLowWatermarkIsPersisted

import com.lmax.disruptor.BlockingWaitStrategy; //导入依赖的package包/类
@Test(timeOut = 30_000)
public void testLowWatermarkIsPersisted() throws Exception {

    TSOServerConfig tsoConfig = new TSOServerConfig();

    PersistenceProcessorHandler[] handlers = new PersistenceProcessorHandler[tsoConfig.getNumConcurrentCTWriters()];
    for (int i = 0; i < tsoConfig.getNumConcurrentCTWriters(); i++) {
        handlers[i] = new PersistenceProcessorHandler(metrics,
                                                      "localhost:1234",
                                                      mock(LeaseManager.class),
                                                      commitTable,
                                                      mock(ReplyProcessor.class),
                                                      retryProcessor,
                                                      panicker);
    }

    // Component under test
    PersistenceProcessorImpl persistenceProcessor =
            new PersistenceProcessorImpl(tsoConfig,
                                         new BlockingWaitStrategy(),
                                         commitTable,
                                         mock(ObjectPool.class),
                                         panicker,
                                         handlers,
                                         metrics);

    persistenceProcessor.persistLowWatermark(ANY_LWM).get();

    ArgumentCaptor<Long> lwmCapture = ArgumentCaptor.forClass(Long.class);
    CommitTable.Writer lwmWriter = commitTable.getWriter();
    verify(lwmWriter, timeout(100).times(1)).updateLowWatermark(lwmCapture.capture());
    assertEquals(lwmCapture.getValue().longValue(), ANY_LWM);

}
 
开发者ID:apache,项目名称:incubator-omid,代码行数:35,代码来源:TestPersistenceProcessor.java

示例12: testCommitTableExceptionOnCommitPersistenceTakesDownDaemon

import com.lmax.disruptor.BlockingWaitStrategy; //导入依赖的package包/类
@Test(timeOut = 30_000)
public void testCommitTableExceptionOnCommitPersistenceTakesDownDaemon() throws Exception {

    // Init lease management (doesn't matter if HA or not)
    LeaseManagement leaseManager = mock(LeaseManagement.class);

    TSOServerConfig config = new TSOServerConfig();

    ObjectPool<Batch> batchPool = spy(new BatchPoolModule(config).getBatchPool());

    ReplyProcessor replyProcessor = new ReplyProcessorImpl(new BlockingWaitStrategy(), metrics, panicker, batchPool);

    PersistenceProcessorHandler[] handlers = new PersistenceProcessorHandler[config.getNumConcurrentCTWriters()];
    for (int i = 0; i < config.getNumConcurrentCTWriters(); i++) {
        handlers[i] = new PersistenceProcessorHandler(metrics,
                                                      "localhost:1234",
                                                      leaseManager,
                                                      commitTable,
                                                      replyProcessor,
                                                      mock(RetryProcessor.class),
                                                      panicker);
    }

    PersistenceProcessorImpl proc = new PersistenceProcessorImpl(config, new BlockingWaitStrategy(), commitTable, batchPool,
                                                                 panicker, handlers, metrics);

    MonitoringContext monCtx = new MonitoringContext(metrics);

    // Configure lease manager to work normally
    doReturn(true).when(leaseManager).stillInLeasePeriod();

    // Configure commit table writer to explode when flushing changes to DB
    doThrow(new IOException("Unable to [email protected]")).when(mockWriter).flush();

    // Check the panic is extended!
    proc.addCommitToBatch(ANY_ST, ANY_CT, mock(Channel.class), monCtx);
    proc.triggerCurrentBatchFlush();
    verify(panicker, timeout(1000).atLeastOnce()).panic(anyString(), any(Throwable.class));

}
 
开发者ID:apache,项目名称:incubator-omid,代码行数:41,代码来源:TestPersistenceProcessor.java

示例13: testRuntimeExceptionOnCommitPersistenceTakesDownDaemon

import com.lmax.disruptor.BlockingWaitStrategy; //导入依赖的package包/类
@Test(timeOut = 30_000)
public void testRuntimeExceptionOnCommitPersistenceTakesDownDaemon() throws Exception {

    TSOServerConfig config = new TSOServerConfig();

    ObjectPool<Batch> batchPool = new BatchPoolModule(config).getBatchPool();

    ReplyProcessor replyProcessor = new ReplyProcessorImpl(new BlockingWaitStrategy(), metrics, panicker, batchPool);

    PersistenceProcessorHandler[] handlers = new PersistenceProcessorHandler[config.getNumConcurrentCTWriters()];
    for (int i = 0; i < config.getNumConcurrentCTWriters(); i++) {
        handlers[i] = new PersistenceProcessorHandler(metrics,
                                                      "localhost:1234",
                                                      mock(LeaseManager.class),
                                                      commitTable,
                                                      replyProcessor,
                                                      retryProcessor,
                                                      panicker);
    }

    PersistenceProcessorImpl proc = new PersistenceProcessorImpl(config, new BlockingWaitStrategy(), commitTable, batchPool,
                                                                 panicker, handlers, metrics);

    // Configure writer to explode with a runtime exception
    doThrow(new RuntimeException("Kaboom!")).when(mockWriter).addCommittedTransaction(anyLong(), anyLong());
    MonitoringContext monCtx = new MonitoringContext(metrics);

    // Check the panic is extended!
    proc.addCommitToBatch(ANY_ST, ANY_CT, mock(Channel.class), monCtx);
    proc.triggerCurrentBatchFlush();
    verify(panicker, timeout(1000).atLeastOnce()).panic(anyString(), any(Throwable.class));

}
 
开发者ID:apache,项目名称:incubator-omid,代码行数:34,代码来源:TestPersistenceProcessor.java

示例14: testBadFormedPackageThrowsException

import com.lmax.disruptor.BlockingWaitStrategy; //导入依赖的package包/类
@Test(timeOut = 10_000)
public void testBadFormedPackageThrowsException() throws Exception {

    // We need an instance throwing exceptions for this test
    replyProcessor = spy(new ReplyProcessorImpl(new BlockingWaitStrategy(), metrics, new RuntimeExceptionPanicker(), batchPool));

    // Prepare test batch
    Batch batch = batchPool.borrowObject();
    batch.addCommitRetry(FIRST_ST, null, monCtx);
    ReplyBatchEvent e = ReplyBatchEvent.EVENT_FACTORY.newInstance();
    ReplyBatchEvent.makeReplyBatch(e, batch, 0);

    assertEquals(replyProcessor.nextIDToHandle.get(), 0);
    assertEquals(replyProcessor.futureEvents.size(), 0);
    assertEquals(batchPool.getNumActive(), 1);
    assertEquals(batchPool.getNumIdle(), BATCH_POOL_SIZE - 1);

    try {
        replyProcessor.onEvent(e, ANY_DISRUPTOR_SEQUENCE, false);
        fail();
    } catch (RuntimeException re) {
        // Expected
    }

    assertEquals(replyProcessor.nextIDToHandle.get(), 0);
    assertEquals(replyProcessor.futureEvents.size(), 0);
    assertEquals(batchPool.getNumActive(), 1);
    assertEquals(batchPool.getNumIdle(), BATCH_POOL_SIZE - 1);

}
 
开发者ID:apache,项目名称:incubator-omid,代码行数:31,代码来源:TestReplyProcessor.java

示例15: init

import com.lmax.disruptor.BlockingWaitStrategy; //导入依赖的package包/类
/**
     * Initialize mission board context.
     */
    public void init() {
        this.board = new ConcurrentHashMap<>();
        //  HikariCP
        HikariConfig hikariConfig = new HikariConfig(config.getHikariCPConfigPath());
        this.dataSource = new HikariDataSource(hikariConfig);
        //  Disruptor
        int rbSize = (config.getRingBufferSize() % 2 == 0 && config.getRingBufferSize() > 0) ? config.getRingBufferSize() : DEF_BUFFER_SIZE;
        this.disruptor = new Disruptor<>(DEFAULT_FACTORY, rbSize, DEFAULT_POOL, MULTI, new BlockingWaitStrategy());
        this.disruptor.handleEventsWith(new LogRecordTaskHandler());
//        this.disruptor.handleEventsWithWorkerPool(); // TODO: 用于后期EventHandler和WorkPool的WorkHandler对比测试
//        this.disruptor.handleExceptionsWith(exceptionHandler);
        this.disruptor.start();
        //  Struct parser
        this.parser = new Dom4JParser(config.getLogPath());
        this.tasks = new SimpleTaskService();

        // schedule publish task
        this.future = this.tasks.scheduleAtFixedRate(() -> {
            try {
                publishAll();
            } catch (Exception e) {
                LOG.error("Error publishAll().", e);
            }
        }, 1000L, config.getTaskInterval(), TimeUnit.MILLISECONDS);
        // add shutdown hook
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            stop();
        }));
    }
 
开发者ID:ogcs,项目名称:Okra-LOG,代码行数:33,代码来源:MissionBoard.java


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