Commit 873e48ec authored by Alex Wenckus's avatar Alex Wenckus Committed by alex

If wait was set to a longer time then session timeout, the session would be...

If wait was set to a longer time then session timeout, the session would be timeout even though there were connections waiting for a response. Did some refactoring so that the session "knows" when all connections are closed and now returns the current time if there are currently connections actively awaiting a response when requested to return the last activity on a connection.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6874 b35dd754-fafc-0310-a699-88a17e54d16e
parent ab7f66d7
......@@ -109,12 +109,13 @@ public class HttpBindServlet extends HttpServlet {
private boolean isContinuation(HttpServletRequest request, HttpServletResponse response)
throws IOException
{
HttpConnection connection = (HttpConnection) request.getAttribute("request-connection");
if (connection == null) {
HttpSession session = (HttpSession) request.getAttribute("request-session");
if (session == null) {
return false;
}
synchronized (connection.getSession()) {
respond(response, connection);
synchronized (session) {
respond(response, session.getResponse((Long) request.getAttribute("request"))
.getBytes("utf-8"));
}
return true;
}
......@@ -162,7 +163,8 @@ public class HttpBindServlet extends HttpServlet {
else {
connection
.setContinuation(ContinuationSupport.getContinuation(request, connection));
request.setAttribute("request-connection", connection);
request.setAttribute("request-session", connection.getSession());
request.setAttribute("request", connection.getRequestId());
respond(response, connection);
}
}
......@@ -218,7 +220,7 @@ public class HttpBindServlet extends HttpServlet {
response.getOutputStream().write(content);
}
private String createEmptyBody() {
private static String createEmptyBody() {
Element body = DocumentHelper.createElement("body");
body.addNamespace("", "http://jabber.org/protocol/httpbind");
return body.asXML();
......
......@@ -42,7 +42,7 @@ public class HttpSession extends ClientSession {
private int wait;
private int hold = 0;
private String language;
private final Queue<HttpConnection> connectionQueue = new LinkedList<HttpConnection>();
private final List<HttpConnection> connectionQueue = new LinkedList<HttpConnection>();
private final List<Deliverable> pendingElements = new ArrayList<Deliverable>();
private final List<Deliverable> sentElements = new ArrayList<Deliverable>();
private boolean isSecure;
......@@ -296,12 +296,37 @@ public class HttpSession extends ClientSession {
/**
* Returns the time in milliseconds since the epoch that this session was last active. Activity
* is a request was either made or responded to.
* is a request was either made or responded to. If the session is currently active, meaning
* there are connections awaiting a response, the current time is returned.
*
* @return the time in milliseconds since the epoch that this session was last active.
*/
public synchronized long getLastActivity() {
return lastActivity;
if (connectionQueue.size() <= 0) {
return lastActivity;
}
// The session is currently active, return the current time.
else {
return System.currentTimeMillis();
}
}
public String getResponse(long requestID) {
for (HttpConnection connection : connectionQueue) {
if (connection.getRequestId() == requestID) {
String response;
try {
response = connection.getResponse();
}
catch (HttpBindTimeoutException e) {
response = createEmptyBody();
}
connectionQueue.remove(connection);
fireConnectionClosed(connection);
return response;
}
}
throw new InternalError("Could not locate connection: " + requestID);
}
/**
......@@ -393,11 +418,11 @@ public class HttpSession extends ClientSession {
// With this connection we need to check if we will have too many connections open,
// closing any extras.
while (connectionQueue.size() >= hold) {
HttpConnection toClose = connectionQueue.remove();
HttpConnection toClose = connectionQueue.remove(0);
toClose.close();
fireConnectionClosed(toClose);
}
connectionQueue.offer(connection);
connectionQueue.add(connection);
fireConnectionOpened(connection);
}
lastRequestID = connection.getRequestId();
......@@ -444,12 +469,11 @@ public class HttpSession extends ClientSession {
private void deliver(Deliverable stanza) {
String deliverable = createDeliverable(Arrays.asList(stanza));
boolean delivered = false;
while (!delivered && connectionQueue.size() > 0) {
HttpConnection connection = connectionQueue.remove();
for (HttpConnection connection : connectionQueue) {
try {
deliver(connection, deliverable);
delivered = true;
fireConnectionClosed(connection);
break;
}
catch (HttpConnectionClosedException e) {
/* Connection was closed, try the next one */
......@@ -488,8 +512,7 @@ public class HttpSession extends ClientSession {
failDelivery();
}
while (connectionQueue.size() > 0) {
HttpConnection toClose = connectionQueue.remove();
for (HttpConnection toClose : connectionQueue) {
toClose.close();
fireConnectionClosed(toClose);
}
......@@ -511,6 +534,12 @@ public class HttpSession extends ClientSession {
pendingElements.clear();
}
private static String createEmptyBody() {
Element body = DocumentHelper.createElement("body");
body.addNamespace("", "http://jabber.org/protocol/httpbind");
return body.asXML();
}
/**
* A virtual server connection relates to a http session which its self can relate to many http
* connections.
......
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