Exemplo n.º 1
0
  /**
   * Use this method when the shell is being executed as a top level shell.
   *
   * @param args
   * @throws Exception
   */
  public void run(String args[]) throws Exception {

    ThreadIOImpl threadio = new ThreadIOImpl();
    threadio.start();

    ClassLoader cl = Main.class.getClassLoader();
    // This is a workaround for windows machines struggling with long class paths.
    loadJarsFromPath(new File(System.getProperty(KARAF_HOME), "system"));
    loadJarsFromPath(new File(System.getProperty(KARAF_HOME), "deploy"));
    CommandProcessorImpl commandProcessor = new CommandProcessorImpl(threadio);

    discoverCommands(commandProcessor, cl);

    InputStream in = unwrap(System.in);
    PrintStream out = wrap(unwrap(System.out));
    PrintStream err = wrap(unwrap(System.err));
    run(commandProcessor, args, in, out, err);
  }
Exemplo n.º 2
0
 @Override
 public void stop(BundleContext context) throws Exception {
   filterTracker.close();
   sessionFactoryRegistration.unregister();
   if (localConsoleManager != null) {
     localConsoleManager.stop();
   }
   sessionFactory.stop();
   actionExtender.stop(context);
   threadIO.stop();
   if (eventAdminListener != null) {
     eventAdminListener.close();
   }
 }
Exemplo n.º 3
0
  @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);

    actionExtender = new CommandExtender(sessionFactory);
    actionExtender.start(context);

    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");
    }
  }