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


Java ProducerType类代码示例

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


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

示例1: initDisruptor

import com.lmax.disruptor.dsl.ProducerType; //导入依赖的package包/类
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,代码行数:23,代码来源:PublishManager.java

示例2: SharedMessageStore

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

示例3: createDisruptor

import com.lmax.disruptor.dsl.ProducerType; //导入依赖的package包/类
/**
 * create a disruptor
 *
 * @param name           The title of the disruptor
 * @param ringBufferSize The size of ringBuffer
 */
public void createDisruptor(String name, int ringBufferSize) {
    if (DISRUPTOR_MAP.keySet().contains(name)) {
        throw new NulsRuntimeException(ErrorCode.FAILED, "create disruptor faild,the name is repetitive!");
    }

    Disruptor<DisruptorEvent> disruptor = new Disruptor<DisruptorEvent>(EVENT_FACTORY,
            ringBufferSize, new NulsThreadFactory(ModuleService.getInstance().getModuleId(EventBusModuleBootstrap.class),name), ProducerType.SINGLE,
            new SleepingWaitStrategy());
    disruptor.handleEventsWith(new EventHandler<DisruptorEvent>() {
        @Override
        public void onEvent(DisruptorEvent disruptorEvent, long l, boolean b) throws Exception {
            Log.debug(disruptorEvent.getData() + "");
        }
    });
    DISRUPTOR_MAP.put(name, disruptor);
}
 
开发者ID:nuls-io,项目名称:nuls,代码行数:23,代码来源:DisruptorUtil.java

示例4: main

import com.lmax.disruptor.dsl.ProducerType; //导入依赖的package包/类
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,代码行数:27,代码来源:MultiProducerWithTranslator.java

示例5: RingBufferService

import com.lmax.disruptor.dsl.ProducerType; //导入依赖的package包/类
@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,代码行数:17,代码来源:RingBufferService.java

示例6: initDispatcherFactoryFromConfiguration

import com.lmax.disruptor.dsl.ProducerType; //导入依赖的package包/类
private void initDispatcherFactoryFromConfiguration(String name) {
  if (dispatcherFactories.get(name) != null) {
    return;
  }
  for (DispatcherConfiguration dispatcherConfiguration : configuration.getDispatcherConfigurations()) {

    if (!dispatcherConfiguration.getName()
      .equalsIgnoreCase(name)) {
      continue;
    }

    if (DispatcherType.DISPATCHER_GROUP == dispatcherConfiguration.getType()) {
      addCachedDispatchers(dispatcherConfiguration.getName(),
        createDispatcherFactory(dispatcherConfiguration.getName(),
          dispatcherConfiguration.getSize() == 0 ? PROCESSORS : dispatcherConfiguration.getSize(),
          dispatcherConfiguration.getBacklog(),
          null,
          ProducerType.MULTI,
          new AgileWaitingStrategy()));
    }
  }
}
 
开发者ID:camunda,项目名称:camunda-bpm-reactor,代码行数:23,代码来源:Environment.java

示例7: RingBufferProcessor

import com.lmax.disruptor.dsl.ProducerType; //导入依赖的package包/类
private RingBufferProcessor(String name,
                            ExecutorService executor,
                            int bufferSize,
                            WaitStrategy waitStrategy,
                            boolean shared,
                            boolean autoCancel) {
  super(name, executor, autoCancel);

  this.ringBuffer = RingBuffer.create(
    shared ? ProducerType.MULTI : ProducerType.SINGLE,
    new EventFactory<MutableSignal<E>>() {
      @Override
      public MutableSignal<E> newInstance() {
        return new MutableSignal<E>();
      }
    },
    bufferSize,
    waitStrategy
  );

  this.recentSequence = new Sequence(Sequencer.INITIAL_CURSOR_VALUE);
  this.barrier = ringBuffer.newBarrier();
  //ringBuffer.addGatingSequences(recentSequence);
}
 
开发者ID:camunda,项目名称:camunda-bpm-reactor,代码行数:25,代码来源:RingBufferProcessor.java

示例8: RingBufferWorkProcessor

import com.lmax.disruptor.dsl.ProducerType; //导入依赖的package包/类
private RingBufferWorkProcessor(String name,
                                ExecutorService executor,
                                int bufferSize,
                                WaitStrategy waitStrategy,
                                boolean share,
                                boolean autoCancel) {
  super(name, executor, autoCancel);

  this.ringBuffer = RingBuffer.create(
    share ? ProducerType.MULTI : ProducerType.SINGLE,
    new EventFactory<MutableSignal<E>>() {
      @Override
      public MutableSignal<E> newInstance() {
        return new MutableSignal<E>();
      }
    },
    bufferSize,
    waitStrategy
  );

  ringBuffer.addGatingSequences(workSequence);

}
 
开发者ID:camunda,项目名称:camunda-bpm-reactor,代码行数:24,代码来源:RingBufferWorkProcessor.java

示例9: qndSingleThread

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

示例10: DisruptorQueueImpl

import com.lmax.disruptor.dsl.ProducerType; //导入依赖的package包/类
public DisruptorQueueImpl(String queueName, ProducerType producerType,
		int bufferSize, WaitStrategy wait) {
	this._queueName = PREFIX + queueName;
	_buffer = RingBuffer.create(producerType, new ObjectEventFactory(),
			bufferSize, wait);
	_consumer = new Sequence();
	_barrier = _buffer.newBarrier();
	_buffer.addGatingSequences(_consumer);
	if (producerType == ProducerType.SINGLE) {
		consumerStartedFlag = true;
	} else {
		// make sure we flush the pending messages in cache first
		if (bufferSize < 2) {
			throw new RuntimeException("QueueSize must >= 2");
		}
		try {
			publishDirect(FLUSH_CACHE, true);
		} catch (InsufficientCapacityException e) {
			throw new RuntimeException("This code should be unreachable!",
					e);
		}
	}
}
 
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:24,代码来源:DisruptorQueueImpl.java

示例11: create

import com.lmax.disruptor.dsl.ProducerType; //导入依赖的package包/类
/**
 * Create a new Ring Buffer with the specified producer type (SINGLE or MULTI)
 *
 * @param producerType producer type to use {@link ProducerType}.
 * @param factory used to create events within the ring buffer.
 * @param bufferSize number of elements to create within the ring buffer.
 * @param waitStrategy used to determine how to wait for new elements to become available.
 * @throws IllegalArgumentException if bufferSize is less than 1 or not a power of 2
 */
public static <E> RingBuffer<E> create(ProducerType    producerType,
                                       EventFactory<E> factory,
                                       int             bufferSize,
                                       WaitStrategy    waitStrategy)
{
    switch (producerType)
    {
    case SINGLE:
        return createSingleProducer(factory, bufferSize, waitStrategy);
    case MULTI:
        return createMultiProducer(factory, bufferSize, waitStrategy);
    default:
        throw new IllegalStateException(producerType.toString());
    }
}
 
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:25,代码来源:RingBuffer.java

示例12: open

import com.lmax.disruptor.dsl.ProducerType; //导入依赖的package包/类
/**
 * 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,代码行数:24,代码来源:EventReactor.java

示例13: DisruptorQueueImpl

import com.lmax.disruptor.dsl.ProducerType; //导入依赖的package包/类
public DisruptorQueueImpl(String queueName, ProducerType producerType, int bufferSize, WaitStrategy wait) {
    this._queueName = PREFIX + queueName;
    _buffer = RingBuffer.create(producerType, new ObjectEventFactory(), bufferSize, wait);
    _consumer = new Sequence();
    _barrier = _buffer.newBarrier();
    _buffer.addGatingSequences(_consumer);
    if (producerType == ProducerType.SINGLE) {
        consumerStartedFlag = true;
    } else {
        // make sure we flush the pending messages in cache first
        if (bufferSize < 2) {
            throw new RuntimeException("QueueSize must >= 2");
        }
        try {
            publishDirect(FLUSH_CACHE, true);
        } catch (InsufficientCapacityException e) {
            throw new RuntimeException("This code should be unreachable!", e);
        }
    }
}
 
开发者ID:kkllwww007,项目名称:jstrom,代码行数:21,代码来源:DisruptorQueueImpl.java

示例14: testLaterStartConsumer

import com.lmax.disruptor.dsl.ProducerType; //导入依赖的package包/类
@Test
public void testLaterStartConsumer() throws InterruptedException {
    System.out.println("!!!!!!!!!!!!!!!Begin testLaterStartConsumer!!!!!!!!!!");
    final AtomicBoolean messageConsumed = new AtomicBoolean(false);

    // Set queue length to 1, so that the RingBuffer can be easily full
    // to trigger consumer blocking
    DisruptorQueue queue = createQueue("consumerHang", ProducerType.MULTI, 2);
    push(queue, 1);
    Runnable producer = new Producer(queue);
    Runnable consumer = new Consumer(queue, new EventHandler<Object>() {
        long count = 0;

        @Override
        public void onEvent(Object obj, long sequence, boolean endOfBatch) throws Exception {

            messageConsumed.set(true);
            System.out.println("Consume " + count++);
        }
    });

    run(producer, 0, 0, consumer, 50);
    Assert.assertTrue("disruptor message is never consumed due to consumer thread hangs", messageConsumed.get());

    System.out.println("!!!!!!!!!!!!!!!!End testLaterStartConsumer!!!!!!!!!!");
}
 
开发者ID:kkllwww007,项目名称:jstrom,代码行数:27,代码来源:DisruptorTest.java

示例15: testSingleProducer

import com.lmax.disruptor.dsl.ProducerType; //导入依赖的package包/类
@Test
public void testSingleProducer() throws InterruptedException {
    System.out.println("!!!!!!!!!!!!!!Begin testSingleProducer!!!!!!!!!!!!!!");
    final AtomicBoolean messageConsumed = new AtomicBoolean(false);

    // Set queue length to 1, so that the RingBuffer can be easily full
    // to trigger consumer blocking
    DisruptorQueue queue = createQueue("consumerHang", ProducerType.SINGLE, 1);
    push(queue, 1);
    Runnable producer = new Producer(queue);
    Runnable consumer = new Consumer(queue, new EventHandler<Object>() {
        long count = 0;

        @Override
        public void onEvent(Object obj, long sequence, boolean endOfBatch) throws Exception {

            messageConsumed.set(true);
            System.out.println("Consume " + count++);
        }
    });

    run(producer, 0, 0, consumer, 50);
    Assert.assertTrue("disruptor message is never consumed due to consumer thread hangs", messageConsumed.get());

    System.out.println("!!!!!!!!!!!!!!End testSingleProducer!!!!!!!!!!!!!!");
}
 
开发者ID:kkllwww007,项目名称:jstrom,代码行数:27,代码来源:DisruptorTest.java


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