Java Code Examples for com.lmax.disruptor.dsl.ProducerType.SINGLE

The following are Jave code examples for showing how to use SINGLE of the com.lmax.disruptor.dsl.ProducerType class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: nuls   File: DisruptorUtil.java   View Source Code Vote up 6 votes
/**
 * create a disruptor
 *
 * @param name           The title of the disruptor
 * @param ringBufferSize The size of ringBuffer
 */
public void createDisruptor(String name, int ringBufferSize) {
    if (DISRUPTOR_MAP.keySet().contains(name)) {
        throw new NulsRuntimeException(ErrorCode.FAILED, "create disruptor faild,the name is repetitive!");
    }

    Disruptor<DisruptorEvent> disruptor = new Disruptor<DisruptorEvent>(EVENT_FACTORY,
            ringBufferSize, new NulsThreadFactory(ModuleService.getInstance().getModuleId(EventBusModuleBootstrap.class),name), ProducerType.SINGLE,
            new SleepingWaitStrategy());
    disruptor.handleEventsWith(new EventHandler<DisruptorEvent>() {
        @Override
        public void onEvent(DisruptorEvent disruptorEvent, long l, boolean b) throws Exception {
            Log.debug(disruptorEvent.getData() + "");
        }
    });
    DISRUPTOR_MAP.put(name, disruptor);
}
 
Example 2
Project: jstorm-0.9.6.3-   File: DisruptorQueueImpl.java   View Source Code Vote up 6 votes
public DisruptorQueueImpl(String queueName, ProducerType producerType,
		int bufferSize, WaitStrategy wait) {
	this._queueName = PREFIX + queueName;
	_buffer = RingBuffer.create(producerType, new ObjectEventFactory(),
			bufferSize, wait);
	_consumer = new Sequence();
	_barrier = _buffer.newBarrier();
	_buffer.addGatingSequences(_consumer);
	if (producerType == ProducerType.SINGLE) {
		consumerStartedFlag = true;
	} else {
		// make sure we flush the pending messages in cache first
		if (bufferSize < 2) {
			throw new RuntimeException("QueueSize must >= 2");
		}
		try {
			publishDirect(FLUSH_CACHE, true);
		} catch (InsufficientCapacityException e) {
			throw new RuntimeException("This code should be unreachable!",
					e);
		}
	}
}
 
Example 3
Project: learn_jstorm   File: DisruptorQueueImpl.java   View Source Code Vote up 6 votes
public DisruptorQueueImpl(String queueName, ProducerType producerType,
		int bufferSize, WaitStrategy wait) {
	this._queueName = PREFIX + queueName;
	_buffer = RingBuffer.create(producerType, new ObjectEventFactory(),
			bufferSize, wait);
	_consumer = new Sequence();
	_barrier = _buffer.newBarrier();
	_buffer.addGatingSequences(_consumer);
	if (producerType == ProducerType.SINGLE) {
		consumerStartedFlag = true;
	} else {
		// make sure we flush the pending messages in cache first
		if (bufferSize < 2) {
			throw new RuntimeException("QueueSize must >= 2");
		}
		try {
			publishDirect(FLUSH_CACHE, true);
		} catch (InsufficientCapacityException e) {
			throw new RuntimeException("This code should be unreachable!",
					e);
		}
	}
}
 
Example 4
Project: jstrom   File: DisruptorQueueImpl.java   View Source Code Vote up 6 votes
public DisruptorQueueImpl(String queueName, ProducerType producerType, int bufferSize, WaitStrategy wait) {
    this._queueName = PREFIX + queueName;
    _buffer = RingBuffer.create(producerType, new ObjectEventFactory(), bufferSize, wait);
    _consumer = new Sequence();
    _barrier = _buffer.newBarrier();
    _buffer.addGatingSequences(_consumer);
    if (producerType == ProducerType.SINGLE) {
        consumerStartedFlag = true;
    } else {
        // make sure we flush the pending messages in cache first
        if (bufferSize < 2) {
            throw new RuntimeException("QueueSize must >= 2");
        }
        try {
            publishDirect(FLUSH_CACHE, true);
        } catch (InsufficientCapacityException e) {
            throw new RuntimeException("This code should be unreachable!", e);
        }
    }
}
 
Example 5
Project: Scaled-ML   File: AbstractParallelModule.java   View Source Code Vote up 6 votes
@Provides
@Singleton
@Named("disruptor")
@SuppressWarnings("Unchecked")
protected Disruptor<TwoPhaseEvent<T>> inputDisruptor(Provider<WorkHandler<TwoPhaseEvent<T>>> workHandlerProvider,
                                                     Provider<EventHandler<TwoPhaseEvent<T>>> evenHandlerProvider) {
    Disruptor<TwoPhaseEvent<T>> disruptor = new Disruptor<>(
            TwoPhaseEvent.factory(outputEventFactory()),
            options.ringSize(), threadsProvider,
            ProducerType.SINGLE, new SleepingWaitStrategy());
    WorkHandler<TwoPhaseEvent<T>>[] parsers = new WorkHandler[options.threads()];
    for (int i = 0; i < options.threads(); i++) {
        parsers[i] = workHandlerProvider.get();
    }
    disruptor.handleExceptionsWith(new FatalExceptionHandler());
    disruptor.handleEventsWithWorkerPool(parsers).then(evenHandlerProvider.get());
    return disruptor;
}
 
Example 6
Project: Scaled-ML   File: FeatureEngineeringModule.java   View Source Code Vote up 6 votes
@Provides
@Singleton
@Named("firstPassDisruptor")
public Disruptor<TwoPhaseEvent<Void>> firstPassDisruptor(
        Provider<WorkHandler<TwoPhaseEvent<Void>>> statisticsHandlerProvider) {
    Disruptor<TwoPhaseEvent<Void>> disruptor = new Disruptor<>(
            TwoPhaseEvent.factory(() -> null),
            options.ringSize(), threadsProvider,
            ProducerType.SINGLE, new SleepingWaitStrategy());
    WorkHandler<TwoPhaseEvent<Void>>[] parsers = new WorkHandler[options.threads()];
    for (int i = 0; i < options.threads(); i++) {
        parsers[i] = statisticsHandlerProvider.get();
    }
    disruptor.handleExceptionsWith(new FatalExceptionHandler());
    disruptor.handleEventsWithWorkerPool(parsers);
    return disruptor;
}
 
Example 7
Project: Scaled-ML   File: FeatureEngineeringModule.java   View Source Code Vote up 6 votes
@Provides
@Singleton
@Named("secondPassDisruptor")
public Disruptor<TwoPhaseEvent<SparseItem>> secondPassDisruptor(
        Provider<WorkHandler<TwoPhaseEvent<SparseItem>>> binningHandlerProvider,
        Provider<EventHandler<TwoPhaseEvent<SparseItem>>> outputHandlerProvider) {
    Disruptor<TwoPhaseEvent<SparseItem>> disruptor = new Disruptor<>(
            TwoPhaseEvent.factory(SparseItem::new),
            options.ringSize(), threadsProvider,
            ProducerType.SINGLE, new SleepingWaitStrategy());
    WorkHandler<TwoPhaseEvent<SparseItem>>[] parsers = new WorkHandler[options.threads()];
    for (int i = 0; i < options.threads(); i++) {
        parsers[i] = binningHandlerProvider.get();
    }
    disruptor.handleExceptionsWith(new FatalExceptionHandler());
    disruptor.handleEventsWithWorkerPool(parsers)
            .then(outputHandlerProvider.get());
    return disruptor;
}
 
Example 8
Project: Tstream   File: DisruptorQueueImpl.java   View Source Code Vote up 6 votes
public DisruptorQueueImpl(String queueName, ProducerType producerType,
		int bufferSize, WaitStrategy wait) {
	this._queueName = PREFIX + queueName;
	_buffer = RingBuffer.create(producerType, new ObjectEventFactory(),
			bufferSize, wait);
	_consumer = new Sequence();
	_barrier = _buffer.newBarrier();
	_buffer.addGatingSequences(_consumer);
	if (producerType == ProducerType.SINGLE) {
		consumerStartedFlag = true;
	} else {
		// make sure we flush the pending messages in cache first
		if (bufferSize < 2) {
			throw new RuntimeException("QueueSize must >= 2");
		}
		try {
			publishDirect(FLUSH_CACHE, true);
		} catch (InsufficientCapacityException e) {
			throw new RuntimeException("This code should be unreachable!",
					e);
		}
	}
}
 
Example 9
Project: pinenut   File: PersonHelper.java   View Source Code Vote up 6 votes
public PersonHelper() {
    //参数1 事件
    //参数2 单线程使用
    //参数3 等待策略
    EventFactory<PersonEvent> eventFactory = PersonEvent.EVENT_FACTORY;
    ExecutorService executor = Executors.newSingleThreadExecutor();
    int ringBufferSize = 4; // RingBuffer 大小,必须是 2 的 N 次方;

    Disruptor<PersonEvent> disruptor = new Disruptor<>(eventFactory,
            ringBufferSize, executor, ProducerType.SINGLE,
            new YieldingWaitStrategy());

    ringBuffer = disruptor.getRingBuffer();
    //获取生产者的位置信息
    sequenceBarrier = ringBuffer.newBarrier();
    //消费者
    handler = new PersonEventHandler();
    //事件处理器,监控指定ringBuffer,有数据时通知指定handler进行处理
    batchEventProcessor = new BatchEventProcessor<>(ringBuffer, sequenceBarrier, handler);
    //传入所有消费者线程的序号
//        ringBuffer.setGatingSequences(batchEventProcessor.getSequence());

  }
 
Example 10
Project: scala-playground   File: Main.java   View Source Code Vote up 5 votes
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();
}
 
Example 11
Project: jaf-examples   File: DisruptorPublisher.java   View Source Code Vote up 5 votes
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);
  }
 
Example 12
Project: jaf-examples   File: Main.java   View Source Code Vote up 5 votes
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();

}
 
Example 13
Project: Okra-Ax   File: DisruptorAdapterHandler.java   View Source Code Vote up 5 votes
@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;
        }
 
Example 14
Project: Okra-Ax   File: DisruptorAdapterBy41xHandler.java   View Source Code Vote up 5 votes
@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;
        }
 
Example 15
Project: disruptor-code-analysis   File: OneToOneTranslatorThroughputTest.java   View Source Code Vote up 5 votes
@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();
}
 
Example 16
Project: disruptor-code-analysis   File: SequencerTest.java   View Source Code Vote up 5 votes
@Parameters
public static Collection<Object[]> generateData()
{
    Object[][] allocators =
        {
            {ProducerType.SINGLE, new BlockingWaitStrategy()},
            {ProducerType.MULTI, new BlockingWaitStrategy()},
        };
    return Arrays.asList(allocators);
}
 
Example 17
Project: disruptor-code-analysis   File: ShutdownOnFatalExceptionTest.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
@Before
public void setUp()
{
    disruptor = new Disruptor<byte[]>(
        new ByteArrayFactory(256), 1024, Executors.newCachedThreadPool(), ProducerType.SINGLE,
        new BlockingWaitStrategy());
    disruptor.handleEventsWith(eventHandler);
    disruptor.setDefaultExceptionHandler(new FatalExceptionHandler());
}
 
Example 18
Project: disruptorDemo   File: Demo3.java   View Source Code Vote up 5 votes
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));
		
	}
 
Example 19
Project: simple-actor   File: ActorExecutor.java   View Source Code Vote up 5 votes
public ActorExecutor(int bufferSize, Executor executor) {
    this.bufferSize = bufferSize;
    this.executor   = executor;
    disruptor = new Disruptor<>(new ActorEvent.ActorEventFactory(),
            bufferSize, executor
            ,ProducerType.SINGLE, new PhasedBackoffWaitStrategy(2,2, TimeUnit.MILLISECONDS,new YieldingWaitStrategy()));
    ringBuffer = disruptor.getRingBuffer();
    disruptor.handleEventsWith(new ActorHandler(this));
    disruptor.start();
}
 
Example 20
Project: silverflash   File: MessageBuffer.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
public void start() {
  if (isRunning.compareAndSet(false, true)) {
    this.disruptor =
        new Disruptor<>(BufferEvent.EVENT_FACTORY, ringSize, threadFactory, ProducerType.SINGLE,
            new BusySpinWaitStrategy());
    this.disruptor.handleEventsWith(this::handleEvent);
    this.ringBuffer = disruptor.start();
  }
}
 
Example 21
Project: silverflash   File: BufferedTransportConsumer.java   View Source Code Vote up 5 votes
@Override
public CompletableFuture<? extends Service> open() {
  if (isRunning.compareAndSet(false, true)) {
    this.disruptor = new Disruptor<>(BufferEvent.EVENT_FACTORY, ringSize, threadFactory,
        ProducerType.SINGLE, new BusySpinWaitStrategy());
    this.disruptor.handleEventsWith(this::onEvent);
    this.ringBuffer = disruptor.start();
  }
  return CompletableFuture.completedFuture(this);
}
 
Example 22
Project: silverflash   File: RingBufferSupplier.java   View Source Code Vote up 5 votes
@Override
public CompletableFuture<? extends Service> open() {
  if (isRunning.compareAndSet(false, true)) {
    this.disruptor = new Disruptor<>(BufferEvent.EVENT_FACTORY, ringSize, threadFactory,
        ProducerType.SINGLE, new BusySpinWaitStrategy());
    this.disruptor.handleEventsWith(this::onEvent);
    this.ringBuffer = disruptor.start();
  }
  return CompletableFuture.completedFuture(this);
}
 
Example 23
Project: reveno   File: DisruptorPipeProcessor.java   View Source Code Vote up 5 votes
@Override
public void start() {
	if (isStarted) throw new IllegalStateException("The Pipe Processor is alredy started.");
	
	disruptor = new Disruptor(eventFactory(), bufferSize(), executor(),
			singleProducer() ? ProducerType.SINGLE : ProducerType.MULTI,
			createWaitStrategy());

	attachHandlers(disruptor);
	startupInterceptor();
	disruptor.start();

	log.info("Started.");
	isStarted = true;
}
 
Example 24
Project: Okra   File: DisruptorAdapterHandler.java   View Source Code Vote up 5 votes
@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;
        }
 
Example 25
Project: Okra   File: DisruptorAdapterBy41xHandler.java   View Source Code Vote up 5 votes
@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;
        }
 
Example 26
Project: disruptor-code-analysis   File: BatchingTest.java   View Source Code Vote up 4 votes
@Parameters
public static Collection<Object[]> generateData()
{
    Object[][] producerTypes = {{ProducerType.MULTI}, {ProducerType.SINGLE}};
    return Arrays.asList(producerTypes);
}
 
Example 27
Project: HeliosStreams   File: ListenerMain.java   View Source Code Vote up 4 votes
@SuppressWarnings("unchecked")
public ListenerMain(final Properties properties) {
	log.info(">>>>> Starting TSDB Event Listener...");
	
	// ================  Configure Tag Caches		
	tagKeyCache = CacheBuilder.from(statEnableSpec(ConfigurationHelper.getSystemThenEnvProperty(CONFIG_TAGK_CACHE, DEFAULT_TAGK_CACHE, properties))).build();
	tagValueCache = CacheBuilder.from(statEnableSpec(ConfigurationHelper.getSystemThenEnvProperty(CONFIG_TAGV_CACHE, DEFAULT_TAGV_CACHE, properties))).build();
	tagMetricCache = CacheBuilder.from(statEnableSpec(ConfigurationHelper.getSystemThenEnvProperty(CONFIG_METRIC_CACHE, DEFAULT_METRIC_CACHE, properties))).build();
	tagPairCache = CacheBuilder.from(statEnableSpec(ConfigurationHelper.getSystemThenEnvProperty(CONFIG_TAGPAIR_CACHE, DEFAULT_TAGPAIR_CACHE, properties))).build();

	// ================  Configure Outbound Queue
	inQueueTextFormat = ConfigurationHelper.getBooleanSystemThenEnvProperty(CONFIG_INQ_TEXT, DEFAULT_INQ_TEXT, properties);
	inQueueDirName = ConfigurationHelper.getSystemThenEnvProperty(CONFIG_INQ_DIR, DEFAULT_INQ_DIR, properties);
	log.info("InQueue Directory: [{}]", inQueueDirName);
	inQueueDir = new File(inQueueDirName);
	
	
	while(!isQueueFileReady()) {
		log.info("No cq4 in queue files found in [{}]. Waiting....", inQueueDir);
		long loops = 0;
		while(!isQueueFileReady()) {
			loops++;
			if(loops%60==0) {
				log.info("No cq4 in queue files found in [{}]. Waiting....", inQueueDir);
			}
			SystemClock.sleep(1000);
		}
		break;
	}
	
	inQueueRollCycle = ConfigurationHelper.getEnumSystemThenEnvProperty(RollCycles.class, CONFIG_INQ_ROLLCYCLE, DEFAULT_INQ_ROLLCYCLE, properties); 
	inQueue = SingleChronicleQueueBuilder.binary(inQueueDir)
			.rollCycle(inQueueRollCycle)
			.wireType(inQueueTextFormat ? WireType.JSON : WireType.BINARY)
			.build();
	
	dispatchRbThreads = ConfigurationHelper.getIntSystemThenEnvProperty(CONFIG_DISPATCHRB_THREADS, DEFAULT_DISPATCHRB_THREADS, properties);
	dispatchRbSize = ConfigurationHelper.getIntSystemThenEnvProperty(CONFIG_DISPATCHRB_SIZE, DEFAULT_DISPATCHRB_SIZE, properties); 
	final Properties dispatchRbWaitStratConfig = Props.extract(CONFIG_DISPATCHRB_WAITSTRAT_PROPS, properties, true, false);
	dispatchRbWaitStrat = ConfigurationHelper.getEnumSystemThenEnvProperty(RBWaitStrategy.class, CONFIG_DISPATCHRB_WAITSTRAT, DEFAULT_DISPATCHRB_WAITSTRAT, properties);
	dispatchRbDisruptor = new Disruptor<TSDBMetricMeta>(TSDBMetricMeta.FACTORY, dispatchRbSize, dispatchRbThreadFactory, ProducerType.SINGLE, dispatchRbWaitStrat.waitStrategy(dispatchRbWaitStratConfig));
	dispatchRbDisruptor.setDefaultExceptionHandler(dispatchExceptionHandler);
	dispatchRbDisruptor.handleEventsWith(dispatchHandler);		
	log.info("Started MetricDispatch RingBuffer");
	
	ds = DefaultDataSource.getInstance(properties);
	sqlWorker = SQLWorker.getInstance(ds.getDataSource());
	
	final CountDownLatch keyLoadLatch = asynchLoadUIDCache("tagKeyCache", tagKeyCache, "SELECT XUID, NAME FROM TSD_TAGK");
	final CountDownLatch valueLoadLatch = asynchLoadUIDCache("tagValueCache", tagValueCache, "SELECT XUID, NAME FROM TSD_TAGV");
	asynchLoadUIDCache("tagMetricCache", tagMetricCache, "SELECT XUID, NAME FROM TSD_METRIC");
	asynchLoadUIDCache("tagPairCache", tagPairCache, "SELECT XUID, NAME FROM TSD_TAGPAIR", keyLoadLatch, valueLoadLatch);
	
	
	log.info("<<<<< TSDB Event Listener Ready");
}
 
Example 28
Project: perf-workshop   File: AppMain.java   View Source Code Vote up 4 votes
public static void main(final String[] args) throws Exception
{
    final CommandLineArgs commandLineArgs = new CommandLineArgs();
    new JCommander(commandLineArgs).parse(args);

    final Disruptor<Packet> packetDisruptor =
            new Disruptor<>(new Packet.Factory(commandLineArgs.getRecordLength()), commandLineArgs.getBufferSize(),
                    newCachedThreadPool(DAEMON_THREAD_FACTORY), ProducerType.SINGLE, new SpinLoopHintBusySpinWaitStrategy());

    final Overrides overrides = new Overrides(commandLineArgs);
    overrides.init();

    final Journaller journaller = new Journaller(SYSTEM_NANO_TIMER, commandLineArgs, overrides.enableJournaller());
    journaller.init();

    final Histogram[] messageTransitTimeHistograms = new Histogram[commandLineArgs.getNumberOfIterations()];
    setAll(messageTransitTimeHistograms, HISTOGRAMS::createHistogramForArray);
    final Histogram[] interMessageTimeHistograms = new Histogram[commandLineArgs.getNumberOfIterations()];
    setAll(interMessageTimeHistograms, HISTOGRAMS::createHistogramForArray);

    packetDisruptor.handleEventsWith(
            runOnCpus(wrap(new Accumulator(messageTransitTimeHistograms, interMessageTimeHistograms, SYSTEM_NANO_TIMER, commandLineArgs)::process),
                    "Accumulator", overrides.getAccumulatorThreadAffinity()),
            runOnCpus(wrap(journaller::process), "Journaller", overrides.getJournallerThreadAffinity()));

    packetDisruptor.start();

    final InputReader inputReader = new InputReader(packetDisruptor.getRingBuffer(), SYSTEM_NANO_TIMER, commandLineArgs);

    if(commandLineArgs.runSpinners())
    {
        System.out.println("Starting spinner threads to perturb the system");
        Spinners.SPINNERS.start();
    }

    System.out.println("Starting replay at " + new Date());

    final Thread thread = DAEMON_THREAD_FACTORY.newThread(THREADS.runOnCpu(inputReader::processFiles,
            overrides.getProducerThreadAffinity()));
    thread.start();

    try
    {
        thread.join();
        System.out.println("Finished replay at " + new Date());
        packetDisruptor.shutdown(1, TimeUnit.MINUTES);
    }
    catch (TimeoutException e)
    {
        throw new RuntimeException("Consumers did not process remaining events within timeout", e);
    }
    finally
    {
        Spinners.SPINNERS.stop();
        packetDisruptor.halt();
    }

    System.out.println("Pausing for 10 seconds...");
    THREADS.sleep(10L, TimeUnit.SECONDS);
}
 
Example 29
Project: cakes   File: Main.java   View Source Code Vote up 3 votes
public static void main(String[] args) {
    ThreadFactory threadFactory = Executors.defaultThreadFactory();

    Disruptor<UserEvent> disruptor = new Disruptor<>(new UserEventFactory(), 1024, threadFactory, ProducerType.SINGLE, new YieldingWaitStrategy());

    disruptor.handleEventsWith(new UserEventConsumer());

    disruptor.start();

    new UserEventProducer(disruptor.getRingBuffer()).doProcess();

    disruptor.shutdown();
}