com.hazelcast.config.Config Java Examples

The following examples show how to use com.hazelcast.config.Config. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestCustomerSerializers.java    From subzero with Apache License 2.0 6 votes vote down vote up
@Test
public void testTypedCustomSerializer_configuredBySubclassing() throws Exception {
    String mapName = randomMapName();

    Config config = new Config();
    SerializerConfig serializerConfig = new SerializerConfig();
    serializerConfig.setClass(MySerializer.class);
    serializerConfig.setTypeClass(AnotherNonSerializableObject.class);
    config.getSerializationConfig().getSerializerConfigs().add(serializerConfig);

    HazelcastInstance member = hazelcastFactory.newHazelcastInstance(config);
    IMap<Integer, AnotherNonSerializableObject> myMap = member.getMap(mapName);

    myMap.put(0, new AnotherNonSerializableObject());
    AnotherNonSerializableObject fromCache = myMap.get(0);

    assertEquals("deserialized", fromCache.name);
}
 
Example #2
Source File: HazelcastConfigVariable.java    From hazelcast-demo with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
	try {
		// 获取配置文件磁盘路径
		final String path = Thread.currentThread().getContextClassLoader().getResource("").toString() + DEF_CONFIG_FILE;
		// 构建XML配置
		XmlConfigBuilder builder = new XmlConfigBuilder(path);
		// 配置对应的properties解析参数
		builder.setProperties(getProperties());
		// 创建Config
		Config config = builder.build();
		// 输出Config参数
		System.out.println(config.getGroupConfig().getName());
	} catch (FileNotFoundException e) {
		e.printStackTrace();
	}
}
 
Example #3
Source File: AtomicExample.java    From chuidiang-ejemplos with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void main( String[] args ) throws FileNotFoundException, InterruptedException
{
   Config config = new Config();
   HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
   
   IAtomicLong atomicLong = hazelcastInstance.getAtomicLong("soy productor");
   
   boolean cambiado = atomicLong.compareAndSet(0, 1);
   
   if (cambiado){
      produce(hazelcastInstance);
   } else {
      consume(hazelcastInstance);
   }
   
}
 
Example #4
Source File: Hazelcast.java    From lannister with Apache License 2.0 6 votes vote down vote up
private Config createConfig() {
	Config config;
	try {
		config = new XmlConfigBuilder(Application.class.getClassLoader().getResource(CONFIG_NAME)).build();
	}
	catch (IOException e) {
		logger.error(e.getMessage(), e);
		throw new Error(e);
	}

	config.getSerializationConfig().addDataSerializableFactory(SerializableFactory.ID, new SerializableFactory());

	config.getSerializationConfig().getSerializerConfigs().add(new SerializerConfig().setTypeClass(JsonNode.class)
			.setImplementation(JsonSerializer.makePlain(JsonNode.class)));

	return config;
}
 
Example #5
Source File: HazelcastConfigRuntimeModify.java    From hazelcast-demo with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
	// 创建默认config对象
	Config config = new Config();
	
	// 获取network元素<network></network>
	NetworkConfig netConfig = config.getNetworkConfig();
	System.out.println("Default port:" + netConfig.getPort());
	
	// 设置组网起始监听端口
	netConfig.setPort(9701);
	System.out.println("Customer port:" + netConfig.getPort());
	// 获取join元素<join></join>
	JoinConfig joinConfig = netConfig.getJoin();
	// 获取multicast元素<multicast></multicast>
	MulticastConfig multicastConfig = joinConfig.getMulticastConfig();
	// 输出组播协议端口
	System.out.println(multicastConfig.getMulticastPort());
	// 禁用multicast协议
	multicastConfig.setEnabled(false);
	
	// 初始化Hazelcast
	Hazelcast.newHazelcastInstance(config);
}
 
Example #6
Source File: Examples.java    From vertx-hazelcast with Apache License 2.0 6 votes vote down vote up
public void customizeDefaultConfig() {
  Config hazelcastConfig = ConfigUtil.loadConfig();

  hazelcastConfig.setClusterName("my-cluster-name");

  ClusterManager mgr = new HazelcastClusterManager(hazelcastConfig);

  VertxOptions options = new VertxOptions().setClusterManager(mgr);

  Vertx.clusteredVertx(options, res -> {
    if (res.succeeded()) {
      Vertx vertx = res.result();
    } else {
      // failed!
    }
  });
}
 
Example #7
Source File: HazelcastReentrantReadWriteLockTest.java    From hazelcast-locks with Apache License 2.0 6 votes vote down vote up
@BeforeClass
    public static void createGrids() {
		/* Suppress Hazelcast log output to standard error which does not appear to be suppressible via Agent Server's
		 * log4j.xml. */
//        ConsoleOutputSuppressor.suppressStandardError();
        final Config standardConfig1 = new ClasspathXmlConfig("hazelcast1.xml"),
                standardConfig2 = new ClasspathXmlConfig("hazelcast2.xml");

        standardConfig1.setProperty("hazelcast.operation.call.timeout.millis", "3000");
        standardConfig2.setProperty("hazelcast.operation.call.timeout.millis", "3000");
        grid1 = Hazelcast.newHazelcastInstance(standardConfig1);
        grid2 = Hazelcast.newHazelcastInstance(standardConfig2);

        dataStructureFactory1 = HazelcastDataStructureFactory.getInstance(grid1);
        dataStructureFactory2 = HazelcastDataStructureFactory.getInstance(grid2);

        lockService1 = new DistributedLockUtils().new PublicDistributedLockService(dataStructureFactory1);
        lockService2 = new DistributedLockUtils().new PublicDistributedLockService(dataStructureFactory2);
    }
 
Example #8
Source File: InstanceHelper.java    From spring-data-hazelcast with Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * Create a cluster using {@code 127.0.0.1:5701} as the master. The master must be created first, and may be the only
 * server instance in this JVM.
 * </P>
 *
 * @param name Enables easy identification
 * @param port The only port this server can use.
 * @return The master or the 2nd server in the cluster
 */
public static HazelcastInstance makeServer(final String name, final int port) {
    Config hazelcastConfig = new Config(name);

    hazelcastConfig.getNetworkConfig().setReuseAddress(true);

    hazelcastConfig.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
    hazelcastConfig.getNetworkConfig().getJoin().getAwsConfig().setEnabled(false);

    TcpIpConfig tcpIpConfig = hazelcastConfig.getNetworkConfig().getJoin().getTcpIpConfig();
    tcpIpConfig.setEnabled(true);
    tcpIpConfig.setMembers(Arrays.asList(MASTER_SERVER));
    tcpIpConfig.setRequiredMember(MASTER_SERVER);

    hazelcastConfig.getNetworkConfig().setPort(port);
    hazelcastConfig.getNetworkConfig().setPortAutoIncrement(false);

    HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(hazelcastConfig);

    LOG.debug("Created {}", hazelcastInstance);

    return hazelcastInstance;
}
 
Example #9
Source File: HazelcastMemberFactory.java    From incubator-batchee with Apache License 2.0 6 votes vote down vote up
public static HazelcastInstance findOrCreateMember(final String xmlConfiguration, String instanceName) throws IOException {
    final HazelcastInstance found = Hazelcast.getHazelcastInstanceByName(instanceName);
    if (found != null) {
        return found;
    }

    final Config config;
    if (xmlConfiguration != null) {
        config =  new XmlConfigBuilder(IOs.findConfiguration(xmlConfiguration)).build();
    } else {
        config =  new XmlConfigBuilder().build();
    }
    if (instanceName != null) {
        config.setInstanceName(instanceName);
    }
    return Hazelcast.newHazelcastInstance(config);
}
 
Example #10
Source File: HazelcastMemoryService.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
 * Service INIT
 */
public void init() {
    String clientServers = serverConfigurationService.getString("memory.hc.server", null);
    boolean clientConfigured = StringUtils.isNotBlank(clientServers);
    if (clientConfigured) {
        ClientConfig clientConfig = new ClientConfig();
        ClientNetworkConfig clientNetworkConfig = new ClientNetworkConfig();
        clientNetworkConfig.addAddress(StringUtils.split(clientServers, ','));
        clientConfig.setNetworkConfig(clientNetworkConfig);
        hcInstance = HazelcastClient.newHazelcastClient(clientConfig);
    } else {
        // start up a local server instead
        Config localConfig = new Config();
        localConfig.setInstanceName(serverConfigurationService.getServerIdInstance());
        hcInstance = Hazelcast.newHazelcastInstance(localConfig);
    }
    if (hcInstance == null) {
        throw new IllegalStateException("init(): HazelcastInstance is null!");
    }
    log.info("INIT: " + hcInstance.getName() + " ("+(clientConfigured?"client:"+hcInstance.getClientService():"localServer")+"), cache maps: " + hcInstance.getDistributedObjects());
}
 
Example #11
Source File: AdminApplicationHazelcastTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@Bean
public Config hazelcastConfig() {
	MapConfig eventStoreMap = new MapConfig(DEFAULT_NAME_EVENT_STORE_MAP)
			.setInMemoryFormat(InMemoryFormat.OBJECT).setBackupCount(1).setEvictionPolicy(EvictionPolicy.NONE)
			.setMergePolicyConfig(new MergePolicyConfig(PutIfAbsentMapMergePolicy.class.getName(), 100));

	MapConfig sentNotificationsMap = new MapConfig(DEFAULT_NAME_SENT_NOTIFICATIONS_MAP)
			.setInMemoryFormat(InMemoryFormat.OBJECT).setBackupCount(1).setEvictionPolicy(EvictionPolicy.LRU)
			.setMergePolicyConfig(new MergePolicyConfig(PutIfAbsentMapMergePolicy.class.getName(), 100));

	Config config = new Config();
	config.addMapConfig(eventStoreMap);
	config.addMapConfig(sentNotificationsMap);
	config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
	TcpIpConfig tcpIpConfig = config.getNetworkConfig().getJoin().getTcpIpConfig();
	tcpIpConfig.setEnabled(true);
	tcpIpConfig.setMembers(singletonList("127.0.0.1"));
	return config;
}
 
Example #12
Source File: BasicTestCase.java    From snowcast with Apache License 2.0 6 votes vote down vote up
@Test
public void test_simple_sequencer_initialization_declarative()
        throws Exception {

    ClassLoader classLoader = BasicTestCase.class.getClassLoader();
    InputStream stream = classLoader.getResourceAsStream("hazelcast-node-configuration.xml");
    Config config = new XmlConfigBuilder(stream).build();

    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(1);
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance(config);

    try {
        Snowcast snowcast = SnowcastSystem.snowcast(hazelcastInstance);
        SnowcastSequencer sequencer = buildSnowcastSequencer(snowcast);

        assertNotNull(sequencer);
    } finally {
        factory.shutdownAll();
    }
}
 
Example #13
Source File: Cluster.java    From OSPREY3 with GNU General Public License v2.0 6 votes vote down vote up
public Member(Parallelism parallelism) {

			this.parallelism = parallelism;
			this.name = String.format("%s-member-%d", Cluster.this.name, nodeId);

			// configure the cluster
			Config cfg = new Config();
			cfg.setClusterName(id);
			cfg.setInstanceName(name);
			cfg.getQueueConfig(TasksScatterName).setMaxSize(numMembers()*2);

			// disable Hazelcast's automatic phone home "feature", which is on by default
			cfg.setProperty("hazelcast.phone.home.enabled", "false");

			inst = Hazelcast.newHazelcastInstance(cfg);

			log("node started on cluster %s", id);

			activeId = new Value<>(inst, TasksActiveIdName);
			scatter = inst.getQueue(TasksScatterName);
			gather = inst.getQueue(TasksGatherName);
		}
 
Example #14
Source File: CacheConfiguration.java    From flair-engine with Apache License 2.0 6 votes vote down vote up
@Bean
public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) {
    log.debug("Configuring Hazelcast");
    HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("fbiengine");
    if (hazelCastInstance != null) {
        log.debug("Hazelcast already initialized");
        return hazelCastInstance;
    }
    Config config = new Config();
    config.setInstanceName("fbiengine");
    config.getNetworkConfig().setPort(5701);
    config.getNetworkConfig().setPortAutoIncrement(true);

    // In development, remove multicast auto-configuration
    if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) {
        System.setProperty("hazelcast.local.localAddress", "127.0.0.1");

        config.getNetworkConfig().getJoin().getAwsConfig().setEnabled(false);
        config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
        config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(false);
    }
    config.getMapConfigs().put("default", initializeDefaultMapConfig());
    config.getMapConfigs().put("com.fbi.engine.domain.*", initializeDomainMapConfig(jHipsterProperties));
    return Hazelcast.newHazelcastInstance(config);
}
 
Example #15
Source File: Examples.java    From vertx-hazelcast with Apache License 2.0 6 votes vote down vote up
public void example2() {

    Config hazelcastConfig = new Config();

    // Now set some stuff on the config (omitted)

    ClusterManager mgr = new HazelcastClusterManager(hazelcastConfig);

    VertxOptions options = new VertxOptions().setClusterManager(mgr);

    Vertx.clusteredVertx(options, res -> {
      if (res.succeeded()) {
        Vertx vertx = res.result();
      } else {
        // failed!
      }
    });
  }
 
Example #16
Source File: ElasticsearchQueryStoreTest.java    From foxtrot with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    this.dataStore = Mockito.mock(DataStore.class);

    HazelcastConnection hazelcastConnection = Mockito.mock(HazelcastConnection.class);
    when(hazelcastConnection.getHazelcast()).thenReturn(hazelcastInstance);
    when(hazelcastConnection.getHazelcastConfig()).thenReturn(new Config());

    CardinalityConfig cardinalityConfig = new CardinalityConfig("true", String.valueOf(ElasticsearchUtils.DEFAULT_SUB_LIST_SIZE));
    TestUtils.ensureIndex(elasticsearchConnection, TableMapStore.TABLE_META_INDEX);
    TestUtils.ensureIndex(elasticsearchConnection, DistributedTableMetadataManager.CARDINALITY_CACHE_INDEX);
    this.tableMetadataManager = new DistributedTableMetadataManager(
            hazelcastConnection, elasticsearchConnection, mapper, cardinalityConfig);
    tableMetadataManager.start();
    tableMetadataManager.save(Table.builder()
            .name(TestUtils.TEST_TABLE_NAME)
            .ttl(30)
            .build());
    this.removerConfiguration = spy(TextNodeRemoverConfiguration.builder().build());
    List<IndexerEventMutator> mutators = Lists.newArrayList(new LargeTextNodeRemover(mapper, removerConfiguration));
    this.queryStore = new ElasticsearchQueryStore(tableMetadataManager, elasticsearchConnection, dataStore, mutators, mapper, cardinalityConfig);
}
 
Example #17
Source File: ClusterNode.java    From modernmt with Apache License 2.0 5 votes vote down vote up
private Config getHazelcastConfig(NodeConfig nodeConfig, long interval, TimeUnit unit) {
    Config hazelcastConfig = new XmlConfigBuilder().build();
    hazelcastConfig.setGroupConfig(
            new GroupConfig().setName(this.clusterName));

    NetworkConfig networkConfig = nodeConfig.getNetworkConfig();
    if (unit != null && interval > 0L) {
        long seconds = Math.max(unit.toSeconds(interval), 1L);
        hazelcastConfig.setProperty("hazelcast.max.join.seconds", Long.toString(seconds));
    }

    String host = networkConfig.getHost();
    if (host != null)
        hazelcastConfig.getNetworkConfig().setPublicAddress(host);

    hazelcastConfig.getNetworkConfig().setPort(networkConfig.getPort());

    String listenInterface = networkConfig.getListeningInterface();
    if (listenInterface != null) {
        hazelcastConfig.getNetworkConfig().getInterfaces()
                .setEnabled(true)
                .addInterface(listenInterface);
        hazelcastConfig.setProperty("hazelcast.local.localAddress", listenInterface);
        hazelcastConfig.setProperty("hazelcast.local.publicAddress", listenInterface);
    }

    JoinConfig joinConfig = networkConfig.getJoinConfig();
    JoinConfig.Member[] members = joinConfig.getMembers();
    if (members != null && members.length > 0) {
        TcpIpConfig tcpIpConfig = hazelcastConfig.getNetworkConfig().getJoin().getTcpIpConfig();
        tcpIpConfig.setConnectionTimeoutSeconds(joinConfig.getTimeout());
        tcpIpConfig.setEnabled(true);

        for (JoinConfig.Member member : members)
            tcpIpConfig.addMember(member.getHost() + ":" + member.getPort());
    }

    return hazelcastConfig;
}
 
Example #18
Source File: TransactionManagerConfig.java    From hazelcastmq with Apache License 2.0 5 votes vote down vote up
@Bean(destroyMethod = "shutdown")
public HazelcastInstance hazelcast() {
  Config config = new Config();
  config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);

  return Hazelcast.newHazelcastInstance(config);
}
 
Example #19
Source File: HazelcastSharedStateComponentTest.java    From apiman with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    final Config config = HazelcastConfigUtil.buildConfigWithDisabledNetwork();
    HazelcastInstanceManager.DEFAULT_MANAGER.setOverrideConfig(config);

    component = new HazelcastSharedStateComponent(emptyMap());
}
 
Example #20
Source File: HazelcastCommandExecutorTest.java    From concursus with MIT License 5 votes vote down vote up
private CommandExecutor getCommandExecutor() {
    ObjectMapper objectMapper = new ObjectMapper().findAndRegisterModules();

    HazelcastCommandExecutorConfiguration config = HazelcastCommandExecutorConfiguration.using(objectMapper);
    config.subscribe(TestCommands.class, (ts, id, input) -> input.toUpperCase());

    HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(
            config.addCommandExecutorConfiguration(new Config()));

    return config.getCommandExecutor(hazelcastInstance);
}
 
Example #21
Source File: SubZeroTest.java    From subzero with Apache License 2.0 5 votes vote down vote up
@Test
public void givenGlobalSerializerConfigDoes_whenUseAsGlobalSerializer_thenNewSubZeroIsUsedAsGlobalSerializer() {
    Config config = new Config();
    config.getSerializationConfig().setGlobalSerializerConfig(new GlobalSerializerConfig().setClassName("foo"));

    SubZero.useAsGlobalSerializer(config);

    assertEquals(Serializer.class.getName(), config.getSerializationConfig().getGlobalSerializerConfig().getClassName());
}
 
Example #22
Source File: ProgrammaticHazelcastClusterManagerTest.java    From vertx-hazelcast with Apache License 2.0 5 votes vote down vote up
@Test
public void testProgrammaticSetConfig() throws Exception {
  Config config = createConfig();
  HazelcastClusterManager mgr = new HazelcastClusterManager();
  mgr.setConfig(config);
  testProgrammatic(mgr, config);
}
 
Example #23
Source File: HazelcastConfigSimple.java    From hazelcast-demo with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	// 从classpath加载配置文件
	Config config = new ClasspathXmlConfig("xmlconfig/simple-config.xml");
	// 获取网络配置
	NetworkConfig netConfig = config.getNetworkConfig();
	// 获取用户定义的map配置
	MapConfig mapConfigXml = config.getMapConfig("demo.config");
	// 获取系统默认的map配置
	MapConfig mapConfigDefault = config.getMapConfig("default");
	// 输出集群监听的起始端口号
	System.out.println("Current port:" + netConfig.getPort());
	// 输出监听端口的累加号
	System.out.println("Current port count:" + netConfig.getPortCount());
	// 输出自定义map的备份副本个数
	System.out.println("Config map backup count:" + mapConfigXml.getBackupCount());
	// 输出默认map的备份副本个数
	System.out.println("Default map backup count:" + mapConfigDefault.getBackupCount());

	// 测试创建Hazelcast实例并读写测试数据
	HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
	HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config);

	Map<Integer, String> defaultMap1 = instance1.getMap("defaultMap");
	defaultMap1.put(1, "testMap");
	Map<Integer, String> configMap1 = instance1.getMap("configMap");
	configMap1.put(1, "configMap");

	Map<Integer, String> testMap2 = instance2.getMap("defaultMap");
	System.out.println("Default map value:" + testMap2.get(1));
	Map<Integer, String> configMap2 = instance2.getMap("configMap");
	System.out.println("Config map value:" + configMap2.get(1));
}
 
Example #24
Source File: TransactionAwareConfig.java    From hazelcastmq with Apache License 2.0 5 votes vote down vote up
@Bean(destroyMethod = "shutdown")
public HazelcastInstance hazelcast() {
  Config config = new Config();
  config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);

  return Hazelcast.newHazelcastInstance(config);
}
 
Example #25
Source File: HazelcastSessionDao.java    From spring-boot-shiro-orientdb with Apache License 2.0 5 votes vote down vote up
public HazelcastSessionDao() {
    log.info("Initializing Hazelcast Shiro session persistence..");

    // configure Hazelcast instance
    final Config cfg = new Config();
    cfg.setInstanceName(hcInstanceName);
    // group configuration
    cfg.setGroupConfig(new GroupConfig(HC_GROUP_NAME, HC_GROUP_PASSWORD));
    // network configuration initialization
    final NetworkConfig netCfg = new NetworkConfig();
    netCfg.setPortAutoIncrement(true);
    netCfg.setPort(HC_PORT);
    // multicast
    final MulticastConfig mcCfg = new MulticastConfig();
    mcCfg.setEnabled(false);
    mcCfg.setMulticastGroup(HC_MULTICAST_GROUP);
    mcCfg.setMulticastPort(HC_MULTICAST_PORT);
    // tcp
    final TcpIpConfig tcpCfg = new TcpIpConfig();
    tcpCfg.addMember("127.0.0.1");
    tcpCfg.setEnabled(false);
    // network join configuration
    final JoinConfig joinCfg = new JoinConfig();
    joinCfg.setMulticastConfig(mcCfg);
    joinCfg.setTcpIpConfig(tcpCfg);
    netCfg.setJoin(joinCfg);
    // ssl
    netCfg.setSSLConfig(new SSLConfig().setEnabled(false));

    // get map
    map = Hazelcast.newHazelcastInstance(cfg).getMap(HC_MAP);
    log.info("Hazelcast Shiro session persistence initialized.");
}
 
Example #26
Source File: HazelcastTestFactory.java    From ratelimitj with Apache License 2.0 5 votes vote down vote up
static HazelcastInstance newStandaloneHazelcastInstance() {
    Config config = new Config();
    config.setProperty("hazelcast.logging.type", "slf4j");
    config.setProperty("hazelcast.shutdownhook.enabled", "false");
    NetworkConfig network = config.getNetworkConfig();
    network.getJoin().getTcpIpConfig().setEnabled(false);
    network.getJoin().getMulticastConfig().setEnabled(false);
    return Hazelcast.newHazelcastInstance(config);
}
 
Example #27
Source File: ServiceCacheConfiguration.java    From iotplatform with Apache License 2.0 5 votes vote down vote up
private void addZkConfig(Config config) {
    config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
    config.setProperty(GroupProperty.DISCOVERY_SPI_ENABLED.getName(), Boolean.TRUE.toString());
    DiscoveryStrategyConfig discoveryStrategyConfig = new DiscoveryStrategyConfig(new ZookeeperDiscoveryStrategyFactory());
    discoveryStrategyConfig.addProperty(ZookeeperDiscoveryProperties.ZOOKEEPER_URL.key(), zkUrl);
    discoveryStrategyConfig.addProperty(ZookeeperDiscoveryProperties.ZOOKEEPER_PATH.key(), zkDir);
    discoveryStrategyConfig.addProperty(ZookeeperDiscoveryProperties.GROUP.key(), HAZELCAST_CLUSTER_NAME);
    config.getNetworkConfig().getJoin().getDiscoveryConfig().addDiscoveryStrategyConfig(discoveryStrategyConfig);
}
 
Example #28
Source File: ServiceCacheConfiguration.java    From iotplatform with Apache License 2.0 5 votes vote down vote up
@Bean
public HazelcastInstance hazelcastInstance() {
    Config config = new Config();

    if (zkEnabled) {
        addZkConfig(config);
    }

    config.addMapConfig(createDeviceCredentialsCacheConfig());

    return Hazelcast.newHazelcastInstance(config);
}
 
Example #29
Source File: GenericTypesTest.java    From hazelcast-simulator with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void beforeClass() {
    Config config = new Config();
    config.setProperty("hazelcast.partition.count", "" + PARTITION_COUNT);

    hz = Hazelcast.newHazelcastInstance(config);
}
 
Example #30
Source File: DistributedLockFactory.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
public static synchronized HazelcastInstance getHazelcastInstance(String instanceName) {
	logger.debug("Getting Hazelcast instance with name [" + instanceName + "]");
	HazelcastInstance hz = Hazelcast.getHazelcastInstanceByName(instanceName);
	if (hz == null) {
		logger.debug("No Hazelcast instance with name [" + instanceName + "] found");
		logger.debug("Creating Hazelcast instance with name [" + instanceName + "]");
		Config config = getDefaultConfig();
		config.setInstanceName(instanceName);
		hz = Hazelcast.newHazelcastInstance(config);
	}
	return hz;
}