/** * Constructor that uses the {@link IStorageDescriptor} to initiate the initial values. * * @param storageDescriptor * Storage descriptor that will be used to denote the range. */ public RangeDescriptor(IStorageDescriptor storageDescriptor) { start = storageDescriptor.getPosition(); end = (storageDescriptor.getPosition() + storageDescriptor.getSize()) - 1; }
long readPosition = storageDescriptor.getPosition(); long descriptorTotalSize = storageDescriptor.getSize(); long descriptorReadSize = 0;
if (null == storageDescriptor) { storageDescriptor = new StorageDescriptor(entry.getKey()); storageDescriptor.setPositionAndSize(descriptor.getPosition(), descriptor.getSize()); } else { if (!storageDescriptor.join(descriptor)) { optimizedDescriptors.add(storageDescriptor); storageDescriptor = new StorageDescriptor(entry.getKey()); storageDescriptor.setPositionAndSize(descriptor.getPosition(), descriptor.getSize());
/** * Joins the information from the other storage descriptor if possible. This method will return * true if the join was successfully done, and false if no join was done. The join is possible * only if the two descriptors are actually describing the data in the same channel that are * next to each other. There is no difference if the other descriptor is pointing to the data * after or before this descriptor. After successful join the joined data descriptor will be * represented by this descriptor. * * @param other * Descriptor information to join. * @return This method will return true if the join was successfully done, and false if no join * was done. */ public boolean join(IStorageDescriptor other) { if (this.getChannelId() != other.getChannelId()) { return false; } else { return join(other.getPosition(), other.getSize()); } }
rangeDescriptor = new RangeDescriptor(descriptor); } else { if ((rangeDescriptor.getEnd() + 1) == descriptor.getPosition()) { rangeDescriptor.setEnd((descriptor.getPosition() + descriptor.getSize()) - 1); } else { rangeHeader.append(rangeDescriptor.toString());
/** * {@inheritDoc} */ @Override public int compareTo(IStorageDescriptor other) { if ((this.getChannelId() - other.getChannelId()) != 0) { return this.getChannelId() - other.getChannelId(); } if ((this.getPosition() - other.getPosition()) != 0) { return (int) (this.getPosition() - other.getPosition()); } if ((this.getSize() - other.getSize()) != 0) { return (int) (this.getSize() - other.getSize()); } return 0; }
assertThat("Amount of descriptors is less than the amount of invocations saved.", descriptors.size(), is(equalTo(createdInvocations.size()))); for (IStorageDescriptor descriptor : descriptors) { assertThat("position of descriptor is negative.", descriptor.getPosition(), is(greaterThanOrEqualTo(0L))); assertThat("Size of the descriptor is wrong.", descriptor.getSize(), is(greaterThan(0L)));
assertThat("Amount of descriptors is less than the amount of invocations saved.", descriptors.size(), is(equalTo(createdInvocations.size()))); for (IStorageDescriptor descriptor : descriptors) { assertThat("position of descriptor is negative.", descriptor.getPosition(), is(greaterThanOrEqualTo(0L))); assertThat("Size of the descriptor is wrong.", descriptor.getSize(), is(greaterThan(0L)));
long descriptorSize = Math.min(random.nextInt(2048), readSize - totalInDescriptors); IStorageDescriptor storageDescriptor = mock(StorageDescriptor.class); when(storageDescriptor.getPosition()).thenReturn(totalInDescriptors); when(storageDescriptor.getSize()).thenReturn(descriptorSize); totalInDescriptors += descriptorSize;