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


Java EventTranslatorOneArg类代码示例

本文整理汇总了Java中com.lmax.disruptor.EventTranslatorOneArg的典型用法代码示例。如果您正苦于以下问题:Java EventTranslatorOneArg类的具体用法?Java EventTranslatorOneArg怎么用?Java EventTranslatorOneArg使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


EventTranslatorOneArg类属于com.lmax.disruptor包,在下文中一共展示了EventTranslatorOneArg类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: translateAndPublishBatch

import com.lmax.disruptor.EventTranslatorOneArg; //导入依赖的package包/类
private <A> void translateAndPublishBatch(final EventTranslatorOneArg<E, A> translator, final A[] arg0,
                                          int batchStartsAt, final int batchSize, final long finalSequence)
{
    final long initialSequence = finalSequence - (batchSize - 1);
    try
    {
        long sequence = initialSequence;
        final int batchEndsAt = batchStartsAt + batchSize;
        for (int i = batchStartsAt; i < batchEndsAt; i++)
        {
            translator.translateTo(get(sequence), sequence++, arg0[i]);
        }
    }
    finally
    {
        sequencer.publish(initialSequence, finalSequence);
    }
}
 
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:19,代码来源:RingBuffer.java

示例2: init

import com.lmax.disruptor.EventTranslatorOneArg; //导入依赖的package包/类
@Before
public void init(){
	m_latch = new CountDownLatch(1);
	BatchProcessor<Object> bp = new BatchProcessor<Object>() {

		@Override
		public void process(List<? extends Object> batch) throws BatchProcessorException {
			m_receivedEvents.add(new ArrayList<>(batch));
			for (int i = 0; i < batch.size(); i++){
				m_latch.countDown();
			}
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}				
		}
		
		
	};
	m_processor = new AsyncConcurrentBatchingProcessor<Object>(bp, Object::new, new EventTranslatorOneArg<Object, Object>() {
		public void translateTo(Object event, long sequence, Object arg0) {};
	});
}
 
开发者ID:davruet,项目名称:shenanigans.io,代码行数:25,代码来源:AsyncConcurrentBatchingProcessorTest.java

示例3: tryPublishEvent

import com.lmax.disruptor.EventTranslatorOneArg; //导入依赖的package包/类
/**
 * Allows one user supplied argument.
 *
 * @see #tryPublishEvent(EventTranslator)
 * @param translator The user specified translation for the event
 * @param arg0 A user supplied argument.
 * @return true if the value was published, false if there was insufficient
 * capacity.
 */
public <A> boolean tryPublishEvent(EventTranslatorOneArg<E, A> translator, A arg0)
{
    try
    {
        final long sequence = sequencer.tryNext();
        translateAndPublish(translator, sequence, arg0);
        return true;
    }
    catch (InsufficientCapacityException e)
    {
        return false;
    }
}
 
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:23,代码来源:RingBuffer.java

示例4: tryPublishEvents

import com.lmax.disruptor.EventTranslatorOneArg; //导入依赖的package包/类
/**
 * Allows one user supplied argument.
 *
 * @param translator    The user specified translation for each event
 * @param batchStartsAt The first element of the array which is within the batch.
 * @param batchSize     The actual size of the batch
 * @param arg0          An array of user supplied arguments, one element per event.
 * @return true if the value was published, false if there was insufficient
 *         capacity.
 * @see #tryPublishEvents(EventTranslator[])
 */
public <A> boolean tryPublishEvents(EventTranslatorOneArg<E, A> translator, int batchStartsAt, int batchSize, A[] arg0)
{
    checkBounds(arg0, batchStartsAt, batchSize);
    try
    {
        final long finalSequence = sequencer.tryNext(batchSize);
        translateAndPublishBatch(translator, arg0, batchStartsAt, batchSize, finalSequence);
        return true;
    }
    catch (InsufficientCapacityException e)
    {
        return false;
    }
}
 
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:26,代码来源:RingBuffer.java

示例5: translateAndPublish

import com.lmax.disruptor.EventTranslatorOneArg; //导入依赖的package包/类
private <A> void translateAndPublish(EventTranslatorOneArg<E, A> translator, long sequence, A arg0)
{
    try
    {
        translator.translateTo(get(sequence), sequence, arg0);
    }
    finally
    {
        sequencer.publish(sequence);
    }
}
 
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:12,代码来源:RingBuffer.java

示例6: tryPublishEvent

import com.lmax.disruptor.EventTranslatorOneArg; //导入依赖的package包/类
/**
 * Allows one user supplied argument.
 * 
 * @see #tryPublishEvent(EventTranslator)
 * @param translator The user specified translation for the event
 * @param arg0 A user supplied argument.
 * @return true if the value was published, false if there was insufficient capacity.
 */
public <A> boolean tryPublishEvent(EventTranslatorOneArg<E, A> translator, A arg0) {
    try {
        final long sequence = sequencer.tryNext();
        translateAndPublish(translator, sequence, arg0);
        return true;
    } catch (InsufficientCapacityException e) {
        return false;
    }
}
 
开发者ID:kkllwww007,项目名称:jstrom,代码行数:18,代码来源:RingBuffer.java

示例7: tryPublishEvents

import com.lmax.disruptor.EventTranslatorOneArg; //导入依赖的package包/类
/**
 * Allows one user supplied argument.
 * 
 * @param translator The user specified translation for each event
 * @param batchStartsAt The first element of the array which is within the batch.
 * @param batchSize The actual size of the batch
 * @param arg0 An array of user supplied arguments, one element per event.
 * @return true if the value was published, false if there was insufficient capacity.
 * @see #tryPublishEvents(EventTranslator[])
 */
public <A> boolean tryPublishEvents(EventTranslatorOneArg<E, A> translator, int batchStartsAt, int batchSize, A[] arg0) {
    checkBounds(arg0, batchStartsAt, batchSize);
    try {
        final long finalSequence = sequencer.tryNext(batchSize);
        translateAndPublishBatch(translator, arg0, batchStartsAt, batchSize, finalSequence);
        return true;
    } catch (InsufficientCapacityException e) {
        return false;
    }
}
 
开发者ID:kkllwww007,项目名称:jstrom,代码行数:21,代码来源:RingBuffer.java

示例8: translateAndPublish

import com.lmax.disruptor.EventTranslatorOneArg; //导入依赖的package包/类
private <A> void translateAndPublish(EventTranslatorOneArg<E, A> translator, long sequence, A arg0) {
    try {
        translator.translateTo(get(sequence), sequence, arg0);
    } finally {
        sequencer.publish(sequence);
    }
}
 
开发者ID:kkllwww007,项目名称:jstrom,代码行数:8,代码来源:RingBuffer.java

示例9: translateAndPublishBatch

import com.lmax.disruptor.EventTranslatorOneArg; //导入依赖的package包/类
private <A> void translateAndPublishBatch(final EventTranslatorOneArg<E, A> translator, final A[] arg0, int batchStartsAt, final int batchSize,
        final long finalSequence) {
    final long initialSequence = finalSequence - (batchSize - 1);
    try {
        long sequence = initialSequence;
        final int batchEndsAt = batchStartsAt + batchSize;
        for (int i = batchStartsAt; i < batchEndsAt; i++) {
            translator.translateTo(get(sequence), sequence++, arg0[i]);
        }
    } finally {
        sequencer.publish(initialSequence, finalSequence);
    }
}
 
开发者ID:kkllwww007,项目名称:jstrom,代码行数:14,代码来源:RingBuffer.java

示例10: test

import com.lmax.disruptor.EventTranslatorOneArg; //导入依赖的package包/类
@org.junit.Test
  public void test() {
  	
  	long t1 =System.currentTimeMillis();
  	
  	for (int i = 0;i < 10;i++) {
       new Thread() {
           @Override
           public void run() {
               for (int j = 0; j < count; j++) {
                   disruptor.getRingBuffer().publishEvent(new EventTranslatorOneArg<Event, Integer>() {
	
					@Override
					public void translateTo(Event event,
							long sequence, Integer arg0) {
						event.setValue(arg0);
					}
                   	
                   }, j);
               }
           }
       }.start();
  	}
  	
  	try {
	cdh1.await();
} catch (InterruptedException e) {
	e.printStackTrace();
}
  	
  	System.out.println("count " + counter.get());
  	
  	System.out.println(System.currentTimeMillis() -  t1);
  }
 
开发者ID:Jakegogo,项目名称:concurrent,代码行数:35,代码来源:Test8.java

示例11: AsyncConcurrentBatchingProcessor

import com.lmax.disruptor.EventTranslatorOneArg; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public AsyncConcurrentBatchingProcessor(BatchProcessor<T> processor, EventFactory<T> factory, EventTranslatorOneArg<T,T> translator ){
	Executor executor = Executors.newSingleThreadExecutor();
	int bufferSize = 1024;		
	m_disruptor = new Disruptor<T>(factory, bufferSize, executor);
	m_disruptor.handleEventsWith(this);
	m_buffer = m_disruptor.start();
	m_processor = processor;
	m_translator = translator;
}
 
开发者ID:davruet,项目名称:shenanigans.io,代码行数:11,代码来源:AsyncConcurrentBatchingProcessor.java

示例12: publishEvents

import com.lmax.disruptor.EventTranslatorOneArg; //导入依赖的package包/类
private void publishEvents(int size, RingBuffer<T> valueEventRingBuffer) {
    final EventTranslatorOneArg<T, Long> eventTranslator = new EventTranslatorOneArg<T, Long>() {
        @Override
        public void translateTo(T event, long sequence, Long arg0) {
            eventFactory.setEventValue(event, arg0);
        }
    };
    for(long i = 0; i < size; i++) {
        valueEventRingBuffer.publishEvent(eventTranslator, i);
    }
}
 
开发者ID:4BitBen,项目名称:disruptor-vs-queue,代码行数:12,代码来源:EventHandlerRunner.java

示例13: getEventTranslator

import com.lmax.disruptor.EventTranslatorOneArg; //导入依赖的package包/类
public EventTranslatorOneArg<DisruptorEvent, Object> getEventTranslator() {
	return eventTranslator;
}
 
开发者ID:vindell,项目名称:spring-boot-starter-disruptor,代码行数:4,代码来源:DisruptorApplicationContext.java

示例14: setEventTranslator

import com.lmax.disruptor.EventTranslatorOneArg; //导入依赖的package包/类
public void setEventTranslator(EventTranslatorOneArg<DisruptorEvent, Object> eventTranslator) {
	this.eventTranslator = eventTranslator;
}
 
开发者ID:vindell,项目名称:spring-boot-starter-disruptor,代码行数:4,代码来源:DisruptorApplicationContext.java

示例15: eventTranslator

import com.lmax.disruptor.EventTranslatorOneArg; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public EventTranslatorOneArg<DisruptorEvent, Object> eventTranslator() {
	return new DisruptorEventTranslator();
}
 
开发者ID:vindell,项目名称:spring-boot-starter-disruptor,代码行数:6,代码来源:DisruptorAutoConfiguration.java


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