Example usage for java.util.concurrent ConcurrentHashMap ConcurrentHashMap

List of usage examples for java.util.concurrent ConcurrentHashMap ConcurrentHashMap

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentHashMap ConcurrentHashMap.

Prototype

public ConcurrentHashMap() 

Source Link

Document

Creates a new, empty map with the default initial table size (16).

Usage

From source file:com.uber.tchannel.ping.PingClient.java

public void run() throws Exception {
    TChannel tchannel = new TChannel.Builder("ping-client").build();
    SubChannel subChannel = tchannel.makeSubChannel("ping-server");
    final ConcurrentHashMap<String, Integer> msgs = new ConcurrentHashMap<String, Integer>();
    final CountDownLatch done = new CountDownLatch(requests);

    for (int i = 0; i < requests; i++) {
        JsonRequest<Ping> request = new JsonRequest.Builder<Ping>("ping-server", "ping")
                .setBody(new Ping("{'key': 'ping?'}")).setHeader("some", "header").setTimeout(100 + i).build();
        TFuture<JsonResponse<Pong>> f = subChannel.send(request, InetAddress.getByName(host), port);

        f.addCallback(new TFutureCallback<JsonResponse<Pong>>() {
            @Override/*w  w w  .j av a2  s.com*/
            public void onResponse(JsonResponse<Pong> pongResponse) {
                done.countDown();
                String msg = pongResponse.toString();
                if (msgs.containsKey(msg)) {
                    msgs.put(msg, msgs.get(msg) + 1);
                } else {
                    msgs.put(msg, 1);
                }
            }
        });
    }

    done.await();
    for (String msg : msgs.keySet()) {
        System.out.println(String.format("%s\n\tcount:%d", msg, msgs.get(msg)));
    }

    tchannel.shutdown(false);
}

From source file:com.clustercontrol.maintenance.view.action.MaintenanceDeleteAction.java

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // ???// w w w .j  ava 2s. 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();

    List<?> list = (List<?>) selection.toList();

    Map<String, List<String>> map = new ConcurrentHashMap<String, List<String>>();
    for (Object obj : list) {
        List<?> objList = (List<?>) obj;
        String managerName = (String) objList.get(GetMaintenanceListTableDefine.MANAGER_NAME);
        if (map.get(managerName) == null) {
            map.put(managerName, new ArrayList<String>());
        }
    }

    StringBuffer maintenanceId = new StringBuffer();
    for (Object obj : list) {
        List<?> objList = (List<?>) obj;
        String managerName = (String) objList.get(GetMaintenanceListTableDefine.MANAGER_NAME);
        String id = (String) objList.get(GetMaintenanceListTableDefine.MAINTENANCE_ID);
        map.get(managerName).add(id);
        if (maintenanceId.length() > 0) {
            maintenanceId.append(", ");
        }
        maintenanceId.append(id + "(" + managerName + ")");
    }

    // ?????????
    if (map.isEmpty()) {
        MessageDialog.openWarning(null, Messages.getString("warning"),
                Messages.getString("message.maintenance.9"));
        return null;
    }

    String[] args = { maintenanceId.toString() };

    if (MessageDialog.openConfirm(null, Messages.getString("confirmed"),
            Messages.getString("message.maintenance.7", args)) == false) {

        return null;
    }

    Map<String, String> errorMsgs = new ConcurrentHashMap<>();
    for (Map.Entry<String, List<String>> entry : map.entrySet()) {
        String managerName = entry.getKey();
        MaintenanceEndpointWrapper wrapper = MaintenanceEndpointWrapper.getWrapper(managerName);
        for (String val : entry.getValue()) {
            try {
                wrapper.deleteMaintenance(val);
            } catch (InvalidRole_Exception e) {
                errorMsgs.put(managerName, Messages.getString("message.accesscontrol.16"));
            } catch (Exception e) {
                m_log.warn("run(), " + e.getMessage(), e);
                errorMsgs.put(managerName, Messages.getString("message.hinemos.failure.unexpected")
                        + HinemosMessage.replace(e.getMessage()));
            }
        }
    }

    //
    if (0 < errorMsgs.size()) {
        UIManager.showMessageBox(errorMsgs, true);
    } else {
        MessageDialog.openInformation(null, Messages.getString("successful"),
                Messages.getString("message.maintenance.5", args));
    }

    composite.update();
    return null;
}

From source file:de.thm.arsnova.FeedbackStorage.java

@Transactional(isolation = Isolation.READ_COMMITTED)
public void saveFeedback(final Session session, final int value, final User user) {
    if (data.get(session) == null) {
        data.put(session, new ConcurrentHashMap<User, FeedbackStorageObject>());
    }//from w ww . ja  v  a 2  s  . c o  m

    data.get(session).put(user, new FeedbackStorageObject(value, user));
}

From source file:org.apache.hadoop.gateway.GatewayPortMappingFuncTest.java

/**
 * Creates a deployment of a gateway instance that all test methods will share.  This method also creates a
 * registry of sorts for all of the services that will be used by the test methods.
 * The createTopology method is used to create the topology file that would normally be read from disk.
 * The driver.setupGateway invocation is where the creation of GATEWAY_HOME occurs.
 * <p/>/*  www . jav a 2  s .  c o  m*/
 * This would normally be done once for this suite but the failure tests start affecting each other depending
 * on the state the last 'active' url
 *
 * @throws Exception Thrown if any failure occurs.
 */
@Before
public void setup() throws Exception {
    LOG_ENTER();

    eeriePort = getAvailablePort(1240, 49151);

    ConcurrentHashMap<String, Integer> topologyPortMapping = new ConcurrentHashMap<String, Integer>();
    topologyPortMapping.put("eerie", eeriePort);

    masterServer = new MockServer("master", true);
    GatewayTestConfig config = new GatewayTestConfig();
    config.setGatewayPath("gateway");
    config.setTopologyPortMapping(topologyPortMapping);

    driver.setResourceBase(WebHdfsHaFuncTest.class);
    driver.setupLdap(0);

    driver.setupService("WEBHDFS", "http://vm.local:50070/webhdfs", "/eerie/webhdfs", USE_MOCK_SERVICES);

    driver.setupGateway(config, "eerie", createTopology("WEBHDFS"), USE_GATEWAY);

    LOG_EXIT();
}

From source file:com.honnix.jaxo.core.internal.services.PoolableCoreServiceImpl.java

public PoolableCoreServiceImpl() {
    super();//from  w  w  w .  j a v  a 2  s . com

    objectPoolMap = new HashMap<String, ObjectPool>();
    validatorObjectPoolMap = new ConcurrentHashMap<Schema, ObjectPool<Validator>>();
}

From source file:com.clustercontrol.infra.view.action.DeleteInfraManagementAction.java

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    this.window = HandlerUtil.getActiveWorkbenchWindow(event);
    // In case this action has been disposed
    if (null == this.window || !isEnabled()) {
        return null;
    }//  w  w  w  .java 2  s.c om

    // ???
    this.viewPart = HandlerUtil.getActivePart(event);
    if (!(viewPart instanceof InfraManagementView)) {
        return null;
    }

    InfraManagementView view = (InfraManagementView) viewPart;

    StructuredSelection selection = null;
    if (view.getComposite().getTableViewer().getSelection() instanceof StructuredSelection) {
        selection = (StructuredSelection) view.getComposite().getTableViewer().getSelection();
    }

    StringBuffer strManagementIds = new StringBuffer();
    String tmpManagementId = null;
    Map<String, List<String>> map = new ConcurrentHashMap<String, List<String>>();
    if (selection != null) {
        for (Object object : selection.toList()) {
            String managerName = (String) ((ArrayList<?>) object)
                    .get(GetInfraManagementTableDefine.MANAGER_NAME);
            if (map.get(managerName) == null) {
                map.put(managerName, new ArrayList<String>());
            }
        }

        for (Object object : selection.toList()) {
            String managerName = (String) ((ArrayList<?>) object)
                    .get(GetInfraManagementTableDefine.MANAGER_NAME);
            tmpManagementId = (String) ((ArrayList<?>) object).get(GetInfraManagementTableDefine.MANAGEMENT_ID);
            map.get(managerName).add(tmpManagementId);
            strManagementIds.append(tmpManagementId + ", ");

        }
        strManagementIds.setLength(strManagementIds.length() - 2);

        if (MessageDialog.openConfirm(null, Messages.getString("confirmed"),
                Messages.getString("message.infra.confirm.action",
                        new Object[] { Messages.getString("infra.management.id"), Messages.getString("delete"),
                                strManagementIds }))) {
            Map<String, String> errMsg = new ConcurrentHashMap<String, String>();
            for (Map.Entry<String, List<String>> entry : map.entrySet()) {
                String managerName = entry.getKey();
                InfraEndpointWrapper wrapper = InfraEndpointWrapper.getWrapper(managerName);
                List<String> managementIds = entry.getValue();
                try {
                    wrapper.deleteInfraManagement(managementIds);
                } catch (InvalidRole_Exception e) {
                    // ???
                    errMsg.put(managerName, Messages.getString("message.accesscontrol.16"));
                } catch (InfraManagementNotFound_Exception | HinemosUnknown_Exception
                        | InvalidUserPass_Exception | NotifyNotFound_Exception e) {
                    m_log.debug("execute() : " + e.getClass() + e.getMessage());
                    String arg = Messages.getString("message.infra.action.result",
                            new Object[] { Messages.getString("infra.management.id"),
                                    Messages.getString("delete"), Messages.getString("failed"),
                                    HinemosMessage.replace(e.getMessage()) });
                    errMsg.put(managerName, arg);
                }
            }

            if (errMsg.isEmpty()) {
                MessageDialog.openInformation(null, Messages.getString("confirmed"),
                        Messages.getString("message.infra.action.result",
                                new Object[] { Messages.getString("infra.management.id"),
                                        Messages.getString("delete"), Messages.getString("successful"),
                                        strManagementIds }));
            } else {
                UIManager.showMessageBox(errMsg, true);
            }
            view.update();
        }
    }
    return null;
}

From source file:com.zia.freshdocs.preference.CMISPreferencesManager.java

@SuppressWarnings("unchecked")
protected Map<String, CMISHost> readPreferences(Context ctx) {
    ConcurrentHashMap<String, CMISHost> prefs = new ConcurrentHashMap<String, CMISHost>();
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    String encPrefs = null;/*from   ww w  . ja  v a 2s  .  c o  m*/

    if (sharedPrefs.contains(SERVERS_KEY)) {
        encPrefs = sharedPrefs.getString(SERVERS_KEY, null);

        if (encPrefs != null) {
            byte[] repr = Base64.decodeBase64(encPrefs.getBytes());
            Object obj = SerializationUtils.deserialize(repr);

            if (obj != null) {
                prefs = (ConcurrentHashMap<String, CMISHost>) obj;
            }
        }
    }

    return prefs;
}

From source file:com.graphaware.reco.generic.stats.DefaultStatistics.java

private ConcurrentMap<String, Object> getStatistics(String task) {
    ConcurrentMap<String, Object> taskStats = stats.get(task);

    if (taskStats == null) {
        stats.putIfAbsent(task, new ConcurrentHashMap<String, Object>());
        taskStats = stats.get(task);/*from  w  ww  . ja  va  2s  .  c  om*/
    }
    return taskStats;
}

From source file:ai.susi.mind.SusiMind.java

public SusiMind(File initpath, File watchpath, File memorypath) {
    // initialize class objects
    this.initpath = initpath;
    if (this.initpath != null)
        this.initpath.mkdirs(); // a dream does not have that
    this.watchpath = watchpath;
    if (this.watchpath != null)
        this.watchpath.mkdirs(); // a dream does not have that
    this.memorypath = memorypath;
    if (this.memorypath != null)
        this.memorypath.mkdirs(); // a dream SHOULD have that
    this.skilltrigger = new ConcurrentHashMap<>();
    this.observations = new HashMap<>();
    this.reader = new SusiReader();
    this.memories = new SusiMemory(memorypath, ATTENTION_TIME);
    try {/* w w  w . j  ava2 s  . c  o  m*/
        observe();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.clustercontrol.maintenance.view.action.HinemosPropertyDeleteAction.java

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // ???//from   ww w  .ja v a2  s. c  o m
    this.viewPart = HandlerUtil.getActivePart(event);
    HinemosPropertyView view = null;
    try {
        view = (HinemosPropertyView) this.viewPart.getAdapter(HinemosPropertyView.class);
    } catch (Exception e) {
        m_log.info("execute " + e.getMessage());
        return null;
    }

    if (view == null) {
        m_log.info("execute: view is null");
        return null;
    }

    HinemosPropertyComposite composite = (HinemosPropertyComposite) view.getComposite();
    StructuredSelection selection = (StructuredSelection) composite.getTableViewer().getSelection();

    List<?> list = (List<?>) selection.toList();
    Map<String, List<String>> map = new ConcurrentHashMap<String, List<String>>();
    for (Object obj : list) {
        List<?> objList = (List<?>) obj;
        String managerName = (String) objList.get(GetHinemosPropertyTableDefine.MANAGER_NAME);
        if (map.get(managerName) == null) {
            map.put(managerName, new ArrayList<String>());
        }
    }

    int size = 0;
    StringBuilder key = new StringBuilder();
    for (Object obj : list) {
        List<?> objList = (List<?>) obj;
        String managerName = (String) objList.get(GetHinemosPropertyTableDefine.MANAGER_NAME);
        String k = (String) objList.get(GetHinemosPropertyTableDefine.KEY);
        map.get(managerName).add(k);
        if (size > 0) {
            key.append(", ");
        }
        key.append(k + "(" + managerName + ")");
        size++;
    }

    // ?????????
    if (map.isEmpty()) {
        MessageDialog.openWarning(null, Messages.getString("warning"),
                Messages.getString("message.maintenance.9"));
        return null;
    }

    String[] args = { key.toString() };

    if (MessageDialog.openConfirm(null, Messages.getString("confirmed"),
            Messages.getString("message.maintenance.7", args)) == false) {

        return null;
    }

    // ?????????
    Map<String, String> errorMsgs = new ConcurrentHashMap<>();
    for (Map.Entry<String, List<String>> entry : map.entrySet()) {
        String managerName = entry.getKey();
        HinemosPropertyEndpointWrapper wrapper = HinemosPropertyEndpointWrapper.getWrapper(managerName);
        for (String val : entry.getValue()) {
            try {
                wrapper.deleteHinemosProperty(val);
            } catch (InvalidRole_Exception e) {
                errorMsgs.put(managerName, Messages.getString("message.accesscontrol.16"));
            } catch (Exception e) {
                m_log.warn("run(), " + e.getMessage(), e);
                errorMsgs.put(managerName, Messages.getString("message.hinemos.failure.unexpected")
                        + HinemosMessage.replace(e.getMessage()));
            }
        }
    }

    //
    if (0 < errorMsgs.size()) {
        UIManager.showMessageBox(errorMsgs, true);
    } else {
        MessageDialog.openInformation(null, Messages.getString("successful"),
                Messages.getString("message.hinemos.property.6", args));
    }

    composite.update();
    return null;
}