/** Returns a header for a range of IDs, or null if not found */ public <T extends Header> T getHeader(short ... ids) { if(ids == null || ids.length == 0) return null; return Headers.getHeader(this.headers, ids); } /*---------------------------------------------------------------------*/
/** * Returns a reference to the headers hashmap, which is <em>immutable</em>. Any attempt to modify * the returned map will cause a runtime exception */ public Map<Short,Header> getHeaders() { return Headers.getHeaders(this.headers); }
public String printHeaders() { return Headers.printHeaders(this.headers); }
public int getNumHeaders() {return Headers.size(this.headers);} public int numHeaders() {return Headers.size(this.headers);}
/** Puts a header given an ID into the hashmap. Overwrites potential existing entry. */ public Message putHeader(short id, Header hdr) { if(id < 0) throw new IllegalArgumentException("An ID of " + id + " is invalid"); if(hdr != null) hdr.setProtId(id); synchronized(this) { Header[] resized_array=Headers.putHeader(this.headers, id, hdr, true); if(resized_array != null) this.headers=resized_array; } return this; }
public String printObjectHeaders() { return Headers.printObjectHeaders(this.headers); }
/** * Returns the exact size of the marshalled message. Uses method size() of each header to compute * the size, so if a Header subclass doesn't implement size() we will use an approximation. * However, most relevant header subclasses have size() implemented correctly. (See * org.jgroups.tests.SizeTest).<p/> * The return type is a long as this is the length of the payload ({@link #getLength()}) plus metadata (e.g. flags, * headers, source and dest addresses etc). Since the largest payload can be Integer.MAX_VALUE, adding the metadata * might lead to an int overflow, that's why we use a long. * @return The number of bytes for the marshalled message */ public long size() { long retval=(long)Global.BYTE_SIZE // leading byte + Global.SHORT_SIZE; // flags if(dest_addr != null) retval+=Util.size(dest_addr); if(src_addr != null) retval+=Util.size(src_addr); retval+=Global.SHORT_SIZE; // number of headers retval+=Headers.marshalledSize(this.headers); if(buf != null) retval+=Global.INT_SIZE // length (integer) + length; // number of bytes in the buffer return retval; }
/** * Create a copy of the message. If offset and length are used (to refer to another buffer), the * copy will contain only the subset offset and length point to, copying the subset into the new * copy.<p/> * Note that for headers, only the arrays holding references to the headers are copied, not the headers themselves ! * The consequence is that the headers array of the copy hold the *same* references as the original, so do *not* * modify the headers ! If you want to change a header, copy it and call {@link Message#putHeader(short,Header)} again. * * @param copy_buffer * @param copy_headers * Copy the headers * @return Message with specified data */ public Message copy(boolean copy_buffer, boolean copy_headers) { Message retval=new Message(false); retval.dest_addr=dest_addr; retval.src_addr=src_addr; short tmp_flags=this.flags; byte tmp_tflags=this.transient_flags; retval.flags=tmp_flags; retval.transient_flags=tmp_tflags; if(copy_buffer && buf != null) retval.setBuffer(buf, offset, length); //noinspection NonAtomicOperationOnVolatileField retval.headers=copy_headers && headers != null? Headers.copy(this.headers) : createHeaders(Util.DEFAULT_HEADERS); return retval; }
hdrs=resize(hdrs); resized=true;
public int numHeaders() {return Headers.size(this.headers);}
/** Puts a header given an ID into the hashmap. Overwrites potential existing entry. */ public Message putHeader(short id, Header hdr) { if(id < 0) throw new IllegalArgumentException("An ID of " + id + " is invalid"); if(hdr != null) hdr.setProtId(id); synchronized(this) { Header[] resized_array=Headers.putHeader(this.headers, id, hdr, true); if(resized_array != null) this.headers=resized_array; } return this; }
public String printObjectHeaders() { return Headers.printObjectHeaders(this.headers); }
/** * Returns the exact size of the marshalled message. Uses method size() of each header to compute * the size, so if a Header subclass doesn't implement size() we will use an approximation. * However, most relevant header subclasses have size() implemented correctly. (See * org.jgroups.tests.SizeTest).<p/> * The return type is a long as this is the length of the payload ({@link #getLength()}) plus metadata (e.g. flags, * headers, source and dest addresses etc). Since the largest payload can be Integer.MAX_VALUE, adding the metadata * might lead to an int overflow, that's why we use a long. * @return The number of bytes for the marshalled message */ public long size() { long retval=(long)Global.BYTE_SIZE // leading byte + Global.SHORT_SIZE; // flags if(dest_addr != null) retval+=Util.size(dest_addr); if(src_addr != null) retval+=Util.size(src_addr); retval+=Global.SHORT_SIZE; // number of headers retval+=Headers.marshalledSize(this.headers); if(buf != null) retval+=Global.INT_SIZE // length (integer) + length; // number of bytes in the buffer return retval; }
/** * Create a copy of the message. If offset and length are used (to refer to another buffer), the * copy will contain only the subset offset and length point to, copying the subset into the new * copy.<p/> * Note that for headers, only the arrays holding references to the headers are copied, not the headers themselves ! * The consequence is that the headers array of the copy hold the *same* references as the original, so do *not* * modify the headers ! If you want to change a header, copy it and call {@link Message#putHeader(short,Header)} again. * * @param copy_buffer * @param copy_headers * Copy the headers * @return Message with specified data */ public Message copy(boolean copy_buffer, boolean copy_headers) { Message retval=new Message(false); retval.dest_addr=dest_addr; retval.src_addr=src_addr; short tmp_flags=this.flags; byte tmp_tflags=this.transient_flags; retval.flags=tmp_flags; retval.transient_flags=tmp_tflags; if(copy_buffer && buf != null) retval.setBuffer(buf, offset, length); //noinspection NonAtomicOperationOnVolatileField retval.headers=copy_headers && headers != null? Headers.copy(this.headers) : createHeaders(Util.DEFAULT_HEADERS); return retval; }
hdrs=resize(hdrs); resized=true;
int size=Headers.size(hdrs, excluded_headers); out.writeShort(size); if(size > 0) {
public <T extends Header> T getHeader(short id) { if(id <= 0) throw new IllegalArgumentException("An ID of " + id + " is invalid. Add the protocol which calls " + "getHeader() to jg-protocol-ids.xml"); return Headers.getHeader(this.headers, id); }
/** * Returns a reference to the headers hashmap, which is <em>immutable</em>. Any attempt to modify * the returned map will cause a runtime exception */ public Map<Short,Header> getHeaders() { return Headers.getHeaders(this.headers); }
public String printHeaders() { return Headers.printHeaders(this.headers); }
int size=Headers.size(hdrs); out.writeShort(size); if(size > 0) {