public Buffer getBuffer() {return new Buffer(buf, 0, pos);} public ByteBuffer getByteBuffer() {return ByteBuffer.wrap(buf, 0, pos);}
/** * <em> * Note that the byte[] buffer passed as argument must not be modified. Reason: if we retransmit the * message, it would still have a ref to the original byte[] buffer passed in as argument, and so we would * retransmit a changed byte[] buffer ! * </em> */ public final Message setBuffer(Buffer buf) { if(buf != null) { this.buf=buf.getBuf(); this.offset=buf.getOffset(); this.length=buf.getLength(); } return this; }
public void run() { Throwable t=null; while(canRun()) { Buffer data=null; try { data=send_queue.take(); if(data.hashCode() == termination.hashCode()) break; } catch(InterruptedException e) { t=e; break; } try { _send(data.getBuf(), 0, data.getLength(), false, send_queue.isEmpty()); } catch(Throwable ignored) { t=ignored; } } server.notifyConnectionClosed(TcpConnection.this, String.format("%s: %s", getClass().getSimpleName(), t != null? t.toString() : "normal stop")); } }
public void run() { Throwable t=null; while(canRun()) { Buffer data=null; try { data=send_queue.take(); if(data.hashCode() == termination.hashCode()) break; } catch(InterruptedException e) { t=e; break; } try { _send(data.getBuf(), 0, data.getLength(), false, send_queue.isEmpty()); } catch(Throwable ignored) { t=ignored; } } server.notifyConnectionClosed(TcpConnection.this, String.format("%s: %s", getClass().getSimpleName(), t != null? t.toString() : "normal stop")); } }
/** * <em> * Note that the byte[] buffer passed as argument must not be modified. Reason: if we retransmit the * message, it would still have a ref to the original byte[] buffer passed in as argument, and so we would * retransmit a changed byte[] buffer ! * </em> */ public final Message setBuffer(Buffer buf) { if(buf != null) { this.buf=buf.getBuf(); this.offset=buf.getOffset(); this.length=buf.getLength(); } return this; }
public Buffer getBuffer() {return new Buffer(buf, 0, pos);} public ByteBuffer getByteBuffer() {return ByteBuffer.wrap(buf, 0, pos);}
public void run() { Throwable t=null; while(canRun()) { Buffer data=null; try { data=send_queue.take(); if(data.hashCode() == termination.hashCode()) break; } catch(InterruptedException e) { t=e; break; } try { _send(data.getBuf(), 0, data.getLength(), false, send_queue.isEmpty()); } catch(Throwable ignored) { t=ignored; } } server.notifyConnectionClosed(TcpConnection.this, String.format("%s: %s", getClass().getSimpleName(), t != null? t.toString() : "normal stop")); } }
/** * <em> * Note that the byte[] buffer passed as argument must not be modified. Reason: if we retransmit the * message, it would still have a ref to the original byte[] buffer passed in as argument, and so we would * retransmit a changed byte[] buffer ! * </em> */ public final Message setBuffer(Buffer buf) { if(buf != null) { this.buf=buf.getBuf(); this.offset=buf.getOffset(); this.length=buf.getLength(); } return this; }
public Buffer getBuffer() {return new Buffer(buf, 0, pos);} public ByteBuffer getByteBuffer() {return ByteBuffer.wrap(buf, 0, pos);}
public void run() { for(int i=1; i <= number_of_msgs; i++) { try { Message msg=new Message(null, buf); if(oob) msg.setFlag(Message.Flag.OOB); if(dont_bundle) msg.setFlag(Message.Flag.DONT_BUNDLE); if(i > 0 && do_print > 0 && i % do_print == 0) System.out.println("-- sent " + i); Buffer buffer=writeMessage(msg); output_lock.lock(); // need to sync if we have more than 1 sender try { // msg.writeTo(output); output.writeInt(buffer.getLength()); output.write(buffer.getBuf(), buffer.getOffset(), buffer.getLength()); // output.flush(); } finally { output_lock.unlock(); } } catch(Exception e) { e.printStackTrace(); } } }
public Buffer copy() { byte[] new_buf=buf != null? new byte[length] : null; int new_length=new_buf != null? new_buf.length : 0; if(new_buf != null) System.arraycopy(buf, offset, new_buf, 0, length); return new Buffer(new_buf, 0, new_length); }
public void run() { for(int i=1; i <= number_of_msgs; i++) { try { Message msg=new Message(null, buf); if(oob) msg.setFlag(Message.Flag.OOB); if(dont_bundle) msg.setFlag(Message.Flag.DONT_BUNDLE); if(i > 0 && do_print > 0 && i % do_print == 0) System.out.println("-- sent " + i); Buffer buffer=writeMessage(msg); output_lock.lock(); // need to sync if we have more than 1 sender try { // msg.writeTo(output); output.writeInt(buffer.getLength()); output.write(buffer.getBuf(), buffer.getOffset(), buffer.getLength()); // output.flush(); } finally { output_lock.unlock(); } } catch(Exception e) { e.printStackTrace(); } } }
public Buffer copy() { byte[] new_buf=buf != null? new byte[length] : null; int new_length=new_buf != null? new_buf.length : 0; if(new_buf != null) System.arraycopy(buf, offset, new_buf, 0, length); return new Buffer(new_buf, 0, new_length); }
public void run() { for(int i=1; i <= number_of_msgs; i++) { try { Message msg=new Message(null, buf); if(oob) msg.setFlag(Message.Flag.OOB); if(dont_bundle) msg.setFlag(Message.Flag.DONT_BUNDLE); if(i > 0 && do_print > 0 && i % do_print == 0) System.out.println("-- sent " + i); Buffer buffer=writeMessage(msg); output_lock.lock(); // need to sync if we have more than 1 sender try { // msg.writeTo(output); output.writeInt(buffer.getLength()); output.write(buffer.getBuf(), buffer.getOffset(), buffer.getLength()); // output.flush(); } finally { output_lock.unlock(); } } catch(Exception e) { e.printStackTrace(); } } }
public Buffer copy() { byte[] new_buf=buf != null? new byte[length] : null; int new_length=new_buf != null? new_buf.length : 0; if(new_buf != null) System.arraycopy(buf, offset, new_buf, 0, length); return new Buffer(new_buf, 0, new_length); }
public Buffer getBufferAsBuffer() { return new Buffer(buf.array(), buf.arrayOffset(), buf.position()); }
public Buffer getBufferAsBuffer() { return new Buffer(buf.array(), buf.arrayOffset(), buf.position()); }