Java Code Examples for com.hazelcast.config.Config#setInstanceName()
The following examples show how to use
com.hazelcast.config.Config#setInstanceName() .
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: HazelcastMemberFactory.java From incubator-batchee with Apache License 2.0 | 6 votes |
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 2
Source File: HazelcastMemoryService.java From sakai with Educational Community License v2.0 | 6 votes |
/** * 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 3
Source File: Cluster.java From OSPREY3 with GNU General Public License v2.0 | 6 votes |
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 4
Source File: HazelcastMemoryService.java From sakai with Educational Community License v2.0 | 6 votes |
/** * 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 5
Source File: CacheConfiguration.java From flair-engine with Apache License 2.0 | 6 votes |
@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 6
Source File: HazelcastManaged.java From cqrs-eventsourcing-kafka with Apache License 2.0 | 5 votes |
public static HazelcastInstance getInstance() { if (hazelcastInstance == null) { Config config = new XmlConfigBuilder().build(); config.setInstanceName(Thread.currentThread().getName()); hazelcastInstance = Hazelcast.getOrCreateHazelcastInstance(config); } return hazelcastInstance; }
Example 7
Source File: HazelcastSessionDao.java From spring-boot-shiro-orientdb with Apache License 2.0 | 5 votes |
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 8
Source File: HazelcastWorkQueue.java From telekom-workflow-engine with MIT License | 5 votes |
@Override public void start(){ String hcInstanceName = config.getClusterHazelcastName(); hcInstance = Hazelcast.getHazelcastInstanceByName( hcInstanceName ); if (hcInstance == null) { log.info( "Didn't find an existing Hazelcast instance by name " + hcInstanceName + ". Starting our own instance!" ); Config hcConfig = new Config(); // Unfortunately, using the following line does not yet apply during the Hazelcast // initialization such that Hazelcast initalization log output ends up at stout. // This propblem is resolved by setting a system property as shown below. // hcConfig.setProperty( "hazelcast.logging.type", "slf4j" ); System.setProperty( "hazelcast.logging.class", "com.hazelcast.logging.Slf4jFactory" ); hcConfig.setProperty( "hazelcast.jmx", "true" ); hcConfig.setProperty( "hazelcast.shutdownhook.enabled", "false" ); hcConfig.setInstanceName( hcInstanceName ); hcConfig.getGroupConfig().setName( config.getClusterName() ); hcConfig.getNetworkConfig().getJoin().getMulticastConfig().setEnabled( true ); hcConfig.getNetworkConfig().getJoin().getMulticastConfig().setMulticastGroup( config.getClusterMulticastGroup() ); hcConfig.getNetworkConfig().getJoin().getMulticastConfig().setMulticastPort( config.getClusterMulticastPort() ); hcConfig.getNetworkConfig().getJoin().getMulticastConfig().setMulticastTimeToLive( config.getClusterMulticastTtl() ); hcInstance = Hazelcast.newHazelcastInstance( hcConfig ); isLocalHcInstance.set( true ); } else { log.info( "Found an existing Hazelcast instance by name " + hcInstanceName + ". Using that." ); } isStarted.set( true ); log.info( "Started queue" ); }
Example 9
Source File: HazelcastSessionDao.java From dpCms with Apache License 2.0 | 5 votes |
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 10
Source File: HazelcastLocal.java From j2cache with Apache License 2.0 | 5 votes |
public synchronized HazelcastInstance getHazelcast() { if (hazelcast == null) { Config config = new ClasspathXmlConfig("org/j2server/j2cache/cache/hazelcast/hazelcast-cache-config.xml"); config.setInstanceName("j2cache"); hazelcast = Hazelcast.newHazelcastInstance(config); } return hazelcast; }
Example 11
Source File: HazelCastConfigration.java From sctalk with Apache License 2.0 | 5 votes |
@Bean public HazelcastInstance hazelcastInstance(MessageServerConfig serverConfig) { log.debug("Configuring Hazelcast"); HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("message-server"); if (hazelCastInstance != null) { log.debug("Hazelcast already initialized"); return hazelCastInstance; } Config config = new Config(); config.setInstanceName("message-server"); config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false); if (this.registration == null) { log.warn("No discovery service is set up, Hazelcast cannot create a cluster."); } else { // The serviceId is by default the application's name, see Spring Boot's // eureka.instance.appname property String serviceId = registration.getServiceId(); log.debug("Configuring Hazelcast clustering for instanceId: {}", serviceId); config.getNetworkConfig().setPort(5701); config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(true); for (ServiceInstance instance : discoveryClient.getInstances(serviceId)) { String clusterMember = instance.getHost() + ":5701"; log.debug("Adding Hazelcast (prod) cluster member " + clusterMember); config.getNetworkConfig().getJoin().getTcpIpConfig().addMember(clusterMember); } } config.getMapConfigs().put("default", initializeDefaultMapConfig()); config.getMapConfigs().put("com.blt.talk.domain.*", initializeDomainMapConfig(serverConfig)); return Hazelcast.newHazelcastInstance(config); }
Example 12
Source File: DistributedLockFactory.java From Knowage-Server with GNU Affero General Public License v3.0 | 5 votes |
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; }
Example 13
Source File: HazelcastHttpSessionManager.java From piranha with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Constructor. * * @param name the name used for the hazelcast session map. */ public HazelcastHttpSessionManager(String name) { super(); Config config = new Config(); config.setInstanceName(name); hazelcast = Hazelcast.newHazelcastInstance(); sessions = hazelcast.getMap(name); }
Example 14
Source File: CachingConfig.java From Spring-5.0-Cookbook with MIT License | 5 votes |
@Bean public Config hazelCastConfig() { Config config = new Config(); config.setInstanceName("hazelcast-packt-cache"); config.setProperty("hazelcast.jmx", "true"); MapConfig deptCache = new MapConfig(); deptCache.setTimeToLiveSeconds(20); deptCache.setEvictionPolicy(EvictionPolicy.LFU); config.getMapConfigs().put("hazeldept",deptCache); return config; }
Example 15
Source File: HazelCastConfigration.java From jvue-admin with MIT License | 5 votes |
@Bean public HazelcastInstance hazelcastInstance() { log.debug("Configuring Hazelcast"); HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("jvue-server"); if (hazelCastInstance != null) { log.debug("Hazelcast already initialized"); return hazelCastInstance; } Config config = new Config(); config.setInstanceName("jvue-server"); config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false); if (this.registration == null) { log.warn("No discovery service is set up, Hazelcast cannot create a cluster."); } else { String serviceId = registration.getServiceId(); log.debug("Configuring Hazelcast clustering for instanceId: {}", serviceId); config.getNetworkConfig().setPort(5701); config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(true); for (ServiceInstance instance : discoveryClient.getInstances(serviceId)) { String clusterMember = instance.getHost() + ":5701"; log.debug("Adding Hazelcast (prod) cluster member " + clusterMember); config.getNetworkConfig().getJoin().getTcpIpConfig().addMember(clusterMember); } } config.getMapConfigs().put("default", initializeDefaultMapConfig()); config.getMapConfigs().put("net.ccfish.jvue.domain.*", initializeDefaultMapConfig()); return Hazelcast.newHazelcastInstance(config); }
Example 16
Source File: HazelcastTest.java From java-specialagent with Apache License 2.0 | 4 votes |
@Test public void testGetOrCreateHazelcastInstance(final MockTracer tracer) { final Config config = new Config(); config.setInstanceName("name"); test(Hazelcast.getOrCreateHazelcastInstance(config), tracer); }
Example 17
Source File: HazelcastTest.java From java-specialagent with Apache License 2.0 | 4 votes |
@BeforeClass public static void beforeClass() { final Config config = new Config(); config.setInstanceName("name"); hazelcast = Hazelcast.newHazelcastInstance(config); }
Example 18
Source File: HazelcastManager.java From lumongo with Apache License 2.0 | 4 votes |
public void init(Set<HazelcastNode> nodes, String hazelcastName) throws Exception { // force Hazelcast to use log4j int hazelcastPort = localNodeConfig.getHazelcastPort(); Config cfg = new Config(); cfg.setProperty(GroupProperty.LOGGING_TYPE.getName(), "log4j"); // disable Hazelcast shutdown hook to allow LuMongo to handle cfg.setProperty(GroupProperty.SHUTDOWNHOOK_ENABLED.getName(), "false"); cfg.setProperty(GroupProperty.REST_ENABLED.getName(), "false"); cfg.getGroupConfig().setName(hazelcastName); cfg.getGroupConfig().setPassword(hazelcastName); cfg.getNetworkConfig().setPortAutoIncrement(false); cfg.getNetworkConfig().setPort(hazelcastPort); cfg.setInstanceName("" + hazelcastPort); cfg.getManagementCenterConfig().setEnabled(false); NetworkConfig network = cfg.getNetworkConfig(); JoinConfig joinConfig = network.getJoin(); joinConfig.getMulticastConfig().setEnabled(false); joinConfig.getTcpIpConfig().setEnabled(true); for (HazelcastNode node : nodes) { joinConfig.getTcpIpConfig().addMember(node.getAddress() + ":" + node.getHazelcastPort()); } hazelcastInstance = Hazelcast.newHazelcastInstance(cfg); self = hazelcastInstance.getCluster().getLocalMember(); hazelcastInstance.getCluster().addMembershipListener(this); hazelcastInstance.getLifecycleService().addLifecycleListener(this); log.info("Initialized hazelcast"); Set<Member> members = hazelcastInstance.getCluster().getMembers(); Member firstMember = members.iterator().next(); if (firstMember.equals(self)) { log.info("Member is owner of cluster"); indexManager.loadIndexes(); } log.info("Current cluster members: <" + members + ">"); indexManager.openConnections(members); initLock.writeLock().unlock(); }