Search in sources :

Example 1 with ConnectionSource

use of ch.qos.logback.core.db.ConnectionSource in project qpid-broker-j by apache.

the class JDBCLoggerHelper method restartConnectionSourceIfExists.

void restartConnectionSourceIfExists(final Appender appender) {
    if (appender instanceof DBAppender) {
        final ConnectionSource connectionSource = ((DBAppender) appender).getConnectionSource();
        if (connectionSource != null) {
            connectionSource.stop();
            connectionSource.start();
        }
    }
}
Also used : ConnectionSource(ch.qos.logback.core.db.ConnectionSource) DBAppender(ch.qos.logback.classic.db.DBAppender)

Example 2 with ConnectionSource

use of ch.qos.logback.core.db.ConnectionSource in project qpid-broker-j by apache.

the class JDBCLoggerHelper method validateConnectionSourceSettings.

void validateConnectionSourceSettings(final ConfiguredObject<?> logger, final JDBCSettings settings) {
    try {
        final ConnectionSource connectionSource = createConnectionSource(logger, settings);
        connectionSource.getConnection().close();
    } catch (Exception e) {
        throw new IllegalConfigurationException("Cannot create connection source from given URL, credentials and connection pool type");
    }
}
Also used : ConnectionSource(ch.qos.logback.core.db.ConnectionSource) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException)

Example 3 with ConnectionSource

use of ch.qos.logback.core.db.ConnectionSource in project qpid-broker-j by apache.

the class JDBCLoggerHelperTest method restartConnectionSourceIfExists.

@Test
public void restartConnectionSourceIfExists() {
    final ConnectionSource connectionSource = mock(ConnectionSource.class);
    final DBAppender appender = mock(DBAppender.class);
    when(appender.getConnectionSource()).thenReturn(connectionSource);
    _jdbcLoggerHelper.restartConnectionSourceIfExists(appender);
    verify(connectionSource).stop();
    verify(connectionSource).start();
    verifyNoMoreInteractions(connectionSource);
}
Also used : ConnectionSource(ch.qos.logback.core.db.ConnectionSource) DBAppender(ch.qos.logback.classic.db.DBAppender) Test(org.junit.Test)

Example 4 with ConnectionSource

use of ch.qos.logback.core.db.ConnectionSource in project qpid-broker-j by apache.

the class JDBCLoggerHelper method createAppenderInstance.

Appender<ILoggingEvent> createAppenderInstance(final Context context, final ConfiguredObject<?> logger, final JDBCSettings settings) {
    try {
        final JDBCSettingsDBNameResolver dbNameResolver = new JDBCSettingsDBNameResolver(settings);
        final ConnectionSource connectionSource = createConnectionSource(context, logger, settings);
        final DBAppender appender = new DBAppender();
        appender.setDbNameResolver(dbNameResolver);
        appender.setConnectionSource(connectionSource);
        appender.setContext(context);
        appender.start();
        return appender;
    } catch (Exception e) {
        LOGGER.error("Failed to create appender", e);
        throw new IllegalConfigurationException("Cannot create appender");
    }
}
Also used : ConnectionSource(ch.qos.logback.core.db.ConnectionSource) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) DBAppender(ch.qos.logback.classic.db.DBAppender) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException)

Aggregations

ConnectionSource (ch.qos.logback.core.db.ConnectionSource)4 DBAppender (ch.qos.logback.classic.db.DBAppender)3 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)2 Test (org.junit.Test)1