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


Java EventFactory类代码示例

本文整理汇总了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);
}
 
开发者ID:camunda,项目名称:camunda-bpm-reactor,代码行数:25,代码来源:RingBufferProcessor.java

示例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);

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

示例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);
}
 
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:27,代码来源:RingBuffer.java

示例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());
    }
}
 
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:25,代码来源:RingBuffer.java

示例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);
}
 
开发者ID:kkllwww007,项目名称:jstrom,代码行数:23,代码来源:RingBuffer.java

示例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;
}
 
开发者ID:ricardopadilha,项目名称:dsys-snio,代码行数:19,代码来源:RingBufferProvider.java

示例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();
}
 
开发者ID:couchbase,项目名称:couchbase-jvm-core,代码行数:22,代码来源:AbstractGenericHandlerTest.java

示例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);
  }
 
开发者ID:walle-liao,项目名称:jaf-examples,代码行数:12,代码来源:DisruptorPublisher.java

示例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();

}
 
开发者ID:walle-liao,项目名称:jaf-examples,代码行数:15,代码来源:Main.java

示例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");
}
 
开发者ID:canepat,项目名称:Helios,代码行数:11,代码来源:ArchiveProcessor.java

示例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));
}
 
开发者ID:winwill2012,项目名称:disruptor-code-analysis,代码行数:20,代码来源:Disruptor.java

示例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>();
        }
    };
}
 
开发者ID:winwill2012,项目名称:disruptor-code-analysis,代码行数:13,代码来源:PullWithBatchedPoller.java

示例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>();
        }
    };
}
 
开发者ID:winwill2012,项目名称:disruptor-code-analysis,代码行数:12,代码来源:PullWithPoller.java

示例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));
		
	}
 
开发者ID:wujh88,项目名称:disruptorDemo,代码行数:38,代码来源:Demo3.java

示例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();
    }
}
 
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:8,代码来源:RingBuffer.java


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