public Buffer getBuffer2() { if(buf == null) return null; return new Buffer(buf, offset, length); }
/** * 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 Buffer getBuffer() {return new Buffer(buf, 0, pos);} public ByteBuffer getByteBuffer() {return ByteBuffer.wrap(buf, 0, pos);}
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(); } } }
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()); }
@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); } }
private <R> Buffer createBuffer(Command<R, ? super C> command) { try { return new Buffer(this.marshaller.marshal(command)); } catch (IOException e) { throw new IllegalArgumentException(e); } }
/** * 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; }
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); }
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()); } }
/** * 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); }
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(); } } }
/** * 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); }
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); } }
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); }