Java Code Examples for org.apache.flink.shaded.netty4.io.netty.channel.Channel

The following examples show how to use org.apache.flink.shaded.netty4.io.netty.channel.Channel. These examples are extracted from open source projects. 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 Project: Flink-CEPplus   Author: ljygz   File: HttpTestClient.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Sends a request to to the server.
 *
 * <pre>
 * HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/overview");
 * request.headers().set(HttpHeaders.Names.HOST, host);
 * request.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
 *
 * sendRequest(request);
 * </pre>
 *
 * @param request The {@link HttpRequest} to send to the server
 */
public void sendRequest(HttpRequest request, FiniteDuration timeout) throws InterruptedException, TimeoutException {
	LOG.debug("Writing {}.", request);

	// Make the connection attempt.
	ChannelFuture connect = bootstrap.connect(host, port);

	Channel channel;
	if (connect.await(timeout.toMillis(), TimeUnit.MILLISECONDS)) {
		channel = connect.channel();
	}
	else {
		throw new TimeoutException("Connection failed");
	}

	channel.writeAndFlush(request);
}
 
Example #2
Source Project: Flink-CEPplus   Author: ljygz   File: RestServerEndpoint.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the address on which this endpoint is accepting requests.
 *
 * @return address on which this endpoint is accepting requests or null if none
 */
@Nullable
public InetSocketAddress getServerAddress() {
	synchronized (lock) {
		Preconditions.checkState(state != State.CREATED, "The RestServerEndpoint has not been started yet.");
		Channel server = this.serverChannel;

		if (server != null) {
			try {
				return ((InetSocketAddress) server.localAddress());
			} catch (Exception e) {
				log.error("Cannot access local server address", e);
			}
		}

		return null;
	}
}
 
Example #3
Source Project: Flink-CEPplus   Author: ljygz   File: PartitionRequestClientFactory.java    License: Apache License 2.0 6 votes vote down vote up
private void handInChannel(Channel channel) {
	synchronized (connectLock) {
		try {
			NetworkClientHandler clientHandler = channel.pipeline().get(NetworkClientHandler.class);
			partitionRequestClient = new PartitionRequestClient(
				channel, clientHandler, connectionId, clientFactory);

			if (disposeRequestClient) {
				partitionRequestClient.disposeIfNotUsed();
			}

			connectLock.notifyAll();
		}
		catch (Throwable t) {
			notifyOfError(t);
		}
	}
}
 
Example #4
Source Project: flink   Author: apache   File: NettyClientServerSslTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testClientUntrustedCertificate() throws Exception {
	final Configuration serverConfig = createSslConfig();
	final Configuration clientConfig = createSslConfig();

	// give the client a different keystore / certificate
	clientConfig.setString(SecurityOptions.SSL_INTERNAL_KEYSTORE, "src/test/resources/untrusted.keystore");

	final NettyConfig nettyServerConfig = createNettyConfig(serverConfig);
	final NettyConfig nettyClientConfig = createNettyConfig(clientConfig);

	final NettyBufferPool bufferPool = new NettyBufferPool(1);
	final NettyProtocol protocol = new NoOpProtocol();

	final NettyServer server = NettyTestUtil.initServer(nettyServerConfig, protocol, bufferPool);
	final NettyClient client = NettyTestUtil.initClient(nettyClientConfig, protocol, bufferPool);
	final NettyServerAndClient serverAndClient = new NettyServerAndClient(server, client);

	final Channel ch = NettyTestUtil.connect(serverAndClient);
	ch.pipeline().addLast(new StringDecoder()).addLast(new StringEncoder());

	// Attempting to write data over ssl should fail
	assertFalse(ch.writeAndFlush("test").await().isSuccess());

	NettyTestUtil.shutdown(serverAndClient);
}
 
Example #5
Source Project: Flink-CEPplus   Author: ljygz   File: NettyServerLowAndHighWatermarkTest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
	final Channel ch = ctx.channel();

	assertEquals("Low watermark", expectedLowWatermark, ch.config().getWriteBufferLowWaterMark());
	assertEquals("High watermark", expectedHighWatermark, ch.config().getWriteBufferHighWaterMark());

	// Start with a writable channel
	assertTrue(ch.isWritable());

	// First buffer should not change writability
	ch.write(buffer());
	assertTrue(ch.isWritable());

	// ...second buffer should though
	ch.write(buffer());
	assertFalse(ch.isWritable());

	// Flush everything and close the channel after the writability changed event is fired.
	hasFlushed = true;
	ch.flush();
}
 
Example #6
Source Project: Flink-CEPplus   Author: ljygz   File: ClientTest.java    License: Apache License 2.0 6 votes vote down vote up
private Channel createServerChannel(final ChannelHandler... handlers) throws UnknownHostException, InterruptedException {
	ServerBootstrap bootstrap = new ServerBootstrap()
			// Bind address and port
			.localAddress(InetAddress.getLocalHost(), 0)
			// NIO server channels
			.group(nioGroup)
			.channel(NioServerSocketChannel.class)
			// See initializer for pipeline details
			.childHandler(new ChannelInitializer<SocketChannel>() {
				@Override
				protected void initChannel(SocketChannel ch) throws Exception {
					ch.pipeline()
							.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4))
							.addLast(handlers);
				}
			});

	return bootstrap.bind().sync().channel();
}
 
Example #7
Source Project: Flink-CEPplus   Author: ljygz   File: Client.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates an established connection with the given channel.
 *
 * @param serverAddress Address of the server connected to
 * @param channel The actual TCP channel
 */
EstablishedConnection(
		final InetSocketAddress serverAddress,
		final MessageSerializer<REQ, RESP> serializer,
		final Channel channel) {

	this.serverAddress = Preconditions.checkNotNull(serverAddress);
	this.channel = Preconditions.checkNotNull(channel);

	// Add the client handler with the callback
	channel.pipeline().addLast(
			getClientName() + " Handler",
			new ClientHandler<>(clientName, serializer, this)
	);

	stats.reportActiveConnection();
}
 
Example #8
Source Project: flink   Author: flink-tpc-ds   File: HttpTestClient.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Sends a request to to the server.
 *
 * <pre>
 * HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/overview");
 * request.headers().set(HttpHeaders.Names.HOST, host);
 * request.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
 *
 * sendRequest(request);
 * </pre>
 *
 * @param request The {@link HttpRequest} to send to the server
 */
public void sendRequest(HttpRequest request, FiniteDuration timeout) throws InterruptedException, TimeoutException {
	LOG.debug("Writing {}.", request);

	// Make the connection attempt.
	ChannelFuture connect = bootstrap.connect(host, port);

	Channel channel;
	if (connect.await(timeout.toMillis(), TimeUnit.MILLISECONDS)) {
		channel = connect.channel();
	}
	else {
		throw new TimeoutException("Connection failed");
	}

	channel.writeAndFlush(request);
}
 
Example #9
Source Project: flink   Author: flink-tpc-ds   File: RestServerEndpoint.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the address on which this endpoint is accepting requests.
 *
 * @return address on which this endpoint is accepting requests or null if none
 */
@Nullable
public InetSocketAddress getServerAddress() {
	synchronized (lock) {
		Preconditions.checkState(state != State.CREATED, "The RestServerEndpoint has not been started yet.");
		Channel server = this.serverChannel;

		if (server != null) {
			try {
				return ((InetSocketAddress) server.localAddress());
			} catch (Exception e) {
				log.error("Cannot access local server address", e);
			}
		}

		return null;
	}
}
 
Example #10
Source Project: flink   Author: flink-tpc-ds   File: PartitionRequestClientFactory.java    License: Apache License 2.0 6 votes vote down vote up
private void handInChannel(Channel channel) {
	synchronized (connectLock) {
		try {
			NetworkClientHandler clientHandler = channel.pipeline().get(NetworkClientHandler.class);
			partitionRequestClient = new NettyPartitionRequestClient(
				channel, clientHandler, connectionId, clientFactory);

			if (disposeRequestClient) {
				partitionRequestClient.disposeIfNotUsed();
			}

			connectLock.notifyAll();
		}
		catch (Throwable t) {
			notifyOfError(t);
		}
	}
}
 
Example #11
Source Project: flink   Author: apache   File: ClientTest.java    License: Apache License 2.0 6 votes vote down vote up
private Channel createServerChannel(final ChannelHandler... handlers) throws UnknownHostException, InterruptedException {
	ServerBootstrap bootstrap = new ServerBootstrap()
			// Bind address and port
			.localAddress(InetAddress.getLocalHost(), 0)
			// NIO server channels
			.group(nioGroup)
			.channel(NioServerSocketChannel.class)
			// See initializer for pipeline details
			.childHandler(new ChannelInitializer<SocketChannel>() {
				@Override
				protected void initChannel(SocketChannel ch) throws Exception {
					ch.pipeline()
							.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4))
							.addLast(handlers);
				}
			});

	return bootstrap.bind().sync().channel();
}
 
Example #12
Source Project: flink   Author: flink-tpc-ds   File: NettyServerLowAndHighWatermarkTest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
	final Channel ch = ctx.channel();

	assertEquals("Low watermark", expectedLowWatermark, ch.config().getWriteBufferLowWaterMark());
	assertEquals("High watermark", expectedHighWatermark, ch.config().getWriteBufferHighWaterMark());

	// Start with a writable channel
	assertTrue(ch.isWritable());

	// First buffer should not change writability
	ch.write(buffer());
	assertTrue(ch.isWritable());

	// ...second buffer should though
	ch.write(buffer());
	assertFalse(ch.isWritable());

	// Flush everything and close the channel after the writability changed event is fired.
	hasFlushed = true;
	ch.flush();
}
 
Example #13
Source Project: flink   Author: flink-tpc-ds   File: NettyClientServerSslTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testClientUntrustedCertificate() throws Exception {
	final Configuration serverConfig = createSslConfig();
	final Configuration clientConfig = createSslConfig();

	// give the client a different keystore / certificate
	clientConfig.setString(SecurityOptions.SSL_INTERNAL_KEYSTORE, "src/test/resources/untrusted.keystore");

	final NettyConfig nettyServerConfig = createNettyConfig(serverConfig);
	final NettyConfig nettyClientConfig = createNettyConfig(clientConfig);

	final NettyBufferPool bufferPool = new NettyBufferPool(1);
	final NettyProtocol protocol = new NoOpProtocol();

	final NettyServer server = NettyTestUtil.initServer(nettyServerConfig, protocol, bufferPool);
	final NettyClient client = NettyTestUtil.initClient(nettyClientConfig, protocol, bufferPool);
	final NettyServerAndClient serverAndClient = new NettyServerAndClient(server, client);

	final Channel ch = NettyTestUtil.connect(serverAndClient);
	ch.pipeline().addLast(new StringDecoder()).addLast(new StringEncoder());

	// Attempting to write data over ssl should fail
	assertFalse(ch.writeAndFlush("test").await().isSuccess());

	NettyTestUtil.shutdown(serverAndClient);
}
 
Example #14
Source Project: flink   Author: flink-tpc-ds   File: ClientTest.java    License: Apache License 2.0 6 votes vote down vote up
private Channel createServerChannel(final ChannelHandler... handlers) throws UnknownHostException, InterruptedException {
	ServerBootstrap bootstrap = new ServerBootstrap()
			// Bind address and port
			.localAddress(InetAddress.getLocalHost(), 0)
			// NIO server channels
			.group(nioGroup)
			.channel(NioServerSocketChannel.class)
			// See initializer for pipeline details
			.childHandler(new ChannelInitializer<SocketChannel>() {
				@Override
				protected void initChannel(SocketChannel ch) throws Exception {
					ch.pipeline()
							.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4))
							.addLast(handlers);
				}
			});

	return bootstrap.bind().sync().channel();
}
 
Example #15
Source Project: flink   Author: flink-tpc-ds   File: Client.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates an established connection with the given channel.
 *
 * @param serverAddress Address of the server connected to
 * @param channel The actual TCP channel
 */
EstablishedConnection(
		final InetSocketAddress serverAddress,
		final MessageSerializer<REQ, RESP> serializer,
		final Channel channel) {

	this.serverAddress = Preconditions.checkNotNull(serverAddress);
	this.channel = Preconditions.checkNotNull(channel);

	// Add the client handler with the callback
	channel.pipeline().addLast(
			getClientName() + " Handler",
			new ClientHandler<>(clientName, serializer, this)
	);

	stats.reportActiveConnection();
}
 
Example #16
Source Project: flink   Author: apache   File: HttpTestClient.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Sends a request to to the server.
 *
 * <pre>
 * HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/overview");
 * request.headers().set(HttpHeaders.Names.HOST, host);
 * request.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
 *
 * sendRequest(request);
 * </pre>
 *
 * @param request The {@link HttpRequest} to send to the server
 */
public void sendRequest(HttpRequest request, Duration timeout) throws InterruptedException, TimeoutException {
	LOG.debug("Writing {}.", request);

	// Make the connection attempt.
	ChannelFuture connect = bootstrap.connect(host, port);

	Channel channel;
	if (connect.await(timeout.toMillis(), TimeUnit.MILLISECONDS)) {
		channel = connect.channel();
	}
	else {
		throw new TimeoutException("Connection failed");
	}

	channel.writeAndFlush(request);
}
 
Example #17
Source Project: flink   Author: apache   File: RestServerEndpoint.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the address on which this endpoint is accepting requests.
 *
 * @return address on which this endpoint is accepting requests or null if none
 */
@Nullable
public InetSocketAddress getServerAddress() {
	synchronized (lock) {
		Preconditions.checkState(state != State.CREATED, "The RestServerEndpoint has not been started yet.");
		Channel server = this.serverChannel;

		if (server != null) {
			try {
				return ((InetSocketAddress) server.localAddress());
			} catch (Exception e) {
				log.error("Cannot access local server address", e);
			}
		}

		return null;
	}
}
 
Example #18
Source Project: flink   Author: apache   File: PartitionRequestClientFactory.java    License: Apache License 2.0 6 votes vote down vote up
private void handInChannel(Channel channel) {
	synchronized (connectLock) {
		try {
			NetworkClientHandler clientHandler = channel.pipeline().get(NetworkClientHandler.class);
			partitionRequestClient = new NettyPartitionRequestClient(
				channel, clientHandler, connectionId, clientFactory);

			if (disposeRequestClient) {
				partitionRequestClient.disposeIfNotUsed();
			}

			connectLock.notifyAll();
		}
		catch (Throwable t) {
			notifyOfError(t);
		}
	}
}
 
Example #19
Source Project: Flink-CEPplus   Author: ljygz   File: MesosArtifactServer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get the server port on which the artifact server is listening.
 */
public synchronized int getServerPort() {
	Channel server = this.serverChannel;
	if (server != null) {
		try {
			return ((InetSocketAddress) server.localAddress()).getPort();
		} catch (Exception e) {
			LOG.error("Cannot access local server port", e);
		}
	}
	return -1;
}
 
Example #20
Source Project: Flink-CEPplus   Author: ljygz   File: WebFrontendBootstrap.java    License: Apache License 2.0 5 votes vote down vote up
public int getServerPort() {
	Channel server = this.serverChannel;
	if (server != null) {
		try {
			return ((InetSocketAddress) server.localAddress()).getPort();
		}
		catch (Exception e) {
			log.error("Cannot access local server port", e);
		}
	}

	return -1;
}
 
Example #21
Source Project: Flink-CEPplus   Author: ljygz   File: KeepAliveWrite.java    License: Apache License 2.0 5 votes vote down vote up
public static ChannelFuture flush(Channel ch, HttpRequest req, HttpResponse res) {
	if (!HttpHeaders.isKeepAlive(req)) {
		return ch.writeAndFlush(res).addListener(ChannelFutureListener.CLOSE);
	} else {
		res.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
		return ch.writeAndFlush(res);
	}
}
 
Example #22
Source Project: Flink-CEPplus   Author: ljygz   File: RestClient.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void writeTo(Channel channel) {
	ChannelFuture future = channel.writeAndFlush(httpRequest);
	// this should never be false as we explicitly set the encoder to use multipart messages
	if (bodyRequestEncoder.isChunked()) {
		future = channel.writeAndFlush(bodyRequestEncoder);
	}

	// release data and remove temporary files if they were created, once the writing is complete
	future.addListener((ignored) -> bodyRequestEncoder.cleanFiles());
}
 
Example #23
Source Project: Flink-CEPplus   Author: ljygz   File: PartitionRequestClient.java    License: Apache License 2.0 5 votes vote down vote up
PartitionRequestClient(
		Channel tcpChannel,
		NetworkClientHandler clientHandler,
		ConnectionID connectionId,
		PartitionRequestClientFactory clientFactory) {

	this.tcpChannel = checkNotNull(tcpChannel);
	this.clientHandler = checkNotNull(clientHandler);
	this.connectionId = checkNotNull(connectionId);
	this.clientFactory = checkNotNull(clientFactory);
}
 
Example #24
Source Project: Flink-CEPplus   Author: ljygz   File: CreditBasedPartitionRequestClientHandler.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Tries to write&flush unannounced credits for the next input channel in queue.
 *
 * <p>This method may be called by the first input channel enqueuing, or the complete
 * future's callback in previous input channel, or the channel writability changed event.
 */
private void writeAndFlushNextMessageIfPossible(Channel channel) {
	if (channelError.get() != null || !channel.isWritable()) {
		return;
	}

	while (true) {
		RemoteInputChannel inputChannel = inputChannelsWithCredit.poll();

		// The input channel may be null because of the write callbacks
		// that are executed after each write.
		if (inputChannel == null) {
			return;
		}

		//It is no need to notify credit for the released channel.
		if (!inputChannel.isReleased()) {
			AddCredit msg = new AddCredit(
				inputChannel.getPartitionId(),
				inputChannel.getAndResetUnannouncedCredit(),
				inputChannel.getInputChannelId());

			// Write and flush and wait until this is done before
			// trying to continue with the next input channel.
			channel.writeAndFlush(msg).addListener(writeListener);

			return;
		}
	}
}
 
Example #25
Source Project: Flink-CEPplus   Author: ljygz   File: PartitionRequestQueue.java    License: Apache License 2.0 5 votes vote down vote up
private void handleException(Channel channel, Throwable cause) throws IOException {
	LOG.error("Encountered error while consuming partitions", cause);

	fatalError = true;
	releaseAllResources();

	if (channel.isActive()) {
		channel.writeAndFlush(new ErrorResponse(cause)).addListener(ChannelFutureListener.CLOSE);
	}
}
 
Example #26
Source Project: Flink-CEPplus   Author: ljygz   File: NettyTestUtil.java    License: Apache License 2.0 5 votes vote down vote up
static Channel connect(NettyClient client, NettyServer server) throws Exception {
	final NettyConfig config = server.getConfig();

	return client
			.connect(new InetSocketAddress(config.getServerAddress(), config.getServerPort()))
			.sync()
			.channel();
}
 
Example #27
Source Project: Flink-CEPplus   Author: ljygz   File: PartitionRequestClientHandlerTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that {@link RemoteInputChannel#onFailedPartitionRequest()} is called when a
 * {@link PartitionNotFoundException} is received.
 */
@Test
public void testReceivePartitionNotFoundException() throws Exception {
	// Minimal mock of a remote input channel
	final BufferProvider bufferProvider = mock(BufferProvider.class);
	when(bufferProvider.requestBuffer()).thenReturn(TestBufferFactory.createBuffer(0));

	final RemoteInputChannel inputChannel = mock(RemoteInputChannel.class);
	when(inputChannel.getInputChannelId()).thenReturn(new InputChannelID());
	when(inputChannel.getBufferProvider()).thenReturn(bufferProvider);

	final ErrorResponse partitionNotFound = new ErrorResponse(
		new PartitionNotFoundException(new ResultPartitionID()),
		inputChannel.getInputChannelId());

	final PartitionRequestClientHandler client = new PartitionRequestClientHandler();
	client.addInputChannel(inputChannel);

	// Mock channel context
	ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
	when(ctx.channel()).thenReturn(mock(Channel.class));

	client.channelActive(ctx);

	client.channelRead(ctx, partitionNotFound);

	verify(inputChannel, times(1)).onFailedPartitionRequest();
}
 
Example #28
Source Project: Flink-CEPplus   Author: ljygz   File: CreditBasedPartitionRequestClientHandlerTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that {@link RemoteInputChannel#onFailedPartitionRequest()} is called when a
 * {@link PartitionNotFoundException} is received.
 */
@Test
public void testReceivePartitionNotFoundException() throws Exception {
	// Minimal mock of a remote input channel
	final BufferProvider bufferProvider = mock(BufferProvider.class);
	when(bufferProvider.requestBuffer()).thenReturn(TestBufferFactory.createBuffer(0));

	final RemoteInputChannel inputChannel = mock(RemoteInputChannel.class);
	when(inputChannel.getInputChannelId()).thenReturn(new InputChannelID());
	when(inputChannel.getBufferProvider()).thenReturn(bufferProvider);

	final ErrorResponse partitionNotFound = new ErrorResponse(
		new PartitionNotFoundException(new ResultPartitionID()),
		inputChannel.getInputChannelId());

	final CreditBasedPartitionRequestClientHandler client = new CreditBasedPartitionRequestClientHandler();
	client.addInputChannel(inputChannel);

	// Mock channel context
	ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
	when(ctx.channel()).thenReturn(mock(Channel.class));

	client.channelActive(ctx);

	client.channelRead(ctx, partitionNotFound);

	verify(inputChannel, times(1)).onFailedPartitionRequest();
}
 
Example #29
Source Project: Flink-CEPplus   Author: ljygz   File: Client.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Hands in a channel after a successful connection.
 *
 * @param channel Channel to hand in
 */
private void handInChannel(Channel channel) {
	synchronized (connectLock) {
		if (connectionShutdownFuture.get() != null || failureCause != null) {
			// Close the channel and we are done. Any queued requests
			// are removed on the close/failure call and after that no
			// new ones can be enqueued.
			channel.close();
		} else {
			established = new EstablishedConnection(serverAddress, serializer, channel);

			while (!queuedRequests.isEmpty()) {
				final PendingRequest pending = queuedRequests.poll();

				established.sendRequest(pending.request).whenComplete(
						(response, throwable) -> {
							if (throwable != null) {
								pending.completeExceptionally(throwable);
							} else {
								pending.complete(response);
							}
						});
			}

			// Publish the channel for the general public
			establishedConnections.put(serverAddress, established);
			pendingConnections.remove(serverAddress);

			// Check shut down for possible race with shut down. We
			// don't want any lingering connections after shut down,
			// which can happen if we don't check this here.
			if (clientShutdownFuture.get() != null) {
				if (establishedConnections.remove(serverAddress, established)) {
					established.close();
				}
			}
		}
	}
}
 
Example #30
Source Project: flink   Author: flink-tpc-ds   File: MesosArtifactServer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get the server port on which the artifact server is listening.
 */
public synchronized int getServerPort() {
	Channel server = this.serverChannel;
	if (server != null) {
		try {
			return ((InetSocketAddress) server.localAddress()).getPort();
		} catch (Exception e) {
			LOG.error("Cannot access local server port", e);
		}
	}
	return -1;
}