本文整理匯總了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();
}
示例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;
}
示例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);
}
}
示例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.");
}
示例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);
}
}
示例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();
}
示例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();
}
示例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();
}
示例9: generateData
@Parameters
public static Collection<Object[]> generateData()
{
Object[][] allocators =
{
{ProducerType.SINGLE, new BlockingWaitStrategy()},
{ProducerType.MULTI, new BlockingWaitStrategy()},
};
return Arrays.asList(allocators);
}
示例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();
}
示例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());
}
示例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);
}
示例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);
}
示例14: createRingBufferDispatcher
private static RingBufferDispatcher createRingBufferDispatcher(DispatcherConfiguration dispatcherConfiguration) {
int backlog = getBacklog(dispatcherConfiguration, 1024);
return new RingBufferDispatcher(dispatcherConfiguration.getName(),
backlog,
null,
ProducerType.MULTI,
new AgileWaitingStrategy());
}
示例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());
}