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;
}
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();
}
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));
}
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"));
}
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"));
}
Aggregations