Java 类com.hazelcast.config.Config 实例源码

项目:greycat    文件:HazelcastScheduler.java   
public static void main(String[] args) {
    Config cfg = new Config();
    HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);
    Map<Integer, String> mapCustomers = instance.getMap("customers");
    mapCustomers.put(1, "Joe");
    mapCustomers.put(2, "Ali");
    mapCustomers.put(3, "Avi");

    System.out.println("Customer with key 1: "+ mapCustomers.get(1));
    System.out.println("Map Size:" + mapCustomers.size());

    Queue<String> queueCustomers = instance.getQueue("customers");
    queueCustomers.offer("Tom");
    queueCustomers.offer("Mary");
    queueCustomers.offer("Jane");
    System.out.println("First customer: " + queueCustomers.poll());
    System.out.println("Second customer: "+ queueCustomers.peek());
    System.out.println("Queue size: " + queueCustomers.size());
}
项目:xm-commons    文件:XmConfigHazelcastConfiguration.java   
@Bean(TENANT_CONFIGURATION_HAZELCAST)
public HazelcastInstance tenantConfigurationHazelcast() throws IOException {
    log.info("{}", appProps.getHazelcast());

    Properties props = new Properties();
    props.putAll(appProps.getHazelcast());
    props.put(HAZELCAST_LOCAL_LOCAL_ADDRESS, InetUtils.getFirstNonLoopbackHostInfo().getIpAddress());

    String hazelcastConfigUrl = appProps.getHazelcast().get(HAZELCAST_CONFIG_URL_PROPERTY);
    InputStream in = context.getResource(hazelcastConfigUrl).getInputStream();

    Config config = new XmlConfigBuilder(in).setProperties(props).build();
    config.getNetworkConfig().setInterfaces(buildInterfaces(appProps.getHazelcast().get(INTERFACES)));
    HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
    return hazelcastInstance;
}
项目:xm-ms-balance    文件:CacheConfiguration.java   
@Bean
public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) {
    log.debug("Configuring Hazelcast");
    HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("balance");
    if (hazelCastInstance != null) {
        log.debug("Hazelcast already initialized");
        return hazelCastInstance;
    }
    Config config = new Config();
    config.setInstanceName("balance");
    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.icthh.xm.ms.balance.domain.*", initializeDomainMapConfig(jHipsterProperties));
    return Hazelcast.newHazelcastInstance(config);
}
项目:cas-5.1.0    文件:HazelcastSessionConfiguration.java   
/**
 * Hazelcast instance that is used by the spring session
 * repository to broadcast session events. The name
 * of this bean must be left untouched.
 *
 * @return the hazelcast instance
 */
@Bean
public HazelcastInstance hazelcastInstance() {
    final Resource hzConfigResource = casProperties.getWebflow().getSession().getHzLocation();
    try {
        final URL configUrl = hzConfigResource.getURL();
        final Config config = new XmlConfigBuilder(hzConfigResource.getInputStream()).build();
        config.setConfigurationUrl(configUrl);
        config.setInstanceName(this.getClass().getSimpleName())
                .setProperty("hazelcast.logging.type", "slf4j")
                .setProperty("hazelcast.max.no.heartbeat.seconds", "300");
        return Hazelcast.newHazelcastInstance(config);
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
项目:xm-ms-dashboard    文件:CacheConfiguration.java   
@Bean
@Primary
public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) {
    log.debug("Configuring Hazelcast");
    HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("dashboard");
    if (hazelCastInstance != null) {
        log.debug("Hazelcast already initialized");
        return hazelCastInstance;
    }
    Config config = new Config();
    config.setInstanceName("dashboard");
    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.icthh.xm.ms.dashboard.domain.*", initializeDomainMapConfig(jHipsterProperties));
    return Hazelcast.newHazelcastInstance(config);
}
项目:xm-gate    文件:CacheConfiguration.java   
@Bean
@Primary
public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) {
    log.debug("Configuring Hazelcast");
    HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("gate");
    if (hazelCastInstance != null) {
        log.debug("Hazelcast already initialized");
        return hazelCastInstance;
    }
    Config config = new Config();
    config.setInstanceName("gate");
    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.icthh.xm.gate.domain.*", initializeDomainMapConfig(jHipsterProperties));
    return Hazelcast.newHazelcastInstance(config);
}
项目:xm-ms-entity    文件:CacheConfiguration.java   
@Bean
@Primary
public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) {
    log.debug("Configuring Hazelcast");
    HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("entity");
    if (hazelCastInstance != null) {
        log.debug("Hazelcast already initialized");
        return hazelCastInstance;
    }
    Config config = new Config();
    config.setInstanceName("entity");
    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.icthh.xm.ms.entity.domain.*", initializeDomainMapConfig(jHipsterProperties));
    return Hazelcast.newHazelcastInstance(config);
}
项目:Code4Health-Platform    文件:CacheConfiguration.java   
@Bean
public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) {
    log.debug("Configuring Hazelcast");
    Config config = new Config();
    config.setInstanceName("operoncloudplatform");
    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("cloud.operon.platform.domain.*", initializeDomainMapConfig(jHipsterProperties));
    return Hazelcast.newHazelcastInstance(config);
}
项目:cyp2sql    文件:KeyValueTest.java   
/**
 * Main method for executing the schema conversion to Hazelcast.
 * The method just needs to be called statically as it operates on files created during the initial
 * schema conversion process.
 */
public static void executeSchemaChange() {
    Config cfg = new Config();
    HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);

    mapNodes = instance.getMap("nodes");
    mapEdges = instance.getMap("edges");
    mapLabels = instance.getMap("labels");
    mapOut = instance.getMap("out");
    mapIn = instance.getMap("in");

    nodesMap();
    edgesMap();

    exampleQueries();
}
项目:simple-openid-provider    文件:SessionConfiguration.java   
@PostConstruct
public void init() {
    Config config = this.hazelcastInstance.getConfig();
    String mapName = this.sessionProperties.getMapName();
    MapConfig mapConfig = config.getMapConfigOrNull(mapName);

    if (mapConfig == null) {
        // @formatter:off
        MapAttributeConfig principalNameAttributeConfig = new MapAttributeConfig()
                .setName(HazelcastSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)
                .setExtractor(PrincipalNameExtractor.class.getName());
        // @formatter:on

        MapIndexConfig principalNameIndexConfig = new MapIndexConfig(
                HazelcastSessionRepository.PRINCIPAL_NAME_ATTRIBUTE, false);

        // @formatter:off
        mapConfig = new MapConfig(mapName)
                .addMapAttributeConfig(principalNameAttributeConfig)
                .addMapIndexConfig(principalNameIndexConfig);
        // @formatter:on

        config.addMapConfig(mapConfig);
    }
}
项目:hazelcast-zookeeper    文件:HazelcastIntegrationTest.java   
@Test
public void testIntegration() {
    String zookeeperURL = zkTestServer.getConnectString();
    Config config = new Config();
    config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
    config.setProperty("hazelcast.discovery.enabled", "true");

    DiscoveryStrategyConfig discoveryStrategyConfig = new DiscoveryStrategyConfig(new ZookeeperDiscoveryStrategyFactory());
    discoveryStrategyConfig.addProperty(ZookeeperDiscoveryProperties.ZOOKEEPER_URL.key(), zookeeperURL);
    config.getNetworkConfig().getJoin().getDiscoveryConfig().addDiscoveryStrategyConfig(discoveryStrategyConfig);

    HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
    HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config);

    int instance1Size = instance1.getCluster().getMembers().size();
    assertEquals(2, instance1Size);
    int instance2Size = instance2.getCluster().getMembers().size();
    assertEquals(2, instance2Size);
}
项目:concursus    文件:HazelcastCommandExecutorConfiguration.java   
/**
 * Add configuration to the supplied {@link Config} to support the use of a {@link HazelcastCommandExecutor}.
 * @param config The {@link Config} to configure.
 * @return The updated {@link Config}.
 */
public Config addCommandExecutorConfiguration(Config config) {
    SerializerConfig serializerConfig = new SerializerConfig()
            .setImplementation(RemoteCommandSerialiser.using(
                    objectMapper,
                    CommandTypeMatcher.matchingAgainst(typeInfoMap)))
            .setTypeClass(RemoteCommand.class);

    ManagedContext managedContext = CommandProcessingManagedContext
            .processingCommandsWith(dispatchingCommandProcessor);

    config.getSerializationConfig().addSerializerConfig(serializerConfig);

    config.setManagedContext(config.getManagedContext() == null
            ? managedContext
            : CompositeManagedContext.of(managedContext, config.getManagedContext()));

    config.addExecutorConfig(new ExecutorConfig(executorName, threadsPerNode));
    return config;
}
项目:hazelcast-demo    文件:HazelcastConfigVariable.java   
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();
    }
}
项目:hazelcast-demo    文件:HazelcastConfigRuntimeModify.java   
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);
}
项目:hazelcast_eureka    文件:HazelcastMemberConfiguration.java   
@Bean
public Config hazelcastConfig () {
    val config = new Config();
    config.setProperty("hazelcast.discovery.enabled", "true");

    val networkingConfig = config.getNetworkConfig();
    networkingConfig.setPort(hazelcastPort);
    networkingConfig.setPortAutoIncrement(false);

    val joinConfig = networkingConfig.getJoin();

    joinConfig.getMulticastConfig().setEnabled(false);
    joinConfig.getTcpIpConfig().setEnabled(false);
    joinConfig.getAwsConfig().setEnabled(false);
    joinConfig.getDiscoveryConfig()
            .addDiscoveryStrategyConfig(new DiscoveryStrategyConfig(discoveryStrategyFactory()));

    return config;
}
项目:hazelcast-hibernate    文件:CustomPropertiesTest.java   
@Test
public void testNamedInstance() {
    TestHazelcastFactory factory = new TestHazelcastFactory();
    Config config = new Config();
    config.setInstanceName("hibernate");
    HazelcastInstance hz = factory.newHazelcastInstance(config);
    Properties props = new Properties();
    props.setProperty(Environment.CACHE_REGION_FACTORY, HazelcastCacheRegionFactory.class.getName());
    props.put(CacheEnvironment.HAZELCAST_INSTANCE_NAME, "hibernate");
    props.put(CacheEnvironment.SHUTDOWN_ON_STOP, "false");
    props.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");

    Configuration configuration = new Configuration();
    configuration.addProperties(props);

    SessionFactory sf = configuration.buildSessionFactory();
    assertTrue(hz.equals(HazelcastAccessor.getHazelcastInstance(sf)));
    sf.close();
    assertTrue(hz.getLifecycleService().isRunning());
    factory.shutdownAll();
}
项目:javacode-demo    文件:GettingStarted.java   
public static void main(String[] args) {
    Config cfg = new Config();
    HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);
    Map<Integer, String> mapCustomers = instance.getMap("customers");
    mapCustomers.put(1, "Joe");
    mapCustomers.put(2, "Ali");
    mapCustomers.put(3, "Avi");

    System.out.println("Customer with key 1: "+ mapCustomers.get(1));
    System.out.println("Map Size:" + mapCustomers.size());

    Queue<String> queueCustomers = instance.getQueue("customers");
    queueCustomers.offer("Tom");
    queueCustomers.offer("Mary");
    queueCustomers.offer("Jane");
    System.out.println("First customer: " + queueCustomers.poll());
    System.out.println("Second customer: "+ queueCustomers.peek());
    System.out.println("Queue size: " + queueCustomers.size());
}
项目:hazelcast-eureka    文件:HazelcastClientTestCase.java   
@Test
public void testExternalRegistration(){
    EurekaHttpResponse<Applications> response = generateMockResponse(Collections.<InstanceInfo>emptyList());
    when(requestHandler.getApplications()).thenReturn(response);

    Config config = new XmlConfigBuilder().build();
    DiscoveryConfig discoveryConfig = config.getNetworkConfig().getJoin().getDiscoveryConfig();
    DiscoveryStrategyConfig strategyConfig = discoveryConfig.getDiscoveryStrategyConfigs().iterator().next();
    strategyConfig.addProperty("self-registration", "false");

    HazelcastInstance hz1 = factory.newHazelcastInstance(config);
    HazelcastInstance hz2 = factory.newHazelcastInstance(config);

    assertClusterSizeEventually(2, hz1);
    assertClusterSizeEventually(2, hz2);

    verify(requestHandler, after(5000).never()).register(any(InstanceInfo.class));

}
项目:hazelcast-jclouds    文件:JCloudsDiscoveryFactoryTest.java   
@Test
public void discoveryStrategyFactoryTest() {
    JCloudsDiscoveryStrategyFactory jCloudsDiscoveryStrategyFactory = new JCloudsDiscoveryStrategyFactory();
    String xmlFileName = "test-jclouds-config.xml";
    InputStream xmlResource = JCloudsDiscoveryFactoryTest.class.getClassLoader().getResourceAsStream(xmlFileName);
    Config config = new XmlConfigBuilder(xmlResource).build();

    JoinConfig joinConfig = config.getNetworkConfig().getJoin();
    DiscoveryConfig discoveryConfig = joinConfig.getDiscoveryConfig();
    DiscoveryStrategyConfig providerConfig = discoveryConfig.getDiscoveryStrategyConfigs().iterator().next();

    assertEquals(jCloudsDiscoveryStrategyFactory.getDiscoveryStrategyType(), JCloudsDiscoveryStrategy.class);
    assertEquals(JCloudsDiscoveryStrategy.class.getName(), providerConfig.getClassName());
    assertEquals(jCloudsDiscoveryStrategyFactory.getConfigurationProperties().size(), providerConfig.getProperties().size());
    assertTrue(jCloudsDiscoveryStrategyFactory.
            newDiscoveryStrategy(null, null, new HashMap<String, Comparable>()) instanceof DiscoveryStrategy);
}
项目:lannister    文件:Hazelcast.java   
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;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:HazelcastAutoConfigurationTests.java   
@Test
public void configInstanceWithName() {
    Config config = new Config("my-test-instance");
    HazelcastInstance existingHazelcastInstance = Hazelcast
            .newHazelcastInstance(config);
    try {
        load(HazelcastConfigWithName.class,
                "spring.hazelcast.config=this-is-ignored.xml");
        HazelcastInstance hazelcastInstance = this.context
                .getBean(HazelcastInstance.class);
        assertThat(hazelcastInstance.getConfig().getInstanceName())
                .isEqualTo("my-test-instance");
        // Should reuse any existing instance by default.
        assertThat(hazelcastInstance).isEqualTo(existingHazelcastInstance);
    }
    finally {
        existingHazelcastInstance.shutdown();
    }
}
项目:reactive-data    文件:HazelcastInstanceProxy.java   
/**
 * 
 * @throws FileNotFoundException
 * @throws ConfigurationException 
 */
private HazelcastInstanceProxy(Config hzConfig, String entityScanPath) {
    this.hzConfig = hzConfig;
    setProperty("hazelcast.event.thread.count", "6");
   setProperty("hazelcast.operation.thread.count", "4");
   setProperty("hazelcast.io.thread.count", "4"); //4+4+1
   setProperty("hazelcast.shutdownhook.enabled", "false");

   try {
     addMapConfigs(EntityFinder.findMapEntityClasses(entityScanPath));
   } catch (Exception e) {
     throw new BeanCreationException("Unable to load entity classes", e);
   }


}
项目:subzero    文件:TestCustomerSerializers.java   
@Test
public void testGlobalCustomSerializationConfiguredProgrammaticallyForClientConfig() {
    Config memberConfig = new Config();
    SubZero.useAsGlobalSerializer(memberConfig);
    hazelcastFactory.newHazelcastInstance(memberConfig);

    String mapName = randomMapName();
    ClientConfig config = new ClientConfig();

    SubZero.useAsGlobalSerializer(config, MyGlobalUserSerlizationConfig.class);

    HazelcastInstance member = hazelcastFactory.newHazelcastClient(config);
    IMap<Integer, AnotherNonSerializableObject> myMap = member.getMap(mapName);
    myMap.put(0, new AnotherNonSerializableObject());
    AnotherNonSerializableObject fromCache = myMap.get(0);

    assertEquals("deserialized", fromCache.name);
}
项目:subzero    文件:TestCustomerSerializers.java   
@Test
public void testGlobalCustomDelegateSerializationConfiguredProgrammaticallyForClientConfig() {
    Config memberConfig = new Config();
    SubZero.useAsGlobalSerializer(memberConfig);
    hazelcastFactory.newHazelcastInstance(memberConfig);

    String mapName = randomMapName();
    ClientConfig config = new ClientConfig();

    SubZero.useAsGlobalSerializer(config, MyGlobalDelegateSerlizationConfig.class);

    HazelcastInstance member = hazelcastFactory.newHazelcastClient(config);
    IMap<Integer, AnotherNonSerializableObject> myMap = member.getMap(mapName);
    myMap.put(0, new AnotherNonSerializableObject());
    AnotherNonSerializableObject fromCache = myMap.get(0);

    assertEquals("deserialized", fromCache.name);
}
项目:subzero    文件:TestCustomerSerializers.java   
@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);
}
项目:Camel    文件:HazelcastAggregationRepository.java   
@Override
protected void doStart() throws Exception {
    if (maximumRedeliveries < 0) {
        throw new IllegalArgumentException("Maximum redelivery retries must be zero or a positive integer.");
    }
    if (recoveryInterval < 0) {
        throw new IllegalArgumentException("Recovery interval must be zero or a positive integer.");
    }
    ObjectHelper.notEmpty(mapName, "repositoryName");
    if (useLocalHzInstance)  {
        Config cfg = new XmlConfigBuilder().build();
        cfg.setProperty("hazelcast.version.check.enabled", "false");
        hzInstance = Hazelcast.newHazelcastInstance(cfg);
    } else {
        ObjectHelper.notNull(hzInstance, "hzInstanse");
    }
    cache = hzInstance.getMap(mapName);
    if (useRecovery) {
        persistedCache = hzInstance.getMap(persistenceMapName);
    }
}
项目:hazelcast-hibernate    文件:HazelcastQueryResultsRegionTest.java   
@Before
public void setUp() throws Exception {
    mapConfig = mock(MapConfig.class);
    when(mapConfig.getMaxSizeConfig()).thenReturn(new MaxSizeConfig(maxSize, MaxSizeConfig.MaxSizePolicy.PER_NODE));
    when(mapConfig.getTimeToLiveSeconds()).thenReturn(timeout);

    config = mock(Config.class);
    when(config.findMapConfig(eq(REGION_NAME))).thenReturn(mapConfig);

    Cluster cluster = mock(Cluster.class);
    when(cluster.getClusterTime()).thenAnswer(new Answer<Long>() {
        @Override
        public Long answer(InvocationOnMock invocation) throws Throwable {
            return System.currentTimeMillis();
        }
    });

    instance = mock(HazelcastInstance.class);
    when(instance.getConfig()).thenReturn(config);
    when(instance.getCluster()).thenReturn(cluster);

    region = new HazelcastQueryResultsRegion(instance, REGION_NAME, new Properties());
}
项目:hazelcast-jetty-sessionmanager    文件:JettySessionUtils.java   
/**
 * 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);
}
项目:hazelcast-hibernate    文件:CustomPropertiesTest.java   
@Test
public void testNamedInstance() {
    TestHazelcastFactory factory = new TestHazelcastFactory();
    Config config = new Config();
    config.setInstanceName("hibernate");
    HazelcastInstance hz = factory.newHazelcastInstance(config);
    Properties props = new Properties();
    props.setProperty(Environment.CACHE_REGION_FACTORY, HazelcastCacheRegionFactory.class.getName());
    props.put(CacheEnvironment.HAZELCAST_INSTANCE_NAME, "hibernate");
    props.put(CacheEnvironment.SHUTDOWN_ON_STOP, "false");
    props.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");

    Configuration configuration = new Configuration();
    configuration.addProperties(props);

    SessionFactory sf = configuration.buildSessionFactory();
    assertTrue(hz.equals(HazelcastAccessor.getHazelcastInstance(sf)));
    sf.close();
    assertTrue(hz.getLifecycleService().isRunning());
    factory.shutdownAll();
}
项目:hazelcast-hibernate    文件:HazelcastQueryResultsRegionTest.java   
@Before
public void setUp() throws Exception {
    mapConfig = mock(MapConfig.class);
    when(mapConfig.getMaxSizeConfig()).thenReturn(new MaxSizeConfig(maxSize, MaxSizeConfig.MaxSizePolicy.PER_NODE));
    when(mapConfig.getTimeToLiveSeconds()).thenReturn(timeout);

    config = mock(Config.class);
    when(config.findMapConfig(eq(REGION_NAME))).thenReturn(mapConfig);

    Cluster cluster = mock(Cluster.class);
    when(cluster.getClusterTime()).thenAnswer(new Answer<Long>() {
        @Override
        public Long answer(InvocationOnMock invocation) throws Throwable {
            return System.currentTimeMillis();
        }
    });

    instance = mock(HazelcastInstance.class);
    when(instance.getConfig()).thenReturn(config);
    when(instance.getCluster()).thenReturn(cluster);

    region = new HazelcastQueryResultsRegion(instance, REGION_NAME, new Properties());
}
项目:hazelcast-hibernate5    文件:HazelcastTimestampsRegionTest.java   
@Before
public void setUp() throws Exception {
    mapConfig = mock(MapConfig.class);
    when(mapConfig.getMaxSizeConfig()).thenReturn(new MaxSizeConfig(50, MaxSizeConfig.MaxSizePolicy.PER_NODE));
    when(mapConfig.getTimeToLiveSeconds()).thenReturn(timeout);

    config = mock(Config.class);
    when(config.findMapConfig(eq(REGION_NAME))).thenReturn(mapConfig);

    Cluster cluster = mock(Cluster.class);
    when(cluster.getClusterTime()).thenAnswer(new Answer<Long>() {
        @Override
        public Long answer(InvocationOnMock invocation) throws Throwable {
            return System.currentTimeMillis();
        }
    });

    instance = mock(HazelcastInstance.class);
    when(instance.getConfig()).thenReturn(config);
    when(instance.getCluster()).thenReturn(cluster);

    cache = mock(RegionCache.class);

    region = new HazelcastTimestampsRegion<RegionCache>(instance, REGION_NAME, new Properties(), cache);
}
项目:hazelcast-hibernate5    文件:HazelcastQueryResultsRegionTest.java   
@Before
public void setUp() throws Exception {
    mapConfig = mock(MapConfig.class);
    when(mapConfig.getMaxSizeConfig()).thenReturn(new MaxSizeConfig(maxSize, MaxSizeConfig.MaxSizePolicy.PER_NODE));
    when(mapConfig.getTimeToLiveSeconds()).thenReturn(timeout);

    config = mock(Config.class);
    when(config.findMapConfig(eq(REGION_NAME))).thenReturn(mapConfig);

    Cluster cluster = mock(Cluster.class);
    when(cluster.getClusterTime()).thenAnswer(new Answer<Long>() {
        @Override
        public Long answer(InvocationOnMock invocation) throws Throwable {
            return System.currentTimeMillis();
        }
    });

    instance = mock(HazelcastInstance.class);
    when(instance.getConfig()).thenReturn(config);
    when(instance.getCluster()).thenReturn(cluster);

    region = new HazelcastQueryResultsRegion(instance, REGION_NAME, new Properties());
}
项目:spring-boot-concourse    文件:HazelcastAutoConfigurationTests.java   
@Test
public void configInstanceWithName() {
    Config config = new Config("my-test-instance");
    HazelcastInstance existingHazelcastInstance = Hazelcast
            .newHazelcastInstance(config);
    try {
        load(HazelcastConfigWithName.class,
                "spring.hazelcast.config=this-is-ignored.xml");
        HazelcastInstance hazelcastInstance = this.context
                .getBean(HazelcastInstance.class);
        assertThat(hazelcastInstance.getConfig().getInstanceName())
                .isEqualTo("my-test-instance");
        // Should reuse any existing instance by default.
        assertThat(hazelcastInstance).isEqualTo(existingHazelcastInstance);
    }
    finally {
        existingHazelcastInstance.shutdown();
    }
}
项目:hazelcast-hibernate    文件:HazelcastTimestampsRegionTest.java   
@Before
public void setUp() throws Exception {
    mapConfig = mock(MapConfig.class);
    when(mapConfig.getMaxSizeConfig()).thenReturn(new MaxSizeConfig(50, MaxSizeConfig.MaxSizePolicy.PER_NODE));
    when(mapConfig.getTimeToLiveSeconds()).thenReturn(timeout);

    config = mock(Config.class);
    when(config.findMapConfig(eq(REGION_NAME))).thenReturn(mapConfig);

    Cluster cluster = mock(Cluster.class);
    when(cluster.getClusterTime()).thenAnswer(new Answer<Long>() {
        @Override
        public Long answer(InvocationOnMock invocation) throws Throwable {
            return System.currentTimeMillis();
        }
    });

    instance = mock(HazelcastInstance.class);
    when(instance.getConfig()).thenReturn(config);
    when(instance.getCluster()).thenReturn(cluster);

    cache = mock(RegionCache.class);

    region = new HazelcastTimestampsRegion<RegionCache>(instance, REGION_NAME, new Properties(), cache);
}
项目:hazelcast-hibernate    文件:LocalRegionCacheTest.java   
@Test
public void testThreeArgConstructorRegistersTopicListener() {
    MapConfig mapConfig = mock(MapConfig.class);

    Config config = mock(Config.class);
    when(config.findMapConfig(eq(CACHE_NAME))).thenReturn(mapConfig);

    ITopic<Object> topic = mock(ITopic.class);
    when(topic.addMessageListener(isNotNull(MessageListener.class))).thenReturn("ignored");

    HazelcastInstance instance = mock(HazelcastInstance.class);
    when(instance.getConfig()).thenReturn(config);
    when(instance.getTopic(eq(CACHE_NAME))).thenReturn(topic);

    new LocalRegionCache(CACHE_NAME, instance, null);
    verify(config).findMapConfig(eq(CACHE_NAME));
    verify(instance).getConfig();
    verify(instance).getTopic(eq(CACHE_NAME));
    verify(topic).addMessageListener(isNotNull(MessageListener.class));
}
项目:xm-uaa    文件:CacheConfiguration.java   
@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());
    config.getMapConfigs().put("com.icthh.xm.uaa.domain.*", initializeDomainMapConfig(jHipsterProperties));
    // Uncomment if session needed
    //config.getMapConfigs().put("clustered-http-sessions", initializeClusteredSession(jHipsterProperties));
    return Hazelcast.newHazelcastInstance(config);
}
项目:Spring-5.0-Cookbook    文件:CachingConfig.java   
@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;
}
项目:springboot-shiro-cas-mybatis    文件:DefaultHazelcastInstanceConfigurationTests.java   
@Test
public void correctHazelcastInstanceIsCreated() throws Exception {
    assertNotNull(this.hzInstance);
    final Config config = this.hzInstance.getConfig();
    assertFalse(config.getNetworkConfig().getJoin().getMulticastConfig().isEnabled());
    assertEquals(Arrays.asList("localhost"), config.getNetworkConfig().getJoin().getTcpIpConfig().getMembers());
    assertTrue(config.getNetworkConfig().isPortAutoIncrement());
    assertEquals(5701, config.getNetworkConfig().getPort());

    final MapConfig mapConfig = config.getMapConfig("tickets");
    assertNotNull(mapConfig);
    assertEquals(28800, mapConfig.getMaxIdleSeconds());
    assertEquals(EvictionPolicy.LRU, mapConfig.getEvictionPolicy());
    assertEquals(10, mapConfig.getEvictionPercentage());
}
项目:springboot-shiro-cas-mybatis    文件:ProvidedHazelcastInstanceConfigurationTests.java   
@Test
public void hazelcastInstanceIsCreatedNormally() throws Exception {
    assertNotNull(this.hzInstance);
    final Config config = this.hzInstance.getConfig();
    assertTrue(config.getNetworkConfig().getJoin().getMulticastConfig().isEnabled());
    assertEquals(Arrays.asList("127.0.0.1"), config.getNetworkConfig().getJoin().getTcpIpConfig().getMembers());
    assertFalse(config.getNetworkConfig().isPortAutoIncrement());
    assertEquals(5801, config.getNetworkConfig().getPort());

    final MapConfig mapConfig = config.getMapConfig("tickets-from-external-config");
    assertNotNull(mapConfig);
    assertEquals(20000, mapConfig.getMaxIdleSeconds());
    assertEquals(EvictionPolicy.LFU, mapConfig.getEvictionPolicy());
    assertEquals(99, mapConfig.getEvictionPercentage());
}
项目:cas-5.1.0    文件:DefaultHazelcastInstanceConfigurationTests.java   
@Test
public void correctHazelcastInstanceIsCreated() throws Exception {
    assertNotNull(this.hzInstance);
    final Config config = this.hzInstance.getConfig();
    assertFalse(config.getNetworkConfig().getJoin().getMulticastConfig().isEnabled());
    assertEquals(Arrays.asList("localhost"), config.getNetworkConfig().getJoin().getTcpIpConfig().getMembers());
    assertTrue(config.getNetworkConfig().isPortAutoIncrement());
    assertEquals(5701, config.getNetworkConfig().getPort());
    assertEquals(2, config.getMapConfigs().size());
}