本文整理汇总了Java中com.lmax.disruptor.dsl.ProducerType.SINGLE属性的典型用法代码示例。如果您正苦于以下问题:Java ProducerType.SINGLE属性的具体用法?Java ProducerType.SINGLE怎么用?Java ProducerType.SINGLE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.lmax.disruptor.dsl.ProducerType
的用法示例。
在下文中一共展示了ProducerType.SINGLE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDisruptor
/**
* 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);
}
示例2: DisruptorQueueImpl
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);
}
}
}
示例3: DisruptorQueueImpl
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);
}
}
}
示例4: inputDisruptor
@Provides
@Singleton
@Named("disruptor")
@SuppressWarnings("Unchecked")
protected Disruptor<TwoPhaseEvent<T>> inputDisruptor(Provider<WorkHandler<TwoPhaseEvent<T>>> workHandlerProvider,
Provider<EventHandler<TwoPhaseEvent<T>>> evenHandlerProvider) {
Disruptor<TwoPhaseEvent<T>> disruptor = new Disruptor<>(
TwoPhaseEvent.factory(outputEventFactory()),
options.ringSize(), threadsProvider,
ProducerType.SINGLE, new SleepingWaitStrategy());
WorkHandler<TwoPhaseEvent<T>>[] parsers = new WorkHandler[options.threads()];
for (int i = 0; i < options.threads(); i++) {
parsers[i] = workHandlerProvider.get();
}
disruptor.handleExceptionsWith(new FatalExceptionHandler());
disruptor.handleEventsWithWorkerPool(parsers).then(evenHandlerProvider.get());
return disruptor;
}
示例5: firstPassDisruptor
@Provides
@Singleton
@Named("firstPassDisruptor")
public Disruptor<TwoPhaseEvent<Void>> firstPassDisruptor(
Provider<WorkHandler<TwoPhaseEvent<Void>>> statisticsHandlerProvider) {
Disruptor<TwoPhaseEvent<Void>> disruptor = new Disruptor<>(
TwoPhaseEvent.factory(() -> null),
options.ringSize(), threadsProvider,
ProducerType.SINGLE, new SleepingWaitStrategy());
WorkHandler<TwoPhaseEvent<Void>>[] parsers = new WorkHandler[options.threads()];
for (int i = 0; i < options.threads(); i++) {
parsers[i] = statisticsHandlerProvider.get();
}
disruptor.handleExceptionsWith(new FatalExceptionHandler());
disruptor.handleEventsWithWorkerPool(parsers);
return disruptor;
}
示例6: secondPassDisruptor
@Provides
@Singleton
@Named("secondPassDisruptor")
public Disruptor<TwoPhaseEvent<SparseItem>> secondPassDisruptor(
Provider<WorkHandler<TwoPhaseEvent<SparseItem>>> binningHandlerProvider,
Provider<EventHandler<TwoPhaseEvent<SparseItem>>> outputHandlerProvider) {
Disruptor<TwoPhaseEvent<SparseItem>> disruptor = new Disruptor<>(
TwoPhaseEvent.factory(SparseItem::new),
options.ringSize(), threadsProvider,
ProducerType.SINGLE, new SleepingWaitStrategy());
WorkHandler<TwoPhaseEvent<SparseItem>>[] parsers = new WorkHandler[options.threads()];
for (int i = 0; i < options.threads(); i++) {
parsers[i] = binningHandlerProvider.get();
}
disruptor.handleExceptionsWith(new FatalExceptionHandler());
disruptor.handleEventsWithWorkerPool(parsers)
.then(outputHandlerProvider.get());
return disruptor;
}
示例7: PersonHelper
public PersonHelper() {
//参数1 事件
//参数2 单线程使用
//参数3 等待策略
EventFactory<PersonEvent> eventFactory = PersonEvent.EVENT_FACTORY;
ExecutorService executor = Executors.newSingleThreadExecutor();
int ringBufferSize = 4; // RingBuffer 大小,必须是 2 的 N 次方;
Disruptor<PersonEvent> disruptor = new Disruptor<>(eventFactory,
ringBufferSize, executor, ProducerType.SINGLE,
new YieldingWaitStrategy());
ringBuffer = disruptor.getRingBuffer();
//获取生产者的位置信息
sequenceBarrier = ringBuffer.newBarrier();
//消费者
handler = new PersonEventHandler();
//事件处理器,监控指定ringBuffer,有数据时通知指定handler进行处理
batchEventProcessor = new BatchEventProcessor<>(ringBuffer, sequenceBarrier, handler);
//传入所有消费者线程的序号
// ringBuffer.setGatingSequences(batchEventProcessor.getSequence());
}
示例8: main
public static void main(String[] args) {
ExecutorService executor = Executors.newCachedThreadPool();
int bufferSize = 1024;
WaitStrategy ws = new BlockingWaitStrategy();
Disruptor<CpuUsageEvent> disruptor = new Disruptor<>(factory, bufferSize, executor, ProducerType.SINGLE, ws);
disruptor.handleEventsWith(handler);
RingBuffer<CpuUsageEvent> ringBuffer = disruptor.start();
publishEvents(ringBuffer);
disruptor.shutdown();
executor.shutdown();
}
示例9: DisruptorPublisher
public DisruptorPublisher(int bufferSize, TestHandler handler) {
this.handler = new HelloEventHandler(handler);
EventFactory<HelloEvent> eventFactory = new HelloEventFactory();
int ringBufferSize = 1024 * 1024; // RingBuffer 大小,必须是 2 的 N 次方;
executor = Executors.newSingleThreadExecutor();
disruptor = new Disruptor<HelloEvent>(
eventFactory, ringBufferSize, Executors.defaultThreadFactory(),
ProducerType.SINGLE, YIELDING_WAIT);
}
示例10: main
public static void main(String[] args) {
EventFactory<HelloEvent> eventFactory = new HelloEventFactory();
int ringBufferSize = 1024 * 1024; // RingBuffer 大小,必须是 2 的 N 次方;
Disruptor<HelloEvent> disruptor = new Disruptor<HelloEvent>(
eventFactory, ringBufferSize, Executors.defaultThreadFactory(),
ProducerType.SINGLE, new YieldingWaitStrategy());
EventHandler<HelloEvent> eventHandler = new HelloEventHandler();
disruptor.handleEventsWith(eventHandler, eventHandler);
disruptor.start();
}
示例11: initialValue
@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;
}
示例12: OneToOneTranslatorThroughputTest
@SuppressWarnings("unchecked")
public OneToOneTranslatorThroughputTest()
{
Disruptor<ValueEvent> disruptor =
new Disruptor<ValueEvent>(
ValueEvent.EVENT_FACTORY,
BUFFER_SIZE, executor,
ProducerType.SINGLE,
new YieldingWaitStrategy());
disruptor.handleEventsWith(handler);
this.ringBuffer = disruptor.start();
}
示例13: generateData
@Parameters
public static Collection<Object[]> generateData()
{
Object[][] allocators =
{
{ProducerType.SINGLE, new BlockingWaitStrategy()},
{ProducerType.MULTI, new BlockingWaitStrategy()},
};
return Arrays.asList(allocators);
}
示例14: setUp
@SuppressWarnings("unchecked")
@Before
public void setUp()
{
disruptor = new Disruptor<byte[]>(
new ByteArrayFactory(256), 1024, Executors.newCachedThreadPool(), ProducerType.SINGLE,
new BlockingWaitStrategy());
disruptor.handleEventsWith(eventHandler);
disruptor.setDefaultExceptionHandler(new FatalExceptionHandler());
}
示例15: main
public static void main(String[] args) throws InterruptedException {
long beginTime=System.currentTimeMillis();
int bufferSize=1024;
ExecutorService executor=Executors.newFixedThreadPool(4);
//������캯�����������������˽�����2��demo֮��Ϳ��¾������ˣ���������~
Disruptor<TradeTransaction> disruptor=new Disruptor<TradeTransaction>(new EventFactory<TradeTransaction>() {
@Override
public TradeTransaction newInstance() {
return new TradeTransaction();
}
}, bufferSize, executor, ProducerType.SINGLE, new BusySpinWaitStrategy());
//ʹ��disruptor������������C1,C2
EventHandlerGroup<TradeTransaction> handlerGroup=disruptor.handleEventsWith(new TradeTransactionVasConsumer(),new TradeTransactionInDBHandler());
TradeTransactionJMSNotifyHandler jmsConsumer=new TradeTransactionJMSNotifyHandler();
//������C1,C2����֮��ִ��JMS��Ϣ���Ͳ��� Ҳ���������ߵ�C3
handlerGroup.then(jmsConsumer);
disruptor.start();//����
CountDownLatch latch=new CountDownLatch(1);
//��������
executor.submit(new TradeTransactionPublisher(latch, disruptor));
latch.await();//�ȴ�����������.
disruptor.shutdown();
executor.shutdown();
System.out.println("�ܺ�ʱ:"+(System.currentTimeMillis()-beginTime));
// long tt= System.currentTimeMillis();
// for (int i = 0; i < 1000; i++) {
// int j=i;
// }
// System.out.println("�ܺ�ʱ:"+(System.currentTimeMillis()-tt));
}