public String toString() { StringBuilder sb=new StringBuilder(); sb.append("dest=" + dest); if(sender != null) sb.append(", sender=").append(sender); sb.append(", mode=" + mode); if(cluster_name != null) sb.append(", cluster=").append(cluster_name); if(sb.length() > 0) sb.append(", "); sb.append(size() + " messages [capacity=" + messages.length + "]"); return sb.toString(); }
public void up(MessageBatch batch) { System.out.println("---------------- TRACE (received) ----------------------"); System.out.println("message batch (" + batch.size() + " messages"); System.out.println("--------------------------------------------------------"); up_prot.up(batch); }
public String printHeaders() { StringBuilder sb=new StringBuilder().append("dest=" + dest); if(sender != null) sb.append(", sender=").append(sender); sb.append("\n").append(size()).append(":\n"); int count=1; for(Message msg: this) sb.append("#").append(count++).append(": ").append(msg.printHeaders()).append("\n"); return sb.toString(); }
/** * Adds another batch to this one * @param batch the batch to add to this batch * @param resize when true, this batch will be resized to accommodate the other batch * @return the number of messages from the other batch that were added successfully. Will always be batch.size() * unless resize==0: in this case, the number of messages that were added successfully is returned */ public int add(final MessageBatch batch, boolean resize) { if(batch == null) return 0; if(this == batch) throw new IllegalArgumentException("cannot add batch to itself"); int batch_size=batch.size(); if(index+batch_size >= messages.length && resize) resize(messages.length + batch_size + 1); int cnt=0; for(Message msg: batch) { if(index >= messages.length) return cnt; messages[index++]=msg; cnt++; } return cnt; }
/** * Transfers messages from other to this batch. Optionally clears the other batch after the transfer * @param other the other batch * @param clear If true, the transferred messages are removed from the other batch * @return the number of transferred messages (may be 0 if the other batch was empty) */ public int transferFrom(MessageBatch other, boolean clear) { if(other == null || this == other) return 0; int capacity=messages.length, other_size=other.size(); if(other_size == 0) return 0; if(capacity < other_size) messages=new Message[other_size]; System.arraycopy(other.messages, 0, this.messages, 0, other_size); if(this.index > other_size) for(int i=other_size; i < this.index; i++) messages[i]=null; this.index=other_size; if(clear) other.clear(); return other_size; }
public Stream<Message> stream() { Spliterator<Message> sp=Spliterators.spliterator(iterator(), size(), 0); return StreamSupport.stream(sp, false); }
public String toString() { return String.format("batch size=%d queued msgs=%d queued batches=%d submitted msgs=%d submitted batches=%d", batch.size(), queued_msgs.sum(), queued_batches.sum(), submitted_msgs.sum(), submitted_batches.sum()); } }
protected void submit(MessageBatch mb) { try { submitted_batches.increment(); BatchHandlerLoop handler=new BatchHandlerLoop(batch_creator.apply(mb.size()).add(mb), this, false); if(!tp.submitToThreadPool(handler, false)) setRunning(false); } catch(Throwable t) { setRunning(false); } }
public void up(MessageBatch batch) { if(log.isTraceEnabled()) { long size=raw_buffer? batch.length() : batch.totalSize(); if(size >= min_size) { StringBuilder sb=new StringBuilder(local_addr + ".up(): size of message batch="); sb.append(Util.printBytes(size)).append(", " + batch.size() + " messages, " + numHeaders(batch) + " headers"); log.trace(sb); } } up_prot.up(batch); }
protected void deliverBatch(MessageBatch batch) { try { if(batch.isEmpty()) return; if(is_trace) { Message first=batch.first(), last=batch.last(); StringBuilder sb=new StringBuilder(local_addr + ": delivering"); if(first != null && last != null) { UnicastHeader3 hdr1=first.getHeader(id), hdr2=last.getHeader(id); sb.append(" #").append(hdr1.seqno).append(" - #").append(hdr2.seqno); } sb.append(" (" + batch.size()).append(" messages)"); log.trace(sb); } up_prot.up(batch); } catch(Throwable t) { log.warn(Util.getMessage("FailedToDeliverMsg"), local_addr, "batch", batch, t); } }
protected void deliverBatch(MessageBatch batch) { try { if(batch.isEmpty()) return; if(log.isTraceEnabled()) { Message first=batch.first(), last=batch.last(); StringBuilder sb=new StringBuilder(local_addr + ": delivering"); if(first != null && last != null) { SequencerHeader hdr1=first.getHeader(id), hdr2=last.getHeader(id); sb.append(" #").append(hdr1.seqno).append(" - #").append(hdr2.seqno); } sb.append(" (" + batch.size()).append(" messages)"); log.trace(sb); } up_prot.up(batch); } catch(Throwable t) { log.error(Util.getMessage("FailedToDeliverMsg"), local_addr, "batch", batch, t); } }
protected void deliverBatch(MessageBatch batch) { try { if(batch == null || batch.isEmpty()) return; if(is_trace) { Message first=batch.first(), last=batch.last(); StringBuilder sb=new StringBuilder(local_addr + ": delivering " + batch.sender()); if(first != null && last != null) { NakAckHeader2 hdr1=first.getHeader(id), hdr2=last.getHeader(id); sb.append("#").append(hdr1.seqno).append("-").append(hdr2.seqno); } sb.append(" (" + batch.size()).append(" messages)"); log.trace(sb); } up_prot.up(batch); } catch(Throwable t) { log.error(Util.getMessage("FailedToDeliverMsg"), local_addr, "batch", batch, t); } }
public void up(MessageBatch batch) { if(!up) { up_prot.up(batch); return; } if(batch.size() > 1) { shuffle(batch); if(!batch.isEmpty()) up_prot.up(batch); } else add(up_msgs, batch, up_lock, m -> up_prot.up(m)); }
int size=batch.size(); Map<Short,List<LongTuple<Message>>> msgs=new LinkedHashMap<>(); ReceiverEntry entry=recv_table.get(batch.sender());
/** Callback invoked by the protocol stack to deliver a message batch */ public JChannel up(MessageBatch batch) { if(stats) { received_msgs+=batch.size(); received_bytes+=batch.length(); } // discard local messages (sent by myself to me) if(discard_own_messages && local_addr != null && batch.sender() != null && local_addr.equals(batch.sender())) return this; if(up_handler != null) { try { up_handler.up(batch); } catch(Throwable t) { log.error(Util.getMessage("UpHandlerFailure"), t); } return this; } if(receiver != null) { try { receiver.receive(batch); } catch(Throwable t) { log.error(Util.getMessage("ReceiverFailure"), t); } } return this; }
protected void handleBatchFromSelf(MessageBatch batch, Entry entry) { List<LongTuple<Message>> list=new ArrayList<>(batch.size());
avg_delivery_batch_size.add(batch.size());
public void up(MessageBatch batch) { int size=batch.size(); boolean got_retransmitted_msg=false; // if at least 1 XMIT-RSP was received
public void passBatchUp(MessageBatch batch, boolean perform_cluster_name_matching, boolean discard_own_mcast) { if(is_trace) log.trace("%s: received message batch of %d messages from %s", local_addr, batch.size(), batch.sender()); if(up_prot == null) return; // Discard if message's cluster name is not the same as our cluster name if(perform_cluster_name_matching && cluster_name != null && !cluster_name.equals(batch.clusterName())) { if(log_discard_msgs && log.isWarnEnabled()) { Address sender=batch.sender(); if(suppress_log_different_cluster != null) suppress_log_different_cluster.log(SuppressLog.Level.warn, sender, suppress_time_different_cluster_warnings, batch.clusterName(),cluster_name, sender); else log.warn(Util.getMessage("BatchDroppedDiffCluster"), batch.clusterName(),cluster_name, sender); } return; } if(batch.multicast() && discard_own_mcast && local_addr != null && local_addr.equals(batch.sender())) return; up_prot.up(batch); }
public void run() { if(batch == null || (!batch.multicast() && tp.unicastDestMismatch(batch.dest()))) return; if(tp.statsEnabled()) { int batch_size=batch.size(); MsgStats msg_stats=tp.getMessageStats(); if(batch.getMode() == MessageBatch.Mode.OOB) msg_stats.incrNumOOBMsgsReceived(batch_size); else if(batch.getMode() == MessageBatch.Mode.INTERNAL) msg_stats.incrNumInternalMsgsReceived(batch_size); else msg_stats.incrNumMsgsReceived(batch_size); msg_stats.incrNumBatchesReceived(1); msg_stats.incrNumBytesReceived(batch.length()); tp.avgBatchSize().add(batch_size); } passBatchUp(); }