Java 类com.hazelcast.core.Hazelcast 实例源码

项目: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();
}
项目:scalable-websocket-chat-with-hazelcast    文件:WebSocketServerManager.java   
void runServer(boolean autoShutDown, String port) throws Exception {

        server = new Server("localhost",
                Integer.parseInt(port),
                "", null, ChatServer.class);

        server.start();
        HZ = Hazelcast.newHazelcastInstance();

        if (autoShutDown) {
            Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
                @Override
                public void run() {
                    stop();
                    System.out.println("Stopped WebSocket server & HZ");

                }
            }));

            System.out.print("Shutdown hook added");

        }
        started = true;
    }
项目: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);
}
项目:hazelcast-demo    文件:ListenerDemo.java   
public static void main(String[] args) {
    HazelcastInstance ins = Hazelcast.newHazelcastInstance();
    IMap<Integer, String> map = ins.getMap("");
    map.addEntryListener(new ListenerExample(), true);//添加自定义监听器
    map.put(1, "Grand Theft Auto");
    map.put(1, "Final Fantasy");
    map.put(2, "World Of Warcraft");

    HazelcastInstance insex = Hazelcast.newHazelcastInstance();
    IMap<Integer, String> mapex = insex.getMap("");

    System.out.println(mapex.get(1));
    System.out.println(mapex.get(2));
    mapex.remove(1);
    mapex.remove(2);
    System.exit(0);
}
项目: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);
}
项目:bigstreams    文件:HazelcastLockMemory.java   
public HazelcastLockMemory(IMap<String, LockValue> locksMap) {
    super();
    this.locksMap = locksMap;

    LOG.info("HazelcastLockMemory ----- MAP_ID: " + locksMap.getId());
    LOG.info("HazelcastLockMemory ----- MAP_NAME: " + locksMap.getName());
    LOG.info("HazelcastLockMemory ----- MAP_STRING: " + locksMap.toString());
    LOG.info("HazelcastLockMemory ----- MAP_INSTANCE_TYPE: " + locksMap.getInstanceType());

    MapConfig mapConf = Hazelcast.getConfig().getMapConfig(DistributedMapNames.MAP.LOCK_MEMORY_LOCKS_MAP.toString());

    MapStoreConfig mapStoreConf = mapConf.getMapStoreConfig();

    if(mapStoreConf == null){
        LOG.info("HazelcastLockMemory ----- MAPSTORE NULL");    
    }else{
        LOG.info("HazelcastLockMemory ----- MAPSTORE IMPL: " + mapStoreConf.getImplementation());
    }


}
项目:bigstreams    文件:HazelcastFileTrackerStorage.java   
/**
 * Requires a hazelcast map.
 * 
 * @param fileTrackerMemory
 * @param logTypeSet
 *            stores the log types
 * @param agentSet
 */
public HazelcastFileTrackerStorage(
        IMap<FileTrackingStatusKey, FileTrackingStatus> fileTrackerMemory,
        IMap<String, LogTypeContact> logTypeSet, IMap<String, AgentContact> agentSet) {

    this.fileTrackerMemoryMap = fileTrackerMemory;
    this.logTypeSet = logTypeSet;
    this.agentSet = agentSet;

    MapConfig mapConf = Hazelcast.getConfig().getMapConfig(
            DistributedMapNames.MAP.FILE_TRACKER_MAP.toString());

    MapStoreConfig mapStoreConf = mapConf.getMapStoreConfig();

    if (mapStoreConf == null) {
        LOG.info("HazelcastFileTrackerStorage ----- MAPSTORE NULL");
    } else {
        LOG.info("HazelcastFileTrackerStorage ----- MAPSTORE IMPL: "
                + mapStoreConf.getImplementation());
    }

}
项目: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());
}
项目:jpoint-2016-computing-talk    文件:MasterMember.java   
public static void main(String[] args) {
    HazelcastInstance hz = Hazelcast.newHazelcastInstance();
    IExecutorService executor = hz.getExecutorService("executor");
    ExecutionCallback<Long> executionCallback = new ExecutionCallback<Long>() {
        public void onFailure(Throwable t) {
            t.printStackTrace();
        }

        public void onResponse(Long response) {
            System.out.println("Result: " + response);
        }
    };
    executor.submit(new FibonacciCallable(10), executionCallback);
    System.out.println("Fibonacci task submitted");
}
项目:reactive-data    文件:HazelcastInstanceProxy.java   
/**
 * 
 */
private void createHazelcastInstance()
{
  hazelcast = Hazelcast.getOrCreateHazelcastInstance(hzConfig);
   Set<Member> members = hazelcast.getCluster().getMembers();

   int memberIdCnt = 0;
   for(Member m : members)
   {

     if(m.getStringAttribute(Configurator.NODE_INSTANCE_ID).equals(getInstanceId()))
     {
       memberIdCnt++;
     }
     if(memberIdCnt >= 2){
       stop();
       throw new IllegalStateException("Instance not allowed to join cluster as ["+getInstanceId()+"]. Duplicate name!");
     }

   }
   log.info("** Instance ["+getInstanceId()+"] joined cluster ["+hzConfig.getGroupConfig().getName()+"] successfully **");
}
项目: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-hibernate5    文件:HibernateSerializationHookAvailableTest.java   
@Test
public void testAutoregistrationOnHibernate5Available()
        throws Exception {

    HazelcastInstance hz = Hazelcast.newHazelcastInstance();
    HazelcastInstanceImpl impl = (HazelcastInstanceImpl) ORIGINAL.get(hz);
    SerializationService ss = impl.getSerializationService();
    @SuppressWarnings("unchecked")
    ConcurrentMap<Class, ?> typeMap = (ConcurrentMap) TYPE_MAP.get(ss);

    boolean cacheEntrySerializerFound = false;
    for (Class clazz : typeMap.keySet()) {
        if (StandardCacheEntryImpl.class.equals(clazz)
                || "com.hazelcast.hibernate.serialization.CacheEntryImpl".equals(clazz.getName())) {
            cacheEntrySerializerFound = true;
        }
    }

    assertTrue("CacheEntry serializer not found", cacheEntrySerializerFound);
}
项目: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-wm    文件:AbstractWebFilterTest.java   
protected void ensureInstanceIsUp() throws Exception {
    if (isInstanceNotActive(hz)) {
        hz = Hazelcast.newHazelcastInstance(
                new FileSystemXmlConfig(new File(sourceDir + "/WEB-INF/", "hazelcast.xml")));
    }
    if (serverXml1 != null) {
        if (server1 == null) {
            serverPort1 = availablePort();
            server1 = getServletContainer(serverPort1, sourceDir, serverXml1);
        } else if (!server1.isRunning()) {
            server1.start();
        }
    }
    if (serverXml2 != null) {
        if (server2 == null) {
            serverPort2 = availablePort();
            server2 = getServletContainer(serverPort2, sourceDir, serverXml2);
        } else if (!server2.isRunning()) {
            server2.start();
        }
    }
}
项目:hazelcast-wm    文件:AbstractWebFilterTest.java   
@AfterClass
public static void teardownClass() throws Exception {
    for (Entry<Class<? extends AbstractWebFilterTest>, ContainerContext> ccEntry :
            CONTAINER_CONTEXT_MAP.entrySet()) {
        ContainerContext cc = ccEntry.getValue();
        try {
            // Stop servers
            cc.server1.stop();
            if (cc.server2 != null) {
                cc.server2.stop();
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
    // Shutdown all instances
    Hazelcast.shutdownAll();
}
项目:hazelcast-wm    文件:WebFilterClientFailOverTests.java   
@Test
public void whenClusterIsDown_enabledDeferredWrite() throws Exception {
    CookieStore cookieStore = new BasicCookieStore();
    assertEquals("true", executeRequest("write", serverPort1, cookieStore));
    assertEquals("value", executeRequest("read", serverPort1, cookieStore));
    hz.shutdown();

    assertEquals("value", executeRequest("read", serverPort1, cookieStore));
    assertEquals("true", executeRequest("remove", serverPort1, cookieStore));
    assertEquals("null", executeRequest("read", serverPort1, cookieStore));

    hz = Hazelcast.newHazelcastInstance(
            new FileSystemXmlConfig(new File(sourceDir + "/WEB-INF/", "hazelcast.xml")));
    assertClusterSizeEventually(1, hz);

    assertEquals("true", executeRequest("write", serverPort1, cookieStore));
    assertEquals("value", executeRequest("read", serverPort1, cookieStore));
}
项目:hazelcast-wm    文件:WebFilterClientFailOverTests.java   
@Test
public void whenClusterIsDownAtBeginning_enabledDeferredWrite() throws Exception {
    hz.shutdown();

    CookieStore cookieStore = new BasicCookieStore();
    assertEquals("true", executeRequest("write", serverPort1, cookieStore));
    assertEquals("value", executeRequest("read", serverPort1, cookieStore));

    assertEquals("value", executeRequest("read", serverPort1, cookieStore));
    assertEquals("true", executeRequest("remove", serverPort1, cookieStore));
    assertEquals("null", executeRequest("read", serverPort1, cookieStore));

    assertEquals("true", executeRequest("write", serverPort1, cookieStore));
    assertEquals("value", executeRequest("read", serverPort1, cookieStore));

    hz = Hazelcast.newHazelcastInstance(
            new FileSystemXmlConfig(new File(sourceDir + "/WEB-INF/", "hazelcast.xml")));
    assertClusterSizeEventually(1, hz);

    assertEquals("value", executeRequest("read", serverPort1, cookieStore));
    assertEquals("true", executeRequest("remove", serverPort1, cookieStore));
    assertEquals("null", executeRequest("read", serverPort1, cookieStore));

}
项目:hazelcast-wm    文件:WebFilterClientFailOverTests.java   
@Test
public void testWhenClusterIsDownAtBeginningInNonDeferredMode() throws Exception {
    if (!testName.equals("client - not deferred")) {
        return;
    }

    hz.shutdown();
    CookieStore cookieStore = new BasicCookieStore();
    assertEquals("true", executeRequest("write", serverPort1, cookieStore));
    assertEquals("value", executeRequest("read", serverPort1, cookieStore));

    hz = Hazelcast.newHazelcastInstance(
            new FileSystemXmlConfig(new File(sourceDir + "/WEB-INF/", "hazelcast.xml")));
    assertClusterSizeEventually(1, hz);

    assertEquals("value", executeRequest("read", serverPort1, cookieStore));
    IMap<String, Object> map = hz.getMap(DEFAULT_MAP_NAME);
    assertEquals(1, map.size());
}
项目:hazelcast-wm    文件:WebFilterClientFailOverTests.java   
@Test
public void testWhenClusterIsDownAtBeginningInDeferedMode() throws Exception {
    if (!testName.equals("client - not deferred")) {
        return;
    }

    hz.shutdown();
    CookieStore cookieStore = new BasicCookieStore();
    assertEquals("true", executeRequest("write", serverPort1, cookieStore));
    assertEquals("value", executeRequest("read", serverPort1, cookieStore));

    hz = Hazelcast.newHazelcastInstance(
            new FileSystemXmlConfig(new File(sourceDir + "/WEB-INF/", "hazelcast.xml")));
    assertClusterSizeEventually(1, hz);
    assertEquals("value", executeRequest("read", serverPort1, cookieStore));

    IMap<String, Object> map = hz.getMap(DEFAULT_MAP_NAME);
    assertEquals(0, map.size());
}
项目:hazelcast-wm    文件:DeferredWriteClusterTest.java   
@Override
protected void ensureInstanceIsUp() throws Exception {
    if (isInstanceNotActive(hz)) {
        hz = Hazelcast.newHazelcastInstance(
                new FileSystemXmlConfig(new File(sourceDir + "/WEB-INF/", "hazelcast.xml")));
    }
    if (serverXml1 != null) {
        if (server1 == null) {
            serverPort1 = availablePort();
            server1 = getServletContainer(serverPort1, sourceDir, serverXml1);
        } else if (!server1.isRunning()) {
            server1.start();
        }
    }
    if (serverXml2 != null) {
        if (server2 == null) {
            serverPort2 = availablePort();
            server2 = getServletContainer(serverPort2, sourceDir, serverXml2);
        } else if (!server2.isRunning()) {
            server2.start();
        }
    }
}
项目:hazelcast-wm    文件:DeferredFailoverClusterTest.java   
@Override
protected void ensureInstanceIsUp() throws Exception {
    if (isInstanceNotActive(hz)) {
        hz = Hazelcast.newHazelcastInstance(
                new FileSystemXmlConfig(new File(sourceDir + "/WEB-INF/", "hazelcast.xml")));
    }
    if (serverXml1 != null) {
        if (server1 == null) {
            serverPort1 = availablePort();
            server1 = getServletContainer(serverPort1, sourceDir, serverXml1);
        } else if (!server1.isRunning()) {
            server1.start();
        }
    }
    if (serverXml2 != null) {
        if (server2 == null) {
            serverPort2 = availablePort();
            server2 = getServletContainer(serverPort2, sourceDir, serverXml2);
        } else if (!server2.isRunning()) {
            server2.start();
        }
    }
}
项目: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);
}
项目:cas-5.1.0    文件:HazelcastMonitor.java   
@Override
protected CacheStatistics[] getStatistics() {
    final List<CacheStatistics> statsList = new ArrayList<>();
    final HazelcastProperties hz = casProperties.getTicket().getRegistry().getHazelcast();
    LOGGER.debug("Locating hazelcast instance [{}]...", hz.getCluster().getInstanceName());
    final HazelcastInstance instance = Hazelcast.getHazelcastInstanceByName(hz.getCluster().getInstanceName());

    instance.getConfig().getMapConfigs().keySet().forEach(key -> {
        final IMap map = instance.getMap(key);
        LOGGER.debug("Starting to collect hazelcast statistics for map [{}] identified by key [{}]...", map, key);
        statsList.add(new HazelcastStatistics(map, hz.getCluster().getMembers().size()));
    });
    return statsList.toArray(new CacheStatistics[statsList.size()]);
}
项目:teamcity-gradle-build-cache-plugin    文件:BuildCacheServer.java   
void start() {
    LOGGER.info(getClass().getSimpleName() + " started");
    java.util.logging.Logger.getLogger("com.hazelcast").setLevel(Level.WARNING);
    Config config = new Config();
    config.setInstanceName(INSTANCE_NAME);
    config.getNetworkConfig()
            .setPort(5701)
            .getJoin()
            .getMulticastConfig()
            .setEnabled(false);
    hazelcastInstance = Hazelcast.newHazelcastInstance(config);
}
项目:teamcity-gradle-build-cache-plugin    文件:BuildCachePage.java   
public void fillModel(@NotNull Map<String, Object> model, @NotNull HttpServletRequest request) {
    HazelcastInstance instance = Hazelcast.getHazelcastInstanceByName(INSTANCE_NAME);
    if (instance != null) {
        IMap<String, byte[]> taskCache = instance.getMap(TASK_CACHE_NAME);
        LocalMapStats statistics = taskCache.getLocalMapStats();
        model.put("statistics", statistics);
    }
}
项目:rate-limiting    文件:RateLimitingFilter.java   
protected void initHazelcast(RateLimitingSettings initSettings) {
    if (getHZ() == null) {
        String hzConfig = getHazelcastConfig(initSettings);
        if (isBlank(hzConfig)) {
            logger.warn("Starting new local instance of Hazelcast, valid only during testing!!!");
            logger.warn("You can pass the location of HZ configuration using 'HZ_FILE' system property");
            hazelcastInstance = Hazelcast.newHazelcastInstance();
        } else {
            hazelcastInstance = HzUtil.loadHzConfiguration(hzConfig);
        }
    }
}
项目:j1st-mqtt    文件:HazelcastHttpCommunicator.java   
@Override
public void init(AbstractConfiguration config, String serverId) {
    this.hazelcast = Hazelcast.newHazelcastInstance();

    logger.trace("Initializing Hazelcast broker resources ...");

    BROKER_TOPIC_PREFIX = config.getString("communicator.broker.topic");
    APPLICATION_TOPIC = config.getString("communicator.application.topic");
}
项目:bookstore    文件:HazelcastConfig.java   
@Bean
public HazelcastInstance hazelcastInstance() {
    Config config = new Config();

    //Cluster
    String clusterName = hzProperties.getGroup().getName();
    config.setInstanceName(clusterName);
    config.getGroupConfig().setName(clusterName);
    config.getGroupConfig().setPassword(hzProperties.getGroup().getPassword());

    //Properties
    config.getSerializationConfig().addDataSerializableFactory(1, new ShoppingCartDSFactory());
    config.setProperty("hazelcast.logging.type", hzProperties.getLogging().getType());
    config.setProperty("hazelcast.jmx", hzProperties.getJmx());

    //Network
    NetworkConfig network = config.getNetworkConfig();
    network.setPort(hzProperties.getNetwork().getPort());
    network.setPortAutoIncrement(hzProperties.getNetwork().isPortAutoIncrement());
    JoinConfig join = network.getJoin();
    join.getMulticastConfig().setEnabled(false);
    TcpIpConfig tcpIpConfig = join.getTcpIpConfig();
    tcpIpConfig.setEnabled(true);
    tcpIpConfig.setMembers(Arrays.asList(hzProperties.getCluster().getMembers().split(HZ_MEMBERS_SEPARATOR)));

    //Maps
    config.addMapConfig(configBookMap());
    config.addMapConfig(configShoppingCartMap());

    return Hazelcast.newHazelcastInstance(config);
}
项目:xm-ms-config    文件:HazelcastConfiguration.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)));

    return Hazelcast.newHazelcastInstance(config);
}
项目:kalinka    文件:HcConnectionStoreTest.java   
@Before
public void setUp() throws Exception {

    final Config config = new Config();
    config.getGroupConfig().setName(GROUP_NAME);
    config.setProperty("hazelcast.logging.type", "slf4j");
    this.hzInstance = Hazelcast.newHazelcastInstance(config);
    this.hcConnectionStore = new HcConnectionStore("127.0.0.1:5701", GROUP_NAME, MAP_NAME, "192.168.90.1");
}
项目:Android_Code_Arbiter    文件:HazelcastSymmetric.java   
public void init() {

        //Specific map time to live
        MapConfig myMapConfig = new MapConfig();
        myMapConfig.setName("cachetest");
        myMapConfig.setTimeToLiveSeconds(10);

        //Package config
        Config myConfig = new Config();
        myConfig.addMapConfig(myMapConfig);

        //Symmetric Encryption
        SymmetricEncryptionConfig symmetricEncryptionConfig = new SymmetricEncryptionConfig();
        symmetricEncryptionConfig.setAlgorithm("DESede");
        symmetricEncryptionConfig.setSalt("saltysalt");
        symmetricEncryptionConfig.setPassword("lamepassword");
        symmetricEncryptionConfig.setIterationCount(1337);

        //Weak Network config..
        NetworkConfig networkConfig = new NetworkConfig();
        networkConfig.setSymmetricEncryptionConfig(symmetricEncryptionConfig);

        myConfig.setNetworkConfig(networkConfig);

        Hazelcast.init(myConfig);

        cacheMap = Hazelcast.getMap("cachetest");
    }
项目:sctalk    文件:HazelCastConfigration.java   
@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);
}