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$ * $Revision$
* $Date$ * $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), * This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution. * a copy of which is included in this distribution.
*/ */
package org.jivesoftware.util; package org.jivesoftware.util;
/** /**
......
...@@ -862,6 +862,9 @@ public class XMPPServer { ...@@ -862,6 +862,9 @@ public class XMPPServer {
for (XMPPServerListener listener : listeners) { for (XMPPServerListener listener : listeners) {
listener.serverStopping(); listener.serverStopping();
} }
// Shutdown the task engine.
TaskEngine.getInstance().shutdown();
// If we don't have modules then the server has already been shutdown // If we don't have modules then the server has already been shutdown
if (modules.isEmpty()) { if (modules.isEmpty()) {
return; return;
......
...@@ -16,29 +16,64 @@ import org.jivesoftware.wildfire.XMPPServer; ...@@ -16,29 +16,64 @@ import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.XMPPServerInfo; import org.jivesoftware.wildfire.XMPPServerInfo;
import org.jivesoftware.wildfire.ServerPort; import org.jivesoftware.wildfire.ServerPort;
import org.jivesoftware.util.Log; 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.JmDNS;
import javax.jmdns.ServiceInfo; import javax.jmdns.ServiceInfo;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator; 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 * as Rendezvous) protocol. This lets other nodes on the local network to discover
* the name and port of Wildfire.<p> * 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 * @author Matt Tucker
*/ */
public class MulticastDNSService extends BasicModule { public class MulticastDNSService extends BasicModule {
private JmDNS jmdns; private JmDNS jmdns;
private ServiceInfo serviceInfo;
public MulticastDNSService() { public MulticastDNSService() {
super("Multicast DNS Service"); 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) { public void initialize(XMPPServer server) {
...@@ -46,27 +81,36 @@ public class MulticastDNSService extends BasicModule { ...@@ -46,27 +81,36 @@ public class MulticastDNSService extends BasicModule {
} }
public void start() throws IllegalStateException { public void start() throws IllegalStateException {
if (jmdns != null) { TimerTask startService = new TimerTask() {
Runnable startService = new Runnable() {
public void run() { public void run() {
XMPPServerInfo info = XMPPServer.getInstance().getServerInfo(); XMPPServerInfo info = XMPPServer.getInstance().getServerInfo();
Iterator ports = info.getServerPorts(); Iterator ports = info.getServerPorts();
int portNum = -1; int clientPortNum = -1;
int componentPortNum = -1;
while (ports.hasNext()) { while (ports.hasNext()) {
ServerPort port = (ServerPort)ports.next(); ServerPort port = (ServerPort)ports.next();
if (port.isClientPort() && !port.isSecure()) { if (port.isClientPort()) {
portNum = port.getPort(); clientPortNum = port.getPort();
}
else if (port.isComponentPort()) {
componentPortNum = port.getPort();
} }
} }
try { try {
if (jmdns == null) { if (jmdns == null) {
jmdns = new JmDNS(); jmdns = new JmDNS();
} }
if (portNum != -1) { String serverName = XMPPServer.getInstance().getServerInfo().getName();
String serverName = AdminConsole.getAppName();
serviceInfo = new ServiceInfo("_xmpp-client._tcp.local.", if (clientPortNum != -1) {
serverName, portNum, 0, 0, "XMPP Server"); ServiceInfo clientService = new ServiceInfo("_xmpp-client._tcp.local.",
jmdns.registerService(serviceInfo); 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) { catch (IOException ioe) {
...@@ -74,8 +118,8 @@ public class MulticastDNSService extends BasicModule { ...@@ -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 { ...@@ -84,7 +128,9 @@ public class MulticastDNSService extends BasicModule {
try { try {
jmdns.close(); 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