public static ServiceConfiguration findService(final String name) {
    checkParam(name, notNullValue());
    Predicate<ServiceConfiguration> nameOrFullName =
        new Predicate<ServiceConfiguration>() {

          @Override
          public boolean apply(ServiceConfiguration input) {
            return name.equals(input.getName()) || name.equals(input.getFullName().toString());
          }
        };
    for (final ComponentId compId : ComponentIds.list()) {
      ServiceConfiguration a;
      try {
        return Iterables.find(Components.lookup(compId).services(), nameOrFullName);
      } catch (NoSuchElementException ex) {
        if (compId.isRegisterable()) {
          try {
            return ServiceConfigurations.lookupByName(compId.getClass(), name);
          } catch (Exception ex1) {
          }
        }
      }
    }
    throw new NoSuchElementException("Failed to lookup service named: " + name);
  }
예제 #2
0
    @SuppressWarnings({"rawtypes", "unchecked", "synthetic-access"})
    @Override
    public boolean processClass(final Class candidate) throws Exception {
      if (FilteredPipeline.class.isAssignableFrom(candidate)
          && !Modifier.isAbstract(candidate.getModifiers())
          && !Modifier.isInterface(candidate.getModifiers())
          && Ats.from(candidate).has(ComponentPart.class)) {
        try {
          final ComponentId compId =
              Ats.from(candidate).get(ComponentPart.class).value().newInstance();
          final Class<? extends FilteredPipeline> pipelineClass = candidate;
          final FilteredPipeline pipeline = Classes.newInstance(pipelineClass);
          Pipelines.pipelines.add(pipeline);
          return true;
        } catch (final Exception ex) {
          LOG.trace(ex, ex);
          return false;
        }
      } else if (ChannelPipelineFactory.class.isAssignableFrom(candidate)
          && !Modifier.isAbstract(candidate.getModifiers())
          && !Modifier.isInterface(candidate.getModifiers())
          && Ats.from(candidate).has(ComponentPart.class)) {
        try {
          final ComponentId compId =
              Ats.from(candidate).get(ComponentPart.class).value().newInstance();
          final Class<? extends ChannelPipelineFactory> pipelineClass = candidate;
          final ChannelPipelineFactory pipeline = Classes.newInstance(pipelineClass);
          Pipelines.clientPipelines.put(compId.getClass(), pipeline);
          return true;
        } catch (final Exception ex) {
          LOG.trace(ex, ex);
          return false;
        }

      } else {
        return false;
      }
    }