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:gaffer.gafferpop.GafferPopGraph.java

private GafferPopGraphVariables createVariables() {
    final ConcurrentHashMap<String, Object> variablesMap = new ConcurrentHashMap<>();
    variablesMap.put(GafferPopGraphVariables.OP_OPTIONS, Collections.unmodifiableMap(opOptions));
    variablesMap.put(GafferPopGraphVariables.SCHEMA, graph.getSchema());
    return new GafferPopGraphVariables(variablesMap);
}

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

public void loadJSONFile() throws Exception {
    String fn = Constants.MAP_FILE;
    String content = this.diskService.readFile(fn);
    ConcurrentHashMap<String, ConcurrentHashMap<String, GroupInfo>> map = new ConcurrentHashMap<String, ConcurrentHashMap<String, GroupInfo>>();
    @SuppressWarnings("unchecked")
    Map<String, Map<String, String>> map2 = (Map<String, Map<String, String>>) JSONUtils
            .deserializeObject(content, HashMap.class);
    for (String key : map2.keySet()) {
        Map<String, String> map3 = map2.get(key);
        if (map != null) {
            ConcurrentHashMap<String, GroupInfo> cMap = new ConcurrentHashMap<String, GroupInfo>();
            for (Entry<String, String> e : map3.entrySet()) {
                GroupInfo gInfo = new GroupInfo();
                gInfo.setGroup(e.getValue());
                gInfo.setDataId(e.getKey());
                gInfo.setAddress(key);//from ww  w  . j  a va  2 s .c om
                cMap.put(e.getKey(), gInfo);
            }
            map.put(key, cMap);
        }
    }
    this.addressGroupCache = map;
}

From source file:uk.gov.gchq.gaffer.gafferpop.GafferPopGraph.java

private GafferPopGraphVariables createVariables() {
    final ConcurrentHashMap<String, Object> variablesMap = new ConcurrentHashMap<>();
    variablesMap.put(GafferPopGraphVariables.OP_OPTIONS, Collections.unmodifiableMap(opOptions));
    variablesMap.put(GafferPopGraphVariables.USER, user);
    variablesMap.put(GafferPopGraphVariables.SCHEMA, graph.getSchema());
    return new GafferPopGraphVariables(variablesMap);
}

From source file:org.wso2.carbon.mediator.kerberos.KerberosMediator.java

/**
 * Set the authorization header to the message context.
 *
 * @param synCtx        message context.
 * @param serviceTicket Kerberos ticket.
 * @throws UnsupportedEncodingException on error while encrypting the token.
 *///w  w  w. j av a  2 s . c  o m
private void setAuthorizationHeader(Axis2MessageContext synCtx, byte[] serviceTicket)
        throws UnsupportedEncodingException {

    org.apache.axis2.context.MessageContext msgCtx = synCtx.getAxis2MessageContext();
    Map<String, Object> headerProp = new HashMap<>();
    headerProp.put(HttpHeaders.AUTHORIZATION,
            KerberosConstants.NEGOTIATE + " " + new String(Base64.encodeBase64(serviceTicket), "UTF-8"));
    msgCtx.setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, headerProp);

    Map<String, String> headers = (Map<String, String>) msgCtx
            .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
    ConcurrentHashMap<String, Object> headerProperties = new ConcurrentHashMap<>();
    for (Map.Entry<String, String> entry : headers.entrySet()) {
        headerProperties.put(entry.getKey(), entry.getValue());
    }
    headerProperties.put(HttpHeaders.AUTHORIZATION, KerberosConstants.NEGOTIATE + " "
            + new String(Base64.encodeBase64(serviceTicket), KerberosConstants.UTF8));
    msgCtx.setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, headerProperties);
}

From source file:org.restcomm.connect.http.SmsMessagesEndpoint.java

@SuppressWarnings("unchecked")
protected Response putSmsMessage(final String accountSid, final MultivaluedMap<String, String> data,
        final MediaType responseType) {
    secure(accountsDao.getAccount(accountSid), "RestComm:Create:SmsMessages");
    try {//from  w  ww  .ja v  a2 s  .  c o m
        validate(data);
        if (normalizePhoneNumbers)
            normalize(data);
    } catch (final RuntimeException exception) {
        return status(BAD_REQUEST).entity(exception.getMessage()).build();
    }
    final String sender = data.getFirst("From");
    final String recipient = data.getFirst("To");
    final String body = data.getFirst("Body");
    final SmsSessionRequest.Encoding encoding;
    if (!data.containsKey("Encoding")) {
        encoding = SmsSessionRequest.Encoding.GSM;
    } else {
        encoding = SmsSessionRequest.Encoding.valueOf(data.getFirst("Encoding").replace('-', '_'));
    }
    ConcurrentHashMap<String, String> customRestOutgoingHeaderMap = new ConcurrentHashMap<String, String>();
    Iterator<String> iter = data.keySet().iterator();
    while (iter.hasNext()) {
        String name = iter.next();
        if (name.startsWith("X-")) {
            customRestOutgoingHeaderMap.put(name, data.getFirst(name));
        }
    }
    final Timeout expires = new Timeout(Duration.create(60, TimeUnit.SECONDS));
    try {
        Future<Object> future = (Future<Object>) ask(aggregator,
                new CreateSmsSession(sender, recipient, accountSid, true), expires);
        Object object = Await.result(future, Duration.create(10, TimeUnit.SECONDS));
        Class<?> klass = object.getClass();
        if (SmsServiceResponse.class.equals(klass)) {
            final SmsServiceResponse<ActorRef> smsServiceResponse = (SmsServiceResponse<ActorRef>) object;
            if (smsServiceResponse.succeeded()) {
                // Create an SMS record for the text message.
                final SmsMessage record = sms(new Sid(accountSid), getApiVersion(data), sender, recipient, body,
                        SmsMessage.Status.SENDING, SmsMessage.Direction.OUTBOUND_API);
                dao.addSmsMessage(record);
                // Send the sms.
                final ActorRef session = smsServiceResponse.get();
                final ActorRef observer = observer();
                session.tell(new Observe(observer), observer);
                session.tell(new SmsSessionAttribute("record", record), null);
                final SmsSessionRequest request = new SmsSessionRequest(sender, recipient, body, encoding,
                        customRestOutgoingHeaderMap);
                session.tell(request, null);
                if (APPLICATION_JSON_TYPE == responseType) {
                    return ok(gson.toJson(record), APPLICATION_JSON).build();
                } else if (APPLICATION_XML_TYPE == responseType) {
                    final RestCommResponse response = new RestCommResponse(record);
                    return ok(xstream.toXML(response), APPLICATION_XML).build();
                } else {
                    return null;
                }
            } else {
                String msg = smsServiceResponse.cause().getMessage();
                String error = "SMS_LIMIT_EXCEEDED";
                return status(Response.Status.FORBIDDEN)
                        .entity(buildErrorResponseBody(msg, error, responseType)).build();
            }
        }
        return status(INTERNAL_SERVER_ERROR).build();
    } catch (final Exception exception) {
        return status(INTERNAL_SERVER_ERROR).entity(exception.getMessage()).build();
    }
}

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

/**
 * /*from   w ww  .  j  a  v a  2  s.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:org.wso2.carbon.event.stream.core.internal.CarbonEventStreamService.java

public void addEventStreamConfig(EventStreamConfiguration eventStreamConfiguration)
        throws EventStreamConfigurationException {
    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    ConcurrentHashMap<String, EventStreamConfiguration> eventStreamConfigs = tenantSpecificEventStreamConfigs
            .get(tenantId);/* w w w  .  j  a  v a2s  . c o  m*/
    if (eventStreamConfigs == null) {
        eventStreamConfigs = new ConcurrentHashMap<String, EventStreamConfiguration>();
        tenantSpecificEventStreamConfigs.put(tenantId, eventStreamConfigs);
    }
    eventStreamConfigs.put(eventStreamConfiguration.getStreamDefinition().getStreamId(),
            eventStreamConfiguration);
    for (EventStreamListener eventStreamListener : EventStreamServiceValueHolder.getEventStreamListenerList()) {
        eventStreamListener.addedEventStream(tenantId, eventStreamConfiguration.getStreamDefinition().getName(),
                eventStreamConfiguration.getStreamDefinition().getVersion());
    }
}

From source file:org.apache.oodt.cas.catalog.struct.impl.index.DataSourceIndex.java

/**
 * {@inheritDoc}//from ww  w  . j  av  a2s  .co  m
 */
public Map<TransactionId<?>, List<TermBucket>> getBuckets(List<TransactionId<?>> transactionIds)
        throws QueryServiceException {
    ConcurrentHashMap<TransactionId<?>, List<TermBucket>> map = new ConcurrentHashMap<TransactionId<?>, List<TermBucket>>();
    for (TransactionId<?> transactionId : transactionIds) {
        map.put(transactionId, this.getBuckets(transactionId));
    }
    return map;
}

From source file:com.alibaba.wasp.meta.TableSchemaCacheReader.java

private void mapping(Index index, String tableName) {
    ConcurrentHashMap<String, List<Index>> indexs = compositeIndex.get(tableName);
    if (indexs == null) {
        indexs = new ConcurrentHashMap<String, List<Index>>();
        compositeIndex.put(tableName, indexs);
    }/*from   w  w w.  j  a v  a2 s . c  om*/
    StringBuilder start = new StringBuilder();
    for (Field field : index.getIndexKeys().values()) {
        start.append(field.getName());
        List<Index> indexList = indexs.get(start.toString());
        if (indexList == null) {
            indexList = new ArrayList<Index>();
            indexs.put(start.toString(), indexList);
        }
        indexList.add(index);
    }
}