package org.jboss.ha.jndi;
import java.io.Serializable;
import java.util.Collection;
import javax.naming.Name;
import javax.naming.NamingException;
import org.jnp.interfaces.Naming;
import org.jboss.ha.framework.interfaces.HAPartition;
import org.jboss.ha.framework.interfaces.HAPartition.HAPartitionStateTransfer;
import org.jboss.logging.Logger;
public class HAJNDI
implements HAPartitionStateTransfer, Serializable, org.jnp.interfaces.Naming
{
static final long serialVersionUID = -6277328603304171620L;
private static Logger log = Logger.getLogger(HAJNDI.class);
protected HAPartition partition;
protected TreeHead delegate;
protected Naming haStub;
public HAJNDI(HAPartition partition)
throws NamingException
{
this.partition = partition;
delegate = new TreeHead();
delegate.setPartition(this.partition);
delegate.setHARMIHead(this);
}
public void init() throws Exception
{
log.debug("subscribeToStateTransferEvents");
partition.subscribeToStateTransferEvents("HAJNDI", this);
delegate.init();
}
public void stop() throws Exception
{
delegate.stop();
partition.unsubscribeFromStateTransferEvents("HAJNDI", this);
}
public void setHAStub (Naming stub)
{
this.haStub = stub;
}
public Naming getHAStub ()
{
return this.haStub;
}
public Serializable getCurrentState()
{
if( log.isTraceEnabled() )
log.trace("getCurrentState called");
return delegate;
}
public void setCurrentState(Serializable newState)
{
if( log.isTraceEnabled() )
log.trace("setCurrentState called");
try
{
delegate.stop();
delegate = (TreeHead)newState;
delegate.setPartition(this.partition);
delegate.setHARMIHead (this);
delegate.init();
}
catch (Exception failed)
{
log.warn("Problem restoring state to HA-JNDI", failed);
}
}
public synchronized void bind(Name name, Object obj, String className)
throws NamingException
{
delegate.bind (name, obj, className);
}
public synchronized void rebind(Name name, Object obj, String className)
throws NamingException
{
delegate.rebind (name, obj, className);
}
public synchronized void unbind(Name name)
throws NamingException
{
delegate.unbind (name);
}
public Object lookup(Name name)
throws NamingException
{
return delegate.lookup (name);
}
public Collection list(Name name)
throws NamingException
{
return delegate.list(name) ;
}
public Collection listBindings(Name name)
throws NamingException
{
return delegate.listBindings(name);
}
public javax.naming.Context createSubcontext(Name name)
throws NamingException
{
return delegate.createSubcontext(name);
}
}