@Override public Channel getOpenChannelOrFail() throws ChannelClosedException { final Channel ch = getChannelOrFail(); if (ch.isClosingOrClosed()) { // TODO: Since Remoting 2.33, we still need to explicitly declare minimum Remoting version throw new ChannelClosedException(new IllegalStateException("The associated channel " + ch + " is closing down or has closed down", ch.getCloseRequestCause())); } return ch; } }
@Override public void checkIfCanBeExecutedOnChannel(Channel channel) throws IOException { // Default check for all requests super.checkIfCanBeExecutedOnChannel(channel); // We also do not want to run UserRequests when the channel is being closed if (channel.isClosingOrClosed()) { throw new ChannelClosedException("The request cannot be executed on channel " + channel + ". " + "The channel is closing down or has closed down", channel.getCloseRequestCause()); } } }
@Override public void checkIfCanBeExecutedOnChannel(Channel channel) throws IOException { // Default check for all requests super.checkIfCanBeExecutedOnChannel(channel); // We also do not want to run UserRequests when the channel is being closed if (channel.isClosingOrClosed()) { throw new ChannelClosedException("The request cannot be executed on channel " + channel + ". " + "The channel is closing down or has closed down", channel.getCloseRequestCause()); } }
/** * Gets an open channel, which is ready to accept commands. * * It is a convenience method for cases, when a callable needs to invoke call backs on the master. * In such case the requests will be likely failed by {@linkplain UserRequest} logic anyway, but it is better to fail fast. * * @return Channel instance * @throws ChannelStateException The channel is closing down or has been closed. * Also happens if the channel is not associated with the thread at all. * @since TODO */ @Nonnull default Channel getOpenChannelOrFail() throws ChannelStateException { final Channel ch = getChannelOrFail(); if (ch.isClosingOrClosed()) { throw new ChannelClosedException(ch, "The associated channel " + ch + " is closing down or has closed down", ch.getCloseRequestCause()); } return ch; } }
+ "The channel is closing down or has closed down", getCloseRequestCause());
/** * {@inheritDoc} */ public <V,T extends Throwable> Future<V> callAsync(final Callable<V,T> callable) throws IOException { if (isClosingOrClosed()) { // No reason to even try performing a user request throw new ChannelClosedException("Remote call on " + name + " failed. " + "The channel is closing down or has closed down", getCloseRequestCause()); } final Future<UserRequest.ResponseToUserRequest<V, T>> f = new UserRequest<V, T>(this, callable).callAsync(this); return new FutureAdapter<V, UserRequest.ResponseToUserRequest<V, T>>(f) { @Override protected V adapt(UserRequest.ResponseToUserRequest<V, T> r) throws ExecutionException { try { return r.retrieve(Channel.this, UserRequest.getClassLoader(callable)); } catch (Throwable t) {// really means catch(T t) throw new ExecutionException(t); } } }; }