com.hazelcast.core.Hazelcast.getOrCreateHazelcastInstance()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(188)

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

Hazelcast.getOrCreateHazelcastInstance介绍

[英]Gets or creates a HazelcastInstance with the default XML configuration looked up in:

  1. System property: Hazelcast will first check if "hazelcast.config" system property is set to a file or a classpath:... path. Examples: -Dhazelcast.config=C:/myhazelcast.xml , -Dhazelcast.config=classpath:the-hazelcast-config.xml , -Dhazelcast.config=classpath:com/mydomain/hazelcast.xml
  2. "hazelcast.xml" file in current working directory
  3. Classpath: Hazelcast will check classpath for hazelcast.xml file.
    If a configuration file is not located, an IllegalArgumentException will be thrown. If a Hazelcast instance with the same name as the configuration exists, then it is returned, otherwise it is created.
    [中]获取或创建具有在中查找的默认XML配置的HazelcastInstance:
    1.系统属性:Hazelcast将首先检查“Hazelcast.config”系统属性是否设置为文件或类路径:。。。路径示例:-Dhazelcast。config=C:/myhazelcast。xml,-Dhazelcast。config=classpath:hazelcast配置。xml,-Dhazelcast。config=classpath:com/mydomain/hazelcast。xml
    1.当前工作目录中的“hazelcast.xml”文件
    1.类路径:Hazelcast将检查Hazelcast的类路径。xml文件。
    如果未找到配置文件,将引发IllegalArgumentException。如果存在与配置同名的Hazelcast实例,则返回该实例,否则将创建该实例。

代码示例

代码示例来源:origin: org.jnosql.diana/hazelcast-driver

/**
 * Creates a {@link HazelcastBucketManagerFactory} from hazelcast config
 * @param config the {@link Config}
 * @return the HazelCastBucketManagerFactory instance
 * @throws NullPointerException when config is null
 */
public HazelcastBucketManagerFactory get(Config config)throws NullPointerException {
  requireNonNull(config, "config is required");
  HazelcastInstance hazelcastInstance = Hazelcast.getOrCreateHazelcastInstance(config);
  return new DefaultHazelcastBucketManagerFactory(hazelcastInstance);
}

代码示例来源:origin: org.jnosql.diana/hazelcast-driver

/**
 * Creates a {@link HazelcastBucketManagerFactory} from configuration map
 * @param configurations the configuration map
 * @return the HazelCastBucketManagerFactory instance
 * @throws NullPointerException when configurations is null
 */
public HazelcastBucketManagerFactory get(Map<String, String> configurations) throws NullPointerException {
  List<String> servers = configurations.keySet().stream().filter(s -> s.startsWith("hazelcast-hoster-"))
      .collect(Collectors.toList());
  Config config = new Config(configurations.getOrDefault("hazelcast-instanceName", "hazelcast-instanceName"));
  HazelcastInstance hazelcastInstance = Hazelcast.getOrCreateHazelcastInstance(config);
  return new DefaultHazelcastBucketManagerFactory(hazelcastInstance);
}

代码示例来源:origin: vgoldin/cqrs-eventsourcing-kafka

public static HazelcastInstance getInstance() {
  if (hazelcastInstance == null) {
    Config config = new XmlConfigBuilder().build();
    config.setInstanceName(Thread.currentThread().getName());
    hazelcastInstance = Hazelcast.getOrCreateHazelcastInstance(config);
  }
  return hazelcastInstance;
}

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

private HazelcastInstance getDefaultInstance() {
  if (hazelcastInstance == null) {
    // if there is no default instance in use (not created yet and not specified):
    // 1. locate default ClientConfig: if it specifies an instance name, get-or-create an instance by that name
    // 2. otherwise start a new Hazelcast member
    Config config = getDefaultConfig();
    if (isNullOrEmptyAfterTrim(config.getInstanceName())) {
      hazelcastInstance = Hazelcast.newHazelcastInstance();
    } else {
      hazelcastInstance = Hazelcast.getOrCreateHazelcastInstance(config);
    }
  }
  return hazelcastInstance;
}

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

private HazelcastInstance getDefaultInstance() {
  if (hazelcastInstance == null) {
    // if there is no default instance in use (not created yet and not specified):
    // 1. locate default ClientConfig: if it specifies an instance name, get-or-create an instance by that name
    // 2. otherwise start a new Hazelcast member
    Config config = getDefaultConfig();
    if (isNullOrEmptyAfterTrim(config.getInstanceName())) {
      hazelcastInstance = Hazelcast.newHazelcastInstance();
    } else {
      hazelcastInstance = Hazelcast.getOrCreateHazelcastInstance(config);
    }
  }
  return hazelcastInstance;
}

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

/**
 * Gets an existing {@link HazelcastInstance} by {@code instanceName} or,
 * if not found, creates a new {@link HazelcastInstance} with the default
 * configuration and given {@code instanceName}.
 *
 * @param instanceName name to lookup an existing {@link HazelcastInstance}
 *                     or to create a new one
 * @return a {@link HazelcastInstance} with the given {@code instanceName}
 */
private HazelcastInstance getOrCreateByInstanceName(String instanceName) {
  HazelcastInstance instance = Hazelcast.getHazelcastInstanceByName(instanceName);
  if (instance == null) {
    Config config = getDefaultConfig();
    config.setInstanceName(instanceName);
    instance = Hazelcast.getOrCreateHazelcastInstance(config);
  }
  return instance;
}

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

/**
 * Gets an existing {@link HazelcastInstance} by {@code instanceName} or,
 * if not found, creates a new {@link HazelcastInstance} with the default
 * configuration and given {@code instanceName}.
 *
 * @param instanceName name to lookup an existing {@link HazelcastInstance}
 *                     or to create a new one
 * @return a {@link HazelcastInstance} with the given {@code instanceName}
 */
private HazelcastInstance getOrCreateByInstanceName(String instanceName) {
  HazelcastInstance instance = Hazelcast.getHazelcastInstanceByName(instanceName);
  if (instance == null) {
    Config config = getDefaultConfig();
    config.setInstanceName(instanceName);
    instance = Hazelcast.getOrCreateHazelcastInstance(config);
  }
  return instance;
}

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

/**
   * Create hazelcast full instance.
   *
   * @param configLocation the config location
   * @return the hazelcast instance
   */
  public static HazelcastInstance createHazelcastFullInstance(String configLocation) {
    Config config;
    try {
      if (configLocation == null) {
        config = new XmlConfigBuilder().build();
      } else {
        config = ConfigLoader.load(configLocation);
      }
    } catch (IOException e) {
      throw new RuntimeException("failed to load config", e);
    }

    checkNotNull(config, "failed to find configLocation: " + configLocation);

    config.setInstanceName(DEFAULT_INSTANCE_NAME);
    return Hazelcast.getOrCreateHazelcastInstance(config);
  }
}

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

} else if (config != null) {
  if (ObjectHelper.isNotEmpty(config.getInstanceName())) {
    hzInstance = Hazelcast.getOrCreateHazelcastInstance(config);
  } else {
    hzInstance = Hazelcast.newHazelcastInstance(config);

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

this.hazelcastInstance = Hazelcast.getOrCreateHazelcastInstance(this.hazelcastConfig);

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

this.hazelcastInstance = Hazelcast.getOrCreateHazelcastInstance(this.hazelcastConfig);

代码示例来源:origin: org.wso2.siddhi/siddhi-extension-event-table

return Hazelcast.getOrCreateHazelcastInstance(config);
} else {
  ClientConfig clientConfig = new ClientConfig();

代码示例来源:origin: com.intrbiz.util/cache-hazelcast

this.hazelcastInstance = Hazelcast.getOrCreateHazelcastInstance(config);

代码示例来源:origin: org.eclipse.jetty/jetty-hazelcast

hazelcastInstance = Hazelcast.getOrCreateHazelcastInstance( config );

相关文章