@Override public void run() { try { byte[] buf = new byte[1024]; while (isOpen()) { int result = Socket.recv(handle, buf, 0, buf.length); if (result < Status.APR_SUCCESS) { throwException(result); } messageReceived(new ByteArrayBuffer(buf, 0, result)); } } catch (Exception e) { if (isOpen()) { log.warn(e.getClass().getSimpleName() + " while still open: " + e.getMessage()); } else { if (log.isDebugEnabled()) { log.debug("Closed client loop exception", e); } } } finally { try { close(); } catch (IOException e) { if (log.isDebugEnabled()) { log.debug(e.getClass().getSimpleName() + " while closing: " + e.getMessage()); } } } }
public AgentClient(String authSocket, CloseableExecutorService executor) throws IOException { super((executor == null) ? ThreadUtils.newSingleThreadExecutor("AgentClient[" + authSocket + "]") : executor); this.authSocket = authSocket; try { pool = Pool.create(AprLibrary.getInstance().getRootPool()); handle = Local.create(authSocket, pool); int result = Local.connect(handle, 0); if (result != Status.APR_SUCCESS) { throwException(result); } receiveBuffer = new ByteArrayBuffer(); messages = new ArrayBlockingQueue<>(10); CloseableExecutorService service = getExecutorService(); pumper = service.submit(this); } catch (IOException e) { throw e; } catch (Exception e) { throw new SshException(e); } }
@Override public SshAgent createClient(FactoryManager manager) throws IOException { String authSocket = manager.getString(SshAgent.SSH_AUTHSOCKET_ENV_NAME); if (GenericUtils.isEmpty(authSocket)) { throw new SshException("No " + SshAgent.SSH_AUTHSOCKET_ENV_NAME + " value"); } return new AgentClient(authSocket, newExecutor()); }
@Override protected synchronized Buffer request(Buffer buffer) throws IOException { int wpos = buffer.wpos(); buffer.wpos(0); buffer.putInt(wpos - 4); buffer.wpos(wpos); synchronized (messages) { try { int result = Socket.send(handle, buffer.array(), buffer.rpos(), buffer.available()); if (result < Status.APR_SUCCESS) { throwException(result); } if (messages.isEmpty()) { messages.wait(); } return messages.poll(); } catch (InterruptedException e) { throw (IOException) new InterruptedIOException(authSocket + ": Interrupted while polling for messages").initCause(e); } } }
public AgentClient(String authSocket, CloseableExecutorService executor) throws IOException { super((executor == null) ? ThreadUtils.newSingleThreadExecutor("AgentClient[" + authSocket + "]") : executor); this.authSocket = authSocket; try { pool = Pool.create(AprLibrary.getInstance().getRootPool()); handle = Local.create(authSocket, pool); int result = Local.connect(handle, 0); if (result != Status.APR_SUCCESS) { throwException(result); } receiveBuffer = new ByteArrayBuffer(); messages = new ArrayBlockingQueue<>(10); CloseableExecutorService service = getExecutorService(); pumper = service.submit(this); } catch (IOException e) { throw e; } catch (Exception e) { throw new SshException(e); } }
@Override public SshAgent createClient(FactoryManager manager) throws IOException { String authSocket = manager.getString(SshAgent.SSH_AUTHSOCKET_ENV_NAME); if (GenericUtils.isEmpty(authSocket)) { throw new SshException("No " + SshAgent.SSH_AUTHSOCKET_ENV_NAME + " value"); } return new AgentClient(authSocket, newExecutor()); }
@Override protected synchronized Buffer request(Buffer buffer) throws IOException { int wpos = buffer.wpos(); buffer.wpos(0); buffer.putInt(wpos - 4); buffer.wpos(wpos); synchronized (messages) { try { int result = Socket.send(handle, buffer.array(), buffer.rpos(), buffer.available()); if (result < Status.APR_SUCCESS) { throwException(result); } if (messages.isEmpty()) { messages.wait(); } return messages.poll(); } catch (InterruptedException e) { throw (IOException) new InterruptedIOException(authSocket + ": Interrupted while polling for messages").initCause(e); } } }
@Override public void run() { try { byte[] buf = new byte[1024]; while (isOpen()) { int result = Socket.recv(handle, buf, 0, buf.length); if (result < Status.APR_SUCCESS) { throwException(result); } messageReceived(new ByteArrayBuffer(buf, 0, result)); } } catch (Exception e) { if (isOpen()) { log.warn(e.getClass().getSimpleName() + " while still open: " + e.getMessage()); } else { if (log.isDebugEnabled()) { log.debug("Closed client loop exception", e); } } } finally { try { close(); } catch (IOException e) { if (log.isDebugEnabled()) { log.debug(e.getClass().getSimpleName() + " while closing: " + e.getMessage()); } } } }