Ejemplo n.º 1
0
  @Override
  public synchronized void init(BundleContext context, DependencyManager manager) throws Exception {
    // Console registration
    Properties properties = new Properties();
    properties.put(Constants.SERVICE_PID, "it.hash.osgi.aws.console");
    manager.add(
        createComponent()
            .setInterface(
                new String[] {Console.class.getName(), ManagedService.class.getName()}, properties)
            .setImplementation(ConsoleImpl.class)
            .add(createServiceDependency().setService(LogService.class).setRequired(false)));

    // Shell Commands registration
    properties = new Properties();
    properties.put(CommandProcessor.COMMAND_SCOPE, "aws");
    properties.put(
        CommandProcessor.COMMAND_FUNCTION,
        new String[] {
          "ec2", "s3", "sdb", "ses", "sqs", "dyndb", "createtable", "putuser", "listusers"
        });
    manager.add(
        createComponent()
            .setInterface(Object.class.getName(), properties)
            .setImplementation(ShellCommands.class)
            .add(createServiceDependency().setService(Console.class).setRequired(true)));
  }
  @Override
  public void build(MetaData srvMeta, List<MetaData> depsMeta, Bundle b, DependencyManager dm)
      throws Exception {
    int stateMask =
        srvMeta.getInt(Params.stateMask, Bundle.INSTALLED | Bundle.RESOLVED | Bundle.ACTIVE);
    String filter = srvMeta.getString(Params.filter, null);
    Class<?> adapterImplClass = b.loadClass(srvMeta.getString(Params.impl));
    String[] provides = srvMeta.getStrings(Params.provides, null);
    Dictionary<String, Object> properties = srvMeta.getDictionary(Params.properties, null);
    boolean propagate = "true".equals(srvMeta.getString(Params.propagate, "false"));
    Component c = dm.createBundleAdapterService(stateMask, filter, propagate);
    c.setInterface(provides, properties);
    String factoryMethod = srvMeta.getString(Params.factoryMethod, null);
    if (factoryMethod == null) {
      c.setImplementation(adapterImplClass);
    } else {
      c.setFactory(adapterImplClass, factoryMethod);
    }

    setCommonServiceParams(c, srvMeta);
    c.setComposition(srvMeta.getString(Params.composition, null));
    ServiceLifecycleHandler lfcleHandler = new ServiceLifecycleHandler(c, b, dm, srvMeta, depsMeta);
    // The dependencies will be plugged by our lifecycle handler.
    c.setCallbacks(lfcleHandler, "init", "start", "stop", "destroy");
    // Adds dependencies (except named dependencies, which are managed by the lifecycle handler).
    addUnamedDependencies(b, dm, c, srvMeta, depsMeta);
    dm.add(c);
  }
Ejemplo n.º 3
0
  public void register(DependencyManager manager, Activity activity) {
    m_activity = activity;

    manager.add(
        manager
            .createComponent()
            .setInterface(ClockListener.class.getName(), null)
            .setImplementation(this));
  }
Ejemplo n.º 4
0
 @Override
 public void init(BundleContext context, DependencyManager manager) throws Exception {
   manager.add(
       createComponent()
           .setInterface(SimService.class.getName(), null)
           .setImplementation(SimServiceImpl.class)
           .add(createServiceDependency().setService(MongoDBService.class).setRequired(true)));
   manager.add(
       createComponent()
           .setInterface(AccountMergeHelper.class.getName(), null)
           .setImplementation(SimAccountMergeHelper.class)
           .add(createServiceDependency().setService(SimService.class).setRequired(true)));
 }
Ejemplo n.º 5
0
  public void init(BundleContext context, DependencyManager manager) throws Exception {
    Properties props = new Properties();
    props.put(RemoteConstants.SERVICE_EXPORTED_INTERFACES, Calculator.class.getName());
    manager.add(
        createComponent().setInterface(Calculator.class.getName(), props).setImplementation(this));

    final CalculatorServerServlet calculatorServerServlet = new CalculatorServerServlet();
    manager.add(
        createComponent()
            .setImplementation(calculatorServerServlet)
            .add(createServiceDependency().setService(HttpService.class).setRequired(true))
            .add(createServiceDependency().setService(LogService.class).setRequired(false)));
  }
Ejemplo n.º 6
0
 private void unregisterFactoryService() {
   Component component = m_factoryComponent;
   m_factoryComponent = null;
   if (component != null) {
     m_dependencyManager.remove(component);
   }
 }
Ejemplo n.º 7
0
  private void registerFactoryService() {
    Dictionary<String, Object> properties = new Hashtable<String, Object>();
    properties.put(REMOTE_CONFIGS_SUPPORTED, SUPPORTED_CONFIGURATION_TYPES);
    properties.put(REMOTE_INTENTS_SUPPORTED, SUPPORTED_INTENTS);

    RemoteServiceAdminFactory factory = new RemoteServiceAdminFactory(m_dependencyManager);

    Component component =
        createComponent()
            .setInterface(RemoteServiceAdmin.class.getName(), properties)
            .setImplementation(factory)
            .add(createServiceDependency().setService(LogService.class).setRequired(false))
            .add(
                createServiceDependency()
                    .setService(RemoteServiceAdminListener.class)
                    .setCallbacks(factory.getEventsHandler(), "listenerAdded", "listenerRemoved")
                    .setRequired(false))
            .add(
                createServiceDependency()
                    .setService(EventAdmin.class)
                    .setCallbacks(
                        factory.getEventsHandler(), "eventAdminAdded", "eventAdminRemoved")
                    .setRequired(false))
            .add(
                createServiceDependency()
                    .setService(WiringSender.class)
                    .setRequired(false)
                    .setCallbacks("wiringSenderAdded", "wiringSenderRemoved"));

    m_factoryComponent = component;
    m_dependencyManager.add(component);
  }
Ejemplo n.º 8
0
 @Override
 public void init(BundleContext arg0, DependencyManager dm) throws Exception {
   dm.add(
       createComponent()
           .setInterface(Object.class.getName(), null)
           .setImplementation(SimpleResource.class));
 }
Ejemplo n.º 9
0
 @Override
 public synchronized void init(BundleContext context, DependencyManager manager) throws Exception {
   manager.add(
       createComponent()
           .setInterface(Object.class.getName(), null)
           .setImplementation(ExampleComponent.class)
           .add(createServiceDependency().setService(LogService.class).setRequired(false)));
 }
Ejemplo n.º 10
0
 @Override
 public void init(BundleContext bc, DependencyManager dm) throws Exception {
   dm.add(
       createComponent()
           .setInterface(Job.class.getName(), null)
           .setImplementation(Indexer.class)
           .add(createServiceDependency().setService(SearchService.class).setRequired(true))
           .add(createServiceDependency().setService(ProductService.class).setRequired(true)));
 }
 @Override
 public void init(BundleContext context, DependencyManager manager) throws Exception {
   manager.add(
       createComponent()
           .setInterface(LearningController.class.getName(), null)
           .setImplementation(LearningControllerImpl.class)
           .add(createServiceDependency().setService(WiFiProfileFactory.class).setRequired(true))
           .add(
               createServiceDependency()
                   .setService(LocationProfileService.class)
                   .setRequired(false)));
 }
Ejemplo n.º 12
0
  /** {@inheritDoc} */
  @Override
  public void init(final BundleContext aContext, final DependencyManager aManager)
      throws Exception {
    // Do not start if we're running headless...
    if (GraphicsEnvironment.isHeadless()) {
      throw new RuntimeException("Cannot start client: running headless.");
    }

    final ClientController clientController = new ClientController(aContext);

    aManager.add(
        createBundleAdapterService(Bundle.ACTIVE, CP_BUNDLE_FILTER, true /* propagate */) //
            .setImplementation(ComponentProviderBundleAdapter.class));

    aManager.add(
        createBundleAdapterService(Bundle.ACTIVE, TOOL_BUNDLE_FILTER, true /* propagate */) //
            .setImplementation(ToolBundleAdapter.class));

    aManager.add(
        createBundleAdapterService(Bundle.ACTIVE, DEVICE_BUNDLE_FILTER, true /* propagate */) //
            .setImplementation(DeviceBundleAdapter.class));

    aManager.add(
        createBundleAdapterService(Bundle.ACTIVE, EXPORTER_BUNDLE_FILTER, true /* propagate */) //
            .setImplementation(ExporterBundleAdapter.class));

    Properties props = new Properties();
    props.put(Constants.SERVICE_PID, UIManagerConfigurator.PID);

    String[] serviceNames =
        new String[] {UIManagerConfigurator.class.getName(), ManagedService.class.getName()};

    // UI Manager Configuration...
    aManager.add(
        createComponent() //
            .setInterface(serviceNames, props) //
            .setImplementation(UIManagerConfigurator.class) //
        );

    props.put(Constants.SERVICE_PID, UIColorSchemeManager.PID);

    serviceNames =
        new String[] {UIColorSchemeManager.class.getName(), ManagedServiceFactory.class.getName()};

    // UI Manager Configuration...
    aManager.add(
        createComponent() //
            .setInterface(serviceNames, props) //
            .setImplementation(UIColorSchemeManager.class));

    // User session manager...
    aManager.add(
        createComponent() //
            .setImplementation(new UserSessionManager()) //
            .add(
                createServiceDependency() //
                    .setService(ProjectManager.class) //
                    .setRequired(true)) //
            .add(
                createServiceDependency() //
                    .setService(UserSettingsManager.class) //
                    .setRequired(true)) //
            .add(
                createServiceDependency() //
                    .setService(PreferencesService.class) //
                    .setRequired(true)) //
            .add(
                createServiceDependency() //
                    .setService(LogService.class) //
                    .setRequired(false) //
                ));

    // All the interfaces we're registering the client controller under...
    serviceNames =
        new String[] {
          AcquisitionDataListener.class.getName(),
          AcquisitionProgressListener.class.getName(),
          AcquisitionStatusListener.class.getName(),
          AnnotationListener.class.getName(),
          PlatformCallback.class.getName()
        };

    // Client controller...
    aManager.add(
        createComponent() //
            .setInterface(serviceNames, null) //
            .setImplementation(clientController) //
            .add(
                createServiceDependency() //
                    .setService(HostProperties.class) //
                    .setRequired(true)) //
            .add(
                createServiceDependency() //
                    .setService(ProjectManager.class) //
                    .setRequired(true) //
                    .setCallbacks("setProjectManager", "removeProjectManager")) //
            .add(
                createServiceDependency() //
                    .setService(DataAcquisitionService.class) //
                    .setRequired(true)) //
            .add(
                createServiceDependency() //
                    .setService(UIColorSchemeManager.class) //
                    .setRequired(true)) //
            .add(
                createServiceDependency() //
                    .setService(ComponentProvider.class, "(OLS-ComponentProvider=Menu)") //
                    .setCallbacks("addMenu", "removeMenu") //
                    .setRequired(false)) //
            .add(
                createServiceDependency() //
                    .setService(Device.class) //
                    .setCallbacks("addDevice", "removeDevice") //
                    .setRequired(false)) //
            .add(
                createServiceDependency() //
                    .setService(Tool.class) //
                    .setCallbacks("addTool", "removeTool") //
                    .setRequired(false)) //
            .add(
                createServiceDependency() //
                    .setService(Exporter.class) //
                    .setCallbacks("addExporter", "removeExporter") //
                    .setRequired(false)) //
            .add(
                createConfigurationDependency() //
                    .setPid(UIManagerConfigurator.PID)) //
        );
  }