Fields Summary |
---|
protected ServerSocket | bootstrapSocketThe jnp server socket through which the HAJNDI stub is vended |
protected HAJNDI | theServerThe Naming interface server implementation |
protected Map | marshalledInvocationMappingThe mapping from the long method hash to the Naming Method |
protected org.jnp.interfaces.Naming | stubThe protocol stub returned to clients by the bootstrap lookup |
protected org.jboss.ha.framework.interfaces.HAPartition | partitionThe HAPartition used for the state transfer service |
protected org.jboss.ha.framework.server.ClusterPartitionMBean | clusterPartitionThe ClusterPartition with which we are associated. |
protected String | partitionNameThe partition name used to lookup the HAPartition binding |
private ObjectName | proxyFactoryThe proxy factory service that generates the Naming stub |
protected InetAddress | bindAddressThe interface to bind to. This is useful for multi-homed hosts that want
control over which interfaces accept connections. |
protected int | backlogThe bootstrapSocket listen queue depth |
protected int | portThe jnp protocol listening port. The default is 1100, the same as the RMI
registry default port. |
protected String | adGroupAddressThe autodiscovery multicast group |
protected int | adGroupPortThe autodiscovery port |
protected InetAddress | discoveryBindAddressThe interface to bind the Multicast socket for autodiscovery to |
protected AutomaticDiscovery | autoDiscoveryThe runable task for discovery request packets |
protected boolean | discoveryDisabledA flag indicating if autodiscovery should be disabled |
protected int | autoDiscoveryTTLThe autodiscovery Multicast reply TTL |
protected ServerSocketFactory | jnpServerSocketFactoryAn optional custom server socket factory for the bootstrap lookup |
protected String | jnpServerSocketFactoryNameThe class name of the optional custom JNP server socket factory |
protected org.jboss.util.threadpool.ThreadPool | lookupPoolThe thread pool used to handle jnp stub lookup requests |
Methods Summary |
---|
protected void | createService()
boolean debug = log.isDebugEnabled();
if (this.clusterPartition == null)
{
partition = findHAPartitionWithName(partitionName);
}
else
{
partition = clusterPartition.getHAPartition();
partitionName = partition.getPartitionName();
}
if (partition == null)
throw new IllegalStateException("Cannot find partition '" + partitionName + "'");
if (debug)
log.debug("Initializing HAJNDI server on partition: " + partitionName);
// Start HAJNDI service
theServer = new HAJNDI(partition);
log.debug("initialize HAJNDI");
theServer.init();
// Build the Naming interface method map
HashMap tmpMap = new HashMap(13);
Method[] methods = Naming.class.getMethods();
for (int m = 0; m < methods.length; m++)
{
Method method = methods[m];
Long hash = new Long(MarshalledInvocation.calculateHash(method));
tmpMap.put(hash, method);
}
marshalledInvocationMapping = Collections.unmodifiableMap(tmpMap);
// share instance for in-vm discovery
NamingContext.setHANamingServerForPartition(partitionName, theServer);
|
protected void | destroyService()
log.debug("Destroying the HAJNDI service");
theServer.destroy();
|
protected org.jboss.ha.framework.interfaces.HAPartition | findHAPartitionWithName(java.lang.String name)
HAPartition result = null;
QueryExp exp = Query.and(Query.eq(Query.classattr(),
Query.value(ClusterPartition.class.getName())),
Query.match(Query.attr("PartitionName"),
Query.value(name)));
Set mbeans = this.getServer().queryMBeans(null, exp);
if (mbeans != null && mbeans.size() > 0)
{
ObjectInstance inst = (ObjectInstance) (mbeans.iterator().next());
ClusterPartitionMBean cp = (ClusterPartitionMBean) MBeanProxyExt.create(ClusterPartitionMBean.class,
inst.getObjectName(),
this.getServer());
result = cp.getHAPartition();
}
return result;
|
public java.lang.String | getAutoDiscoveryAddress()
return this.adGroupAddress;
|
public java.lang.String | getAutoDiscoveryBindAddress()
String address = null;
if (discoveryBindAddress != null)
address = discoveryBindAddress.getHostAddress();
return address;
|
public int | getAutoDiscoveryGroup()
return this.adGroupPort;
|
public int | getAutoDiscoveryTTL()
return autoDiscoveryTTL;
|
public int | getBacklog()
return backlog;
|
public java.lang.String | getBindAddress()
String address = null;
if (bindAddress != null)
address = bindAddress.getHostAddress();
return address;
|
public org.jboss.ha.framework.server.ClusterPartitionMBean | getClusterPartition()
return clusterPartition;
|
public boolean | getDiscoveryDisabled()
return this.discoveryDisabled;
|
public java.util.Map | getMethodMap()Expose the Naming service interface mapping as a read-only attribute
return marshalledInvocationMapping;
|
protected org.jnp.interfaces.Naming | getNamingProxy()Get the Naming proxy for the transport. This version looks up the
proxyFactory service Proxy attribute. Subclasses can override this to set
the proxy another way.
Naming proxy = (Naming) server.getAttribute(proxyFactory, "Proxy");
return proxy;
|
public java.lang.String | getPartitionName()
return partitionName;
|
public int | getPort()
return port;
|
public javax.management.ObjectName | getProxyFactoryObjectName()
return proxyFactory;
|
protected void | initBootstrapListener()Bring up the bootstrap lookup port for obtaining the naming service proxy
// Start listener
try
{
// Get the default ServerSocketFactory is one was not specified
if (jnpServerSocketFactory == null)
jnpServerSocketFactory = ServerSocketFactory.getDefault();
bootstrapSocket = jnpServerSocketFactory.createServerSocket(port, backlog, bindAddress);
// If an anonymous port was specified get the actual port used
if (port == 0)
port = bootstrapSocket.getLocalPort();
String msg = "Started ha-jndi bootstrap jnpPort=" + port
+ ", backlog=" + backlog + ", bindAddress=" + bindAddress;
log.info(msg);
}
catch (IOException e)
{
log.error("Could not start on port " + port, e);
}
if (lookupPool == null)
lookupPool = new BasicThreadPool("HANamingBootstrap Pool");
AcceptHandler handler = new AcceptHandler();
lookupPool.run(handler);
|
public java.lang.Object | invoke(org.jboss.invocation.Invocation invocation)Expose the Naming service via JMX to invokers.
// Set the method hash to Method mapping
if (invocation instanceof MarshalledInvocation)
{
MarshalledInvocation mi = (MarshalledInvocation) invocation;
mi.setMethodMap(marshalledInvocationMapping);
}
// Invoke the Naming method via reflection
Method method = invocation.getMethod();
Object[] args = invocation.getArguments();
Object value = null;
try
{
value = method.invoke(theServer, args);
}
catch (InvocationTargetException e)
{
Throwable t = e.getTargetException();
if (t instanceof Exception)
throw (Exception) t;
else
throw new UndeclaredThrowableException(t, method.toString());
}
return value;
|
public void | setAutoDiscoveryAddress(java.lang.String adAddress)
this.adGroupAddress = adAddress;
|
public void | setAutoDiscoveryBindAddress(java.lang.String address)
discoveryBindAddress = InetAddress.getByName(address);
|
public void | setAutoDiscoveryGroup(int adGroup)
this.adGroupPort = adGroup;
|
public void | setAutoDiscoveryTTL(int ttl)
autoDiscoveryTTL = ttl;
|
public void | setBacklog(int backlog)
if (backlog <= 0)
backlog = 50;
this.backlog = backlog;
|
public void | setBindAddress(java.lang.String host)
bindAddress = InetAddress.getByName(host);
|
public void | setClusterPartition(org.jboss.ha.framework.server.ClusterPartitionMBean clusterPartition)
this.clusterPartition = clusterPartition;
|
public void | setDiscoveryDisabled(boolean disable)
this.discoveryDisabled = disable;
|
public void | setJNPServerSocketFactory(java.lang.String factoryClassName)
this.jnpServerSocketFactoryName = factoryClassName;
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Class clazz = loader.loadClass(jnpServerSocketFactoryName);
jnpServerSocketFactory = (ServerSocketFactory) clazz.newInstance();
|
public void | setLookupPool(org.jboss.util.threadpool.BasicThreadPoolMBean poolMBean)
lookupPool = poolMBean.getInstance();
|
public void | setPartitionName(java.lang.String partitionName)
this.partitionName = partitionName;
|
public void | setPort(int p)
port = p;
|
public void | setProxyFactoryObjectName(javax.management.ObjectName proxyFactory)
this.proxyFactory = proxyFactory;
|
public void | startService(org.jboss.ha.framework.interfaces.HAPartition haPartition)
this.partition = haPartition;
this.startService();
|
protected void | startService()
log.debug("Obtaining the transport proxy");
stub = this.getNamingProxy();
this.theServer.setHAStub(stub);
if (port >= 0)
{
log.debug("Starting HAJNDI bootstrap listener");
initBootstrapListener();
}
// Automatic Discovery for unconfigured clients
if (adGroupAddress != null && discoveryDisabled == false)
{
try
{
autoDiscovery = new AutomaticDiscovery();
autoDiscovery.start();
lookupPool.run(autoDiscovery);
}
catch (Exception e)
{
log.warn("Failed to start AutomaticDiscovery", e);
}
}
|
protected void | stopService()
// un-share instance for in-vm discovery
NamingContext.removeHANamingServerForPartition(partitionName);
// Stop listener
ServerSocket s = bootstrapSocket;
bootstrapSocket = null;
if (s != null)
{
log.debug("Closing the bootstrap listener");
s.close();
}
// Stop HAJNDI service
log.debug("Stopping the HAJNDI service");
theServer.stop();
log.debug("Stopping AutomaticDiscovery");
if (autoDiscovery != null && discoveryDisabled == false)
autoDiscovery.stop();
|