/** * Closes the client (disconnects the client) if the client is connected. */ private void disconnectClient() { if (isConnected()) { client.close(); } }
/** * Reconnects the client if it's not already connected. * * @throws IOException * If {@link IOException} occurs during the connection. */ private void reconnectClient() throws IOException { if (!isConnected()) { client.reconnect(); bindServices(); } }
/** * {@inheritDoc} */ @Override public void reconnect() throws ConnectException { if ((null != client) && !isConnected()) { try { reconnectClient(); log.info("KryoNet: Reconnection successful!"); connectionException = false; synchronized (reconnectionMonitor) { reconnectionMonitor.notifyAll(); } } catch (Exception exception) { connectionException = true; ConnectException e = new ConnectException(exception.getMessage()); e.initCause(exception); throw e; // NOPMD root cause exception is set } } }
/** * {@inheritDoc} */ @Override public void connect(String host, int port) throws ConnectException { if (!isConnected()) { try { if (!connectionException) { log.info("KryoNet: Connecting to " + host + ":" + port); } startClient(host, port); log.info("KryoNet: Connection established!"); connectionException = false; } catch (Exception exception) { if (!connectionException) { log.info("KryoNet: Connection to the server failed."); } connectionException = true; stopClient(); if (log.isTraceEnabled()) { log.trace("connect()", exception); } ConnectException e = new ConnectException(exception.getMessage()); e.initCause(exception); throw e; // NOPMD root cause exception is set } } }
public Collection<JmxAttributeDescriptor> analyzeJmxAttributes(final long platformIdent, final Collection<JmxAttributeDescriptor> descriptors) throws ServerUnavailableException, BusinessException { if (!isConnected()) { throw new ServerUnavailableException();
if (!isConnected()) { throw new ServerUnavailableException();
if (!isConnected()) { throw new ServerUnavailableException();
if (!isConnected()) { throw new ServerUnavailableException();
if (!isConnected()) { throw new ServerUnavailableException();
/** * {@inheritDoc} */ @Override public void sendDataObjects(List<? extends DefaultData> measurements) throws ServerUnavailableException { if (!isConnected()) { throw new ServerUnavailableException(); } if ((null != measurements) && !measurements.isEmpty()) { try { AddDataObjects remote = new AddDataObjects(agentStorageService, measurements); remote.makeCall(); } catch (ExecutionException executionException) { // there should be no execution exception log.error("Could not send data objects", executionException); } catch (ServerUnavailableException e) { if (!e.isServerTimeout()) { disconnectClient(); } throw e; } } }
/** * {@inheritDoc} */ @Override public void sendKeepAlive(final long platformId) throws ServerUnavailableException { if (!isConnected()) { throw new ServerUnavailableException(); } FailFastRemoteMethodCall<IKeepAliveService, Void> call = new FailFastRemoteMethodCall<IKeepAliveService, Void>(keepAliveService) { @Override protected Void performRemoteCall(IKeepAliveService service) { service.sendKeepAlive(platformId); return null; } }; try { call.makeCall(); } catch (ExecutionException e) { // there should be no execution exception log.error("Exception thrown while trying to send keep-alive signal to the server.", e); } catch (ServerUnavailableException e) { if (!e.isServerTimeout()) { disconnectClient(); } throw e; } }
/** * {@inheritDoc} */ @Override public void instrumentationApplied(final long platformIdent, Map<Long, long[]> methodToSensorMap) throws ServerUnavailableException { if (!isConnected()) { throw new ServerUnavailableException(); } if (MapUtils.isNotEmpty(methodToSensorMap)) { try { InstrumentationAppliedCall call = new InstrumentationAppliedCall(agentService, platformIdent, methodToSensorMap); call.makeCall(); } catch (ExecutionException executionException) { // there should be no execution exception log.error("Could not sent instrumented method ids", executionException); } catch (ServerUnavailableException e) { if (!e.isServerTimeout()) { disconnectClient(); } throw e; } } }