public Buffer getBuffer2() { if(buf == null) return null; return new Buffer(buf, offset, length); }
public Buffer getBuffer() {return new Buffer(buf, 0, pos);} public ByteBuffer getByteBuffer() {return ByteBuffer.wrap(buf, 0, pos);}
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()); }
private <R> Buffer createBuffer(Command<R, ? super C> command) { try { return new Buffer(this.marshaller.marshal(command)); } catch (IOException e) { throw new IllegalArgumentException(e); } }
protected <T> GroupRequest<T> cast(final Collection<Address> dests, byte[] data, int offset, int length, RequestOptions options, boolean block_for_results) throws Exception { return cast(dests, new Buffer(data, offset, length), options, block_for_results); }
/** * Sends a message to all members and expects responses from members in dests (if non-null). * @param dests A list of group members from which to expect responses (if the call is blocking). * @param data The buffer * @param offset the offset into data * @param length the number of bytes to send * @param opts A set of options that govern the call. See {@link org.jgroups.blocks.RequestOptions} for details * @return RspList A list of Rsp elements, or null if the RPC is asynchronous * @throws Exception If the request cannot be sent * @since 4.0 */ public <T> RspList<T> castMessage(Collection<Address> dests, byte[] data, int offset, int length, RequestOptions opts) throws Exception { return castMessage(dests, new Buffer(data, offset, length), opts); }
/** * Sends a unicast message to the target defined by msg.getDest() and returns a future * @param dest the target to which to send the unicast message. Must not be null. * @param data the payload to send * @param offset the offset at which the data starts * @param length the number of bytes to send * @param opts the options * @return CompletableFuture<T> A future from which the result can be fetched, or null if the call was asynchronous * @throws Exception If there was problem sending the request, processing it at the receiver, or processing * it at the sender. {@link java.util.concurrent.Future#get()} will throw this exception */ public <T> CompletableFuture<T> sendMessageWithFuture(Address dest, byte[] data, int offset, int length, RequestOptions opts) throws Exception { return sendMessageWithFuture(dest, new Buffer(data, offset, length), opts); }
/** * Sends a unicast message and - depending on the options - returns a result * @param dest the target to which to send the unicast message. Must not be null. * @param data the payload to send * @param offset the offset at which the data starts * @param length the number of bytes to send * @param opts the options to be used * @return T the result. Null if the call is asynchronous (non-blocking) or if the response is null * @throws Exception If there was problem sending the request, processing it at the receiver, or processing * it at the sender. * @throws TimeoutException If the call didn't succeed within the timeout defined in options (if set) */ public <T> T sendMessage(Address dest, byte[] data, int offset, int length, RequestOptions opts) throws Exception { return sendMessage(dest, new Buffer(data, offset, length), opts); }
void sendMessages(int num) throws Exception { long start, stop; int show=num/10; if(show <=0) show=1; start=System.currentTimeMillis(); RequestOptions opts=new RequestOptions(ResponseMode.GET_ALL, TIMEOUT).flags(Message.Flag.DONT_BUNDLE, Message.Flag.NO_FC); byte[] data="bla".getBytes(); Buffer buf=new Buffer(data, 0, data.length); System.out.println("-- sending " + num + " messages"); for(int i=1; i <= num; i++) { disp.castMessage(null, buf, opts); if(i % show == 0) System.out.println("-- sent " + i); } stop=System.currentTimeMillis(); printStats(stop-start, num); }
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)); }
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 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()); } }
public Buffer getBuffer2() { if(buf == null) return null; return new Buffer(buf, offset, length); }
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 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); }
private <R> Buffer createBuffer(Command<R, ? super C> command) { try { return new Buffer(this.marshaller.marshal(command)); } catch (IOException e) { throw new IllegalArgumentException(e); } }
@Override public Buffer objectToBuffer(Object obj) throws Exception { // wrap MethodCall in Object[service_name, byte[]] so that service name is available during demarshalling if (obj instanceof MethodCall) { String name = ((MethodCall) obj).getName(); int idx = name.lastIndexOf('.'); String serviceName = name.substring(0, idx); return new Buffer(CoreGroupCommunicationService.this.objectToByteBufferInternal(new Object[] { serviceName, CoreGroupCommunicationService.this.objectToByteBufferInternal(obj) })); } return new Buffer(CoreGroupCommunicationService.this.objectToByteBufferInternal(obj)); }
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 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()); } }