本文整理汇总了Java中org.apache.commons.pool2.SwallowedExceptionListener类的典型用法代码示例。如果您正苦于以下问题:Java SwallowedExceptionListener类的具体用法?Java SwallowedExceptionListener怎么用?Java SwallowedExceptionListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SwallowedExceptionListener类属于org.apache.commons.pool2包,在下文中一共展示了SwallowedExceptionListener类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: swallowException
import org.apache.commons.pool2.SwallowedExceptionListener; //导入依赖的package包/类
/**
* Swallows an exception and notifies the configured listener for swallowed
* exceptions queue.
*
* @param e exception to be swallowed
*/
final void swallowException(Exception e) {
SwallowedExceptionListener listener = getSwallowedExceptionListener();
if (listener == null) {
return;
}
try {
listener.onSwallowException(e);
} catch (OutOfMemoryError oome) {
throw oome;
} catch (VirtualMachineError vme) {
throw vme;
} catch (Throwable t) {
// Ignore. Enjoy the irony.
}
}
示例2: swallowException
import org.apache.commons.pool2.SwallowedExceptionListener; //导入依赖的package包/类
/**
* Swallows an exception and notifies the configured listener for swallowed
* exceptions queue.
*
* @param e exception to be swallowed
*/
final void swallowException(final Exception e) {
final SwallowedExceptionListener listener = getSwallowedExceptionListener();
if (listener == null) {
return;
}
try {
listener.onSwallowException(e);
} catch (final OutOfMemoryError oome) {
throw oome;
} catch (final VirtualMachineError vme) {
throw vme;
} catch (final Throwable t) {
// Ignore. Enjoy the irony.
}
}
示例3: createProcessPool
import org.apache.commons.pool2.SwallowedExceptionListener; //导入依赖的package包/类
private GenericObjectPool<PhantomJSProcess> createProcessPool(JRPropertiesUtil properties)
{
ProcessFactory processFactory = new ProcessFactory(this, properties);
GenericObjectPool<PhantomJSProcess> pool = new GenericObjectPool<>(processFactory);
pool.setLifo(true);
int maxProcessCount = properties.getIntegerProperty(PhantomJS.PROPERTY_PHANTOMJS_MAX_PROCESS_COUNT,
PhantomJS.DEFAULT_PHANTOMJS_MAX_PROCESS_COUNT);
pool.setMaxTotal(maxProcessCount);
pool.setMaxIdle(maxProcessCount);
int borrowTimeout = properties.getIntegerProperty(PhantomJS.PROPERTY_PHANTOMJS_POOL_BORROW_TIMEOUT,
PhantomJS.DEFAULT_PHANTOMJS_POOL_BORROW_TIMEOUT);
pool.setMaxWaitMillis(borrowTimeout);
int idleTimeout = properties.getIntegerProperty(PhantomJS.PROPERTY_PHANTOMJS_IDLE_TIMEOUT,
PhantomJS.DEFAULT_PHANTOMJS_IDLE_TIMEOUT);
pool.setMinEvictableIdleTimeMillis(idleTimeout);
pool.setTimeBetweenEvictionRunsMillis(idlePingInterval);
pool.setTestWhileIdle(true);
pool.setNumTestsPerEvictionRun(Integer.MAX_VALUE);
pool.setSwallowedExceptionListener(new SwallowedExceptionListener()
{
@Override
public void onSwallowException(Exception e)
{
if (log.isDebugEnabled())
{
log.debug("Pool exception", e);
}
}
});
return pool;
}
示例4: testSwallowedExceptionListener
import org.apache.commons.pool2.SwallowedExceptionListener; //导入依赖的package包/类
@Test
public void testSwallowedExceptionListener() {
genericObjectPool.setSwallowedExceptionListener(null); // must simply return
final List<Exception> swallowedExceptions = new ArrayList<>();
/*
* A simple listener, that will throw a OOM on 3rd exception.
*/
final SwallowedExceptionListener listener = new SwallowedExceptionListener() {
@Override
public void onSwallowException(final Exception e) {
if (swallowedExceptions.size() == 2) {
throw new OutOfMemoryError();
}
swallowedExceptions.add(e);
}
};
genericObjectPool.setSwallowedExceptionListener(listener);
final Exception e1 = new Exception();
final Exception e2 = new ArrayIndexOutOfBoundsException();
genericObjectPool.swallowException(e1);
genericObjectPool.swallowException(e2);
try {
genericObjectPool.swallowException(e1);
fail("Not supposed to get here");
} catch (final OutOfMemoryError oom) {
// expected
}
assertEquals(2, swallowedExceptions.size());
}
示例5: reconstructConnectionPool
import org.apache.commons.pool2.SwallowedExceptionListener; //导入依赖的package包/类
private static void reconstructConnectionPool() {
connectionFactory = new ModbusSlaveConnectionFactoryImpl();
GenericKeyedObjectPool<ModbusSlaveEndpoint, ModbusSlaveConnection> genericKeyedObjectPool = new GenericKeyedObjectPool<>(
connectionFactory, poolConfig);
genericKeyedObjectPool.setSwallowedExceptionListener(new SwallowedExceptionListener() {
@Override
public void onSwallowException(Exception e) {
logger.error("Connection pool swallowed unexpected exception: {}", e.getMessage());
}
});
connectionPool = genericKeyedObjectPool;
}
示例6: getSwallowedExceptionListener
import org.apache.commons.pool2.SwallowedExceptionListener; //导入依赖的package包/类
/**
* The listener used (if any) to receive notifications of exceptions
* unavoidably swallowed by the pool.
*
* @return The listener or <code>null</code> for no listener
*/
public final SwallowedExceptionListener getSwallowedExceptionListener() {
return swallowedExceptionListener;
}
示例7: setSwallowedExceptionListener
import org.apache.commons.pool2.SwallowedExceptionListener; //导入依赖的package包/类
/**
* The listener used (if any) to receive notifications of exceptions
* unavoidably swallowed by the pool.
*
* @param swallowedExceptionListener The listener or <code>null</code>
* for no listener
*/
public final void setSwallowedExceptionListener(
SwallowedExceptionListener swallowedExceptionListener) {
this.swallowedExceptionListener = swallowedExceptionListener;
}
示例8: setSwallowedExceptionListener
import org.apache.commons.pool2.SwallowedExceptionListener; //导入依赖的package包/类
/**
* The listener used (if any) to receive notifications of exceptions
* unavoidably swallowed by the pool.
*
* @param swallowedExceptionListener The listener or <code>null</code>
* for no listener
*/
public final void setSwallowedExceptionListener(
final SwallowedExceptionListener swallowedExceptionListener) {
this.swallowedExceptionListener = swallowedExceptionListener;
}