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


Java ProducerType.MULTI屬性代碼示例

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


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

示例1: initDisruptor

private void initDisruptor(int processors, int ringBufferSize) {
  LOG.info("eds client init disruptor with processors="
      + processors + " and ringBufferSize=" + ringBufferSize);

  executor = Executors.newFixedThreadPool(
      processors,
      new ThreadFactoryBuilder().setNameFormat("disruptor-executor-%d").build());

  final WaitStrategy waitStrategy = createWaitStrategy();
  ringBufferSize = sizeFor(ringBufferSize); // power of 2
  disruptor = new Disruptor<>(EdsRingBufferEvent.FACTORY, ringBufferSize, executor,
      ProducerType.MULTI, waitStrategy);

  EdsEventWorkHandler[] handlers = new EdsEventWorkHandler[processors];
  for (int i = 0; i < handlers.length; i++) {
    handlers[i] = new EdsEventWorkHandler();
  }
  // handlers number = threads number
  disruptor.handleEventsWithWorkerPool(handlers); // "handleEventsWith" just like topics , with multiple consumers

  disruptor.start();
}
 
開發者ID:eXcellme,項目名稱:eds,代碼行數:22,代碼來源:PublishManager.java

示例2: SharedMessageStore

@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,代碼行數:18,代碼來源:SharedMessageStore.java

示例3: main

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

示例4: RingBufferService

@SuppressWarnings("unchecked")
private RingBufferService(final Properties config) {
	config.put(KafkaProducerService.CONFIG_PREFIX + "value.serializer", ByteBufSerde.ByteBufSerializer.class.getName());
	config.put(KafkaProducerService.CONFIG_PREFIX + "key.serializer", Serdes.String().serializer());
	producer = KafkaProducerService.getInstance(config);
	bufferSize = ConfigurationHelper.getIntSystemThenEnvProperty(RB_CONF_BUFFER_SIZE, RB_DEFAULT_BUFFER_SIZE, config);
	targetTopic = ConfigurationHelper.getSystemThenEnvProperty(RB_CONF_TOPIC_NAME, RB_DEFAULT_TOPIC_NAME, config);
	eventBuffInitSize = ConfigurationHelper.getIntSystemThenEnvProperty(RB_CONF_BUFF_INITIAL_SIZE, RB_DEFAULT_BUFF_INITIAL_SIZE, config);
	shutdownTimeout = ConfigurationHelper.getIntSystemThenEnvProperty(RB_CONF_STOP_TIMEOUT, RB_DEFAULT_STOP_TIMEOUT, config);
	waitStrategy = RBWaitStrategy.getConfiguredStrategy(config);
	disruptor = new Disruptor<ByteBuf>(this, bufferSize, threadFactory, ProducerType.MULTI, waitStrategy);
	disruptor.handleEventsWith(this);   // FIXME: need to able to supply several handlers
	disruptor.start();
	ringBuffer = disruptor.getRingBuffer();
	log.info("<<<<< RawRingBufferDispatcher Started.");		
}
 
開發者ID:nickman,項目名稱:HeliosStreams,代碼行數:16,代碼來源:RingBufferService.java

示例5: open

/**
 * Start dispatching events
 * 
 * @return a Future that asyncrhonously notifies an observer when this EventReactor is ready
 */
@SuppressWarnings("unchecked")
public CompletableFuture<? extends EventReactor<T>> open() {
  if (isRunning.compareAndSet(false, true)) {
    CompletableFuture<EventReactor<T>> future = new CompletableFuture<>();
    this.disruptor =
        new Disruptor<>(EVENT_FACTORY, ringSize, threadFactory, ProducerType.MULTI,
            new BusySpinWaitStrategy());
    this.disruptor.handleEventsWith(this::handleEvent);
    this.ringBuffer = disruptor.start();

    // Starts a timer thread
    this.timer = new Timer();
    future.complete(this);
    return future;
  } else {
    return CompletableFuture.completedFuture(this);
  }
}
 
開發者ID:FIXTradingCommunity,項目名稱:silverflash,代碼行數:23,代碼來源:EventReactor.java

示例6: qndSingleThread

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

示例7: initDis

@SuppressWarnings("unchecked")
protected void initDis()
   {
   	disruptorExecutor = new ThreadPoolExecutor(1,1,0L, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>(),new NamedThreadFactory("disruptor"));
       int bufferSize = 1024*1024;
       disruptor = new Disruptor<>(new QueueEventFactory(), bufferSize, disruptorExecutor,ProducerType.MULTI,YIELDING_WAIT);
       //注冊消費者
       disruptor.handleEventsWithWorkerPool(new QueueEventHandler());
       disruptor.start();
   }
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:10,代碼來源:FixedThreadPoolQueuesExecutor_mina_disruptor.java

示例8: DOMNotificationRouter

@SuppressWarnings("unchecked")
private DOMNotificationRouter(final ExecutorService executor, final int queueDepth, final WaitStrategy strategy) {
    this.executor = Preconditions.checkNotNull(executor);

    disruptor = new Disruptor<>(DOMNotificationRouterEvent.FACTORY, queueDepth, executor, ProducerType.MULTI, strategy);
    disruptor.handleEventsWith(DISPATCH_NOTIFICATIONS);
    disruptor.after(DISPATCH_NOTIFICATIONS).handleEventsWith(NOTIFY_FUTURE);
    disruptor.start();
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:9,代碼來源:DOMNotificationRouter.java

示例9: generateData

@Parameters
public static Collection<Object[]> generateData()
{
    Object[][] allocators =
        {
            {ProducerType.SINGLE, new BlockingWaitStrategy()},
            {ProducerType.MULTI, new BlockingWaitStrategy()},
        };
    return Arrays.asList(allocators);
}
 
開發者ID:winwill2012,項目名稱:disruptor-code-analysis,代碼行數:10,代碼來源:SequencerTest.java

示例10: DisruptorEventQueue

@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,代碼行數:15,代碼來源:DisruptorEventQueue.java

示例11: MetricsMetaAPIImpl

/**
 * Creates a new MetricsMetaAPIImpl
 * @param properties The configuration properties
 */
public MetricsMetaAPIImpl(final Properties properties) {
	dataSource = SQLCompilerDataSource.getInstance(properties);
	sqlWorker = dataSource.getSQLWorker();
	tagPredicateCache = new TagPredicateCache(sqlWorker);
	fjPool = new ManagedForkJoinPool(getClass().getSimpleName(), Runtime.getRuntime().availableProcessors(), true, JMXHelper.objectName(getClass()));
	metaReader = new DefaultMetaReader(sqlWorker);
	dispatcher = new WorkQueueDispatcher("MetricsMetaDispatcher", Runtime.getRuntime().availableProcessors(), 1024, this, ProducerType.MULTI, new LiteBlockingWaitStrategy());
	log.info("Dispatcher Alive: {}", dispatcher.alive());
}
 
開發者ID:nickman,項目名稱:HeliosStreams,代碼行數:13,代碼來源:MetricsMetaAPIImpl.java

示例12: initSpecDisruptor

/**
 * 根據config初始化特殊通道
 *
 * @param symbol    事件
 * @param listeners 對應的監聽器集合
 */
private void initSpecDisruptor(String symbol, List<ElectronsListener> listeners) {
    ExecutorService specPool = Executors.newFixedThreadPool(conf.getSpecCircuitNum(), new ThreadFactory() {

        final AtomicInteger cursor = new AtomicInteger(0);

        @Override
        public Thread newThread(Runnable r) {
            return new Thread(r, "Electrons Thread (from spec channel) : thread" + cursor.incrementAndGet());
        }
    });
    pools.add(specPool);

    Disruptor<ElectronsHolder> disruptor = new Disruptor<>(ElectronsHolder::new, conf.getSpecCircuitLen(), specPool, ProducerType.MULTI, new LiteBlockingWaitStrategy());
    disruptor.handleExceptionsWith(new ElecExceptionHandler("Spec Disruptor {" + symbol + "}"));

    //初始化管道並放入集合中
    SpecChannel specChannel = new SpecChannel(disruptor);
    if (conf.isBreaker()) {
        EventCountCircuitBreaker breaker = new EventCountCircuitBreaker(conf.getErrorNum(), conf.getPerUnit(), conf.getUnit(), conf.getCloseThreshold(), conf.getRest(), conf.getRestUnit());
        specChannel.setBreaker(breaker);
    }

    //構建listener順序
    ListenerChainBuilderNew.buildChain(specChannel, listeners);

    channelMap.put(SPEC_CHANNEL_PREFIX + symbol, specChannel);
}
 
開發者ID:carryxyh,項目名稱:Electrons,代碼行數:33,代碼來源:Dispatcher.java

示例13: initNormalChannel

/**
 * 初始化正常管道,任何情況下都會有
 *
 * @param pool 線程池
 */
private void initNormalChannel(ExecutorService pool) {
    Disruptor<ElectronsHolder> normalDis = new Disruptor<>(ElectronsHolder::new, conf.getCircuitLen(), pool, ProducerType.MULTI, new LiteBlockingWaitStrategy());
    WorkHandler[] workHandlers = new WorkHandler[conf.getCircuitNum()];
    Arrays.fill(workHandlers, (WorkHandler<ElectronsHolder>) electronsHolder -> electronsHolder.handle());
    normalDis.handleEventsWithWorkerPool(workHandlers);
    normalDis.handleExceptionsWith(new ElecExceptionHandler("Normal Disruptor"));

    //初始化channel
    Channel normalChannel = new NormalChannel(normalDis);
    //配置限流相關
    normalChannel.confLimitRate(conf.isLimitRate(), conf.getPermitsPerSecond(), conf.isWarmup(), conf.getWarmupPeriod(), conf.getWarmPeriodUnit());
    channelMap.put(NORMAL_CHANNEL_KEY, normalChannel);
}
 
開發者ID:carryxyh,項目名稱:Electrons,代碼行數:18,代碼來源:Dispatcher.java

示例14: createRingBufferDispatcher

private static RingBufferDispatcher createRingBufferDispatcher(DispatcherConfiguration dispatcherConfiguration) {
  int backlog = getBacklog(dispatcherConfiguration, 1024);
  return new RingBufferDispatcher(dispatcherConfiguration.getName(),
    backlog,
    null,
    ProducerType.MULTI,
    new AgileWaitingStrategy());
}
 
開發者ID:camunda,項目名稱:camunda-bpm-reactor,代碼行數:8,代碼來源:Environment.java

示例15: WorkQueueDispatcher

@SuppressWarnings("unchecked")
public WorkQueueDispatcher(String name,
                           int poolSize,
                           int backlog,
                           final Consumer<Throwable> uncaughtExceptionHandler) {
  this(name, poolSize, backlog, uncaughtExceptionHandler, ProducerType.MULTI, new BlockingWaitStrategy());
}
 
開發者ID:camunda,項目名稱:camunda-bpm-reactor,代碼行數:7,代碼來源:WorkQueueDispatcher.java


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