Search in sources :

Example 31 with ConcurrentHashMap

use of java.util.concurrent.ConcurrentHashMap in project vert.x by eclipse.

the class FakeClusterManager method getSyncMap.

@Override
public <K, V> Map<K, V> getSyncMap(String name) {
    Map map = syncMaps.get(name);
    if (map == null) {
        map = new ConcurrentHashMap<>();
        Map prevMap = syncMaps.putIfAbsent(name, map);
        if (prevMap != null) {
            map = prevMap;
        }
    }
    @SuppressWarnings("unchecked") Map<K, V> theMap = map;
    return theMap;
}
Also used : ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap) AsyncMap(io.vertx.core.shareddata.AsyncMap) Map(java.util.Map) AsyncMultiMap(io.vertx.core.spi.cluster.AsyncMultiMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 32 with ConcurrentHashMap

use of java.util.concurrent.ConcurrentHashMap in project tomcat by apache.

the class DeltaSession method doReadObject.

private void doReadObject(ObjectInput stream) throws ClassNotFoundException, IOException {
    // Deserialize the scalar instance variables (except Manager)
    // Transient only
    authType = null;
    creationTime = ((Long) stream.readObject()).longValue();
    lastAccessedTime = ((Long) stream.readObject()).longValue();
    maxInactiveInterval = ((Integer) stream.readObject()).intValue();
    isNew = ((Boolean) stream.readObject()).booleanValue();
    isValid = ((Boolean) stream.readObject()).booleanValue();
    thisAccessedTime = ((Long) stream.readObject()).longValue();
    version = ((Long) stream.readObject()).longValue();
    boolean hasPrincipal = stream.readBoolean();
    principal = null;
    if (hasPrincipal) {
        principal = (Principal) stream.readObject();
    }
    //        setId((String) stream.readObject());
    id = (String) stream.readObject();
    if (log.isDebugEnabled())
        log.debug(sm.getString("deltaSession.readSession", id));
    // Deserialize the attribute count and attribute values
    if (attributes == null)
        attributes = new ConcurrentHashMap<>();
    int n = ((Integer) stream.readObject()).intValue();
    boolean isValidSave = isValid;
    isValid = true;
    for (int i = 0; i < n; i++) {
        String name = (String) stream.readObject();
        final Object value;
        try {
            value = stream.readObject();
        } catch (WriteAbortedException wae) {
            if (wae.getCause() instanceof NotSerializableException) {
                // Skip non serializable attributes
                continue;
            }
            throw wae;
        }
        // the web application was stopped.
        if (exclude(name, value)) {
            continue;
        }
        attributes.put(name, value);
    }
    isValid = isValidSave;
    // Session listeners
    n = ((Integer) stream.readObject()).intValue();
    if (listeners == null || n > 0) {
        listeners = new ArrayList<>();
    }
    for (int i = 0; i < n; i++) {
        SessionListener listener = (SessionListener) stream.readObject();
        listeners.add(listener);
    }
    if (notes == null) {
        notes = new Hashtable<>();
    }
    activate();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NotSerializableException(java.io.NotSerializableException) WriteAbortedException(java.io.WriteAbortedException) SessionListener(org.apache.catalina.SessionListener) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 33 with ConcurrentHashMap

use of java.util.concurrent.ConcurrentHashMap in project storm by apache.

the class PacemakerTest method testServerGetPulse.

@Test
public void testServerGetPulse() {
    Pacemaker handler = new Pacemaker(new ConcurrentHashMap());
    makeNode(handler, "/some-root/GET_PULSE");
    messageWithRandId(HBServerMessageType.GET_PULSE, HBMessageData.path("/some-root/GET_PULSE"));
    HBMessage badResponse = handler.handleMessage(hbMessage, false);
    HBMessage goodResponse = handler.handleMessage(hbMessage, true);
    HBPulse goodPulse = goodResponse.get_data().get_pulse();
    Assert.assertEquals(mid, badResponse.get_message_id());
    Assert.assertEquals(HBServerMessageType.NOT_AUTHORIZED, badResponse.get_type());
    Assert.assertNull(badResponse.get_data());
    Assert.assertEquals(mid, goodResponse.get_message_id());
    Assert.assertEquals(HBServerMessageType.GET_PULSE_RESPONSE, goodResponse.get_type());
    Assert.assertEquals("/some-root/GET_PULSE", goodPulse.get_id());
    Assert.assertEquals("nothing", Utils.javaDeserialize(goodPulse.get_details(), String.class));
}
Also used : HBPulse(org.apache.storm.generated.HBPulse) Pacemaker(org.apache.storm.pacemaker.Pacemaker) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HBMessage(org.apache.storm.generated.HBMessage) Test(org.junit.Test)

Example 34 with ConcurrentHashMap

use of java.util.concurrent.ConcurrentHashMap in project storm by apache.

the class PacemakerTest method testServerGetAllNodesForPath.

@Test
public void testServerGetAllNodesForPath() {
    Pacemaker handler = new Pacemaker(new ConcurrentHashMap());
    makeNode(handler, "/some-root-path/foo");
    makeNode(handler, "/some-root-path/bar");
    makeNode(handler, "/some-root-path/baz");
    makeNode(handler, "/some-root-path/boo");
    messageWithRandId(HBServerMessageType.GET_ALL_NODES_FOR_PATH, HBMessageData.path("/some-root-path"));
    HBMessage badResponse = handler.handleMessage(hbMessage, false);
    HBMessage goodResponse = handler.handleMessage(hbMessage, true);
    List<String> pulseIds = goodResponse.get_data().get_nodes().get_pulseIds();
    Assert.assertEquals(mid, badResponse.get_message_id());
    Assert.assertEquals(HBServerMessageType.NOT_AUTHORIZED, badResponse.get_type());
    Assert.assertEquals(mid, goodResponse.get_message_id());
    Assert.assertEquals(HBServerMessageType.GET_ALL_NODES_FOR_PATH_RESPONSE, goodResponse.get_type());
    Assert.assertTrue(pulseIds.contains("foo"));
    Assert.assertTrue(pulseIds.contains("bar"));
    Assert.assertTrue(pulseIds.contains("baz"));
    Assert.assertTrue(pulseIds.contains("boo"));
    makeNode(handler, "/some/deeper/path/foo");
    makeNode(handler, "/some/deeper/path/bar");
    makeNode(handler, "/some/deeper/path/baz");
    messageWithRandId(HBServerMessageType.GET_ALL_NODES_FOR_PATH, HBMessageData.path("/some/deeper/path"));
    badResponse = handler.handleMessage(hbMessage, false);
    goodResponse = handler.handleMessage(hbMessage, true);
    pulseIds = goodResponse.get_data().get_nodes().get_pulseIds();
    Assert.assertEquals(mid, badResponse.get_message_id());
    Assert.assertEquals(HBServerMessageType.NOT_AUTHORIZED, badResponse.get_type());
    Assert.assertEquals(mid, goodResponse.get_message_id());
    Assert.assertEquals(HBServerMessageType.GET_ALL_NODES_FOR_PATH_RESPONSE, goodResponse.get_type());
    Assert.assertTrue(pulseIds.contains("foo"));
    Assert.assertTrue(pulseIds.contains("bar"));
    Assert.assertTrue(pulseIds.contains("baz"));
}
Also used : Pacemaker(org.apache.storm.pacemaker.Pacemaker) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HBMessage(org.apache.storm.generated.HBMessage) Test(org.junit.Test)

Example 35 with ConcurrentHashMap

use of java.util.concurrent.ConcurrentHashMap in project storm by apache.

the class PacemakerTest method testServerDeletePulseId.

@Test
public void testServerDeletePulseId() {
    Pacemaker handler = new Pacemaker(new ConcurrentHashMap());
    makeNode(handler, "/some-root/DELETE_PULSE_ID/foo");
    makeNode(handler, "/some-root/DELETE_PULSE_ID/bar");
    makeNode(handler, "/some-root/DELETE_PULSE_ID/baz");
    makeNode(handler, "/some-root/DELETE_PULSE_ID/boo");
    messageWithRandId(HBServerMessageType.DELETE_PULSE_ID, HBMessageData.path("/some-root/DELETE_PULSE_ID/foo"));
    HBMessage response = handler.handleMessage(hbMessage, true);
    Assert.assertEquals(mid, response.get_message_id());
    Assert.assertEquals(HBServerMessageType.DELETE_PULSE_ID_RESPONSE, response.get_type());
    Assert.assertNull(response.get_data());
    messageWithRandId(HBServerMessageType.GET_ALL_NODES_FOR_PATH, HBMessageData.path("/some-root/DELETE_PULSE_ID"));
    response = handler.handleMessage(hbMessage, true);
    List<String> pulseIds = response.get_data().get_nodes().get_pulseIds();
    Assert.assertEquals(mid, response.get_message_id());
    Assert.assertEquals(HBServerMessageType.GET_ALL_NODES_FOR_PATH_RESPONSE, response.get_type());
    Assert.assertFalse(pulseIds.contains("foo"));
}
Also used : Pacemaker(org.apache.storm.pacemaker.Pacemaker) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HBMessage(org.apache.storm.generated.HBMessage) Test(org.junit.Test)

Aggregations

ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)420 Map (java.util.Map)106 Test (org.junit.Test)102 HashMap (java.util.HashMap)75 ArrayList (java.util.ArrayList)73 CountDownLatch (java.util.concurrent.CountDownLatch)53 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)49 IOException (java.io.IOException)47 List (java.util.List)38 Set (java.util.Set)36 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)33 HashSet (java.util.HashSet)31 AtomicLong (java.util.concurrent.atomic.AtomicLong)29 ConcurrentMap (java.util.concurrent.ConcurrentMap)28 Random (java.util.Random)25 ExecutorService (java.util.concurrent.ExecutorService)23 Collection (java.util.Collection)20 UUID (java.util.UUID)20 Iterator (java.util.Iterator)19 Configuration (org.apache.hadoop.conf.Configuration)17