@Override public void send(final Message msg) throws Exception { Runnable async_send=() -> { ByteArrayDataOutputStream out=new ByteArrayDataOutputStream((int)(msg.size() + 10)); sendSingleMessage(msg, out); }; thread_pool.execute(async_send); } }
public static Buffer exceptionToBuffer(Throwable t) throws Exception { ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(512, true); exceptionToStream(t, out); return out.getBuffer(); }
public void init(TP transport) { this.transport=transport; log=transport.getLog(); output=new ByteArrayDataOutputStream(transport.getMaxBundleSize() + MSG_OVERHEAD); } public void start() {}
public void send(Message msg) throws Exception { ByteArrayDataOutputStream out=new ByteArrayDataOutputStream((int)(msg.size() + 10)); sendSingleMessage(msg, out); }
public static byte[] collectionToByteBuffer(Collection<Address> c) throws Exception { final ByteArrayDataOutputStream out=new ByteArrayDataOutputStream((int)Util.size(c)); Util.writeAddresses(c,out); return Arrays.copyOf(out.buffer(), out.position()); }
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; } }
public static byte[] streamableToByteBuffer(Streamable obj) throws Exception { int expected_size=obj instanceof SizeStreamable? ((SizeStreamable)obj).serializedSize() : 512; final ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(expected_size); obj.writeTo(out); return Arrays.copyOf(out.buffer(), out.position()); }
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(); }
protected synchronized void writeRequest(GossipData req) throws Exception { int size=req.serializedSize(); ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(size+5); req.writeTo(out); client.send(remote, out.buffer(), 0, out.position()); }
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; } }
@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 void sendToMember(Address dest, GossipData request) { ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(request.serializedSize()); try { request.writeTo(out); server.send(dest, out.buffer(), 0, out.position()); } catch(Exception ex) { log.error("failed sending unicast message to %s: %s", dest, ex); } }
protected void getStateFrom(JChannel channel, Protocol prot, String stack, String ch, DataOutputStream out) throws Exception { ByteArrayDataOutputStream output=new ByteArrayDataOutputStream(1024); OutputStreamAdapter out_ad=new OutputStreamAdapter(output); Event evt=new Event(Event.STATE_TRANSFER_OUTPUTSTREAM, out_ad); if(channel != null) channel.up(evt); else prot.up(evt); int len=output.position(); if(len > 0) { Bits.writeString(stack, out); Bits.writeString(ch, out); out.writeInt(len); out.write(output.buffer(), 0, len); log.trace("%s: fetched %d bytes from %s:%s", local_addr, len, stack, ch); } }
protected static Buffer streamableToBuffer(byte req_or_rsp, byte type, Streamable obj) throws Exception { int expected_size=obj instanceof SizeStreamable? ((SizeStreamable)obj).serializedSize() : 100; ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(expected_size); out.writeByte(req_or_rsp); out.writeByte(type); obj.writeTo(out); return new Buffer(out.buffer(), 0, out.position()); }
protected void sendLocalAddress(Address local_addr) throws Exception { try { int addr_size=local_addr.serializedSize(); int expected_size=cookie.length + Global.SHORT_SIZE*2 + addr_size; ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(expected_size +2); out.write(cookie, 0, cookie.length); out.writeShort(Version.version); out.writeShort(addr_size); // address size local_addr.writeTo(out); ByteBuffer buf=out.getByteBuffer(); send(buf, false); updateLastAccessed(); } catch(Exception ex) { close(); throw ex; } }