/** * 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; }
/** * Prepares the stream for read. Must be called before any read operation is executed. * * @throws IOException * if preparation fails due to inability to obtain defined number of byte buffers */ @Override public void prepare() throws IOException { super.prepare(); // set total size long totalSize = 0; for (IStorageDescriptor descriptor : descriptors) { totalSize += descriptor.getSize(); } setTotalSize(totalSize); executorService.execute(new ReadTask()); }
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()); } }
/** * {@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; }
} else { if ((rangeDescriptor.getEnd() + 1) == descriptor.getPosition()) { rangeDescriptor.setEnd((descriptor.getPosition() + descriptor.getSize()) - 1); } else { rangeHeader.append(rangeDescriptor.toString());
assertThat(results.size(), is(equalTo(entries - 1))); for (IStorageDescriptor storageDescriptor : results) { assertThat(storageDescriptor.getSize(), is(not(equalTo(removeId)))); assertThat(resultsForkJoin.size(), is(equalTo(entries - 1))); for (IStorageDescriptor storageDescriptor : resultsForkJoin) { assertThat(storageDescriptor.getSize(), is(not(equalTo(removeId))));
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)));
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)));
size += storageDescriptor.getSize(); limitedDescriptors.add(storageDescriptor);
IStorageDescriptor storageDescriptor = mock(StorageDescriptor.class); when(storageDescriptor.getPosition()).thenReturn(totalInDescriptors); when(storageDescriptor.getSize()).thenReturn(descriptorSize); totalInDescriptors += descriptorSize; descriptors.add(storageDescriptor);