List of usage examples for java.util.concurrent.locks Lock unlock
void unlock();
From source file:com.netprogs.minecraft.plugins.social.SocialPerson.java
public void setStatusUpdatesIgnored(boolean ignoreUpdates) { Lock lock = rwNotificationsLock.writeLock(); lock.lock();/* w w w . j ava 2 s . c o m*/ try { person.setStatusUpdatesIgnored(ignoreUpdates); } finally { lock.unlock(); } }
From source file:com.netprogs.minecraft.plugins.social.SocialPerson.java
public boolean isGenderChoiceRemindersIgnored() { Lock lock = rwNotificationsLock.readLock(); lock.lock();/*from w w w. java 2 s. com*/ try { return person.isGenderChoiceRemindersIgnored(); } finally { lock.unlock(); } }
From source file:com.netprogs.minecraft.plugins.social.SocialPerson.java
public Map<String, SocialRelationship> getRelationships() { Lock lock = rwRelationshipLock.readLock(); lock.lock();/*from w ww .jav a 2 s . com*/ try { return Collections.unmodifiableMap(relationships); } finally { lock.unlock(); } }
From source file:com.esofthead.mycollab.module.project.service.ibatis.GanttAssignmentServiceImpl.java
@Override public void massDeletePredecessors(List<TaskPredecessor> predecessors, @CacheKey Integer sAccountId) { Lock lock = DistributionLockUtil.getLock("gantt-predecessor-service" + sAccountId); try {/*from w w w .j a v a 2 s . c o m*/ if (lock.tryLock(30, TimeUnit.SECONDS)) { try (Connection connection = dataSource.getConnection()) { connection.setAutoCommit(false); PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM " + "`m_prj_predecessor` WHERE sourceType=? AND predestype=? AND sourceId=? AND descId=? AND descType=?"); for (int i = 0; i < predecessors.size(); i++) { preparedStatement.setString(1, predecessors.get(i).getSourcetype()); preparedStatement.setString(2, predecessors.get(i).getPredestype()); preparedStatement.setInt(3, predecessors.get(i).getSourceid()); preparedStatement.setInt(4, predecessors.get(i).getDescid()); preparedStatement.setString(5, predecessors.get(i).getDesctype()); preparedStatement.addBatch(); } preparedStatement.executeBatch(); connection.commit(); } } } catch (Exception e) { throw new MyCollabException(e); } finally { DistributionLockUtil.removeLock("gantt-predecessor-service" + sAccountId); lock.unlock(); } }
From source file:jp.aegif.nemaki.cmis.service.impl.ObjectServiceImpl.java
@Override public AllowableActions getAllowableActions(CallContext callContext, String repositoryId, String objectId) { exceptionService.invalidArgumentRequired("objectId", objectId); Lock lock = threadLockService.getReadLock(repositoryId, objectId); try {//from w w w. ja va 2 s. c o m lock.lock(); // ////////////////// // General Exception // ////////////////// Content content = contentService.getContent(repositoryId, objectId); exceptionService.objectNotFound(DomainType.OBJECT, content, objectId); // NOTE: The permission key doesn't exist according to CMIS // specification. // ////////////////// // Body of the method // ////////////////// return compileService.compileAllowableActions(callContext, repositoryId, content); } finally { lock.unlock(); } }
From source file:com.netprogs.minecraft.plugins.social.SocialPerson.java
public List<String> getIgnoredPlayers() { Lock lock = rwIgnoreLock.writeLock(); lock.lock();//www. j a v a2 s.c om try { return Collections.unmodifiableList(person.getIgnoreList()); } finally { lock.unlock(); } }
From source file:org.springframework.integration.aggregator.AbstractCorrelatingMessageHandler.java
@Override protected void handleMessageInternal(Message<?> message) throws Exception { Object correlationKey = correlationStrategy.getCorrelationKey(message); Assert.state(correlationKey != null, "Null correlation not allowed. Maybe the CorrelationStrategy is failing?"); if (logger.isDebugEnabled()) { logger.debug("Handling message with correlationKey [" + correlationKey + "]: " + message); }//from w ww . j ava 2 s .co m // TODO: INT-1117 - make the lock global? Lock lock = this.lockRegistry.obtain(UUIDConverter.getUUID(correlationKey).toString()); lock.lockInterruptibly(); try { MessageGroup messageGroup = messageStore.getMessageGroup(correlationKey); if (this.sequenceAware) { messageGroup = new SequenceAwareMessageGroup(messageGroup); } if (!messageGroup.isComplete() && messageGroup.canAdd(message)) { if (logger.isTraceEnabled()) { logger.trace("Adding message to group [ " + messageGroup + "]"); } messageGroup = this.store(correlationKey, message); if (releaseStrategy.canRelease(messageGroup)) { Collection<Message<?>> completedMessages = null; try { completedMessages = this.completeGroup(message, correlationKey, messageGroup); } finally { // Always clean up even if there was an exception // processing messages this.afterRelease(messageGroup, completedMessages); } } } else { discardChannel.send(message); } } finally { lock.unlock(); } }
From source file:com.netprogs.minecraft.plugins.social.SocialPerson.java
public void setGenderChoiceRemindersIgnored(boolean ignoreUpdates) { Lock lock = rwNotificationsLock.writeLock(); lock.lock();// ww w . j av a2 s . c o m try { person.setGenderChoiceRemindersIgnored(ignoreUpdates); } finally { lock.unlock(); } }
From source file:org.ambraproject.wombat.service.AssetServiceImpl.java
/** * {@inheritDoc}//from w ww . j av a2 s. co m */ @Override public String getCompiledAssetLink(AssetType assetType, List<String> filenames, Site site) throws IOException { String sourceCacheKey = generateCacheKey(assetType, site, filenames); String compiledFilename = cache.get(sourceCacheKey); if (compiledFilename == null) { // Keep a lock on asset compilation. We do this because we've // had a problem when we bring up wombat, and all the requests // attempt to compile assets simultaneously, leading to high // load. Lock lock = lockStripes.get(sourceCacheKey); try { lock.lock(); // Check again in case another thread built this while we were // waiting for the lock. compiledFilename = cache.get(sourceCacheKey); if (compiledFilename == null) { File concatenated = concatenateFiles(filenames, site, assetType.getExtension()); CompiledAsset compiled = compileAsset(assetType, concatenated); concatenated.delete(); compiledFilename = compiled.digest.getFile().getName(); // We cache both the file name and the file contents (if it is small enough) in memcache. // In an ideal world, we would use the filename (including the hash of its contents) as // the only cache key. However, it's potentially expensive to calculate that key since // you need the contents of the compiled file, which is why we do it this way. cache.put(sourceCacheKey, compiledFilename, CACHE_TTL); if (compiled.contents.length < MAX_ASSET_SIZE_TO_CACHE) { String contentsCacheKey = compiled.digest.getCacheKey(); cache.put(contentsCacheKey, compiled.contents, CACHE_TTL); } } } finally { lock.unlock(); } } return AssetUrls.COMPILED_PATH_PREFIX + compiledFilename; }
From source file:net.myrrix.online.ServerRecommender.java
/** * <p>Lists the items that were most influential in recommending a given item to a given user. Exactly how this * is determined is left to the implementation, but, generally this will return items that the user prefers * and that are similar to the given item.</p> * * <p>These values by which the results are ordered are opaque values and have no interpretation * other than that larger means stronger.</p> * * @param userID ID of user who was recommended the item * @param itemID ID of item that was recommended * @param howMany maximum number of items to return * @return {@link List} of {@link RecommendedItem}, ordered from most influential in recommended the given * item to least/*from ww w. ja v a2s. c o m*/ * @throws NoSuchUserException if the user is not known in the model * @throws NoSuchItemException if the item is not known in the model * @throws NotReadyException if the recommender has no model available yet */ @Override public List<RecommendedItem> recommendedBecause(long userID, long itemID, int howMany) throws NoSuchUserException, NoSuchItemException, NotReadyException { Preconditions.checkArgument(howMany > 0, "howMany must be positive"); Generation generation = getCurrentGeneration(); FastByIDMap<FastIDSet> knownItemIDs = generation.getKnownItemIDs(); if (knownItemIDs == null) { throw new UnsupportedOperationException("No known item IDs available"); } Lock knownItemLock = generation.getKnownItemLock().readLock(); FastIDSet userKnownItemIDs; knownItemLock.lock(); try { userKnownItemIDs = knownItemIDs.get(userID); } finally { knownItemLock.unlock(); } if (userKnownItemIDs == null) { throw new NoSuchUserException(userID); } FastByIDMap<float[]> Y = generation.getY(); Lock yLock = generation.getYLock().readLock(); yLock.lock(); try { float[] features = Y.get(itemID); if (features == null) { throw new NoSuchItemException(itemID); } FastByIDMap<float[]> toFeatures; synchronized (userKnownItemIDs) { toFeatures = new FastByIDMap<float[]>(userKnownItemIDs.size()); LongPrimitiveIterator it = userKnownItemIDs.iterator(); while (it.hasNext()) { long fromItemID = it.nextLong(); float[] fromFeatures = Y.get(fromItemID); toFeatures.put(fromItemID, fromFeatures); } } return TopN.selectTopN(new RecommendedBecauseIterator(toFeatures.entrySet().iterator(), generation.getUserTagIDs(), features), howMany); } finally { yLock.unlock(); } }