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 createChildOf(SocialPerson memberPerson) { Lock lock = rwChildOfLock.writeLock(); lock.lock();//w w w . j a va 2 s . c o m try { String childOf = memberPerson.getName(); if (childOf != null) { firePlayerMemberChangeEvent(childOf, SocialNetworkCommandType.child, Type.preAdd, false); person.setChildOf(childOf); firePlayerMemberChangeEvent(childOf, SocialNetworkCommandType.child, Type.postAdd, false); } } finally { lock.unlock(); } }
From source file:com.netprogs.minecraft.plugins.social.SocialPerson.java
public <U extends IMessage> int getMessageCountFrom(String fromPlayerName, Class<U> messageClass) { Lock lock = rwMessageQueueLock.readLock(); lock.lock();//from w w w . j a v a2 s . c o m try { String className = messageClass.getCanonicalName(); if (person.getMessageQueue().containsKey(className)) { if (person.getMessageQueue().get(className).containsKey(fromPlayerName)) { return person.getMessageQueue().get(className).get(fromPlayerName).size(); } } return 0; } finally { lock.unlock(); } }
From source file:jp.aegif.nemaki.cmis.service.impl.NavigationServiceImpl.java
@Override public List<ObjectInFolderContainer> getDescendants(CallContext callContext, String repositoryId, String folderId, BigInteger depth, String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, Boolean includePathSegment, boolean foldersOnly, ExtensionsData extension, Holder<ObjectData> anscestorObjectData) { exceptionService.invalidArgumentRequiredString("folderId", folderId); Lock parentLock = threadLockService.getReadLock(repositoryId, folderId); try {/*ww w . j av a2 s .c o m*/ parentLock.lock(); // ////////////////// // General Exception // ////////////////// Folder folder = contentService.getFolder(repositoryId, folderId); exceptionService.permissionDenied(callContext, repositoryId, PermissionMapping.CAN_GET_DESCENDENTS_FOLDER, folder); // ////////////////// // Specific Exception // ////////////////// exceptionService.invalidArgumentFolderId(folder, folderId); exceptionService.invalidArgumentDepth(depth); // ////////////////// // Body of the method // ////////////////// // check depth int d = (depth == null ? 2 : depth.intValue()); // set defaults if values not set boolean iaa = (includeAllowableActions == null ? false : includeAllowableActions.booleanValue()); boolean ips = (includePathSegment == null ? false : includePathSegment.booleanValue()); // Set ObjectData of the starting folder for ObjectInfo ObjectData _folder = compileService.compileObjectData(callContext, repositoryId, folder, filter, includeAllowableActions, includeRelationships, renditionFilter, false); anscestorObjectData.setValue(_folder); // get the tree. return getDescendantsInternal(callContext, repositoryId, _folder, filter, iaa, false, includeRelationships, null, ips, 0, d, foldersOnly); } finally { parentLock.unlock(); } }
From source file:com.cloudera.oryx.als.serving.ServerRecommender.java
@Override public float[] similarityToItem(String toItemID, String... itemIDs) throws NotReadyException, NoSuchItemException { Generation generation = getCurrentGeneration(); LongObjectMap<float[]> Y = generation.getY(); float[] similarities = new float[itemIDs.length]; Lock yLock = generation.getYLock().readLock(); yLock.lock();/* ww w . ja v a 2s . c o m*/ try { float[] toFeatures = Y.get(StringLongMapping.toLong(toItemID)); if (toFeatures == null) { throw new NoSuchItemException(toItemID); } double toFeaturesNorm = SimpleVectorMath.norm(toFeatures); boolean anyFound = false; for (int i = 0; i < similarities.length; i++) { float[] features = Y.get(StringLongMapping.toLong(itemIDs[i])); if (features == null) { similarities[i] = Float.NaN; } else { anyFound = true; double featuresNorm = SimpleVectorMath.norm(features); similarities[i] = (float) (SimpleVectorMath.dot(features, toFeatures) / (featuresNorm * toFeaturesNorm)); } } if (!anyFound) { throw new NoSuchItemException(Arrays.toString(itemIDs)); } } finally { yLock.unlock(); } return similarities; }
From source file:com.thoughtworks.studios.journey.JourneyService.java
/** * API for run migrations under the namespace * * @param ns namespace name//from www . j ava 2 s. c om * @return 200 response */ @POST @Produces(MediaType.TEXT_PLAIN) @Path("/{ns}/migrate") public Response migrate(@PathParam("ns") String ns) { Lock writingLock = getWritingLock(ns); writingLock.lock(); try { Application app = new Application(graphDB, ns); ArrayList<Long> ids = new ArrayList<>(); try (Transaction ignored = graphDB.beginTx()) { ResourceIterator<Node> nodes = graphDB.findNodes(app.journeys().getLabel()); while (nodes.hasNext()) { Node node = nodes.next(); ids.add(node.getId()); } } try (BatchTransaction tx = new BatchTransaction(graphDB, 5000)) { for (Long id : ids) { Node journey = graphDB.getNodeById(id); if (!journey.hasProperty(Journeys.PROP_LENGTH)) { Integer length = journey.getDegree(RelTypes.BELONGS_TO, Direction.INCOMING); journey.setProperty(Journeys.PROP_LENGTH, length); Index<Node> index = GraphDbUtils.legacyIndex(graphDB, app.journeys().getLabel()); index.add(journey, Journeys.PROP_LENGTH, new ValueContext(length).indexNumeric()); } tx.increment(); } } } finally { writingLock.unlock(); } return Response.status(Response.Status.OK).build(); }
From source file:com.netprogs.minecraft.plugins.social.SocialPerson.java
public void createDivorce(SocialPerson memberPerson) { Lock lock = rwDivorceLock.writeLock(); lock.lock();/*from w w w .j ava2 s .c om*/ try { String memberName = memberPerson.getName(); firePlayerMemberChangeEvent(memberName, SocialNetworkCommandType.divorce, Type.preAdd, false); Divorce divorce = new Divorce(memberName); socialDivorce = new SocialDivorce(divorce); person.setDivorce(divorce); firePlayerMemberChangeEvent(memberName, SocialNetworkCommandType.divorce, Type.postAdd, false); } finally { lock.unlock(); } }
From source file:org.apache.nifi.cluster.coordination.http.replication.ThreadPoolRequestReplicator.java
@Override public AsyncClusterResponse replicate(Set<NodeIdentifier> nodeIds, String method, URI uri, Object entity, Map<String, String> headers, final boolean indicateReplicated, final boolean performVerification) { final Map<String, String> updatedHeaders = new HashMap<>(headers); updatedHeaders.put(RequestReplicator.CLUSTER_ID_GENERATION_SEED_HEADER, ComponentIdGenerator.generateId().toString()); if (indicateReplicated) { updatedHeaders.put(RequestReplicator.REPLICATION_INDICATOR_HEADER, "true"); }/*ww w.ja va 2s.c om*/ // include the proxied entities header updateRequestHeaders(updatedHeaders); if (indicateReplicated) { // If we are replicating a request and indicating that it is replicated, then this means that we are // performing an action, rather than simply proxying the request to the cluster coordinator. In this case, // we need to ensure that we use proper locking. We don't want two requests modifying the flow at the same // time, so we use a write lock if the request is mutable and a read lock otherwise. final Lock lock = isMutableRequest(method, uri.getPath()) ? writeLock : readLock; logger.debug("Obtaining lock {} in order to replicate request {} {}", lock, method, uri); lock.lock(); try { logger.debug("Lock {} obtained in order to replicate request {} {}", lock, method, uri); // Unlocking of the lock is performed within the replicate method, as we need to ensure that it is unlocked only after // the entire request has completed. final Object monitor = new Object(); synchronized (monitor) { final AsyncClusterResponse response = replicate(nodeIds, method, uri, entity, updatedHeaders, performVerification, null, !performVerification, true, monitor); try { monitor.wait(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } return response; } } finally { lock.unlock(); logger.debug("Unlocked {} after replication completed for {} {}", lock, method, uri); } } else { return replicate(nodeIds, method, uri, entity, updatedHeaders, performVerification, null, !performVerification, true, null); } }
From source file:com.netprogs.minecraft.plugins.social.SocialPerson.java
public void createMarriage(SocialPerson memberPerson) { Lock lock = rwMarriageLock.writeLock(); lock.lock();//from w w w . ja v a 2s . c o m try { String memberName = memberPerson.getName(); firePlayerMemberChangeEvent(memberName, SocialNetworkCommandType.marriage, Type.preAdd, false); Marriage marriage = new Marriage(memberName); socialMarriage = new SocialMarriage(marriage); person.setMarriage(marriage); firePlayerMemberChangeEvent(memberName, SocialNetworkCommandType.marriage, Type.postAdd, false); } finally { lock.unlock(); } }
From source file:com.netprogs.minecraft.plugins.social.SocialPerson.java
public void addFriend(SocialPerson memberPerson) { Lock lock = rwFriendLock.writeLock(); lock.lock();// ww w .j a va2s.co m try { String memberName = memberPerson.getName(); firePlayerMemberChangeEvent(memberName, SocialNetworkCommandType.friend, Type.preAdd, false); Friend friend = new Friend(memberName); person.getFriends().put(memberName, friend); friends.put(memberName, new SocialFriend(friend)); firePlayerMemberChangeEvent(memberName, SocialNetworkCommandType.friend, Type.postAdd, false); } finally { lock.unlock(); } }
From source file:com.netprogs.minecraft.plugins.social.SocialPerson.java
public void addAffair(SocialPerson memberPerson) { Lock lock = rwAffairLock.writeLock(); lock.lock();/*w w w .j av a 2s . c o m*/ try { String memberName = memberPerson.getName(); firePlayerMemberChangeEvent(memberName, SocialNetworkCommandType.affair, Type.preAdd, false); Affair affair = new Affair(memberName); person.getAffairs().put(memberName, affair); affairs.put(memberName, new SocialAffair(affair)); firePlayerMemberChangeEvent(memberName, SocialNetworkCommandType.affair, Type.postAdd, false); } finally { lock.unlock(); } }