Skip to content

Commit

Permalink
Address minor style and documentation comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinjia committed Sep 7, 2015
1 parent 18e5b37 commit 79ef279
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 21 deletions.
Expand Up @@ -28,7 +28,7 @@ public abstract class InStream extends InputStream {
* Moves the starting read position of the stream to the specified position which is relative to * Moves the starting read position of the stream to the specified position which is relative to
* the start of the stream. Seeking to a position before the current read position is supported. * the start of the stream. Seeking to a position before the current read position is supported.
* *
* @param pos The position to seek to, it must be between 0 and the size of the block. * @param pos The position to seek to, it must be between 0 and the size of the block - 1.
* @throws IOException if the seek fails due to an error accessing the stream at the position * @throws IOException if the seek fails due to an error accessing the stream at the position
*/ */
public abstract void seek(long pos) throws IOException; public abstract void seek(long pos) throws IOException;
Expand Down
Expand Up @@ -20,15 +20,18 @@


/** /**
* Class representing a pool of resources to be temporarily used and returned. Inheriting classes * Class representing a pool of resources to be temporarily used and returned. Inheriting classes
* should implement the close method as well as initialize the resources in the constructor. * should implement the close method as well as initialize the resources in the constructor. The
* implemented methods are thread-safe and inheriting classes should also written in a
* thread-safe manner. See {@link tachyon.client.file.FSMasterClientPool} as an example.
* *
* @param <T> The type of resource this pool manages. * @param <T> The type of resource this pool manages.
*/ */
// TODO: This may fit better in the common module
public abstract class ResourcePool<T> { public abstract class ResourcePool<T> {
protected final Object mCapacityLock; protected final Object mCapacityLock;
protected int mCurrentCapacity;
protected final int mMaxCapacity; protected final int mMaxCapacity;
protected BlockingQueue<T> mResources; protected final BlockingQueue<T> mResources;
protected int mCurrentCapacity;


public ResourcePool(int maxCapacity) { public ResourcePool(int maxCapacity) {
mCapacityLock = new Object(); mCapacityLock = new Object();
Expand Down
Expand Up @@ -38,8 +38,8 @@ public final class TachyonFSTestUtils {
*/ */
public static TachyonFile createByteFile(TachyonFileSystem tfs, String fileName, public static TachyonFile createByteFile(TachyonFileSystem tfs, String fileName,
ClientOptions options, int len) throws IOException { ClientOptions options, int len) throws IOException {
return createByteFile(tfs, fileName, options.getTachyonStorageType(), options.getUnderStorageType(), return createByteFile(tfs, fileName, options.getTachyonStorageType(),
len, options.getBlockSize()); options.getUnderStorageType(), len, options.getBlockSize());
} }


/** /**
Expand Down
Expand Up @@ -30,7 +30,8 @@


/** /**
* This class provides a streaming API to read a block in Tachyon. The data will be directly read * This class provides a streaming API to read a block in Tachyon. The data will be directly read
* from the local machine's storage. * from the local machine's storage. The instances of this class should only be used by one
* thread and are not thread safe.
*/ */
public class LocalBlockInStream extends BlockInStream { public class LocalBlockInStream extends BlockInStream {
private final long mBlockId; private final long mBlockId;
Expand Down Expand Up @@ -86,7 +87,7 @@ public void close() throws IOException {


@Override @Override
public int read() throws IOException { public int read() throws IOException {
failIfClosed(); checkIfClosed();
if (mData.remaining() == 0) { if (mData.remaining() == 0) {
close(); close();
return -1; return -1;
Expand All @@ -96,13 +97,13 @@ public int read() throws IOException {


@Override @Override
public int read(byte[] b) throws IOException { public int read(byte[] b) throws IOException {
failIfClosed(); checkIfClosed();
return read(b, 0, b.length); return read(b, 0, b.length);
} }


@Override @Override
public int read(byte[] b, int off, int len) throws IOException { public int read(byte[] b, int off, int len) throws IOException {
failIfClosed(); checkIfClosed();
Preconditions.checkArgument(b != null, "Buffer is null"); Preconditions.checkArgument(b != null, "Buffer is null");
Preconditions.checkArgument(off >= 0 && len >= 0 && len + off <= b.length, String Preconditions.checkArgument(off >= 0 && len >= 0 && len + off <= b.length, String
.format("Buffer length (%d), offset(%d), len(%d)", b.length, off, len)); .format("Buffer length (%d), offset(%d), len(%d)", b.length, off, len));
Expand All @@ -124,8 +125,9 @@ public long remaining() {
return mData.remaining(); return mData.remaining();
} }


@Override
public void seek(long pos) throws IOException { public void seek(long pos) throws IOException {
failIfClosed(); checkIfClosed();
Preconditions.checkArgument(pos >= 0, "Seek position is negative: " + pos); Preconditions.checkArgument(pos >= 0, "Seek position is negative: " + pos);
Preconditions.checkArgument(pos <= mData.limit(), "Seek position is past buffer limit: " + pos Preconditions.checkArgument(pos <= mData.limit(), "Seek position is past buffer limit: " + pos
+ ", Buffer Size = " + mData.limit()); + ", Buffer Size = " + mData.limit());
Expand All @@ -134,7 +136,7 @@ public void seek(long pos) throws IOException {


@Override @Override
public long skip(long n) throws IOException { public long skip(long n) throws IOException {
failIfClosed(); checkIfClosed();
if (n <= 0) { if (n <= 0) {
return 0; return 0;
} }
Expand All @@ -147,9 +149,7 @@ public long skip(long n) throws IOException {
return ret; return ret;
} }


private void failIfClosed() throws IOException { private void checkIfClosed() throws IOException {
if (mClosed) { Preconditions.checkState(!mClosed, "Cannot do operations on a closed BlockInStream");
throw new IOException("Cannot do operations on a closed BlockInStream");
}
} }
} }
Expand Up @@ -32,8 +32,9 @@
import tachyon.worker.WorkerClient; import tachyon.worker.WorkerClient;


/** /**
* Provides a streaming API to write to a Tachyon block. This output stream will directly write * Provides a streaming API to write to a Tachyon block. This output stream will directly write the
* the input to a file in local Tachyon storage. * input to a file in local Tachyon storage. The instances of this class should only be used by one
* thread and are not thread safe.
*/ */
public class LocalBlockOutStream extends BufferedBlockOutStream { public class LocalBlockOutStream extends BufferedBlockOutStream {
private final Closer mCloser; private final Closer mCloser;
Expand Down
Expand Up @@ -28,7 +28,8 @@


/** /**
* This class provides a streaming API to read a block in Tachyon. The data will be transferred * This class provides a streaming API to read a block in Tachyon. The data will be transferred
* through a Tachyon worker's dataserver to the client. * through a Tachyon worker's dataserver to the client. The instances of this class should only be
* used by one thread and are not thread safe.
*/ */
public class RemoteBlockInStream extends BlockInStream { public class RemoteBlockInStream extends BlockInStream {
private final long mBlockId; private final long mBlockId;
Expand Down
Expand Up @@ -23,7 +23,8 @@


/** /**
* Provides a streaming API to write to a Tachyon block. This output stream will send the write * Provides a streaming API to write to a Tachyon block. This output stream will send the write
* through a Tachyon worker which will then write the block to a file in Tachyon storage. * through a Tachyon worker which will then write the block to a file in Tachyon storage. The
* instances of this class should only be used by one thread and are not thread safe.
*/ */
public final class RemoteBlockOutStream extends BufferedBlockOutStream { public final class RemoteBlockOutStream extends BufferedBlockOutStream {
private final RemoteBlockWriter mRemoteWriter; private final RemoteBlockWriter mRemoteWriter;
Expand Down
Expand Up @@ -52,7 +52,7 @@ public static synchronized TachyonBlockStore get() {
/** /**
* Creates a Tachyon block store. * Creates a Tachyon block store.
*/ */
public TachyonBlockStore() { private TachyonBlockStore() {
mContext = BSContext.INSTANCE; mContext = BSContext.INSTANCE;
} }


Expand Down

0 comments on commit 79ef279

Please sign in to comment.