/** * Adds elements from list to the table * @param list * @return True if at least 1 element was added successfully */ public boolean add(final List<LongTuple<T>> list) { return add(list, false); }
public SenderEntry(short send_conn_id) { super(send_conn_id, new Table<>(xmit_table_num_rows, xmit_table_msgs_per_row, 0, xmit_table_resize_factor, xmit_table_max_compaction_time)); }
boolean added=false; long highest_seqno=findHighestSeqno(list); lock.lock(); try { if(highest_seqno != -1 && computeRow(highest_seqno) >= matrix.length) resize(highest_seqno); long seqno=tuple.getVal1(); T element=const_value != null? const_value : tuple.getVal2(); if(_add(seqno, element, false, null)) added=true; else if(remove_added_elements)
/** * To be used only for testing; doesn't do any index or sanity checks * @param seqno * @return */ public T _get(long seqno) { lock.lock(); try { int row_index=computeRow(seqno); if(row_index < 0 || row_index >= matrix.length) return null; T[] row=matrix[row_index]; if(row == null) return null; int index=computeIndex(seqno); return index >= 0? row[index] : null; } finally { lock.unlock(); } }
return false; int row_index=computeRow(seqno); if(check_if_resize_needed && row_index >= matrix.length) { resize(seqno); row_index=computeRow(seqno); T[] row=getRow(row_index); int index=computeIndex(seqno); T existing_element=row[index]; if(existing_element == null) { hr=seqno; if(remove_filter != null && hd +1 == seqno) { forEach(hd + 1, hr, (seq, msg, r, c) -> { if(msg == null || !remove_filter.test(msg))
/** Moves rows down the matrix, by removing purged rows. If resizing to accommodate seqno is still needed, computes * a new size. Then either moves existing rows down, or copies them into a new array (if resizing took place). * The lock must be held by the caller of resize(). */ @SuppressWarnings("unchecked") @GuardedBy("lock") protected void resize(long seqno) { int num_rows_to_purge=computeRow(low); int row_index=computeRow(seqno) - num_rows_to_purge; if(row_index < 0) return; int new_size=Math.max(row_index +1, matrix.length); if(new_size > matrix.length) { T[][] new_matrix=(T[][])new Object[new_size][]; System.arraycopy(matrix, num_rows_to_purge, new_matrix, 0, matrix.length - num_rows_to_purge); matrix=new_matrix; num_resizes++; } else if(num_rows_to_purge > 0) { move(num_rows_to_purge); } offset+=(num_rows_to_purge * elements_per_row); }
int start_row=computeRow(low), end_row=computeRow(seqno); if(start_row < 0) start_row=0; if(end_row < 0) int index=computeIndex(seqno); for(int i=0; i <= index; i++) // null all elements up to and including seqno in the given row matrix[end_row][i]=null; if(seqno - hd > 0) low=hd=seqno; size=computeSize(); if(last_compaction_timestamp > 0) { if(current_time - last_compaction_timestamp >= max_compaction_time) { _compact(); last_compaction_timestamp=current_time;
protected void handleBatchReceived(final ReceiverEntry entry, Address sender, List<LongTuple<Message>> msgs, boolean oob) { if(is_trace) log.trace("%s <-- DATA(%s: %s)", local_addr, sender, printMessageList(msgs)); int batch_size=msgs.size(); Table<Message> win=entry.msgs; // adds all messages to the table, removing messages from 'msgs' which could not be added (already present) boolean added=win.add(msgs, oob, oob? DUMMY_OOB_MSG : null); update(entry, batch_size); if(batch_size >= ack_threshold) sendAck(sender, win.getHighestDeliverable(), entry.connId()); else entry.sendAck(true); // OOB msg is passed up. When removed, we discard it. Affects ordering: http://jira.jboss.com/jira/browse/JGRP-379 if(added && oob) { MessageBatch oob_batch=new MessageBatch(local_addr, sender, null, false, MessageBatch.Mode.OOB, msgs.size()); for(LongTuple<Message> tuple: msgs) oob_batch.add(tuple.getVal2()); deliverBatch(oob_batch); } removeAndDeliver(win, sender); }
boolean added=loopback || buf.add(msgs, oob, oob? DUMMY_OOB_MSG : null); for(LongTuple<Message> tuple: msgs) { long seq=tuple.getVal1(); Message msg=buf.get(seq); // we *have* to get the message, because loopback means we didn't add it to win ! if(msg != null && msg.isFlagSet(Message.Flag.OOB) && msg.setTransientFlagIfAbsent(Message.TransientFlag.OOB_DELIVERED)) oob_batch.add(msg);
msg.putHeader(this.id,UnicastHeader3.createDataHeader(seqno,send_conn_id,seqno == DEFAULT_FIRST_SEQNO)); entry.msgs.add(seqno, msg, dont_loopback_set? dont_loopback_filter : null); if(conn_expiry_timeout > 0) entry.update(); if(dont_loopback_set) entry.msgs.purge(entry.msgs.getHighestDeliverable()); break;
//Pixmap with one pixel Pixmap pm1 = new Pixmap(1, 1, Format.RGB565); pm1.setColor(Color.GREEN); pm1.fill(); Pixmap pm2 = new Pixmap(1, 1, Format.RGB565); pm2.setColor(Color.RED); pm2.fill(); dialogueWindow = getWindow(); dialogueWindow.setTitle("New Game"); // The table that will have the green color Table row1 = new Table(mySkin); row1.add(nameStation); row1.add(nameStationField); row1.setBackground(new TextureRegionDrawable(new TextureRegion(new Texture(pm1)))); dialogueWindow.add(row1); dialogueWindow.row(); // The table that will have the green color Table row2 = new Table(mySkin); row2.setBackground(new TextureRegionDrawable(new TextureRegion(new Texture(pm2)))); row2.add(cancel).size(120, 60); row2.add(ok).size(100, 60); dialogueWindow.add(row2).fillX(); dialogueWindow.row();
filler.setFillParent(true); filler.add(hGroup).fill().center();
/** * Adds an element if the element at the given index is null. Returns true if no element existed at the given index, * else returns false and doesn't set the element. * @param seqno * @param element * @return True if the element at the computed index was null, else false */ public boolean add(long seqno, T element) { lock.lock(); try { return _add(seqno, element, true, null); } finally { lock.unlock(); } }
@ManagedAttribute(description="Capacity of the retransmit buffer. Computed as xmit_table_num_rows * xmit_table_msgs_per_row") public long getXmitTableCapacity() { Table<Message> table=local_addr != null? xmit_table.get(local_addr) : null; return table != null? table.capacity() : 0; }
public void compact() { lock.lock(); try { _compact(); } finally { lock.unlock(); } }
@ManagedOperation(description="Compacts the retransmit buffer") public void compact() { Table<Message> table=local_addr != null? xmit_table.get(local_addr) : null; if(table != null) table.compact(); }
/** * Moves the contents of matrix down by the number of purged rows and resizes the matrix accordingly. The * capacity of the matrix should be size * resize_factor. Caller must hold the lock. */ @SuppressWarnings("unchecked") @GuardedBy("lock") protected void _compact() { // This is the range we need to copy into the new matrix (including from and to) int from=computeRow(low), to=computeRow(hr); int range=to - from +1; // e.g. from=3, to=5, new_size has to be [3 .. 5] (=3) int new_size=(int)Math.max( (double)range * resize_factor, (double) range +1 ); new_size=Math.max(new_size, num_rows); // don't fall below the initial size defined if(new_size < matrix.length) { T[][] new_matrix=(T[][])new Object[new_size][]; System.arraycopy(matrix, from, new_matrix, 0, range); matrix=new_matrix; offset+=from * elements_per_row; num_compactions++; } }
return false; int row_index=computeRow(seqno); if(check_if_resize_needed && row_index >= matrix.length) { resize(seqno); row_index=computeRow(seqno); T[] row=getRow(row_index); int index=computeIndex(seqno); T existing_element=row[index]; if(existing_element == null) { hr=seqno; if(remove_filter != null && hd +1 == seqno) { forEach(hd + 1, hr, (seq, msg, r, c) -> { if(msg == null || !remove_filter.test(msg))
/** * Returns an element at seqno * @param seqno * @return */ public T get(long seqno) { lock.lock(); try { if(seqno - low <= 0 || seqno - hr > 0) return null; int row_index=computeRow(seqno); if(row_index < 0 || row_index >= matrix.length) return null; T[] row=matrix[row_index]; if(row == null) return null; int index=computeIndex(seqno); return index >= 0? row[index] : null; } finally { lock.unlock(); } }