Java Code Examples for org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext#close()

The following examples show how to use org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext#close() . 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: RestClient.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) {
	if (msg instanceof HttpResponse && ((HttpResponse) msg).status().equals(REQUEST_ENTITY_TOO_LARGE)) {
		jsonFuture.completeExceptionally(
			new RestClientException(
				String.format(
					REQUEST_ENTITY_TOO_LARGE + ". Try to raise [%s]",
					RestOptions.CLIENT_MAX_CONTENT_LENGTH.key()),
				((HttpResponse) msg).status()));
	} else if (msg instanceof FullHttpResponse) {
		readRawResponse((FullHttpResponse) msg);
	} else {
		LOG.error("Implementation error: Received a response that wasn't a FullHttpResponse.");
		if (msg instanceof HttpResponse) {
			jsonFuture.completeExceptionally(
				new RestClientException(
					"Implementation error: Received a response that wasn't a FullHttpResponse.",
					((HttpResponse) msg).getStatus()));
		} else {
			jsonFuture.completeExceptionally(
				new RestClientException(
					"Implementation error: Received a response that wasn't a FullHttpResponse.",
					HttpResponseStatus.INTERNAL_SERVER_ERROR));
		}

	}
	ctx.close();
}
 
Example 2
Source File: RestClient.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) {
	if (cause instanceof TooLongFrameException) {
		jsonFuture.completeExceptionally(new TooLongFrameException(String.format(
			cause.getMessage() + " Try to raise [%s]",
			RestOptions.CLIENT_MAX_CONTENT_LENGTH.key())));
	} else {
		jsonFuture.completeExceptionally(cause);
	}
	ctx.close();
}
 
Example 3
Source File: RestClient.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
	if (evt instanceof IdleStateEvent) {
		jsonFuture.completeExceptionally(new ConnectionIdleException("Channel became idle."));
		ctx.close();
	} else {
		super.userEventTriggered(ctx, evt);
	}
}
 
Example 4
Source File: RestClient.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) {
	if (msg instanceof HttpResponse && ((HttpResponse) msg).status().equals(REQUEST_ENTITY_TOO_LARGE)) {
		jsonFuture.completeExceptionally(
			new RestClientException(
				String.format(
					REQUEST_ENTITY_TOO_LARGE + ". Try to raise [%s]",
					RestOptions.CLIENT_MAX_CONTENT_LENGTH.key()),
				((HttpResponse) msg).status()));
	} else if (msg instanceof FullHttpResponse) {
		readRawResponse((FullHttpResponse) msg);
	} else {
		LOG.error("Implementation error: Received a response that wasn't a FullHttpResponse.");
		if (msg instanceof HttpResponse) {
			jsonFuture.completeExceptionally(
				new RestClientException(
					"Implementation error: Received a response that wasn't a FullHttpResponse.",
					((HttpResponse) msg).getStatus()));
		} else {
			jsonFuture.completeExceptionally(
				new RestClientException(
					"Implementation error: Received a response that wasn't a FullHttpResponse.",
					HttpResponseStatus.INTERNAL_SERVER_ERROR));
		}

	}
	ctx.close();
}
 
Example 5
Source File: HttpTestClient.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
	LOG.debug("Received {}", msg);

	if (msg instanceof HttpResponse) {
		HttpResponse response = (HttpResponse) msg;

		currentStatus = response.getStatus();
		currentType = response.headers().get(HttpHeaders.Names.CONTENT_TYPE);
		currentLocation = response.headers().get(HttpHeaders.Names.LOCATION);

		if (HttpHeaders.isTransferEncodingChunked(response)) {
			LOG.debug("Content is chunked");
		}
	}

	if (msg instanceof HttpContent) {
		HttpContent content = (HttpContent) msg;

		// Add the content
		currentContent += content.content().toString(CharsetUtil.UTF_8);

		// Finished with this
		if (content instanceof LastHttpContent) {
			responses.add(new SimpleHttpResponse(currentStatus, currentType,
					currentContent, currentLocation));

			currentStatus = null;
			currentType = null;
			currentLocation = null;
			currentContent = "";

			ctx.close();
		}
	}
}
 
Example 6
Source File: NettyServerLowAndHighWatermarkTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
	if (error.get() == null) {
		error.set(cause);
	}

	ctx.close();

	super.exceptionCaught(ctx, cause);
}
 
Example 7
Source File: NettyServerLowAndHighWatermarkTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
	if (hasFlushed) {
		// After flushing the writability should change back to writable
		assertTrue(ctx.channel().isWritable());

		// Close the channel. This will terminate the main test Thread.
		ctx.close();
	}

	super.channelWritabilityChanged(ctx);
}
 
Example 8
Source File: RestClient.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) {
	if (cause instanceof TooLongFrameException) {
		jsonFuture.completeExceptionally(new TooLongFrameException(String.format(
			cause.getMessage() + " Try to raise [%s]",
			RestOptions.CLIENT_MAX_CONTENT_LENGTH.key())));
	} else {
		jsonFuture.completeExceptionally(cause);
	}
	ctx.close();
}
 
Example 9
Source File: RestClient.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
	if (evt instanceof IdleStateEvent) {
		jsonFuture.completeExceptionally(new ConnectionIdleException("Channel became idle."));
		ctx.close();
	} else {
		super.userEventTriggered(ctx, evt);
	}
}
 
Example 10
Source File: RestClient.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) {
	if (msg instanceof HttpResponse && ((HttpResponse) msg).status().equals(REQUEST_ENTITY_TOO_LARGE)) {
		jsonFuture.completeExceptionally(
			new RestClientException(
				String.format(
					REQUEST_ENTITY_TOO_LARGE + ". Try to raise [%s]",
					RestOptions.CLIENT_MAX_CONTENT_LENGTH.key()),
				((HttpResponse) msg).status()));
	} else if (msg instanceof FullHttpResponse) {
		readRawResponse((FullHttpResponse) msg);
	} else {
		LOG.error("Implementation error: Received a response that wasn't a FullHttpResponse.");
		if (msg instanceof HttpResponse) {
			jsonFuture.completeExceptionally(
				new RestClientException(
					"Implementation error: Received a response that wasn't a FullHttpResponse.",
					((HttpResponse) msg).getStatus()));
		} else {
			jsonFuture.completeExceptionally(
				new RestClientException(
					"Implementation error: Received a response that wasn't a FullHttpResponse.",
					HttpResponseStatus.INTERNAL_SERVER_ERROR));
		}

	}
	ctx.close();
}
 
Example 11
Source File: HttpTestClient.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
	LOG.debug("Received {}", msg);

	if (msg instanceof HttpResponse) {
		HttpResponse response = (HttpResponse) msg;

		currentStatus = response.getStatus();
		currentType = response.headers().get(HttpHeaders.Names.CONTENT_TYPE);
		currentLocation = response.headers().get(HttpHeaders.Names.LOCATION);

		if (HttpHeaders.isTransferEncodingChunked(response)) {
			LOG.debug("Content is chunked");
		}
	}

	if (msg instanceof HttpContent) {
		HttpContent content = (HttpContent) msg;

		// Add the content
		currentContent += content.content().toString(CharsetUtil.UTF_8);

		// Finished with this
		if (content instanceof LastHttpContent) {
			responses.add(new SimpleHttpResponse(currentStatus, currentType,
					currentContent, currentLocation));

			currentStatus = null;
			currentType = null;
			currentLocation = null;
			currentContent = "";

			ctx.close();
		}
	}
}
 
Example 12
Source File: NettyServerLowAndHighWatermarkTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
	if (error.get() == null) {
		error.set(cause);
	}

	ctx.close();

	super.exceptionCaught(ctx, cause);
}
 
Example 13
Source File: NettyServerLowAndHighWatermarkTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
	if (hasFlushed) {
		// After flushing the writability should change back to writable
		assertTrue(ctx.channel().isWritable());

		// Close the channel. This will terminate the main test Thread.
		ctx.close();
	}

	super.channelWritabilityChanged(ctx);
}
 
Example 14
Source File: RestClient.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) {
	if (cause instanceof TooLongFrameException) {
		jsonFuture.completeExceptionally(new TooLongFrameException(String.format(
			cause.getMessage() + " Try to raise [%s]",
			RestOptions.CLIENT_MAX_CONTENT_LENGTH.key())));
	} else {
		jsonFuture.completeExceptionally(cause);
	}
	ctx.close();
}
 
Example 15
Source File: RestClient.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
	if (evt instanceof IdleStateEvent) {
		jsonFuture.completeExceptionally(new ConnectionIdleException("Channel became idle."));
		ctx.close();
	} else {
		super.userEventTriggered(ctx, evt);
	}
}
 
Example 16
Source File: HttpTestClient.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
	LOG.debug("Received {}", msg);

	if (msg instanceof HttpResponse) {
		HttpResponse response = (HttpResponse) msg;

		currentStatus = response.getStatus();
		currentType = response.headers().get(HttpHeaders.Names.CONTENT_TYPE);
		currentLocation = response.headers().get(HttpHeaders.Names.LOCATION);

		if (HttpHeaders.isTransferEncodingChunked(response)) {
			LOG.debug("Content is chunked");
		}
	}

	if (msg instanceof HttpContent) {
		HttpContent content = (HttpContent) msg;

		// Add the content
		currentContent += content.content().toString(CharsetUtil.UTF_8);

		// Finished with this
		if (content instanceof LastHttpContent) {
			responses.add(new SimpleHttpResponse(currentStatus, currentType,
					currentContent, currentLocation));

			currentStatus = null;
			currentType = null;
			currentLocation = null;
			currentContent = "";

			ctx.close();
		}
	}
}
 
Example 17
Source File: RestClient.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void channelInactive(ChannelHandlerContext ctx) {
	jsonFuture.completeExceptionally(new ConnectionClosedException("Channel became inactive."));
	ctx.close();
}
 
Example 18
Source File: RestClient.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void channelInactive(ChannelHandlerContext ctx) {
	jsonFuture.completeExceptionally(new ConnectionClosedException("Channel became inactive."));
	ctx.close();
}
 
Example 19
Source File: RestClient.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void channelInactive(ChannelHandlerContext ctx) {
	jsonFuture.completeExceptionally(new ConnectionClosedException("Channel became inactive."));
	ctx.close();
}