Skip to content

Commit

Permalink
Use package implementation to remove dup code (#12)
Browse files Browse the repository at this point in the history
* Refactor code and use package dependent to reduce duplicate code.
  • Loading branch information
maobaolong committed Feb 2, 2021
1 parent a0f3760 commit 03d6a04
Show file tree
Hide file tree
Showing 19 changed files with 123 additions and 2,381 deletions.
2 changes: 1 addition & 1 deletion build/checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
<!-- Suppresses files in the src/main folder. To be used for rules which only apply to test
code. -->
<suppress files="[\\/]src[\\/]main[\\/].*|[\\/]generated-sources[\\/].*" id="TestScope" />
<suppress files="jnifuse[\\/].*\.java" checks="[a-zA-Z0-9]*"/>
<suppress files="alluxio[\\/].*\.java" checks="[a-zA-Z0-9]*"/>
</suppressions>
46 changes: 35 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

<properties>
<rootPOM>${basedir}/</rootPOM>
<multimodule.version>1.0.0-SNAPSHOT</multimodule.version>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
<maven.compiler.source>1.8</maven.compiler.source>
Expand All @@ -26,7 +24,7 @@
<maven-jar-plugin.version>2.5</maven-jar-plugin.version>
<log4j.version>2.5</log4j.version>

<alluxio.version>2.4.1</alluxio.version>
<alluxio.version>2.4.1-2</alluxio.version>
<hadoop.version>3.2.1</hadoop.version>
<ozone.version>1.0.0</ozone.version>
<!-- Test package version -->
Expand Down Expand Up @@ -98,6 +96,11 @@
<artifactId>hadoop-common</artifactId>
<version>${hadoop.version}</version>
</dependency>
<dependency>
<groupId>org.alluxio</groupId>
<artifactId>alluxio-integration-fuse</artifactId>
<version>${alluxio.version}</version>
</dependency>
<dependency>
<groupId>org.alluxio</groupId>
<artifactId>alluxio-core-base</artifactId>
Expand All @@ -114,6 +117,11 @@
<artifactId>alluxio-core-common</artifactId>
<version>${alluxio.version}</version>
</dependency>
<dependency>
<groupId>org.alluxio</groupId>
<artifactId>alluxio-core-client-fs</artifactId>
<version>${alluxio.version}</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-ozone-client</artifactId>
Expand All @@ -127,6 +135,10 @@
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.alluxio</groupId>
<artifactId>alluxio-integration-fuse</artifactId>
</dependency>
<dependency>
<groupId>org.alluxio</groupId>
<artifactId>alluxio-core-base</artifactId>
Expand Down Expand Up @@ -155,10 +167,6 @@
<artifactId>grpc-netty</artifactId>
<groupId>io.grpc</groupId>
</exclusion>
<exclusion>
<artifactId>grpc-protobuf</artifactId>
<groupId>io.grpc</groupId>
</exclusion>
<exclusion>
<artifactId>grpc-stub</artifactId>
<groupId>io.grpc</groupId>
Expand All @@ -185,10 +193,6 @@
<artifactId>grpc-core</artifactId>
<groupId>io.grpc</groupId>
</exclusion>
<exclusion>
<artifactId>grpc-netty</artifactId>
<groupId>io.grpc</groupId>
</exclusion>
<exclusion>
<artifactId>grpc-stub</artifactId>
<groupId>io.grpc</groupId>
Expand Down Expand Up @@ -225,6 +229,20 @@
<artifactId>log4j-slf4j-impl</artifactId>
<groupId>org.apache.logging.log4j</groupId>
</exclusion>
<exclusion>
<artifactId>commons-codec</artifactId>
<groupId>commons-codec</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.alluxio</groupId>
<artifactId>alluxio-core-client-fs</artifactId>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
Expand Down Expand Up @@ -254,6 +272,12 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<exclusions>
<exclusion>
<artifactId>animal-sniffer-annotations</artifactId>
<groupId>org.codehaus.mojo</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,56 @@
package hcfsfuse.fuse;
/*
* 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.fuse;

import com.google.common.base.Preconditions;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;

import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
* Convenience class to encapsulate input/output streams of open target files.
* <p>
* Convenience class to encapsulate input/output streams of open alluxio files.
*
* An open file can be either write-only or read-only, never both. This means that one of getIn or
* getOut will be null, while the other will be non-null. It is up to the user of this class
* (currently, only {@link HCFSFuseFileSystem}) to check that.
* <p>
* (currently, only {@link AlluxioFuseFileSystem}) to check that.
*
* This mechanism is preferred over more complex sub-classing to avoid useless casts or type checks
* for every read/write call, which happen quite often.
*/
@NotThreadSafe
final class OpenFileEntry implements Closeable {

public final class OpenFileEntry<T1 extends InputStream, T2 extends OutputStream>
implements Closeable {
private final long mId;
private final FSDataInputStream mIn;
private final FSDataOutputStream mOut;
private final T1 mIn;
private final T2 mOut;

// Path is likely to be changed when fuse rename() is called
private String mPath;
/**
* the next write offset.
*/
/** the next write offset. */
private long mOffset;

/**
* Constructs a new {@link OpenFileEntry} for an target file.
* Constructs a new {@link OpenFileEntry} for an Alluxio file.
*
* @param id the id of the file
* @param path the path of the file
* @param in the input stream of the file
* @param out the output stream of the file
*/
OpenFileEntry(long id, String path, FSDataInputStream in, FSDataOutputStream out) {
public OpenFileEntry(long id, String path, T1 in, T2 out) {
Preconditions.checkArgument(id != -1 && !path.isEmpty());
Preconditions.checkArgument(in != null || out != null);
mId = id;
Expand Down Expand Up @@ -69,21 +78,21 @@ public String getPath() {
* Gets the opened input stream for this open file entry. The value returned can be {@code null}
* if the file is not open for reading.
*
* @return an opened input stream for the open target file, or null
* @return an opened input stream for the open alluxio file, or null
*/
@Nullable
public FSDataInputStream getIn() {
public T1 getIn() {
return mIn;
}

/**
* Gets the opened output stream for this open file entry. The value returned can be {@code null}
* if the file is not open for writing.
*
* @return an opened input stream for the open target file, or null
* @return an opened input stream for the open alluxio file, or null
*/
@Nullable
public FSDataOutputStream getOut() {
public T2 getOut() {
return mOut;
}

Expand All @@ -95,7 +104,8 @@ public long getWriteOffset() {
}

/**
* Sets the path of the file. The file path can be changed if fuse rename() is called.
* Sets the path of the file. The file path can be changed
* if fuse rename() is called.
*
* @param path the new path of the file
*/
Expand Down
27 changes: 0 additions & 27 deletions src/main/java/alluxio/jnifuse/FuseFillDir.java

This file was deleted.

8 changes: 0 additions & 8 deletions src/main/java/alluxio/jnifuse/LibFuse.java

This file was deleted.

Loading

0 comments on commit 03d6a04

Please sign in to comment.