本文整理汇总了Java中com.hazelcast.core.Hazelcast类的典型用法代码示例。如果您正苦于以下问题:Java Hazelcast类的具体用法?Java Hazelcast怎么用?Java Hazelcast使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Hazelcast类属于com.hazelcast.core包,在下文中一共展示了Hazelcast类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.hazelcast.core.Hazelcast; //导入依赖的package包/类
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());
}
示例2: tenantConfigurationHazelcast
import com.hazelcast.core.Hazelcast; //导入依赖的package包/类
@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;
}
示例3: hazelcastInstance
import com.hazelcast.core.Hazelcast; //导入依赖的package包/类
@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);
}
示例4: hazelcastInstance
import com.hazelcast.core.Hazelcast; //导入依赖的package包/类
/**
* 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);
}
}
示例5: hazelcastInstance
import com.hazelcast.core.Hazelcast; //导入依赖的package包/类
@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);
}
示例6: hazelcastInstance
import com.hazelcast.core.Hazelcast; //导入依赖的package包/类
@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);
}
示例7: hazelcastInstance
import com.hazelcast.core.Hazelcast; //导入依赖的package包/类
@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);
}
示例8: hazelcastInstance
import com.hazelcast.core.Hazelcast; //导入依赖的package包/类
@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);
}
示例9: executeSchemaChange
import com.hazelcast.core.Hazelcast; //导入依赖的package包/类
/**
* 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();
}
示例10: runServer
import com.hazelcast.core.Hazelcast; //导入依赖的package包/类
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;
}
开发者ID:abhirockzz,项目名称:scalable-websocket-chat-with-hazelcast,代码行数:25,代码来源:WebSocketServerManager.java
示例11: testIntegration
import com.hazelcast.core.Hazelcast; //导入依赖的package包/类
@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);
}
示例12: main
import com.hazelcast.core.Hazelcast; //导入依赖的package包/类
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);
}
示例13: main
import com.hazelcast.core.Hazelcast; //导入依赖的package包/类
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);
}
示例14: HazelcastLockMemory
import com.hazelcast.core.Hazelcast; //导入依赖的package包/类
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());
}
}
示例15: HazelcastFileTrackerStorage
import com.hazelcast.core.Hazelcast; //导入依赖的package包/类
/**
* 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());
}
}