/** * This method needs to be synchronized on out_stream when it is called * @param msg * @throws java.io.IOException */ public static void writeMessage(Message msg, DataOutput dos, boolean multicast) throws Exception { byte flags=0; dos.writeShort(Version.version); // write the version if(multicast) flags+=MULTICAST; dos.writeByte(flags); msg.writeTo(dos); }
protected static final void writeMessage(final Message msg, DataOutputStream out) throws Exception { byte flags=0; if(msg.getDest() == null) flags+=(byte)2; out.writeShort(Version.version); // write the version out.writeByte(flags); msg.writeTo(out); }
public static Buffer messageToByteBuffer(Message msg) throws Exception { ByteArrayDataOutputStream out=new ByteArrayDataOutputStream((int)msg.size()+1); out.writeBoolean(msg != null); if(msg != null) msg.writeTo(out); return out.getBuffer(); }
msg.writeTo(dos); byte[] buffer=dos.buffer(); byte[][] fragments=Util.fragmentBuffer(buffer, frag_size, dos.position());
flags+=(byte)2; dos.writeByte(flags); msg.writeTo(dos); Buffer buffer=dos.getBuffer();
@Override protected void sendMcastDiscoveryRequest(Message msg) { try { if(msg.getSrc() == null) msg.setSrc(local_addr); ByteArrayDataOutputStream out=new ByteArrayDataOutputStream((int)msg.size()); msg.writeTo(out); for(int i=bind_port; i <= bind_port+port_range; i++) { DatagramPacket packet=new DatagramPacket(out.buffer(), 0, out.position(), dest_addr, i); sock.send(packet); } } catch(Exception ex) { log.error(Util.getMessage("FailedSendingDiscoveryRequest"), ex); } }
protected Buffer writeMessage(final Message msg) throws Exception { dos.position(0); byte flags=0; dos.writeShort(Version.version); // write the version if(msg.getDest() == null) flags+=(byte)2; dos.writeByte(flags); msg.writeTo(dos); return new Buffer(dos.buffer(), 0, dos.position()); } }
protected Object _down(Message msg) throws Exception { Address dest=msg.dest(); setSourceAddress(msg); // very important !! listToBuffer() will fail with a null src address !! int size=(int)msg.size(); ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(size + Global.INT_SIZE); out.writeInt(size); msg.writeTo(out); if(dest != null) // unicast sendTo(dest, out.buffer(), 0, out.position()); else { // multicast Collection<Address> dests=view != null? view.getMembers(): addr_table.keySet(); for(Address dst: dests) { try { sendTo(dst, out.buffer(), 0, out.position()); } catch(Throwable t) { log.error("failed sending multicast message to " + dst, t); } } } return null; }
@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); } }
/** * This method needs to be synchronized on out_stream when it is called * @param msg * @throws java.io.IOException */ public static void writeMessage(Message msg, DataOutput dos, boolean multicast) throws Exception { byte flags=0; dos.writeShort(Version.version); // write the version if(multicast) flags+=MULTICAST; dos.writeByte(flags); msg.writeTo(dos); }
protected static final void writeMessage(final Message msg, DataOutputStream out) throws Exception { byte flags=0; if(msg.getDest() == null) flags+=(byte)2; out.writeShort(Version.version); // write the version out.writeByte(flags); msg.writeTo(out); }
/** * This method needs to be synchronized on out_stream when it is called * @param msg * @return * @throws java.io.IOException */ private static void writeMessage(Message msg, DataOutputStream dos, boolean multicast) throws Exception { byte flags=0; dos.writeShort(Version.version); // write the version if(multicast) flags+=MULTICAST; if(msg.isFlagSet(Message.OOB)) flags+=OOB; dos.writeByte(flags); msg.writeTo(dos); }
int sizeOf(Message msg) { DataOutputStream out=null; synchronized(out_stream) { try { out_stream.reset(); out=new DataOutputStream(out_stream); msg.writeTo(out); out.flush(); return out_stream.size(); } catch(Exception e) { return 0; } finally { Util.close(out); } } }
private static void writeMessageList(List<Message> msgs, DataOutputStream dos, boolean multicast) throws Exception { Address src; byte flags=0; int len=msgs != null? msgs.size() : 0; boolean src_written=false; dos.writeShort(Version.version); flags+=LIST; if(multicast) flags+=MULTICAST; dos.writeByte(flags); dos.writeInt(len); if(msgs != null) { for(Message msg: msgs) { src=msg.getSrc(); if(!src_written) { Util.writeAddress(src, dos); src_written=true; } msg.writeTo(dos); } } }
/** * Marshalls a list of messages. * @param xmit_list LinkedList<Message> * @return Buffer * @throws IOException */ public static Buffer msgListToByteBuffer(LinkedList xmit_list) throws IOException { ExposedByteArrayOutputStream output=new ExposedByteArrayOutputStream(512); DataOutputStream out=new DataOutputStream(output); Message msg; Buffer retval=null; out.writeInt(xmit_list.size()); for(Iterator it=xmit_list.iterator(); it.hasNext();) { msg=(Message)it.next(); msg.writeTo(out); } out.flush(); retval=new Buffer(output.getRawBuffer(), 0, output.size()); out.close(); output.close(); return retval; }
public static Buffer messageToByteBuffer(Message msg) throws Exception { ByteArrayDataOutputStream out=new ByteArrayDataOutputStream((int)msg.size()+1); out.writeBoolean(msg != null); if(msg != null) msg.writeTo(out); return out.getBuffer(); }
@Override protected void sendMcastDiscoveryRequest(Message msg) { try { if(msg.getSrc() == null) msg.setSrc(local_addr); ByteArrayDataOutputStream out=new ByteArrayDataOutputStream((int)msg.size()); msg.writeTo(out); for(int i=bind_port; i <= bind_port+port_range; i++) { DatagramPacket packet=new DatagramPacket(out.buffer(), 0, out.position(), dest_addr, i); sock.send(packet); } } catch(Exception ex) { log.error(Util.getMessage("FailedSendingDiscoveryRequest"), ex); } }
protected Buffer writeMessage(final Message msg) throws Exception { dos.position(0); byte flags=0; dos.writeShort(Version.version); // write the version if(msg.getDest() == null) flags+=(byte)2; dos.writeByte(flags); msg.writeTo(dos); return new Buffer(dos.buffer(), 0, dos.position()); } }
protected Object _down(Message msg) throws Exception { Address dest=msg.dest(); setSourceAddress(msg); // very important !! listToBuffer() will fail with a null src address !! int size=(int)msg.size(); ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(size + Global.INT_SIZE); out.writeInt(size); msg.writeTo(out); if(dest != null) // unicast sendTo(dest, out.buffer(), 0, out.position()); else { // multicast Collection<Address> dests=view != null? view.getMembers(): addr_table.keySet(); for(Address dst: dests) { try { sendTo(dst, out.buffer(), 0, out.position()); } catch(Throwable t) { log.error("failed sending multicast message to " + dst, t); } } } return null; }
@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); } }