use of org.webpieces.nio.api.exceptions.NioClosedChannelException in project webpieces by deanhiller.
the class HttpSocketImpl method cleanUpPendings.
private void cleanUpPendings(String msg) {
//do we need an isClosing state and cache that future? (I don't think so but time will tell)
while (!responsesToComplete.isEmpty()) {
HttpResponseListener listener = responsesToComplete.poll();
if (listener != null) {
listener.failure(new NioClosedChannelException(msg + " before responses were received"));
}
}
synchronized (this) {
while (!pendingRequests.isEmpty()) {
PendingRequest pending = pendingRequests.poll();
pending.getListener().failure(new NioClosedChannelException(msg + " before requests were sent"));
}
}
}
use of org.webpieces.nio.api.exceptions.NioClosedChannelException in project webpieces by deanhiller.
the class BasChannelImpl method write.
@Override
public CompletableFuture<Channel> write(ByteBuffer b) {
if (b.remaining() == 0)
throw new IllegalArgumentException("buffer has no data");
else if (!getSelectorManager().isRunning())
throw new IllegalStateException(this + "ChannelManager must be running and is stopped");
else if (isClosed) {
if (isRemoteEndInitiateClose)
throw new NioClosedChannelException(this + "Client cannot write after the remote end closed the socket");
else
throw new NioClosedChannelException(this + "Your Application cannot write after YOUR Application closed the socket");
} else if (doNotAllowWrites)
throw new IllegalStateException("This channel is in a failed state. " + "failure functions were called so look for exceptions from them");
apiLog.trace(() -> this + "Basic.write");
CompletableFuture<Channel> future = new CompletableFuture<Channel>();
boolean wroteAllData = writeSynchronized(b, future);
if (wroteAllData) {
//since we didn't switch and were not in this mode, complete the action outside sync block
pool.releaseBuffer(b);
future.complete(this);
log.trace(() -> this + " wrote bytes on client thread");
} else {
log.trace(() -> this + "sent write to queue");
}
return future;
}
use of org.webpieces.nio.api.exceptions.NioClosedChannelException in project webpieces by deanhiller.
the class BasChannelImpl method unqueueAndFailWritesThenClose.
private void unqueueAndFailWritesThenClose(CloseRunnable action) {
List<CompletableFuture<Channel>> promises;
synchronized (this) {
//put here for emphasis that we are synchronizing here but not below
promises = failAllWritesInQueue();
}
//TODO: This should really be inlined now. It's a remnant of an old design since close didn't
//work well outside the selector thread previously
action.runDelayedAction();
//notify clients outside the synchronization block!!!
for (CompletableFuture<Channel> promise : promises) {
log.info("WRITES outstanding while close was called, notifying client through his failure method of the exception");
//we only incur the cost of Throwable.fillInStackTrace() if we will use this exception
//(it's called in the Throwable constructor) so we don't do this on every close channel
NioClosedChannelException closeExc = new NioClosedChannelException("There are " + promises.size() + " writes that are not complete yet(you called write but " + "they did not call success back to the client).");
promise.completeExceptionally(closeExc);
}
}
Aggregations