Commit df85bf12 authored by Matt Tucker's avatar Matt Tucker Committed by matt

Updated multi-cast DNS logic, added TaskEngine to Wildfire.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6160 b35dd754-fafc-0310-a699-88a17e54d16e
parent a32d115d
This diff is collapsed.
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
* Copyright (C) 2004-2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.util;
/**
......
......@@ -862,6 +862,9 @@ public class XMPPServer {
for (XMPPServerListener listener : listeners) {
listener.serverStopping();
}
// Shutdown the task engine.
TaskEngine.getInstance().shutdown();
// If we don't have modules then the server has already been shutdown
if (modules.isEmpty()) {
return;
......
......@@ -16,29 +16,64 @@ import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.XMPPServerInfo;
import org.jivesoftware.wildfire.ServerPort;
import org.jivesoftware.util.Log;
import org.jivesoftware.admin.AdminConsole;
import org.jivesoftware.util.PropertyEventDispatcher;
import org.jivesoftware.util.PropertyEventListener;
import org.jivesoftware.util.TaskEngine;
import javax.jmdns.JmDNS;
import javax.jmdns.ServiceInfo;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.TimerTask;
/**
* Publishes Wildfire as a service using the Multicast DNS (marketed by Apple
* Publishes Wildfire information as a service using the Multicast DNS (marketed by Apple
* as Rendezvous) protocol. This lets other nodes on the local network to discover
* the name and port of Wildfire.<p>
*
* The multicast DNS entry is published with a type of "_xmpp-client._tcp.local.".
* The multicast DNS entries published:<ul>
* <li>Client connections: type of "_xmpp-client._tcp.local.".
* <li>Component connections: type of "_xmpp-component._tcp.local.".
* </ul>
*
* @author Matt Tucker
*/
public class MulticastDNSService extends BasicModule {
private JmDNS jmdns;
private ServiceInfo serviceInfo;
public MulticastDNSService() {
super("Multicast DNS Service");
PropertyEventDispatcher.addListener(new PropertyEventListener() {
public void propertySet(String property, Map params) {
// Restart the service if component settings changes.
if (property.equals("xmpp.component.socket.active") ||
property.equals(" xmpp.component.socket.port"))
{
stop();
start();
}
}
public void propertyDeleted(String property, Map params) {
// Restart the service if component settings changes.
if (property.equals("xmpp.component.socket.active") ||
property.equals(" xmpp.component.socket.port"))
{
stop();
start();
}
}
public void xmlPropertySet(String property, Map params) {
}
public void xmlPropertyDeleted(String property, Map params) {
}
});
}
public void initialize(XMPPServer server) {
......@@ -46,27 +81,36 @@ public class MulticastDNSService extends BasicModule {
}
public void start() throws IllegalStateException {
if (jmdns != null) {
Runnable startService = new Runnable() {
TimerTask startService = new TimerTask() {
public void run() {
XMPPServerInfo info = XMPPServer.getInstance().getServerInfo();
Iterator ports = info.getServerPorts();
int portNum = -1;
int clientPortNum = -1;
int componentPortNum = -1;
while (ports.hasNext()) {
ServerPort port = (ServerPort)ports.next();
if (port.isClientPort() && !port.isSecure()) {
portNum = port.getPort();
if (port.isClientPort()) {
clientPortNum = port.getPort();
}
else if (port.isComponentPort()) {
componentPortNum = port.getPort();
}
}
try {
if (jmdns == null) {
jmdns = new JmDNS();
}
if (portNum != -1) {
String serverName = AdminConsole.getAppName();
serviceInfo = new ServiceInfo("_xmpp-client._tcp.local.",
serverName, portNum, 0, 0, "XMPP Server");
jmdns.registerService(serviceInfo);
String serverName = XMPPServer.getInstance().getServerInfo().getName();
if (clientPortNum != -1) {
ServiceInfo clientService = new ServiceInfo("_xmpp-client._tcp.local.",
serverName + "._xmpp-client._tcp.local.", clientPortNum, "XMPP Server");
jmdns.registerService(clientService);
}
if (componentPortNum != -1) {
ServiceInfo componentService = new ServiceInfo("_xmpp-component._tcp.local.",
serverName + "._xmpp-component._tcp.local.", componentPortNum, "XMPP Component Server");
jmdns.registerService(componentService);
}
}
catch (IOException ioe) {
......@@ -74,8 +118,8 @@ public class MulticastDNSService extends BasicModule {
}
}
};
new Thread(startService).start();
}
// Schedule the task to run in 5 seconds, to give Wildire time to start the ports.
TaskEngine.getInstance().schedule(startService, 5000);
}
......@@ -84,7 +128,9 @@ public class MulticastDNSService extends BasicModule {
try {
jmdns.close();
}
catch (Exception e) { }
catch (Exception e) {
// Ignore.
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment