Skip to content
Prev Previous commit
Next Next commit
Load balancing/ fallback refactoring
  • Loading branch information
mpv1989 committed Nov 14, 2017
commit a96178d23573becbd465d6a60d563c7d162887cf
10 changes: 1 addition & 9 deletions src/main/java/com/arangodb/internal/ArangoExecutorSync.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,8 @@ public <T> T execute(
final Request request,
final ResponseDeserializer<T> responseDeserializer,
final HostHandle hostHandle) throws ArangoDBException {
return execute(request, responseDeserializer, hostHandle, false);
}

public <T> T execute(
final Request request,
final ResponseDeserializer<T> responseDeserializer,
final HostHandle hostHandle,
final boolean closeConnection) throws ArangoDBException {
try {
final Response response = protocol.execute(request, hostHandle, closeConnection);
final Response response = protocol.execute(request, hostHandle);
return responseDeserializer.deserialize(response);
} catch (final VPackException e) {
throw new ArangoDBException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,23 @@ public void disconnect() throws IOException {
connectionPool.disconnect();
}

public Response execute(final Request request, final HostHandle hostHandle, final boolean closeConnection)
throws ArangoDBException, IOException {
public Response execute(final Request request, final HostHandle hostHandle) throws ArangoDBException, IOException {
final HttpConnection connection = connectionPool.connection(hostHandle);
try {
return execute(request, connection, closeConnection);
return execute(request, connection);
} catch (final ArangoDBException e) {
if (e instanceof ArangoDBRedirectException) {
final String location = ArangoDBRedirectException.class.cast(e).getLocation();
final Host host = HostUtils.createFromLocation(location);
connectionPool.closeConnectionOnError(connection);
return execute(request, new HostHandle().setHost(host), closeConnection);
return execute(request, new HostHandle().setHost(host));
} else {
throw e;
}
}
}

protected Response execute(final Request request, final HttpConnection connection, final boolean closeConnection)
protected Response execute(final Request request, final HttpConnection connection)
throws ArangoDBException, IOException {
return connection.execute(request);
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/arangodb/internal/http/HttpProtocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ public HttpProtocol(final HttpCommunication httpCommunitaction) {
}

@Override
public Response execute(final Request request, final HostHandle hostHandle, final boolean closeConnection)
throws ArangoDBException {
public Response execute(final Request request, final HostHandle hostHandle) throws ArangoDBException {
try {
return httpCommunitaction.execute(request, hostHandle, closeConnection);
return httpCommunitaction.execute(request, hostHandle);
} catch (final ClientProtocolException e) {
throw new ArangoDBException(e);
} catch (final IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
*/
public interface CommunicationProtocol extends Closeable {

Response execute(final Request request, HostHandle hostHandle, boolean closeConnection) throws ArangoDBException;
Response execute(final Request request, HostHandle hostHandle) throws ArangoDBException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,23 @@ public void disconnect() throws IOException {
connectionPool.disconnect();
}

public R execute(final Request request, final HostHandle hostHandle, final boolean closeConnection)
throws ArangoDBException {
public R execute(final Request request, final HostHandle hostHandle) throws ArangoDBException {
final C connection = connectionPool.connection(hostHandle);
try {
return execute(request, connection, closeConnection);
return execute(request, connection);
} catch (final ArangoDBException e) {
if (e instanceof ArangoDBRedirectException) {
final String location = ArangoDBRedirectException.class.cast(e).getLocation();
final Host host = HostUtils.createFromLocation(location);
connectionPool.closeConnectionOnError(connection);
return execute(request, new HostHandle().setHost(host), closeConnection);
return execute(request, new HostHandle().setHost(host));
} else {
throw e;
}
}
}

protected abstract R execute(final Request request, C connection, boolean closeConnection) throws ArangoDBException;
protected abstract R execute(final Request request, C connection) throws ArangoDBException;

protected void checkError(final Response response) throws ArangoDBException {
ResponseUtils.checkError(util, response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ public ConnectionSync createConnection(final Host host) {
}

@Override
protected Response execute(final Request request, final ConnectionSync connection, final boolean closeConnection)
throws ArangoDBException {
protected Response execute(final Request request, final ConnectionSync connection) throws ArangoDBException {
connect(connection);
try {
final Message requestMessage = createMessage(request);
Expand All @@ -145,12 +144,7 @@ protected Response execute(final Request request, final ConnectionSync connectio
return response;
} catch (final VPackParserException e) {
throw new ArangoDBException(e);
} finally {
if (closeConnection) {
connection.close();
}
}

}

private Message send(final Message message, final ConnectionSync connection) throws ArangoDBException {
Expand All @@ -165,7 +159,7 @@ private Message send(final Message message, final ConnectionSync connection) thr
protected void authenticate(final ConnectionSync connection) {
final Response response = execute(
new AuthenticationRequest(user, password != null ? password : "", ArangoDBConstants.ENCRYPTION_PLAIN),
connection, false);
connection);
checkError(response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ public VstProtocol(final VstCommunication<Response, ConnectionSync> communicatio
}

@Override
public Response execute(final Request request, final HostHandle hostHandle, final boolean closeConnection)
throws ArangoDBException {
return communication.execute(request, hostHandle, closeConnection);
public Response execute(final Request request, final HostHandle hostHandle) throws ArangoDBException {
return communication.execute(request, hostHandle);
}

@Override
Expand Down