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) {
IQ wrapper = new IQ(IQ.Type.set);
wrapper.setFrom(serverName); wrapper.setFrom(serverName);
wrapper.setTo(connectionManagerName); wrapper.setTo(connectionManagerName);
Element child = wrapper.setChildElement("session", wrapper.setChildElement(packet.getElement().createCopy());
"http://jabber.org/protocol/connectionmanager");
child.addAttribute("id", session.getStreamID().getID());
Element send = child.addElement("send");
send.add(packet.getElement().createCopy());
// Deliver wrapper // Deliver wrapper
multiplexerSession.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,6 +126,9 @@ public class ClientSessionConnection extends VirtualConnection { ...@@ -134,6 +126,9 @@ 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 {
ConnectionMultiplexerSession multiplexerSession =
multiplexerManager.getMultiplexerSession(connectionManagerName);
if (multiplexerSession != null) {
// Server requested to close the client session so let the connection manager // Server requested to close the client session so let the connection manager
// know that he has to finish the client session // know that he has to finish the client session
IQ closeRequest = new IQ(IQ.Type.set); IQ closeRequest = new IQ(IQ.Type.set);
...@@ -143,7 +138,8 @@ public class ClientSessionConnection extends VirtualConnection { ...@@ -143,7 +138,8 @@ public class ClientSessionConnection extends VirtualConnection {
"http://jabber.org/protocol/connectionmanager"); "http://jabber.org/protocol/connectionmanager");
child.addAttribute("id", streamID); child.addAttribute("id", streamID);
child.addElement("close"); child.addElement("close");
deliver(closeRequest); 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