Search in sources :

Example 1 with LogbackLoggingSystemLauncherListener

use of org.apache.qpid.server.logging.logback.LogbackLoggingSystemLauncherListener in project qpid-broker-j by apache.

the class InternalBrokerHolder method start.

public void start(final Map<String, Object> systemConfig) throws Exception {
    if (Thread.getDefaultUncaughtExceptionHandler() == null) {
        Thread.setDefaultUncaughtExceptionHandler(UNCAUGHT_EXCEPTION_HANDLER);
    }
    LOGGER.info("Starting internal broker (same JVM)");
    _systemLauncher = new SystemLauncher(new LogbackLoggingSystemLauncherListener(), new SystemLauncherListener.DefaultSystemLauncherListener() {

        @Override
        public void onShutdown(final int exitCode) {
            _systemLauncher = null;
        }

        @Override
        public void exceptionOnShutdown(final Exception e) {
            if (e instanceof IllegalStateException || e instanceof IllegalStateTransitionException) {
                System.out.println("IllegalStateException occurred on broker shutdown in test " + getClassQualifiedTestName());
            }
        }
    });
    _systemLauncher.startup(systemConfig);
}
Also used : SystemLauncher(org.apache.qpid.server.SystemLauncher) LogbackLoggingSystemLauncherListener(org.apache.qpid.server.logging.logback.LogbackLoggingSystemLauncherListener) IllegalStateTransitionException(org.apache.qpid.server.model.IllegalStateTransitionException) IllegalStateTransitionException(org.apache.qpid.server.model.IllegalStateTransitionException)

Example 2 with LogbackLoggingSystemLauncherListener

use of org.apache.qpid.server.logging.logback.LogbackLoggingSystemLauncherListener in project qpid-broker-j by apache.

the class EmbeddedBrokerPerClassAdminImpl method beforeTestClass.

@Override
public void beforeTestClass(final Class testClass) {
    _preservedProperties = new HashMap<>();
    try {
        String timestamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date(System.currentTimeMillis()));
        _currentWorkDirectory = Files.createTempDirectory(String.format("qpid-work-%s-%s-", timestamp, testClass.getSimpleName())).toString();
        ConfigItem[] configItems = (ConfigItem[]) testClass.getAnnotationsByType(ConfigItem.class);
        Arrays.stream(configItems).filter(ConfigItem::jvm).forEach(i -> {
            _preservedProperties.put(i.name(), System.getProperty(i.name()));
            System.setProperty(i.name(), i.value());
        });
        Map<String, String> context = new HashMap<>();
        context.put("qpid.work_dir", _currentWorkDirectory);
        context.put("qpid.port.protocol_handshake_timeout", "1000000");
        context.putAll(Arrays.stream(configItems).filter(i -> !i.jvm()).collect(Collectors.toMap(ConfigItem::name, ConfigItem::value, (name, value) -> value)));
        Map<String, Object> systemConfigAttributes = new HashMap<>();
        systemConfigAttributes.put(ConfiguredObject.CONTEXT, context);
        systemConfigAttributes.put(ConfiguredObject.TYPE, System.getProperty("broker.config-store-type", "JSON"));
        systemConfigAttributes.put(SystemConfig.STARTUP_LOGGED_TO_SYSTEM_OUT, Boolean.FALSE);
        if (Thread.getDefaultUncaughtExceptionHandler() == null) {
            Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler());
        }
        LOGGER.info("Starting internal broker (same JVM)");
        List<SystemLauncherListener> systemLauncherListeners = new ArrayList<>();
        systemLauncherListeners.add(new LogbackLoggingSystemLauncherListener());
        systemLauncherListeners.add(new ShutdownLoggingSystemLauncherListener());
        systemLauncherListeners.add(new PortExtractingLauncherListener());
        _systemLauncher = new SystemLauncher(systemLauncherListeners.toArray(new SystemLauncherListener[systemLauncherListeners.size()]));
        _systemLauncher.startup(systemConfigAttributes);
    } catch (Exception e) {
        throw new BrokerAdminException("Failed to start broker for test class", e);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Date(java.util.Date) IllegalStateTransitionException(org.apache.qpid.server.model.IllegalStateTransitionException) NotFoundException(org.apache.qpid.server.model.NotFoundException) SystemLauncherListener(org.apache.qpid.server.SystemLauncherListener) LogbackLoggingSystemLauncherListener(org.apache.qpid.server.logging.logback.LogbackLoggingSystemLauncherListener) SystemLauncher(org.apache.qpid.server.SystemLauncher) LogbackLoggingSystemLauncherListener(org.apache.qpid.server.logging.logback.LogbackLoggingSystemLauncherListener) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) SimpleDateFormat(java.text.SimpleDateFormat)

Example 3 with LogbackLoggingSystemLauncherListener

use of org.apache.qpid.server.logging.logback.LogbackLoggingSystemLauncherListener in project qpid-broker-j by apache.

the class Main method startBroker.

protected void startBroker(Map<String, Object> attributes) throws Exception {
    SystemLauncher systemLauncher = new SystemLauncher(new LogbackLoggingSystemLauncherListener(), new SystemLauncherListener.DefaultSystemLauncherListener() {

        @Override
        public void onShutdown(final int exitCode) {
            if (exitCode != 0) {
                shutdown(exitCode);
            }
        }
    });
    systemLauncher.startup(attributes);
}
Also used : LogbackLoggingSystemLauncherListener(org.apache.qpid.server.logging.logback.LogbackLoggingSystemLauncherListener) LogbackLoggingSystemLauncherListener(org.apache.qpid.server.logging.logback.LogbackLoggingSystemLauncherListener)

Aggregations

LogbackLoggingSystemLauncherListener (org.apache.qpid.server.logging.logback.LogbackLoggingSystemLauncherListener)3 SystemLauncher (org.apache.qpid.server.SystemLauncher)2 IllegalStateTransitionException (org.apache.qpid.server.model.IllegalStateTransitionException)2 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 SystemLauncherListener (org.apache.qpid.server.SystemLauncherListener)1 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)1 NotFoundException (org.apache.qpid.server.model.NotFoundException)1