Commit fb54dbba authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Added support for <system-shutdown>. JM-707

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3992 b35dd754-fafc-0310-a699-88a17e54d16e
parent 69b8520e
...@@ -59,6 +59,13 @@ public interface Connection { ...@@ -59,6 +59,13 @@ public interface Connection {
*/ */
public void close(); public void close();
/**
* Notification message indicating that the server is being shutdown. Implementors
* should send a stream error whose condition is system-shutdown before closing
* the connection.
*/
public void systemShutdown();
/** /**
* Returns true if the connection/session is closed. * Returns true if the connection/session is closed.
* *
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
package org.jivesoftware.wildfire.multiplex; package org.jivesoftware.wildfire.multiplex;
import org.dom4j.Element; import org.dom4j.Element;
import org.jivesoftware.util.StringUtils;
import org.jivesoftware.wildfire.XMPPServer; import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.net.VirtualConnection; import org.jivesoftware.wildfire.net.VirtualConnection;
import org.xmpp.packet.IQ; import org.xmpp.packet.IQ;
...@@ -58,24 +57,13 @@ public class ClientSessionConnection extends VirtualConnection { ...@@ -58,24 +57,13 @@ public class ClientSessionConnection extends VirtualConnection {
ConnectionMultiplexerSession multiplexerSession = ConnectionMultiplexerSession multiplexerSession =
multiplexerManager.getMultiplexerSession(connectionManagerName); multiplexerManager.getMultiplexerSession(connectionManagerName);
if (multiplexerSession != null) { if (multiplexerSession != null) {
// If TO is null then wrap packet so that the connection manager can // Wrap packet so that the connection manager can figure out the target session
// figure out the target session Route wrapper = new Route(session.getStreamID().getID());
if (packet.getTo() == null) { wrapper.setFrom(serverName);
IQ wrapper = new IQ(IQ.Type.set); wrapper.setTo(connectionManagerName);
wrapper.setFrom(serverName); wrapper.setChildElement(packet.getElement().createCopy());
wrapper.setTo(connectionManagerName); // Deliver wrapper
Element child = wrapper.setChildElement("session", multiplexerSession.deliver(wrapper);
"http://jabber.org/protocol/connectionmanager");
child.addAttribute("id", session.getStreamID().getID());
Element send = child.addElement("send");
send.add(packet.getElement().createCopy());
// Deliver wrapper
multiplexerSession.deliver(wrapper);
}
else {
// Deliver original packet
multiplexerSession.deliver(packet);
}
session.incrementServerPacketCount(); session.incrementServerPacketCount();
} }
} }
...@@ -97,13 +85,11 @@ public class ClientSessionConnection extends VirtualConnection { ...@@ -97,13 +85,11 @@ public class ClientSessionConnection extends VirtualConnection {
if (multiplexerSession != null) { if (multiplexerSession != null) {
// Wrap packet so that the connection manager can figure out the target session // Wrap packet so that the connection manager can figure out the target session
StringBuilder sb = new StringBuilder(200 + text.length()); StringBuilder sb = new StringBuilder(200 + text.length());
sb.append("<iq type=\"set\" from=\"").append(serverName); sb.append("<route from=\"").append(serverName);
sb.append("\" to=\"").append(connectionManagerName); sb.append("\" to=\"").append(connectionManagerName);
sb.append("\" id=\"").append(StringUtils.randomString(10)); sb.append("\" streamid=\"").append(session.getStreamID().getID()).append("\">");
sb.append("\"><session xmlns=\"http://jabber.org/protocol/connectionmanager\" id=\"");
sb.append(session.getStreamID().getID()).append("\"><send>");
sb.append(text); sb.append(text);
sb.append("</send></session></iq>"); sb.append("</route>");
// Deliver the wrapped stanza // Deliver the wrapped stanza
multiplexerSession.getConnection().deliverRawText(sb.toString()); multiplexerSession.getConnection().deliverRawText(sb.toString());
} }
...@@ -120,6 +106,12 @@ public class ClientSessionConnection extends VirtualConnection { ...@@ -120,6 +106,12 @@ public class ClientSessionConnection extends VirtualConnection {
return null; return null;
} }
public void systemShutdown() {
// Do nothing since a system-shutdown error will be sent to the Connection Manager
// that in turn will send a system-shutdown to connected clients. This is an
// optimization to reduce number of packets being sent from the server.
}
/** /**
* If the Connection Manager or the Client requested to close the connection then just do * If the Connection Manager or the Client requested to close the connection then just do
* nothing. But if the server originated the request to close the connection then we need * nothing. But if the server originated the request to close the connection then we need
...@@ -134,16 +126,20 @@ public class ClientSessionConnection extends VirtualConnection { ...@@ -134,16 +126,20 @@ public class ClientSessionConnection extends VirtualConnection {
// Do nothing since it has already been removed and closed // Do nothing since it has already been removed and closed
} }
else { else {
// Server requested to close the client session so let the connection manager ConnectionMultiplexerSession multiplexerSession =
// know that he has to finish the client session multiplexerManager.getMultiplexerSession(connectionManagerName);
IQ closeRequest = new IQ(IQ.Type.set); if (multiplexerSession != null) {
closeRequest.setFrom(serverName); // Server requested to close the client session so let the connection manager
closeRequest.setTo(connectionManagerName); // know that he has to finish the client session
Element child = closeRequest.setChildElement("session", IQ closeRequest = new IQ(IQ.Type.set);
"http://jabber.org/protocol/connectionmanager"); closeRequest.setFrom(serverName);
child.addAttribute("id", streamID); closeRequest.setTo(connectionManagerName);
child.addElement("close"); Element child = closeRequest.setChildElement("session",
deliver(closeRequest); "http://jabber.org/protocol/connectionmanager");
child.addAttribute("id", streamID);
child.addElement("close");
multiplexerSession.deliver(closeRequest);
}
} }
} }
} }
...@@ -450,6 +450,12 @@ public class SocketConnection implements Connection { ...@@ -450,6 +450,12 @@ public class SocketConnection implements Connection {
} }
} }
public void systemShutdown() {
deliverRawText("<stream:error><system-shutdown " +
"xmlns='urn:ietf:params:xml:ns:xmpp-streams'/></stream:error>");
close();
}
void writeStarted() { void writeStarted() {
writeStarted = System.currentTimeMillis(); writeStarted = System.currentTimeMillis();
} }
......
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