Example usage for org.apache.commons.collections.map ReferenceMap ReferenceMap

List of usage examples for org.apache.commons.collections.map ReferenceMap ReferenceMap

Introduction

In this page you can find the example usage for org.apache.commons.collections.map ReferenceMap ReferenceMap.

Prototype

public ReferenceMap(int keyType, int valueType, int capacity, float loadFactor) 

Source Link

Document

Constructs a new ReferenceMap with the specified reference types, load factor and initial capacity.

Usage

From source file:lucee.runtime.type.StructImpl.java

/**
 * This implementation spares its clients from the unspecified, 
 * generally chaotic ordering provided by normally Struct , 
 * without incurring the increased cost associated with TreeMap. 
 * It can be used to produce a copy of a map that has the same order as the original
 * @param type// w w  w  .  ja v a 2 s  .  c o m
 * @param initialCapacity initial capacity - MUST be a power of two.
 */
public StructImpl(int type, int initialCapacity) {
    if (type == TYPE_WEAKED)
        map = new SyncMap<Collection.Key, Object>(new WeakHashMapPro<Collection.Key, Object>(initialCapacity));
    else if (type == TYPE_SOFT)
        map = new SyncMap<Collection.Key, Object>(new MapProWrapper<Collection.Key, Object>(
                new ReferenceMap(ReferenceMap.HARD, ReferenceMap.SOFT, initialCapacity, 0.75f),
                new SerializableObject()));
    else if (type == TYPE_LINKED)
        map = new SyncMap<Collection.Key, Object>(
                new LinkedHashMapPro<Collection.Key, Object>(initialCapacity));
    else
        map = MapFactory.getConcurrentMap(initialCapacity);
}

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 {//  ww  w .  ja  va  2 s .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.hibernate.engine.StatefulPersistenceContext.java

public static StatefulPersistenceContext deserialize(ObjectInputStream ois, SessionImplementor session)
        throws IOException, ClassNotFoundException {
    log.trace("deserializing 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 {/*ww w .j a  v  a2s . 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("staring 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("staring 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("staring deserialization of [" + count + "] proxiesByKey entries");
        rtn.proxiesByKey = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.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("staring 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("staring 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("staring 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("staring 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("staring 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("staring deserialization of [" + count + "] nullifiableEntityKeys 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;
}