User: slaboure Date: 01/11/18 04:40:42 Modified: src/main/org/jboss/ha/jndi HANamingService.java Log: JNDI JNP client no more requires PROVIDER_URL setting when used with HA-JNDI on the server. If no configuration is set (or given configuration is not able to contact a server), a multicast message is sent over the network. Any server can answer to this multicast message. The client will only pick the first answer and download the HA stub from this location. Revision Changes Path 1.13 +75 -1 jbossmx/src/main/org/jboss/ha/jndi/HANamingService.java Index: HANamingService.java =================================================================== RCS file: /cvsroot/jboss/jbossmx/src/main/org/jboss/ha/jndi/HANamingService.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- HANamingService.java 2001/11/12 06:36:49 1.12 +++ HANamingService.java 2001/11/18 12:40:42 1.13 @@ -15,6 +15,8 @@ import java.net.InetAddress; import java.net.Socket; import java.net.ServerSocket; +import java.net.MulticastSocket; +import java.net.DatagramPacket; import java.net.UnknownHostException; import java.net.URL; import java.rmi.Remote; @@ -59,7 +61,7 @@ * Management Bean for HA-JNDI service. * * @author [EMAIL PROTECTED] - * @version $Revision: 1.12 $ + * @version $Revision: 1.13 $ * * <p><b>Revisions:</b><br> */ @@ -100,6 +102,10 @@ protected DistributedReplicantManager replicantManager; protected String partitionName = "DefaultPartition"; + protected AutomaticDiscovery autoDiscovery = null; + protected String adGroupAddress = org.jnp.interfaces.NamingContext.DEFAULT_DISCOVERY_GROUP_ADDRESS; + protected int adGroupPort = org.jnp.interfaces.NamingContext.DEFAULT_DISCOVERY_GROUP_PORT; + // Public -------------------------------------------------------- public HANamingService() @@ -227,6 +233,11 @@ { log.error("Could not start on port " + port, e); } + + // Automatic Discovery for unconfigured clients + // + autoDiscovery = new AutomaticDiscovery (); + autoDiscovery.listen (); } protected void stopService() @@ -311,4 +322,67 @@ // Private ------------------------------------------------------- // Inner classes ------------------------------------------------- + + protected class AutomaticDiscovery implements Runnable + { + protected MulticastSocket socket = null; + protected byte[] ipAddress = null; + + + public AutomaticDiscovery () throws Exception + { + socket = new MulticastSocket (adGroupPort); + InetAddress group = InetAddress.getByName (adGroupAddress); + socket.joinGroup (group); + + String address = getBindAddress(); + if (address == null) + ipAddress = (java.net.InetAddress.getLocalHost().getHostAddress() + ":" + port).getBytes(); + else + ipAddress = (address + ":" + port).getBytes(); + } + + public void run () + { + + // Wait for a datagram + // + byte[] buf = new byte[256]; + DatagramPacket packet = new DatagramPacket(buf, buf.length); + try + { + log.debug("HA-JNDI AutomaticDiscovery waiting for queries..."); + socket.receive(packet); + log.debug("HA-JNDI AutomaticDiscovery Packet received."); + } + catch (IOException e) + { + log.error ("HA-JNDI AutomaticDiscovery stopped", e); + return; + } + + // Create a new thread to accept the next datagram + listen (); + + // Return the naming server IP address and port to the client + // + try + { + DatagramPacket p = new DatagramPacket (ipAddress, ipAddress.length, packet.getAddress(), packet.getPort()); + log.debug("Sending AutomaticDiscovery answer: " + p); + socket.send (p); + log.debug("AutomaticDiscovery answer sent."); + } + catch (IOException ex) + { + log.error ("Error writing response", ex); + } + } + + protected void listen () + { + Thread t = new Thread (this, "HAJNDI - AutomaticDiscovery"); + t.start (); + } + } }
_______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development