org.apache.camel.spi.Registry.findByType()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(90)

本文整理了Java中org.apache.camel.spi.Registry.findByType方法的一些代码示例,展示了Registry.findByType的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Registry.findByType方法的具体详情如下:
包路径:org.apache.camel.spi.Registry
类名称:Registry
方法名:findByType

Registry.findByType介绍

暂无

代码示例

代码示例来源:origin: org.apache.camel/camel-jsonpath

private ObjectMapper resolveObjectMapper(Registry registry) {
  Set<ObjectMapper> mappers = registry.findByType(ObjectMapper.class);
  if (mappers.size() == 1) {
    return mappers.iterator().next();
  }
  return defaultMapper;
}

代码示例来源:origin: OpenWiseSolutions/openhub-framework

@Override
public <T> Set<T> findByType(Class<T> type) {
  for (Registry registry : applicationContextsRegistry.values()) {
    Set<T> result = registry.findByType(type);
    if (!CollectionUtils.isEmpty(result)) {
      return result;
    }
  }
  return Collections.emptySet();
}

代码示例来源:origin: io.syndesis/integration-runtime

private static ObjectMapper resolveObjectMapper(Registry registry) {
    Set<ObjectMapper> mappers = registry.findByType(ObjectMapper.class);
    if (mappers.size() == 1) {
      return mappers.iterator().next();
    }

    return MAPPER;
  }
}

代码示例来源:origin: io.syndesis.integration-runtime/runtime

private ObjectMapper resolveObjectMapper(Registry registry) {
    Set<ObjectMapper> mappers = registry.findByType(ObjectMapper.class);
    if (mappers.size() == 1) {
      return mappers.iterator().next();
    }
    return new ObjectMapper();
  }
}

代码示例来源:origin: org.apache.camel/camel-metrics

MetricRegistry getMetricRegistryFromCamelRegistry(Registry camelRegistry, String registryName) {
  MetricRegistry registry = camelRegistry.lookupByNameAndType(registryName, MetricRegistry.class);
  if (registry != null) {
    return registry;
  } else {
    Set<MetricRegistry> registries = camelRegistry.findByType(MetricRegistry.class);
    if (registries.size() == 1) {
      return registries.iterator().next();
    }
  }
  return null;
}

代码示例来源:origin: org.apache.camel/camel-micrometer

public static MeterRegistry getMeterRegistryFromCamelRegistry(Registry camelRegistry, String registryName) {
  MeterRegistry registry = camelRegistry.lookupByNameAndType(registryName, MeterRegistry.class);
  if (registry != null) {
    return registry;
  } else {
    Set<MeterRegistry> registries = camelRegistry.findByType(MeterRegistry.class);
    if (registries.size() == 1) {
      return registries.iterator().next();
    }
  }
  return null;
}

代码示例来源:origin: org.openehealth.ipf.platform-camel/ipf-platform-camel-core

public static <T> T beanOrNull(Class<T> type, CamelContext camelContext) {
  Set<T> beans = camelContext.getRegistry().findByType(type);
  int count = beans.size();
  if (count == 1) {
    return beans.iterator().next();
  } else if (count == 0) {
    return null; 
  } else {
    throw new IllegalArgumentException(
        "Too many beans in the application context of type: " 
        + type + ". Found: " + count);
  }
}

代码示例来源:origin: org.openehealth.ipf.platform-camel/ipf-platform-camel-flow

private <T> T lookup(Class<T> type) {
    Set<T> processors = routeBuilder.getContext().getRegistry().findByType(type);
    if (processors.isEmpty() || processors.size() > 1) {
      throw new IllegalArgumentException("Must have exactly one processor of type " + type.getName() + ", but found " + processors.size());
    } else {
      T processor = processors.iterator().next();
      return processor;
    }

  }
}

代码示例来源:origin: OpenWiseSolutions/openhub-framework

/**
 * Returns bean by its type from registry.
 *
 * @param type the type of the registered bean
 * @param <T> as class of type
 * @return bean of specified type
 */
protected final <T> T getBean(Class<T> type) {
  Set<T> beans = getContext().getRegistry().findByType(type);
  Assert.state(beans.size() == 1, "there is more beans of type " + type);
  return beans.iterator().next();
}

代码示例来源:origin: OpenWiseSolutions/openhub-framework

/**
   * Gets {@link ProducerTemplate} default instance from Camel Context.
   *
   * @return ProducerTemplate
   * @throws IllegalStateException when there is no ProducerTemplate
   */
  public ProducerTemplate getProducerTemplate() {
    if (!isStarted() && !isStarting()) {
      throw new IllegalStateException(getClass().getName() + " is not started so far!");
    }

    Set<ProducerTemplate> templates = camelContext.getRegistry().findByType(ProducerTemplate.class);
    Assert.state(templates.size() >= 1, "ProducerTemplate must be at least one.");

    return templates.iterator().next();
  }
}

代码示例来源:origin: io.rhiot/camel-gps-bu353

protected ProcessManager resolveProcessManager() {
  LOG.debug("Started resolving ProcessManager...");
  if(processManager != null) {
    LOG.debug("ProcessManager has been set on the component level. Camel will use it: {}", processManager);
    return processManager;
  }
  Set<ProcessManager> processManagers = getCamelContext().getRegistry().findByType(ProcessManager.class);
  if(processManagers.isEmpty()) {
    LOG.debug("No ProcessManager found in the registry - creating new DefaultProcessManager.");
    return new DefaultProcessManager();
  } else if(processManagers.size() == 1) {
    return processManagers.iterator().next();
  } else {
    return new DefaultProcessManager();
  }
}

代码示例来源:origin: io.rhiot/camel-webcam

protected ProcessManager resolveProcessManager() {
  LOG.debug("Started resolving ProcessManager...");
  if(processManager != null) {
    LOG.debug("ProcessManager has been set on the component level. Camel will use it: {}", processManager);
    return processManager;
  }
  Set<ProcessManager> processManagers = getCamelContext().getRegistry().findByType(ProcessManager.class);
  if(processManagers.isEmpty()) {
    LOG.debug("No ProcessManager found in the registry - creating new DefaultProcessManager.");
    return new DefaultProcessManager();
  } else if(processManagers.size() == 1) {
    return processManagers.iterator().next();
  } else {
    return new DefaultProcessManager();
  }
}

代码示例来源:origin: io.rhiot/camel-gpsd

protected Installer resolveInstaller() {
  LOG.debug("Started resolving Installer...");
  if(installer != null) {
    LOG.debug("Installer has been set on the component level. Camel will use it: {}", installer);
    return installer;
  }
  Set<DefaultInstaller> installers = getCamelContext().getRegistry().findByType(DefaultInstaller.class);
  if(installers.isEmpty()) {
    LOG.debug("No Installer found in the registry - creating new DefaultInstaller.");
    return new DefaultInstaller();
  } else if(installers.size() == 1) {
    return installers.iterator().next();
  } else {
    return new DefaultInstaller();
  }
}

代码示例来源:origin: io.rhiot/camel-gpsd

protected ProcessManager resolveProcessManager() {
  LOG.debug("Started resolving ProcessManager...");
  if(processManager != null) {
    LOG.debug("ProcessManager has been set on the component level. Camel will use it: {}", processManager);
    return processManager;
  }
  Set<ProcessManager> processManagers = getCamelContext().getRegistry().findByType(ProcessManager.class);
  if(processManagers.isEmpty()) {
    LOG.debug("No ProcessManager found in the registry - creating new DefaultProcessManager.");
    return new DefaultProcessManager();
  } else if(processManagers.size() == 1) {
    return processManagers.iterator().next();
  } else {
    return new DefaultProcessManager();
  }
}

代码示例来源:origin: io.rhiot/camel-webcam

protected Installer resolveInstaller() {
  LOG.debug("Started resolving Installer...");
  if(installer != null) {
    LOG.debug("Installer has been set on the component level. Camel will use it: {}", installer);
    return installer;
  }
  Set<Installer> installers = getCamelContext().getRegistry().findByType(Installer.class);
  if(installers.isEmpty()) {
    LOG.debug("No Installer found in the registry - creating new DefaultInstaller.");
    return new DefaultInstaller();
  } else if(installers.size() == 1) {
    return installers.iterator().next();
  } else {
    return new DefaultInstaller();
  }
}

代码示例来源:origin: OpenWiseSolutions/openhub-framework

/**
 * Gets {@link MessageService} instance from Camel Context.
 *
 * @return MessageService
 * @throws IllegalStateException when there is no MessageService
 */
protected MessageService getMessageService() {
  if (!isStarted() && !isStarting()) {
    throw new IllegalStateException(getClass().getName() + " is not started so far!");
  }
  Set<MessageService> services = getEndpoint().getCamelContext().getRegistry().findByType(MessageService.class);
  Assert.state(services.size() >= 1, "MessageService must be at least one.");
  return services.iterator().next();
}

代码示例来源:origin: org.apache.camel/camel-spark

protected HiveContext resolveHiveContext() {
  Set<HiveContext> hiveContexts = getEndpoint().getComponent().getCamelContext().getRegistry().findByType(HiveContext.class);
  if (hiveContexts.size() == 1) {
    return hiveContexts.iterator().next();
  }
  return null;
}

代码示例来源:origin: OpenWiseSolutions/openhub-framework

/**
   * Gets {@link ProducerTemplate} default instance from Camel Context.
   *
   * @return ProducerTemplate
   * @throws IllegalStateException when there is no ProducerTemplate
   */
  protected ProducerTemplate getProducerTemplate() {
    if (!isStarted() && !isStarting()) {
      throw new IllegalStateException(getClass().getName() + " is not started so far!");
    }

    Set<ProducerTemplate> templates = getEndpoint().getCamelContext().getRegistry().findByType(ProducerTemplate.class);
    Assert.state(templates.size() >= 1, "ProducerTemplate must be at least one.");

    return templates.iterator().next();
  }
}

代码示例来源:origin: io.syndesis.integration/integration-runtime

public JsonSimplePredicate(final String expression, final CamelContext context) {
  final Language language = ObjectHelper.notNull(context.resolveLanguage("simple"), "simple language");
  final String ognlExpression = convertSimpleToOGNLForMaps(expression);
  predicate = language.createPredicate(expression);
  ognlPredicate = language.createPredicate(ognlExpression);
  final Registry registry = context.getRegistry();
  final Set<ObjectMapper> mappers = registry.findByType(ObjectMapper.class);
  if (mappers.size() != 1) {
    mapper = MAPPER;
  } else {
    mapper = mappers.iterator().next();
  }
}

代码示例来源:origin: org.apache.camel/camel-amqp

@Override
protected void doStart() throws Exception {
  Set<AMQPConnectionDetails> connectionDetails = getCamelContext().getRegistry().findByType(AMQPConnectionDetails.class);
  if (connectionDetails.size() == 1) {
    AMQPConnectionDetails details = connectionDetails.iterator().next();
    JmsConnectionFactory connectionFactory = new JmsConnectionFactory(details.username(), details.password(), details.uri());
    if (details.setTopicPrefix()) {
      connectionFactory.setTopicPrefix("topic://");
    }
    setConnectionFactory(connectionFactory);
  }
  super.doStart();
}

相关文章