use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelException in project flink by apache.
the class AkkaBootstrapTools method startRemoteActorSystem.
/**
* Starts a remote Actor System at given address and specific port.
*
* @param configuration The Flink configuration.
* @param actorSystemName Name of the started {@link ActorSystem}
* @param externalAddress The external address to access the ActorSystem.
* @param externalPort The external port to access the ActorSystem.
* @param bindAddress The local address to bind to.
* @param bindPort The local port to bind to.
* @param logger the logger to output log information.
* @param actorSystemExecutorConfiguration configuration for the ActorSystem's underlying
* executor
* @param customConfig Custom Akka config to be combined with the config derived from Flink
* configuration.
* @return The ActorSystem which has been started.
* @throws Exception
*/
private static ActorSystem startRemoteActorSystem(Configuration configuration, String actorSystemName, String externalAddress, int externalPort, String bindAddress, int bindPort, Logger logger, Config actorSystemExecutorConfiguration, Config customConfig) throws Exception {
String externalHostPortUrl = NetUtils.unresolvedHostAndPortToNormalizedString(externalAddress, externalPort);
String bindHostPortUrl = NetUtils.unresolvedHostAndPortToNormalizedString(bindAddress, bindPort);
logger.info("Trying to start actor system, external address {}, bind address {}.", externalHostPortUrl, bindHostPortUrl);
try {
Config akkaConfig = AkkaUtils.getAkkaConfig(configuration, new HostAndPort(externalAddress, externalPort), new HostAndPort(bindAddress, bindPort), actorSystemExecutorConfiguration);
if (customConfig != null) {
akkaConfig = customConfig.withFallback(akkaConfig);
}
return startActorSystem(akkaConfig, actorSystemName, logger);
} catch (Throwable t) {
if (t instanceof ChannelException) {
Throwable cause = t.getCause();
if (cause != null && t.getCause() instanceof BindException) {
throw new IOException("Unable to create ActorSystem at address " + bindHostPortUrl + " : " + cause.getMessage(), t);
}
}
throw new Exception("Could not create actor system", t);
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelException in project netty by netty.
the class SslHandler method handlerRemoved0.
@Override
public void handlerRemoved0(ChannelHandlerContext ctx) throws Exception {
try {
if (!pendingUnencryptedWrites.isEmpty()) {
// Check if queue is not empty first because create a new ChannelException is expensive
pendingUnencryptedWrites.releaseAndFailAll(ctx, new ChannelException("Pending write on removal of SslHandler"));
}
pendingUnencryptedWrites = null;
SSLException cause = null;
// pipeline.
if (!handshakePromise.isDone()) {
cause = new SSLHandshakeException("SslHandler removed before handshake completed");
if (handshakePromise.tryFailure(cause)) {
ctx.fireUserEventTriggered(new SslHandshakeCompletionEvent(cause));
}
}
if (!sslClosePromise.isDone()) {
if (cause == null) {
cause = new SSLException("SslHandler removed before SSLEngine was closed");
}
notifyClosePromise(cause);
}
} finally {
ReferenceCountUtil.release(engine);
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelException in project netty by netty.
the class EpollSocketChannelConfigTest method testGetOptionWhenClosed.
// For this test to pass, we are relying on the sockets file descriptor not being reused after the socket is closed.
// This is inherently racy, so we allow getSoLinger to throw ChannelException a few of times, but eventually we do
// want to see a ClosedChannelException for the test to pass.
@RepeatedIfExceptionsTest(repeats = 4)
public void testGetOptionWhenClosed() {
ch.close().syncUninterruptibly();
ChannelException e = assertThrows(ChannelException.class, new Executable() {
@Override
public void execute() throws Throwable {
ch.config().getSoLinger();
}
});
assertThat(e).hasCauseInstanceOf(ClosedChannelException.class);
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelException in project netty by netty.
the class NioEventLoop method openSelector.
private SelectorTuple openSelector() {
final Selector unwrappedSelector;
try {
unwrappedSelector = provider.openSelector();
} catch (IOException e) {
throw new ChannelException("failed to open a new selector", e);
}
if (DISABLE_KEY_SET_OPTIMIZATION) {
return new SelectorTuple(unwrappedSelector);
}
Object maybeSelectorImplClass = AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
public Object run() {
try {
return Class.forName("sun.nio.ch.SelectorImpl", false, PlatformDependent.getSystemClassLoader());
} catch (Throwable cause) {
return cause;
}
}
});
if (!(maybeSelectorImplClass instanceof Class) || // ensure the current selector implementation is what we can instrument.
!((Class<?>) maybeSelectorImplClass).isAssignableFrom(unwrappedSelector.getClass())) {
if (maybeSelectorImplClass instanceof Throwable) {
Throwable t = (Throwable) maybeSelectorImplClass;
logger.trace("failed to instrument a special java.util.Set into: {}", unwrappedSelector, t);
}
return new SelectorTuple(unwrappedSelector);
}
final Class<?> selectorImplClass = (Class<?>) maybeSelectorImplClass;
final SelectedSelectionKeySet selectedKeySet = new SelectedSelectionKeySet();
Object maybeException = AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
public Object run() {
try {
Field selectedKeysField = selectorImplClass.getDeclaredField("selectedKeys");
Field publicSelectedKeysField = selectorImplClass.getDeclaredField("publicSelectedKeys");
if (PlatformDependent.javaVersion() >= 9 && PlatformDependent.hasUnsafe()) {
// Let us try to use sun.misc.Unsafe to replace the SelectionKeySet.
// This allows us to also do this in Java9+ without any extra flags.
long selectedKeysFieldOffset = PlatformDependent.objectFieldOffset(selectedKeysField);
long publicSelectedKeysFieldOffset = PlatformDependent.objectFieldOffset(publicSelectedKeysField);
if (selectedKeysFieldOffset != -1 && publicSelectedKeysFieldOffset != -1) {
PlatformDependent.putObject(unwrappedSelector, selectedKeysFieldOffset, selectedKeySet);
PlatformDependent.putObject(unwrappedSelector, publicSelectedKeysFieldOffset, selectedKeySet);
return null;
}
// We could not retrieve the offset, lets try reflection as last-resort.
}
Throwable cause = ReflectionUtil.trySetAccessible(selectedKeysField, true);
if (cause != null) {
return cause;
}
cause = ReflectionUtil.trySetAccessible(publicSelectedKeysField, true);
if (cause != null) {
return cause;
}
selectedKeysField.set(unwrappedSelector, selectedKeySet);
publicSelectedKeysField.set(unwrappedSelector, selectedKeySet);
return null;
} catch (NoSuchFieldException e) {
return e;
} catch (IllegalAccessException e) {
return e;
}
}
});
if (maybeException instanceof Exception) {
selectedKeys = null;
Exception e = (Exception) maybeException;
logger.trace("failed to instrument a special java.util.Set into: {}", unwrappedSelector, e);
return new SelectorTuple(unwrappedSelector);
}
selectedKeys = selectedKeySet;
logger.trace("instrumented a special java.util.Set into: {}", unwrappedSelector);
return new SelectorTuple(unwrappedSelector, new SelectedSelectionKeySetSelector(unwrappedSelector, selectedKeySet));
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelException in project netty by netty.
the class EpollSocketChannelConfig method setSendBufferSize.
@Override
public EpollSocketChannelConfig setSendBufferSize(int sendBufferSize) {
try {
((EpollSocketChannel) channel).socket.setSendBufferSize(sendBufferSize);
calculateMaxBytesPerGatheringWrite();
return this;
} catch (IOException e) {
throw new ChannelException(e);
}
}
Aggregations