Refine search
public void flush() throws IOException { try { learner.writePacket(null, true); } catch(IOException e) { LOG.warn("Closing connection to leader, exception during packet send", e); try { if (!learner.sock.isClosed()) { learner.sock.close(); } } catch (IOException e1) { // Nothing to do, we are shutting things down, so an exception here is irrelevant LOG.debug("Ignoring error closing the connection", e1); } } }
Socket s = new Socket(); System.out.println("isConnected: " + s.isConnected() + " isBound: " + s.isBound() + " isClosed: " + s.isClosed()); s.connect(new InetSocketAddress("google.com", 80)); System.out.println("isConnected: " + s.isConnected() + " isBound: " + s.isBound() + " isClosed: " + s.isClosed()); s.close(); System.out.println("isConnected: " + s.isConnected() + " isBound: " + s.isBound() + " isClosed: " + s.isClosed());
public void flush() throws IOException { try { learner.writePacket(null, true); } catch(IOException e) { LOG.warn("Closing connection to leader, exception during packet send", e); try { if (!learner.sock.isClosed()) { learner.sock.close(); } } catch (IOException e1) { // Nothing to do, we are shutting things down, so an exception here is irrelevant LOG.debug("Ignoring error closing the connection", e1); } } }
private boolean closeSocket() { clearSelectionKey(); SocketChannel channel = this.channel; if (channel != null) { boolean isSocketClosed = true; Socket socket = channel.socket(); if (socket != null) { try { socket.close(); } catch (Throwable e) { } isSocketClosed = socket.isClosed(); } try { channel.close(); } catch (Throwable e) { } return isSocketClosed && (!channel.isOpen()); } else { return true; } }
public void shutdown() { // Send the packet of death try { queuedPackets.put(proposalOfDeath); } catch (InterruptedException e) { LOG.warn("Ignoring unexpected exception", e); } try { if (sock != null && !sock.isClosed()) { sock.close(); } } catch (IOException e) { LOG.warn("Ignoring unexpected exception during socket close", e); } this.interrupt(); learnerMaster.removeLearnerHandler(this); learnerMaster.unregisterLearnerHandlerBean(this); }
/** * 建立远程连接并发送命令 * * @param command * @param server * @param port */ private static void doSend(String command, String server, int port) { Socket socket = null; try { socket = new Socket(server, port); OutputStream os = socket.getOutputStream(); BufferedOutputStream out = new BufferedOutputStream(os); out.write(command.getBytes()); out.write('\r'); out.flush(); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (socket != null && !socket.isClosed()) { try { socket.close(); } catch (IOException e) { e.printStackTrace(); } } } }
public void shutdown() { // Send the packet of death try { queuedPackets.put(proposalOfDeath); } catch (InterruptedException e) { LOG.warn("Ignoring unexpected exception", e); } try { if (sock != null && !sock.isClosed()) { sock.close(); } } catch (IOException e) { LOG.warn("Ignoring unexpected exception during socket close", e); } this.interrupt(); leader.removeLearnerHandler(this); }
public void processRequest(Request si) { if(si.type != OpCode.sync){ QuorumPacket qp = new QuorumPacket(Leader.ACK, si.getHdr().getZxid(), null, null); try { learner.writePacket(qp, false); } catch (IOException e) { LOG.warn("Closing connection to leader, exception during packet send", e); try { if (!learner.sock.isClosed()) { learner.sock.close(); } } catch (IOException e1) { // Nothing to do, we are shutting things down, so an exception here is irrelevant LOG.debug("Ignoring error closing the connection", e1); } } } }
public static void closeQuietly(final Socket socket) { if (socket == null) { return; } try { try { // can't shudown input/output individually with secure sockets if ((socket instanceof SSLSocket) == false) { if (socket.isInputShutdown() == false) { socket.shutdownInput(); } if (socket.isOutputShutdown() == false) { socket.shutdownOutput(); } } } finally { if (socket.isClosed() == false) { socket.close(); } } } catch (final Exception ex) { logger.debug("Failed to close socket due to: " + ex, ex); } }
public void processRequest(Request si) { if(si.type != OpCode.sync){ QuorumPacket qp = new QuorumPacket(Leader.ACK, si.hdr.getZxid(), null, null); try { learner.writePacket(qp, false); } catch (IOException e) { LOG.warn("Closing connection to leader, exception during packet send", e); try { if (!learner.sock.isClosed()) { learner.sock.close(); } } catch (IOException e1) { // Nothing to do, we are shutting things down, so an exception here is irrelevant LOG.debug("Ignoring error closing the connection", e1); } } } }
@Override public void run() { try { DataInputStream input = new DataInputStream(socket.getInputStream()); DataOutputStream output = new DataOutputStream(socket.getOutputStream()); while (socket.isConnected() && !socket.isClosed()) { int size = input.readInt(); if (renegotiate.get()) { renegotiate.set(false); ((SSLSocket) socket).startHandshake(); } byte[] bytes = new byte[size]; input.readFully(bytes); output.writeInt(size); output.write(bytes); output.flush(); } } catch (IOException e) { // ignore } finally { try { socket.close(); } catch (IOException e) { // ignore } } } };