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:com.iitb.cse.Utils.java

public static ConcurrentHashMap<String, String> getAccessPointConnectionDetails() {

    ConcurrentHashMap<String, String> apConnection = new ConcurrentHashMap<String, String>();
    Enumeration macList = Constants.currentSession.connectedClients.keys();

    while (macList.hasMoreElements()) {
        String macAddr = (String) macList.nextElement();
        DeviceInfo device = Constants.currentSession.connectedClients.get(macAddr);

        if (apConnection.get(device.getBssid()) == null) {
            apConnection.put(device.getBssid(), device.getSsid() + "#1");
        } else {/*from  w  w  w.  j a va 2s  .c o m*/
            String ssid_count = apConnection.get(device.getBssid());
            int count = Integer.parseInt(ssid_count.split("#")[1]);
            count++;
            apConnection.put(device.getBssid(), device.getSsid() + "#" + Integer.toString(count));
        }
    }
    return apConnection;
}

From source file:com.iitb.cse.Utils.java

public static Enumeration<String> getAllBssids() {

    ConcurrentHashMap<String, Boolean> obj = new ConcurrentHashMap<String, Boolean>();
    ConcurrentHashMap<String, DeviceInfo> clients = Constants.currentSession.getConnectedClients();
    Enumeration<String> macList = clients.keys();

    if (clients != null) {
        while (macList.hasMoreElements()) {
            String macAddr = macList.nextElement();
            DeviceInfo device = clients.get(macAddr);
            obj.put(device.getBssid(), Boolean.TRUE);
        }//  w  w  w.ja va2s. com
    }

    Enumeration<String> bssidList = obj.keys();
    return bssidList;
}

From source file:com.iitb.cse.Utils.java

public static Enumeration<String> getAllSsids() {

    ConcurrentHashMap<String, Boolean> obj = new ConcurrentHashMap<String, Boolean>();
    ConcurrentHashMap<String, DeviceInfo> clients = Constants.currentSession.getConnectedClients();
    Enumeration<String> macList = clients.keys();

    if (clients != null) {
        while (macList.hasMoreElements()) {
            String macAddr = macList.nextElement();
            DeviceInfo device = clients.get(macAddr);
            obj.put(device.getSsid(), Boolean.TRUE);
        }//from   w  w  w  . j a  v  a 2s  . co m
    }

    Enumeration<String> bssidList = obj.keys();
    return bssidList;
}

From source file:ubicrypt.core.dto.VClock.java

@Override
public Object clone() throws CloneNotSupportedException {
    return new VClock(map.entrySet().stream().collect(ConcurrentHashMap<Integer, AtomicLong>::new,
            (ConcurrentHashMap<Integer, AtomicLong> map, Map.Entry<Integer, AtomicLong> entry) -> map
                    .put(entry.getKey(), new AtomicLong(entry.getValue().longValue())),
            (ConcurrentHashMap<Integer, AtomicLong> map1, ConcurrentHashMap<Integer, AtomicLong> map2) -> map1
                    .putAll(map2)));//from  w  w  w  . ja v  a2s  .  co m
}

From source file:com.intercepter.LocalVPN.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_local_vpn);
    loadInterceptorApiList();/*from   w ww  .j a va 2  s . co m*/
    final Button vpnButton = (Button) findViewById(R.id.vpn);
    vpnButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startVPN();
        }
    });
    waitingForVPNStart = false;
    LocalBroadcastManager.getInstance(this).registerReceiver(vpnStateReceiver,
            new IntentFilter(LocalVPNService.BROADCAST_VPN_STATE));
    ConcurrentHashMap<String, String> api = new ConcurrentHashMap<>();
    api.put("dSetOnlineStatus",
            "{\"code\":304,\"msg\":\"CACHED\",\"data\":[],\"ns\":\"gulf_driver\",\"key\":\"dd9a7bfb6ccbe1a73314b4e88ab9a5f\",\"md5\":\"\"}");
    api.put("dGetListenMode",
            "{\"errno\":0,\"errmsg\":\"SUCCESS\",\"listen_mode\":1,\"book_stime\":-1,\"book_etime\":-1,\"listen_carpool_mode\":1,\"nova_enabled\":0,\"listen_distance\":0,\"auto_grab_flag\":1,\"grab_mode\":1,\"compet_show_dest\":1,\"can_compet_order_num\":-1,\"addr_info\":{\"dest_name\":\"\",\"dest_address\":\"\",\"dest_lng\":\"0.000000\",\"dest_lat\":\"0.000000\",\"dest_type\":0},\"receive_level\":\"600,500\",\"receive_level_type\":96,\"show_carpool\":0,\"show_nova\":0,\"distance_config\":\"\",\"show_auto_grab\":0,\"show_assign\":0,\"show_dest\":1,\"car_level\":{\"default_level\":\"600\",\"level_info\":\"\\u666e\\u901a\"}}");
    interceptor = new HttpInterceptor("api.udache.com", api);

}

From source file:net.yacy.kelondro.util.FileUtils.java

public static ConcurrentHashMap<String, byte[]> loadMapB(final File f) {
    ConcurrentHashMap<String, String> m = loadMap(f);
    if (m == null)
        return null;
    ConcurrentHashMap<String, byte[]> mb = new ConcurrentHashMap<String, byte[]>();
    for (Map.Entry<String, String> e : m.entrySet())
        mb.put(e.getKey(), UTF8.getBytes(e.getValue()));
    return mb;/*from   w w w  .java  2  s. com*/
}

From source file:org.fishwife.jrugged.spring.TestCircuitBreakerBeanFactory.java

@Test
public void testFindInvalidCircuitBreakerBean() {
    String breakerName = "testFindInvalid";

    // Create a map with an invalid CircuitBreaker (non-bean) in it, and jam it in.
    ConcurrentHashMap<String, CircuitBreaker> invalidMap = new ConcurrentHashMap<String, CircuitBreaker>();
    invalidMap.put(breakerName, new CircuitBreaker());
    ReflectionTestUtils.setField(factory, "circuitBreakerMap", invalidMap);

    // Try to find it.
    CircuitBreakerBean foundBreaker = factory.findCircuitBreakerBean(breakerName);
    assertNull(foundBreaker);//w  w w.jav a2 s.  co m
}

From source file:gov.nih.nci.integration.dao.DefaultServiceInvocationMessageDao.java

/**
 * getAllByReferenceMessageId// w  ww  .j ava 2  s . c om
 * 
 * @param refMsgId - messageId
 * @return Map
 */
@SuppressWarnings("unchecked")
public Map<StrategyIdentifier, ServiceInvocationMessage> getAllByReferenceMessageId(Long refMsgId) {
    final Query msgsQuery = this.getEm().createQuery("from " + getDomainClass().getSimpleName()
            + " svcInvMsg where svcInvMsg.referenceMessageId = :referenceMessageId ");
    msgsQuery.setParameter("referenceMessageId", refMsgId);
    final List<ServiceInvocationMessage> msgs = msgsQuery.getResultList();
    final ConcurrentHashMap<StrategyIdentifier, ServiceInvocationMessage> map = new ConcurrentHashMap<StrategyIdentifier, ServiceInvocationMessage>();
    for (ServiceInvocationMessage serviceInvocationMessage : msgs) {
        map.put(serviceInvocationMessage.getStrategyIdentifier(), serviceInvocationMessage);
    }

    return map;
}

From source file:com.athena.sqs.MessageAggregator.java

/**
 * Aggregate splitted messages into single message.
 * @param rawData base64 string/*from  w w w.  j a  v  a 2  s . c o  m*/
 * @throws MessageException
 */
public void aggregate(String rawString) throws MessageException {
    try {
        BASE64Decoder decoder = new BASE64Decoder();

        int index = rawString.indexOf(MessageContext.DATA_DELIMITER);

        // 1. Split header
        String[] header = parseHeader(rawString.substring(0, index));
        String content = rawString.substring(index + 2);

        // 2. Assign header value to local variable
        MessageTransferType transferType = MessageTransferType.valueOf(header[0]);
        String businessName = header[1];
        String transactionId = header[2];
        MessageSplitType splitType = MessageSplitType.valueOf(header[3]);
        int current = Integer.parseInt(header[4]);
        int total = Integer.parseInt(header[5]);

        // 3 Check Message Single
        switch (splitType) {
        case SINGLE:
            // TODO single message work
            doProcess(transactionId, new String(decoder.decodeBuffer(content)));
            return;
        case MULTI:
            break;
        }

        logger.debug("Transaction ID : " + transactionId);

        // 4. Check Message Order
        // If transaction id is not exist in txMap, create new tx map object
        if (!txMap.containsKey(transactionId)) {
            ConcurrentHashMap<Integer, String> orderedMessages = new ConcurrentHashMap<Integer, String>();
            orderedMessages.put(current, content);

            txMap.put(transactionId, orderedMessages);
        } else {
            // Already same transaction message was inserted
            ConcurrentHashMap<Integer, String> orderedMessages = txMap.get(transactionId);
            orderedMessages.put(current, content);

            // Message compare
            if (orderedMessages.size() == total) {
                // All messages arrived
                Object[] key = orderedMessages.keySet().toArray();
                Arrays.sort(key);

                String finalMessage = "";
                for (int i = 0; i < key.length; i++) {
                    finalMessage += orderedMessages.get(key[i]);
                }

                logger.debug("===== [ " + transactionId + "] ======");
                logger.debug(new String(decoder.decodeBuffer(finalMessage)));
                boolean isDelete = txMap.remove(transactionId, orderedMessages);
                if (!isDelete) {
                    throw new MessageException("Can't delete message from transaction map");
                }

                doProcess(transactionId, new String(decoder.decodeBuffer(finalMessage)));
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.wso2.carbon.identity.oauth2.token.handlers.grant.saml.SAML1BearerGrantHandlerTest.java

@Test(dataProvider = "BuildAssertion")
public void testValidateGrant(String assertion, boolean enableAudienceRestriction, boolean expectedResult)
        throws Exception {
    OAuthTokenReqMessageContext oAuthTokenReqMessageContext = buildOAuth2AccessTokenReqDTO();
    RequestParameter[] requestParameters = new RequestParameter[] {
            new RequestParameter("assertion", Base64.encodeBase64String(assertion.getBytes())) };
    DefaultBootstrap.bootstrap();/*from  ww  w  .j a  va 2 s.  c o m*/
    oAuthTokenReqMessageContext.getOauth2AccessTokenReqDTO().setRequestParameters(requestParameters);
    WhiteboxImpl.setInternalState(saml1BearerGrantHandler, "audienceRestrictionValidationEnabled",
            enableAudienceRestriction);
    RealmService realmService = mock(RealmService.class);
    RegistryService registryService = mock(RegistryService.class);
    ServerConfigurationService serverConfigurationService = mock(ServerConfigurationService.class);
    CarbonCoreDataHolder.getInstance().setRegistryService(registryService);
    CarbonCoreDataHolder.getInstance().setServerConfigurationService(serverConfigurationService);
    TenantManager tenantManager = mock(TenantManager.class);
    when(realmService.getTenantManager()).thenReturn(tenantManager);
    when(tenantManager.getTenantId(TestConstants.CARBON_TENANT_DOMAIN))
            .thenReturn(MultitenantConstants.SUPER_TENANT_ID);
    IdpMgtServiceComponentHolder.getInstance().setRealmService(realmService);
    KeyStoreManager keyStoreManager = mock(KeyStoreManager.class);
    ConcurrentHashMap<String, KeyStoreManager> mtKeyStoreManagers = new ConcurrentHashMap();
    mtKeyStoreManagers.put("-1234", keyStoreManager);
    WhiteboxImpl.setInternalState(KeyStoreManager.class, "mtKeyStoreManagers", mtKeyStoreManagers);
    X509Certificate cert = (X509Certificate) CertificateFactory.getInstance("X.509")
            .generateCertificate(new ByteArrayInputStream(Base64.decodeBase64(CERTIFICATE)));
    when(keyStoreManager.getDefaultPrimaryCertificate()).thenReturn(cert);
    Map<String, Object> configuration = new HashMap<>();
    configuration.put("SSOService.EntityId", "LOCAL");
    WhiteboxImpl.setInternalState(IdentityUtil.class, "configuration", configuration);
    saml1BearerGrantHandler.profileValidator = new SAMLSignatureProfileValidator();
    assertEquals(saml1BearerGrantHandler.validateGrant(oAuthTokenReqMessageContext), expectedResult);
    WhiteboxImpl.setInternalState(IdentityUtil.class, "configuration", new HashMap<>());
}