List of usage examples for java.util.concurrent ConcurrentMap keySet
Set<K> keySet();
From source file:playground.acmarmol.matsim2030.microcensus2010.MZPopulationUtils.java
public static void analyzeActivityTypesAndLengths(Population population) throws ExecutionException { LoadingCache<String, SummaryStatistics> activityDuration = CacheBuilder.newBuilder() .build(CacheLoader.from(new Supplier<SummaryStatistics>() { @Override//from w w w .ja v a 2 s .co m public SummaryStatistics get() { return new SummaryStatistics(); } })); for (Person p : population.getPersons().values()) { if (p.getPlans().size() == 0) continue; Plan plan = p.getPlans().get(0); List<PlanElement> planElements = plan.getPlanElements(); for (PlanElement pe : planElements) { if (!(pe instanceof Activity)) continue; Activity activity = (Activity) pe; double startTime = activity.getStartTime(); double endTime = activity.getEndTime(); SummaryStatistics typeStats = activityDuration.get(activity.getType()); if (endTime != Time.UNDEFINED_TIME) { if (startTime == Time.UNDEFINED_TIME) startTime = 0; typeStats.addValue(endTime - startTime); } } } ConcurrentMap<String, SummaryStatistics> activityDurationMap = activityDuration.asMap(); { int i = 0; final StringBuffer s = new StringBuffer(); for (final String actType : activityDurationMap.keySet()) { final SummaryStatistics stats = activityDurationMap.get(actType); s.append(String.format("<param name=\"activityType_%d\" value=\"%s\" />\n", i, actType)); s.append(String.format("<param name=\"activityPriority_%d\" value=\"1\" />\n", i)); s.append(String.format("<param name=\"activityTypicalDuration_%d\" value=\"%s\" />\n", i, Time.writeTime(stats.getMean()))); s.append("\n"); i++; } log.info("All activities:\n" + s.toString()); } }
From source file:com.engine.QuoteServletData.java
/** * * @param id - zTblOpp4.ID// ww w . j a v a 2s .c o 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:com.alibaba.dubbo.governance.service.impl.ProviderServiceImpl.java
public List<String> findServices() { List<String> ret = new ArrayList<String>(); ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY); if (providerUrls != null) ret.addAll(providerUrls.keySet()); return ret;//from www . ja v a2s. c om }
From source file:alluxio.job.move.MoveDefinition.java
/** * {@inheritDoc}/*from ww w. java2s.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:com.engine.QuoteServlet.java
private String lookupNearestWarehouse(String originZip) { String zip = ""; java.sql.Connection con = null; java.sql.PreparedStatement stmt = null; java.sql.ResultSet rs = null; try {// ww w.j a va2 s . c o m con = ControlPanelPool.getInstance().getConnection(); 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)); zip = key; } } } con.close(); } catch (IOException | SQLException | PropertyVetoException ex) { Logger.getLogger(QuoteServlet.class.getName()).log(Level.SEVERE, null, ex); } finally { DbUtils.closeQuietly(con, stmt, rs); } return zip; }
From source file:com.murati.oszk.audiobook.model.MusicProvider.java
private Collection<MediaBrowserCompat.MediaItem> createGroupList( ConcurrentMap<String, List<String>> categoryMap, String mediaIdCategory, Uri imageUri, Resources resources) {//from ww w .ja v a 2 s . c om if (mCurrentState != State.INITIALIZED) return Collections.emptyList(); TreeSet<String> sortedCategoryList = new TreeSet<String>(collator); sortedCategoryList.addAll(categoryMap.keySet()); List<MediaBrowserCompat.MediaItem> categoryList = new ArrayList<MediaBrowserCompat.MediaItem>(); for (String categoryName : sortedCategoryList) { try { MediaBrowserCompat.MediaItem browsableCategory = createGroupItem( createMediaID(null, mediaIdCategory, categoryName), categoryName, String.format(resources.getString(R.string.browse_title_count), String.valueOf(categoryMap.get(categoryName).size())), imageUri); categoryList.add(browsableCategory); } catch (Exception e) { //TODO: log } } return categoryList; }
From source file:com.cubeia.firebase.server.lobby.systemstate.StateLobby.java
public String printPaths() { SnapshotGenerator tableGenerator = generators.get(LobbyPathType.TABLES); SnapshotGenerator tournamentGenerator = generators.get(LobbyPathType.MTT); String info = "TABLE PATHS:\n"; ConcurrentMap<LobbyPath, FullSnapshot> tableSnapshots = tableGenerator.getFullSnapshots(); for (LobbyPath path : tableSnapshots.keySet()) { info += path + "\n"; }//from w ww . j a va 2 s. c om info += "\nTOURNAMENT PATHS\n"; ConcurrentMap<LobbyPath, FullSnapshot> tournamentSnapshots = tournamentGenerator.getFullSnapshots(); for (LobbyPath path : tournamentSnapshots.keySet()) { info += path + "\n"; } return info; }
From source file:com.cubeia.firebase.server.lobby.systemstate.StateLobby.java
public String printPacketCounts() { ConcurrentMap<LobbyPath, Integer> fullPacketCount = new ConcurrentHashMap<LobbyPath, Integer>(); ConcurrentMap<LobbyPath, Integer> deltaPacketCount = new ConcurrentHashMap<LobbyPath, Integer>(); for (SnapshotGenerator generator : generators.values()) { ConcurrentMap<LobbyPath, FullSnapshot> fullSnapshots = generator.getFullSnapshots(); ConcurrentMap<LobbyPath, DeltaSnapshot> deltaSnapshots = generator.getDeltaSnapshots(); for (LobbyPath path : fullSnapshots.keySet()) { FullSnapshot fullSnapshot = fullSnapshots.get(path); fullPacketCount.put(path, fullSnapshot.getLobbyData().size()); }/*from ww w .java 2s.co m*/ for (LobbyPath path : deltaSnapshots.keySet()) { DeltaSnapshot deltaSnapshot = deltaSnapshots.get(path); deltaPacketCount.put(path, deltaSnapshot.getLobbyData().size()); } } String info = "Lobby Snapshots Per Chached Lobby Path\n"; info += "-----------------------\n"; info += "Full Packet Path Count: " + fullPacketCount.size() + "\n"; info += "Delta Packet Path Count: " + deltaPacketCount.size() + "\n"; info += "-----------------------\n"; info += "FULL PACKET COUNT PER PATH\n"; for (LobbyPath path : fullPacketCount.keySet()) { info += StringUtils.rightPad(path.toString(), 60) + "\t : " + fullPacketCount.get(path) + "\n"; } info += "-----------------------\n"; info += "DELTA PACKET COUNT PER PATH\n"; for (LobbyPath path : deltaPacketCount.keySet()) { info += StringUtils.rightPad(path.toString(), 60) + "\t : " + deltaPacketCount.get(path) + "\n"; ; } return info; }
From source file:com.asakusafw.runtime.directio.hadoop.HadoopDataSourceUtil.java
private static void prepareParallel(Counter counter, FileSystem fs, Path base, List<Path> list, ExecutorService executor) throws IOException, InterruptedException { ConcurrentMap<Path, Boolean> requiredDirs = new ConcurrentHashMap<>(); parallel(executor, list.stream().map(p -> new Path(base, p)).map(file -> (Callable<?>) () -> { try {//from w ww .ja va 2s. c o m FileStatus stat = fs.getFileStatus(file); if (LOG.isDebugEnabled()) { LOG.debug(MessageFormat.format("deleting file: {0}", //$NON-NLS-1$ file)); } if (stat.isDirectory()) { fs.delete(file, true); } else { fs.delete(file, false); } counter.add(1); } catch (FileNotFoundException e) { Path parent = file.getParent(); if (fs.exists(parent) == false) { requiredDirs.put(parent, Boolean.TRUE); } } return null; }).collect(Collectors.toList())); parallel(executor, requiredDirs.keySet().stream().map(parent -> (Callable<?>) () -> { if (LOG.isDebugEnabled()) { LOG.debug(MessageFormat.format("creating directory: {0}", //$NON-NLS-1$ parent)); } fs.mkdirs(parent); counter.add(1); return null; }).collect(Collectors.toList())); }
From source file:org.opendaylight.ovsdb.plugin.impl.ConfigurationServiceImpl.java
public String getSpecialCaseParentUUID(Node node, String databaseName, String childTableName) { if (!databaseName.equals(OvsVswitchdSchemaConstants.DATABASE_NAME)) return null; String[] parentColumn = OvsVswitchdSchemaConstants.getParentColumnToMutate(childTableName); if (parentColumn != null && parentColumn[0].equals(OvsVswitchdSchemaConstants.DATABASE_NAME)) { Connection connection = connectionService.getConnection(node); OpenVSwitch openVSwitch = connection.getClient().getTypedRowWrapper(OpenVSwitch.class, null); ConcurrentMap<String, Row> row = this.getRows(node, openVSwitch.getSchema().getName()); if (row == null || row.size() == 0) return null; return (String) row.keySet().toArray()[0]; }// w w w . java 2 s.co m return null; }