Skip to content

Commit

Permalink
Update BasicCheckpoint to use TachyonFileSystem.
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinjia committed Oct 19, 2015
1 parent 867eaed commit 29186f8
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions examples/src/main/java/tachyon/examples/BasicCheckpoint.java
Expand Up @@ -26,14 +26,13 @@


import tachyon.Constants; import tachyon.Constants;
import tachyon.TachyonURI; import tachyon.TachyonURI;
import tachyon.client.ReadType;
import tachyon.client.TachyonFS;
import tachyon.client.TachyonFile;
import tachyon.client.file.FileInStream; import tachyon.client.file.FileInStream;
import tachyon.client.file.TachyonFile;
import tachyon.client.file.TachyonFileSystem;
import tachyon.client.file.TachyonFileSystem.TachyonFileSystemFactory; import tachyon.client.file.TachyonFileSystem.TachyonFileSystemFactory;
import tachyon.client.file.options.OutStreamOptions; import tachyon.client.file.options.OutStreamOptions;
import tachyon.conf.TachyonConf;
import tachyon.exception.TachyonException; import tachyon.exception.TachyonException;
import tachyon.thrift.FileInfo;


/** /**
* An example to show to how use Tachyon's API * An example to show to how use Tachyon's API
Expand All @@ -53,19 +52,20 @@ public BasicCheckpoint(TachyonURI tachyonURI, String fileFolder, int numFiles) {


@Override @Override
public Boolean call() throws Exception { public Boolean call() throws Exception {
TachyonFS tachyonClient = TachyonFS.get(mLocation, new TachyonConf()); TachyonFileSystem tachyonClient = TachyonFileSystemFactory.get();
writeFile(tachyonClient); writeFile(tachyonClient);
return readFile(tachyonClient); return readFile(tachyonClient);
} }


private boolean readFile(TachyonFS tachyonClient) throws IOException { private boolean readFile(TachyonFileSystem tachyonClient) throws IOException, TachyonException {
boolean pass = true; boolean pass = true;
for (int i = 0; i < mNumFiles; i ++) { for (int i = 0; i < mNumFiles; i ++) {
TachyonURI filePath = new TachyonURI(mFileFolder + "/part-" + i); TachyonURI filePath = new TachyonURI(mFileFolder + "/part-" + i);
LOG.debug("Reading data from {}", filePath); LOG.debug("Reading data from {}", filePath);
TachyonFile file = tachyonClient.getFile(filePath); TachyonFile file = tachyonClient.open(filePath);
FileInStream is = file.getInStream(ReadType.CACHE); FileInStream is = tachyonClient.getInStream(file);
ByteBuffer buf = ByteBuffer.allocate((int) file.getBlockSizeByte()); FileInfo info = tachyonClient.getInfo(file);
ByteBuffer buf = ByteBuffer.allocate((int) info.getBlockSizeBytes());
is.read(buf.array()); is.read(buf.array());
buf.order(ByteOrder.nativeOrder()); buf.order(ByteOrder.nativeOrder());
for (int k = 0; k < mNumFiles; k ++) { for (int k = 0; k < mNumFiles; k ++) {
Expand All @@ -76,7 +76,7 @@ private boolean readFile(TachyonFS tachyonClient) throws IOException {
return pass; return pass;
} }


private void writeFile(TachyonFS tachyonClient) throws IOException, TachyonException { private void writeFile(TachyonFileSystem tachyonClient) throws IOException, TachyonException {
for (int i = 0; i < mNumFiles; i ++) { for (int i = 0; i < mNumFiles; i ++) {
ByteBuffer buf = ByteBuffer.allocate(80); ByteBuffer buf = ByteBuffer.allocate(80);
buf.order(ByteOrder.nativeOrder()); buf.order(ByteOrder.nativeOrder());
Expand All @@ -86,8 +86,7 @@ private void writeFile(TachyonFS tachyonClient) throws IOException, TachyonExcep
buf.flip(); buf.flip();
TachyonURI filePath = new TachyonURI(mFileFolder + "/part-" + i); TachyonURI filePath = new TachyonURI(mFileFolder + "/part-" + i);
LOG.debug("Writing data to {}", filePath); LOG.debug("Writing data to {}", filePath);
OutputStream os = OutputStream os = tachyonClient.getOutStream(filePath, OutStreamOptions.defaults());
TachyonFileSystemFactory.get().getOutStream(filePath, OutStreamOptions.defaults());
os.write(buf.array()); os.write(buf.array());
os.close(); os.close();
} }
Expand Down

0 comments on commit 29186f8

Please sign in to comment.