Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor UnderStoreBlockInStream to use composition
- Loading branch information
Showing
9 changed files
with
187 additions
and
505 deletions.
There are no files selected for viewing
94 changes: 0 additions & 94 deletions
94
core/client/src/main/java/alluxio/client/block/DelegatedUnderStoreBlockInStream.java
This file was deleted.
Oops, something went wrong.
60 changes: 0 additions & 60 deletions
60
core/client/src/main/java/alluxio/client/block/DirectUnderStoreBlockInStream.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
core/client/src/main/java/alluxio/client/file/DelegatedUnderStoreStreamFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,55 @@ | |||
/* | |||
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | |||
* (the "License"). You may not use this work except in compliance with the License, which is | |||
* available at www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | |||
* either express or implied, as more fully set forth in the License. | |||
* | |||
* See the NOTICE file distributed with this work for information regarding copyright ownership. | |||
*/ | |||
|
|||
package alluxio.client.file; | |||
|
|||
import alluxio.AlluxioURI; | |||
import alluxio.client.block.UnderStoreBlockInStream.UnderStoreStreamFactory; | |||
import alluxio.client.file.options.CloseUfsFileOptions; | |||
import alluxio.client.file.options.OpenUfsFileOptions; | |||
import alluxio.exception.AlluxioException; | |||
|
|||
import java.io.IOException; | |||
import java.io.InputStream; | |||
|
|||
/** | |||
* | |||
*/ | |||
public class DelegatedUnderStoreStreamFactory implements UnderStoreStreamFactory { | |||
private final FileSystemWorkerClient mClient; | |||
private final long mFileId; | |||
|
|||
public DelegatedUnderStoreStreamFactory(FileSystemContext context, String path) throws IOException { | |||
mClient = FileSystemContext.INSTANCE.createWorkerClient(); | |||
try { | |||
mFileId = mClient.openUfsFile(new AlluxioURI(path), OpenUfsFileOptions.defaults()); | |||
} catch (AlluxioException | IOException e) { | |||
mClient.close(); | |||
throw new IOException(e); | |||
} | |||
} | |||
|
|||
@Override | |||
public InputStream create() { | |||
return new UnderFileSystemFileInStream(mClient.getWorkerDataServerAddress(), mFileId); | |||
} | |||
|
|||
@Override | |||
public void close() throws IOException { | |||
try { | |||
mClient.closeUfsFile(mFileId, CloseUfsFileOptions.defaults()); | |||
} catch (AlluxioException e) { | |||
throw new IOException(e); | |||
} finally { | |||
mClient.close(); | |||
} | |||
} | |||
} |
42 changes: 42 additions & 0 deletions
42
core/client/src/main/java/alluxio/client/file/DirectUnderStoreStreamFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,42 @@ | |||
/* | |||
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | |||
* (the "License"). You may not use this work except in compliance with the License, which is | |||
* available at www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | |||
* either express or implied, as more fully set forth in the License. | |||
* | |||
* See the NOTICE file distributed with this work for information regarding copyright ownership. | |||
*/ | |||
|
|||
package alluxio.client.file; | |||
|
|||
import alluxio.client.block.UnderStoreBlockInStream.UnderStoreStreamFactory; | |||
import alluxio.underfs.UnderFileSystem; | |||
|
|||
import java.io.IOException; | |||
import java.io.InputStream; | |||
|
|||
/** | |||
* | |||
*/ | |||
public class DirectUnderStoreStreamFactory implements UnderStoreStreamFactory { | |||
private final String mPath; | |||
|
|||
public DirectUnderStoreStreamFactory(String path) { | |||
mPath = path; | |||
} | |||
|
|||
@Override | |||
public InputStream create() throws IOException { | |||
return UnderFileSystem.get(mPath).open(mPath); | |||
} | |||
|
|||
/* (non-Javadoc) | |||
* @see alluxio.client.block.UnderStoreBlockInStream.UnderStoreStreamFactory#close() | |||
*/ | |||
@Override | |||
public void close() throws IOException { | |||
// Nothing needs to be closed. | |||
} | |||
} |
Oops, something went wrong.