List of usage examples for java.util Collections synchronizedList
public static <T> List<T> synchronizedList(List<T> list)
From source file:org.syncope.core.persistence.dao.impl.UserSearchDAOImpl.java
@Override public boolean matches(final SyncopeUser user, final NodeCond searchCondition) { List<Object> parameters = Collections.synchronizedList(new ArrayList<Object>()); // 1. get the query string from the search condition StringBuilder queryString = getQuery(searchCondition, parameters); // 2. take into account the passed user queryString.insert(0, "SELECT u.user_id FROM ("); queryString.append(") u WHERE user_id=?").append(setParameter(parameters, user.getId())); // 3. prepare the search query Query query = entityManager.createNativeQuery(queryString.toString()); // 4. populate the search query with parameter values fillWithParameters(query, parameters); // 5. executes query List<SyncopeUser> result = query.getResultList(); return !result.isEmpty(); }
From source file:op.care.values.PnlValues.java
private void initPanel() { cpMap = Collections.synchronizedMap(new HashMap<String, CollapsiblePane>()); linemap = Collections.synchronizedMap(new HashMap<ResValue, JPanel>()); mapType2Values = Collections.synchronizedMap(new HashMap<String, ArrayList<ResValue>>()); // mapCollapsed = Collections.synchronizedMap(new HashMap<String, Boolean>()); // balances = Collections.synchronizedMap(new HashMap<LocalDate, Pair<BigDecimal, BigDecimal>>()); EntityManager em = OPDE.createEM();//ww w .j a v a 2s . c o m Query query = em.createQuery("SELECT t FROM ResValueTypes t WHERE t.valType != :valtype ORDER BY t.text"); query.setParameter("valtype", ResValueTypesTools.LIQUIDBALANCE); lstValueTypes = Collections.synchronizedList(new ArrayList<ResValueTypes>(query.getResultList())); // lstValueTypes.remove(LIQUIDBALANCE); em.close(); // color1 = SYSConst.blue1; // color2 = SYSConst.greyscale; }
From source file:com.launchkey.example.springmvc.AuthManager.java
public void handleCallback(Map<String, String> callbackData) throws AuthException { try {/* ww w. ja v a 2s . c o m*/ CallbackResponse callbackResponse = authService.handleCallback(callbackData, 300); if (callbackResponse instanceof AuthResponseCallbackResponse) { AuthResponse authResponse = ((AuthResponseCallbackResponse) callbackResponse).getAuthResponse(); String authRequestId = authResponse.getAuthRequestId(); String sessionId = null; for (Map.Entry<String, String> entry : sessionAuthRequestMap.entrySet()) { if (entry.getValue().equals(authRequestId)) { sessionId = entry.getKey(); break; } } if (null == sessionId) { throw new AuthException("No session found for auth request: " + authRequestId); } sessionAuthenticationMap.put(sessionId, authResponse.isAuthorized()); List<String> sessionList = userHashSessionMap.get(authResponse.getUserHash()); if (null == sessionList) { // If no session list exists for the user hash, create one in the map sessionList = Collections.synchronizedList(new ArrayList<String>()); userHashSessionMap.put(authResponse.getUserHash(), sessionList); } // If the session does not already exist in the session list add it if (!sessionList.contains(sessionId)) { sessionList.add(sessionId); } } else if (callbackResponse instanceof DeOrbitCallbackResponse) { String userHash = ((DeOrbitCallbackResponse) callbackResponse).getUserHash(); for (String sessionId : userHashSessionMap.get(userHash)) { logout(sessionId); } userHashSessionMap.remove(userHash); } } catch (LaunchKeyException launchKeyException) { throw new AuthException("Error handling callback", launchKeyException); } }
From source file:org.eclipse.amp.amf.testing.ide.TestRunSet.java
public void runTests(final IProgressMonitor monitor, final MultiStatus status) { this.monitor = monitor; this.status = status; monitor.beginTask("Executing Escape Tests: " + name, uniqueTests.size()); initialize();// w ww . java 2 s . c om monitor.subTask("Preparing Tests"); testsWaiting = Collections.synchronizedList(new ArrayList<Resource>()); for (IResource resource : uniqueTests) { IPath modelPath = ((IFile) resource).getFullPath(); URI aTestURI = URI.createPlatformResourceURI(modelPath.toString(), true); Resource atestResource = resourceSet.getResource(aTestURI, true); Model testmodel = (Model) atestResource.getContents().get(0); if (testmodel.getContains().size() == 0) { for (int i = 0; i < runsPerTest; i++) { testsWaiting.add(atestResource); } } else { for (TestMember member : testmodel.getContains()) { Resource emfResource = resourceSet .getResource(URI.createURI(ATestInterpreter.convertURI(member)), true); for (int i = 0; i < runsPerTest; i++) { testsWaiting.add(emfResource); } } } } // Release the unique tests so that the underlying resources can be gc'd when individual tests are removed. uniqueTests = null; testRunCount = testsWaiting.size(); testCompleteCount = 0; testSuccessCount = 0; fillThreads(); while (testCompleteCount < testRunCount && !monitor.isCanceled()) { try { Thread.sleep(100); } catch (InterruptedException e) { } } if (!monitor.isCanceled()) { if (testSuccessCount == testRunCount) { runSet.setResult(ResultType.SUCCESS); } else { runSet.setResult(ResultType.FAILURE); } saveResults(); } monitor.done(); }
From source file:com.medlog.webservice.vo.PatientVO.java
/** * @param healthcareProviderList the healthcareProviderList to set *///www . j a va2s . co m public void setHealthcareProviderList(List<HealthcareProviderVO> healthcareProviderList) { this.healthcareProviderList = Collections.synchronizedList(healthcareProviderList); }
From source file:op.care.reports.PnlReport.java
private void initPanel() { contentmap = Collections.synchronizedMap(new HashMap<String, JPanel>()); cpMap = Collections.synchronizedMap(new HashMap<String, CollapsiblePane>()); valuecache = Collections.synchronizedMap(new HashMap<String, ArrayList<NReport>>()); linemap = Collections.synchronizedMap(new HashMap<NReport, JPanel>()); holidays = new HashMap<LocalDate, String>(); listUsedCommontags = Collections.synchronizedList(new ArrayList<Commontags>()); // prepareSearchArea(); }
From source file:biz.c24.io.spring.batch.reader.C24ItemReaderParallelTests.java
private Collection<ComplexDataObject> readFile(C24Model model, String optionalElementStartRegEx, String optionalElementStopRegEx, boolean validate, SplittingReaderSource source, SourceFactory factory) throws IOException, UnexpectedInputException, ParseException, NonTransientResourceException, ValidationException {// w ww . j a va 2s. c o m C24ItemReader<ComplexDataObject> reader = new C24ItemReader<ComplexDataObject>(); reader.setModel(model); if (optionalElementStartRegEx != null) { reader.setElementStartPattern(optionalElementStartRegEx); } if (optionalElementStopRegEx != null) { reader.setElementStopPattern(optionalElementStopRegEx); } if (factory != null) { reader.setSourceFactory(factory); } reader.setSource(source); reader.setValidate(validate); StepExecution stepExecution = getStepExecution(); reader.setup(stepExecution); Collection<ComplexDataObject> objs = Collections.synchronizedList(new LinkedList<ComplexDataObject>()); Thread[] threads = new Thread[8]; for (int i = 0; i < threads.length; i++) { threads[i] = new Thread(new Worker<ComplexDataObject>(model, objs, reader)); threads[i].start(); } for (int i = 0; i < threads.length; i++) { try { threads[i].join(20000); } catch (InterruptedException e) { throw new RuntimeException("Interrupted waiting on thread"); } if (threads[i].isAlive()) { throw new RuntimeException("Timed out waiting for thread to complete its work"); } } reader.cleanup(); return objs; }
From source file:at.ac.tuwien.dsg.quelle.elasticityQuantification.engines.CloudServiceElasticityAnalysisEngine.java
public List<AnalysisResult> analyzeElasticity(CloudProvider cloudProvider) { final List<AnalysisResult> analysisResults = Collections.synchronizedList(new ArrayList<AnalysisResult>()); List<Thread> threads = new ArrayList<Thread>(); for (final CloudOfferedService unit : cloudProvider.getCloudOfferedServices()) { if (!unit.getCategory().equals("IaaS")) { continue; }/* w ww . ja v a 2 s . c o m*/ Thread t = new Thread() { @Override public void run() { analysisResults.add(analyzeElasticity(unit)); } }; threads.add(t); t.start(); } for (Thread t : threads) { try { t.join(); } catch (InterruptedException ex) { Logger.getLogger(CloudServiceElasticityAnalysisEngine.class.getName()).log(Level.SEVERE, null, ex); } } Collections.sort(analysisResults, new Comparator<AnalysisResult>() { @Override public int compare(AnalysisResult o1, AnalysisResult o2) { return ((Double) o1.getValue(OVERALL_ELASTICITY)) .compareTo(((Double) o2.getValue(OVERALL_ELASTICITY))); } }); return analysisResults; }
From source file:voldemort.store.routed.ThreadPoolRoutedStore.java
@Override public boolean delete(final ByteArray key, final Version version) throws VoldemortException { StoreUtils.assertValidKey(key);/*from w ww . ja v a 2 s .c om*/ final List<Node> nodes = availableNodes(routingStrategy.routeRequest(key.get())); // quickly fail if there aren't enough live nodes to meet the // requirements final int numNodes = nodes.size(); if (numNodes < this.storeDef.getRequiredWrites()) throw new InsufficientOperationalNodesException("Only " + numNodes + " nodes in preference list, but " + this.storeDef.getRequiredWrites() + " writes required."); // A count of the number of successful operations final AtomicInteger successes = new AtomicInteger(0); final AtomicBoolean deletedSomething = new AtomicBoolean(false); // A list of thrown exceptions, indicating the number of failures final List<Exception> failures = Collections.synchronizedList(new LinkedList<Exception>()); // A semaphore indicating the number of completed operations // Once inititialized all permits are acquired, after that // permits are released when an operation is completed. // semaphore.acquire(n) waits for n operations to complete final Semaphore semaphore = new Semaphore(0, false); // Add the operations to the pool for (final Node node : nodes) { this.executor.execute(new Runnable() { @Override public void run() { long startNs = System.nanoTime(); try { boolean deleted = innerStores.get(node.getId()).delete(key, version); successes.incrementAndGet(); deletedSomething.compareAndSet(false, deleted); recordSuccess(node, startNs); } catch (UnreachableStoreException e) { failures.add(e); recordException(node, startNs, e); } catch (VoldemortApplicationException e) { throw e; } catch (Exception e) { failures.add(e); logger.warn("Error in DELETE on node " + node.getId() + "(" + node.getHost() + ")", e); } finally { // signal that the operation is complete semaphore.release(); } } }); } int attempts = Math.min(storeDef.getPreferredWrites(), numNodes); if (this.storeDef.getPreferredWrites() <= 0) { return true; } else { for (int i = 0; i < numNodes; i++) { try { long timeoutMs = timeoutConfig.getOperationTimeout(VoldemortOpCode.DELETE_OP_CODE); boolean acquired = semaphore.tryAcquire(timeoutMs, TimeUnit.MILLISECONDS); if (!acquired) logger.warn("Delete operation timed out waiting for operation " + i + " to complete after waiting " + timeoutMs + " ms."); // okay, at least the required number of operations have // completed, were they successful? if (successes.get() >= attempts) return deletedSomething.get(); } catch (InterruptedException e) { throw new InsufficientOperationalNodesException("Delete operation interrupted!", e); } } } // If we get to here, that means we couldn't hit the preferred number // of writes, throw an exception if you can't even hit the required // number if (successes.get() < storeDef.getRequiredWrites()) throw new InsufficientOperationalNodesException( this.storeDef.getRequiredWrites() + " deletes required, but " + successes.get() + " succeeded.", failures); else return deletedSomething.get(); }
From source file:com.adobe.acs.commons.mcp.impl.processes.asset.AssetIngestor.java
private synchronized EnumMap<ReportColumns, Object> trackActivity(String item, String action, String description, Long bytes) { if (reportRows == null) { reportRows = Collections.synchronizedList(new ArrayList<>()); }// ww w . j ava 2s.c o m EnumMap<ReportColumns, Object> reportRow = new EnumMap<>(ReportColumns.class); reportRow.put(ReportColumns.item, item); reportRow.put(ReportColumns.action, action); reportRow.put(ReportColumns.description, description); reportRow.put(ReportColumns.count, 0L); reportRow.put(ReportColumns.bytes, bytes); reportRows.add(reportRow); return reportRow; }