/** * Sets the buffer<p/> * 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 ! */ public Message setBuffer(Buffer buf) { if(buf != null) { this.buf=buf.getBuf(); this.offset=buf.getOffset(); this.length=buf.getLength(); } return this; }
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(); } } }
output.write(buffer.getBuf(),buffer.getOffset(),buffer.getLength());
@Override protected void sendMcastDiscoveryRequest(Message msg) { try { if(msg.getSrc() == null) msg.setSrc(local_addr); ByteArrayDataOutputStream out=new ByteArrayDataOutputStream((int)(msg.size()+1)); msg.writeTo(out); Buffer buf=out.getBuffer(); DatagramPacket packet=new DatagramPacket(buf.getBuf(), buf.getOffset(), buf.getLength(), mcast_addr, mcast_port); if(mcast_send_sockets != null) { MulticastSocket s; for(int i=0; i < mcast_send_sockets.length; i++) { s=mcast_send_sockets[i]; try { s.send(packet); } catch(Exception e) { log.error(Util.getMessage("FailedSendingPacketOnSocket"), s); } } } else { // DEFAULT path if(mcast_sock != null) mcast_sock.send(packet); } } catch(Exception ex) { log.error(Util.getMessage("FailedSendingDiscoveryRequest"), ex); } }
/** * Sets the buffer<p/> * 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 ! */ public Message setBuffer(Buffer buf) { if(buf != null) { this.buf=buf.getBuf(); this.offset=buf.getOffset(); this.length=buf.getLength(); } return this; }
public byte[] objectToByteBuffer(Object obj) throws Exception { Buffer b = objectToBuffer(obj); byte[] bytes = new byte[b.getLength()]; System.arraycopy(b.getBuf(), b.getOffset(), bytes, 0, b.getLength()); return bytes; }
private void doSend(Buffer buf, Address dest, boolean multicast) throws Exception { if(stats) { num_msgs_sent++; num_bytes_sent+=buf.getLength(); } if(multicast) { sendToAllMembers(buf.getBuf(), buf.getOffset(), buf.getLength()); } else { sendToSingleMember(dest, buf.getBuf(), buf.getOffset(), buf.getLength()); } }
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(); } } }
private void sendXmitRsp(Address dest, LinkedList xmit_list, long first_seqno, long last_seqno) { Buffer buf; if(xmit_list == null || xmit_list.isEmpty()) { if(log.isErrorEnabled()) log.error("xmit_list is empty"); return; } if(use_mcast_xmit) dest=null; if(stats) { xmit_rsps_sent+=xmit_list.size(); updateStats(sent, dest, 0, 1, 0); } try { buf=Util.msgListToByteBuffer(xmit_list); Message msg=new Message(dest, null, buf.getBuf(), buf.getOffset(), buf.getLength()); // changed Bela Jan 4 2007: we should use OOB for retransmitted messages, otherwise we tax the OOB thread pool // too much // msg.setFlag(Message.OOB); msg.putHeader(name, new NakAckHeader(NakAckHeader.XMIT_RSP, first_seqno, last_seqno)); down_prot.down(new Event(Event.MSG, msg)); } catch(IOException ex) { log.error("failed marshalling xmit list", ex); } }
output.write(buffer.getBuf(),buffer.getOffset(),buffer.getLength());
packet=new DatagramPacket(buf.getBuf(), buf.getOffset(), buf.getLength(), mcast_addr, mcast_port); if(mcast_send_sockets != null) { MulticastSocket s;
@Override protected void sendMcastDiscoveryRequest(Message msg) { try { if(msg.getSrc() == null) msg.setSrc(local_addr); ByteArrayDataOutputStream out=new ByteArrayDataOutputStream((int)(msg.size()+1)); msg.writeTo(out); Buffer buf=out.getBuffer(); DatagramPacket packet=new DatagramPacket(buf.getBuf(), buf.getOffset(), buf.getLength(), mcast_addr, mcast_port); if(mcast_send_sockets != null) { MulticastSocket s; for(int i=0; i < mcast_send_sockets.length; i++) { s=mcast_send_sockets[i]; try { s.send(packet); } catch(Exception e) { log.error(Util.getMessage("FailedSendingPacketOnSocket"), s); } } } else { // DEFAULT path if(mcast_sock != null) mcast_sock.send(packet); } } catch(Exception ex) { log.error(Util.getMessage("FailedSendingDiscoveryRequest"), ex); } }