本文整理汇总了Java中com.lmax.disruptor.EventFactory类的典型用法代码示例。如果您正苦于以下问题:Java EventFactory类的具体用法?Java EventFactory怎么用?Java EventFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EventFactory类属于com.lmax.disruptor包,在下文中一共展示了EventFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: RingBufferProcessor
import com.lmax.disruptor.EventFactory; //导入依赖的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);
}
示例2: RingBufferWorkProcessor
import com.lmax.disruptor.EventFactory; //导入依赖的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);
}
示例3: RingBuffer
import com.lmax.disruptor.EventFactory; //导入依赖的package包/类
/**
* Construct a RingBuffer with the full option set.
*
* @param eventFactory to newInstance entries for filling the RingBuffer
* @param sequencer sequencer to handle the ordering of events moving through the RingBuffer.
* @throws IllegalArgumentException if bufferSize is less than 1 or not a power of 2
*/
public RingBuffer(EventFactory<E> eventFactory,
Sequencer sequencer)
{
this.sequencer = sequencer;
this.bufferSize = sequencer.getBufferSize();
if (bufferSize < 1)
{
throw new IllegalArgumentException("bufferSize must not be less than 1");
}
if (Integer.bitCount(bufferSize) != 1)
{
throw new IllegalArgumentException("bufferSize must be a power of 2");
}
this.indexMask = bufferSize - 1;
this.entries = new Object[sequencer.getBufferSize()];
fill(eventFactory);
}
示例4: create
import com.lmax.disruptor.EventFactory; //导入依赖的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());
}
}
示例5: RingBuffer
import com.lmax.disruptor.EventFactory; //导入依赖的package包/类
/**
* Construct a RingBuffer with the full option set.
*
* @param eventFactory to newInstance entries for filling the RingBuffer
* @param sequencer sequencer to handle the ordering of events moving through the RingBuffer.
* @throws IllegalArgumentException if bufferSize is less than 1 or not a power of 2
*/
public RingBuffer(EventFactory<E> eventFactory, Sequencer sequencer) {
this.sequencer = sequencer;
this.bufferSize = sequencer.getBufferSize();
if (bufferSize < 1) {
throw new IllegalArgumentException("bufferSize must not be less than 1");
}
if (Integer.bitCount(bufferSize) != 1) {
throw new IllegalArgumentException("bufferSize must be a power of 2");
}
this.indexMask = bufferSize - 1;
this.entries = new Object[sequencer.getBufferSize()];
fill(eventFactory);
}
示例6: RingBufferProvider
import com.lmax.disruptor.EventFactory; //导入依赖的package包/类
RingBufferProvider(@Nonnegative final int capacity, @Nonnull final Factory<T> factory,
@Nonnull final MessageBufferConsumer<T> appIn) {
if (appIn == null) {
throw new NullPointerException("appIn == null");
}
this.waitOut = new WakeupWaitStrategy();
this.waitIn = null;
final EventFactory<T> evfactory = wrapFactory(factory);
this.out = RingBuffer.createMultiProducer(evfactory, capacity, waitOut);
this.in = null;
this.attachOut = new Object[capacity];
this.attachIn = null;
this.appOut = new RingBufferProducer<>(out, attachOut);
this.chnIn = new RingBufferConsumer<>(out, attachOut);
this.chnOut = appIn.createProducer();
this.appIn = appIn;
this.internalConsumer = false;
}
示例7: setup
import com.lmax.disruptor.EventFactory; //导入依赖的package包/类
@Before
@SuppressWarnings("unchecked")
public void setup() {
responseBuffer = new Disruptor<ResponseEvent>(new EventFactory<ResponseEvent>() {
@Override
public ResponseEvent newInstance() {
return new ResponseEvent();
}
}, 1024, Executors.newCachedThreadPool());
firedEvents = Collections.synchronizedList(new ArrayList<CouchbaseMessage>());
latch = new CountDownLatch(1);
responseBuffer.handleEventsWith(new EventHandler<ResponseEvent>() {
@Override
public void onEvent(ResponseEvent event, long sequence, boolean endOfBatch) throws Exception {
firedEvents.add(event.getMessage());
latch.countDown();
}
});
responseRingBuffer = responseBuffer.start();
}
示例8: DisruptorPublisher
import com.lmax.disruptor.EventFactory; //导入依赖的package包/类
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);
}
示例9: main
import com.lmax.disruptor.EventFactory; //导入依赖的package包/类
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();
}
示例10: ArchiveProcessor
import com.lmax.disruptor.EventFactory; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public ArchiveProcessor(final EventFactory<E> eventFactory, int ringBufferSize, final Class<E> eventClass,
final int batchSize, final ArchiveBatchHandler<E> batchHandler)
{
eventDisruptor = new Disruptor<>(eventFactory, ringBufferSize, DaemonThreadFactory.INSTANCE);
eventDisruptor.handleEventsWith(new ArchiveEventHandler<>(eventClass, batchSize, batchHandler));
running = false;
archiveThread = new Thread(this, "archiveProcessor");
}
示例11: Disruptor
import com.lmax.disruptor.EventFactory; //导入依赖的package包/类
/**
* Create a new Disruptor.
*
* @param eventFactory the factory to create events in the ring buffer.
* @param ringBufferSize the size of the ring buffer, must be power of 2.
* @param threadFactory a {@link ThreadFactory} to create threads for processors.
* @param producerType the claim strategy to use for the ring buffer.
* @param waitStrategy the wait strategy to use for the ring buffer.
*/
public Disruptor(
final EventFactory<T> eventFactory,
final int ringBufferSize,
final ThreadFactory threadFactory,
final ProducerType producerType,
final WaitStrategy waitStrategy) {
this(RingBuffer.create(
producerType, eventFactory, ringBufferSize, waitStrategy),
new BasicExecutor(threadFactory));
}
示例12: factory
import com.lmax.disruptor.EventFactory; //导入依赖的package包/类
public static <T> EventFactory<BatchedPoller.DataEvent<T>> factory()
{
return new EventFactory<BatchedPoller.DataEvent<T>>()
{
@Override
public BatchedPoller.DataEvent<T> newInstance()
{
return new BatchedPoller.DataEvent<T>();
}
};
}
示例13: factory
import com.lmax.disruptor.EventFactory; //导入依赖的package包/类
public static <T> EventFactory<DataEvent<T>> factory()
{
return new EventFactory<DataEvent<T>>()
{
@Override
public DataEvent<T> newInstance()
{
return new DataEvent<T>();
}
};
}
示例14: main
import com.lmax.disruptor.EventFactory; //导入依赖的package包/类
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));
}
示例15: fill
import com.lmax.disruptor.EventFactory; //导入依赖的package包/类
private void fill(EventFactory<E> eventFactory)
{
for (int i = 0; i < entries.length; i++)
{
entries[i] = eventFactory.newInstance();
}
}