Example usage for java.util.concurrent ConcurrentHashMap put

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

Introduction

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

Prototype

public V put(K key, V value) 

Source Link

Document

Maps the specified key to the specified value in this table.

Usage

From source file:org.apache.hadoop.hbase.regionserver.ccindex.IndexedRegion.java

private synchronized HTable getIndexTable(IndexSpecification index) throws IOException {
    ConcurrentHashMap<IndexSpecification, HTable> tMap = this.getTableMap();
    HTable indexTable = tMap.get(index);
    if (indexTable == null) {
        indexTable = new HTable(conf,
                index.getIndexedTableName(super.getRegionInfo().getTableDesc().getName()));
        tMap.put(index, indexTable);

    }//ww w  . j a v  a  2s.c  o m
    indexTable.setWriteBufferSize(1000 * 1000 * 100);
    return indexTable;
}

From source file:ru.runa.wfe.user.cache.ExecutorCacheImpl.java

@Override
public <T extends Executor> void addAllExecutor(VersionedCacheData<List<T>> oldCachedData, Class<?> clazz,
        BatchPresentation batch, List<T> executors) {
    if (!mayUpdateVersionnedData(oldCachedData)) {
        return;// w w  w.  j  a  v a 2  s. c  om
    }
    synchronized (this) {
        ConcurrentHashMap<BatchPresentationFieldEquals, List<Executor>> map = batchAllExecutors.get(clazz);
        if (map == null) {
            map = new ConcurrentHashMap<BatchPresentationFieldEquals, List<Executor>>();
        }
        List<Executor> result = new ArrayList<Executor>();
        for (Executor executor : executors) {
            result.add(executor);
        }
        map.put(new BatchPresentationFieldEquals(batch), result);
        batchAllExecutors.put(clazz, map);
    }
}

From source file:org.seedstack.mqtt.internal.MqttModuleTest.java

/**
 * Test method for//  w  ww  . ja v  a2s .c  o  m
 * {@link org.seedstack.mqtt.internal.MqttModule#configure()}.
 * 
 * @throws Exception
 *             if an error occurred
 */
@Test
public void testConfigureWithPublisher(@Mocked final Binder binder,
        @Mocked final MqttClientUtils mqttClientUtils) throws Exception {
    ConcurrentHashMap<String, MqttClientDefinition> mqttClientDefinitions = new ConcurrentHashMap<String, MqttClientDefinition>();
    ConcurrentHashMap<String, IMqttClient> mqttClients = new ConcurrentHashMap<String, IMqttClient>();
    final String uri = "uri";
    final String clientId = "id";
    final String clientName = "name";
    MqttClientDefinition clientDefinition = new MqttClientDefinition(uri, clientId);
    final MqttPublisherDefinition publisherDefinition = new MqttPublisherDefinition(PublishHandler.class,
            PublishHandler.class.getCanonicalName());
    clientDefinition.setPublisherDefinition(publisherDefinition);
    mqttClientDefinitions.put(clientName, clientDefinition);

    mqttClients.put(clientName, mqttClient);
    MqttModule module = new MqttModule(mqttClients, mqttClientDefinitions);

    module.configure(binder);

    new Verifications() {
        {
            binder.bind(IMqttClient.class).annotatedWith(Names.named(clientName)).toInstance(mqttClient);

            binder.bind(MqttCallback.class).annotatedWith(Names.named(PublishHandler.class.getCanonicalName()))
                    .to(PublishHandler.class);

        }
    };
}

From source file:org.apache.hadoop.hbase.regionserver.ccindex.IndexedRegion.java

private synchronized HTable getCCTTable(IndexSpecification index) throws IOException {
    ConcurrentHashMap<IndexSpecification, HTable> tMap = this.getCCTMap();
    HTable indexTable = tMap.get(index);
    if (indexTable == null) {
        indexTable = new HTable(conf,
                Bytes.add(index.getIndexedTableName(super.getRegionInfo().getTableDesc().getName()),
                        CCIndexAdmin.CCT_TAIL));
        tMap.put(index, indexTable);

    }//from ww  w  .  ja v  a2 s. com
    indexTable.setWriteBufferSize(1000 * 1000 * 100);
    return indexTable;
}

From source file:com.taobao.tddl.jdbc.atom.jdbc.TDataSourceWrapper.java

@Override
public ConcurrentHashMap<String, Values> getValues() {
    ConcurrentHashMap<String, Values> concurrentHashMap = new ConcurrentHashMap<String, Values>();
    String prefix = connectionProperties.datasourceName + "_";

    // threadCount
    Values threadCountValues = new Values();
    threadCountValues.value1.set(threadCount.longValue());
    threadCountValues.value2.set(connectionProperties.threadCountRestriction);
    concurrentHashMap.put(prefix + Key.THREAD_COUNT, threadCountValues);

    ///* w  w w.  ja  va 2  s. c o  m*/
    Values rejectCountValues = new Values();
    rejectCountValues.value1.set(readTimesReject.longValue() + this.readFlowControl.getTotalRejectCount());
    rejectCountValues.value2.set(writeTimesReject.longValue() + this.writeFlowControl.getTotalRejectCount());
    concurrentHashMap.put(prefix + Key.READ_WRITE_TIMES_REJECT_COUNT, rejectCountValues);

    // count
    Values lastReadWriteSnapshot = new Values();
    lastReadWriteSnapshot.value1.set(this.readFlowControl.getCurrentCount());
    lastReadWriteSnapshot.value2.set(this.writeFlowControl.getCurrentCount());
    concurrentHashMap.put(prefix + Key.READ_WRITE_TIMES, lastReadWriteSnapshot);

    //
    Values rwConcurrent = new Values();
    rwConcurrent.value1.set(this.concurrentReadCount.longValue());
    rwConcurrent.value2.set(this.concurrentWriteCount.longValue());
    concurrentHashMap.put(prefix + Key.READ_WRITE_CONCURRENT, rwConcurrent);

    return concurrentHashMap;
}

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 w w.j a va  2 s. c  o m*/

            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.viettel.hqmc.DAO.FeeDao.java

public String onInsertFeePaymentInfoIpn(String paymentInfo, String filescode, String hash,
        String feeInfoIdStr) {/*from   w ww.  ja va 2s . c  om*/
    try {
        FeeDAOHE rdhe = new FeeDAOHE();
        // hieptq update 030615 hash lai noi dung so voi sercure hash keypay gui lai
        String[] parts = hash.split(";");
        ConcurrentHashMap<String, String> fields = new ConcurrentHashMap<String, String>();
        fields.put("command", parts[0]);
        fields.put("merchant_trans_id", parts[1]);
        fields.put("merchant_code", parts[2]);
        fields.put("response_code", parts[3]);
        fields.put("trans_id", parts[4]);
        fields.put("good_code", parts[5]);
        fields.put("net_cost", parts[6]);
        fields.put("ship_fee", parts[7]);
        fields.put("tax", parts[8]);
        fields.put("service_code", parts[9]);
        fields.put("currency_code", parts[10]);
        if (parts[11] != null && parts[11].trim().length() > 0) {
            fields.put("bank_code", parts[11]);
        }

        HashFunction hf = new HashFunction();
        ResourceBundle rb = ResourceBundle.getBundle("config");
        //            String url_redirect = rb.getString("online_keypay");
        String transKey = rb.getString("transkey");
        String secure_hash = hf.hashAllFields(fields, transKey);
        boolean check = true;
        if (secure_hash.equals(parts[17])) {
            Long userId = getUserId();
            String[] lstfeeInfoId = feeInfoIdStr.split(",");
            int countObj = lstfeeInfoId.length;
            Long feeInfoId;
            for (int i = 0; i < countObj; i++) {
                feeInfoId = Long.parseLong(lstfeeInfoId[i]);
                boolean bReturn = rdhe.insertFeePaymentInfo(feeInfoId, userId, paymentInfo, filescode);
                // gui den cuc attp -> doi trang thai
                FeePaymentInfoDAOHE fdhe1 = new FeePaymentInfoDAOHE();
                FilesDAOHE fdhe = new FilesDAOHE();
                FeePaymentInfo finew = fdhe1.findById(feeInfoId);
                Fee f = (Fee) rdhe.findById(Fee.class, "feeId", finew.getFeeId());
                FeePaymentInfo fi = (FeePaymentInfo) fdhe1.findById(FeePaymentInfo.class, "fileId",
                        finew.getFileId());
                Files file = fdhe.findById(fi.getFileId());
                if (file.getStatus().equals(Constants.FILE_STATUS.NEW_CREATE)
                        || file.getStatus().equals(Constants.FILE_STATUS.NEW)) {//binhnt53 update 150215
                    if (f.getFeeType().equals(Constants.FEE_TYPE.PHI_THAM_DINH)) {//binhnt53 update 150215
                        DepartmentDAOHE dphe = new DepartmentDAOHE();
                        Department dep = dphe.findByDeptCode("ATTP");
                        BusinessDAOHE bus = new BusinessDAOHE();
                        Business bus1 = bus.findById(file.getDeptId());//4
                        bReturn = fdhe.assignFileToDept(fi.getFileId(), dep.getDeptId(), file.getUserCreateId(),
                                file.getUserCreateName(), bus1.getBusinessId(), bus1.getBusinessName());
                    }
                }
                check = bReturn;
                if (check == false) {
                    break;
                }
            }
        } else {
            EventLogDAOHE edhe = new EventLogDAOHE();
            edhe.insertEventLog("KEYPAY", "ERR null data", getRequest());
            check = false;
        }

        if (check) {
            EventLogDAOHE edhe = new EventLogDAOHE();
            edhe.insertEventLog("Cp nht thanh ton thnh cng qua IPN ", "ph c id=" + feeInfoIdStr,
                    getRequest());
        } else {
            EventLogDAOHE edhe = new EventLogDAOHE();
            edhe.insertEventLog("Cp nht thanh ton khng thnh cng qua IPN ",
                    "ph c id=" + feeInfoIdStr, getRequest());
        }
    } catch (Exception ex) {
        EventLogDAOHE edhe = new EventLogDAOHE();
        edhe.insertEventLog("KEYPAY ERROR: ", "ERROR:" + ex.getMessage(), getRequest());
        LogUtil.addLog(ex);//binhnt sonar a160901
    }
    return GRID_DATA;
}

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/*from  w ww  . j  a va2  s.  c o m*/
            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.viettel.hqmc.DAO.FeeDao.java

/**
 * update thong tin thanh toan//w  w  w.  ja v a 2  s. c o  m
 *
 * @return
 */
public String onInsertFeePaymentInfo() {
    FeeDao fdao = new FeeDao();
    FeeDAOHE rdhe = new FeeDAOHE();
    String paymentInfo = getRequest().getParameter("paymentInfo");
    String filescode = (getRequest().getParameter("filescode") == null ? "0"
            : getRequest().getParameter("filescode"));
    String hash = getRequest().getParameter("hash");

    // hieptq update 030615 hash lai noi dung so voi sercure hash keypay gui lai
    String[] parts = hash.split(";");
    ConcurrentHashMap<String, String> fields = new ConcurrentHashMap<String, String>();
    fields.put("command", parts[0]);
    fields.put("merchant_trans_id", parts[1]);
    fields.put("merchant_code", parts[2]);
    fields.put("response_code", parts[3]);
    fields.put("trans_id", parts[4]);
    fields.put("good_code", parts[5]);
    fields.put("net_cost", parts[6]);
    fields.put("ship_fee", parts[7]);
    fields.put("tax", parts[8]);
    fields.put("service_code", parts[9]);
    fields.put("currency_code", parts[10]);
    if (parts[11] != null && parts[11].trim().length() > 0) {
        fields.put("bank_code", parts[11]);
    }
    String secure_hash;
    int countObj = 0;
    String[] lstfeeInfoIdNew = null;
    HashFunction hf = new HashFunction();
    ResourceBundle rb = ResourceBundle.getBundle("config");
    //        String url_redirect = rb.getString("online_keypay");
    String transKey = rb.getString("transkey");
    secure_hash = hf.hashAllFields(fields, transKey);
    boolean check = true;
    String feeInfoIdNew = getRequest().getParameter("feeInfoId");
    // hieptq update check trang thai thanh toan truoc khi chuyen luong
    if (fdao.checkPaymentStatus(feeInfoIdNew) == true) {
        if (secure_hash.equals(parts[17])) {
            Long userId = getUserId();
            lstfeeInfoIdNew = feeInfoIdNew.split(",");
            countObj = lstfeeInfoIdNew.length;
            Long feeInfoId;
            for (int i = 0; i < countObj; i++) {
                feeInfoId = Long.parseLong(lstfeeInfoIdNew[i]);
                boolean bReturn = rdhe.insertFeePaymentInfo(feeInfoId, userId, paymentInfo, filescode);
                // gui den cuc attp -> doi trang thai
                FeePaymentInfoDAOHE fdhe1 = new FeePaymentInfoDAOHE();
                FilesDAOHE fdhe = new FilesDAOHE();
                FeePaymentInfo finew = fdhe1.findById(feeInfoId);
                Fee f = (Fee) rdhe.findById(Fee.class, "feeId", finew.getFeeId());
                FeePaymentInfo fi = (FeePaymentInfo) fdhe1.findById(FeePaymentInfo.class, "fileId",
                        finew.getFileId());
                Files file = fdhe.findById(fi.getFileId());
                if (file.getStatus().equals(Constants.FILE_STATUS.NEW_CREATE)
                        || file.getStatus().equals(Constants.FILE_STATUS.NEW)) {//binhnt53 update 150215
                    if (f.getFeeType().equals(Constants.FEE_TYPE.PHI_THAM_DINH)) {//binhnt53 update 150215
                        DepartmentDAOHE dphe = new DepartmentDAOHE();
                        Department dep = dphe.findByDeptCode("ATTP");
                        BusinessDAOHE bus = new BusinessDAOHE();
                        Business bus1 = bus.findById(file.getDeptId());//4
                        bReturn = fdhe.assignFileToDept(fi.getFileId(), dep.getDeptId(), file.getUserCreateId(),
                                file.getUserCreateName(), bus1.getBusinessId(), bus1.getBusinessName());
                    }
                }
                check = bReturn;
                if (check == false) {
                    break;
                }
            }
        } else {
            check = false;
        }
    } else {
        check = false;
    }
    // hieptq update 021015
    try {
        for (int i = 0; i < countObj; i++) {
            this.onSavePaymentOnlineIPN(lstfeeInfoIdNew[i]);
        }
    } catch (Exception ex) {
        LogUtil.addLog(ex);//binhnt sonar a160901
        check = false;
    }
    List resultMessage = new ArrayList();
    if (check) {
        resultMessage.add("1");
        resultMessage.add("Lu d liu thnh cng");
    } else {
        resultMessage.add("3");
        resultMessage.add("Lu d liu khng thnh cng");
    }
    jsonDataGrid.setItems(resultMessage);
    return GRID_DATA;
}

From source file:org.sindice.siren.index.Utils.java

/**
 * Flatten a list of triples to n-tuples containing many objects for the same
 * predicate. Generate one n-tuple per predicate.
 * /*  w  w w.j  ava2  s .co  m*/
 * @param values
 *          The list of n-triples.
 * @return The n-tuples concatenated.
 */
private static synchronized void flattenNTriples(final StringBuilder triples,
        final ConcurrentHashMap<String, ConcurrentSkipListSet<String>> map,
        final ConcurrentSkipListSet<String> types, final ConcurrentSkipListSet<String> label,
        final ConcurrentSkipListSet<String> description, final boolean isOut) {
    try {
        initParser();
        parser.parse(new StringReader(triples.toString()), "");
        for (Statement st : collector.getStatements()) {
            sb.setLength(0);
            final String subject = sb.append('<').append(st.getSubject().toString()).append('>').toString();
            sb.setLength(0);
            final String predicate = sb.append('<').append(st.getPredicate().toString()).append('>').toString();
            sb.setLength(0);
            final String object = (st.getObject() instanceof URI)
                    ? sb.append('<').append(st.getObject().toString()).append('>').toString()
                    : st.getObject().toString();
            if (label != null && predicate.equals(RDFS_LABEL))
                label.add(object);
            if (description != null && predicate.equals(DC_DESCRIPTION))
                description.add(object);
            if (description != null && predicate.equals(DBP_ABSTRACT))
                description.add(object);
            if (types != null && predicate.equals(RDF_TYPE)) {
                types.add(object);
            } else {
                ConcurrentSkipListSet<String> hs = map.get(predicate);
                final String toAdd = isOut ? object : subject;
                if (hs == null) {
                    hs = new ConcurrentSkipListSet<String>();
                    map.put(predicate, hs);
                }
                if (hs.size() < 65535) // 2 ^ 16 - 1
                    hs.add(toAdd);
            }
        }
    } catch (RDFParseException e1) {
    } catch (RDFHandlerException e1) {
    } catch (IOException e1) {
    }
    triples.setLength(0);
}