public static <K, V> ConcurrentMap<K, V> concurrentMap(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4) { ConcurrentMap<K, V> map = concurrentMap(key1, value1, key2, value2, key3, value3); map.put(key4, value4); return map; }
public static <K, V> ConcurrentMap<K, V> concurrentMap(K key1, V value1, K key2, V value2) { ConcurrentMap<K, V> map = concurrentMap(key1, value1); map.put(key2, value2); return map; }
public static <K, V> ConcurrentMap<K, V> concurrentMap(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4, K key5, V value5) { ConcurrentMap<K, V> map = concurrentMap(key1, value1, key2, value2, key3, value3, key4, value4); map.put(key5, value5); return map; }
public static <K, V> ConcurrentMap<K, V> concurrentMap(K key, V value) { ConcurrentMap<K, V> map = concurrentMap(); map.put(key, value); return map; }
public static <K, V> ConcurrentMap<K, V> concurrentMap(K key1, V value1, K key2, V value2, K key3, V value3) { ConcurrentMap<K, V> map = concurrentMap(key1, value1, key2, value2); map.put(key3, value3); return map; }
public static <K, V> ConcurrentMap<K, V> concurrentMap(Map<? extends K, ? extends V> src, boolean ignoreNullValues) { ConcurrentMap<K, V> map = concurrentMap(); for (Map.Entry<? extends K, ? extends V> e : src.entrySet()) { if (!ignoreNullValues || e.getValue() != null) { map.put(e.getKey(), e.getValue()); } } return map; }
@SuppressWarnings("unchecked") public static <K, V> ConcurrentMap<K, V> concurrentMap(Object... keysAndValues) { U.must(keysAndValues.length % 2 == 0, "Incorrect number of arguments (expected key-value pairs)!"); ConcurrentMap<K, V> map = concurrentMap(); for (int i = 0; i < keysAndValues.length / 2; i++) { map.put((K) keysAndValues[i * 2], (V) keysAndValues[i * 2 + 1]); } return map; }
@Override public Map<String, Serializable> loadSession(Req req, String sessionId) { Fire.event(Events.SESSION_LOAD, "id", sessionId); SessionHolder holder = sessions.get(sessionId); if (holder.session == null) { synchronized (holder) { if (holder.session == null) { if (holder.serialized != null) { Fire.event(Events.SESSION_DESERIALIZE, "id", sessionId); holder.session = U.cast(Msc.deserialize(holder.serialized)); } else { holder.session = Coll.concurrentMap(); Fire.event(Events.SESSION_CONCURRENT_ACCESS, "id", sessionId); } } } } holder.refCounter.incrementAndGet(); return holder.session; }
@SuppressWarnings("unchecked") public static <T> T newInstance(Class<T> clazz) { Err.argMust(clazz != AutoExpandingMap.class, "Cannot instantiate AutoExpandingMap!"); if (clazz == List.class) { return (T) U.list(); } else if (clazz == Set.class) { return (T) U.set(); } else if (clazz == Map.class) { return (T) U.map(); } else if (clazz == ConcurrentMap.class) { return (T) Coll.concurrentMap(); } else if (clazz.getName().equals("java.util.Collections$SynchronizedSet")) { return (T) Coll.synchronizedSet(); } else if (clazz.getName().equals("java.util.Collections$SynchronizedList")) { return (T) Coll.synchronizedList(); } else if (clazz.getName().equals("java.util.Collections$SynchronizedMap")) { return (T) Coll.synchronizedMap(); } else if (clazz == Var.class) { return (T) Vars.var("<new>", null); } else if (clazz == Object.class) { return (T) new Object(); } return newBeanInstance(clazz); }
@Override public Map<String, Serializable> loadSession(Req req, String sessionId) throws Exception { Fire.event(Events.SESSION_LOAD, "id", sessionId); SessionHolder holder = sessions.get(sessionId); if (holder.session == null) { synchronized (holder) { if (holder.session == null) { if (holder.serialized != null) { Fire.event(Events.SESSION_DESERIALIZE, "id", sessionId); holder.session = U.cast(Msc.deserialize(holder.serialized)); } else { holder.session = Coll.concurrentMap(); Fire.event(Events.SESSION_CONCURRENT_ACCESS, "id", sessionId); } } } } holder.refCounter.incrementAndGet(); return holder.session; }