Search in sources :

Example 1 with LockManagerProxy

use of org.jboss.stm.internal.proxy.LockManagerProxy in project narayana by jbosstm.

the class Container method getContainer.

/**
 * Given the proxy return the container that is managing it.
 *
 * @param proxy the instance within the container we're looking for.
 * @return the container or null. Shouldn't really be possible to get null!
 */
public static final Container<?> getContainer(Object proxy) {
    /*
         * Rather than maintain a list of Container instances and iterate through them
         * we create a clone of the Container using the real container within the
         * proxy itself. Container is essentially a (almost) stateless wrapper class
         * anyway so hopefully this is a lightweight and faster way of achieving this.
         * Can revisit later if this creates too many instances.
         */
    Container<?> toReturn = null;
    if (proxy instanceof OptimisticLockManagerProxy<?>) {
        RecoverableContainer<?> cont = ((OptimisticLockManagerProxy<?>) proxy).getContainer();
        toReturn = new Container(cont);
    } else {
        if (proxy instanceof LockManagerProxy<?>) {
            RecoverableContainer<?> cont = ((LockManagerProxy<?>) proxy).getContainer();
            toReturn = new Container(cont);
        } else
            throw new IllegalArgumentException("Not a proxy object!");
    }
    return toReturn;
}
Also used : RecoverableContainer(org.jboss.stm.internal.RecoverableContainer) PersistentContainer(org.jboss.stm.internal.PersistentContainer) OptimisticLockManagerProxy(org.jboss.stm.internal.proxy.OptimisticLockManagerProxy) LockManagerProxy(org.jboss.stm.internal.proxy.LockManagerProxy) OptimisticLockManagerProxy(org.jboss.stm.internal.proxy.OptimisticLockManagerProxy)

Aggregations

PersistentContainer (org.jboss.stm.internal.PersistentContainer)1 RecoverableContainer (org.jboss.stm.internal.RecoverableContainer)1 LockManagerProxy (org.jboss.stm.internal.proxy.LockManagerProxy)1 OptimisticLockManagerProxy (org.jboss.stm.internal.proxy.OptimisticLockManagerProxy)1