Skip to content
Open
Changes from all 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
24 changes: 16 additions & 8 deletions src/com/subgraph/orchid/circuits/CircuitIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public class CircuitIO implements DashboardRenderable {
private final Map<Integer, StreamImpl> streamMap;
private final Object relaySendLock = new Object();

/** LOCKING: streamMap */
private boolean isMarkedForClose;
/** LOCKING: streamMap */
private boolean isClosed;

CircuitIO(CircuitImpl circuit, Connection connection, int circuitId) {
Expand Down Expand Up @@ -233,27 +235,32 @@ void sendCell(Cell cell) {
}

void markForClose() {
boolean shouldClose;
synchronized (streamMap) {
if(isMarkedForClose) {
return;
}
isMarkedForClose = true;
if(streamMap.isEmpty()) {
closeCircuit();
}
shouldClose = streamMap.isEmpty();
}
if (shouldClose)
closeCircuit();
}

boolean isMarkedForClose() {
return isMarkedForClose;
synchronized (streamMap) {
return isMarkedForClose;
}
}

private void closeCircuit() {
logger.fine("Closing circuit "+ circuit);
sendDestroyCell(Cell.ERROR_NONE);
connection.removeCircuit(circuit);
circuit.setStateDestroyed();
isClosed = true;
synchronized(streamMap) {
isClosed = true;
}
}

void sendDestroyCell(int reason) {
Expand Down Expand Up @@ -295,12 +302,13 @@ StreamImpl createNewStream(boolean autoclose) {
}

void removeStream(StreamImpl stream) {
boolean shouldClose;
synchronized(streamMap) {
streamMap.remove(stream.getStreamId());
if(streamMap.isEmpty() && isMarkedForClose) {
closeCircuit();
}
shouldClose = streamMap.isEmpty() && isMarkedForClose;
}
if (shouldClose)
closeCircuit();
}

List<Stream> getActiveStreams() {
Expand Down