Java Code Examples for com.hazelcast.core.Hazelcast#getHazelcastInstanceByName()

The following examples show how to use com.hazelcast.core.Hazelcast#getHazelcastInstanceByName() . 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 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 2
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 3
Source File: CacheConfiguration.java    From cubeai with Apache License 2.0 5 votes vote down vote up
@Bean
public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) {
    log.debug("Configuring Hazelcast");
    HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("umm");
    if (hazelCastInstance != null) {
        log.debug("Hazelcast already initialized");
        return hazelCastInstance;
    }
    Config config = new Config();
    config.setInstanceName("umm");
    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());

    // Full reference is available at: http://docs.hazelcast.org/docs/management-center/3.9/manual/html/Deploying_and_Starting.html
    config.setManagementCenterConfig(initializeDefaultManagementCenterConfig(jHipsterProperties));
    config.getMapConfigs().put("com.wyy.domain.*", initializeDomainMapConfig(jHipsterProperties));
    return Hazelcast.newHazelcastInstance(config);
}
 
Example 4
Source File: AbstractTopologyIT.java    From spring-data-hazelcast with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    super.setUp();

    HazelcastInstance hazelcastServer = null;

    // Look for any instance apart from Spring's one
    hazelcastServer = Hazelcast.getHazelcastInstanceByName(TestConstants.SERVER_INSTANCE_NAME);

    assertThat("Server found", hazelcastServer, notNullValue());
    this.server_personMap = hazelcastServer.getMap(TestConstants.PERSON_MAP_NAME);
}
 
Example 5
Source File: HazelcastSessionDao.java    From spring-boot-shiro-orientdb with Apache License 2.0 5 votes vote down vote up
/**
 * Destroys currently allocated instance.
 */
public void destroy() {
    log.info("Shutting down Hazelcast instance [{}]..", hcInstanceName);
    final HazelcastInstance instance = Hazelcast.getHazelcastInstanceByName(
            hcInstanceName);
    if (instance != null) {
        instance.shutdown();
    }
}
 
Example 6
Source File: HazelcastWorkQueue.java    From telekom-workflow-engine with MIT License 5 votes vote down vote up
@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 7
Source File: HazelcastSessionDao.java    From dpCms with Apache License 2.0 5 votes vote down vote up
/**
 * Destroys currently allocated instance.
 */
public void destroy() {
    log.info("Shutting down Hazelcast instance [{}]..", hcInstanceName);
    final HazelcastInstance instance = Hazelcast.getHazelcastInstanceByName(
            hcInstanceName);
    if (instance != null) {
        instance.shutdown();
    }
}
 
Example 8
Source File: HazelCastConfigration.java    From sctalk with Apache License 2.0 5 votes vote down vote up
@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 9
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;
}
 
Example 10
Source File: HazelCastConfigration.java    From jvue-admin with MIT License 5 votes vote down vote up
@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 11
Source File: CacheConfiguration.java    From cubeai with Apache License 2.0 5 votes vote down vote up
@Bean
public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) {
    log.debug("Configuring Hazelcast");
    HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("uaa");
    if (hazelCastInstance != null) {
        log.debug("Hazelcast already initialized");
        return hazelCastInstance;
    }
    Config config = new Config();
    config.setInstanceName("uaa");
    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());

    // Full reference is available at: http://docs.hazelcast.org/docs/management-center/3.9/manual/html/Deploying_and_Starting.html
    config.setManagementCenterConfig(initializeDefaultManagementCenterConfig(jHipsterProperties));
    config.getMapConfigs().put("com.wyy.domain.*", initializeDomainMapConfig(jHipsterProperties));
    return Hazelcast.newHazelcastInstance(config);
}
 
Example 12
Source File: CacheConfiguration.java    From cubeai with Apache License 2.0 5 votes vote down vote up
@Bean
public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) {
    log.debug("Configuring Hazelcast");
    HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("umo");
    if (hazelCastInstance != null) {
        log.debug("Hazelcast already initialized");
        return hazelCastInstance;
    }
    Config config = new Config();
    config.setInstanceName("umo");
    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());

    // Full reference is available at: http://docs.hazelcast.org/docs/management-center/3.9/manual/html/Deploying_and_Starting.html
    config.setManagementCenterConfig(initializeDefaultManagementCenterConfig(jHipsterProperties));
    return Hazelcast.newHazelcastInstance(config);
}
 
Example 13
Source File: CacheConfiguration.java    From cubeai with Apache License 2.0 5 votes vote down vote up
@Bean
public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) {
    log.debug("Configuring Hazelcast");
    HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("umu");
    if (hazelCastInstance != null) {
        log.debug("Hazelcast already initialized");
        return hazelCastInstance;
    }
    Config config = new Config();
    config.setInstanceName("umu");
    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());

    // Full reference is available at: http://docs.hazelcast.org/docs/management-center/3.9/manual/html/Deploying_and_Starting.html
    config.setManagementCenterConfig(initializeDefaultManagementCenterConfig(jHipsterProperties));
    return Hazelcast.newHazelcastInstance(config);
}
 
Example 14
Source File: CacheConfiguration.java    From cubeai with Apache License 2.0 5 votes vote down vote up
@Bean
public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) {
    log.debug("Configuring Hazelcast");
    HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("gateway");
    if (hazelCastInstance != null) {
        log.debug("Hazelcast already initialized");
        return hazelCastInstance;
    }
    Config config = new Config();
    config.setInstanceName("gateway");
    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());

    // Full reference is available at: http://docs.hazelcast.org/docs/management-center/3.9/manual/html/Deploying_and_Starting.html
    config.setManagementCenterConfig(initializeDefaultManagementCenterConfig(jHipsterProperties));
    return Hazelcast.newHazelcastInstance(config);
}
 
Example 15
Source File: CacheConfiguration.java    From cubeai with Apache License 2.0 5 votes vote down vote up
@Bean
public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) {
    log.debug("Configuring Hazelcast");
    HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("ability");
    if (hazelCastInstance != null) {
        log.debug("Hazelcast already initialized");
        return hazelCastInstance;
    }
    Config config = new Config();
    config.setInstanceName("ability");
    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());

    // Full reference is available at: http://docs.hazelcast.org/docs/management-center/3.9/manual/html/Deploying_and_Starting.html
    config.setManagementCenterConfig(initializeDefaultManagementCenterConfig(jHipsterProperties));
    return Hazelcast.newHazelcastInstance(config);
}
 
Example 16
Source File: CacheConfiguration.java    From cubeai with Apache License 2.0 5 votes vote down vote up
@Bean
public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) {
    log.debug("Configuring Hazelcast");
    HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("ucomposer");
    if (hazelCastInstance != null) {
        log.debug("Hazelcast already initialized");
        return hazelCastInstance;
    }
    Config config = new Config();
    config.setInstanceName("ucomposer");
    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());

    // Full reference is available at: http://docs.hazelcast.org/docs/management-center/3.9/manual/html/Deploying_and_Starting.html
    config.setManagementCenterConfig(initializeDefaultManagementCenterConfig(jHipsterProperties));
    return Hazelcast.newHazelcastInstance(config);
}
 
Example 17
Source File: CacheConfiguration.java    From cubeai with Apache License 2.0 5 votes vote down vote up
@Bean
public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) {
    log.debug("Configuring Hazelcast");
    HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("umd");
    if (hazelCastInstance != null) {
        log.debug("Hazelcast already initialized");
        return hazelCastInstance;
    }
    Config config = new Config();
    config.setInstanceName("umd");
    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());

    // Full reference is available at: http://docs.hazelcast.org/docs/management-center/3.9/manual/html/Deploying_and_Starting.html
    config.setManagementCenterConfig(initializeDefaultManagementCenterConfig(jHipsterProperties));
    return Hazelcast.newHazelcastInstance(config);
}