public static Buffer exceptionToBuffer(Throwable t) throws Exception { ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(512, true); exceptionToStream(t, out); return out.getBuffer(); }
public static Buffer streamableToBuffer(Streamable obj) { int expected_size=obj instanceof SizeStreamable? ((SizeStreamable)obj).serializedSize() +1 : 512; final ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(expected_size); try { Util.writeStreamable(obj,out); return out.getBuffer(); } catch(Exception ex) { return null; } }
protected static Buffer marshal(final Collection<? extends Address> participants, final Digest digest) { final ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(512); try { Util.writeAddresses(participants, out); Util.writeStreamable(digest,out); return out.getBuffer(); } catch(Exception ex) { return null; } }
protected static Buffer marshal(final ViewId view_id) { try { final ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(Util.size(view_id)); Util.writeViewId(view_id, out); return out.getBuffer(); } catch(Exception ex) { return null; } }
protected static Buffer marshal(Collection<? extends Address> mbrs) { try { final ByteArrayDataOutputStream out=new ByteArrayDataOutputStream((int)Util.size(mbrs)); Util.writeAddresses(mbrs, out); return out.getBuffer(); } catch(Exception ex) { return null; } }
protected static Buffer methodCallToBuffer(final MethodCall call, Marshaller marshaller) throws Exception { Object[] args=call.args(); int estimated_size=64; if(args != null) for(Object arg: args) estimated_size+=marshaller != null? marshaller.estimatedSize(arg) : (arg == null? 2 : 50); ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(estimated_size, true); call.writeTo(out, marshaller); return out.getBuffer(); }
protected static Buffer replyToBuffer(Object obj, Marshaller marshaller) throws Exception { int estimated_size=marshaller != null? marshaller.estimatedSize(obj) : 50; ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(estimated_size, true); if(marshaller != null) marshaller.objectToStream(obj, out); else Util.objectToStream(obj, out); return out.getBuffer(); }
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(); }
public static Buffer objectToBuffer(Object obj) throws Exception { if(obj == null) return new Buffer(TYPE_NULL_ARRAY); if(obj instanceof Streamable) { int expected_size=obj instanceof SizeStreamable? ((SizeStreamable)obj).serializedSize() : 512; final ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(expected_size, true); out.write(TYPE_STREAMABLE); writeGenericStreamable((Streamable)obj,out); return out.getBuffer(); } Byte type=PRIMITIVE_TYPES.get(obj.getClass()); if(type == null) { // will throw an exception if object is not serializable final ByteArrayDataOutputStream out_stream=new ByteArrayDataOutputStream(512, true); out_stream.write(TYPE_SERIALIZABLE); try(ObjectOutputStream out=new ObjectOutputStream(new OutputStreamAdapter(out_stream))) { out.writeObject(obj); out.flush(); return out_stream.getBuffer(); } } return new Buffer(marshalPrimitiveType(type, obj)); }
public static Buffer marshal(LazyRemovalCache<Address,IpAddress> addrs) { final ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(512); try { int size=addrs != null? addrs.size() : 0; out.writeInt(size); if(size > 0) { for(Map.Entry<Address,LazyRemovalCache.Entry<IpAddress>> entry: addrs.entrySet()) { Address key=entry.getKey(); IpAddress val=entry.getValue().getVal(); Util.writeAddress(key, out); Util.writeStreamable(val, out); } } return out.getBuffer(); } catch(Exception ex) { return null; } }
dos.writeByte(flags); msg.writeTo(dos); Buffer buffer=dos.getBuffer();
protected static Buffer marshal(final View view, final Digest digest) { try { int expected_size=Global.SHORT_SIZE; if(view != null) expected_size+=view.serializedSize(); boolean write_addrs=writeAddresses(view, digest); if(digest != null) expected_size=(int)digest.serializedSize(write_addrs); final ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(expected_size +10); out.writeShort(determineFlags(view, digest)); if(view != null) view.writeTo(out); if(digest != null) digest.writeTo(out, write_addrs); return out.getBuffer(); } catch(Exception ex) { 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); } }
protected static Buffer marshal(Collection<? extends Address> mbrs) { try { final ByteArrayDataOutputStream out=new ByteArrayDataOutputStream((int)Util.size(mbrs)); Util.writeAddresses(mbrs, out); return out.getBuffer(); } catch(Exception ex) { return null; } }
protected static Buffer marshal(final Collection<? extends Address> participants, final Digest digest) { final ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(512); try { Util.writeAddresses(participants, out); Util.writeStreamable(digest,out); return out.getBuffer(); } catch(Exception ex) { return null; } }
public static Buffer streamableToBuffer(Streamable obj) { int expected_size=obj instanceof SizeStreamable? ((SizeStreamable)obj).serializedSize() +1 : 512; final ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(expected_size); try { Util.writeStreamable(obj,out); return out.getBuffer(); } catch(Exception ex) { return null; } }
protected static Buffer marshal(final ViewId view_id) { try { final ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(Util.size(view_id)); Util.writeViewId(view_id, out); return out.getBuffer(); } catch(Exception ex) { return null; } }
protected static Buffer methodCallToBuffer(final MethodCall call, Marshaller marshaller) throws Exception { Object[] args=call.args(); int estimated_size=64; if(args != null) for(Object arg: args) estimated_size+=marshaller != null? marshaller.estimatedSize(arg) : (arg == null? 2 : 50); ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(estimated_size, true); call.writeTo(out, marshaller); return out.getBuffer(); }
protected static Buffer replyToBuffer(Object obj, Marshaller marshaller) throws Exception { int estimated_size=marshaller != null? marshaller.estimatedSize(obj) : 50; ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(estimated_size, true); if(marshaller != null) marshaller.objectToStream(obj, out); else Util.objectToStream(obj, out); return out.getBuffer(); }
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(); }