public V get(final Object key) { try { ReferenceKey<K> refKey = this.lookupFactory.createKey(this.queue, (K) key); ReferenceValue<V> refVal = this.cache.get(refKey); V value = dereferenceValue(refVal); if (value != null) { return value; } else { V created = create((K) key); refVal = valueFactory.createValue(queue, created); refKey = this.keyFactory.createKey(this.queue, (K) key); refVal = this.cache.putIfAbsent(refKey, refVal); value = dereferenceValue(refVal); if (value == null) { value = this.create((K) key); this.put((K) key, value); } return value; } } catch (Exception e) { if (e instanceof RuntimeException) throw (RuntimeException) e; throw new IllegalStateException(e); } }
public ReferenceCache(Type keyType, Type valueType, int initialSize) { this.keyFactory = toFactory(keyType); this.valueFactory = toFactory(valueType); this.lookupFactory = new StrongReferenceFactory(); this.cache = new ConcurrentHashMap<ReferenceKey<K>, ReferenceValue<V>>(initialSize); this.queue = new ReferenceQueueRunner(); }
private V dereferenceValue(Future<ReferenceValue<V>> futureValue) { try { return futureValue == null ? null : dereferenceValue(futureValue.get()); } catch (Exception e) { return null; } }
public static Method findMethod(Object base, Object name, Object[] params) { Method r = null; if (base != null && name != null) { Class type = base.getClass(); String methodName = ELSupport.coerceToString(name); MethodCache m = methodCache.get(type); // if (m == null || type != m.getType()) { // m = new MethodCache(type); // methodCache.set(type, m); // } r = m.findMethod(methodName, params); if (r == null) { throw new MethodNotFoundException(MessageFactory.get( "error.method.notfound", base, name, paramString(paramTypes(params)))); } } else { throw new MethodNotFoundException(); } return r; }
public ReferenceValue<V> call() throws Exception { V created = create((K) key); if (created != null) { return valueFactory.createValue(queue, created); } else { throw new NullPointerException("Value created was Null"); } } };
public V remove(Object key) { ReferenceKey<K> keyRef = this.lookupFactory.createKey(this.queue, key); return this.dereferenceValue(this.cache.remove(keyRef)); }
public static Method findMethod(Object base, Object name, Object[] params) { Method r = null; if (base != null && name != null) { Class type = base.getClass(); String methodName = ELSupport.coerceToString(name); MethodCache m = methodCache.get(type); // if (m == null || type != m.getType()) { // m = new MethodCache(type); // methodCache.set(type, m); // } r = m.findMethod(methodName, params); if (r == null) { throw new MethodNotFoundException(MessageFactory.get( "error.method.notfound", base, name, paramString(paramTypes(params)))); } } else { throw new MethodNotFoundException(); } return r; }
public V get(final Object key) { try { ReferenceKey<K> refKey = this.lookupFactory.createKey(this.queue, (K) key); ReferenceValue<V> refVal = this.cache.get(refKey); V value = dereferenceValue(refVal); if (value != null) { return value; } else { V created = create((K) key); refVal = valueFactory.createValue(queue, created); refKey = this.keyFactory.createKey(this.queue, (K) key); refVal = this.cache.putIfAbsent(refKey, refVal); value = dereferenceValue(refVal); if (value == null) { value = this.create((K) key); this.put((K) key, value); } return value; } } catch (Exception e) { if (e instanceof RuntimeException) throw (RuntimeException) e; throw new IllegalStateException(e); } }
public V remove(Object key) { ReferenceKey<K> keyRef = this.lookupFactory.createKey(this.queue, key); return this.dereferenceValue(this.cache.remove(keyRef)); }
public ReferenceCache(Type keyType, Type valueType, int initialSize) { this.keyFactory = toFactory(keyType); this.valueFactory = toFactory(valueType); this.lookupFactory = new StrongReferenceFactory(); this.cache = new ConcurrentHashMap<ReferenceKey<K>,Future<ReferenceValue<V>>>(initialSize); this.queue = new ReferenceQueueRunner(); Thread t = new Thread(this.queue); t.setDaemon(true); t.start(); }
public static Method findMethod(Object base, Object name, Object[] params) { Method r = null; if (base != null && name != null) { Class type = base.getClass(); String methodName = ELSupport.coerceToString(name); MethodCache m = methodCache.get(type); // if (m == null || type != m.getType()) { // m = new MethodCache(type); // methodCache.set(type, m); // } r = m.findMethod(methodName, params); if (r == null) { throw new MethodNotFoundException(MessageFactory.get( "error.method.notfound", base, name, paramString(paramTypes(params)))); } } else { throw new MethodNotFoundException(); } return r; }
ReferenceKey<K> refKey = this.lookupFactory.createKey(this.queue, (K) key); Future<ReferenceValue<V>> f = this.cache.get(refKey); V value = dereferenceValue(f); if (value != null) { return value; value = dereferenceValue(f); if (value == null) { value = this.create((K) key); this.put((K) key, value);
public V remove(Object key) { ReferenceKey<K> keyRef = this.lookupFactory.createKey(this.queue, key); return this.dereferenceValue(this.cache.remove(keyRef)); }
public ReferenceCache(Type keyType, Type valueType, int initialSize) { this.keyFactory = toFactory(keyType); this.valueFactory = toFactory(valueType); this.lookupFactory = new StrongReferenceFactory(); this.cache = new ConcurrentHashMap<ReferenceKey<K>, ReferenceValue<V>>(initialSize); this.queue = new ReferenceQueueRunner(); }