[jboss-cvs] JBossAS SVN: r74707 - trunk/cluster/src/main/org/jboss/ha/jndi.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jun 17 14:11:45 EDT 2008
Author: dimitris at jboss.org
Date: 2008-06-17 14:11:45 -0400 (Tue, 17 Jun 2008)
New Revision: 74707
Modified:
trunk/cluster/src/main/org/jboss/ha/jndi/DetachedHANamingService.java
trunk/cluster/src/main/org/jboss/ha/jndi/DetachedHANamingServiceMBean.java
trunk/cluster/src/main/org/jboss/ha/jndi/HAJNDI.java
trunk/cluster/src/main/org/jboss/ha/jndi/HANamingService.java
trunk/cluster/src/main/org/jboss/ha/jndi/TreeHead.java
Log:
revert changes that break the build
Modified: trunk/cluster/src/main/org/jboss/ha/jndi/DetachedHANamingService.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/jndi/DetachedHANamingService.java 2008-06-17 18:06:55 UTC (rev 74706)
+++ trunk/cluster/src/main/org/jboss/ha/jndi/DetachedHANamingService.java 2008-06-17 18:11:45 UTC (rev 74707)
@@ -36,6 +36,7 @@
import java.rmi.MarshalledObject;
import java.util.Collections;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -43,7 +44,6 @@
import javax.management.ObjectName;
import javax.management.Query;
import javax.management.QueryExp;
-import javax.naming.Binding;
import javax.net.ServerSocketFactory;
import org.jboss.cache.Cache;
@@ -79,20 +79,20 @@
/**
* The jnp server socket through which the HAJNDI stub is vended
*/
- ServerSocket bootstrapSocket;
+ protected ServerSocket bootstrapSocket;
/**
* The Naming interface server implementation
*/
- HAJNDI theServer;
+ protected HAJNDI theServer;
/**
* The mapping from the long method hash to the Naming Method
*/
- private Map<Long, Method> marshalledInvocationMapping;
+ protected Map marshalledInvocationMapping;
/**
* The protocol stub returned to clients by the bootstrap lookup
*/
- Naming stub;
+ protected Naming stub;
/**
* The HAPartition
*/
@@ -100,7 +100,7 @@
/**
* The cache used to store HA-JNDI bindings
*/
- private Cache<String, Binding> cache;
+ protected Cache cache;
/**
* The proxy factory service that generates the Naming stub
@@ -111,48 +111,48 @@
* The interface to bind to. This is useful for multi-homed hosts that want
* control over which interfaces accept connections.
*/
- InetAddress bindAddress;
+ protected InetAddress bindAddress;
/**
* The bootstrapSocket listen queue depth
*/
- private int backlog = 50;
+ protected int backlog = 50;
/**
* The jnp protocol listening port. The default is 1100, the same as the RMI
* registry default port.
*/
- int port = 1100;
+ protected int port = 1100;
/**
* The autodiscovery multicast group
*/
- String adGroupAddress = NamingContext.DEFAULT_DISCOVERY_GROUP_ADDRESS;
+ protected String adGroupAddress = NamingContext.DEFAULT_DISCOVERY_GROUP_ADDRESS;
/**
* The autodiscovery port
*/
- int adGroupPort = NamingContext.DEFAULT_DISCOVERY_GROUP_PORT;
+ protected int adGroupPort = NamingContext.DEFAULT_DISCOVERY_GROUP_PORT;
/**
* The interface to bind the Multicast socket for autodiscovery to
*/
- InetAddress discoveryBindAddress;
+ protected InetAddress discoveryBindAddress;
/** The runable task for discovery request packets */
- private AutomaticDiscovery autoDiscovery = null;
+ protected AutomaticDiscovery autoDiscovery = null;
/** A flag indicating if autodiscovery should be disabled */
- private boolean discoveryDisabled = false;
+ protected boolean discoveryDisabled = false;
/** The autodiscovery Multicast reply TTL */
- int autoDiscoveryTTL = 16;
+ protected int autoDiscoveryTTL = 16;
/**
* An optional custom server socket factory for the bootstrap lookup
*/
- private ServerSocketFactory jnpServerSocketFactory;
+ protected ServerSocketFactory jnpServerSocketFactory;
/**
* The class name of the optional custom JNP server socket factory
*/
- private String jnpServerSocketFactoryName;
+ protected String jnpServerSocketFactoryName;
/**
* The thread pool used to handle jnp stub lookup requests
*/
- ThreadPool lookupPool;
+ protected ThreadPool lookupPool;
// Public --------------------------------------------------------
@@ -166,19 +166,19 @@
* @return A Map<Long hash, Method> of the Naming interface
* @jmx:managed-attribute
*/
- public Map<Long, Method> getMethodMap()
+ public Map getMethodMap()
{
- return this.marshalledInvocationMapping;
+ return marshalledInvocationMapping;
}
public String getPartitionName()
{
- return this.clusterPartition.getPartitionName();
+ return clusterPartition.getPartitionName();
}
public HAPartition getHAPartition()
{
- return this.clusterPartition;
+ return clusterPartition;
}
public void setHAPartition(HAPartition clusterPartition)
@@ -186,19 +186,19 @@
this.clusterPartition = clusterPartition;
}
- public Cache<String, Binding> getClusteredCache()
- {
- return this.cache;
+ public Cache getClusteredCache()
+ {
+ return cache;
}
- public void setClusteredCache(Cache<String, Binding> cache)
+ public void setClusteredCache(Cache cache)
{
this.cache = cache;
}
public ObjectName getProxyFactoryObjectName()
{
- return this.proxyFactory;
+ return proxyFactory;
}
public void setProxyFactoryObjectName(ObjectName proxyFactory)
@@ -208,40 +208,36 @@
public void setPort(int p)
{
- this.port = p;
+ port = p;
}
public int getPort()
{
- return this.port;
+ return port;
}
public String getBindAddress()
{
String address = null;
- if (this.bindAddress != null)
- {
- address = this.bindAddress.getHostAddress();
- }
+ if (bindAddress != null)
+ address = bindAddress.getHostAddress();
return address;
}
public void setBindAddress(String host) throws java.net.UnknownHostException
{
- this.bindAddress = InetAddress.getByName(host);
+ bindAddress = InetAddress.getByName(host);
}
public int getBacklog()
{
- return this.backlog;
+ return backlog;
}
public void setBacklog(int backlog)
{
if (backlog <= 0)
- {
backlog = 50;
- }
this.backlog = backlog;
}
@@ -269,7 +265,6 @@
{
return this.adGroupPort;
}
-
public void setAutoDiscoveryGroup(int adGroup)
{
this.adGroupPort = adGroup;
@@ -277,35 +272,39 @@
public String getAutoDiscoveryBindAddress()
{
- return (this.discoveryBindAddress != null) ? this.discoveryBindAddress.getHostAddress() : null;
+ String address = null;
+ if (discoveryBindAddress != null)
+ address = discoveryBindAddress.getHostAddress();
+ return address;
}
-
- public void setAutoDiscoveryBindAddress(String address) throws UnknownHostException
+ public void setAutoDiscoveryBindAddress(String address)
+ throws UnknownHostException
{
- this.discoveryBindAddress = InetAddress.getByName(address);
+ discoveryBindAddress = InetAddress.getByName(address);
}
public int getAutoDiscoveryTTL()
{
- return this.autoDiscoveryTTL;
+ return autoDiscoveryTTL;
}
public void setAutoDiscoveryTTL(int ttl)
{
- this.autoDiscoveryTTL = ttl;
+ autoDiscoveryTTL = ttl;
}
- public void setJNPServerSocketFactory(String factoryClassName) throws ClassNotFoundException, InstantiationException, IllegalAccessException
+ public void setJNPServerSocketFactory(String factoryClassName)
+ throws ClassNotFoundException, InstantiationException, IllegalAccessException
{
this.jnpServerSocketFactoryName = factoryClassName;
ClassLoader loader = Thread.currentThread().getContextClassLoader();
- Class<?> clazz = loader.loadClass(this.jnpServerSocketFactoryName);
- this.jnpServerSocketFactory = (ServerSocketFactory) clazz.newInstance();
+ Class clazz = loader.loadClass(jnpServerSocketFactoryName);
+ jnpServerSocketFactory = (ServerSocketFactory) clazz.newInstance();
}
public void setLookupPool(BasicThreadPoolMBean poolMBean)
{
- this.lookupPool = poolMBean.getInstance();
+ lookupPool = poolMBean.getInstance();
}
/*
public void startService(HAPartition haPartition)
@@ -314,104 +313,95 @@
this.startService();
}
*/
- @Override
- protected void createService() throws Exception
+ protected void createService()
+ throws Exception
{
- if (this.clusterPartition == null)
- {
+ if (clusterPartition == null)
throw new IllegalStateException("HAPartition property must be set before starting HAJNDI service");
- }
- if (this.cache == null)
- {
+ if (cache == null)
throw new IllegalStateException("ClusteredCache property must be set before starting HAJNDI service");
- }
- this.log.debug("Initializing HAJNDI server on partition: " + this.clusterPartition.getPartitionName());
+ if (log.isDebugEnabled())
+ log.debug("Initializing HAJNDI server on partition: " + clusterPartition.getPartitionName());
// Start HAJNDI service
- this.theServer = new HAJNDI(this.clusterPartition, this.cache);
+ theServer = new HAJNDI(clusterPartition, cache);
// Build the Naming interface method map
- Map<Long, Method> map = new HashMap<Long, Method>(13);
+ HashMap tmpMap = new HashMap(13);
Method[] methods = Naming.class.getMethods();
- for (Method method: methods)
+ for (int m = 0; m < methods.length; m++)
{
+ Method method = methods[m];
Long hash = new Long(MarshalledInvocation.calculateHash(method));
- map.put(hash, method);
+ tmpMap.put(hash, method);
}
- this.marshalledInvocationMapping = Collections.unmodifiableMap(map);
+ marshalledInvocationMapping = Collections.unmodifiableMap(tmpMap);
// share instance for in-vm discovery
- NamingContext.setHANamingServerForPartition(this.clusterPartition.getPartitionName(), this.theServer);
+ NamingContext.setHANamingServerForPartition(clusterPartition.getPartitionName(), theServer);
}
- @Override
protected void startService()
throws Exception
{
- this.log.debug("Obtaining the HAJNDI transport proxy");
- this.stub = this.getNamingProxy();
- this.theServer.setHAStub(this.stub);
- if (this.port >= 0)
+ log.debug("Obtaining the HAJNDI transport proxy");
+ stub = this.getNamingProxy();
+ this.theServer.setHAStub(stub);
+ if (port >= 0)
{
- this.log.debug("Starting HAJNDI bootstrap listener");
- this.initBootstrapListener();
+ log.debug("Starting HAJNDI bootstrap listener");
+ initBootstrapListener();
}
// Automatic Discovery for unconfigured clients
- if (this.adGroupAddress != null && this.discoveryDisabled == false)
+ if (adGroupAddress != null && discoveryDisabled == false)
{
try
{
- this.autoDiscovery = new AutomaticDiscovery();
- this.autoDiscovery.start();
- this.lookupPool.run(this.autoDiscovery);
+ autoDiscovery = new AutomaticDiscovery();
+ autoDiscovery.start();
+ lookupPool.run(autoDiscovery);
}
catch (Exception e)
{
- this.log.warn("Failed to start AutomaticDiscovery", e);
+ log.warn("Failed to start AutomaticDiscovery", e);
}
}
- this.log.debug("initializing HAJNDI");
- this.theServer.init();
+ log.debug("initializing HAJNDI");
+ theServer.init();
}
- @Override
protected void stopService() throws Exception
{
// un-share instance for in-vm discovery
- NamingContext.removeHANamingServerForPartition(this.clusterPartition.getPartitionName());
+ NamingContext.removeHANamingServerForPartition(clusterPartition.getPartitionName());
// Stop listener
- ServerSocket s = this.bootstrapSocket;
- this.bootstrapSocket = null;
+ ServerSocket s = bootstrapSocket;
+ bootstrapSocket = null;
if (s != null)
{
- this.log.debug("Closing the HAJNDI bootstrap listener");
+ log.debug("Closing the HAJNDI bootstrap listener");
s.close();
}
// Stop HAJNDI service
- this.log.debug("Stopping the HAJNDI service");
- this.theServer.stop();
+ log.debug("Stopping the HAJNDI service");
+ theServer.stop();
- this.log.debug("Stopping AutomaticDiscovery");
- if (this.autoDiscovery != null && this.discoveryDisabled == false)
- {
- this.autoDiscovery.stop();
- }
+ log.debug("Stopping AutomaticDiscovery");
+ if (autoDiscovery != null && discoveryDisabled == false)
+ autoDiscovery.stop();
}
- @Override
protected void destroyService() throws Exception
{
- this.log.debug("Destroying the HAJNDI service");
+ log.debug("Destroying the HAJNDI service");
// server may be null if service failed on startup
- if (this.theServer != null)
- {
- this.theServer.destroy();
- }
+ if (theServer != null)
+ theServer.destroy();
}
/**
@@ -427,7 +417,7 @@
if (invocation instanceof MarshalledInvocation)
{
MarshalledInvocation mi = (MarshalledInvocation) invocation;
- mi.setMethodMap(this.marshalledInvocationMapping);
+ mi.setMethodMap(marshalledInvocationMapping);
}
// Invoke the Naming method via reflection
Method method = invocation.getMethod();
@@ -435,17 +425,15 @@
Object value = null;
try
{
- value = method.invoke(this.theServer, args);
+ value = method.invoke(theServer, args);
}
catch (InvocationTargetException e)
{
Throwable t = e.getTargetException();
if (t instanceof Exception)
- {
throw (Exception) t;
- }
-
- throw new UndeclaredThrowableException(t, method.toString());
+ else
+ throw new UndeclaredThrowableException(t, method.toString());
}
return value;
@@ -460,36 +448,30 @@
try
{
// Get the default ServerSocketFactory is one was not specified
- if (this.jnpServerSocketFactory == null)
- {
- this.jnpServerSocketFactory = ServerSocketFactory.getDefault();
- }
- this.bootstrapSocket = this.jnpServerSocketFactory.createServerSocket(this.port, this.backlog, this.bindAddress);
+ if (jnpServerSocketFactory == null)
+ jnpServerSocketFactory = ServerSocketFactory.getDefault();
+ bootstrapSocket = jnpServerSocketFactory.createServerSocket(port, backlog, bindAddress);
// If an anonymous port was specified get the actual port used
- if (this.port == 0)
- {
- this.port = this.bootstrapSocket.getLocalPort();
- }
- String msg = "Started HAJNDI bootstrap; jnpPort=" + this.port
- + ", backlog=" + this.backlog + ", bindAddress=" + this.bindAddress;
- this.log.info(msg);
+ if (port == 0)
+ port = bootstrapSocket.getLocalPort();
+ String msg = "Started HAJNDI bootstrap; jnpPort=" + port
+ + ", backlog=" + backlog + ", bindAddress=" + bindAddress;
+ log.info(msg);
}
catch (IOException e)
{
- this.log.error("Could not start HAJNDI bootstrap listener on port " + this.port, e);
+ log.error("Could not start HAJNDI bootstrap listener on port " + port, e);
}
- if (this.lookupPool == null)
- {
- this.lookupPool = new BasicThreadPool("HANamingBootstrap Pool");
- }
+ if (lookupPool == null)
+ lookupPool = new BasicThreadPool("HANamingBootstrap Pool");
AcceptHandler handler = new AcceptHandler();
- this.lookupPool.run(handler);
+ lookupPool.run(handler);
}
// Protected -----------------------------------------------------
- protected HAPartition findHAPartitionWithName(String name)
+ protected HAPartition findHAPartitionWithName(String name) throws Exception
{
HAPartition result = null;
// Class name match does not work with the AOP proxy :(
@@ -500,12 +482,12 @@
QueryExp matchPartitionName = Query.match(Query.attr("PartitionName"),
Query.value(name));
QueryExp exp = Query.and(matchName, matchPartitionName);
- Set<?> mbeans = this.getServer().queryMBeans(null, exp);
+ Set mbeans = this.getServer().queryMBeans(null, exp);
if (mbeans != null && mbeans.size() > 0)
{
- for (Object mbean: mbeans)
+ for (Iterator iter = mbeans.iterator(); iter.hasNext();)
{
- ObjectInstance inst = (ObjectInstance) mbean;
+ ObjectInstance inst = (ObjectInstance) iter.next();
try
{
ClusterPartitionMBean cp =
@@ -516,10 +498,7 @@
result = cp.getHAPartition();
break;
}
- catch (Exception e)
- {
- // Ignore
- }
+ catch (Exception e) {}
}
}
@@ -534,7 +513,8 @@
*/
protected Naming getNamingProxy() throws Exception
{
- return (Naming) this.server.getAttribute(this.proxyFactory, "Proxy");
+ Naming proxy = (Naming) server.getAttribute(proxyFactory, "Proxy");
+ return proxy;
}
// Private -------------------------------------------------------
@@ -542,17 +522,17 @@
private class AutomaticDiscovery
implements Runnable
{
- private Logger log = Logger.getLogger(AutomaticDiscovery.class);
+ protected Logger log = Logger.getLogger(AutomaticDiscovery.class);
/** The socket for auto discovery requests */
- private MulticastSocket socket = null;
+ protected MulticastSocket socket = null;
/** The ha-jndi addres + ':' + port string */
- private byte[] ipAddress = null;
+ protected byte[] ipAddress = null;
/** The multicast group address */
- private InetAddress group = null;
- private boolean stopping = false;
- // Thread that is executing the run() method
- private Thread receiverThread = null;
- private boolean receiverStopped = true;
+ protected InetAddress group = null;
+ protected boolean stopping = false;
+ // Thread that is executing the run() method
+ protected Thread receiverThread = null;
+ protected boolean receiverStopped = true;
public AutomaticDiscovery() throws Exception
{
@@ -560,23 +540,21 @@
public void start() throws Exception
{
- this.stopping = false;
+ stopping = false;
// Use the jndi bind address if there is no discovery address
- if (DetachedHANamingService.this.discoveryBindAddress == null)
- {
- DetachedHANamingService.this.discoveryBindAddress = DetachedHANamingService.this.bindAddress;
- }
- this.socket = new MulticastSocket(DetachedHANamingService.this.adGroupPort);
+ if (discoveryBindAddress == null)
+ discoveryBindAddress = bindAddress;
+ socket = new MulticastSocket(adGroupPort);
// If there is a bind address valid, set the socket interface to it
- if (DetachedHANamingService.this.discoveryBindAddress != null && DetachedHANamingService.this.discoveryBindAddress.isAnyLocalAddress() == false)
+ if (discoveryBindAddress != null && discoveryBindAddress.isAnyLocalAddress() == false)
{
- this.socket.setInterface(DetachedHANamingService.this.discoveryBindAddress);
+ socket.setInterface(discoveryBindAddress);
}
- this.socket.setTimeToLive(DetachedHANamingService.this.autoDiscoveryTTL);
- this.group = InetAddress.getByName(DetachedHANamingService.this.adGroupAddress);
- this.socket.joinGroup(this.group);
+ socket.setTimeToLive(autoDiscoveryTTL);
+ group = InetAddress.getByName(adGroupAddress);
+ socket.joinGroup(group);
- String address = DetachedHANamingService.this.getBindAddress();
+ String address = getBindAddress();
/* An INADDR_ANY (0.0.0.0 || null) address is useless as the value
sent to a remote client so check for this and use the local host
address instead.
@@ -585,99 +563,87 @@
{
address = InetAddress.getLocalHost().getHostAddress();
}
- this.ipAddress = (address + ":" + DetachedHANamingService.this.port).getBytes();
+ ipAddress = (address + ":" + port).getBytes();
- this.log.info("Listening on " + this.socket.getInterface() + ":" + this.socket.getLocalPort()
- + ", group=" + DetachedHANamingService.this.adGroupAddress
- + ", HA-JNDI address=" + new String(this.ipAddress));
+ log.info("Listening on " + socket.getInterface() + ":" + socket.getLocalPort()
+ + ", group=" + adGroupAddress
+ + ", HA-JNDI address=" + new String(ipAddress));
}
public void stop()
{
try
{
- this.stopping = true;
+ stopping = true;
// JBAS-2834 -- try to stop the receiverThread
- if (this.receiverThread != null
- && this.receiverThread != Thread.currentThread()
- && this.receiverThread.isInterrupted() == false)
+ if (receiverThread != null
+ && receiverThread != Thread.currentThread()
+ && receiverThread.isInterrupted() == false)
{
// Give it a moment to die on its own (unlikely)
- this.receiverThread.join(5);
- if (!this.receiverStopped)
- {
- this.receiverThread.interrupt(); // kill it
- }
+ receiverThread.join(5);
+ if (!receiverStopped)
+ receiverThread.interrupt(); // kill it
}
- this.socket.leaveGroup(this.group);
- this.socket.close();
+ socket.leaveGroup(group);
+ socket.close();
}
catch (Exception ex)
{
- this.log.error("Stopping AutomaticDiscovery failed", ex);
+ log.error("Stopping AutomaticDiscovery failed", ex);
}
}
public void run()
{
- boolean trace = this.log.isTraceEnabled();
- this.log.debug("Discovery request thread begin");
+ boolean trace = log.isTraceEnabled();
+ log.debug("Discovery request thread begin");
// JBAS-2834 Cache a reference to this thread so stop()
// can interrupt it if necessary
- this.receiverThread = Thread.currentThread();
+ receiverThread = Thread.currentThread();
- this.receiverStopped = false;
+ receiverStopped = false;
// Wait for a datagram
while (true)
{
// Stopped by normal means
- if (this.stopping)
- {
+ if (stopping)
break;
- }
try
{
if (trace)
- {
- this.log.trace("HA-JNDI AutomaticDiscovery waiting for queries...");
- }
+ log.trace("HA-JNDI AutomaticDiscovery waiting for queries...");
byte[] buf = new byte[256];
DatagramPacket packet = new DatagramPacket(buf, buf.length);
- this.socket.receive(packet);
+ socket.receive(packet);
if (trace)
- {
- this.log.trace("HA-JNDI AutomaticDiscovery Packet received.");
- }
+ log.trace("HA-JNDI AutomaticDiscovery Packet received.");
// Queue the response to the thread pool
- DiscoveryRequestHandler handler = new DiscoveryRequestHandler(this.log,
- packet, this.socket, this.ipAddress);
- DetachedHANamingService.this.lookupPool.run(handler);
+ DiscoveryRequestHandler handler = new DiscoveryRequestHandler(log,
+ packet, socket, ipAddress);
+ lookupPool.run(handler);
if (trace)
- {
- this.log.trace("Queued DiscoveryRequestHandler");
- }
+ log.trace("Queued DiscoveryRequestHandler");
}
catch (Throwable t)
{
- if (this.stopping == false)
- {
- this.log.warn("Ignored error while processing HAJNDI discovery request:", t);
- }
+ if (stopping == false)
+ log.warn("Ignored error while processing HAJNDI discovery request:", t);
}
}
- this.receiverStopped = true;
- this.log.debug("Discovery request thread end");
+ receiverStopped = true;
+ log.debug("Discovery request thread end");
}
}
/**
* The class used as the runnable for writing the bootstrap stub
- */
+ */
private class DiscoveryRequestHandler implements Runnable
{
private Logger log;
@@ -695,105 +661,85 @@
}
public void run()
{
- boolean trace = this.log.isTraceEnabled();
+ boolean trace = log.isTraceEnabled();
if( trace )
- {
- this.log.trace("DiscoveryRequestHandler begin");
- }
+ log.trace("DiscoveryRequestHandler begin");
// Return the naming server IP address and port to the client
try
{
// See if the discovery is restricted to a particular parition
- String requestData = new String(this.packet.getData()).trim();
+ String requestData = new String(packet.getData()).trim();
if( trace )
- {
- this.log.trace("RequestData: "+requestData);
- }
+ log.trace("RequestData: "+requestData);
int colon = requestData.indexOf(':');
if (colon > 0)
{
// Check the partition name
String name = requestData.substring(colon + 1);
- if (name.equals(DetachedHANamingService.this.clusterPartition.getPartitionName()) == false)
+ if (name.equals(clusterPartition.getPartitionName()) == false)
{
- this.log.debug("Ignoring discovery request for partition: " + name);
+ log.debug("Ignoring discovery request for partition: " + name);
if( trace )
- {
- this.log.trace("DiscoveryRequestHandler end");
- }
+ log.trace("DiscoveryRequestHandler end");
return;
}
}
- DatagramPacket p = new DatagramPacket(this.ipAddress, this.ipAddress.length,
- this.packet.getAddress(), this.packet.getPort());
+ DatagramPacket p = new DatagramPacket(ipAddress, ipAddress.length,
+ packet.getAddress(), packet.getPort());
if (trace)
- {
- this.log.trace("Sending AutomaticDiscovery answer: " + new String(this.ipAddress) +
- " to " + this.packet.getAddress() + ":" + this.packet.getPort());
- }
- this.socket.send(p);
+ log.trace("Sending AutomaticDiscovery answer: " + new String(ipAddress) +
+ " to " + packet.getAddress() + ":" + packet.getPort());
+ socket.send(p);
if (trace)
- {
- this.log.trace("AutomaticDiscovery answer sent.");
- }
+ log.trace("AutomaticDiscovery answer sent.");
}
catch (IOException ex)
{
- this.log.error("Error writing response", ex);
- }
+ log.error("Error writing response", ex);
+ }
if( trace )
- {
- this.log.trace("DiscoveryRequestHandler end");
- }
+ log.trace("DiscoveryRequestHandler end");
}
}
/**
* The class used as the runnable for the bootstrap lookup thread pool.
- */
+ */
private class AcceptHandler implements Runnable
{
- AcceptHandler()
- {
- }
-
public void run()
{
- boolean trace = DetachedHANamingService.this.log.isTraceEnabled();
- while (DetachedHANamingService.this.bootstrapSocket != null)
+ boolean trace = log.isTraceEnabled();
+ while (bootstrapSocket != null)
{
Socket socket = null;
// Accept a connection
try
{
- socket = DetachedHANamingService.this.bootstrapSocket.accept();
- if (trace)
- {
- DetachedHANamingService.this.log.trace("Accepted bootstrap client: "+socket);
- }
+ socket = bootstrapSocket.accept();
+ if( trace )
+ log.trace("Accepted bootstrap client: "+socket);
BootstrapRequestHandler handler = new BootstrapRequestHandler(socket);
- DetachedHANamingService.this.lookupPool.run(handler);
+ lookupPool.run(handler);
}
catch (IOException e)
{
// Stopped by normal means
- if (DetachedHANamingService.this.bootstrapSocket == null)
- {
+ if (bootstrapSocket == null)
return;
- }
- DetachedHANamingService.this.log.error("Naming accept handler stopping", e);
+ log.error("Naming accept handler stopping", e);
}
catch(Throwable e)
{
- DetachedHANamingService.this.log.error("Unexpected exception during accept", e);
+ log.error("Unexpected exception during accept", e);
}
- }
+ }
}
}
/**
* The class used as the runnable for writing the bootstrap stub
- */
+ */
private class BootstrapRequestHandler implements Runnable
{
private Socket socket;
@@ -806,21 +752,21 @@
// Return the naming server stub
try
{
- OutputStream os = this.socket.getOutputStream();
+ OutputStream os = socket.getOutputStream();
ObjectOutputStream out = new ObjectOutputStream(os);
- MarshalledObject<Naming> replyStub = new MarshalledObject<Naming>(DetachedHANamingService.this.stub);
+ MarshalledObject replyStub = new MarshalledObject(stub);
out.writeObject(replyStub);
out.close();
}
catch (IOException ex)
{
- DetachedHANamingService.this.log.debug("Error writing response to " + this.socket, ex);
+ log.debug("Error writing response to " + socket, ex);
}
finally
{
try
{
- this.socket.close();
+ socket.close();
}
catch (IOException e)
{
Modified: trunk/cluster/src/main/org/jboss/ha/jndi/DetachedHANamingServiceMBean.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/jndi/DetachedHANamingServiceMBean.java 2008-06-17 18:06:55 UTC (rev 74706)
+++ trunk/cluster/src/main/org/jboss/ha/jndi/DetachedHANamingServiceMBean.java 2008-06-17 18:11:45 UTC (rev 74707)
@@ -21,11 +21,9 @@
*/
package org.jboss.ha.jndi;
-import java.lang.reflect.Method;
import java.net.UnknownHostException;
import java.util.Map;
import javax.management.ObjectName;
-import javax.naming.Binding;
import org.jboss.cache.Cache;
import org.jboss.ha.framework.interfaces.HAPartition;
@@ -69,14 +67,14 @@
*
* @return the cache
*/
- Cache<String, Binding> getClusteredCache();
+ Cache getClusteredCache();
/**
* Sets the underlying cache used by this service.
*
* @param cache the cache
*/
- void setClusteredCache(Cache<String, Binding> cache);
+ void setClusteredCache(Cache cache);
/** Get the proxy factory service name used to create the Naming transport
* proxy.
@@ -139,7 +137,8 @@
/** Set the auto-discovery bootstrap multicast bind address. If not specified
* and a BindAddress is specified, the BindAddress will be used.
*/
- void setAutoDiscoveryBindAddress(String adAddress) throws UnknownHostException;
+ void setAutoDiscoveryBindAddress(String adAddress)
+ throws UnknownHostException;
/** Get the TTL (time-to-live) for autodiscovery IP multicast packets */
int getAutoDiscoveryTTL();
@@ -159,7 +158,7 @@
*
* @return A Map<Long hash, Method> of the Naming interface
*/
- public Map<Long, Method> getMethodMap();
+ public Map getMethodMap();
/** Expose the Naming service via JMX for detached invokers.
*
Modified: trunk/cluster/src/main/org/jboss/ha/jndi/HAJNDI.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/jndi/HAJNDI.java 2008-06-17 18:06:55 UTC (rev 74706)
+++ trunk/cluster/src/main/org/jboss/ha/jndi/HAJNDI.java 2008-06-17 18:11:45 UTC (rev 74707)
@@ -23,17 +23,17 @@
import java.util.Collection;
-import javax.naming.Binding;
import javax.naming.Name;
-import javax.naming.NameClassPair;
import javax.naming.NamingException;
+import org.jnp.interfaces.Naming;
+
+import org.jboss.cache.Fqn;
import org.jboss.cache.Cache;
-import org.jboss.cache.Fqn;
import org.jboss.ha.framework.interfaces.HAPartition;
-import org.jnp.interfaces.Naming;
+import org.jboss.logging.Logger;
-/**
+/**
* This class utilizes JBossCache to provide a distributed JNDI implementation.
* Lookups will look for Names in HAJNDI then delegate to the local InitialContext.
*
@@ -48,56 +48,54 @@
static final long serialVersionUID = -6277328603304171620L;
public static final String ROOT = "__HA_JNDI__";
- public static final Fqn<String> ROOTFQN = new Fqn<String>(ROOT);
+ public static final Fqn ROOTFQN = new Fqn(new Object[] { ROOT });
// Attributes --------------------------------------------------------
- private HAPartition partition;
- private TreeHead delegate;
- private Naming haStub;
+ private static Logger log = Logger.getLogger(HAJNDI.class);
+
+ protected HAPartition partition;
+ protected TreeHead delegate;
+ protected Naming haStub;
- // Constructor --------------------------------------------------------
+ // Constructor --------------------------------------------------------
- public HAJNDI(HAPartition partition, Cache<String, Binding> cache)
+ public HAJNDI(HAPartition partition, Cache cache)
+ throws NamingException
{
if (partition == null)
- {
throw new IllegalArgumentException("Null partition");
- }
-
if (cache == null)
- {
throw new IllegalArgumentException("Null cache");
- }
-
this.partition = partition;
- this.delegate = new TreeHead(cache, HAJNDI.ROOTFQN);
- this.delegate.setPartition(this.partition);
- this.delegate.setHARMIHead(this);
+ delegate = new TreeHead(cache, HAJNDI.ROOTFQN);
+ delegate.setPartition(this.partition);
+ delegate.setHARMIHead(this);
+
}
// Public --------------------------------------------------------
- public void init()
+ public void init() throws Exception
{
- this.delegate.init();
+ delegate.init();
}
- public void stop()
+ public void stop() throws Exception
{
- this.delegate.stop();
+ delegate.stop();
}
- public void destroy()
+ public void destroy() throws Exception
{
- this.delegate.destroy();
+ delegate.destroy();
}
- public void setHAStub(Naming stub)
+ public void setHAStub (Naming stub)
{
this.haStub = stub;
}
- public Naming getHAStub()
+ public Naming getHAStub ()
{
return this.haStub;
}
@@ -105,38 +103,45 @@
// Naming implementation -----------------------------------------
- public synchronized void bind(Name name, Object obj, String className) throws NamingException
+ public synchronized void bind(Name name, Object obj, String className)
+ throws NamingException
{
- this.delegate.bind(name, obj, className);
+ delegate.bind (name, obj, className);
}
- public synchronized void rebind(Name name, Object obj, String className) throws NamingException
+ public synchronized void rebind(Name name, Object obj, String className)
+ throws NamingException
{
- this.delegate.rebind(name, obj, className);
+ delegate.rebind (name, obj, className);
}
- public synchronized void unbind(Name name) throws NamingException
+ public synchronized void unbind(Name name)
+ throws NamingException
{
- this.delegate.unbind(name);
+ delegate.unbind (name);
}
- public Object lookup(Name name) throws NamingException
+ public Object lookup(Name name)
+ throws NamingException
{
- return this.delegate.lookup(name);
+ return delegate.lookup (name);
}
- public Collection<NameClassPair> list(Name name) throws NamingException
+ public Collection list(Name name)
+ throws NamingException
{
- return this.delegate.list(name) ;
+ return delegate.list(name) ;
}
- public Collection<Binding> listBindings(Name name) throws NamingException
+ public Collection listBindings(Name name)
+ throws NamingException
{
- return this.delegate.listBindings(name);
+ return delegate.listBindings(name);
}
- public javax.naming.Context createSubcontext(Name name) throws NamingException
+ public javax.naming.Context createSubcontext(Name name)
+ throws NamingException
{
- return this.delegate.createSubcontext(name);
+ return delegate.createSubcontext(name);
}
}
Modified: trunk/cluster/src/main/org/jboss/ha/jndi/HANamingService.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/jndi/HANamingService.java 2008-06-17 18:06:55 UTC (rev 74706)
+++ trunk/cluster/src/main/org/jboss/ha/jndi/HANamingService.java 2008-06-17 18:11:45 UTC (rev 74707)
@@ -21,12 +21,12 @@
*/
package org.jboss.ha.jndi;
+import java.rmi.server.RMIServerSocketFactory;
import java.rmi.server.RMIClientSocketFactory;
-import java.rmi.server.RMIServerSocketFactory;
import org.jboss.ha.client.loadbalance.LoadBalancePolicy;
+import org.jboss.ha.framework.server.HARMIServerImpl;
import org.jboss.ha.framework.interfaces.RoundRobin;
-import org.jboss.ha.framework.server.HARMIServerImpl;
import org.jnp.interfaces.Naming;
/** Management Bean for HA-JNDI service for the legacy version that is coupled
@@ -46,20 +46,20 @@
// Attributes ----------------------------------------------------
/** An optional custom client socket factory */
- private RMIClientSocketFactory clientSocketFactory;
+ protected RMIClientSocketFactory clientSocketFactory;
/** An optional custom server socket factory */
- private RMIServerSocketFactory serverSocketFactory;
+ protected RMIServerSocketFactory serverSocketFactory;
/** The class name of the optional custom client socket factory */
- private String clientSocketFactoryName;
+ protected String clientSocketFactoryName;
/** The class name of the optional custom server socket factory */
- private String serverSocketFactoryName;
+ protected String serverSocketFactoryName;
/** The class name of the load balancing policy */
- private String loadBalancePolicy = RoundRobin.class.getName();
+ protected String loadBalancePolicy = RoundRobin.class.getName();
/** The RMI port on which the Naming implementation will be exported. The
default is 0 which means use any available port. */
- private int rmiPort = 0;
+ protected int rmiPort = 0;
protected String replicantName = "HAJNDI";
- private HARMIServerImpl rmiserver;
+ HARMIServerImpl rmiserver;
// Public --------------------------------------------------------
@@ -70,69 +70,69 @@
public void setRmiPort(int p)
{
- this.rmiPort = p;
+ rmiPort = p;
}
public int getRmiPort()
{
- return this.rmiPort;
+ return rmiPort;
}
public String getClientSocketFactory()
{
- return this.serverSocketFactoryName;
+ return serverSocketFactoryName;
}
-
public void setClientSocketFactory(String factoryClassName)
throws ClassNotFoundException, InstantiationException, IllegalAccessException
{
this.clientSocketFactoryName = factoryClassName;
ClassLoader loader = Thread.currentThread().getContextClassLoader();
- Class<?> clazz = loader.loadClass(this.clientSocketFactoryName);
- this.clientSocketFactory = (RMIClientSocketFactory) clazz.newInstance();
+ Class clazz = loader.loadClass(clientSocketFactoryName);
+ clientSocketFactory = (RMIClientSocketFactory) clazz.newInstance();
}
public String getServerSocketFactory()
{
- return this.serverSocketFactoryName;
+ return serverSocketFactoryName;
}
public void setServerSocketFactory(String factoryClassName)
throws ClassNotFoundException, InstantiationException, IllegalAccessException
{
this.serverSocketFactoryName = factoryClassName;
ClassLoader loader = Thread.currentThread().getContextClassLoader();
- Class<?> clazz = loader.loadClass(this.serverSocketFactoryName);
- this.serverSocketFactory = (RMIServerSocketFactory) clazz.newInstance();
+ Class clazz = loader.loadClass(serverSocketFactoryName);
+ serverSocketFactory = (RMIServerSocketFactory) clazz.newInstance();
}
public String getLoadBalancePolicy()
{
- return this.loadBalancePolicy;
+ return loadBalancePolicy;
}
public void setLoadBalancePolicy(String policyClassName)
{
- this.loadBalancePolicy = policyClassName;
+ loadBalancePolicy = policyClassName;
}
- @Override
protected void stopService() throws Exception
{
super.stopService();
// Unexport server
- this.log.debug("destroy ha rmiserver");
+ log.debug("destroy ha rmiserver");
this.rmiserver.destroy ();
}
- @Override
protected Naming getNamingProxy() throws Exception
{
- this.rmiserver = new HARMIServerImpl(this.clusterPartition, this.replicantName, Naming.class,
- this.theServer, this.rmiPort, this.clientSocketFactory, this.serverSocketFactory, this.bindAddress);
+ Class clazz;
+ LoadBalancePolicy policy;
+
+ rmiserver = new HARMIServerImpl(clusterPartition, replicantName, Naming.class,
+ theServer, rmiPort, clientSocketFactory, serverSocketFactory, bindAddress);
ClassLoader cl = Thread.currentThread().getContextClassLoader();
- Class<?> clazz = cl.loadClass(this.loadBalancePolicy);
- LoadBalancePolicy policy = (LoadBalancePolicy)clazz.newInstance();
+ clazz = cl.loadClass(loadBalancePolicy);
+ policy = (LoadBalancePolicy)clazz.newInstance();
- Naming proxy = (Naming) this.rmiserver.createHAStub(policy);
+ Naming proxy = (Naming) rmiserver.createHAStub(policy);
return proxy;
}
}
Modified: trunk/cluster/src/main/org/jboss/ha/jndi/TreeHead.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/jndi/TreeHead.java 2008-06-17 18:06:55 UTC (rev 74706)
+++ trunk/cluster/src/main/org/jboss/ha/jndi/TreeHead.java 2008-06-17 18:11:45 UTC (rev 74707)
@@ -21,13 +21,14 @@
*/
package org.jboss.ha.jndi;
+import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
-import java.util.LinkedList;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.Vector;
import javax.naming.Binding;
import javax.naming.Context;
@@ -63,84 +64,82 @@
static final long serialVersionUID = 6342802270002172451L;
private static final NamingParser parser = new NamingParser();
- private final Fqn<String> m_root;
+ private final Fqn m_root;
// Attributes --------------------------------------------------------
private static Logger log = Logger.getLogger(TreeHead.class);
- private Cache<String, Binding> m_cache;
+ private Cache m_cache;
private transient HAPartition partition;
private transient HAJNDI father;
// Constructor --------------------------------------------------------
- public TreeHead(Cache<String, Binding> cache, Fqn<String> root)
+ public TreeHead (Cache cache, Fqn root)
+ throws NamingException
{
super();
- this.m_cache = cache;
- this.m_root = root;
+ m_cache = cache;
+ m_root = root;
}
// Public --------------------------------------------------------
- public void init()
+ public void init() throws Exception
{
log.debug("HAJNDI registering RPC Handler with HAPartition");
- this.partition.registerRPCHandler("HAJNDI", this);
+ partition.registerRPCHandler("HAJNDI", this);
log.debug("initializing HAJNDITreeCache root");
- this.putTreeRoot();
+ putTreeRoot();
}
- public void stop()
+ public void stop() throws Exception
{
}
- public void destroy()
+ public void destroy() throws Exception
{
log.debug("HAJNDI unregistering RPCHandler with HAPartition");
- this.partition.unregisterRPCHandler("HAJNDI", this);
+ partition.unregisterRPCHandler("HAJNDI", this);
}
- public void setPartition(HAPartition partition)
+ public void setPartition (HAPartition partition)
{
this.partition = partition;
}
- public void setHARMIHead(HAJNDI father)
+ public void setHARMIHead (HAJNDI father)
{
this.father = father;
}
// Naming implementation -----------------------------------------
- public void bind(Name name, Object obj, String className) throws NamingException
+ public void bind(Name name, Object obj, String className)
+ throws NamingException
{
- if (log.isTraceEnabled())
- {
+ if( log.isTraceEnabled() )
log.trace("bind, name="+name);
- }
- this.internalBind(name, obj, className, false);
+ internalBind(name, obj, className, false);
}
- public void rebind(Name name, Object obj, String className) throws NamingException
+ public void rebind(Name name, Object obj, String className)
+ throws NamingException
{
- if (log.isTraceEnabled())
- {
+ if( log.isTraceEnabled() )
log.trace("rebind, name="+name);
- }
- this.internalBind(name, obj, className, true);
+ internalBind(name, obj, className, true);
}
- public void unbind(Name name) throws NamingException
+ public void unbind(Name name)
+ throws NamingException
{
- if (log.isTraceEnabled())
- {
+ if( log.isTraceEnabled() )
log.trace("unbind, name="+name);
- }
if (name.isEmpty())
{
// Empty names are not allowed
@@ -150,131 +149,130 @@
// is the name a context?
try
{
- Fqn<String> temp = new Fqn<String>(this.m_root, Fqn.fromString(name.toString()));
+ Fqn temp = new Fqn(m_root, Fqn.fromString(name.toString()));
// TODO why not jst call remove -- why hasChild first?
- if (this.m_cache.getRoot().hasChild(temp))
+ if (m_cache.getRoot().hasChild(temp))
{
- this.m_cache.removeNode(temp);
+ m_cache.removeNode(temp);
return;
}
- }
- catch (CacheException ce)
+ } catch (CacheException ce)
{
- // don't chain CacheException since JBoss Cache may not be on remote client's classpath
+ // don't chain CacheException since JBoss Cache may not be on remote client's classpath
NamingException ne = new NamingException(ce.getClass().getName() + ": " + ce.getMessage());
ne.setStackTrace(ce.getStackTrace());
throw ne;
}
- int size = name.size();
+ int size = name.size();
// get the context and key
- Fqn<String> ctx;
+ Fqn ctx;
String key = name.get(size - 1);
if (size > 1) // find subcontext to which the key is bound
- {
+ {
String prefix = name.getPrefix(size - 1).toString();
- Fqn<String> fqn = Fqn.fromString(prefix);
- ctx = new Fqn<String>(this.m_root, fqn);
+ Fqn fqn = Fqn.fromString(prefix);
+ ctx = new Fqn(m_root, fqn);
}
else
- {
- ctx = this.m_root;
- }
+ ctx = m_root;
try
{
- Object removed = this.m_cache.remove(ctx, key);
+ Object removed = m_cache.remove(ctx, key);
if (removed == null)
{
- if (!this.m_cache.getRoot().hasChild(ctx))
+ if (!m_cache.getRoot().hasChild(ctx))
{
- throw new NotContextException(name.getPrefix(size - 1).toString() + " not a context");
+ throw new NotContextException(name.getPrefix(size - 1).toString() + " not a context");
}
-
- throw new NameNotFoundException(key + " not bound");
+ else
+ {
+ throw new NameNotFoundException(key + " not bound");
+ }
}
- }
- catch (CacheException ce)
+ } catch (CacheException ce)
{
- // don't chain CacheException since JBoss Cache may not be on remote client's classpath
+ // don't chain CacheException since JBoss Cache may not be on remote client's classpath
NamingException ne = new NamingException(ce.getClass().getName() + ": " + ce.getMessage());
ne.setStackTrace(ce.getStackTrace());
throw ne;
}
}
- public Object lookup(Name name) throws NamingException
+ public Object lookup(Name name)
+ throws NamingException
{
boolean trace = log.isTraceEnabled();
- if (trace)
- {
+ if( trace )
log.trace("lookup, name="+name);
- }
+ Object result = null;
if (name.isEmpty())
{
- // Return this
- return new NamingContext(null, parser.parse(""), this.getRoot());
+ // Return this
+ return new NamingContext(null, (Name)(parser.parse("")), getRoot());
}
// is the name a context?
try
{
- Node<String, Binding> n = this.m_cache.getRoot().getChild(new Fqn<String>(this.m_root, Fqn.fromString(name.toString())));
+ Node n = m_cache.getRoot().getChild(new Fqn(m_root, Fqn.fromString(name.toString())));
if (n != null)
{
- Name fullName = (Name) name.clone();
- return new NamingContext(null, fullName, this.getRoot());
+ Name fullName = (Name)(name.clone());
+ return new NamingContext(null, fullName, getRoot());
}
- }
- catch (CacheException ce)
+ } catch (CacheException ce)
{
- // don't chain CacheException since JBoss Cache may not be on remote client's classpath
+ // don't chain CacheException since JBoss Cache may not be on remote client's classpath
NamingException ne = new NamingException(ce.getClass().getName() + ": " + ce.getMessage());
ne.setStackTrace(ce.getStackTrace());
throw ne;
}
- int size = name.size();
+ int size = name.size();
// get the context and key
- Fqn<String> ctx;
+ Fqn ctx;
String key = name.get(size - 1);
if (size > 1) // find subcontext to which the key is bound
- {
+ {
String prefix = name.getPrefix(size - 1).toString();
- Fqn<String> fqn = Fqn.fromString(prefix);
- ctx = new Fqn<String>(this.m_root, fqn);
+ Fqn fqn = Fqn.fromString(prefix);
+ ctx = new Fqn(m_root, fqn);
}
else
- {
- ctx = this.m_root;
- }
+ ctx = m_root;
try
{
- Binding b = this.m_cache.get(ctx, key);
-
- // if key not in cache, try local naming server
- return (b != null) ? b.getObject() : this.internalLookupLocally(name);
- }
- catch (CacheException ce)
+ Binding b = (Binding)m_cache.get(ctx, key);
+ if (b != null)
+ {
+ result = b.getObject();
+ }
+ else
+ {
+ // key not in cache, try local naming server
+ result = internalLookupLocally(name);
+ }
+ } catch (CacheException ce)
{
- // don't chain CacheException since JBoss Cache may not be on remote client's classpath
+ // don't chain CacheException since JBoss Cache may not be on remote client's classpath
NamingException ne = new NamingException(ce.getClass().getName() + ": " + ce.getMessage());
ne.setStackTrace(ce.getStackTrace());
throw ne;
}
+ return result;
}
public Object lookupLocally(Name name) throws NamingException
{
boolean trace = log.isTraceEnabled();
- if (trace)
- {
+ if( trace )
log.trace("lookupLocally, name="+name);
- }
// TODO: This is a really big hack here
// We cannot do InitialContext().lookup(name) because
@@ -286,15 +284,16 @@
{
return NamingContext.localServer.lookup(name);
}
-
- return new InitialContext().lookup(name);
+ else
+ {
+ InitialContext ctx = new InitialContext();
+ return ctx.lookup(name);
+ }
}
catch (NamingException e)
{
- if (trace)
- {
+ if( trace )
log.trace("lookupLocally failed, name=" + name, e);
- }
throw e;
}
catch (java.rmi.RemoteException e)
@@ -302,244 +301,230 @@
NamingException ne = new NamingException("unknown remote exception");
ne.setRootCause(e);
if( trace )
- {
log.trace("lookupLocally failed, name=" + name, e);
- }
throw ne;
}
catch (RuntimeException e)
{
- if (trace)
- {
+ if( trace )
log.trace("lookupLocally failed, name=" + name, e);
- }
throw e;
}
}
- public Collection<NameClassPair> list(Name name) throws NamingException
+ public Collection list(Name name)
+ throws NamingException
{
- if (log.isTraceEnabled())
- {
+ if( log.isTraceEnabled() )
log.trace("list, name="+name);
- }
+ Collection result = null;
// get the context
- Fqn<String> ctx;
+ Fqn ctx;
String ctxName = "";
int size = name.size();
if (size >= 1)
- {
+ {
ctxName = name.toString();
- Fqn<String> fqn = Fqn.fromString(ctxName);
- ctx = new Fqn<String>(this.m_root, fqn);
+ Fqn fqn = Fqn.fromString(ctxName);
+ ctx = new Fqn(m_root, fqn);
}
else
- {
- ctx = this.m_root;
- }
+ ctx = m_root;
- boolean exists = this.m_cache.getRoot().hasChild(ctx);
+ boolean exists = m_cache.getRoot().hasChild(ctx);
if (!exists)
- {
+ {
try
{
- return Collections.list(new InitialContext().list(name));
- }
- catch (NamingException e)
+ return enum2list(new InitialContext().list(name));
+ } catch (NamingException e)
{
throw new NotContextException(ctxName+ " not a context");
}
}
-
+
+ Vector list = null;
try
{
- List<NameClassPair> list = new LinkedList<NameClassPair>();
+ list = new Vector();
- Node<String, Binding> base = this.m_cache.getRoot().getChild(ctx);
+ Node base = m_cache.getRoot().getChild(ctx);
if (base != null)
{
- for (Binding b: base.getData().values())
- {
- list.add(new NameClassPair(b.getName(),b.getClassName(),true));
+ Map data = base.getData();
+ for (Iterator it = data.values().iterator(); it.hasNext();)
+ {
+ Binding b = (Binding) it.next();
+ list.addElement(new NameClassPair(b.getName(),b.getClassName(),true));
}
- // Why doesn't this return Set<String>?
- Set<Object> children = base.getChildrenNames();
+ Set children = base.getChildrenNames();
if (children != null && !children.isEmpty())
{
- for (Object child: children)
- {
- String node = (String) child;
- Name fullName = (Name) name.clone();
- fullName.add(node);
- list.add(new NameClassPair(node, NamingContext.class.getName(),true));
+ Iterator iter2 = children.iterator();
+ while (iter2.hasNext()) {
+ String node = (String)iter2.next();
+ Name fullName = (Name)(name.clone());
+ fullName.add(node);
+ list.addElement(new NameClassPair(node, NamingContext.class.getName(),true));
}
}
}
-
- return list;
- }
- catch (CacheException ce)
+ } catch (CacheException ce)
{
- // don't chain CacheException since JBoss Cache may not be on remote client's classpath
+ // don't chain CacheException since JBoss Cache may not be on remote client's classpath
NamingException ne = new NamingException(ce.getClass().getName() + ": " + ce.getMessage());
ne.setStackTrace(ce.getStackTrace());
throw ne;
}
+ return list;
}
- public Collection<Binding> listBindings(Name name) throws NamingException
+ public Collection listBindings(Name name)
+ throws NamingException
{
- if (log.isTraceEnabled())
- {
+ if( log.isTraceEnabled() )
log.trace("listBindings, name="+name);
- }
// get the context
- Fqn<String> ctx;
+ Fqn ctx;
String ctxName = "";
int size = name.size();
if (size >= 1)
- {
+ {
ctxName = name.toString();
- Fqn<String> fqn = Fqn.fromString(ctxName);
- ctx = new Fqn<String>(this.m_root, fqn);
+ Fqn fqn = Fqn.fromString(ctxName);
+ ctx = new Fqn(m_root, fqn);
}
else
- {
- ctx = this.m_root;
- }
+ ctx = m_root;
- boolean exists = this.m_cache.getRoot().hasChild(ctx);
+ boolean exists = m_cache.getRoot().hasChild(ctx);
if (!exists)
{
// not found in global jndi, look in local.
try
{
- return Collections.list(new InitialContext().listBindings(name));
- }
- catch (NamingException e)
+ return enum2list(new InitialContext().listBindings(name));
+ } catch (NamingException e)
{
throw new NotContextException(ctxName+ " not a context");
}
}
-
+
+ Vector list = null;
try
{
- List<Binding> list = new LinkedList<Binding>();
+ list = new Vector();
- Node<String, Binding> node = this.m_cache.getRoot().getChild(ctx);
+ Node node = m_cache.getRoot().getChild(ctx);
if (node != null)
{
- Map<String, Binding> data = node.getData();
- if (data != null && !data.isEmpty())
+ Map data = node.getData();
+ if (data != null && data.size() > 0)
{
list.addAll(data.values());
}
- // Why doesn't this return Set<String>?
- Set<Object> children = node.getChildrenNames();
+ Set children = node.getChildrenNames();
if (children != null && !children.isEmpty())
{
- for (Object obj: children)
- {
- String child = (String) obj;
- Name fullName = (Name) name.clone();
- fullName.add(child);
- NamingContext subCtx = new NamingContext(null, fullName, this.getRoot());
- list.add(new Binding(child, NamingContext.class.getName(), subCtx, true));
+ Iterator iter2 = children.iterator();
+ while (iter2.hasNext()) {
+ String child = (String)iter2.next();
+ Name fullName = (Name)(name.clone());
+ fullName.add(child);
+ NamingContext subCtx = new NamingContext(null, fullName, getRoot());
+ Binding b = new Binding(child, NamingContext.class.getName(), subCtx, true);
+ list.addElement(b);
}
}
}
-
- return list;
- }
- catch (CacheException ce)
+ } catch (CacheException ce)
{
- // don't chain CacheException since JBoss Cache may not be on remote client's classpath
+ // don't chain CacheException since JBoss Cache may not be on remote client's classpath
NamingException ne = new NamingException(ce.getClass().getName() + ": " + ce.getMessage());
ne.setStackTrace(ce.getStackTrace());
throw ne;
}
+ return list;
}
- public Context createSubcontext(Name name) throws NamingException
+ public javax.naming.Context createSubcontext(Name name)
+ throws NamingException
{
- if (log.isTraceEnabled())
- {
- log.trace("createSubcontext, name="+name);
- }
+ if( log.isTraceEnabled() )
+ log.trace("createSubcontext, name="+name);
int size = name.size();
-
- if (size == 0)
- {
+ if( size == 0 )
throw new InvalidNameException("Cannot pass an empty name to createSubcontext");
- }
- // does the new context already exist?
- String str = name.toString();
- Fqn<String> fqn = Fqn.fromString(str);
- Fqn<String> ctx = new Fqn<String>(this.m_root, fqn);
- if (this.m_cache.getRoot().hasChild(ctx))
- {
- throw new NameAlreadyBoundException();
- }
-
- // does the prefix context already exist?
- Fqn<String> pctx;
- String newctx = name.get(size - 1);
- if (size > 1) // find subcontext to which the context will be added
- {
- String prefix = name.getPrefix(size - 1).toString();
- Fqn<String> fqn2 = Fqn.fromString(prefix);
- pctx = new Fqn<String>(this.m_root, fqn2);
- }
- else
- {
- pctx = this.m_root;
- }
-
- boolean exists = this.m_cache.getRoot().hasChild(pctx);
- if (!exists)
- {
- throw new NotContextException(name.getPrefix(size - 1).toString());
- }
+ Context subCtx = null;
+
+ // does the new context already exist?
+ String str = name.toString();
+ Fqn fqn = Fqn.fromString(str);
+ Fqn ctx = new Fqn(m_root, fqn);
+ if (m_cache.getRoot().hasChild(ctx))
+ {
+ throw new NameAlreadyBoundException();
+ }
+
+ // does the prefix context already exist?
+ Fqn pctx;
+ String newctx = name.get(size - 1);
+ if (size > 1) // find subcontext to which the context will be added
+ {
+ String prefix = name.getPrefix(size - 1).toString();
+ Fqn fqn2 = Fqn.fromString(prefix);
+ pctx = new Fqn(m_root, fqn2);
+ }
+ else
+ pctx = m_root;
+
+ boolean exists = m_cache.getRoot().hasChild(pctx);
+ if (!exists)
+ {
+ throw new NotContextException(name.getPrefix(size - 1).toString());
+ }
- Fqn<String> newf = new Fqn<String>(pctx, Fqn.fromString(newctx));
- try
- {
- this.m_cache.put(newf, new HashMap<String, Binding>());
- }
- catch (CacheException ce)
- {
- // don't chain CacheException since JBoss Cache may not be on remote client's classpath
- NamingException ne = new NamingException(ce.getClass().getName() + ": " + ce.getMessage());
- ne.setStackTrace(ce.getStackTrace());
- throw ne;
- }
+ Fqn newf = new Fqn(pctx, Fqn.fromString(newctx));
+ try
+ {
+ m_cache.put(newf, new HashMap());
+ } catch (CacheException ce)
+ {
+ // don't chain CacheException since JBoss Cache may not be on remote client's classpath
+ NamingException ne = new NamingException(ce.getClass().getName() + ": " + ce.getMessage());
+ ne.setStackTrace(ce.getStackTrace());
+ throw ne;
+ }
- Name fullName = parser.parse("");
- fullName.addAll(name);
-
- return new NamingContext(null, fullName, this.getRoot());
+ Name fullName = (Name) parser.parse("");
+ fullName.addAll(name);
+ subCtx = new NamingContext(null, fullName, getRoot());
+
+ return subCtx;
}
- public Naming getRoot()
+ public Naming getRoot ()
{
- return this.father.getHAStub();
+ return father.getHAStub();
}
- private void putTreeRoot() throws CacheException
- {
- if (!this.m_cache.getRoot().hasChild(this.m_root))
- {
- this.m_cache.put(this.m_root, null);
+ private void putTreeRoot()
+ throws CacheException
+ {
+ if (!m_cache.getRoot().hasChild(m_root))
+ {
+ m_cache.put(m_root, null);
}
- }
+ }
- private void internalBind(Name name, Object obj, String className, boolean rebind) throws NamingException
+ private void internalBind(Name name, Object obj, String className, boolean rebind)
+ throws NamingException
{
if (name.isEmpty())
{ // Empty names are not allowed
@@ -547,78 +532,76 @@
}
int size = name.size();
-
+
// get the context and key
- Fqn<String> ctx;
+ Fqn ctx;
String key = name.get(size - 1);
if (size > 1) // find subcontext to which the key will be added
- {
+ {
String prefix = name.getPrefix(size - 1).toString();
- Fqn<String> fqn = Fqn.fromString(prefix);
- ctx = new Fqn<String>(this.m_root, fqn);
+ Fqn fqn = Fqn.fromString(prefix);
+ ctx = new Fqn(m_root, fqn);
}
else
- {
- ctx = this.m_root;
- }
+ ctx = m_root;
- boolean exists = this.m_cache.getRoot().hasChild(ctx);
+ boolean exists = m_cache.getRoot().hasChild(ctx);
if (!exists)
{
throw new NotContextException(name.getPrefix(size - 1).toString() + " not a context");
- // note - NamingServer throws a CannotProceedException if the client attempts to bind
+ // note - NamingServer throws a CannotProceedException if the client attempts to bind
// to a Reference object having an "nns" address. This implementation simply
// throws the NotContextException that's used when "nns" isn't present.
}
if (!rebind)
{
- Node<String, Binding> node = this.m_cache.getRoot().getChild(ctx);
- if ((node != null) && (node.get(key) != null))
+ Node node = m_cache.getRoot().getChild(ctx);
+ if (node != null && (node.get(key) != null))
{
throw new NameAlreadyBoundException(key);
}
}
-
- this.m_cache.put(ctx, key, new Binding(key, className, obj, true));
+ try {
+ m_cache.put(ctx, key, new Binding(key, className, obj, true));
+ }
+ catch (Exception e)
+ {
+ System.out.println(e.toString());
+ }
}
- private Object internalLookupLocally(Name name) throws NamingException
+ private Object internalLookupLocally(Name name)
+ throws NamingException
{
boolean trace = log.isTraceEnabled();
-
+ Object result = null;
try
{
// not found in global jndi, look in local.
- return this.lookupLocally(name);
+ result = lookupLocally(name);
}
catch (NameNotFoundException nnfe)
{
// if we get here, this means we need to try on every node.
Object[] args = new Object[1];
args[0] = name;
- List<?> rsp = null;
+ List rsp = null;
Exception cause = null;
try
{
- if (trace)
- {
+ if( trace )
log.trace("calling lookupLocally(" + name + ") on HAJNDI cluster");
- }
- rsp = this.partition.callMethodOnCluster("HAJNDI", "lookupLocally", args, new Class[] { Name.class }, true);
+ rsp = partition.callMethodOnCluster("HAJNDI", "lookupLocally", args, new Class[]{Name.class}, true);
}
catch (Exception ignored)
{
- if (trace)
- {
+ if( trace )
log.trace("Clustered lookupLocally("+name+") failed", ignored);
- }
cause = ignored;
}
- if (trace)
- {
+ if( trace )
log.trace("Returned results size: "+ (rsp != null ? rsp.size() : 0));
- }
if (rsp == null || rsp.size() == 0)
{
NameNotFoundException nnfe2 = new NameNotFoundException(name.toString());
@@ -628,19 +611,33 @@
for (int i = 0; i < rsp.size(); i++)
{
- Object result = rsp.get(i);
- if (trace)
+ result = rsp.get(i);
+ if( trace )
{
String type = (result != null ? result.getClass().getName() : "null");
log.trace("lookupLocally, i="+i+", value="+result+", type="+type);
}
// Ignore null and Exception return values
- if ((result != null) && !(result instanceof Exception))
- {
+ if ( result != null && !(result instanceof Exception) )
return result;
- }
}
throw nnfe;
}
+ return result;
}
+
+ private ArrayList enum2list (javax.naming.NamingEnumeration en)
+ {
+ ArrayList rtn = new ArrayList();
+ try
+ {
+ while (en.hasMore())
+ {
+ rtn.add(en.next());
+ }
+ en.close();
+ }
+ catch (NamingException ignored) {}
+ return rtn;
+ }
}
More information about the jboss-cvs-commits
mailing list