Utility function to check if channel is ok.
Mainly to throw IOException instead of runtime exception
in case of mismatch. This mismatch can occur for many runtime
reasons.
974052
static void checkChannelValidity(Object channel) throws IOException {
    if (channel == null) {
      /* Most common reason is that original socket does not have a channel.
       * So making this an IOException rather than a RuntimeException.
       */
      throw new IOException("Channel is null. Check " +
                            "how the channel or socket is created.");
    }
    
    if (!(channel instanceof SelectableChannel)) {
      throw new IOException("Channel should be a SelectableChannel");
    }    
  }
450714
protected void recoverFromException(final String channel, final Exception e) {
        final RecoveryStrategy recoveryStrategy = this.exceptionHandlerRef.get().onException(this, e, channel);
        switch (recoveryStrategy) {
        case RECONNECT:
            LOG.info("Ignoring RECONNECT strategy in response to exception because this is a pool", e);
            break;
        case TERMINATE:
            LOG.warn("Terminating in response to exception", e);
            end(false);
            break;
        case PROCEED:
            break;
        default:
            LOG.error("Unknown RecoveryStrategy: " + recoveryStrategy 
                    + " while attempting to recover from the following exception; Admin proceeding...", e);
            break;
        }
    }
1169627
public void handleError(SelectableChannel channel) {
    SocketAddress channelAddress = ((SocketChannel) channel).socket().getRemoteSocketAddress();
    LOG.info("Handling error from channel: " + channelAddress);
    SocketChannelHelper helper = activeConnections.get(channel);
    if (helper == null) {
      LOG.severe("Inactive channel had error?");
      return;
    }
    helper.clear();
    LOG.info("Removing all interest on channel: " + channelAddress);
    nioLooper.removeAllInterest(channel);
    try {
      channel.close();
    } catch (IOException e) {
      LOG.severe("Error closing connection in handleError");
    }
    activeConnections.remove(channel);
    onClose((SocketChannel) channel);
  }
239003
private static void check(byte[] encoding) throws IOException {
        int length = encoding.length;
        if (length < 1 ||      // too short
                (encoding[length - 1] & 0x80) != 0) {  // not ended
            throw new IOException("ObjectIdentifier() -- " +
                    "Invalid DER encoding, not ended");
        }
        for (int i=0; i<length; i++) {
            // 0x80 at the beginning of a subidentifier
            if (encoding[i] == (byte)0x80 &&
                    (i==0 || (encoding[i-1] & 0x80) == 0)) {
                throw new IOException("ObjectIdentifier() -- " +
                        "Invalid DER encoding, useless extra octet detected");
            }
        }
    }
1113174
private void checkForThreadErrors() throws IOException {
    if(error == true && childException != null) {
      error = false;
      IOException temp = childException;
      childException = null;
      throw temp;
    }
  }
744438
@Override
  public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) {
    final Channel channel = ctx.channel();

    LOG.log(Level.INFO, "Unexpected exception from downstream. channel: {0} local: {1} remote: {2}",
        new Object[]{channel, channel.localAddress(), channel.remoteAddress()});
    LOG.log(Level.WARNING, "Unexpected exception from downstream.", cause);
    channel.close();
    this.listener.exceptionCaught(ctx, cause);
  }
352632
public final void mNOT() throws RecognitionException {
        try {
            int _type = NOT;
            int _channel = DEFAULT_TOKEN_CHANNEL;
            // C:\\Project\\Obdalib\\obdalib-parent\\obdalib-core\\src\\main\\java\\it\\unibz\\inf\\obda\\gui\\swing\\utils\\MappingFilter.g:112:4: ( ( 'N' | 'n' ) ( 'O' | 'o' ) ( 'T' | 't' ) )
            // C:\\Project\\Obdalib\\obdalib-parent\\obdalib-core\\src\\main\\java\\it\\unibz\\inf\\obda\\gui\\swing\\utils\\MappingFilter.g:112:6: ( 'N' | 'n' ) ( 'O' | 'o' ) ( 'T' | 't' )
            {
            if ( input.LA(1)=='N'||input.LA(1)=='n' ) {
                input.consume();
            }
            else {
                MismatchedSetException mse = new MismatchedSetException(null,input);
                recover(mse);
                throw mse;
            }


            if ( input.LA(1)=='O'||input.LA(1)=='o' ) {
                input.consume();
            }
            else {
                MismatchedSetException mse = new MismatchedSetException(null,input);
                recover(mse);
                throw mse;
            }


            if ( input.LA(1)=='T'||input.LA(1)=='t' ) {
                input.consume();
            }
            else {
                MismatchedSetException mse = new MismatchedSetException(null,input);
                recover(mse);
                throw mse;
            }


            }

            state.type = _type;
            state.channel = _channel;
        }
        finally {
        	// do for sure before leaving
        }
    }
294934
@Override
  public void exceptionCaught(ChannelHandlerContext ctx, Throwable exception) throws Exception {
    if (exception instanceof FrameDecodingException) {
      int streamId = ((FrameDecodingException) exception).streamId;
      LOG.debug("[{}] Error while decoding response on stream id {}", logPrefix, streamId);
      if (streamId >= 0) {
        // We know which request matches the failing response, fail that one only
        ResponseCallback responseCallback = inFlight.get(streamId);
        if (responseCallback != null) {
          try {
            responseCallback.onFailure(exception.getCause());
          } catch (Throwable t) {
            Loggers.warnWithException(
                LOG, "[{}] Unexpected error while invoking failure handler", logPrefix, t);
          }
        }
        release(streamId, ctx);
      } else {
        Loggers.warnWithException(
            LOG,
            "[{}] Unexpected error while decoding incoming event frame",
            logPrefix,
            exception.getCause());
      }
    } else {
      // Otherwise fail all pending requests
      abortAllInFlight(
          (exception instanceof HeartbeatException)
              ? (HeartbeatException) exception
              : new ClosedConnectionException("Unexpected error on channel", exception));
      ctx.close();
    }
  }
262067
@SuppressWarnings("unused")
    public void error(VirtualConnection vc, TCPWriteRequestContext wsc, IOException ioe) {

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "error() called for vc=" + vc + " ioe=" + ioe);
        }
        HttpInboundServiceContextImpl isc = (HttpInboundServiceContextImpl) vc.getStateMap().get(CallbackIDs.CALLBACK_HTTPISC);

        // log the failed response write
        if (isc.getHttpConfig().getDebugLog().isEnabled(DebugLog.Level.WARN)) {
            isc.getHttpConfig().getDebugLog().log(DebugLog.Level.WARN, HttpMessages.MSG_WRITE_FAIL, isc);
        }
        // close the connection now. No app channel has been involved at this
        // point yet.
        isc.getLink().close(vc, ioe);
    }
1317942
def _recv_flow_ok(self, method_frame):
        '''
        
        '''
        self.channel._active = method_frame.args.read_bit()
        if self._flow_control_cb is not None:
            self._flow_control_cb()
745958
def ok_check(function, *args, **kwargs):
    ''''''
    req = function(*args, **kwargs)
    if req.content.lower() != 'ok':
        raise ClientException(req.content)
    return req.content
897755
private int checkLinkAbleToExceptionMessage()
                    throws SIException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "checkLinkAbleToExceptionMessage");

        int blockingReason = DestinationHandler.OUTPUT_HANDLER_NOT_FOUND;

        blockingReason = checkCanExceptionMessage(_destination);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "checkLinkAbleToExceptionMessage", Integer.valueOf(blockingReason));

        return blockingReason;
    }
20099
private int onException(Exception e) throws IOException {
        eofReached = true;
        if (e instanceof IOException) {
            throw (IOException) e;
        } else if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        } else {
            // Impossible since InputStream throws no other checked exceptions.
            throw Throwables.failure(e);
        }
    }
161344
InputStream readChannel(int channel)
        throws IOException
    {
        while (!isClosed) {
            if (inputReady[channel]) {
                inputReady[channel] = false;
                return is;
            }

            boolean canRead = false;
            synchronized (READ_LOCK) {
                if (!isReadLocked) {
                    isReadLocked = true;
                    canRead = true;
                }
                else {
                    try {
                        READ_LOCK.wait(5000);
                    } catch (Exception e) {
                    }
                }
            }

            if (canRead) {
                try {
                    readData();
                } catch (IOException e) {
                    close();
                }
            }
        }

        return null;
    }
489641
OutputStream writeChannel(int channel)
        throws IOException
    {
        while (os != null) {
            boolean canWrite = false;
            synchronized (WRITE_LOCK) {
                if (!isWriteLocked) {
                    isWriteLocked = true;
                    canWrite = true;
                }
                else {
                    try {
                        WRITE_LOCK.wait(5000);
                    } catch (Exception e) {
                    }
                }
            }

            if (canWrite) {
                os.write('C');
                os.write(channel >> 8);
                os.write(channel);

                return os;
            }
        }

        return null;
    }
648643
def _recv_close_ok(self, method_frame):
        '''
        
        '''
        self.channel._closed = True
        self.channel._closed_cb()
368817
public boolean startCall(int channel, MuxInputStream in, MuxOutputStream out)
        throws IOException
    {
        // XXX: Eventually need to check to see if the channel is used.
        // It's not clear whether this should cause a wait or an exception.

        in.init(this, channel);
        out.init(this, channel);

        return true;
    }