本文整理汇总了Java中com.lmax.disruptor.RingBuffer.get方法的典型用法代码示例。如果您正苦于以下问题:Java RingBuffer.get方法的具体用法?Java RingBuffer.get怎么用?Java RingBuffer.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lmax.disruptor.RingBuffer
的用法示例。
在下文中一共展示了RingBuffer.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: channelRead0
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, O msg) throws Exception {
UUID uuid = CHANNEL_UUID.get(ctx.channel());
if (null != uuid) {
NetSession session = SESSIONS.get(uuid);
if (null != session) {
RingBuffer<ConcurrentEvent> ringBuffer = THREAD_LOCAL.get().getRingBuffer();
long next = ringBuffer.next();
try {
ConcurrentEvent commandEvent = ringBuffer.get(next);
commandEvent.setValues(newExecutor(session, msg));
} finally {
ringBuffer.publish(next);
}
}
}
}
示例2: channelRead0
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, O msg) throws Exception {
UUID uuid = CHANNEL_UUID.get(ctx.channel());
if (null != uuid) {
Session session = SESSIONS.get(uuid);
if (null != session) {
RingBuffer<ConcurrentEvent> ringBuffer = THREAD_LOCAL.get().getRingBuffer();
long next = ringBuffer.next();
try {
ConcurrentEvent commandEvent = ringBuffer.get(next);
commandEvent.setValues(newExecutor(session, msg));
} finally {
ringBuffer.publish(next);
}
}
}
}
示例3: synchronousFire
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
@Override
public void synchronousFire( final Object event ) {
eventCount.increment();
CountDownLatch latch = new CountDownLatch( handlers.size() );
try {
RingBuffer<StatisticEventHolder> ringBuffer = disruptor.getRingBuffer();
long sequence = ringBuffer.next();
try {
StatisticEventHolder holder = ringBuffer.get( sequence );
holder.set( event );
holder.setLatch( latch );
} finally {
ringBuffer.publish( sequence );
}
latch.await();
} catch ( InterruptedException e ) {
return;
}
}
示例4: channelRead0
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, GpcCall msg) throws Exception {
NetSession session = NET_SESSION_MAP.get(ctx.channel().id());
if (null == session)
return;
RingBuffer<ConcurrentEvent> ringBuffer = THREAD_LOCAL.get().getRingBuffer();
long next = ringBuffer.next();
try {
ConcurrentEvent commandEvent = ringBuffer.get(next);
commandEvent.setValues(newExecutor(session, msg));
} finally {
ringBuffer.publish(next);
}
}
示例5: channelRead0
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, O msg) throws Exception {
NetSession session = SESSIONS.get(ctx.channel().id());
if (null == session) {
return;
}
RingBuffer<ConcurrentEvent> ringBuffer = THREAD_LOCAL.get().getRingBuffer();
long next = ringBuffer.next();
try {
ConcurrentEvent commandEvent = ringBuffer.get(next);
commandEvent.setValues(newExecutor(session, msg));
} finally {
ringBuffer.publish(next);
}
}
示例6: runDisruptorPass
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
@Override
protected long runDisruptorPass() throws InterruptedException
{
final CountDownLatch latch = new CountDownLatch(1);
long expectedCount = batchEventProcessor.getSequence().get() + ITERATIONS;
handler.reset(latch, ITERATIONS);
executor.submit(batchEventProcessor);
long start = System.currentTimeMillis();
final RingBuffer<long[]> rb = ringBuffer;
for (long i = 0; i < ITERATIONS; i++)
{
long next = rb.next();
long[] event = rb.get(next);
for (int j = 0; j < event.length; j++)
{
event[j] = i;
}
rb.publish(next);
}
latch.await();
long opsPerSecond = (ITERATIONS * ARRAY_SIZE * 1000L) / (System.currentTimeMillis() - start);
waitForEventProcessorSequence(expectedCount);
batchEventProcessor.halt();
PerfTestUtil.failIf(0, handler.getValue());
return opsPerSecond;
}
开发者ID:winwill2012,项目名称:disruptor-code-analysis,代码行数:32,代码来源:OneToOneSequencedLongArrayThroughputTest.java
示例7: runDisruptorPass
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
@Override
protected long runDisruptorPass() throws Exception
{
byte[] data = this.data;
final CountDownLatch latch = new CountDownLatch(1);
long expectedCount = processor.getSequence().get() + ITERATIONS;
handler.reset(latch, ITERATIONS);
executor.execute(processor);
long start = System.currentTimeMillis();
final RingBuffer<ByteBuffer> rb = buffer;
for (long i = 0; i < ITERATIONS; i++)
{
long next = rb.next();
ByteBuffer event = rb.get(next);
event.clear();
event.put(data);
event.flip();
rb.publish(next);
}
latch.await();
long opsPerSecond = (ITERATIONS * 1000L) / (System.currentTimeMillis() - start);
waitForEventProcessorSequence(expectedCount);
processor.halt();
return opsPerSecond;
}
示例8: publish
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
/**
* Publish record task to record special table's log.
*
* @param struct The table struct.
* @param list The log data list.
*/
public void publish(Struct struct, List<String[]> list) {
RingBuffer<LogRecordTask> rb = disruptor.getRingBuffer();
long next = rb.next();
try {
LogRecordTask event = rb.get(next);
event.setValues(struct, list);
} finally {
rb.publish(next);
}
}
示例9: onNext
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
public static <E> void onNext(E value, RingBuffer<MutableSignal<E>> ringBuffer) {
if (value == null) {
throw SpecificationExceptions.spec_2_13_exception();
}
final long seqId = ringBuffer.next();
final MutableSignal<E> signal = ringBuffer.get(seqId);
signal.type = MutableSignal.Type.NEXT;
signal.value = value;
ringBuffer.publish(seqId);
}
示例10: onError
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
public static <E> void onError(Throwable error, RingBuffer<MutableSignal<E>> ringBuffer) {
if (error == null) {
throw SpecificationExceptions.spec_2_13_exception();
}
final long seqId = ringBuffer.next();
final MutableSignal<E> signal = ringBuffer.get(seqId);
signal.type = MutableSignal.Type.ERROR;
signal.value = null;
signal.error = error;
ringBuffer.publish(seqId);
}
示例11: onComplete
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
public static <E> void onComplete(RingBuffer<MutableSignal<E>> ringBuffer) {
final long seqId = ringBuffer.next();
final MutableSignal<E> signal = ringBuffer.get(seqId);
signal.type = MutableSignal.Type.COMPLETE;
signal.value = null;
signal.error = null;
ringBuffer.publish(seqId);
}
示例12: main
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
public static void main(String[] args) {
final List<ValueEventHandler1PMC> handlers = new ArrayList<>(NUMBER_CONSUMERS);
RingBuffer<ValueEvent> ringBuffer = RingBuffer.createSingleProducer(
ValueEvent.EVENT_FACTORY, RING_SIZE, new SleepingWaitStrategy());
start = System.nanoTime();
//Create consumers
for(int i = 0; i < NUMBER_CONSUMERS; i++) {
ValueEventHandler1PMC handler = new ValueEventHandler1PMC(start, handlers);
handlers.add(handler);
SequenceBarrier barrier = ringBuffer.newBarrier();
BatchEventProcessor<ValueEvent> eventProcessor = new BatchEventProcessor<ValueEvent>(
ringBuffer, barrier, handler);
ringBuffer.addGatingSequences(eventProcessor.getSequence());
// Each EventProcessor can run on a separate thread
EXECUTOR.submit(eventProcessor);
}
for(int i = 0; i < SAMPLES_SIZE; i++) {
// Publishers claim events in sequence
long sequence = ringBuffer.next();
ValueEvent event = ringBuffer.get(sequence);
event.setValue(i); // this could be more complex with multiple fields
// make the event available to EventProcessors
ringBuffer.publish(sequence);
}
}
示例13: channelRead0
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, O msg) throws Exception {
Session session = SESSIONS.get(ctx.channel().id());
if (null == session) {
return;
}
RingBuffer<ConcurrentEvent> ringBuffer = THREAD_LOCAL.get().getRingBuffer();
long next = ringBuffer.next();
try {
ConcurrentEvent commandEvent = ringBuffer.get(next);
commandEvent.setValues(newExecutor(session, msg));
} finally {
ringBuffer.publish(next);
}
}
示例14: fire
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
@Override
public void fire( final Object event ) {
eventCount.increment();
RingBuffer<StatisticEventHolder> ringBuffer = disruptor.getRingBuffer();
long sequence = ringBuffer.next();
try {
StatisticEventHolder holder = ringBuffer.get( sequence );
holder.set( event );
holder.setLatch( null );
} finally {
ringBuffer.publish( sequence );
}
}
示例15: run
import com.lmax.disruptor.RingBuffer; //导入方法依赖的package包/类
@Override
public void run(){
_logger.info("Node run starting...");
Executor executor = Executors.newCachedThreadPool();
Disruptor<SurfEvent> disruptor = new Disruptor<>(SurfEvent.EVENT_FACTORY, 128, executor);
disruptor.handleEventsWith(this);
RingBuffer<SurfEvent> buffer = disruptor.start();
VDSEventListImpl events = null;
while(!_shutdown){
try{
events = _eventListPool.borrowObject(0);
while(events.getEventsList().isEmpty()) {
_source.read(events);
}
if(_needsAck){
Object obj = _acksource.getInputObject();
// Hacking this in for now
// Need to actually ack the object after Kinesis consumes it: TODO
_acksource.updateInputObject(obj);
}
long seq = buffer.next();
SurfEvent event = buffer.get(seq);
event.setEventlist(events);
buffer.publish(seq);
}
catch(Exception ex){
_logger.error("Exception while reading data:", ex);
ex.printStackTrace();
}
}
}