本文整理汇总了Java中com.hazelcast.core.Hazelcast.getMap方法的典型用法代码示例。如果您正苦于以下问题:Java Hazelcast.getMap方法的具体用法?Java Hazelcast.getMap怎么用?Java Hazelcast.getMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.hazelcast.core.Hazelcast
的用法示例。
在下文中一共展示了Hazelcast.getMap方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMultipleLockUnLockFromDifferentCollector
import com.hazelcast.core.Hazelcast; //导入方法依赖的package包/类
/**
* Test that if a different collector tries to unlock a lock held by another
* collector it is blocked from doing so.
*
* @throws Exception
*/
@Test
public void testMultipleLockUnLockFromDifferentCollector() throws Exception {
IMap<String, LockValue> locksMap = Hazelcast.getMap(
DistributedMapNames.MAP.LOCK_MEMORY_LOCKS_MAP.toString());
final HazelcastLockMemory memory = new HazelcastLockMemory(locksMap);
/**
* (long filePointer, long fileSize,int linePointer, String agentName,
* String fileName, String logType)
*/
final FileTrackingStatus status = new FileTrackingStatus(new Date(), 0L, 0L, 1,
"agent1", "file1", "type1", new Date(), 1L);
SyncPointer pointer = memory.setLock(status, "localhost1");
assertNotNull(pointer);
assertNull(memory.removeLock(pointer, "localhost2"));
assertNotNull(memory.removeLock(pointer, "localhost1"));
}
示例2: init
import com.hazelcast.core.Hazelcast; //导入方法依赖的package包/类
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");
}
示例3: testRemoveTimedoutLocks
import com.hazelcast.core.Hazelcast; //导入方法依赖的package包/类
/**
* Create a lock and check when its timedout it is removed.
*
* @throws Exception
*/
@Test
public void testRemoveTimedoutLocks() throws Exception {
IMap<String, LockValue> locksMap = Hazelcast.getMap(
DistributedMapNames.MAP.LOCK_MEMORY_LOCKS_MAP.toString());
final HazelcastLockMemory memory = new HazelcastLockMemory(locksMap);
/**
* (long filePointer, long fileSize,int linePointer, String agentName,
* String fileName, String logType)
*/
final FileTrackingStatus status = new FileTrackingStatus(new Date(), 0L, 0L, 1,
"agent1", "file1", "type1", new Date(), 1L);
SyncPointer pointer = memory.setLock(status, "localhost1");
long timeStamp = memory.lockTimeStamp(status);
assertEquals(pointer.getTimeStamp(), timeStamp);
// sleep 1s
Thread.sleep(1500L);
memory.removeTimedOutLocks(1000L);
assertNull(memory.removeLock(pointer, "localhost1"));
}
示例4: testMultipleLockRequestsConflict
import com.hazelcast.core.Hazelcast; //导入方法依赖的package包/类
/**
* Test that a lock can only be given once to a collector.
*
* @throws Exception
*/
@Test
public void testMultipleLockRequestsConflict() throws Exception {
IMap<String, LockValue> locksMap = Hazelcast.getMap(
DistributedMapNames.MAP.LOCK_MEMORY_LOCKS_MAP.toString());
final HazelcastLockMemory memory = new HazelcastLockMemory(locksMap);
/**
* (long filePointer, long fileSize,int linePointer, String agentName,
* String fileName, String logType)
*/
final FileTrackingStatus status = new FileTrackingStatus(new Date(), 0L, 0L, 1,
"agent1", "file1", "type1", new Date(), 1L);
final AtomicInteger lockCount = new AtomicInteger(0);
int count = 100;
final CountDownLatch latch = new CountDownLatch(count);
ExecutorService service = Executors.newFixedThreadPool(count);
for (int i = 0; i < count; i++) {
service.submit(new Runnable() {
public void run() {
try {
if (memory.setLock(status, "localhost") != null) {
lockCount.incrementAndGet();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
latch.countDown();
}
});
}
latch.await();
assertEquals(1, lockCount.get());
}
示例5: testHazelcast
import com.hazelcast.core.Hazelcast; //导入方法依赖的package包/类
@Test
public void testHazelcast(){
Map<String, String> map = Hazelcast.getMap("mymap");
map.put("key1", "test1");
}