當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。