public void testRVVExceptionB() { RVVExceptionB ex = new RVVExceptionB(5, 10); ex.add(8); ex.add(6); assertEquals(8, ex.getHighestReceivedVersion()); ex.add(5); assertEquals(8, ex.getHighestReceivedVersion()); }
/** * add a received version */ public void add(long receivedVersion) { // String me = this.toString(); // long oldv = this.nextVersion; if (receivedVersion == this.previousVersion+1) { this.previousVersion = receivedVersion; if (this.received != null) { addReceived(receivedVersion); consumeReceivedVersions(); } } else if (receivedVersion == this.nextVersion-1) { this.nextVersion = receivedVersion; if (this.received != null) { addReceived(receivedVersion); consumeReceivedVersions(); } } else if (this.previousVersion < receivedVersion && receivedVersion < this.nextVersion) { addReceived(receivedVersion); } // if (this.nextVersion == 29 && oldv != 29) { // System.out.println("before=" + me + "\nafter=" + this + "\nadded "+receivedVersion); // } }
@Override public long getHighestReceivedVersion() { if(isEmpty()) { return this.previousVersion; } else { //Note, the "length" of the bitset is the highest set bit + 1, //see the javadocs. That's why this works to return the highest //received version return receivedBaseVersion + received.length() - 1; } }
@Override public RVVException changeForm() { //Convert the exception to a bitset exception RVVExceptionB ex = new RVVExceptionB(previousVersion, nextVersion); for(ReceivedVersionsIterator it = this.receivedVersionsIterator(); it.hasNext(); ) { long next = it.next(); ex.add(next); } return ex; }
@Override public RVVExceptionB clone() { RVVExceptionB clone = new RVVExceptionB(previousVersion, nextVersion); if (this.received != null) { clone.received = (BitSet)this.received.clone(); clone.receivedBaseVersion = this.receivedBaseVersion; } return clone; }
protected boolean sameAs(RVVExceptionB ex) { if (!super.sameAs(ex)) { return false; } for (ReceivedVersionsIterator it = receivedVersionsIterator(); it.hasNext(); ) { if (!ex.contains(it.next())) { return false; } } for (ReceivedVersionsIterator it = ex.receivedVersionsIterator(); it.hasNext(); ) { if (!contains(it.next())) { return false; } } return true; }
public void toData(DataOutput out) throws IOException { InternalDataSerializer.writeUnsignedVL(this.previousVersion, out); writeReceived(out); }
protected void writeReceived(DataOutput out) throws IOException { int size = 0; long[] deltas = null; long last = this.previousVersion; //TODO - it would be better just to serialize the longs[] in the BitSet //as is, rather than go through this delta encoding. for(ReceivedVersionsIterator it = receivedVersionsIterator(); it.hasNext(); ) { Long version = it.next(); long delta = version.longValue() - last; if (deltas == null) { deltas = new long[this.received.length()]; } deltas[size++] = delta; last = version.longValue(); } InternalDataSerializer.writeUnsignedVL(size, out); for (int i=0; i<size; i++) { InternalDataSerializer.writeUnsignedVL(deltas[i], out); } //Write each version in the exception as a delta from the previous version //this will likely be smaller than the absolute value, so it will //be more likely to fit into a byte or a short. long delta = this.nextVersion - last; InternalDataSerializer.writeUnsignedVL(delta, out); }
@Override public RVVException changeForm() { //Convert the exception to a bitset exception RVVExceptionB ex = new RVVExceptionB(previousVersion, nextVersion); for(ReceivedVersionsIterator it = this.receivedVersionsIterator(); it.hasNext(); ) { long next = it.next(); ex.add(next); } return ex; }
@Override public RVVExceptionB clone() { RVVExceptionB clone = new RVVExceptionB(previousVersion, nextVersion); if (this.received != null) { clone.received = (BitSet)this.received.clone(); clone.receivedBaseVersion = this.receivedBaseVersion; } return clone; }
protected boolean sameAs(RVVExceptionB ex) { if (!super.sameAs(ex)) { return false; } for (ReceivedVersionsIterator it = receivedVersionsIterator(); it.hasNext(); ) { if (!ex.contains(it.next())) { return false; } } for (ReceivedVersionsIterator it = ex.receivedVersionsIterator(); it.hasNext(); ) { if (!contains(it.next())) { return false; } } return true; }
public void toData(DataOutput out) throws IOException { InternalDataSerializer.writeUnsignedVL(this.previousVersion, out); writeReceived(out); }
protected void writeReceived(DataOutput out) throws IOException { int size = 0; long[] deltas = null; long last = this.previousVersion; //TODO - it would be better just to serialize the longs[] in the BitSet //as is, rather than go through this delta encoding. for(ReceivedVersionsIterator it = receivedVersionsIterator(); it.hasNext(); ) { Long version = it.next(); long delta = version.longValue() - last; if (deltas == null) { deltas = new long[this.received.length()]; } deltas[size++] = delta; last = version.longValue(); } InternalDataSerializer.writeUnsignedVL(size, out); for (int i=0; i<size; i++) { InternalDataSerializer.writeUnsignedVL(deltas[i], out); } //Write each version in the exception as a delta from the previous version //this will likely be smaller than the absolute value, so it will //be more likely to fit into a byte or a short. long delta = this.nextVersion - last; InternalDataSerializer.writeUnsignedVL(delta, out); }
/** Use this method to create a new RVVException */ static RVVException createException(long previousVersion, long nextVersion, long initialExceptionCount) { // arbitrary cutoff of 100 bytes to use a treeSet instead of bitSet // But if we are deserializing an exception too many received versions use a // bitset anyway. long delta = nextVersion - previousVersion; if (UseTreeSetsForTesting || ( delta > RVV_MAX_BITSET_SPAN && initialExceptionCount * 512 < delta )) { return new RVVExceptionT(previousVersion, nextVersion); } return new RVVExceptionB(previousVersion, nextVersion); }
/** * add a received version */ public void add(long receivedVersion) { // String me = this.toString(); // long oldv = this.nextVersion; if (receivedVersion == this.previousVersion+1) { this.previousVersion = receivedVersion; if (this.received != null) { addReceived(receivedVersion); consumeReceivedVersions(); } } else if (receivedVersion == this.nextVersion-1) { this.nextVersion = receivedVersion; if (this.received != null) { addReceived(receivedVersion); consumeReceivedVersions(); } } else if (this.previousVersion < receivedVersion && receivedVersion < this.nextVersion) { addReceived(receivedVersion); } // if (this.nextVersion == 29 && oldv != 29) { // System.out.println("before=" + me + "\nafter=" + this + "\nadded "+receivedVersion); // } }
@Override public long getHighestReceivedVersion() { if(isEmpty()) { return this.previousVersion; } else { //Note, the "length" of the bitset is the highest set bit + 1, //see the javadocs. That's why this works to return the highest //received version return receivedBaseVersion + received.length() - 1; } }
/** Use this method to create a new RVVException */ static RVVException createException(long previousVersion, long nextVersion, long initialExceptionCount) { // arbitrary cutoff of 100 bytes to use a treeSet instead of bitSet // But if we are deserializing an exception too many received versions use a // bitset anyway. long delta = nextVersion - previousVersion; if (UseTreeSetsForTesting || ( delta > RVV_MAX_BITSET_SPAN && initialExceptionCount * 512 < delta )) { return new RVVExceptionT(previousVersion, nextVersion); } return new RVVExceptionB(previousVersion, nextVersion); }