List of usage examples for java.util.concurrent ConcurrentMap put
V put(K key, V value);
From source file:org.marketcetera.photon.PhotonPositionMarketData.java
/** * Updates an internal cache and returns whether the value changed. *///w ww . j a va 2 s .com private boolean updateCache(final Instrument instrument, BigDecimal newValue, final ConcurrentMap<Instrument, BigDecimal> cache) { BigDecimal oldValue = cache.put(instrument, newValue == null ? NULL : newValue); if (oldValue == NULL) { oldValue = null; } // only notify if the value changed if (oldValue == null && newValue == null) { return false; } else if (oldValue != null && newValue != null && oldValue.compareTo(newValue) == 0) { return false; } return true; }
From source file:com.bt.sdk.callcontrol.sip.util.EhCacheCollectionImpl.java
protected ConcurrentMap<String, Semaphore> getSemaphores() { ConcurrentMap<String, Semaphore> result = new ConcurrentHashMap<String, Semaphore>(); for (Object key : semaphoreCache.getKeys()) { result.put((String) key, (Semaphore) cache.get(key).getObjectValue()); }/*from w ww .ja v a 2 s. c o m*/ return result; }
From source file:fi.vm.kapa.identification.proxy.utils.SessionHandlingUtils.java
public void insertIntoSessionCache(String key, AuthMethod authMethod, SessionDTO session) { Map<AuthMethod, SessionDTO> authMethodSessionDTOMap = sessionsCache.getOrDefault(key, Collections.emptyMap()); if (!authMethodSessionDTOMap.isEmpty()) { //Existing session with same authMethod is overwritten authMethodSessionDTOMap.put(authMethod, session); } else {/*from www .ja v a 2 s. c o m*/ ConcurrentMap<AuthMethod, SessionDTO> newSessionDTOMap = new ConcurrentHashMap<>(); newSessionDTOMap.put(authMethod, session); authMethodSessionDTOMap = sessionsCache.putIfAbsent(key, newSessionDTOMap); //Check and update existing entry if (authMethodSessionDTOMap != null) { authMethodSessionDTOMap.put(authMethod, session); } } }
From source file:com.bt.aloha.call.collections.CallCollectionImpl.java
public ConcurrentMap<String, CallInfo> getAllConnectedCallsWithMaxDuration() { ConcurrentMap<String, CallInfo> result = new ConcurrentHashMap<String, CallInfo>(); for (Map.Entry<String, CallInfo> entry : getAll().entrySet()) if (entry.getValue().getCallState().equals(CallState.Connected) && entry.getValue().getMaxDurationInMinutes() > 0) result.put(entry.getKey(), entry.getValue()); return result; }
From source file:com.bt.aloha.media.conference.collections.ConferenceCollectionImpl.java
public ConcurrentMap<String, ConferenceInfo> getAllActiveConferencesWithMaxDuration() { ConcurrentMap<String, ConferenceInfo> result = new ConcurrentHashMap<String, ConferenceInfo>(); for (Map.Entry<String, ConferenceInfo> entry : getAll().entrySet()) if (entry.getValue().getConferenceState().equals(ConferenceState.Active) && entry.getValue().getMaxDurationInMinutes() > 0) result.put(entry.getKey(), entry.getValue()); return result; }
From source file:com.networknt.light.rule.access.AbstractAccessRule.java
protected void updAccess(Map<String, Object> data) throws Exception { OrientGraph graph = ServiceLocator.getInstance().getGraph(); String json = null;/*from ww w. j a va2 s .co m*/ try { graph.begin(); OrientVertex access = (OrientVertex) graph.getVertexByKey("Access.ruleClass", data.get("ruleClass")); if (access != null) { access.setProperty("accessLevel", data.get("accessLevel")); List<String> clients = (List) data.get("clients"); if (clients != null && clients.size() > 0) { access.setProperty("clients", clients); } else { access.removeProperty("clients"); } List<String> roles = (List) data.get("roles"); if (roles != null && roles.size() > 0) { access.setProperty("roles", roles); } else { access.removeProperty("roles"); } List<String> users = (List) data.get("users"); if (users != null && users.size() > 0) { access.setProperty("users", users); } else { access.removeProperty("users"); } access.setProperty("updateDate", data.get("updateDate")); Vertex updateUser = graph.getVertexByKey("User.userId", data.get("updateUserId")); updateUser.addEdge("Update", access); } graph.commit(); json = access.getRecord().toJSON(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } Map<String, Object> accessMap = ServiceLocator.getInstance().getMemoryImage("accessMap"); ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>) accessMap.get("cache"); if (cache == null) { cache = new ConcurrentLinkedHashMap.Builder<Object, Object>().maximumWeightedCapacity(1000).build(); accessMap.put("cache", cache); } cache.put(data.get("ruleClass"), mapper.readValue(json, new TypeReference<HashMap<String, Object>>() { })); }
From source file:com.engine.QuoteServletData.java
/** * * @param id - zTblOpp4.ID/*from w w w.j av a2s . co m*/ */ public QuoteServletData(String id) { items = new ArrayList<>(); java.sql.Connection con = null; java.sql.PreparedStatement stmt = null; java.sql.ResultSet rs = null; try { con = ControlPanelPool.getInstance().getConnection(); /* stmt = con.prepareStatement("SELECT * FROM zTblOpp4 WHERE z3ID = ?"); stmt.setString(1, id); rs = stmt.executeQuery(); originZip = ""; country = ""; while (rs.next()) { originZip = rs.getString("ZIP"); country = rs.getString("COUNTRY"); } productClass = ""; */ System.out.println("tblOppMngr4.z4ID = " + id); String z3Id = ""; String z1Id = ""; stmt = con.prepareStatement("SELECT * FROM tblOppMngr4 WHERE z4ID = ?"); stmt.setString(1, id); rs = stmt.executeQuery(); while (rs.next()) { z3Id = rs.getString("z3ID"); z1Id = rs.getString("z1ID"); originZip = rs.getString("SFZIP"); } stmt = con.prepareStatement("SELECT * FROM tblOppMngr1 WHERE z1ID = ?"); stmt.setString(1, z1Id); rs = stmt.executeQuery(); while (rs.next()) { destinationZip = rs.getString("STZIP"); } //https://www.zipcodeapi.com/rest/NGaSQLHFvsGMP1rbcB7RJbb67rX5JAqxgAq6m7LSAsEpt5BFGIxqUIw29u7S4xqk/distance.json/10801/08854/mile //get the warehouse and compare the zip codes and find out which one is the closest and use that //for generating the quote that is crossdock //while the regular quote should be generated as well //the warehouse should also be checked to be able to handle the hazmat material if the matrial is hazmat //when it is a crossdock the notify prior to delivery fee should be added //if it is a direct order do not notify prior to delivery stmt = con.prepareStatement("SELECT * FROM tblOppMngr3 WHERE z1ID = ?"); stmt.setString(1, z1Id); rs = stmt.executeQuery(); while (rs.next()) { if (rs.getString("HZMT") != null && !rs.getString("HZMT").isEmpty()) { if (rs.getString("HZMT").startsWith("Haz")) { productClass = "85"; } if (rs.getString("HZMT").startsWith("Non")) { productClass = "65"; } } else { productClass = "65"; } productUm = rs.getString("UNITMEASURE") == null ? "LB" : rs.getString("UNITMEASURE"); productWeight = (rs.getDouble("QUANT") == 0 ? 1 : rs.getDouble("QUANT")) * (rs.getDouble("MEASURE") == 0 ? 1 : rs.getDouble("MEASURE")); Item it = new Item(rs.getString("ID"), productClass, String.valueOf(productWeight)); items.add(it); } stmt = con.prepareStatement("SELECT * FROM tblUMMultiplier WHERE UM = ?"); stmt.setString(1, productUm); rs = stmt.executeQuery(); while (rs.next()) { productWeight = productWeight * rs.getFloat("LBmultplier"); } stmt = con.prepareStatement("SELECT * FROM tblWarehouse WHERE Active = 1"); ConcurrentMap<String, String> warehouseZip = new ConcurrentHashMap<>(); rs = stmt.executeQuery(); while (rs.next()) { if (rs.getString("WHZIP") != null) { warehouseZip.put(rs.getString("WHZIP"), ""); } } for (String key : warehouseZip.keySet()) { if (key.matches("[0-9]+")) { URL url = new URL("http://10.1.1.58:8080/zip/distance?zip1=" + originZip + "&zip2=" + key); URLConnection conn = url.openConnection(); BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); String inputLine; while ((inputLine = br.readLine()) != null) { warehouseZip.put(key, inputLine.substring(1, inputLine.length() - 1)); } br.close(); } } double min = 10000.0; for (String key : warehouseZip.keySet()) { if (!warehouseZip.get(key).isEmpty() && warehouseZip.get(key) != null) { if (Double.valueOf(warehouseZip.get(key)) < min) { min = Double.valueOf(warehouseZip.get(key)); whZip = key; } } } con.close(); } catch (IOException | SQLException | PropertyVetoException ex) { Logger.getLogger(QuoteServletData.class.getName()).log(Level.SEVERE, null, ex); } finally { DbUtils.closeQuietly(con, stmt, rs); } }
From source file:alluxio.job.move.MoveDefinition.java
/** * {@inheritDoc}//from w w w .ja va 2s . co m * * Assigns each worker to move whichever files it has the most blocks for. If no worker has blocks * for a file, a random worker is chosen. */ @Override public Map<WorkerInfo, ArrayList<MoveCommand>> selectExecutors(MoveConfig config, List<WorkerInfo> jobWorkerInfoList, JobMasterContext jobMasterContext) throws Exception { AlluxioURI source = new AlluxioURI(config.getSource()); AlluxioURI destination = new AlluxioURI(config.getDestination()); if (source.equals(destination)) { return new HashMap<WorkerInfo, ArrayList<MoveCommand>>(); } checkMoveValid(config); List<BlockWorkerInfo> alluxioWorkerInfoList = AlluxioBlockStore.create(mFileSystemContext).getAllWorkers(); Preconditions.checkState(!jobWorkerInfoList.isEmpty(), "No workers are available"); List<URIStatus> allPathStatuses = getPathStatuses(source); ConcurrentMap<WorkerInfo, ArrayList<MoveCommand>> assignments = Maps.newConcurrentMap(); ConcurrentMap<String, WorkerInfo> hostnameToWorker = Maps.newConcurrentMap(); for (WorkerInfo workerInfo : jobWorkerInfoList) { hostnameToWorker.put(workerInfo.getAddress().getHost(), workerInfo); } List<String> keys = new ArrayList<>(); keys.addAll(hostnameToWorker.keySet()); // Assign each file to the worker with the most block locality. for (URIStatus status : allPathStatuses) { if (status.isFolder()) { moveDirectory(status.getPath(), source.getPath(), destination.getPath()); } else { WorkerInfo bestJobWorker = getBestJobWorker(status, alluxioWorkerInfoList, jobWorkerInfoList, hostnameToWorker); String destinationPath = computeTargetPath(status.getPath(), source.getPath(), destination.getPath()); assignments.putIfAbsent(bestJobWorker, Lists.<MoveCommand>newArrayList()); assignments.get(bestJobWorker).add(new MoveCommand(status.getPath(), destinationPath)); } } return assignments; }
From source file:org.apache.jsieve.ConfigurationManager.java
private ConcurrentMap<String, String> loadConfiguration(final String name) throws IOException { final Properties properties = loadProperties(name); final ConcurrentMap<String, String> result = new ConcurrentHashMap<String, String>(properties.size(), 1.0f, initialConcurrencyLevel);//from w w w.j a v a2 s . co m for (final Map.Entry<Object, Object> entry : properties.entrySet()) { result.put(entry.getKey().toString(), entry.getValue().toString()); } return result; }
From source file:com.bt.aloha.dao.ConferenceInfoDaoImpl.java
@SuppressWarnings("unchecked") private ConcurrentMap<String, ConferenceInfo> getSelectedConferences(String sql) { ConcurrentMap<String, ConferenceInfo> result = new ConcurrentHashMap<String, ConferenceInfo>(); List records = getJdbcTemplate().query(sql, new ConferenceInfoRowMapper()); for (int i = 0; i < records.size(); i++) { ConferenceInfo conferenceInfo = (ConferenceInfo) records.get(i); result.put(conferenceInfo.getId(), conferenceInfo); }//w w w. j av a 2s . co m return result; }