本文整理汇总了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);
}
}
示例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) {};
});
}
示例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;
}
}
示例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;
}
}
示例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);
}
}
示例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;
}
}
示例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;
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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;
}
示例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);
}
}
示例13: getEventTranslator
import com.lmax.disruptor.EventTranslatorOneArg; //导入依赖的package包/类
public EventTranslatorOneArg<DisruptorEvent, Object> getEventTranslator() {
return eventTranslator;
}
示例14: setEventTranslator
import com.lmax.disruptor.EventTranslatorOneArg; //导入依赖的package包/类
public void setEventTranslator(EventTranslatorOneArg<DisruptorEvent, Object> eventTranslator) {
this.eventTranslator = eventTranslator;
}
示例15: eventTranslator
import com.lmax.disruptor.EventTranslatorOneArg; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public EventTranslatorOneArg<DisruptorEvent, Object> eventTranslator() {
return new DisruptorEventTranslator();
}