Skip to content

Commit

Permalink
每个协议包对应一个Transfer实例并且所有ClientSession关闭时关闭AsyncConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
codefollower committed Mar 19, 2016
1 parent baec539 commit 67d6bc4
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 74 deletions.
Expand Up @@ -230,7 +230,7 @@ private Transfer initTransfer(ConnectionInfo ci, String server) throws Exception
} }
} }
sessionId = getNextId(); sessionId = getNextId();
transfer = asyncConnection.getTransfer().copy(this); transfer = asyncConnection.createTransfer(this);
asyncConnection.writeInitPacket(this, sessionId, transfer, ci); asyncConnection.writeInitPacket(this, sessionId, transfer, ci);
asyncConnection.addSession(sessionId, this); asyncConnection.addSession(sessionId, this);
return transfer; return transfer;
Expand Down Expand Up @@ -347,6 +347,16 @@ public void close() {
traceOperation("SESSION_CLOSE", 0); traceOperation("SESSION_CLOSE", 0);
transfer.writeRequestHeader(sessionId, Session.SESSION_CLOSE).flush(); transfer.writeRequestHeader(sessionId, Session.SESSION_CLOSE).flush();
asyncConnection.remove(sessionId); asyncConnection.remove(sessionId);

synchronized (ClientSession.class) {
if (asyncConnection.isEmpty()) {
client.close();
vertx.close();
client = null;
vertx = null;
asyncConnections.clear();
}
}
} catch (RuntimeException e) { } catch (RuntimeException e) {
trace.error(e, "close"); trace.error(e, "close");
closeError = e; closeError = e;
Expand Down
8 changes: 4 additions & 4 deletions lealone-common/src/main/java/org/lealone/db/Session.java
Expand Up @@ -75,10 +75,10 @@ public interface Session extends Closeable, Transaction.Participant {
public static final int COMMAND_STORAGE_MOVE_LEAF_PAGE = 180; public static final int COMMAND_STORAGE_MOVE_LEAF_PAGE = 180;
public static final int COMMAND_STORAGE_REMOVE_LEAF_PAGE = 181; public static final int COMMAND_STORAGE_REMOVE_LEAF_PAGE = 181;


public static final int STATUS_ERROR = 0; public static final int STATUS_ERROR = 1000;
public static final int STATUS_OK = 1; public static final int STATUS_OK = 1001;
public static final int STATUS_OK_STATE_CHANGED = 2; public static final int STATUS_OK_STATE_CHANGED = 1002;
public static final int STATUS_CLOSED = 3; public static final int STATUS_CLOSED = 1003;


Command createCommand(String sql, int fetchSize); Command createCommand(String sql, int fetchSize);


Expand Down

0 comments on commit 67d6bc4

Please sign in to comment.