Search in sources :

Example 1 with SecuredSessionFactoryImpl

use of org.apache.karaf.shell.impl.console.osgi.secured.SecuredSessionFactoryImpl in project karaf by apache.

the class Activator method start.

@Override
public void start(final BundleContext context) throws Exception {
    threadIO = new ThreadIOImpl();
    threadIO.start();
    sessionFactory = new SecuredSessionFactoryImpl(context, threadIO);
    sessionFactory.getCommandProcessor().addConverter(new Converters(context));
    sessionFactory.getCommandProcessor().addConstant(".context", context.getBundle(0).getBundleContext());
    final CopyOnWriteArraySet<CommandLoggingFilter> listeners = new CopyOnWriteArraySet<>();
    filterTracker = new ServiceTracker<>(context, CommandLoggingFilter.class, new ServiceTrackerCustomizer<CommandLoggingFilter, CommandLoggingFilter>() {

        @Override
        public CommandLoggingFilter addingService(ServiceReference<CommandLoggingFilter> reference) {
            CommandLoggingFilter service = context.getService(reference);
            listeners.add(service);
            return service;
        }

        @Override
        public void modifiedService(ServiceReference<CommandLoggingFilter> reference, CommandLoggingFilter service) {
        }

        @Override
        public void removedService(ServiceReference<CommandLoggingFilter> reference, CommandLoggingFilter service) {
            listeners.remove(service);
            context.ungetService(reference);
        }
    });
    filterTracker.open();
    LoggingCommandSessionListener loggingCommandSessionListener = new LoggingCommandSessionListener();
    loggingCommandSessionListener.setFilters(listeners);
    sessionFactory.getCommandProcessor().addListener(loggingCommandSessionListener);
    try {
        EventAdminListener listener = new EventAdminListener(context);
        sessionFactory.getCommandProcessor().addListener(listener);
        eventAdminListener = listener;
    } catch (NoClassDefFoundError error) {
    // Ignore the listener if EventAdmin package isn't present
    }
    sessionFactory.register(new ManagerImpl(sessionFactory, sessionFactory));
    sessionFactoryRegistration = context.registerService(SessionFactory.class, sessionFactory, null);
    commandProcessorRegistration = context.registerService(CommandProcessor.class, sessionFactory.getCommandProcessor(), null);
    actionExtender = new CommandExtender(sessionFactory);
    actionExtender.start(context);
    commandTracker = new CommandTracker(sessionFactory, context);
    commandTracker.open();
    converterTracker = new ConverterTracker(sessionFactory, context);
    converterTracker.open();
    listenerTracker = new ListenerTracker(sessionFactory, context);
    listenerTracker.open();
    if (Boolean.parseBoolean(context.getProperty(START_CONSOLE))) {
        localConsoleManager = new LocalConsoleManager(context, sessionFactory);
        localConsoleManager.start();
    } else {
        LOGGER.info("Not starting local console. To activate set " + START_CONSOLE + "=true");
    }
}
Also used : SessionFactory(org.apache.karaf.shell.api.console.SessionFactory) SecuredSessionFactoryImpl(org.apache.karaf.shell.impl.console.osgi.secured.SecuredSessionFactoryImpl) ThreadIOImpl(org.apache.felix.gogo.runtime.threadio.ThreadIOImpl) ServiceTrackerCustomizer(org.osgi.util.tracker.ServiceTrackerCustomizer) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) ServiceReference(org.osgi.framework.ServiceReference) CommandExtender(org.apache.karaf.shell.impl.action.osgi.CommandExtender) ManagerImpl(org.apache.karaf.shell.impl.action.command.ManagerImpl) CommandLoggingFilter(org.apache.karaf.shell.api.console.CommandLoggingFilter) CommandProcessor(org.apache.felix.service.command.CommandProcessor)

Aggregations

CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)1 ThreadIOImpl (org.apache.felix.gogo.runtime.threadio.ThreadIOImpl)1 CommandProcessor (org.apache.felix.service.command.CommandProcessor)1 CommandLoggingFilter (org.apache.karaf.shell.api.console.CommandLoggingFilter)1 SessionFactory (org.apache.karaf.shell.api.console.SessionFactory)1 ManagerImpl (org.apache.karaf.shell.impl.action.command.ManagerImpl)1 CommandExtender (org.apache.karaf.shell.impl.action.osgi.CommandExtender)1 SecuredSessionFactoryImpl (org.apache.karaf.shell.impl.console.osgi.secured.SecuredSessionFactoryImpl)1 ServiceReference (org.osgi.framework.ServiceReference)1 ServiceTrackerCustomizer (org.osgi.util.tracker.ServiceTrackerCustomizer)1