com.hazelcast.core.ILock Java Examples
The following examples show how to use
com.hazelcast.core.ILock.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClusterDataDisposer.java From lannister with Apache License 2.0 | 6 votes |
public void disposeLock(Lock lock) { switch (Settings.INSTANCE.clusteringMode()) { case HAZELCAST: ((ILock) lock).destroy(); break; case IGNITE: break; case SINGLE: break; default: break; } }
Example #2
Source File: HazelcastDistributedObjectProvider.java From attic-stratos with Apache License 2.0 | 6 votes |
protected com.hazelcast.core.ILock acquireDistributedLock(Object object) { if (object == null) { if (log.isWarnEnabled()) { log.warn("Could not acquire distributed lock, object is null"); } return null; } if (log.isDebugEnabled()) { log.debug(String.format("Acquiring distributed lock for %s...", object.getClass().getSimpleName())); } ILock lock = getHazelcastInstance().getLock(object); if (log.isDebugEnabled()) { log.debug(String.format("Distributed lock acquired for %s", object.getClass().getSimpleName())); } return lock; }
Example #3
Source File: HazelcastDistributedObjectProvider.java From attic-stratos with Apache License 2.0 | 6 votes |
protected void releaseDistributedLock(ILock lock) { if (lock == null) { if (log.isWarnEnabled()) { log.warn("Could not release distributed lock, lock is null"); } return; } if (log.isDebugEnabled()) { log.debug(String.format("Releasing distributed lock for %s...", lock.getKey())); } lock.forceUnlock(); if (log.isDebugEnabled()) { log.debug(String.format("Distributed lock released for %s", lock.getKey())); } }
Example #4
Source File: ApplicationStartup.java From jvue-admin with MIT License | 5 votes |
private void initAdmin() { ILock ilock = hazelcastInstance.getLock("init-admin"); try { if (ilock.isLocked()) { // 已有节点在执行 return; } ilock.lock(); // 没有超级管理员 JvueUser record = new JvueUser(); long userCount =userRepository.selectCount(record); if (userCount > 0) { // 用户已经存在 return; } // 追加管理员 JvueUser user = new JvueUser(); user.setUsername("admin"); user.setPassword(passwordEncoder.encode("admin")); user.setStatus(JvueDataStatus.ENABLE_TRUE); user.setNickname("Supper admin"); user.setSuperUser(JvueDataStatus.SUPER_USER_TRUE); userRepository.insertSelective(user); } finally { ilock.unlock(); } }
Example #5
Source File: HazelcastDistributedObjectProvider.java From attic-stratos with Apache License 2.0 | 5 votes |
/** * Releases a given distributed/local lock. * * @param lock */ @Override public void releaseLock(Lock lock) { if (isClustered()) { releaseDistributedLock((ILock) lock); } else { lock.unlock(); } }
Example #6
Source File: LumongoIndex.java From lumongo with Apache License 2.0 | 5 votes |
private void loadSegment(int segmentNumber) throws Exception { indexLock.writeLock().lock(); try { if (!segmentMap.containsKey(segmentNumber)) { String lockName = indexName + "-" + segmentNumber; ILock hzLock = hazelcastManager.getLock(lockName); hazelLockMap.put(segmentNumber, hzLock); log.info("Waiting for lock for index <" + indexName + "> segment <" + segmentNumber + ">"); hzLock.lock(); log.info("Obtained lock for index <" + indexName + "> segment <" + segmentNumber + ">"); //Just for clarity IndexSegmentInterface indexSegmentInterface = this; //doesnt need to be done each time and it is done in StartNode but helps with test cases that take different paths FacetsConfig.DEFAULT_DIM_CONFIG.multiValued = true; facetsConfig = new FacetsConfig(); LumongoSegment s = new LumongoSegment(segmentNumber, indexSegmentInterface, indexConfig, facetsConfig, documentStorage); segmentMap.put(segmentNumber, s); log.info("Loaded segment <" + segmentNumber + "> for index <" + indexName + ">"); log.info("Current segments <" + (new TreeSet<>(segmentMap.keySet())) + "> for index <" + indexName + ">"); } } finally { indexLock.writeLock().unlock(); } }
Example #7
Source File: LumongoIndex.java From lumongo with Apache License 2.0 | 5 votes |
public void unloadSegment(int segmentNumber, boolean terminate) throws IOException { indexLock.writeLock().lock(); try { ILock hzLock = hazelLockMap.get(segmentNumber); try { if (segmentMap.containsKey(segmentNumber)) { LumongoSegment s = segmentMap.remove(segmentNumber); if (s != null) { log.info("Closing segment <" + segmentNumber + "> for index <" + indexName + ">"); s.close(terminate); log.info("Removed segment <" + segmentNumber + "> for index <" + indexName + ">"); log.info("Current segments <" + (new TreeSet<>(segmentMap.keySet())) + "> for index <" + indexName + ">"); } } } finally { try { hzLock.forceUnlock(); log.info("Unlocked lock for index <" + indexName + "> segment <" + segmentNumber + ">"); } catch (Exception e) { log.error("Failed to unlock <" + segmentNumber + ">: ", e); } } } finally { indexLock.writeLock().unlock(); } }
Example #8
Source File: WebConfigurerTest.java From flair-engine with Apache License 2.0 | 4 votes |
@Override public ILock getLock(String s) { return null; }
Example #9
Source File: Hazelcast.java From lannister with Apache License 2.0 | 4 votes |
protected ILock getLock(String key) { return substance.getLock(key); }
Example #10
Source File: HazelcastManager.java From lumongo with Apache License 2.0 | 4 votes |
public ILock getLock(String lockName) { return hazelcastInstance.getLock(lockName); }
Example #11
Source File: HazelcastSynchroInstanceAware.java From incubator-batchee with Apache License 2.0 | 4 votes |
protected ILock findLock() throws IOException { return instance().getLock(lockName()); }