List of usage examples for org.apache.commons.collections.map AbstractReferenceMap HARD
int HARD
To view the source code for org.apache.commons.collections.map AbstractReferenceMap HARD.
Click Source Link
From source file:com.google.gwt.dev.shell.designtime.WrappersCache.java
/** * Weakly caches a given JSO by unique id. A cached JSO can be looked up by unique id until it is garbage * collected./* w w w. j a v a2 s. c o m*/ * * Instantiations: changed to long. * * @param uniqueId * a unique id associated with the JSO * @param jso * the value to cache */ @SuppressWarnings("unchecked") public static void putCachedJso(ClassLoader cl, long uniqueId, Object jso) { Map<Long, Object> cache = m_jsoCache.get(cl); if (cache == null) { cache = new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.WEAK); m_jsoCache.put(cl, cache); } cache.put(uniqueId, jso); }
From source file:com.google.gwt.dev.cfg.ModuleDefLoader.java
@SuppressWarnings("unchecked") private static Map<String, ModuleDef> getModulesCache() { ClassLoader keyClassLoader = Thread.currentThread().getContextClassLoader(); Map<String, ModuleDef> cache = loadedModulesCaches.get(keyClassLoader); if (cache == null) { cache = new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT); loadedModulesCaches.put(keyClassLoader, cache); }/*from w w w . ja v a2 s . c o m*/ return cache; }
From source file:com.google.gwt.dev.javac.TypeOracleMediatorTestBase.java
/** * Tests which variant of AbstractRefrenceMap we want to store the map for * parameterizedTypes, arrayTypes, and wildCardTypes in TypeOracle. Note: this * test is manual because gc can be unreliable. */// w w w . j av a2s . c om @SuppressWarnings("unchecked") public void manualTestAbstractRefrenceMap() { /* * with a HARD -> WEAK map, verify that the entry remains if there is no * reference to key, but is deleted when the reference to value is gone */ Map<Integer, Integer> simpleMap = new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.WEAK, true); Integer bar = new Integer(42); simpleMap.put(new Integer(32), bar); Runtime.getRuntime().gc(); assertEquals(1, simpleMap.size()); bar = null; Runtime.getRuntime().gc(); assertEquals(0, simpleMap.size()); /* * with a WEAK -> WEAK map, verify that the entry is gone if there are no * references to either the key or the value. */ simpleMap = new ReferenceMap(AbstractReferenceMap.WEAK, AbstractReferenceMap.WEAK, true); Map<Integer, Integer> reverseMap = new ReferenceMap(AbstractReferenceMap.WEAK, AbstractReferenceMap.WEAK, true); Integer foo = new Integer(32); bar = new Integer(42); simpleMap.put(foo, bar); reverseMap.put(bar, foo); Runtime.getRuntime().gc(); assertEquals(1, simpleMap.size()); assertEquals(1, reverseMap.size()); bar = null; Runtime.getRuntime().gc(); assertEquals(0, simpleMap.size()); assertEquals(0, reverseMap.size()); }
From source file:org.apache.cayenne.access.DefaultObjectMapRetainStrategy.java
@SuppressWarnings("unchecked") public Map<Object, Persistent> createObjectMap() { String strategy = runtimeProperties.get(Constants.SERVER_OBJECT_RETAIN_STRATEGY_PROPERTY); if (strategy == null || WEAK_RETAIN_STRATEGY.equals(strategy)) { return new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.WEAK); } else if (SOFT_RETAIN_STRATEGY.equals(strategy)) { return new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT); } else if (HARD_RETAIN_STRATEGY.equals(strategy)) { return new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.HARD); } else {//from www. j a va 2s. co m throw new CayenneRuntimeException("Unsupported retain strategy %s", strategy); } }
From source file:org.apache.cayenne.access.ObjectStore.java
/** * Factory method to create default Map for storing registered objects. * /* w w w.jav a 2s . co m*/ * @since 3.0 * @return a map with hard referenced keys and weak referenced values. */ static Map<Object, Persistent> createObjectMap() { return new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.WEAK); }
From source file:org.apache.myfaces.ext202patch.application.viewstate.SerializedViewCollection.java
/** * @return old serialized views map/* ww w . j ava2 s. c o m*/ */ @SuppressWarnings("unchecked") protected Map<Object, Object> getOldSerializedViewsMap() { FacesContext context = FacesContext.getCurrentInstance(); if (_oldSerializedViews == null && context != null) { String cacheMode = getCacheOldViewsInSessionMode(context); if (ServerSideStateCacheImpl.CACHE_OLD_VIEWS_IN_SESSION_MODE_WEAK.equals(cacheMode)) { _oldSerializedViews = new ReferenceMap(AbstractReferenceMap.WEAK, AbstractReferenceMap.WEAK, true); } else if (ServerSideStateCacheImpl.CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT_WEAK.equals(cacheMode)) { _oldSerializedViews = new ReferenceMap(AbstractReferenceMap.SOFT, AbstractReferenceMap.WEAK, true); } else if (ServerSideStateCacheImpl.CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT.equals(cacheMode)) { _oldSerializedViews = new ReferenceMap(AbstractReferenceMap.SOFT, AbstractReferenceMap.SOFT, true); } else if (ServerSideStateCacheImpl.CACHE_OLD_VIEWS_IN_SESSION_MODE_HARD_SOFT.equals(cacheMode)) { _oldSerializedViews = new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT); } } return _oldSerializedViews; }
From source file:org.hibernate.engine.internal.StatefulPersistenceContext.java
/** * Constructs a PersistentContext, bound to the given session. * * @param session The session "owning" this context. *///from w ww. j a v a 2s . c o m public StatefulPersistenceContext(SessionImplementor session) { this.session = session; entitiesByKey = new HashMap(INIT_COLL_SIZE); entitiesByUniqueKey = new HashMap(INIT_COLL_SIZE); proxiesByKey = new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.WEAK); entitySnapshotsByKey = new HashMap(INIT_COLL_SIZE); entityEntries = IdentityMap.instantiateSequenced(INIT_COLL_SIZE); collectionEntries = IdentityMap.instantiateSequenced(INIT_COLL_SIZE); collectionsByKey = new HashMap(INIT_COLL_SIZE); arrayHolders = IdentityMap.instantiate(INIT_COLL_SIZE); parentsByChild = IdentityMap.instantiateSequenced(INIT_COLL_SIZE); nullifiableEntityKeys = new HashSet(); initTransientState(); }
From source file:org.hibernate.engine.internal.StatefulPersistenceContext.java
public static StatefulPersistenceContext deserialize(ObjectInputStream ois, SessionImplementor session) throws IOException, ClassNotFoundException { LOG.trace("Serializing persistent-context"); StatefulPersistenceContext rtn = new StatefulPersistenceContext(session); // during deserialization, we need to reconnect all proxies and // collections to this session, as well as the EntityEntry and // CollectionEntry instances; these associations are transient // because serialization is used for different things. try {//from w w w. j av a 2s .c om rtn.defaultReadOnly = ois.readBoolean(); // todo : we can actually just determine this from the incoming EntityEntry-s rtn.hasNonReadOnlyEntities = ois.readBoolean(); int count = ois.readInt(); LOG.trace("Starting deserialization of [" + count + "] entitiesByKey entries"); rtn.entitiesByKey = new HashMap(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count); for (int i = 0; i < count; i++) { rtn.entitiesByKey.put(EntityKey.deserialize(ois, session), ois.readObject()); } count = ois.readInt(); LOG.trace("Starting deserialization of [" + count + "] entitiesByUniqueKey entries"); rtn.entitiesByUniqueKey = new HashMap(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count); for (int i = 0; i < count; i++) { rtn.entitiesByUniqueKey.put(EntityUniqueKey.deserialize(ois, session), ois.readObject()); } count = ois.readInt(); LOG.trace("Starting deserialization of [" + count + "] proxiesByKey entries"); rtn.proxiesByKey = new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.WEAK, count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count, .75f); for (int i = 0; i < count; i++) { EntityKey ek = EntityKey.deserialize(ois, session); Object proxy = ois.readObject(); if (proxy instanceof HibernateProxy) { ((HibernateProxy) proxy).getHibernateLazyInitializer().setSession(session); rtn.proxiesByKey.put(ek, proxy); } else LOG.trace("Encountered prunded proxy"); // otherwise, the proxy was pruned during the serialization process } count = ois.readInt(); LOG.trace("Starting deserialization of [" + count + "] entitySnapshotsByKey entries"); rtn.entitySnapshotsByKey = new HashMap(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count); for (int i = 0; i < count; i++) { rtn.entitySnapshotsByKey.put(EntityKey.deserialize(ois, session), ois.readObject()); } count = ois.readInt(); LOG.trace("Starting deserialization of [" + count + "] entityEntries entries"); rtn.entityEntries = IdentityMap.instantiateSequenced(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count); for (int i = 0; i < count; i++) { Object entity = ois.readObject(); EntityEntry entry = EntityEntry.deserialize(ois, session); rtn.entityEntries.put(entity, entry); } count = ois.readInt(); LOG.trace("Starting deserialization of [" + count + "] collectionsByKey entries"); rtn.collectionsByKey = new HashMap(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count); for (int i = 0; i < count; i++) { rtn.collectionsByKey.put(CollectionKey.deserialize(ois, session), ois.readObject()); } count = ois.readInt(); LOG.trace("Starting deserialization of [" + count + "] collectionEntries entries"); rtn.collectionEntries = IdentityMap .instantiateSequenced(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count); for (int i = 0; i < count; i++) { final PersistentCollection pc = (PersistentCollection) ois.readObject(); final CollectionEntry ce = CollectionEntry.deserialize(ois, session); pc.setCurrentSession(session); rtn.collectionEntries.put(pc, ce); } count = ois.readInt(); LOG.trace("Starting deserialization of [" + count + "] arrayHolders entries"); rtn.arrayHolders = IdentityMap.instantiate(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count); for (int i = 0; i < count; i++) { rtn.arrayHolders.put(ois.readObject(), ois.readObject()); } count = ois.readInt(); LOG.trace("Starting deserialization of [" + count + "] nullifiableEntityKey entries"); rtn.nullifiableEntityKeys = new HashSet(); for (int i = 0; i < count; i++) { rtn.nullifiableEntityKeys.add(EntityKey.deserialize(ois, session)); } } catch (HibernateException he) { throw new InvalidObjectException(he.getMessage()); } return rtn; }
From source file:org.nuxeo.ecm.core.storage.sql.PersistenceContext.java
@SuppressWarnings("unchecked") public PersistenceContext(Model model, RowMapper mapper, SessionImpl session) throws StorageException { this.model = model; this.mapper = mapper; this.session = session; hierComplex = new SelectionContext(SelectionType.CHILDREN, Boolean.TRUE, mapper, this); hierNonComplex = new SelectionContext(SelectionType.CHILDREN, Boolean.FALSE, mapper, this); seriesVersions = new SelectionContext(SelectionType.SERIES_VERSIONS, null, mapper, this); selections = new ArrayList<SelectionContext>(Arrays.asList(hierComplex, hierNonComplex, seriesVersions)); if (model.proxiesEnabled) { seriesProxies = new SelectionContext(SelectionType.SERIES_PROXIES, null, mapper, this); targetProxies = new SelectionContext(SelectionType.TARGET_PROXIES, null, mapper, this); selections.add(seriesProxies);/*from ww w . ja v a 2 s.c o m*/ selections.add(targetProxies); } else { seriesProxies = null; targetProxies = null; } // use a weak reference for the values, we don't hold them longer than // they need to be referenced, as the underlying mapper also has its own // cache pristine = new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.WEAK); modified = new HashMap<RowId, Fragment>(); // this has to be linked to keep creation order, as foreign keys // are used and need this createdIds = new LinkedHashSet<Serializable>(); cacheCount = registry.counter( MetricRegistry.name("nuxeo", "repositories", session.getRepositoryName(), "caches", "count")); cacheHitCount = registry.counter( MetricRegistry.name("nuxeo", "repositories", session.getRepositoryName(), "caches", "hit")); }
From source file:org.nuxeo.ecm.core.storage.sql.SelectionContext.java
@SuppressWarnings("unchecked") public SelectionContext(SelectionType selType, Serializable criterion, RowMapper mapper, PersistenceContext context) {// w ww. j a v a 2 s.co m this.selType = selType; this.criterion = criterion; this.mapper = mapper; this.context = context; softMap = new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT); hardMap = new HashMap<Serializable, Selection>(); modifiedInTransaction = new HashSet<Serializable>(); modifiedInTransactionCount = registry.counter(MetricRegistry.name("nuxeo", "repositories", context.session.repository.getName(), "caches", "selections", "modified")); cacheHitCount = registry.counter(MetricRegistry.name("nuxeo", "repositories", context.session.repository.getName(), "caches", "selections", "hit")); cacheGetTimer = registry.timer(MetricRegistry.name("nuxeo", "repositories", context.session.repository.getName(), "caches", "selections", "get")); }