com.hazelcast.config.Config类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(14.4k)|赞(0)|评价(0)|浏览(166)

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

Config介绍

[英]Contains all the configuration to start a com.hazelcast.core.HazelcastInstance. A Config can be created programmatically, but can also be configured using XML, see com.hazelcast.config.XmlConfigBuilder.

Config instances can be shared between threads, but should not be modified after they are used to create HazelcastInstances.
[中]包含启动com的所有配置。黑泽尔卡斯特。果心例如,黑泽尔卡斯特。配置可以通过编程方式创建,但也可以使用XML进行配置,请参见com。黑泽尔卡斯特。配置。XmlConfigBuilder。
配置实例可以在线程之间共享,但在使用它们创建HazelcastInstances后不应进行修改。

代码示例

代码示例来源:origin: SonarSource/sonarqube

public HazelcastMember build() {
 Config config = new Config();
 config.getGroupConfig().setName("SonarQube");
 NetworkConfig netConfig = config.getNetworkConfig();
 netConfig
  .setPort(port)
  .setPortAutoIncrement(false)
  .setReuseAddress(true);
 netConfig.getInterfaces()
  .setEnabled(true)
 config.getPartitionGroupConfig().setEnabled(false);
  .setProperty("hazelcast.tcp.join.port.try.count", "10")
  .setProperty("hazelcast.socket.bind.any", "false")
  .setProperty("hazelcast.phone.home.enabled", "false")
  .setProperty("hazelcast.logging.type", "slf4j");
 MemberAttributeConfig attributes = config.getMemberAttributeConfig();
 attributes.setStringAttribute(Attribute.NODE_NAME.getKey(), requireNonNull(nodeName, "Node name is missing"));
 attributes.setStringAttribute(Attribute.PROCESS_KEY.getKey(), requireNonNull(processId, "Process key is missing").getKey());
 return new HazelcastMemberImpl(Hazelcast.newHazelcastInstance(config));

代码示例来源:origin: paascloud/paascloud-master

/**
 * Hazelcast config config.
 *
 * @return the config
 */
@Bean
public Config hazelcastConfig() {
  return new Config().setProperty("hazelcast.jmx", "true")
      .addMapConfig(new MapConfig("spring-boot-admin-application-store").setBackupCount(1)
          .setEvictionPolicy(EvictionPolicy.NONE))
      .addListConfig(new ListConfig("spring-boot-admin-event-store").setBackupCount(1)
          .setMaxSize(1000));
}

代码示例来源:origin: spring-projects/spring-session

@Bean
public HazelcastInstance hazelcastInstance() {
  MapAttributeConfig attributeConfig = new MapAttributeConfig()
      .setName(HazelcastSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)
      .setExtractor(PrincipalNameExtractor.class.getName());
  Config config = new Config();
  config.getMapConfig(HazelcastSessionRepository.DEFAULT_SESSION_MAP_NAME) // <2>
      .addMapAttributeConfig(attributeConfig)
      .addMapIndexConfig(new MapIndexConfig(
          HazelcastSessionRepository.PRINCIPAL_NAME_ATTRIBUTE, false));
  return Hazelcast.newHazelcastInstance(config); // <3>
}

代码示例来源:origin: jooby-project/jooby

@Override
public void configure(final Env env, final Config conf, final Binder binder) {
 com.hazelcast.config.Config config = new com.hazelcast.config.Config();
 config.setProperties(toProperties(conf.getConfig("hazelcast")));
 if (configurer != null) {
  configurer.accept(config, conf);
 }
 HazelcastInstance hcast = Hazelcast.newHazelcastInstance(config);
 binder.bind(com.hazelcast.config.Config.class).toInstance(config);
 binder.bind(HazelcastInstance.class).toInstance(hcast);
 env.onStop(hcast::shutdown);
}

代码示例来源:origin: com.hazelcast/hazelcast-all

private void handlePort(Node node) {
  String portStr = getTextContent(node).trim();
  NetworkConfig networkConfig = config.getNetworkConfig();
  if (portStr.length() > 0) {
    networkConfig.setPort(parseInt(portStr));
  }
  NamedNodeMap attributes = node.getAttributes();
  for (int a = 0; a < attributes.getLength(); a++) {
    Node att = attributes.item(a);
    String value = getTextContent(att).trim();
    if ("auto-increment".equals(att.getNodeName())) {
      networkConfig.setPortAutoIncrement(getBooleanValue(value));
    } else if ("port-count".equals(att.getNodeName())) {
      int portCount = parseInt(value);
      networkConfig.setPortCount(portCount);
    }
  }
}

代码示例来源:origin: com.hazelcast/hazelcast-all

private void handleInterfaces(Node node) {
  NamedNodeMap attributes = node.getAttributes();
  InterfacesConfig interfaces = config.getNetworkConfig().getInterfaces();
  for (int a = 0; a < attributes.getLength(); a++) {
    Node att = attributes.item(a);
    if ("enabled".equals(att.getNodeName())) {
      String value = att.getNodeValue();
      interfaces.setEnabled(getBooleanValue(value));
    }
  }
  for (Node n : childElements(node)) {
    if ("interface".equals(lowerCaseInternal(cleanNodeName(n)))) {
      String value = getTextContent(n).trim();
      interfaces.addInterface(value);
    }
  }
}

代码示例来源:origin: hazelcast/hazelcast-jet

private void handleInterfaces(Node node) {
  NamedNodeMap attributes = node.getAttributes();
  InterfacesConfig interfaces = config.getNetworkConfig().getInterfaces();
  for (int a = 0; a < attributes.getLength(); a++) {
    Node att = attributes.item(a);
    if ("enabled".equals(att.getNodeName())) {
      String value = att.getNodeValue();
      interfaces.setEnabled(getBooleanValue(value));
    }
  }
  for (Node n : childElements(node)) {
    if ("interface".equals(lowerCaseInternal(cleanNodeName(n)))) {
      String value = getTextContent(n).trim();
      interfaces.addInterface(value);
    }
  }
}

代码示例来源:origin: com.hazelcast/hazelcast-all

private void handleMulticast(Node node) {
  JoinConfig join = config.getNetworkConfig().getJoin();
  MulticastConfig multicastConfig = join.getMulticastConfig();
  NamedNodeMap attributes = node.getAttributes();
  for (int a = 0; a < attributes.getLength(); a++) {
    Node att = attributes.item(a);
    String value = getTextContent(att).trim();
    if ("enabled".equals(lowerCaseInternal(att.getNodeName()))) {
      multicastConfig.setEnabled(getBooleanValue(value));
    } else if ("loopbackmodeenabled".equals(lowerCaseInternal(att.getNodeName()))) {
      multicastConfig.setLoopbackModeEnabled(getBooleanValue(value));
    String value = getTextContent(n).trim();
    if ("multicast-group".equals(cleanNodeName(n))) {
      multicastConfig.setMulticastGroup(value);
    } else if ("multicast-port".equals(cleanNodeName(n))) {
      multicastConfig.setMulticastPort(parseInt(value));

代码示例来源:origin: hazelcast/hazelcast-jet

private void handleMulticast(Node node) {
  JoinConfig join = config.getNetworkConfig().getJoin();
  MulticastConfig multicastConfig = join.getMulticastConfig();
  NamedNodeMap attributes = node.getAttributes();
  for (int a = 0; a < attributes.getLength(); a++) {
    Node att = attributes.item(a);
    String value = getTextContent(att).trim();
    if ("enabled".equals(lowerCaseInternal(att.getNodeName()))) {
      multicastConfig.setEnabled(getBooleanValue(value));
    } else if ("loopbackmodeenabled".equals(lowerCaseInternal(att.getNodeName()))) {
      multicastConfig.setLoopbackModeEnabled(getBooleanValue(value));
    String value = getTextContent(n).trim();
    if ("multicast-group".equals(cleanNodeName(n))) {
      multicastConfig.setMulticastGroup(value);
    } else if ("multicast-port".equals(cleanNodeName(n))) {
      multicastConfig.setMulticastPort(parseInt(value));

代码示例来源:origin: com.hazelcast/hazelcast-all

private void handleTcpIp(Node node) {
  NamedNodeMap attributes = node.getAttributes();
  JoinConfig join = config.getNetworkConfig().getJoin();
  TcpIpConfig tcpIpConfig = join.getTcpIpConfig();
  for (int a = 0; a < attributes.getLength(); a++) {
    Node att = attributes.item(a);
    String value = getTextContent(att).trim();
    if (att.getNodeName().equals("enabled")) {
      tcpIpConfig.setEnabled(getBooleanValue(value));
    } else if (att.getNodeName().equals("connection-timeout-seconds")) {
      tcpIpConfig.setConnectionTimeoutSeconds(getIntegerValue("connection-timeout-seconds", value));
    }
  }
  Set<String> memberTags = new HashSet<String>(Arrays.asList("interface", "member", "members"));
  for (Node n : childElements(node)) {
    String value = getTextContent(n).trim();
    if (cleanNodeName(n).equals("member-list")) {
      handleMemberList(n);
    } else if (cleanNodeName(n).equals("required-member")) {
      if (tcpIpConfig.getRequiredMember() != null) {
        throw new InvalidConfigurationException("Duplicate required-member"
            + " definition found in XML configuration. ");
      }
      tcpIpConfig.setRequiredMember(value);
    } else if (memberTags.contains(cleanNodeName(n))) {
      tcpIpConfig.addMember(value);
    }
  }
}

代码示例来源:origin: hazelcast/hazelcast-jet

private void handleTcpIp(Node node) {
  NamedNodeMap attributes = node.getAttributes();
  JoinConfig join = config.getNetworkConfig().getJoin();
  TcpIpConfig tcpIpConfig = join.getTcpIpConfig();
  for (int a = 0; a < attributes.getLength(); a++) {
    Node att = attributes.item(a);
    String value = getTextContent(att).trim();
    if (att.getNodeName().equals("enabled")) {
      tcpIpConfig.setEnabled(getBooleanValue(value));
    } else if (att.getNodeName().equals("connection-timeout-seconds")) {
      tcpIpConfig.setConnectionTimeoutSeconds(getIntegerValue("connection-timeout-seconds", value));
    }
  }
  Set<String> memberTags = new HashSet<String>(Arrays.asList("interface", "member", "members"));
  for (Node n : childElements(node)) {
    String value = getTextContent(n).trim();
    if (cleanNodeName(n).equals("member-list")) {
      handleMemberList(n);
    } else if (cleanNodeName(n).equals("required-member")) {
      if (tcpIpConfig.getRequiredMember() != null) {
        throw new InvalidConfigurationException("Duplicate required-member"
            + " definition found in XML configuration. ");
      }
      tcpIpConfig.setRequiredMember(value);
    } else if (memberTags.contains(cleanNodeName(n))) {
      tcpIpConfig.addMember(value);
    }
  }
}

代码示例来源:origin: com.hazelcast/hazelcast-all

private void handleMemberAddressProvider(Node node) {
  Node enabledNode = node.getAttributes().getNamedItem("enabled");
  boolean enabled = enabledNode != null && getBooleanValue(getTextContent(enabledNode));
  MemberAddressProviderConfig memberAddressProviderConfig = config.getNetworkConfig().getMemberAddressProviderConfig();
  memberAddressProviderConfig.setEnabled(enabled);
  for (Node n : childElements(node)) {
    String nodeName = cleanNodeName(n);
    if (nodeName.equals("class-name")) {
      String className = getTextContent(n);
      memberAddressProviderConfig.setClassName(className);
    } else if (nodeName.equals("properties")) {
      fillProperties(n, memberAddressProviderConfig.getProperties());
    }
  }
}

代码示例来源:origin: com.hazelcast/hazelcast-all

private void handleFailureDetector(Node node) {
  if (!node.hasChildNodes()) {
    return;
  for (Node child : childElements(node)) {
    if (!cleanNodeName(child).equals("icmp")) {
      throw new IllegalStateException("Unsupported child under failure-detector");
    Node enabledNode = child.getAttributes().getNamedItem("enabled");
    boolean enabled = enabledNode != null && getBooleanValue(getTextContent(enabledNode));
    IcmpFailureDetectorConfig icmpFailureDetectorConfig = new IcmpFailureDetectorConfig();
    config.getNetworkConfig().setIcmpFailureDetectorConfig(icmpFailureDetectorConfig);

代码示例来源:origin: hazelcast/hazelcast-jet

private void handleFailureDetector(Node node) {
  if (!node.hasChildNodes()) {
    return;
    Node enabledNode = child.getAttributes().getNamedItem("enabled");
    boolean enabled = enabledNode != null && getBooleanValue(getTextContent(enabledNode));
    IcmpFailureDetectorConfig icmpFailureDetectorConfig = new IcmpFailureDetectorConfig();
    config.getNetworkConfig().setIcmpFailureDetectorConfig(icmpFailureDetectorConfig);

代码示例来源:origin: com.hazelcast/hazelcast-all

@SuppressWarnings("deprecation")
private void handleMap(Node parentNode) {
  String name = getAttribute(parentNode, "name");
  MapConfig mapConfig = new MapConfig();
  mapConfig.setName(name);
  for (Node node : childElements(parentNode)) {
    String nodeName = cleanNodeName(node);
    String value = getTextContent(node).trim();
    if ("backup-count".equals(nodeName)) {
    } else if ("max-size".equals(nodeName)) {
      MaxSizeConfig msc = mapConfig.getMaxSizeConfig();
      Node maxSizePolicy = node.getAttributes().getNamedItem("policy");
      if (maxSizePolicy != null) {
        msc.setMaxSizePolicy(MaxSizeConfig.MaxSizePolicy.valueOf(
      String className = checkHasText(getTextContent(node), "map-eviction-policy-class-name cannot be null or empty");
      try {
        MapEvictionPolicy mapEvictionPolicy = ClassLoaderUtil.newInstance(config.getClassLoader(), className);
        mapConfig.setMapEvictionPolicy(mapEvictionPolicy);
      } catch (Exception e) {
  config.addMapConfig(mapConfig);

代码示例来源:origin: hazelcast/hazelcast-jet

private void handleSSLConfig(Node node) {
  SSLConfig sslConfig = new SSLConfig();
  NamedNodeMap attributes = node.getAttributes();
  Node enabledNode = attributes.getNamedItem("enabled");
  boolean enabled = enabledNode != null && getBooleanValue(getTextContent(enabledNode).trim());
  sslConfig.setEnabled(enabled);
  for (Node n : childElements(node)) {
    String nodeName = cleanNodeName(n);
    if ("factory-class-name".equals(nodeName)) {
      sslConfig.setFactoryClassName(getTextContent(n).trim());
    } else if ("properties".equals(nodeName)) {
      fillProperties(n, sslConfig.getProperties());
    }
  }
  config.getNetworkConfig().setSSLConfig(sslConfig);
}

代码示例来源:origin: hazelcast/hazelcast-jet

private void handleMemberAddressProvider(Node node) {
  Node enabledNode = node.getAttributes().getNamedItem("enabled");
  boolean enabled = enabledNode != null && getBooleanValue(getTextContent(enabledNode));
  MemberAddressProviderConfig memberAddressProviderConfig = config.getNetworkConfig().getMemberAddressProviderConfig();
  memberAddressProviderConfig.setEnabled(enabled);
  for (Node n : childElements(node)) {
    String nodeName = cleanNodeName(n);
    if (nodeName.equals("class-name")) {
      String className = getTextContent(n);
      memberAddressProviderConfig.setClassName(className);
    } else if (nodeName.equals("properties")) {
      fillProperties(n, memberAddressProviderConfig.getProperties());
    }
  }
}

代码示例来源:origin: hazelcast/hazelcast-code-samples

/**
   * Create a Hazelcast instance for testing, a server instance not connected to others, so turn off discovery.
   *
   * @return A standalone server instance, auto-closeable
   */
  @Bean
  public HazelcastInstance hazelcastInstance() {
    Config config = new Config();

    config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);

    return Hazelcast.newHazelcastInstance(config);
  }
}

代码示例来源:origin: hazelcast/hazelcast-code-samples

public static void main(String[] args) {
    Config config = new Config();
    config.getSerializationConfig()
        .addPortableFactory(SamplePortableFactory.FACTORY_ID, new SamplePortableFactory());
    // Start the Embedded Hazelcast Cluster Member.
    HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
    //Customer can be used here
    hz.shutdown();
  }
}

代码示例来源:origin: hazelcast/hazelcast-code-samples

public static void main(String[] args) throws Exception {
    Config config = new Config();
    config.setProperty("hazelcast.rest.enabled", "true");
    HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
    Person person = new Person("Joe");

    IMap<String, String> hzSimpleMap = hz.getMap("simple");
    hzSimpleMap.set("key1", "value1");

    IMap<String, Person> hzObjectMap = hz.getMap("object");
    hzObjectMap.set("key1", person);
  }
}

相关文章

Config类方法