public void engage() {
    System.out.println("Starting the Disruptor");
    // starts the event processors
    final RingBuffer<DemoEvent> ringBuf = disruptor.start();

    // now we start the publishers
    List<Future<?>> futures = new ArrayList<Future<?>>();
    ExecutorService execService = Executors.newFixedThreadPool(NUM_PUBLISHERS);

    try {
      for (DisruptorDemoPublisher pub : pubs) {
        futures.add(execService.submit(pub));
      }

      // wait for each publisher to finish
      for (Future<?> f : futures) {
        f.get();
      }

      // this should wait until all events are processed
      disruptor.shutdown();

    } catch (Exception e) {
      System.out.println(e.toString());
      e.printStackTrace();

    } finally {
      execService.shutdown();
    }
  }
コード例 #2
0
 @SafeVarargs
 public ShriekingMushroom(int bufferSize, Executor exec, EventHandler<Event>... events) {
   disrupt = new Disruptor<Event>(EventBuilder.FACTORY, bufferSize, exec);
   disrupt.handleEventsWith(events);
   RingBuffer<Event> buffer = disrupt.start();
   builder = new EventBuilder(buffer);
 }
コード例 #3
0
 @SuppressWarnings("unchecked")
 public static void createDisruptors(DisruptorType type, DisruptorConfig disruptorConfig) {
   WaitStrategy inboundWaitStrategy = getWaitStrategy(disruptorConfig.getDisruptorWaitStrategy());
   for (int i = 0; i < disruptorConfig.getNoDisruptors(); i++) {
     ExecutorService executorService =
         Executors.newFixedThreadPool(disruptorConfig.getNoOfEventHandlersPerDisruptor());
     Disruptor disruptor =
         new Disruptor<>(
             CarbonDisruptorEvent.EVENT_FACTORY,
             disruptorConfig.getBufferSize(),
             executorService,
             ProducerType.MULTI,
             inboundWaitStrategy);
     ExceptionHandler exh = new GenericExceptionHandler();
     EventHandler[] eventHandlers =
         new EventHandler[disruptorConfig.getNoOfEventHandlersPerDisruptor()];
     for (int j = 0; j < disruptorConfig.getNoOfEventHandlersPerDisruptor(); j++) {
       EventHandler eventHandler = new CarbonDisruptorEventHandler();
       eventHandlers[j] = eventHandler;
     }
     disruptor.handleEventsWith(eventHandlers);
     for (EventHandler eventHandler : eventHandlers) {
       disruptor.handleExceptionsFor(eventHandler).with(exh);
     }
     disruptorConfig.addDisruptor(disruptor.start());
   }
   disruptorConfigHashMap.put(type, disruptorConfig);
 }
コード例 #4
0
  public void start() throws IllegalStateException {
    if (disruptor == null) {
      throw new IllegalStateException("disruptor == null, call init");
    }

    disruptor.start();
  }
コード例 #5
0
  @SuppressWarnings("unchecked")
  @Override
  public void init() throws ServletException {
    try {
      disruptor =
          new Disruptor<byte[]>(
              new EventFactory<byte[]>() {
                @Override
                public byte[] newInstance() {
                  return new byte[256];
                }
              },
              262144,
              executor);

      disruptor.handleEventsWith(new LogicHandler());
      disruptor.start();
      generator = new Generator(executor);

      MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
      mBeanServer.registerMBean(
          new StandardMBean(generator, GeneratorMBean.class),
          new ObjectName("com.lmax:type=generator"));
    } catch (Exception e) {
      throw new ServletException(e);
    }
  }
コード例 #6
0
  static {
    initInfoForExecutorThread();
    LOGGER.debug("AsyncLogger.ThreadNameStrategy={}", THREAD_NAME_STRATEGY);
    final int ringBufferSize = calculateRingBufferSize();

    final WaitStrategy waitStrategy = createWaitStrategy();
    disruptor =
        new Disruptor<>(
            RingBufferLogEvent.FACTORY, ringBufferSize, EXECUTOR, ProducerType.MULTI, waitStrategy);
    disruptor.handleExceptionsWith(getExceptionHandler());
    disruptor.handleEventsWith(new RingBufferLogEventHandler());

    LOGGER.debug(
        "Starting AsyncLogger disruptor with ringbuffer size {}...",
        disruptor.getRingBuffer().getBufferSize());
    disruptor.start();
  }
 @SuppressWarnings("unchecked")
 private RingBuffer<RecordsHolder> getRingBuffer(Object member) {
   Disruptor<RecordsHolder> disruptor = this.disruptorMap.get(member);
   if (disruptor == null) {
     synchronized (this) {
       disruptor = this.disruptorMap.get(member);
       if (disruptor == null) {
         disruptor =
             new Disruptor<>(
                 new RecordsEventFactory(), REMOTE_INDEX_COMMUNICATOR_BUFFER_SIZE, this.executor);
         disruptor.handleEventsWith(new RecordsEventHandler(member));
         this.disruptorMap.put(member, disruptor);
         disruptor.start();
       }
     }
   }
   return disruptor.getRingBuffer();
 }
コード例 #8
0
 @Override
 public void start() throws Exception {
   initProcess();
   disruptor.start();
 }