/*
* JBoss, Home of Professional Open Source.
* Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.cache.mvcc;
import net.jcip.annotations.ThreadSafe;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.InternalNode;
import org.jboss.cache.Node;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.lock.NodeLock;
import org.jboss.cache.optimistic.DataVersion;
import org.jboss.cache.transaction.GlobalTransaction;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
/**
* A node reference that delegates all calls to a different {@link org.jboss.cache.InternalNode}. Simple indirection
* is all this class does, allowing other processes to change the delegate.
*
* The delegate is a volatile field so the class is thread safe.
*
* This is used to wrap all {@link org.jboss.cache.invocation.NodeInvocationDelegate}s in the {@link org.jboss.cache.DataContainer}
* when using {@link org.jboss.cache.config.Configuration.NodeLockingScheme#MVCC} and {@link org.jboss.cache.lock.IsolationLevel#READ_COMMITTED}.
*
*
* @author Manik Surtani (manik AT jboss DOT org)
* @see org.jboss.cache.mvcc.ReadCommittedNode
* @since 3.0
*/
@ThreadSafe
public class NodeReference implements InternalNode
{
transient volatile InternalNode delegate;
public NodeReference(InternalNode delegate)
{
this.delegate = delegate;
}
/**
* @return the InternalNode being delegated to.
*/
public final InternalNode getDelegate()
{
return delegate;
}
/**
* Sets the internal node to delegate to.
*
* @param delegate node to delegate to.
*/
public final void setDelegate(InternalNode delegate)
{
this.delegate = delegate;
}
public final NodeSPI getParent()
{
return delegate.getParent();
}
public final CacheSPI getCache()
{
return delegate.getCache();
}
public final boolean isChildrenLoaded()
{
return delegate.isChildrenLoaded();
}
public final void setChildrenLoaded(boolean flag)
{
delegate.setChildrenLoaded(flag);
}
public final V get(K key)
{
return delegate.get(key);
}
public final Map getData()
{
return delegate.getData();
}
public final V put(K key, V value)
{
return delegate.put(key, value);
}
public final NodeSPI getOrCreateChild(Object child_name, GlobalTransaction gtx)
{
return delegate.getOrCreateChild(child_name, gtx);
}
public final InternalNode getChild(Fqn f)
{
return delegate.getChild(f);
}
public final InternalNode getChild(Object childName)
{
return delegate.getChild(childName);
}
public final Set> getChildren()
{
return delegate.getChildren();
}
public final Set> getChildren(boolean includeMarkedForRemoval)
{
return delegate.getChildren(includeMarkedForRemoval);
}
public final ConcurrentMap