本文整理匯總了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");
}