use of java.util.LinkedHashMap in project hazelcast by hazelcast.
the class QueueContainer method clear.
public Map<Long, Data> clear() {
long current = Clock.currentTimeMillis();
LinkedHashMap<Long, Data> map = new LinkedHashMap<Long, Data>(getItemQueue().size());
for (QueueItem item : getItemQueue()) {
map.put(item.getItemId(), item.getData());
// For stats
age(item, current);
}
if (store.isEnabled() && !map.isEmpty()) {
try {
store.deleteAll(map.keySet());
} catch (Exception e) {
throw new HazelcastException(e);
}
}
getItemQueue().clear();
dataMap.clear();
scheduleEvictionIfEmpty();
return map;
}
use of java.util.LinkedHashMap in project hazelcast by hazelcast.
the class QueueContainer method drain.
/**
* Removes items from the queue and the queue store (if configured), up to {@code maxSize} or the size of the queue,
* whichever is smaller. Also schedules the queue for destruction if it is empty or destroys it immediately if it is
* empty and {@link QueueConfig#getEmptyQueueTtl()} is 0.
*
* @param maxSize the maximum number of items to be removed
* @return the map of IDs and removed (drained) items
*/
public Map<Long, Data> drain(int maxSize) {
int maxSizeParam = maxSize;
if (maxSizeParam < 0 || maxSizeParam > getItemQueue().size()) {
maxSizeParam = getItemQueue().size();
}
final LinkedHashMap<Long, Data> map = new LinkedHashMap<Long, Data>(maxSizeParam);
mapDrainIterator(maxSizeParam, map);
if (store.isEnabled() && maxSizeParam != 0) {
try {
store.deleteAll(map.keySet());
} catch (Exception e) {
throw new HazelcastException(e);
}
}
long current = Clock.currentTimeMillis();
for (int i = 0; i < maxSizeParam; i++) {
final QueueItem item = getItemQueue().poll();
//For Stats
age(item, current);
}
if (maxSizeParam != 0) {
scheduleEvictionIfEmpty();
}
return map;
}
use of java.util.LinkedHashMap in project Gaffer by gchq.
the class MapGeneratorTest method shouldGenerateAnEmptyMap.
@Test
public void shouldGenerateAnEmptyMap() {
// Given
final Object vertex = "source vertex";
final String prop1 = "property 1";
final int count = 10;
final Element element = new Entity.Builder().group(TestGroups.ENTITY).vertex(vertex).property(TestPropertyNames.PROP_1, prop1).property(TestPropertyNames.COUNT, count).build();
final MapGenerator generator = new MapGenerator();
// When
final Map<String, Object> map = generator.getObject(element);
// Then
final Map<String, Object> expectedMap = new LinkedHashMap<>();
assertEquals(expectedMap, map);
}
use of java.util.LinkedHashMap in project hazelcast by hazelcast.
the class ClientClusterServiceImpl method handleInitialMembershipEvent.
void handleInitialMembershipEvent(InitialMembershipEvent event) {
synchronized (initialMembershipListenerMutex) {
Set<Member> initialMembers = event.getMembers();
LinkedHashMap<Address, Member> newMap = new LinkedHashMap<Address, Member>();
for (Member initialMember : initialMembers) {
newMap.put(initialMember.getAddress(), initialMember);
}
members.set(Collections.unmodifiableMap(newMap));
fireInitialMembershipEvent(event);
}
}
use of java.util.LinkedHashMap in project Lifecycle-Sorter by armandAkop.
the class Lifecycle method sort.
/**
* Sorts the lifecycle methods provided
* @return A Map of the method names and entire method definitions, respecting the
* sort order of mLifecycleOrdering
*/
public Map<String, PsiMethod> sort() {
// LinkedHashMap because we must respect the ordering in which we insert
Map<String, PsiMethod> sortedMethods = new LinkedHashMap<String, PsiMethod>();
for (int i = 0; i < mLifecycleOrdering.size(); i++) {
String methodName = mLifecycleOrdering.get(i);
PsiMethod method = mAllMethods.get(methodName);
if (method != null) {
sortedMethods.put(methodName, method);
}
}
return sortedMethods;
}
Aggregations