Skip to content

Commit

Permalink
~ rethrow exceptions when binding server transport
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinherron committed Nov 3, 2022
1 parent f11d2e6 commit 42e1123
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
Expand Up @@ -12,8 +12,21 @@

public interface OpcServerTransport {

/**
* Bind a {@link ServerApplicationContext} to the given bind address and port.
*
* @param applicationContext the {@link ServerApplicationContext} to bind.
* @param bindAddress the local address to bind to.
* @param bindPort the local port to bind to.
* @throws Exception if an error occurs binding to the address/port combination.
*/
void bind(ServerApplicationContext applicationContext, String bindAddress, int bindPort) throws Exception;

/**
* Unbind this transport (close the server channel).
*
* @throws Exception if an error occurs unbinding this transport.
*/
void unbind() throws Exception;

}
Expand Up @@ -15,6 +15,7 @@
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.socket.SocketChannel;
Expand Down Expand Up @@ -48,19 +49,21 @@ public void bind(ServerApplicationContext applicationContext, String bindAddress
@Override
protected void initChannel(SocketChannel channel) {
channel.pipeline().addLast(RateLimitingHandler.getInstance());
channel.pipeline().addLast(new UascServerHelloHandler(config, applicationContext, TransportProfile.TCP_UASC_UABINARY));
channel.pipeline().addLast(
new UascServerHelloHandler(config, applicationContext, TransportProfile.TCP_UASC_UABINARY)
);
}
});

Channel channel = bootstrap.bind(bindAddress, bindPort).await().channel();
channelReference.set(channel);
ChannelFuture bindFuture = bootstrap.bind(bindAddress, bindPort).sync();
channelReference.set(bindFuture.channel());
}

@Override
public void unbind() throws Exception {
Channel channel = channelReference.getAndSet(null);
if (channel != null) {
channel.close().get();
channel.close().sync();
}
}

Expand Down
Expand Up @@ -16,12 +16,37 @@

public interface UascServerConfig {

/**
* Get the {@link ExecutorService} to use when dispatching inbound {@link UascServiceRequest}s
* that arrive while on the Netty event loop thread.
*
* @return the {@link ExecutorService} to use when dispatching inbound
* {@link UascServiceRequest}s.
*/
ExecutorService getExecutor();

/**
* Get the deadline, in milliseconds, that a "Hello" message must arrive by after the
* underlying channel is activated.
*
* @return the "Hello" message deadline, in milliseconds.
*/
UInteger getHelloDeadline();

/**
* Get the maximum allowed secure channel lifetime, in milliseconds. Requested lifetimes
* larger than this value will be reduced to this value.
*
* @return the maximum allowed secure channel lifetime, in milliseconds.
*/
UInteger getMaximumSecureChannelLifetime();

/**
* Get the minimum allowed secure channel lifetime, in milliseconds. Requested lifetimes
* smaller than this value will be increased to this value.
*
* @return the minimum allowed secure channel lifetime, in milliseconds.
*/
UInteger getMinimumSecureChannelLifetime();

}

0 comments on commit 42e1123

Please sign in to comment.