本文整理汇总了Java中com.lmax.disruptor.dsl.Disruptor.start方法的典型用法代码示例。如果您正苦于以下问题:Java Disruptor.start方法的具体用法?Java Disruptor.start怎么用?Java Disruptor.start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lmax.disruptor.dsl.Disruptor
的用法示例。
在下文中一共展示了Disruptor.start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException
{
Disruptor<ObjectBox> disruptor = new Disruptor<ObjectBox>(
ObjectBox.FACTORY, RING_SIZE, Executors.newCachedThreadPool(), ProducerType.MULTI,
new BlockingWaitStrategy());
disruptor.handleEventsWith(new Consumer()).then(new Consumer());
final RingBuffer<ObjectBox> ringBuffer = disruptor.getRingBuffer();
Publisher p = new Publisher();
IMessage message = new IMessage();
ITransportable transportable = new ITransportable();
String streamName = "com.lmax.wibble";
System.out.println("publishing " + RING_SIZE + " messages");
for (int i = 0; i < RING_SIZE; i++)
{
ringBuffer.publishEvent(p, message, transportable, streamName);
Thread.sleep(10);
}
System.out.println("start disruptor");
disruptor.start();
System.out.println("continue publishing");
while (true)
{
ringBuffer.publishEvent(p, message, transportable, streamName);
Thread.sleep(10);
}
}
示例2: Source
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
/**
* Create a new source.
* <p>This method will prepare the instance with some needed variables
* in order to be started later with the start method (implemented by children).
*
* @param parsersManager Instance of ParserManager that will serve parsers to this source instance
* @param eventHandler Instance of EventHandler that will receive the events generated by this source instance
* @param properties Map of properties associated with this source
*/
public Source(ParsersManager parsersManager, EventHandler eventHandler, Map<String, Object> properties) {
// Save the references for later use
this.parsersManager = parsersManager;
this.properties = properties;
// Create the ring buffer for this topic and start it
Disruptor<MapEvent> disruptor = new Disruptor<>(new MapEventFactory(), ConfigData.getRingBufferSize(), Executors.newCachedThreadPool());
disruptor.handleEventsWith(eventHandler);
disruptor.start();
// Create the event producer that will receive the events produced by
// this source instance
eventProducer = new EventProducer(disruptor.getRingBuffer());
prepare();
}
示例3: qndSingleThread
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
static void qndSingleThread(int numItems) {
final AtomicLong COUNTER_RECEIVED = new AtomicLong(0);
final Disruptor<LongEvent> disruptor = new Disruptor<>(LongEvent.FACTORY, 128,
Executors.defaultThreadFactory(), ProducerType.MULTI, new YieldingWaitStrategy());
disruptor.handleEventsWith(
(event, sequence, endOfBatch) -> COUNTER_RECEIVED.incrementAndGet());
disruptor.start();
final long t = System.currentTimeMillis();
for (int i = 0; i < numItems; i++) {
disruptor.publishEvent((event, seq) -> event.set(seq));
}
long d = System.currentTimeMillis() - t;
NumberFormat nf = NumberFormat.getInstance();
System.out.println("========== qndSingleThread:");
System.out.println("Sent: " + nf.format(numItems) + " / Received: "
+ nf.format(COUNTER_RECEIVED.get()) + " / Duration: " + d + " / Speed: "
+ NumberFormat.getInstance().format((numItems * 1000.0 / d)) + " items/sec");
disruptor.shutdown();
}
示例4: createDisruptor
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
protected Disruptor<BaseEvent> createDisruptor(Class<?> eventClass, List<RegistedEventHandler> registedEventHandlers) {
WaitStrategy waitStrategy = new BlockingWaitStrategy();
// load the customized event bufferSize.
int bufferSize = EventUtils.getEventBufferSize(eventClass);
Disruptor<BaseEvent> disruptor =new Disruptor<BaseEvent>(new BaseEventFactory(),
bufferSize, Executors.newCachedThreadPool(), ProducerType.SINGLE, waitStrategy);
List<BaseEventHandler> baseEventHandlers = Lists.newArrayList();
EventType eventType = EventUtils.getEventType(eventClass);
if(EventType.ORDER.equals(eventType)) {
List<RegistedEventHandler> orderingHandlers = orderingRegistedEventHandlers(registedEventHandlers);
baseEventHandlers.add(new BaseEventHandler(EventType.ORDER, orderingHandlers.toArray(new RegistedEventHandler[0])));
} else if(EventType.CONCURRENCY.equals(eventType)) {
for(RegistedEventHandler registedEventHandler : registedEventHandlers) {
baseEventHandlers.add(new BaseEventHandler(EventType.CONCURRENCY, registedEventHandler));
}
} else {
throw new RuntimeException("The definition of event type is not correct.");
}
disruptor.handleEventsWith(baseEventHandlers.toArray(new BaseEventHandler[0]));
disruptor.start();
return disruptor;
}
示例5: main
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static void main(String[] args) throws InterruptedException {
//Executor that will be used to construct new threads for consumers
Executor executor = Executors.newCachedThreadPool();
//Specify the size of the ring buffer, must be power of 2.
int bufferSize = 1024;
//Disruptor<ObjectEvent> disruptor = new Disruptor<>(ObjectEvent::new, bufferSize, executor);
Disruptor<ObjectEvent> disruptor = new Disruptor<>(ObjectEvent::new, bufferSize, executor,
ProducerType.SINGLE, new LiteBlockingWaitStrategy());
disruptor.handleEventsWith(App::handleEvent1);
disruptor.handleEventsWith(App::handleEvent2);
//disruptor.handleEventsWith((event, sequence, endOfBatch) -> System.out.println("Event: " + event.getObject()));
disruptor.start();
produceEvents(disruptor);
}
示例6: createWorker
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
public static Worker createWorker(File conf, EventHandler<KinesisEvent> handler, String appName)throws IOException{
Executor executor = Executors.newCachedThreadPool();
Disruptor<KinesisEvent> disruptor = new Disruptor<>(KinesisEvent.EVENT_FACTORY, 128, executor);
disruptor.handleEventsWith(handler);
RingBuffer<KinesisEvent> buffer = disruptor.start();
Properties props = new Properties();
props.load(new FileReader(conf));
// Generate a unique worker ID
String workerId = InetAddress.getLocalHost().getCanonicalHostName() + ":" + UUID.randomUUID();
String accessid = props.getProperty("aws-access-key-id");
String secretkey = props.getProperty("aws-secret-key");
String streamname = props.getProperty("aws-kinesis-stream-name");
BasicAWSCredentials creds = new BasicAWSCredentials(accessid, secretkey);
CredProvider credprovider = new CredProvider(creds);
KinesisClientLibConfiguration config = new KinesisClientLibConfiguration(appName, streamname, credprovider, workerId);
Worker worker = new Worker(new RecordProcessorFactory(buffer), config, new MetricsFactory());
return worker;
}
示例7: main
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
public static void main(String[] args) {
ExecutorService executor = Executors.newCachedThreadPool();
int bufferSize = 1024;
WaitStrategy ws = new BlockingWaitStrategy();
Disruptor<CpuUsageEvent> disruptor = new Disruptor<>(factory, bufferSize, executor, ProducerType.SINGLE, ws);
disruptor.handleEventsWith(handler);
RingBuffer<CpuUsageEvent> ringBuffer = disruptor.start();
publishEvents(ringBuffer);
disruptor.shutdown();
executor.shutdown();
}
示例8: main
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的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();
}
示例9: initialValue
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
@Override
protected Disruptor<ConcurrentEvent> initialValue() {
Disruptor<ConcurrentEvent> disruptor = new Disruptor<>(
ConcurrentEventFactory.DEFAULT, DEFAULT_RING_BUFFER_SIZE, CACHED_THREAD_POOL, ProducerType.SINGLE, new BlockingWaitStrategy());
disruptor.handleEventsWith(new ConcurrentHandler());
// disruptor.handleExceptionsWith();
disruptor.start();
return disruptor;
}
示例10: main
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Executor executor = Executors.newCachedThreadPool();
LongEventFactory eventFactory = new LongEventFactory();
int bufferSize = 1024;
// Disruptor<LongEvent> disruptor = new Disruptor<LongEvent>(eventFactory, bufferSize, executor);
// disruptor.handleEventsWith(new LongEventHandler());
// disruptor.start();
Disruptor<LongEvent> disruptor = new Disruptor<>(LongEvent::new, bufferSize, executor);
disruptor.handleEventsWith((event, sequence, endOfBatch) -> {System.out.println("Event: " + event);
System.out.println("CurrentThreadName:" + Thread.currentThread().getName());
});
disruptor.start();
RingBuffer<LongEvent> ringBuffer = disruptor.getRingBuffer();
LongEventProducer producer = new LongEventProducer(ringBuffer);
ByteBuffer bb = ByteBuffer.allocate(8);
for (long l = 0; true; l++) {
bb.putLong(0, l);
ringBuffer.publishEvent((event, sequence, buffer) -> event.set(buffer.getLong(0)), bb);
// producer.onData(bb);
//Thread.sleep(1000);
}
}
示例11: OneToOneTranslatorThroughputTest
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public OneToOneTranslatorThroughputTest()
{
Disruptor<ValueEvent> disruptor =
new Disruptor<ValueEvent>(
ValueEvent.EVENT_FACTORY,
BUFFER_SIZE, executor,
ProducerType.SINGLE,
new YieldingWaitStrategy());
disruptor.handleEventsWith(handler);
this.ringBuffer = disruptor.start();
}
示例12: main
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
public static void main(String[] args)
{
Executor executor = Executors.newFixedThreadPool(4);
Disruptor<DataEvent> disruptor = new Disruptor<DataEvent>(
DataEvent.FACTORY, 1024, DaemonThreadFactory.INSTANCE);
TransformingHandler handler1 = new TransformingHandler(0);
TransformingHandler handler2 = new TransformingHandler(1);
TransformingHandler handler3 = new TransformingHandler(2);
CollatingHandler collator = new CollatingHandler();
disruptor.handleEventsWith(handler1, handler2, handler3).then(collator);
disruptor.start();
}
示例13: main
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException
{
ExecutorService executor = Executors.newCachedThreadPool(DaemonThreadFactory.INSTANCE);
// Build a disruptor and start it.
Disruptor<StubEvent> disruptor = new Disruptor<StubEvent>(
StubEvent.EVENT_FACTORY, 1024, DaemonThreadFactory.INSTANCE);
RingBuffer<StubEvent> ringBuffer = disruptor.start();
// Construct 2 batch event processors.
DynamicHandler handler1 = new DynamicHandler();
BatchEventProcessor<StubEvent> processor1 =
new BatchEventProcessor<StubEvent>(ringBuffer, ringBuffer.newBarrier(), handler1);
DynamicHandler handler2 = new DynamicHandler();
BatchEventProcessor<StubEvent> processor2 =
new BatchEventProcessor<StubEvent>(ringBuffer, ringBuffer.newBarrier(processor1.getSequence()), handler2);
// Dynamically add both sequences to the ring buffer
ringBuffer.addGatingSequences(processor1.getSequence(), processor2.getSequence());
// Start the new batch processors.
executor.execute(processor1);
executor.execute(processor2);
// Remove a processor.
// Stop the processor
processor2.halt();
// Wait for shutdown the complete
handler2.awaitShutdown();
// Remove the gating sequence from the ring buffer
ringBuffer.removeGatingSequence(processor2.getSequence());
}
示例14: main
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的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));
}
示例15: start
import com.lmax.disruptor.dsl.Disruptor; //导入方法依赖的package包/类
private void start() throws Exception {
LOGGER.debug("Starting disruptor {}", this);
Disruptor<ExchangeEvent> newDisruptor = createDisruptor();
newDisruptor.start();
if (executor != null) {
//and use our delayed executor to really really execute the event handlers now
delayedExecutor.executeDelayedCommands(executor);
}
//make sure all event handlers are correctly started before we continue
for (final LifecycleAwareExchangeEventHandler handler : handlers) {
boolean eventHandlerStarted = false;
while (!eventHandlerStarted) {
try {
//The disruptor start command executed above should have triggered a start signal to all
//event processors which, in their death, should notify our event handlers. They respond by
//switching a latch and we want to await that latch here to make sure they are started.
if (!handler.awaitStarted(10, TimeUnit.SECONDS)) {
//we wait for a relatively long, but limited amount of time to prevent an application using
//this component from hanging indefinitely
//Please report a bug if you can reproduce this
LOGGER.error("Disruptor/event handler failed to start properly, PLEASE REPORT");
}
eventHandlerStarted = true;
} catch (InterruptedException e) {
//just retry
}
}
}
publishBufferedExchanges(newDisruptor);
disruptor.set(newDisruptor, false);
}