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.clustercontrol.repository.view.action.ScopeDeleteAction.java

/**
 * @see org.eclipse.core.commands.IHandler#execute
 *///from   w  ww  .j  a v  a 2  s . c  o  m
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // ??????
    // ??????
    this.viewPart = HandlerUtil.getActivePart(event);
    ScopeListView scopeListView = null;
    try {
        scopeListView = (ScopeListView) this.viewPart.getAdapter(ScopeListView.class);
    } catch (Exception e) {
        m_log.info("execute " + e.getMessage());
        return null;
    }

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

    List<?> selectionList = scopeListView.getSelectedScopeItems();
    if (null == selectionList) {
        return null;
    }

    Map<String, List<String>> map = new ConcurrentHashMap<String, List<String>>();
    List<String> facilityNameList = new ArrayList<String>();

    for (Object obj : selectionList) {
        if (obj instanceof FacilityTreeItem) {
            FacilityTreeItem item = (FacilityTreeItem) obj;
            FacilityTreeItem manager = ScopePropertyUtil.getManager(item);
            String managerName = null;
            if (manager == null) {
                managerName = item.getChildren().get(0).getData().getFacilityId();
            } else {
                managerName = manager.getData().getFacilityId();
            }
            if (map.get(managerName) == null) {
                map.put(managerName, new ArrayList<String>());
            }
        }
    }

    int size = 0;
    String facilityId = null;
    for (Object obj : selectionList) {
        String managerName = null;
        if (obj instanceof FacilityTreeItem) {
            FacilityTreeItem item = (FacilityTreeItem) obj;
            // ?????????
            FacilityInfo info = item.getData();
            if (info.getFacilityType() == FacilityConstant.TYPE_COMPOSITE
                    || info.getFacilityType() == FacilityConstant.TYPE_NODE) {
                continue;
            }

            FacilityTreeItem manager = ScopePropertyUtil.getManager(item);
            if (manager == null) {
                managerName = item.getChildren().get(0).getData().getFacilityId();
            } else {
                managerName = manager.getData().getFacilityId();
            }

            facilityId = item.getData().getFacilityId();
            map.get(managerName).add(facilityId);
            facilityNameList.add(item.getData().getFacilityName());
        } else {
            List<?> sList = (List<?>) obj;
            facilityId = null;
            String facilityName = null;
            if (sList != null) {
                managerName = (String) sList.get(GetScopeListTableDefine.MANAGER_NAME);
                facilityId = (String) sList.get(GetScopeListTableDefine.FACILITY_ID);
                facilityName = (String) sList.get(GetScopeListTableDefine.FACILITY_NAME);
                facilityNameList.add(facilityName);
                map.get(managerName).add(facilityId);
            }
        }
        size++;
    }

    // ???????????
    if (map.isEmpty()) {
        return null;
    }

    // ???????????
    String msg = "";
    String[] args = new String[2];
    if (size == 1) {
        args[0] = facilityNameList.get(0);
        args[1] = facilityId;
        msg = "message.repository.3";
    } else {
        args[0] = Integer.toString(size);
        msg = "message.repository.52";
    }

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

        return null;
    }

    for (Map.Entry<String, List<String>> entry : map.entrySet()) {
        String managerName = entry.getKey();
        List<String> facilityIdList = entry.getValue();
        new DeleteScopeProperty().delete(managerName, facilityIdList);
    }

    // 
    scopeListView.update();
    return null;
}

From source file:com.clustercontrol.repository.view.action.AgentUpdateAction.java

/**
 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
 *//*w w w  .  j  a  v  a  2  s. c  o  m*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    this.viewPart = HandlerUtil.getActivePart(event);
    AgentListView view = null;
    try {
        view = (AgentListView) this.viewPart.getAdapter(AgentListView.class);
    } catch (Exception e) {
        m_log.info("execute " + e.getMessage());
        return null;
    }

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

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

    List<?> selectionList = selection.toList();
    if (selectionList.size() == 0) {
        return null;
    }
    Map<String, ArrayList<String>> map = new ConcurrentHashMap<String, ArrayList<String>>();

    for (Object o : selectionList) {
        List<?> list = (List<?>) o;
        if (list == null) {
            continue;
        }
        String managerName = (String) list.get(GetAgentListTableDefine.MANAGER_NAME);
        if (map.get(managerName) == null) {
            map.put(managerName, new ArrayList<String>());
        }
    }

    StringBuffer message = new StringBuffer();
    boolean flag = true;
    for (Object o : selectionList) {
        List<?> list = (List<?>) o;
        String managerName = null;
        String facilityId = null;
        String facilityName = null;
        if (list != null) {
            facilityId = (String) list.get(GetAgentListTableDefine.FACILITY_ID);
            // ID?????????
            if (facilityId == null) {
                return null;
            } else if ("".equals(facilityId)) {
                return null;
            }
            managerName = (String) list.get(GetAgentListTableDefine.MANAGER_NAME);
            facilityName = (String) list.get(GetAgentListTableDefine.FACILITY_NAME);
            map.get(managerName).add(facilityId);
        }

        // ?????????
        if (flag) {
            flag = false;
        } else {
            message.append(", ");
        }
        message.append(facilityName + "(" + facilityId + ")");
    }

    // ??
    String[] args = { message.toString() };
    if (!MessageDialog.openConfirm(null, Messages.getString("confirmed"),
            Messages.getString("message.repository.45", args))) {
        m_log.debug("cancel");
        return null;
    }

    Map<String, String> errorMsgs = new ConcurrentHashMap<>();
    for (Map.Entry<String, ArrayList<String>> entry : map.entrySet()) {
        String managerName = entry.getKey();
        ArrayList<String> facilityIdList = entry.getValue();
        try {
            RepositoryEndpointWrapper wrapper = RepositoryEndpointWrapper.getWrapper(managerName);
            wrapper.restartAgent(facilityIdList, AgentCommandConstant.UPDATE);
        } catch (InvalidRole_Exception e) {
            // ??????
            Object[] arg = { managerName };
            errorMsgs.put(managerName, Messages.getString("message.accesscontrol.16", arg));
        } 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);
    }

    return null;
}

From source file:com.steffi.index.ImgMapIndex.java

public void commitChanges(IndexOperation<T> operations) {

    if (operations.getNewKeyValues() != null) {
        for (IndexOperationItem opItem : operations.getNewKeyValues()) {
            IndexKeyValue indexKeyValue = new IndexKeyValue(opItem.getKey(), opItem.getValue());
            ConcurrentHashMap<Object, Boolean> curElements = getMap().get(indexKeyValue);

            if (curElements == null)
                curElements = new ConcurrentHashMap<Object, Boolean>();

            if (!opItem.getObject().getClass().equals(this.indexClass)
                    && !opItem.getObject().getClass().getSuperclass().equals(this.indexClass))
                throw new RuntimeException("Index was created for " + indexClass.getSimpleName());

            Cell cellElement = indexClass.cast(opItem.getObject());

            if (cellElement instanceof SteffiEdge) {
                SteffiEdge edge = (SteffiEdge) cellElement;

                curElements.put(new EdgeIndexEntry(edge.getSourceCellId(), edge.getId()), true);
            } else {
                curElements.put(cellElement.getId(), true);
            }/*from   w  ww . j  a  v a  2  s.  c om*/

            getMap().put(indexKeyValue, curElements);
        }
    }

    if (operations.getRemovedKeyValues() != null) {
        for (IndexOperationItem opItem : operations.getRemovedKeyValues()) {
            ConcurrentHashMap<Object, Boolean> curValues = getMap()
                    .get(new IndexKeyValue(opItem.getKey(), opItem.getValue()));

            if (curValues != null) {

                Cell cellElement = indexClass.cast(opItem.getObject());

                if (cellElement instanceof SteffiVertex) {
                    curValues.remove(cellElement.getId());
                } else {
                    SteffiEdge edge = (SteffiEdge) cellElement;
                    curValues.remove(new EdgeIndexEntry(edge.getSourceCellId(), edge.getId()));
                }

            }
        }
    }

}

From source file:com.clustercontrol.repository.view.action.AgentRestartAction.java

/**
 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
 *///  www .ja v  a  2s  .  c o  m
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    this.viewPart = HandlerUtil.getActivePart(event);
    AgentListView view = null;
    try {
        view = (AgentListView) this.viewPart.getAdapter(AgentListView.class);
    } catch (Exception e) {
        m_log.info("execute " + e.getMessage());
        return null;
    }

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

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

    List<?> selectionList = selection.toList();
    if (selectionList.size() == 0) {
        return null;
    }
    Map<String, ArrayList<String>> map = new ConcurrentHashMap<String, ArrayList<String>>();

    for (Object o : selectionList) {
        List<?> list = (List<?>) o;
        if (list == null) {
            continue;
        }
        String managerName = (String) list.get(GetAgentListTableDefine.MANAGER_NAME);
        if (map.get(managerName) == null) {
            map.put(managerName, new ArrayList<String>());
        }
    }

    StringBuffer message = new StringBuffer();
    boolean flag = true;
    for (Object o : selectionList) {
        List<?> list = (List<?>) o;
        String managerName = null;
        String facilityId = null;
        String facilityName = null;
        if (list != null) {
            managerName = (String) list.get(GetAgentListTableDefine.MANAGER_NAME);
            facilityId = (String) list.get(GetAgentListTableDefine.FACILITY_ID);
            facilityName = (String) list.get(GetAgentListTableDefine.FACILITY_NAME);
            map.get(managerName).add(facilityId);
        }

        // ID?????????
        if (facilityId == null) {
            return null;
        } else if ("".equals(facilityId)) {
            return null;
        }

        // ?????????
        if (flag) {
            flag = false;
        } else {
            message.append(", ");
        }
        message.append(facilityName + "(" + facilityId + ")");
    }

    // ??
    String[] args = { message.toString() };
    if (!MessageDialog.openConfirm(null, Messages.getString("confirmed"),
            Messages.getString("message.repository.44", args))) {
        m_log.debug("cancel");
        return null;
    }

    Map<String, String> errorMsgs = new ConcurrentHashMap<>();
    for (Map.Entry<String, ArrayList<String>> entry : map.entrySet()) {
        String managerName = entry.getKey();
        ArrayList<String> facilityIdList = entry.getValue();
        try {
            RepositoryEndpointWrapper wrapper = RepositoryEndpointWrapper.getWrapper(managerName);
            wrapper.restartAgent(facilityIdList, AgentCommandConstant.RESTART);
        } catch (InvalidRole_Exception e) {
            // ??????
            Object[] arg = { managerName };
            errorMsgs.put(managerName, Messages.getString("message.accesscontrol.16", arg));
        } 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);
    }

    return null;
}

From source file:com.taobao.diamond.server.service.GroupService.java

/**
 * //from   w ww .j  a  v a 2s . com
 */
// @PostConstruct
public void loadGroupInfo() {
    List<GroupInfo> allGroupInfo = persistService.findAllGroupInfo();
    ConcurrentHashMap<String, ConcurrentHashMap<String, GroupInfo>> tempMap = new ConcurrentHashMap<String, ConcurrentHashMap<String, GroupInfo>>();
    log.warn("...");
    if (allGroupInfo != null) {
        for (GroupInfo info : allGroupInfo) {
            String address = info.getAddress();
            String dataId = info.getDataId();
            if (tempMap.get(address) == null) {
                tempMap.put(address, new ConcurrentHashMap<String, GroupInfo>());
            }
            tempMap.get(address).put(dataId, info);
        }
    }
    this.addressGroupCache = tempMap;
    log.warn("..." + (allGroupInfo != null ? allGroupInfo.size() : 0));
}

From source file:com.neophob.sematrix.core.jmx.PixelControllerStatus.java

/**
 * Register the JMX Bean./*  w  ww.  j a va  2s. c  o  m*/
 *
 * @param configuredFps the configured fps
 */
public PixelControllerStatus(Collector col, int configuredFps) {
    LOG.log(Level.INFO, "Initialize the PixelControllerStatus JMX Bean");

    this.configuredFps = configuredFps;
    this.col = col;

    // initialize all buffers 
    this.timeMeasureMapGlobal = new ConcurrentHashMap<TimeMeasureItemGlobal, CircularFifoBuffer>();
    for (TimeMeasureItemGlobal timeMeasureItem : TimeMeasureItemGlobal.values()) {
        this.timeMeasureMapGlobal.put(timeMeasureItem, new CircularFifoBuffer(this.configuredFps * SECONDS));
    }
    this.timeMeasureMapOutput = new ConcurrentHashMap<IOutput, Map<TimeMeasureItemOutput, CircularFifoBuffer>>();
    this.outputList = new ArrayList<IOutput>();

    startTime = System.currentTimeMillis();

    // register MBean
    try {
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        ObjectName name = new ObjectName(JMX_BEAN_NAME);
        // check if the MBean is already registered
        if (!server.isRegistered(name)) {
            server.registerMBean(this, name);
        }
    } catch (JMException ex) {
        LOG.log(Level.WARNING, "Error while registering class as JMX Bean.", ex);
    }
}

From source file:nl.esciencecenter.octopus.webservice.job.OctopusManager.java

/**
 * Sets preferences in GAT context and initializes a broker.
 *
 * @param configuration/*w w  w.  ja v a2s  .com*/
 * @throws URISyntaxException
 * @throws OctopusException
 * @throws OctopusIOException
 */
public OctopusManager(OctopusConfiguration configuration)
        throws URISyntaxException, OctopusException, OctopusIOException {
    this.configuration = configuration;
    Properties props = configuration.getPreferencesAsProperties();
    octopus = OctopusFactory.newOctopus(props);
    URI schedulerURI = configuration.getScheduler();
    Credential credential = configuration.getCredential();
    // TODO prompt user for password/passphrases
    scheduler = octopus.jobs().newScheduler(schedulerURI, credential, null);
    jobs = new ConcurrentHashMap<String, SandboxedJob>();
    executor = Executors.newSingleThreadScheduledExecutor();
    PollConfiguration pollConf = configuration.getPollConfiguration();
    poller = new JobsPoller(jobs, pollConf, octopus);
}

From source file:com.clustercontrol.repository.factory.NodeProperty.java

public static void init() {
    JpaTransactionManager jtm = null;/*  www  .j  a va  2 s  .  c  o m*/
    try {
        _lock.writeLock();

        long startTime = System.currentTimeMillis();
        jtm = new JpaTransactionManager();
        jtm.getEntityManager().clear();

        ConcurrentHashMap<String, NodeInfo> cache = new ConcurrentHashMap<String, NodeInfo>();

        for (NodeInfo node : QueryUtil.getAllNode_NONE()) {
            cache.put(node.getFacilityId(), node);
        }

        storeCache(cache);

        m_log.info("init cache " + (System.currentTimeMillis() - startTime) + "ms. size=" + cache.size());
    } finally {
        if (jtm != null) {
            jtm.close();
        }
        _lock.writeUnlock();
    }
}

From source file:org.apache.hadoop.gateway.GatewayPortMappingDisableFeatureTest.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/>/*  w  w  w  .j ava2 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);
    // disable the feature
    config.setGatewayPortMappingEnabled(false);

    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.clustercontrol.calendar.view.action.CalendarPatternDeleteAction.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;
    }//  ww  w.  j  a  v a  2s  .c o m

    this.viewPart = HandlerUtil.getActivePart(event);
    // []?????ID?

    CalendarPatternView calendarPatternView = null;
    try {
        calendarPatternView = (CalendarPatternView) this.viewPart.getAdapter(CalendarPatternView.class);
    } catch (Exception e) {
        m_log.info("execute " + e.getMessage());
        return null;
    }

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

    List<ObjectBean> objList = calendarPatternView.getSelectedObjectBeans();

    String[] args = new String[1];
    String msg = null;

    if (objList == null || objList.isEmpty()) {
        return null;
    }

    Map<String, List<String>> map = new ConcurrentHashMap<String, List<String>>();
    int size = 0;
    String patternId = "";
    for (ObjectBean obj : objList) {
        String managerName = obj.getManagerName();
        if (map.get(managerName) == null) {
            map.put(managerName, new ArrayList<String>());
        }
        map.get(managerName).add(obj.getObjectId());
        patternId = obj.getObjectId();
        size++;
    }

    if (size > 0) {
        // ???????????
        if (objList.size() == 1) {
            msg = "message.calendar.49";
            args[0] = patternId;
        } else {
            msg = "message.calendar.72";
            args[0] = Integer.toString(size);
        }

        if (MessageDialog.openConfirm(null, Messages.getString("confirmed"),
                Messages.getString(msg, args)) == false) {
            return null;
        }
    }

    Map<String, String> errMsg = new ConcurrentHashMap<String, String>();
    StringBuffer messageArg = new StringBuffer();
    int i = 0;
    for (Map.Entry<String, List<String>> entry : map.entrySet()) {
        String managerName = entry.getKey();
        List<String> idList = entry.getValue();

        if (i > 0) {
            messageArg.append(", ");
        }
        messageArg.append(managerName);

        try {
            CalendarEndpointWrapper wrapper = CalendarEndpointWrapper.getWrapper(managerName);
            wrapper.deleteCalendarPattern(idList);
        } catch (Exception e) {
            if (e instanceof InvalidRole_Exception) {
                errMsg.put(managerName, Messages.getString("message.accesscontrol.16"));
            } else {
                errMsg.put(managerName, HinemosMessage.replace(e.getMessage()));
            }
        }
        i++;
    }

    if (errMsg.isEmpty()) {
        Object[] arg = { messageArg.toString() };
        // ??
        MessageDialog.openInformation(null, Messages.getString("successful"),
                Messages.getString("message.calendar.38", arg));
    } else {
        // ?
        UIManager.showMessageBox(errMsg, true);
    }

    // 
    calendarPatternView.update();
    return null;
}