Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronizing WSO2-dev and Wso2 Repo [09-July-2014] #28

Merged
merged 4 commits into from
Jul 9, 2014
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void errorConnecting(HttpRoute route, int errorCode, String message) {
* @param host name of the remote host
* @param port remote port number
*/
public void connected(HttpRoute route) {
public void connected(HttpRoute route, NHttpClientConnection conn) {
Queue<MessageContext> queue = null;
lock.lock();
try {
Expand All @@ -206,13 +206,16 @@ public void connected(HttpRoute route) {
}

while (queue.size() > 0) {
NHttpClientConnection conn = targetConnections.getConnection(route);
if(conn == null) {
conn = targetConnections.getExistingConnection(route);
}
if (conn != null) {
MessageContext messageContext = queue.poll();

if (messageContext != null) {
tryNextMessage(messageContext, route, conn);
}
conn = null;
} else {
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public TargetHandler(DeliveryAgent deliveryAgent,

public void connected(NHttpClientConnection conn, Object o) {
assert o instanceof HostConnections : "Attachment should be a HostConnections";

HostConnections pool = (HostConnections) o;
conn.getContext().setAttribute(PassThroughConstants.CONNECTION_POOL, pool);
HttpRoute route = pool.getRoute();
Expand All @@ -90,7 +89,7 @@ public void connected(NHttpClientConnection conn, Object o) {
targetConfiguration.getConnections().addConnection(conn);

// notify about the new connection
deliveryAgent.connected(pool.getRoute());
deliveryAgent.connected(pool.getRoute(), conn);

HttpContext context = conn.getContext();
context.setAttribute(PassThroughConstants.REQ_DEPARTURE_TIME, System.currentTimeMillis());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void addConnection(NHttpClientConnection conn) {
}
lock.lock();
try {
freeConnections.add(conn);
busyConnections.add(conn);
} finally {
lock.unlock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ public NHttpClientConnection getConnection(HttpRoute route) {
return connection;
}

public NHttpClientConnection getExistingConnection(HttpRoute route) {
if (log.isDebugEnabled()) {
log.debug("Trying to get a existing connection connection " + route);
}

HostConnections pool = getConnectionPool(route);
return pool.getConnection();

}

/**
* This connection is no longer valid. So we need to shutdownConnection connection.
*
Expand Down Expand Up @@ -178,16 +188,16 @@ public void addConnection(NHttpClientConnection conn) {

private HostConnections getConnectionPool(HttpRoute route) {
// see weather a pool already exists for this host:port
HostConnections pool = poolMap.get(route);
synchronized (poolMap) {
HostConnections pool = poolMap.get(route);

if (pool == null) {
pool = new HostConnections(route, maxConnections);
poolMap.put(route, pool);
}
}
return pool;

return pool;
}
}


}