Example #1
0
  @Override
  public TrackingStruct addingService(ServiceReference<ResourceAnalyzer> reference) {
    TrackingStruct struct = new TrackingStruct();
    try {
      String filterStr = (String) reference.getProperty(ResourceAnalyzer.FILTER);
      Filter filter = (filterStr != null) ? FrameworkUtil.createFilter(filterStr) : null;

      ResourceAnalyzer analyzer = context.getService(reference);
      if (analyzer == null) return null;

      struct = new TrackingStruct();
      struct.analyzer = analyzer;
      struct.filter = filter;
      struct.valid = true;

      indexer.addAnalyzer(analyzer, filter);
    } catch (InvalidSyntaxException e) {
      struct.valid = false;
      log.log(
          reference,
          LogService.LOG_ERROR,
          "Ignoring ResourceAnalyzer due to invalid filter expression",
          e);
    }
    return struct;
  }
Example #2
0
  @Override
  public void modifiedService(ServiceReference<ResourceAnalyzer> reference, TrackingStruct struct) {
    if (struct.valid) {
      indexer.removeAnalyzer(struct.analyzer, struct.filter);
    }

    try {
      String filterStr = (String) reference.getProperty(ResourceAnalyzer.FILTER);
      Filter filter = (filterStr != null) ? FrameworkUtil.createFilter(filterStr) : null;

      struct = new TrackingStruct();
      struct.filter = filter;
      struct.valid = true;

      indexer.addAnalyzer(struct.analyzer, filter);
    } catch (InvalidSyntaxException e) {
      struct.valid = false;
      log.log(
          reference,
          LogService.LOG_ERROR,
          "Ignoring ResourceAnalyzer due to invalid filter expression",
          e);
    }
  }