/** * Checks that the service version is compatible with the client. * * @param clientVersion the client version */ protected void checkVersion(long clientVersion) throws IOException { if (mServiceVersion == Constants.UNKNOWN_SERVICE_VERSION) { mServiceVersion = getRemoteServiceVersion(); if (mServiceVersion != clientVersion) { throw new IOException(ExceptionMessage.INCOMPATIBLE_VERSION.getMessage(getServiceName(), clientVersion, mServiceVersion)); } } }
/** * Closes the connection with the Alluxio remote and does the necessary cleanup. It should be used * if the client has not connected with the remote for a while, for example. */ public synchronized void disconnect() { if (mConnected) { Preconditions.checkNotNull(mChannel, PreconditionMessage.CHANNEL_NULL_WHEN_CONNECTED); LOG.debug("Disconnecting from the {} @ {}", getServiceName(), mAddress); beforeDisconnect(); mChannel.shutdown(); mConnected = false; afterDisconnect(); } }
} catch (UnavailableException e) { LOG.warn("Failed to determine {} rpc address ({}): {}", getServiceName(), retryPolicy.getAttemptCount(), e.toString()); continue; beforeConnect(); LOG.info("Alluxio client (version {}) is trying to connect with {} @ {}", RuntimeConstants.VERSION, getServiceName(), mAddress); mChannel = GrpcChannelBuilder .newBuilder(mAddress, mContext.getConf()) checkVersion(getServiceVersion()); LOG.info("Alluxio client (version {}) is connected with {} @ {}", RuntimeConstants.VERSION, getServiceName(), mAddress); return; } catch (IOException e) { LOG.warn("Failed to connect ({}) with {} @ {}: {}", retryPolicy.getAttemptCount(), getServiceName(), mAddress, e.getMessage()); String.format("Failed to determine address for %s after %s attempts", getServiceName(), retryPolicy.getAttemptCount())); getServiceName(), mAddress, retryPolicy.getAttemptCount()));
private void doConnect() throws IOException, TTransportException { LOG.info("Alluxio client (version {}) is trying to connect with {} @ {}", RuntimeConstants.VERSION, getServiceName(), mAddress); // The wrapper transport TTransport clientTransport = TransportProvider.Factory.create().getClientTransport(mParentSubject, mAddress); mProtocol = ThriftUtils.createThriftProtocol(clientTransport, getServiceName()); mProtocol.getTransport().open(); LOG.info("Client registered with {} @ {}", getServiceName(), mAddress); mConnected = true; afterConnect(); checkVersion(getClient(), getServiceVersion()); }
/** * Closes the connection with the Alluxio remote and does the necessary cleanup. It should be used * if the client has not connected with the remote for a while, for example. */ public synchronized void disconnect() { if (mConnected) { Preconditions.checkNotNull(mProtocol, PreconditionMessage.PROTOCOL_NULL_WHEN_CONNECTED); LOG.debug("Disconnecting from the {} @ {}", getServiceName(), mAddress); beforeDisconnect(); mProtocol.getTransport().close(); mConnected = false; afterDisconnect(); } }
/** * Checks that the service version is compatible with the client. * * @param client the service client * @param version the client version */ protected void checkVersion(AlluxioService.Client client, long version) throws IOException { if (mServiceVersion == Constants.UNKNOWN_SERVICE_VERSION) { try { mServiceVersion = client.getServiceVersion(new GetServiceVersionTOptions()).getVersion(); } catch (TException e) { throw new IOException(e); } if (mServiceVersion != version) { throw new IOException(ExceptionMessage.INCOMPATIBLE_VERSION.getMessage(getServiceName(), version, mServiceVersion)); } } }
} catch (UnavailableException e) { LOG.warn("Failed to determine {} rpc address ({}): {}", getServiceName(), retryPolicy.getAttemptCount(), e.toString()); continue; } catch (UnavailableException e) { LOG.warn("Failed to handshake ({}) with {} @ {}: {}", retryPolicy.getAttemptCount(), getServiceName(), mAddress, e.getMessage()); continue; } catch (IOException | TTransportException e) { LOG.warn("Failed to connect ({}) with {} @ {}: {}", retryPolicy.getAttemptCount(), getServiceName(), mAddress, e.getMessage()); if (e.getCause() instanceof java.net.SocketTimeoutException) { String.format("Failed to determine address for %s after %s attempts", getServiceName(), retryPolicy.getAttemptCount())); getServiceName(), mAddress, retryPolicy.getAttemptCount()));