Java Code Examples for io.netty.handler.codec.http.websocketx.CloseWebSocketFrame#release()

The following examples show how to use io.netty.handler.codec.http.websocketx.CloseWebSocketFrame#release() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebsocketClientOperations.java    From reactor-netty with Apache License 2.0 6 votes vote down vote up
Mono<Void> sendClose(CloseWebSocketFrame frame) {
	if (CLOSE_SENT.get(this) == 0) {
		//commented for now as we assume the close is always scheduled (deferFuture runs)
		//onTerminate().subscribe(null, null, () -> ReactorNetty.safeRelease(frame));
		return FutureMono.deferFuture(() -> {
			if (CLOSE_SENT.getAndSet(this, 1) == 0) {
				discard();
				onCloseState.onNext(new WebSocketCloseStatus(frame.statusCode(), frame.reasonText()));
				return channel().writeAndFlush(frame)
				                .addListener(ChannelFutureListener.CLOSE);
			}
			frame.release();
			return channel().newSucceededFuture();
		}).doOnCancel(() -> ReactorNetty.safeRelease(frame));
	}
	frame.release();
	return Mono.empty();
}
 
Example 2
Source File: WebsocketClientOperations.java    From reactor-netty with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("FutureReturnValueIgnored")
void sendCloseNow(@Nullable CloseWebSocketFrame frame) {
	if (frame != null && !frame.isFinalFragment()) {
		//"FutureReturnValueIgnored" this is deliberate
		channel().writeAndFlush(frame);
		return;
	}
	if (CLOSE_SENT.getAndSet(this, 1) == 0) {
		if (frame != null) {
			onCloseState.onNext(new WebSocketCloseStatus(frame.statusCode(), frame.reasonText()));
			channel().writeAndFlush(frame)
			         .addListener(ChannelFutureListener.CLOSE);
		} else {
			onCloseState.onNext(new WebSocketCloseStatus(-1, ""));
			channel().writeAndFlush(new CloseWebSocketFrame())
			         .addListener(ChannelFutureListener.CLOSE);
		}
	}
	else if (frame != null) {
		frame.release();
	}
}
 
Example 3
Source File: WebsocketServerOperations.java    From reactor-netty with Apache License 2.0 6 votes vote down vote up
Mono<Void> sendClose(CloseWebSocketFrame frame) {
	if (CLOSE_SENT.get(this) == 0) {
		//commented for now as we assume the close is always scheduled (deferFuture runs)
		//onTerminate().subscribe(null, null, () -> ReactorNetty.safeRelease(frame));
		return FutureMono.deferFuture(() -> {
			if (CLOSE_SENT.getAndSet(this, 1) == 0) {
				discard();
				onCloseState.onNext(new WebSocketCloseStatus(frame.statusCode(), frame.reasonText()));
				return channel().writeAndFlush(frame)
				                .addListener(ChannelFutureListener.CLOSE);
			}
			frame.release();
			return channel().newSucceededFuture();
		}).doOnCancel(() -> ReactorNetty.safeRelease(frame));
	}
	frame.release();
	return Mono.empty();
}
 
Example 4
Source File: WebsocketServerOperations.java    From reactor-netty with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("FutureReturnValueIgnored")
void sendCloseNow(@Nullable CloseWebSocketFrame frame, ChannelFutureListener listener) {
	if (frame != null && !frame.isFinalFragment()) {
		//"FutureReturnValueIgnored" this is deliberate
		channel().writeAndFlush(frame);
		return;
	}
	if (CLOSE_SENT.getAndSet(this, 1) == 0) {
		if (frame != null) {
			onCloseState.onNext(new WebSocketCloseStatus(frame.statusCode(), frame.reasonText()));
			channel().writeAndFlush(frame)
			         .addListener(listener);
		} else {
			onCloseState.onNext(new WebSocketCloseStatus(-1, ""));
			channel().writeAndFlush(new CloseWebSocketFrame())
			         .addListener(listener);
		}
	}
	else if (frame != null) {
		frame.release();
	}
}