@Override public void closeConnection() { handler.writeTarget.closeConnection(); }
@Override public synchronized void writeBytes(byte[] message) throws IOException { handler.writeTarget.writeBytes(message); } }
@Override public void closeConnection() { handler.writeTarget.closeConnection(); }
@Override public synchronized void writeBytes(byte[] message) throws IOException { handler.writeTarget.writeBytes(message); } }
@Override public void closeConnection() { handler.writeTarget.closeConnection(); }
@Override public synchronized void writeBytes(byte[] message) throws IOException { handler.writeTarget.writeBytes(message); } }
@Override public void closeConnection() { handler.writeTarget.closeConnection(); }
@Override public synchronized void writeBytes(byte[] message) throws IOException { handler.writeTarget.writeBytes(message); } }
/** * Closes this connection, eventually triggering a {@link ProtobufConnection.Listener#connectionClosed()} event. */ public void closeConnection() { this.writeTarget.get().closeConnection(); }
/** * <p>Writes the given message to the other side of the connection, prefixing it with the proper 4-byte prefix.</p> * * <p>Provides a write-order guarantee.</p> * * @throws IllegalStateException If the encoded message is larger than the maximum message size. */ public void write(MessageType msg) throws IllegalStateException { byte[] messageBytes = msg.toByteArray(); checkState(messageBytes.length <= maxMessageSize); byte[] messageLength = new byte[4]; Utils.uint32ToByteArrayBE(messageBytes.length, messageLength, 0); try { MessageWriteTarget target = writeTarget.get(); target.writeBytes(messageLength); target.writeBytes(messageBytes); } catch (IOException e) { closeConnection(); } } }
/** * Closes this connection, eventually triggering a {@link ProtobufConnection.Listener#connectionClosed()} event. */ public void closeConnection() { this.writeTarget.get().closeConnection(); }
/** * <p>Writes the given message to the other side of the connection, prefixing it with the proper 4-byte prefix.</p> * * <p>Provides a write-order guarantee.</p> * * @throws IllegalStateException If the encoded message is larger than the maximum message size. */ public void write(MessageType msg) throws IllegalStateException { byte[] messageBytes = msg.toByteArray(); checkState(messageBytes.length <= maxMessageSize); byte[] messageLength = new byte[4]; Utils.uint32ToByteArrayBE(messageBytes.length, messageLength, 0); try { MessageWriteTarget target = writeTarget.get(); target.writeBytes(messageLength); target.writeBytes(messageBytes); } catch (IOException e) { closeConnection(); } } }
/** * Closes this connection, eventually triggering a {@link ProtobufConnection.Listener#connectionClosed()} event. */ public void closeConnection() { this.writeTarget.get().closeConnection(); }
/** * <p>Writes the given message to the other side of the connection, prefixing it with the proper 4-byte prefix.</p> * * <p>Provides a write-order guarantee.</p> * * @throws IllegalStateException If the encoded message is larger than the maximum message size. */ public void write(MessageType msg) throws IllegalStateException { byte[] messageBytes = msg.toByteArray(); checkState(messageBytes.length <= maxMessageSize); byte[] messageLength = new byte[4]; Utils.uint32ToByteArrayBE(messageBytes.length, messageLength, 0); try { MessageWriteTarget target = writeTarget.get(); target.writeBytes(messageLength); target.writeBytes(messageBytes); } catch (IOException e) { closeConnection(); } } }
/** * Closes this connection, eventually triggering a {@link ProtobufConnection.Listener#connectionClosed()} event. */ public void closeConnection() { this.writeTarget.get().closeConnection(); }
/** * <p>Writes the given message to the other side of the connection, prefixing it with the proper 4-byte prefix.</p> * * <p>Provides a write-order guarantee.</p> * * @throws IllegalStateException If the encoded message is larger than the maximum message size. */ public void write(MessageType msg) throws IllegalStateException { byte[] messageBytes = msg.toByteArray(); checkState(messageBytes.length <= maxMessageSize); byte[] messageLength = new byte[4]; Utils.uint32ToByteArrayBE(messageBytes.length, messageLength, 0); try { MessageWriteTarget target = writeTarget.get(); target.writeBytes(messageLength); target.writeBytes(messageBytes); } catch (IOException e) { closeConnection(); } } }
/** * Closes the connection to the peer if one exists, or immediately closes the connection as soon as it opens */ public void close() { lock.lock(); try { if (writeTarget == null) { closePending = true; return; } } finally { lock.unlock(); } writeTarget.closeConnection(); }
/** * Sends the given message to the peer. Due to the asynchronousness of network programming, there is no guarantee * the peer will have received it. Throws NotYetConnectedException if we are not yet connected to the remote peer. * TODO: Maybe use something other than the unchecked NotYetConnectedException here */ public void sendMessage(Message message) throws NotYetConnectedException { lock.lock(); try { if (writeTarget == null) throw new NotYetConnectedException(); } finally { lock.unlock(); } // TODO: Some round-tripping could be avoided here ByteArrayOutputStream out = new ByteArrayOutputStream(); try { serializer.serialize(message, out); writeTarget.writeBytes(out.toByteArray()); } catch (IOException e) { exceptionCaught(e); } }
/** * Closes the connection to the peer if one exists, or immediately closes the connection as soon as it opens */ public void close() { lock.lock(); try { if (writeTarget == null) { closePending = true; return; } } finally { lock.unlock(); } writeTarget.closeConnection(); }
/** * Sends the given message to the peer. Due to the asynchronousness of network programming, there is no guarantee * the peer will have received it. Throws NotYetConnectedException if we are not yet connected to the remote peer. * TODO: Maybe use something other than the unchecked NotYetConnectedException here */ public void sendMessage(Message message) throws NotYetConnectedException { lock.lock(); try { if (writeTarget == null) throw new NotYetConnectedException(); } finally { lock.unlock(); } // TODO: Some round-tripping could be avoided here ByteArrayOutputStream out = new ByteArrayOutputStream(); try { serializer.serialize(message, out); writeTarget.writeBytes(out.toByteArray()); } catch (IOException e) { exceptionCaught(e); } }