当前位置: 首页>>代码示例>>Java>>正文


Java ExceptionHandler类代码示例

本文整理汇总了Java中com.lmax.disruptor.ExceptionHandler的典型用法代码示例。如果您正苦于以下问题:Java ExceptionHandler类的具体用法?Java ExceptionHandler怎么用?Java ExceptionHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ExceptionHandler类属于com.lmax.disruptor包,在下文中一共展示了ExceptionHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldSupportSpecifyingAExceptionHandlerForEventProcessors

import com.lmax.disruptor.ExceptionHandler; //导入依赖的package包/类
@Test
public void shouldSupportSpecifyingAExceptionHandlerForEventProcessors()
    throws Exception
{
    AtomicReference<Throwable> eventHandled = new AtomicReference<Throwable>();
    ExceptionHandler exceptionHandler = new StubExceptionHandler(eventHandled);
    RuntimeException testException = new RuntimeException();
    ExceptionThrowingEventHandler handler = new ExceptionThrowingEventHandler(testException);

    disruptor.handleExceptionsWith(exceptionHandler);
    disruptor.handleEventsWith(handler);

    publishEvent();

    final Throwable actualException = waitFor(eventHandled);
    assertSame(testException, actualException);
}
 
开发者ID:winwill2012,项目名称:disruptor-code-analysis,代码行数:18,代码来源:DisruptorTest.java

示例2: shouldOnlyApplyExceptionsHandlersSpecifiedViaHandleExceptionsWithOnNewEventProcessors

import com.lmax.disruptor.ExceptionHandler; //导入依赖的package包/类
@Test
public void shouldOnlyApplyExceptionsHandlersSpecifiedViaHandleExceptionsWithOnNewEventProcessors()
    throws Exception
{
    AtomicReference<Throwable> eventHandled = new AtomicReference<Throwable>();
    ExceptionHandler exceptionHandler = new StubExceptionHandler(eventHandled);
    RuntimeException testException = new RuntimeException();
    ExceptionThrowingEventHandler handler = new ExceptionThrowingEventHandler(testException);

    disruptor.handleExceptionsWith(exceptionHandler);
    disruptor.handleEventsWith(handler);
    disruptor.handleExceptionsWith(new FatalExceptionHandler());

    publishEvent();

    final Throwable actualException = waitFor(eventHandled);
    assertSame(testException, actualException);
}
 
开发者ID:winwill2012,项目名称:disruptor-code-analysis,代码行数:19,代码来源:DisruptorTest.java

示例3: shouldSupportSpecifyingADefaultExceptionHandlerForEventProcessors

import com.lmax.disruptor.ExceptionHandler; //导入依赖的package包/类
@Test
public void shouldSupportSpecifyingADefaultExceptionHandlerForEventProcessors()
    throws Exception
{
    AtomicReference<Throwable> eventHandled = new AtomicReference<Throwable>();
    ExceptionHandler exceptionHandler = new StubExceptionHandler(eventHandled);
    RuntimeException testException = new RuntimeException();
    ExceptionThrowingEventHandler handler = new ExceptionThrowingEventHandler(testException);

    disruptor.setDefaultExceptionHandler(exceptionHandler);
    disruptor.handleEventsWith(handler);

    publishEvent();

    final Throwable actualException = waitFor(eventHandled);
    assertSame(testException, actualException);
}
 
开发者ID:winwill2012,项目名称:disruptor-code-analysis,代码行数:18,代码来源:DisruptorTest.java

示例4: shouldApplyDefaultExceptionHandlerToExistingEventProcessors

import com.lmax.disruptor.ExceptionHandler; //导入依赖的package包/类
@Test
public void shouldApplyDefaultExceptionHandlerToExistingEventProcessors()
    throws Exception
{
    AtomicReference<Throwable> eventHandled = new AtomicReference<Throwable>();
    ExceptionHandler exceptionHandler = new StubExceptionHandler(eventHandled);
    RuntimeException testException = new RuntimeException();
    ExceptionThrowingEventHandler handler = new ExceptionThrowingEventHandler(testException);

    disruptor.handleEventsWith(handler);
    disruptor.setDefaultExceptionHandler(exceptionHandler);

    publishEvent();

    final Throwable actualException = waitFor(eventHandled);
    assertSame(testException, actualException);
}
 
开发者ID:winwill2012,项目名称:disruptor-code-analysis,代码行数:18,代码来源:DisruptorTest.java

示例5: SiddhiContext

import com.lmax.disruptor.ExceptionHandler; //导入依赖的package包/类
public SiddhiContext() {
    SiddhiExtensionLoader.loadSiddhiExtensions(siddhiExtensions);
    siddhiDataSources = new ConcurrentHashMap<String, DataSource>();
    statisticsConfiguration = new StatisticsConfiguration(new SiddhiMetricsFactory());
    extensionHolderMap = new ConcurrentHashMap<Class, AbstractExtensionHolder>();
    configManager = new InMemoryConfigManager();
    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);
        }
    };
}
 
开发者ID:wso2,项目名称:siddhi,代码行数:25,代码来源:SiddhiContext.java

示例6: getExceptionHandler

import com.lmax.disruptor.ExceptionHandler; //导入依赖的package包/类
private static ExceptionHandler getExceptionHandler() {
    final String cls = System.getProperty("AsyncLogger.ExceptionHandler");
    if (cls == null) {
        LOGGER.debug("No AsyncLogger.ExceptionHandler specified");
        return null;
    }
    try {
        @SuppressWarnings("unchecked")
        final
        Class<? extends ExceptionHandler> klass = (Class<? extends ExceptionHandler>) Class
                .forName(cls);
        final ExceptionHandler result = klass.newInstance();
        LOGGER.debug("AsyncLogger.ExceptionHandler=" + result);
        return result;
    } catch (final Exception ignored) {
        LOGGER.debug(
                "AsyncLogger.ExceptionHandler not set: error creating "
                        + cls + ": ", ignored);
        return null;
    }
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:22,代码来源:AsyncLogger.java

示例7: initDisruptor

import com.lmax.disruptor.ExceptionHandler; //导入依赖的package包/类
private static synchronized void initDisruptor() {
    if (disruptor != null) {
        LOGGER.trace("AsyncLoggerConfigHelper not starting new disruptor, using existing object. Ref count is {}.", count);
        return;
    }
    LOGGER.trace("AsyncLoggerConfigHelper creating new disruptor. Ref count is {}.", count);
    final int ringBufferSize = calculateRingBufferSize();
    final WaitStrategy waitStrategy = createWaitStrategy();
    executor = Executors.newSingleThreadExecutor(threadFactory);
    disruptor = new Disruptor<Log4jEventWrapper>(FACTORY, ringBufferSize,
            executor, ProducerType.MULTI, waitStrategy);
    final EventHandler<Log4jEventWrapper>[] handlers = new Log4jEventWrapperHandler[] {//
    new Log4jEventWrapperHandler() };
    final ExceptionHandler errorHandler = getExceptionHandler();
    disruptor.handleExceptionsWith(errorHandler);
    disruptor.handleEventsWith(handlers);

    LOGGER.debug(
            "Starting AsyncLoggerConfig disruptor with ringbuffer size={}, waitStrategy={}, exceptionHandler={}...",
            disruptor.getRingBuffer().getBufferSize(), waitStrategy.getClass().getSimpleName(), errorHandler);
    disruptor.start();
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:23,代码来源:AsyncLoggerConfigHelper.java

示例8: getExceptionHandler

import com.lmax.disruptor.ExceptionHandler; //导入依赖的package包/类
private static ExceptionHandler getExceptionHandler() {
    final String cls = System
            .getProperty("AsyncLoggerConfig.ExceptionHandler");
    if (cls == null) {
        return null;
    }
    try {
        @SuppressWarnings("unchecked")
        final Class<? extends ExceptionHandler> klass = (Class<? extends ExceptionHandler>) Class
                .forName(cls);
        final ExceptionHandler result = klass.newInstance();
        return result;
    } catch (final Exception ignored) {
        LOGGER.debug(
                "AsyncLoggerConfig.ExceptionHandler not set: error creating "
                        + cls + ": ", ignored);
        return null;
    }
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:20,代码来源:AsyncLoggerConfigHelper.java

示例9: setDefaultExceptionHandler

import com.lmax.disruptor.ExceptionHandler; //导入依赖的package包/类
/**
 * <p>Specify an exception handler to be used for event handlers and worker pools created by this Disruptor.</p>
 * <p>
 * <p>The exception handler will be used by existing and future event handlers and worker pools created by this Disruptor instance.</p>
 *
 * @param exceptionHandler the exception handler to use.
 */
@SuppressWarnings("unchecked")
public void setDefaultExceptionHandler(final ExceptionHandler<? super T> exceptionHandler) {
    checkNotStarted();
    if (!(this.exceptionHandler instanceof ExceptionHandlerWrapper)) {
        throw new IllegalStateException("setDefaultExceptionHandler can not be used after handleExceptionsWith");
    }
    ((ExceptionHandlerWrapper<T>) this.exceptionHandler).switchTo(exceptionHandler);
}
 
开发者ID:winwill2012,项目名称:disruptor-code-analysis,代码行数:16,代码来源:Disruptor.java

示例10: with

import com.lmax.disruptor.ExceptionHandler; //导入依赖的package包/类
/**
 * Specify the {@link ExceptionHandler} to use with the event handler.
 *
 * @param exceptionHandler the exception handler to use.
 */
public void with(ExceptionHandler<? super T> exceptionHandler)
{
    ((BatchEventProcessor<T>) consumerRepository.getEventProcessorFor(eventHandler))
        .setExceptionHandler(exceptionHandler);
    consumerRepository.getBarrierFor(eventHandler).alert();
}
 
开发者ID:winwill2012,项目名称:disruptor-code-analysis,代码行数:12,代码来源:ExceptionHandlerSetting.java

示例11: AbstractByteRingConsumerEx

import com.lmax.disruptor.ExceptionHandler; //导入依赖的package包/类
/**
 * @param ring             source byte ring containing inbound messages
 * @param sequenceBarrier  on which it is waiting.
 * @param delegate   is the delegate to which message are dispatched.
 * @param exceptionHandler to be called back when an error occurs
 *                         as {@link com.lmax.disruptor.Sequencer#INITIAL_CURSOR_VALUE}
 */
public AbstractByteRingConsumerEx(ByteRing ring,
                                  SequenceBarrier sequenceBarrier,
                                  RingBufferBlockProcessor delegate,
                                  ExceptionHandler exceptionHandler) {
    super(ring, sequenceBarrier);
    this.delegate = delegate;
    this.exceptionHandler = exceptionHandler;
}
 
开发者ID:andymalakov,项目名称:f1x,代码行数:16,代码来源:AbstractByteRingConsumerEx.java

示例12: createLogger

import com.lmax.disruptor.ExceptionHandler; //导入依赖的package包/类
public static RingBufferBlockProcessor createLogger(File file, int bufferSize, ExceptionHandler exceptionHandler) {
    try {
        OutputStream os = new BufferedOutputStream(new FileOutputStream(file, true), bufferSize);
        BufferLogger result = new BufferLogger(os, exceptionHandler);
        new Thread(result, "FIX Log Flusher").start();
        return result;
    } catch (FileNotFoundException e) {
        throw new RuntimeException("Cannot write into " + file, e);
    }
}
 
开发者ID:andymalakov,项目名称:f1x,代码行数:11,代码来源:BufferLogger.java

示例13: getDisruptorExceptionHandler

import com.lmax.disruptor.ExceptionHandler; //导入依赖的package包/类
public ExceptionHandler<Object> getDisruptorExceptionHandler() {
    if (disruptorExceptionHandler != null) {
        return disruptorExceptionHandler;
    } else {
        return siddhiContext.getDefaultDisrupterExceptionHandler();
    }
}
 
开发者ID:wso2,项目名称:siddhi,代码行数:8,代码来源:SiddhiAppContext.java

示例14: setExceptionHandler

import com.lmax.disruptor.ExceptionHandler; //导入依赖的package包/类
/**
 * Set a new {@link ExceptionHandler} for handling exceptions propagated out of the {@link com.lmax.disruptor.BatchEventProcessor}
 *
 * @param exceptionHandler to replace the existing exceptionHandler.
 */
public void setExceptionHandler(final ExceptionHandler exceptionHandler) {
    if (null == exceptionHandler) {
        throw new NullPointerException("Exception handler cannot be null.");
    }

    this.exceptionHandler = exceptionHandler;
}
 
开发者ID:wso2,项目名称:andes,代码行数:13,代码来源:ConcurrentContentReadTaskBatchProcessor.java

示例15: start

import com.lmax.disruptor.ExceptionHandler; //导入依赖的package包/类
/**
 * 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();
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:44,代码来源:AsyncLoggerConfigDisruptor.java


注:本文中的com.lmax.disruptor.ExceptionHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。