List of usage examples for java.util.concurrent.locks Lock lock
lock
From source file:org.unitime.timetable.solver.exam.ExamSolver.java
public Collection<ExamInfo> getUnassignedExams() { Lock lock = currentSolution().getLock().readLock(); lock.lock(); try {/*from w w w . j av a2s . c o m*/ Vector<ExamInfo> ret = new Vector<ExamInfo>(); for (Exam exam : currentSolution().getModel().variables()) { ExamPlacement placement = currentSolution().getAssignment().getValue(exam); if (placement == null) ret.add(new ExamInfo(exam)); } return ret; } finally { lock.unlock(); } }
From source file:org.unitime.timetable.solver.exam.ExamSolver.java
public String unassign(ExamInfo examInfo) { Lock lock = currentSolution().getLock().writeLock(); lock.lock(); try {//from w ww.j a v a 2 s .com Exam exam = getExam(examInfo.getExamId()); if (exam == null) return "Examination " + examInfo.getExamName() + " not found."; ExamPlacement placement = currentSolution().getAssignment().getValue(exam); if (placement == null) return "Examination " + examInfo.getExamName() + " is not assigned."; Progress.getInstance(currentSolution().getModel()) .info(exam.getName() + ": " + placement.getName() + " → not assigned"); currentSolution().getAssignment().unassign(0, exam); return null; } finally { lock.unlock(); } }
From source file:org.unitime.timetable.solver.exam.ExamSolver.java
public Map<String, String> statusSolutionInfo() { if (isPassivated()) return (iBestSolutionInfoBeforePassivation == null ? iCurrentSolutionInfoBeforePassivation : iBestSolutionInfoBeforePassivation); Lock lock = currentSolution().getLock().readLock(); lock.lock(); try {// w w w . ja v a 2 s .com Map<String, String> info = super.currentSolution().getBestInfo(); try { Solution<Exam, ExamPlacement> solution = getWorkingSolution(); if (info == null || getSolutionComparator().isBetterThanBestSolution(solution)) info = solution.getModel().getInfo(solution.getAssignment()); } catch (ConcurrentModificationException e) { } return info; } finally { lock.unlock(); } }
From source file:org.unitime.timetable.solver.exam.ExamSolver.java
public ExamConflictStatisticsInfo getCbsInfo() { ConflictStatistics cbs = null;/*from w w w .j av a2 s . c o m*/ for (Extension ext : getExtensions()) { if (ext instanceof ConflictStatistics) { cbs = (ConflictStatistics) ext; break; } } if (cbs == null || cbs.getNoGoods().isEmpty()) { if (iCbsInfo != null) return iCbsInfo; return null; } ExamConflictStatisticsInfo info = new ExamConflictStatisticsInfo(); Lock lock = currentSolution().getLock().readLock(); lock.lock(); try { info.load(cbs); } finally { lock.unlock(); } return info; }
From source file:org.unitime.timetable.solver.exam.ExamSolver.java
public ExamConflictStatisticsInfo getCbsInfo(Long examId) { ConflictStatistics cbs = null;//from w w w .jav a 2 s . co m for (Extension ext : getExtensions()) { if (ext instanceof ConflictStatistics) { cbs = (ConflictStatistics) ext; break; } } if (cbs == null || cbs.getNoGoods().isEmpty()) { if (iCbsInfo != null) return iCbsInfo; return null; } ExamConflictStatisticsInfo info = new ExamConflictStatisticsInfo(); Lock lock = currentSolution().getLock().readLock(); lock.lock(); try { info.load(cbs, examId); } finally { lock.unlock(); } return info; }
From source file:org.unitime.timetable.solver.exam.ExamSolver.java
public Collection<ExamAssignmentInfo> getAssignedExamsOfRoom(Long roomId) { Lock lock = currentSolution().getLock().readLock(); lock.lock(); try {/*from w ww. j av a2 s .c om*/ ExamRoom room = null; for (ExamRoom r : ((ExamModel) currentSolution().getModel()).getRooms()) { if (r.getId() == roomId) { room = r; break; } } if (room == null) return null; Vector<ExamAssignmentInfo> ret = new Vector<ExamAssignmentInfo>(); for (ExamPeriod period : ((ExamModel) currentSolution().getModel()).getPeriods()) { for (ExamPlacement placement : room.getPlacements(currentSolution().getAssignment(), period)) { ret.add(new ExamAssignmentInfo(placement, currentSolution().getAssignment())); } } return ret; } finally { lock.unlock(); } }
From source file:org.unitime.timetable.solver.exam.ExamSolver.java
public TreeSet<ExamAssignment> getExamsOfRoom(long locationId) { Lock lock = currentSolution().getLock().readLock(); lock.lock(); try {// ww w. j av a2 s.c o m ExamModel model = (ExamModel) currentSolution().getModel(); ExamRoom room = null; for (ExamRoom r : model.getRooms()) { if (r.getId() == locationId) { room = r; break; } } if (room == null) return null; TreeSet<ExamAssignment> ret = new TreeSet(); for (ExamPeriod period : model.getPeriods()) { for (ExamPlacement placement : room.getPlacements(currentSolution().getAssignment(), period)) ret.add(new ExamAssignment(placement, currentSolution().getAssignment())); } return ret; } finally { lock.unlock(); } }
From source file:org.unitime.timetable.solver.exam.ExamSolver.java
public Collection<ExamAssignmentInfo> getAssignedExams(Long subjectAreaId) { if (subjectAreaId == null || subjectAreaId < 0) return getAssignedExams(); String sa = new SubjectAreaDAO().get(subjectAreaId).getSubjectAreaAbbreviation() + " "; Lock lock = currentSolution().getLock().readLock(); lock.lock(); try {// www. ja va2 s .c o m Vector<ExamAssignmentInfo> ret = new Vector<ExamAssignmentInfo>(); for (Exam exam : currentSolution().getModel().variables()) { boolean hasSubjectArea = false; for (Iterator<ExamOwner> f = exam.getOwners().iterator(); !hasSubjectArea && f.hasNext();) { ExamOwner ecs = (ExamOwner) f.next(); hasSubjectArea = ecs.getName().startsWith(sa); } if (hasSubjectArea) { ExamPlacement placement = currentSolution().getAssignment().getValue(exam); if (placement != null) ret.add(new ExamAssignmentInfo(placement, currentSolution().getAssignment())); } } return ret; } finally { lock.unlock(); } }
From source file:org.unitime.timetable.solver.exam.ExamSolver.java
public Collection<ExamInfo> getUnassignedExams(Long subjectAreaId) { if (subjectAreaId == null || subjectAreaId < 0) return getUnassignedExams(); String sa = new SubjectAreaDAO().get(subjectAreaId).getSubjectAreaAbbreviation() + " "; Lock lock = currentSolution().getLock().readLock(); lock.lock(); try {/*from ww w.j a va 2s . com*/ Vector<ExamInfo> ret = new Vector<ExamInfo>(); for (Exam exam : currentSolution().getModel().variables()) { boolean hasSubjectArea = false; for (Iterator<ExamOwner> f = exam.getOwners().iterator(); !hasSubjectArea && f.hasNext();) { ExamOwner ecs = f.next(); hasSubjectArea = ecs.getName().startsWith(sa); } if (hasSubjectArea) { ExamPlacement placement = currentSolution().getAssignment().getValue(exam); if (placement == null) ret.add(new ExamInfo(exam)); } } return ret; } finally { lock.unlock(); } }
From source file:net.myrrix.online.ServerRecommender.java
public void setPreference(long userID, long itemID, float value, boolean bulk) { // Record datum try {/*w w w . j a v a 2 s . co m*/ generationManager.append(userID, itemID, value, bulk); } catch (IOException ioe) { log.warn("Could not append datum; continuing", ioe); } Generation generation; try { generation = getCurrentGeneration(); } catch (NotReadyException nre) { // Corner case -- no model ready so all we can do is record (above). Don't fail the request. return; } float[] userFeatures = getFeatures(userID, generation.getX(), generation.getXLock()); boolean newItem; Lock yReadLock = generation.getYLock().readLock(); yReadLock.lock(); try { newItem = generation.getY().get(itemID) == null; } finally { yReadLock.unlock(); } if (newItem) { generation.getCandidateFilter().addItem(itemID); } float[] itemFeatures = getFeatures(itemID, generation.getY(), generation.getYLock()); updateFeatures(userFeatures, itemFeatures, value, generation); FastByIDMap<FastIDSet> knownItemIDs = generation.getKnownItemIDs(); if (knownItemIDs != null) { FastIDSet userKnownItemIDs; ReadWriteLock knownItemLock = generation.getKnownItemLock(); Lock knownItemReadLock = knownItemLock.readLock(); knownItemReadLock.lock(); try { userKnownItemIDs = knownItemIDs.get(userID); if (userKnownItemIDs == null) { userKnownItemIDs = new FastIDSet(); Lock knownItemWriteLock = knownItemLock.writeLock(); knownItemReadLock.unlock(); knownItemWriteLock.lock(); try { knownItemIDs.put(userID, userKnownItemIDs); } finally { knownItemReadLock.lock(); knownItemWriteLock.unlock(); } } } finally { knownItemReadLock.unlock(); } synchronized (userKnownItemIDs) { userKnownItemIDs.add(itemID); } } updateClusters(userID, userFeatures, generation.getUserClusters(), generation.getUserClustersLock().readLock()); updateClusters(itemID, itemFeatures, generation.getItemClusters(), generation.getItemClustersLock().readLock()); }