com.lmax.disruptor.ExceptionHandler Java Examples

The following examples show how to use com.lmax.disruptor.ExceptionHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SiddhiContext.java    From siddhi with Apache License 2.0 6 votes vote down vote up
public SiddhiContext() {
    SiddhiExtensionLoader.loadSiddhiExtensions(siddhiExtensions, extensionHolderMap);
    siddhiDataSources = new ConcurrentHashMap<String, DataSource>();
    statisticsConfiguration = new StatisticsConfiguration(new SiddhiMetricsFactory());
    configManager = new InMemoryConfigManager();
    attributes = new ConcurrentHashMap<>();
    defaultDisrupterExceptionHandler = new ExceptionHandler<Object>() {
        @Override
        public void handleEventException(Throwable throwable, long l, Object event) {
            log.error("Disruptor encountered an error processing" + " [sequence: " + l + ", event: " + event
                    .toString() + "]", throwable);
        }

        @Override
        public void handleOnStartException(Throwable throwable) {
            log.error("Disruptor encountered an error on start", throwable);
        }

        @Override
        public void handleOnShutdownException(Throwable throwable) {
            log.error("Disruptor encountered an error on shutdown", throwable);
        }
    };
}
 
Example #2
Source File: SiddhiAppContext.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public ExceptionHandler<Object> getDisruptorExceptionHandler() {
    if (disruptorExceptionHandler != null) {
        return disruptorExceptionHandler;
    } else {
        return siddhiContext.getDefaultDisrupterExceptionHandler();
    }
}
 
Example #3
Source File: AsyncLoggerConfigDisruptor.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * Increases the reference count and creates and starts a new Disruptor and associated thread if none currently
 * exists.
 *
 * @see #stop()
 */
@Override
public synchronized void start() {
    if (disruptor != null) {
        LOGGER.trace("AsyncLoggerConfigDisruptor not starting new disruptor for this configuration, "
                + "using existing object.");
        return;
    }
    LOGGER.trace("AsyncLoggerConfigDisruptor creating new disruptor for this configuration.");
    ringBufferSize = DisruptorUtil.calculateRingBufferSize("AsyncLoggerConfig.RingBufferSize");
    final WaitStrategy waitStrategy = DisruptorUtil.createWaitStrategy("AsyncLoggerConfig.WaitStrategy");

    final ThreadFactory threadFactory = new Log4jThreadFactory("AsyncLoggerConfig", true, Thread.NORM_PRIORITY) {
        @Override
        public Thread newThread(final Runnable r) {
            final Thread result = super.newThread(r);
            backgroundThreadId = result.getId();
            return result;
        }
    };
    asyncQueueFullPolicy = AsyncQueueFullPolicyFactory.create();

    translator = mutable ? MUTABLE_TRANSLATOR : TRANSLATOR;
    factory = mutable ? MUTABLE_FACTORY : FACTORY;
    disruptor = new Disruptor<>(factory, ringBufferSize, threadFactory, ProducerType.MULTI, waitStrategy);

    final ExceptionHandler<Log4jEventWrapper> errorHandler = DisruptorUtil.getAsyncLoggerConfigExceptionHandler();
    disruptor.setDefaultExceptionHandler(errorHandler);

    final Log4jEventWrapperHandler[] handlers = {new Log4jEventWrapperHandler()};
    disruptor.handleEventsWith(handlers);

    LOGGER.debug("Starting AsyncLoggerConfig disruptor for this configuration with ringbufferSize={}, "
            + "waitStrategy={}, exceptionHandler={}...", disruptor.getRingBuffer().getBufferSize(), waitStrategy
            .getClass().getSimpleName(), errorHandler);
    disruptor.start();
    super.start();
}
 
Example #4
Source File: DisruptorUtil.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
static ExceptionHandler<RingBufferLogEvent> getAsyncLoggerExceptionHandler() {
    final String cls = PropertiesUtil.getProperties().getStringProperty("AsyncLogger.ExceptionHandler");
    if (cls == null) {
        return new AsyncLoggerDefaultExceptionHandler();
    }
    try {
        @SuppressWarnings("unchecked")
        final Class<? extends ExceptionHandler<RingBufferLogEvent>> klass =
            (Class<? extends ExceptionHandler<RingBufferLogEvent>>) Loader.loadClass(cls);
        return klass.newInstance();
    } catch (final Exception ignored) {
        LOGGER.debug("Invalid AsyncLogger.ExceptionHandler value: error creating {}: ", cls, ignored);
        return new AsyncLoggerDefaultExceptionHandler();
    }
}
 
Example #5
Source File: DisruptorUtil.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
static ExceptionHandler<AsyncLoggerConfigDisruptor.Log4jEventWrapper> getAsyncLoggerConfigExceptionHandler() {
    final String cls = PropertiesUtil.getProperties().getStringProperty("AsyncLoggerConfig.ExceptionHandler");
    if (cls == null) {
        return new AsyncLoggerConfigDefaultExceptionHandler();
    }
    try {
        @SuppressWarnings("unchecked")
        final Class<? extends ExceptionHandler<AsyncLoggerConfigDisruptor.Log4jEventWrapper>> klass =
                (Class<? extends ExceptionHandler<AsyncLoggerConfigDisruptor.Log4jEventWrapper>>) Loader.loadClass(cls);
        return klass.newInstance();
    } catch (final Exception ignored) {
        LOGGER.debug("Invalid AsyncLoggerConfig.ExceptionHandler value: error creating {}: ", cls, ignored);
        return new AsyncLoggerConfigDefaultExceptionHandler();
    }
}
 
Example #6
Source File: SiddhiAppRuntimeImpl.java    From siddhi with Apache License 2.0 4 votes vote down vote up
public void handleExceptionWith(ExceptionHandler<Object> exceptionHandler) {
    siddhiAppContext.setDisruptorExceptionHandler(exceptionHandler);
}
 
Example #7
Source File: SiddhiContext.java    From siddhi with Apache License 2.0 4 votes vote down vote up
public ExceptionHandler<Object> getDefaultDisrupterExceptionHandler() {
    return defaultDisrupterExceptionHandler;
}
 
Example #8
Source File: SiddhiAppContext.java    From siddhi with Apache License 2.0 4 votes vote down vote up
public void setDisruptorExceptionHandler(ExceptionHandler<Object> disruptorExceptionHandler) {
    this.disruptorExceptionHandler = disruptorExceptionHandler;
}
 
Example #9
Source File: MysqlMultiStageCoprocessor.java    From canal with Apache License 2.0 4 votes vote down vote up
@Override
public void start() {
    super.start();
    this.exception = null;
    this.disruptorMsgBuffer = RingBuffer.createSingleProducer(new MessageEventFactory(),
        ringBufferSize,
        new BlockingWaitStrategy());
    int tc = parserThreadCount > 0 ? parserThreadCount : 1;
    this.parserExecutor = Executors.newFixedThreadPool(tc, new NamedThreadFactory("MultiStageCoprocessor-Parser-"
                                                                                  + destination));

    this.stageExecutor = Executors.newFixedThreadPool(2, new NamedThreadFactory("MultiStageCoprocessor-other-"
                                                                                + destination));
    SequenceBarrier sequenceBarrier = disruptorMsgBuffer.newBarrier();
    ExceptionHandler exceptionHandler = new SimpleFatalExceptionHandler();
    // stage 2
    this.logContext = new LogContext();
    simpleParserStage = new BatchEventProcessor<MessageEvent>(disruptorMsgBuffer,
        sequenceBarrier,
        new SimpleParserStage(logContext));
    simpleParserStage.setExceptionHandler(exceptionHandler);
    disruptorMsgBuffer.addGatingSequences(simpleParserStage.getSequence());

    // stage 3
    SequenceBarrier dmlParserSequenceBarrier = disruptorMsgBuffer.newBarrier(simpleParserStage.getSequence());
    WorkHandler<MessageEvent>[] workHandlers = new DmlParserStage[tc];
    for (int i = 0; i < tc; i++) {
        workHandlers[i] = new DmlParserStage();
    }
    workerPool = new WorkerPool<MessageEvent>(disruptorMsgBuffer,
        dmlParserSequenceBarrier,
        exceptionHandler,
        workHandlers);
    Sequence[] sequence = workerPool.getWorkerSequences();
    disruptorMsgBuffer.addGatingSequences(sequence);

    // stage 4
    SequenceBarrier sinkSequenceBarrier = disruptorMsgBuffer.newBarrier(sequence);
    sinkStoreStage = new BatchEventProcessor<MessageEvent>(disruptorMsgBuffer,
        sinkSequenceBarrier,
        new SinkStoreStage());
    sinkStoreStage.setExceptionHandler(exceptionHandler);
    disruptorMsgBuffer.addGatingSequences(sinkStoreStage.getSequence());

    // start work
    stageExecutor.submit(simpleParserStage);
    stageExecutor.submit(sinkStoreStage);
    workerPool.start(parserExecutor);
}
 
Example #10
Source File: AsyncLoggerDisruptor.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
/**
 * Creates and starts a new Disruptor and associated thread if none currently exists.
 *
 * @see #stop()
 */
@Override
public synchronized void start() {
    if (disruptor != null) {
        LOGGER.trace(
                "[{}] AsyncLoggerDisruptor not starting new disruptor for this context, using existing object.",
                contextName);
        return;
    }
    LOGGER.trace("[{}] AsyncLoggerDisruptor creating new disruptor for this context.", contextName);
    ringBufferSize = DisruptorUtil.calculateRingBufferSize("AsyncLogger.RingBufferSize");
    final WaitStrategy waitStrategy = DisruptorUtil.createWaitStrategy("AsyncLogger.WaitStrategy");

    final ThreadFactory threadFactory = new Log4jThreadFactory("AsyncLogger[" + contextName + "]", true, Thread.NORM_PRIORITY) {
        @Override
        public Thread newThread(final Runnable r) {
            final Thread result = super.newThread(r);
            backgroundThreadId = result.getId();
            return result;
        }
    };
    asyncQueueFullPolicy = AsyncQueueFullPolicyFactory.create();

    disruptor = new Disruptor<>(RingBufferLogEvent.FACTORY, ringBufferSize, threadFactory, ProducerType.MULTI,
            waitStrategy);

    final ExceptionHandler<RingBufferLogEvent> errorHandler = DisruptorUtil.getAsyncLoggerExceptionHandler();
    disruptor.setDefaultExceptionHandler(errorHandler);

    final RingBufferLogEventHandler[] handlers = {new RingBufferLogEventHandler()};
    disruptor.handleEventsWith(handlers);

    LOGGER.debug("[{}] Starting AsyncLogger disruptor for this context with ringbufferSize={}, waitStrategy={}, "
            + "exceptionHandler={}...", contextName, disruptor.getRingBuffer().getBufferSize(), waitStrategy
            .getClass().getSimpleName(), errorHandler);
    disruptor.start();

    LOGGER.trace("[{}] AsyncLoggers use a {} translator", contextName, useThreadLocalTranslator ? "threadlocal"
            : "vararg");
    super.start();
}
 
Example #11
Source File: SiddhiAppRuntime.java    From siddhi with Apache License 2.0 votes vote down vote up
void handleExceptionWith(ExceptionHandler<Object> exceptionHandler);