List of usage examples for java.util.concurrent ConcurrentHashMap ConcurrentHashMap
public ConcurrentHashMap()
From source file:com.clustercontrol.maintenance.view.action.MaintenanceEnableAction.java
@Override public Object execute(ExecutionEvent event) throws ExecutionException { // ???//from w ww . ja v a 2 s.c o m this.viewPart = HandlerUtil.getActivePart(event); MaintenanceListView view = null; try { view = (MaintenanceListView) this.viewPart.getAdapter(MaintenanceListView.class); } catch (Exception e) { m_log.info("execute " + e.getMessage()); return null; } if (view == null) { m_log.info("execute: view is null"); return null; } MaintenanceListComposite composite = (MaintenanceListComposite) view.getListComposite(); StructuredSelection selection = (StructuredSelection) composite.getTableViewer().getSelection(); Object[] objs = selection.toArray(); // 1???????? if (objs.length == 0) { MessageDialog.openConfirm(null, Messages.getString("confirmed"), Messages.getString("message.maintenance.9")); return null; } // 1?????? String[] args; StringBuffer targetList = new StringBuffer(); StringBuffer successList = new StringBuffer(); StringBuffer failureList = new StringBuffer(); Map<String, List<String>> map = new ConcurrentHashMap<String, List<String>>(); for (Object o : objs) { if (targetList.length() != 0) { targetList.append(", "); } String managerName = (String) ((ArrayList<?>) o).get(GetMaintenanceListTableDefine.MANAGER_NAME); if (map.get(managerName) == null) { map.put(managerName, new ArrayList<String>()); } } for (Object o : objs) { if (targetList.length() != 0) { targetList.append(", "); } String managerName = (String) ((ArrayList<?>) o).get(GetMaintenanceListTableDefine.MANAGER_NAME); String maintenanceId = (String) ((ArrayList<?>) o).get(GetMaintenanceListTableDefine.MAINTENANCE_ID); targetList.append(maintenanceId); map.get(managerName).add(maintenanceId); } // ?(NG) args = new String[] { targetList.toString() }; if (!MessageDialog.openConfirm(null, Messages.getString("confirmed"), Messages.getString("message.maintenance.14", args))) { return null; } boolean hasRole = true; // for (Map.Entry<String, List<String>> entry : map.entrySet()) { String managerName = entry.getKey(); MaintenanceEndpointWrapper wrapper = MaintenanceEndpointWrapper.getWrapper(managerName); for (String maintenanceId : entry.getValue()) { try { wrapper.setMaintenanceStatus(maintenanceId, true); successList.append(maintenanceId + "(" + managerName + ")" + "\n"); } catch (InvalidRole_Exception e) { failureList.append(maintenanceId + "\n"); m_log.warn("run() setMaintenanceStatus maintenanceId=" + maintenanceId + ", " + e.getMessage(), e); hasRole = false; } catch (Exception e) { failureList.append(maintenanceId + "\n"); m_log.warn("run() setMaintenanceStatus maintenanceId=" + maintenanceId + ", " + e.getMessage(), e); } } } if (!hasRole) { // ???????? MessageDialog.openInformation(null, Messages.getString("message"), Messages.getString("message.accesscontrol.16")); } // ? if (successList.length() != 0) { args = new String[] { successList.toString() }; MessageDialog.openInformation(null, Messages.getString("successful"), Messages.getString("message.maintenance.18", args)); } // if (failureList.length() != 0) { args = new String[] { failureList.toString() }; MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.maintenance.19", args)); } // ? composite.update(); return null; }
From source file:com.clustercontrol.maintenance.view.action.MaintenanceDisableAction.java
@Override public Object execute(ExecutionEvent event) throws ExecutionException { // ???//ww w . ja va2 s . co m this.viewPart = HandlerUtil.getActivePart(event); MaintenanceListView view = null; try { view = (MaintenanceListView) this.viewPart.getAdapter(MaintenanceListView.class); } catch (Exception e) { m_log.info("execute " + e.getMessage()); return null; } if (view == null) { m_log.info("execute: view is null"); return null; } MaintenanceListComposite composite = (MaintenanceListComposite) view.getListComposite(); StructuredSelection selection = (StructuredSelection) composite.getTableViewer().getSelection(); Object[] objs = selection.toArray(); // 1???????? if (objs.length == 0) { MessageDialog.openConfirm(null, Messages.getString("confirmed"), Messages.getString("message.maintenance.9")); return null; } // 1?????? String[] args; StringBuffer targetList = new StringBuffer(); StringBuffer successList = new StringBuffer(); StringBuffer failureList = new StringBuffer(); Map<String, List<String>> map = new ConcurrentHashMap<String, List<String>>(); for (Object o : objs) { if (targetList.length() != 0) { targetList.append(", "); } String managerName = (String) ((ArrayList<?>) o).get(GetMaintenanceListTableDefine.MANAGER_NAME); if (map.get(managerName) == null) { map.put(managerName, new ArrayList<String>()); } } for (Object o : objs) { if (targetList.length() != 0) { targetList.append(", "); } String managerName = (String) ((ArrayList<?>) o).get(GetMaintenanceListTableDefine.MANAGER_NAME); String maintenanceId = (String) ((ArrayList<?>) o).get(GetMaintenanceListTableDefine.MAINTENANCE_ID); targetList.append(maintenanceId); map.get(managerName).add(maintenanceId); } // ?(NG) args = new String[] { targetList.toString() }; if (!MessageDialog.openConfirm(null, Messages.getString("confirmed"), Messages.getString("message.maintenance.15", args))) { return null; } boolean hasRole = true; // for (Map.Entry<String, List<String>> entry : map.entrySet()) { String managerName = entry.getKey(); MaintenanceEndpointWrapper wrapper = MaintenanceEndpointWrapper.getWrapper(managerName); for (String maintenanceId : entry.getValue()) { try { wrapper.setMaintenanceStatus(maintenanceId, false); successList.append(maintenanceId + "(" + managerName + ")" + "\n"); } catch (InvalidRole_Exception e) { failureList.append(maintenanceId + "\n"); m_log.warn("run() setNotifyStatus targetId=" + maintenanceId + ", " + e.getMessage(), e); hasRole = false; } catch (Exception e) { failureList.append(maintenanceId + "\n"); m_log.warn("run() setMaintenanceStatus maintenanceId=" + maintenanceId + ", " + e.getMessage(), e); } } } if (!hasRole) { // ???????? MessageDialog.openInformation(null, Messages.getString("message"), Messages.getString("message.accesscontrol.16")); } // ? if (successList.length() != 0) { args = new String[] { successList.toString() }; MessageDialog.openInformation(null, Messages.getString("successful"), Messages.getString("message.maintenance.20", args)); } // if (failureList.length() != 0) { args = new String[] { failureList.toString() }; MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.maintenance.21", args)); } // ? composite.update(); return null; }
From source file:be.solidx.hot.test.TestScriptExecutors.java
@SuppressWarnings("rawtypes") private Collection<Long> multiThreadedTest(final Script script, final int max, final ScriptExecutor scriptExecutor) throws InterruptedException { final int iterations = 100; ExecutorService executor = Executors.newFixedThreadPool(8); final ConcurrentHashMap<String, Long> results = new ConcurrentHashMap<String, Long>(); final ConcurrentHashMap<String, Long> avgs = new ConcurrentHashMap<String, Long>(); long benchStart = System.currentTimeMillis(); for (int i = 0; i < iterations; i++) { Runnable runnable = new Runnable() { @SuppressWarnings("unchecked") @Override/*from w ww . j a v a 2s . c o m*/ public void run() { try { long res = 0; Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("i", new Integer(max)); parameters.put("n", new Integer(0)); //long starting = System.currentTimeMillis(); Object object = scriptExecutor.execute(script, parameters); if (object instanceof Bindings) { Bindings bindings = (Bindings) object; res = (Integer) bindings.get("result"); bindings.clear(); } else if (object instanceof Double) { res = Math.round((Double) object); } else if (object instanceof Long) { res = (long) object; } else res = new Long((Integer) object); long end = System.currentTimeMillis() - avgs.get(this.toString()); results.put(UUID.randomUUID().getLeastSignificantBits() + "", res); avgs.put(this.toString(), end); } catch (Exception e) { e.printStackTrace(); } } }; avgs.put(runnable.toString(), System.currentTimeMillis()); executor.submit(runnable); } while (results.size() < iterations) { Thread.sleep(50); } //Thread.sleep(20000); double sum = 0; for (Long value : avgs.values()) { sum += value; } System.out.println((sum / (double) iterations) + ""); System.out.println("==== Time needed for all requests: " + (System.currentTimeMillis() - benchStart)); results.remove("avg"); executor = null; return results.values(); }
From source file:com.orange.cepheus.broker.persistence.SubscriptionsRepository.java
/** * Get all subscriptions saved/* w w w . j a v a 2s . c o m*/ * @return subscriptions map * @throws SubscriptionPersistenceException */ public Map<String, Subscription> getAllSubscriptions() throws SubscriptionPersistenceException { Map<String, Subscription> subscriptions = new ConcurrentHashMap<>(); try { List<Subscription> subscriptionList = jdbcTemplate.query( "select id, expirationDate, subscribeContext from t_subscriptions", (ResultSet rs, int rowNum) -> { Subscription subscription = new Subscription(); try { subscription.setSubscriptionId(rs.getString("id")); subscription.setExpirationDate(Instant.parse(rs.getString("expirationDate"))); subscription.setSubscribeContext( mapper.readValue(rs.getString("subscribeContext"), SubscribeContext.class)); } catch (IOException e) { throw new SQLException(e); } return subscription; }); subscriptionList .forEach(subscription -> subscriptions.put(subscription.getSubscriptionId(), subscription)); } catch (DataAccessException e) { throw new SubscriptionPersistenceException(e); } return subscriptions; }
From source file:com.taobao.metamorphosis.storm.spout.MetaSpout.java
@Override public void open(final Map conf, final TopologyContext context, final SpoutOutputCollector collector) { final String topic = (String) conf.get(TOPIC); if (topic == null) { throw new IllegalArgumentException(TOPIC + " is null"); }//from www .jav a 2 s . c o m Integer maxSize = (Integer) conf.get(FETCH_MAX_SIZE); if (maxSize == null) { log.warn("Using default FETCH_MAX_SIZE"); maxSize = DEFAULT_MAX_SIZE; } this.id2wrapperMap = new ConcurrentHashMap<Long, MetaMessageWrapper>(); this.messageQueue = new LinkedTransferQueue<MetaMessageWrapper>(); try { this.collector = collector; this.setUpMeta(topic, maxSize); } catch (final MetaClientException e) { log.error("Setup meta consumer failed", e); } }
From source file:com.b5m.banx.counter.MetaSpout.java
public void open(final Map conf, final TopologyContext context, final SpoutOutputCollector collector) { final String topic = (String) conf.get(TOPIC); if (topic == null) { throw new IllegalArgumentException(TOPIC + " is null"); }//ww w.java 2s. c o m Integer maxSize = (Integer) conf.get(FETCH_MAX_SIZE); if (maxSize == null) { log.warn("Using default FETCH_MAX_SIZE"); maxSize = DEFAULT_MAX_SIZE; } this.id2wrapperMap = new ConcurrentHashMap<Long, MetaMessageWrapper>(); this.messageQueue = new LinkedTransferQueue<MetaMessageWrapper>(); try { this.collector = collector; this.setUpMeta(topic, maxSize); } catch (final MetaClientException e) { log.error("Setup meta consumer failed", e); } }
From source file:com.clustercontrol.hub.view.action.LogFormatDeleteAction.java
/** * Handler execution//from w ww .ja va 2 s . c o m */ @Override public Object execute(final ExecutionEvent event) throws ExecutionException { this.window = HandlerUtil.getActiveWorkbenchWindow(event); // In case this action has been disposed if (null == this.window || !isEnabled()) { return null; } this.viewPart = HandlerUtil.getActivePart(event); // []?????ID? LogFormatView view = (LogFormatView) this.viewPart.getAdapter(LogFormatView.class); if (view == null) { m_log.info("execute: view is null"); return null; } Map<String, List<String>> map = view.getSelectedItem(); String[] args = new String[1]; String msg = null; String endMsg = null; int i = 0; int deleteSize = 0; String formatId = null; for (Map.Entry<String, List<String>> entry : map.entrySet()) { for (String id : entry.getValue()) { formatId = id; deleteSize++; } } if (deleteSize > 0) { // ??????????? if (deleteSize == 1) { msg = "message.hub.log.format.delete.single"; endMsg = "message.hub.log.format.delete.single.finish"; args[0] = formatId; } else { msg = "message.hub.log.format.delete.multi"; endMsg = "message.hub.log.format.delete.multi.finish"; args[0] = String.valueOf(deleteSize); } Map<String, String> errorMsgs = new ConcurrentHashMap<>(); StringBuffer messageArg = new StringBuffer(); i = 0; if (MessageDialog.openConfirm(null, Messages.getString("confirmed"), Messages.getString(msg, args))) { for (Map.Entry<String, List<String>> entry : map.entrySet()) { String managerName = entry.getKey(); HubEndpointWrapper wrapper = HubEndpointWrapper.getWrapper(managerName); if (i > 0) { messageArg.append(", "); } messageArg.append(managerName); try { wrapper.deleteLogFormat(entry.getValue()); } catch (Exception e) { if (e instanceof InvalidRole_Exception) { // ??? errorMsgs.put(managerName, Messages.getString("message.accesscontrol.16")); } else if (e instanceof LogFormatUsed_Exception) { errorMsgs.put(managerName, HinemosMessage.replace(e.getMessage())); } else { errorMsgs.put(managerName, Messages.getString("message.hub.log.format.delete.failed") + ", " + e.getMessage()); } } i++; } // if (0 < errorMsgs.size()) { UIManager.showMessageBox(errorMsgs, true); } else { // ?? MessageDialog.openInformation(null, Messages.getString("successful"), Messages.getString(endMsg, args)); } // view.update(); } } return null; }
From source file:com.bzcentre.dapiPush.DapiReceiver.java
public DapiReceiver() { try {/*from www . ja v a 2s.c o m*/ fcmProxy = FcmProxy.prepareClient(); dbconn = connectMySql(); stmt = dbconn.createStatement(); BLKCheck = dbconn.createStatement(); serverSentEventSubscribers = Collections.newSetFromMap(new ConcurrentHashMap<>()); NginxClojureRT.getAppEventListenerManager().addListener(this); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException e1) { NginxClojureRT.log.info(TAG + "Database connecting failed..." + e1.getMessage()); } catch (CertificateException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.ibasco.agql.protocols.valve.source.query.client.SourceRconClient.java
/** * Some games (e.g. Minecraft) do not support terminator packets, if this is the case and you get an * error after sending a command, try to disable this feature by setting the <code>sendTerminatingPacket</code> flag * to <code>false</code>.// www .j ava2s. c o m * * @param sendTerminatingPacket * Set to <code>true</code> to send terminator packets for every command. */ public SourceRconClient(boolean sendTerminatingPacket) { super(new SourceRconMessenger(sendTerminatingPacket)); credentialsMap = new ConcurrentHashMap<>(); }
From source file:ai.grakn.client.LoaderClient.java
public LoaderClient(String keyspace, String uri, Consumer<Json> onCompletionOfTask) { this.uri = uri; this.keyspace = keyspace; this.queries = new HashSet<>(); this.futures = new ConcurrentHashMap<>(); this.onCompletionOfTask = onCompletionOfTask; this.batchNumber = new AtomicInteger(0); setBatchSize(25);//from w ww .j a v a2 s. c om setNumberActiveTasks(25); }