java.net.SocketTimeoutException#getMessage ( )源码实例Demo

下面列出了java.net.SocketTimeoutException#getMessage ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: react-native-sockets   文件: SocketClient.java
private void handleSocketTimeoutException(SocketTimeoutException e) {
    //debug log
    Log.e(eTag, "Client SocketTimeoutException", e);
    //emit event
    String message = e.getMessage();
    WritableMap eventParams = Arguments.createMap();
    eventParams.putString("error", e.getMessage());
    sendEvent(mReactContext, event_timeout, eventParams);
}
 
public void onSocketTimeoutException(SocketTimeoutException sockettimeoutexception)
{
    Message message = c.obtainMessage();
    message.obj = sockettimeoutexception.getMessage();
    message.what = -8;
    c.sendMessage(message);
}
 
源代码3 项目: cs-actions   文件: HttpClientExecutor.java
public CloseableHttpResponse execute() {
    CloseableHttpResponse response;
    try  {
         response = closeableHttpClient.execute(httpRequestBase, context);
    } catch (SocketTimeoutException ste) {
        throw new RuntimeException("Socket timeout: " + ste.getMessage(), ste);
    } catch (HttpHostConnectException connectEx) {
        throw new RuntimeException("Connection error: " + connectEx.getMessage(), connectEx);
    } catch (IOException e) {

        throw new RuntimeException("Error while executing http request: " + e.getMessage(), e);
    }
    return response;
}
 
源代码4 项目: letv   文件: BaseApi.java
public void onSocketTimeoutException(SocketTimeoutException socketTimeoutException) {
    Message obtainMessage = this.mHandler.obtainMessage();
    obtainMessage.obj = socketTimeoutException.getMessage();
    obtainMessage.what = -8;
    this.mHandler.sendMessage(obtainMessage);
}
 
源代码5 项目: hadoop   文件: NetUtils.java
/**
 * Like {@link NetUtils#connect(Socket, SocketAddress, int)} but
 * also takes a local address and port to bind the socket to. 
 * 
 * @param socket
 * @param endpoint the remote address
 * @param localAddr the local address to bind the socket to
 * @param timeout timeout in milliseconds
 */
public static void connect(Socket socket, 
                           SocketAddress endpoint,
                           SocketAddress localAddr,
                           int timeout) throws IOException {
  if (socket == null || endpoint == null || timeout < 0) {
    throw new IllegalArgumentException("Illegal argument for connect()");
  }
  
  SocketChannel ch = socket.getChannel();
  
  if (localAddr != null) {
    Class localClass = localAddr.getClass();
    Class remoteClass = endpoint.getClass();
    Preconditions.checkArgument(localClass.equals(remoteClass),
        "Local address %s must be of same family as remote address %s.",
        localAddr, endpoint);
    socket.bind(localAddr);
  }

  try {
    if (ch == null) {
      // let the default implementation handle it.
      socket.connect(endpoint, timeout);
    } else {
      SocketIOWithTimeout.connect(ch, endpoint, timeout);
    }
  } catch (SocketTimeoutException ste) {
    throw new ConnectTimeoutException(ste.getMessage());
  }

  // There is a very rare case allowed by the TCP specification, such that
  // if we are trying to connect to an endpoint on the local machine,
  // and we end up choosing an ephemeral port equal to the destination port,
  // we will actually end up getting connected to ourself (ie any data we
  // send just comes right back). This is only possible if the target
  // daemon is down, so we'll treat it like connection refused.
  if (socket.getLocalPort() == socket.getPort() &&
      socket.getLocalAddress().equals(socket.getInetAddress())) {
    LOG.info("Detected a loopback TCP socket, disconnecting it");
    socket.close();
    throw new ConnectException(
      "Localhost targeted connection resulted in a loopback. " +
      "No daemon is listening on the target port.");
  }
}
 
源代码6 项目: big-c   文件: NetUtils.java
/**
 * Like {@link NetUtils#connect(Socket, SocketAddress, int)} but
 * also takes a local address and port to bind the socket to. 
 * 
 * @param socket
 * @param endpoint the remote address
 * @param localAddr the local address to bind the socket to
 * @param timeout timeout in milliseconds
 */
public static void connect(Socket socket, 
                           SocketAddress endpoint,
                           SocketAddress localAddr,
                           int timeout) throws IOException {
  if (socket == null || endpoint == null || timeout < 0) {
    throw new IllegalArgumentException("Illegal argument for connect()");
  }
  
  SocketChannel ch = socket.getChannel();
  
  if (localAddr != null) {
    Class localClass = localAddr.getClass();
    Class remoteClass = endpoint.getClass();
    Preconditions.checkArgument(localClass.equals(remoteClass),
        "Local address %s must be of same family as remote address %s.",
        localAddr, endpoint);
    socket.bind(localAddr);
  }

  try {
    if (ch == null) {
      // let the default implementation handle it.
      socket.connect(endpoint, timeout);
    } else {
      SocketIOWithTimeout.connect(ch, endpoint, timeout);
    }
  } catch (SocketTimeoutException ste) {
    throw new ConnectTimeoutException(ste.getMessage());
  }

  // There is a very rare case allowed by the TCP specification, such that
  // if we are trying to connect to an endpoint on the local machine,
  // and we end up choosing an ephemeral port equal to the destination port,
  // we will actually end up getting connected to ourself (ie any data we
  // send just comes right back). This is only possible if the target
  // daemon is down, so we'll treat it like connection refused.
  if (socket.getLocalPort() == socket.getPort() &&
      socket.getLocalAddress().equals(socket.getInetAddress())) {
    LOG.info("Detected a loopback TCP socket, disconnecting it");
    socket.close();
    throw new ConnectException(
      "Localhost targeted connection resulted in a loopback. " +
      "No daemon is listening on the target port.");
  }
}
 
private void postConnectionQueries() throws SQLException {
  try {

    if (options.usePipelineAuth
        && (options.socketTimeout == null
            || options.socketTimeout == 0
            || options.socketTimeout > 500)) {
      // set a timeout to avoid hang in case server doesn't support pipelining
      socket.setSoTimeout(500);
    }

    boolean mustLoadAdditionalInfo = true;
    if (globalInfo != null) {
      if (globalInfo.isAutocommit() == options.autocommit) {
        mustLoadAdditionalInfo = false;
      }
    }

    if (mustLoadAdditionalInfo) {
      Map<String, String> serverData = new TreeMap<>();
      if (options.usePipelineAuth && !options.createDatabaseIfNotExist) {
        try {
          sendPipelineAdditionalData();
          readPipelineAdditionalData(serverData);
        } catch (SQLException sqle) {
          if ("08".equals(sqle.getSQLState())) {
            throw sqle;
          }
          // in case pipeline is not supported
          // (proxy flush socket after reading first packet)
          additionalData(serverData);
        }
      } else {
        additionalData(serverData);
      }

      writer.setMaxAllowedPacket(Integer.parseInt(serverData.get("max_allowed_packet")));
      autoIncrementIncrement = Integer.parseInt(serverData.get("auto_increment_increment"));
      loadCalendar(serverData.get("time_zone"), serverData.get("system_time_zone"));

    } else {

      writer.setMaxAllowedPacket((int) globalInfo.getMaxAllowedPacket());
      autoIncrementIncrement = globalInfo.getAutoIncrementIncrement();
      loadCalendar(globalInfo.getTimeZone(), globalInfo.getSystemTimeZone());
    }

    reader.setServerThreadId(this.serverThreadId, isMasterConnection());
    writer.setServerThreadId(this.serverThreadId, isMasterConnection());

    activeStreamingResult = null;
    hostFailed = false;

    if (options.usePipelineAuth) {
      // reset timeout to configured value
      if (options.socketTimeout != null) {
        socket.setSoTimeout(options.socketTimeout);
      } else {
        socket.setSoTimeout(0);
      }
    }

  } catch (SocketTimeoutException timeoutException) {
    destroySocket();
    String msg = "Socket error during post connection queries: " + timeoutException.getMessage();
    if (options.usePipelineAuth) {
      msg +=
          "\nServer might not support pipelining, try disabling with option `usePipelineAuth` and `useBatchMultiSend`";
    }
    throw exceptionFactory.create(msg, "08000", timeoutException);
  } catch (IOException ioException) {
    destroySocket();
    throw exceptionFactory.create(
        "Socket error during post connection queries: " + ioException.getMessage(),
        "08000",
        ioException);
  } catch (SQLException sqlException) {
    destroySocket();
    throw sqlException;
  }
}