Repository: incubator-distributedlog Updated Branches: refs/heads/master 26942a91a -> 3bd162027
http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LogRecordTooLongException.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LogRecordTooLongException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LogRecordTooLongException.java index 0521133..76a1aa2 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LogRecordTooLongException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/LogRecordTooLongException.java @@ -19,6 +19,11 @@ package com.twitter.distributedlog.exceptions; import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception is thrown when attempting to write a record whose size is too larger. + * + * <p>The size limit of a log record is {@link com.twitter.distributedlog.LogRecord#MAX_LOGRECORD_SIZE}. + */ public class LogRecordTooLongException extends DLException { private static final long serialVersionUID = 2788274084603111386L; http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/MetadataException.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/MetadataException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/MetadataException.java index 76ab573..cb62e7c 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/MetadataException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/MetadataException.java @@ -19,6 +19,9 @@ package com.twitter.distributedlog.exceptions; import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception is thrown when encountering metadata errors. + */ public class MetadataException extends DLException { private static final long serialVersionUID = 6683578078046016125L; http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/NotYetImplementedException.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/NotYetImplementedException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/NotYetImplementedException.java index 7c703e4..04edb01 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/NotYetImplementedException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/NotYetImplementedException.java @@ -19,6 +19,9 @@ package com.twitter.distributedlog.exceptions; import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception is thrown when a method is not implemented yet. + */ public class NotYetImplementedException extends DLException { private static final long serialVersionUID = -6002036746792556106L; http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/OverCapacityException.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/OverCapacityException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/OverCapacityException.java index ab46f64..d564758 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/OverCapacityException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/OverCapacityException.java @@ -19,6 +19,12 @@ package com.twitter.distributedlog.exceptions; import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception is thrown when the system is over capacity. + * + * <p>When this exception is received, the client (either writer or reader) should take actions to not + * overwhelm the system. For example, backoff sending any requests. + */ public class OverCapacityException extends DLException { private static final long serialVersionUID = -6398949404860680263L; http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/OwnershipAcquireFailedException.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/OwnershipAcquireFailedException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/OwnershipAcquireFailedException.java index 9bdef0e..7816333 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/OwnershipAcquireFailedException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/OwnershipAcquireFailedException.java @@ -19,6 +19,11 @@ package com.twitter.distributedlog.exceptions; import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception is thrown when a log writer attempt to acquire a lock. + * + * <p>It is typically thrown when the lock is already acquired by another writer. + */ public class OwnershipAcquireFailedException extends LockingException { private static final long serialVersionUID = 8176056926552748001L; private final String currentOwner; http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/ReadCancelledException.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/ReadCancelledException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/ReadCancelledException.java index 2876d3f..84d9271 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/ReadCancelledException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/ReadCancelledException.java @@ -19,6 +19,9 @@ package com.twitter.distributedlog.exceptions; import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Signals that a read request has been cancelled. + */ public class ReadCancelledException extends DLException { private static final long serialVersionUID = -6273430297547510262L; http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RegionUnavailableException.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RegionUnavailableException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RegionUnavailableException.java index 4158c97..440d86e 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RegionUnavailableException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RegionUnavailableException.java @@ -19,6 +19,11 @@ package com.twitter.distributedlog.exceptions; import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception indicates that the service is not available in one region. + * + * <p>The client should retry the other regions when encountering this exception. + */ public class RegionUnavailableException extends DLException { private static final long serialVersionUID = 5727337162533143957L; http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RequestDeniedException.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RequestDeniedException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RequestDeniedException.java index e4b61c4..0a1e1c5 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RequestDeniedException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RequestDeniedException.java @@ -19,6 +19,9 @@ package com.twitter.distributedlog.exceptions; import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Signals that a request has been denied at the server. + */ public class RequestDeniedException extends DLException { private static final long serialVersionUID = 7338220414584728216L; http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RetryableReadException.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RetryableReadException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RetryableReadException.java index d35988c..5224564 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RetryableReadException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/RetryableReadException.java @@ -19,6 +19,9 @@ package com.twitter.distributedlog.exceptions; import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Signals that a read request can be retried.. + */ public class RetryableReadException extends DLException { private static final long serialVersionUID = 2803207702150642330L; http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/ServiceUnavailableException.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/ServiceUnavailableException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/ServiceUnavailableException.java index 7851c0b..29e20d8 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/ServiceUnavailableException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/ServiceUnavailableException.java @@ -19,6 +19,9 @@ package com.twitter.distributedlog.exceptions; import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception indicates that the service is unavailable at the server side. + */ public class ServiceUnavailableException extends DLException { private static final long serialVersionUID = 6317900286881665746L; http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/StreamNotReadyException.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/StreamNotReadyException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/StreamNotReadyException.java index e44706a..6cac468 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/StreamNotReadyException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/StreamNotReadyException.java @@ -19,6 +19,9 @@ package com.twitter.distributedlog.exceptions; import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception is thrown when a log stream is not ready on server side for serving the write requests. + */ public class StreamNotReadyException extends DLException { private static final long serialVersionUID = 684211282036293028L; http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/StreamUnavailableException.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/StreamUnavailableException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/StreamUnavailableException.java index 1e23da0..9872fdc 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/StreamUnavailableException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/StreamUnavailableException.java @@ -19,6 +19,9 @@ package com.twitter.distributedlog.exceptions; import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception thrown when a stream is not available for serving traffic. + */ public class StreamUnavailableException extends DLException { private static final long serialVersionUID = 684211282036993028L; http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/TooManyStreamsException.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/TooManyStreamsException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/TooManyStreamsException.java index bbee4e4..6ee405d 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/TooManyStreamsException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/TooManyStreamsException.java @@ -19,6 +19,9 @@ package com.twitter.distributedlog.exceptions; import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Signals that a server has been serving too many streams. + */ public class TooManyStreamsException extends OverCapacityException { private static final long serialVersionUID = -6391941401860180163L; http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/TransactionIdOutOfOrderException.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/TransactionIdOutOfOrderException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/TransactionIdOutOfOrderException.java index 370b83e..915525c 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/TransactionIdOutOfOrderException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/TransactionIdOutOfOrderException.java @@ -19,6 +19,9 @@ package com.twitter.distributedlog.exceptions; import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * An exception is thrown when a log writer attempts to write a record with out-of-order transaction id. + */ public class TransactionIdOutOfOrderException extends DLException { private static final long serialVersionUID = -6239322552103630036L; http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/UnexpectedException.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/UnexpectedException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/UnexpectedException.java index ec26ad2..4454cd0 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/UnexpectedException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/UnexpectedException.java @@ -19,6 +19,9 @@ package com.twitter.distributedlog.exceptions; import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * An {@code UnexpectedException} is thrown when encountering unexpected conditions. + */ public class UnexpectedException extends DLException { private static final long serialVersionUID = 903763128422774055L; http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/UnsupportedMetadataVersionException.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/UnsupportedMetadataVersionException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/UnsupportedMetadataVersionException.java index 042c7db..47c361a 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/UnsupportedMetadataVersionException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/UnsupportedMetadataVersionException.java @@ -19,6 +19,9 @@ package com.twitter.distributedlog.exceptions; import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Exception is thrown when found unsupported metadata version. + */ public class UnsupportedMetadataVersionException extends DLException { private static final long serialVersionUID = 4980892659955478446L; http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/WriteCancelledException.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/WriteCancelledException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/WriteCancelledException.java index 33f11d4..f3adac2 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/WriteCancelledException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/WriteCancelledException.java @@ -19,14 +19,17 @@ package com.twitter.distributedlog.exceptions; import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * Signals when a write request is cancelled. + */ public class WriteCancelledException extends DLException { private static final long serialVersionUID = -1836146493496072122L; public WriteCancelledException(String stream, Throwable t) { super(StatusCode.WRITE_CANCELLED_EXCEPTION, - "Write cancelled on stream " + - stream + " due to an earlier error", t); + "Write cancelled on stream " + + stream + " due to an earlier error", t); } public WriteCancelledException(String stream, String reason) { @@ -36,7 +39,7 @@ public class WriteCancelledException extends DLException { public WriteCancelledException(String stream) { super(StatusCode.WRITE_CANCELLED_EXCEPTION, - "Write cancelled on stream " + - stream + " due to an earlier error"); + "Write cancelled on stream " + + stream + " due to an earlier error"); } } http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/WriteException.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/WriteException.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/WriteException.java index 64714d7..77c18d4 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/WriteException.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/WriteException.java @@ -19,13 +19,15 @@ package com.twitter.distributedlog.exceptions; import com.twitter.distributedlog.thrift.service.StatusCode; +/** + * An exception on writing log records. + */ public class WriteException extends DLException { private static final long serialVersionUID = -1836146493446072122L; public WriteException(String stream, String transmitError) { super(StatusCode.WRITE_EXCEPTION, - "Write rejected because stream " + stream + " has encountered an error : " + - transmitError); + "Write rejected because stream " + stream + " has encountered an error : " + transmitError); } } http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/package-info.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/package-info.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/package-info.java new file mode 100644 index 0000000..ad027d8 --- /dev/null +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/exceptions/package-info.java @@ -0,0 +1,21 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Defines exceptions used across distributedlog project. + */ +package com.twitter.distributedlog.exceptions; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/CompressionCodec.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/CompressionCodec.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/CompressionCodec.java index 2637f87..0f1753a 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/CompressionCodec.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/CompressionCodec.java @@ -20,14 +20,13 @@ package com.twitter.distributedlog.io; import org.apache.bookkeeper.stats.OpStatsLogger; /** - * Common interface for compression/decompression operations using different - * compression codecs. + * Common interface for compression/decompression operations using different compression codecs. */ public interface CompressionCodec { /** * Enum specifying the currently supported compression types. */ - public static enum Type { + enum Type { NONE, LZ4, UNKNOWN } http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/CompressionUtils.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/CompressionUtils.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/CompressionUtils.java index 3acef62..2552786 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/CompressionUtils.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/CompressionUtils.java @@ -17,13 +17,16 @@ */ package com.twitter.distributedlog.io; +/** + * Utils for compression related operations. + */ public class CompressionUtils { - public final static String LZ4 = "lz4"; - public final static String NONE = "none"; + public static final String LZ4 = "lz4"; + public static final String NONE = "none"; - private static CompressionCodec identityCodec = new IdentityCompressionCodec(); - private static CompressionCodec lz4Codec = new LZ4CompressionCodec(); + private static final CompressionCodec IDENTITY_CODEC = new IdentityCompressionCodec(); + private static final CompressionCodec LZ4_CODEC = new LZ4CompressionCodec(); /** * Get a cached compression codec instance for the specified type. @@ -32,10 +35,10 @@ public class CompressionUtils { */ public static CompressionCodec getCompressionCodec(CompressionCodec.Type type) { if (type == CompressionCodec.Type.LZ4) { - return lz4Codec; + return LZ4_CODEC; } // No Compression - return identityCodec; + return IDENTITY_CODEC; } /** http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/IdentityCompressionCodec.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/IdentityCompressionCodec.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/IdentityCompressionCodec.java index 4cc7762..39952c3 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/IdentityCompressionCodec.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/IdentityCompressionCodec.java @@ -17,23 +17,26 @@ */ package com.twitter.distributedlog.io; -import java.util.Arrays; - -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import java.util.Arrays; import org.apache.bookkeeper.stats.OpStatsLogger; +/** + * An identity compression codec implementation for {@link CompressionCodec}. + */ public class IdentityCompressionCodec implements CompressionCodec { @Override public byte[] compress(byte[] data, int offset, int length, OpStatsLogger compressionStat) { - Preconditions.checkNotNull(data); - Preconditions.checkArgument(length >= 0); + checkNotNull(data); + checkArgument(length >= 0); return Arrays.copyOfRange(data, offset, offset + length); } @Override public byte[] decompress(byte[] data, int offset, int length, OpStatsLogger decompressionStat) { - Preconditions.checkNotNull(data); + checkNotNull(data); return Arrays.copyOfRange(data, offset, offset + length); } http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/LZ4CompressionCodec.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/LZ4CompressionCodec.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/LZ4CompressionCodec.java index 2137452..12d6ac4 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/LZ4CompressionCodec.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/LZ4CompressionCodec.java @@ -17,21 +17,22 @@ */ package com.twitter.distributedlog.io; -import java.util.concurrent.TimeUnit; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; -import com.google.common.base.Preconditions; import com.google.common.base.Stopwatch; - +import java.util.concurrent.TimeUnit; import net.jpountz.lz4.LZ4Compressor; import net.jpountz.lz4.LZ4Exception; import net.jpountz.lz4.LZ4Factory; import net.jpountz.lz4.LZ4FastDecompressor; import net.jpountz.lz4.LZ4SafeDecompressor; - import org.apache.bookkeeper.stats.OpStatsLogger; /** - * All functions are thread safe. + * An {@code lz4} based {@link CompressionCodec} implementation. + * + * <p>All functions are thread safe. */ public class LZ4CompressionCodec implements CompressionCodec { @@ -50,10 +51,10 @@ public class LZ4CompressionCodec implements CompressionCodec { @Override public byte[] compress(byte[] data, int offset, int length, OpStatsLogger compressionStat) { - Preconditions.checkNotNull(data); - Preconditions.checkArgument(offset >= 0 && offset < data.length); - Preconditions.checkArgument(length >= 0); - Preconditions.checkNotNull(compressionStat); + checkNotNull(data); + checkArgument(offset >= 0 && offset < data.length); + checkArgument(length >= 0); + checkNotNull(compressionStat); Stopwatch watch = Stopwatch.createStarted(); byte[] compressed = compressor.compress(data, offset, length); @@ -63,10 +64,10 @@ public class LZ4CompressionCodec implements CompressionCodec { @Override public byte[] decompress(byte[] data, int offset, int length, OpStatsLogger decompressionStat) { - Preconditions.checkNotNull(data); - Preconditions.checkArgument(offset >= 0 && offset < data.length); - Preconditions.checkArgument(length >= 0); - Preconditions.checkNotNull(decompressionStat); + checkNotNull(data); + checkArgument(offset >= 0 && offset < data.length); + checkArgument(length >= 0); + checkNotNull(decompressionStat); Stopwatch watch = Stopwatch.createStarted(); // Assume that we have a compression ratio of 1/3. @@ -86,11 +87,11 @@ public class LZ4CompressionCodec implements CompressionCodec { // length parameter is ignored here because of the way the fastDecompressor works. public byte[] decompress(byte[] data, int offset, int length, int decompressedSize, OpStatsLogger decompressionStat) { - Preconditions.checkNotNull(data); - Preconditions.checkArgument(offset >= 0 && offset < data.length); - Preconditions.checkArgument(length >= 0); - Preconditions.checkArgument(decompressedSize >= 0); - Preconditions.checkNotNull(decompressionStat); + checkNotNull(data); + checkArgument(offset >= 0 && offset < data.length); + checkArgument(length >= 0); + checkArgument(decompressedSize >= 0); + checkNotNull(decompressionStat); Stopwatch watch = Stopwatch.createStarted(); byte[] decompressed = fastDecompressor.decompress(data, offset, decompressedSize); http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/package-info.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/package-info.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/package-info.java new file mode 100644 index 0000000..bbd9528 --- /dev/null +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/io/package-info.java @@ -0,0 +1,21 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * I/O related utilities used across the project. + */ +package com.twitter.distributedlog.io; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/package-info.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/package-info.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/package-info.java new file mode 100644 index 0000000..8fc526d --- /dev/null +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/package-info.java @@ -0,0 +1,21 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Provides the core data structures used across multiple modules. + */ +package com.twitter.distributedlog; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/BitMaskUtils.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/BitMaskUtils.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/BitMaskUtils.java index adee084..07d9d26 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/BitMaskUtils.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/BitMaskUtils.java @@ -17,15 +17,18 @@ */ package com.twitter.distributedlog.util; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; +/** + * Utils for bit mask operations. + */ public class BitMaskUtils { /** * 1) Unset all bits where value in mask is set. * 2) Set these bits to value specified by newValue. * - * e.g. + * <p>e.g. * if oldValue = 1010, mask = 0011, newValue = 0001 * 1) 1010 -> 1000 * 2) 1000 -> 1001 @@ -36,19 +39,19 @@ public class BitMaskUtils { * @return updated value */ public static long set(long oldValue, long mask, long newValue) { - Preconditions.checkArgument(oldValue >= 0L && mask >= 0L && newValue >= 0L); + checkArgument(oldValue >= 0L && mask >= 0L && newValue >= 0L); return ((oldValue & (~mask)) | (newValue & mask)); } /** - * Get the bits where mask is 1 + * Get the bits where mask is 1. * * @param value value * @param mask mask of the value * @return the bit of the mask */ public static long get(long value, long mask) { - Preconditions.checkArgument(value >= 0L && mask >= 0L); + checkArgument(value >= 0L && mask >= 0L); return (value & mask); } } http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/ProtocolUtils.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/ProtocolUtils.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/ProtocolUtils.java index 0b08471..bac5cdd 100644 --- a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/ProtocolUtils.java +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/ProtocolUtils.java @@ -17,11 +17,10 @@ */ package com.twitter.distributedlog.util; -import java.util.zip.CRC32; +import static com.google.common.base.Charsets.UTF_8; import com.twitter.distributedlog.DLSN; - -import static com.google.common.base.Charsets.UTF_8; +import java.util.zip.CRC32; /** * With CRC embedded in the application, we have to keep track of per api crc. Ideally this http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/package-info.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/package-info.java b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/package-info.java new file mode 100644 index 0000000..f95e666 --- /dev/null +++ b/distributedlog-protocol/src/main/java/com/twitter/distributedlog/util/package-info.java @@ -0,0 +1,21 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * defines the utilities used across the project. + */ +package com.twitter.distributedlog.util; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/test/java/com/twitter/distributedlog/TestDLSN.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/test/java/com/twitter/distributedlog/TestDLSN.java b/distributedlog-protocol/src/test/java/com/twitter/distributedlog/TestDLSN.java index 373994b..551d0ca 100644 --- a/distributedlog-protocol/src/test/java/com/twitter/distributedlog/TestDLSN.java +++ b/distributedlog-protocol/src/test/java/com/twitter/distributedlog/TestDLSN.java @@ -17,9 +17,14 @@ */ package com.twitter.distributedlog; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + import org.junit.Test; -import static org.junit.Assert.*; +/** + * Test Case for {@link DLSN}. + */ public class TestDLSN { @Test(timeout = 60000) http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/distributedlog-protocol/src/test/java/com/twitter/distributedlog/TestLogRecordSet.java ---------------------------------------------------------------------- diff --git a/distributedlog-protocol/src/test/java/com/twitter/distributedlog/TestLogRecordSet.java b/distributedlog-protocol/src/test/java/com/twitter/distributedlog/TestLogRecordSet.java index bc1e627..4a5fdac 100644 --- a/distributedlog-protocol/src/test/java/com/twitter/distributedlog/TestLogRecordSet.java +++ b/distributedlog-protocol/src/test/java/com/twitter/distributedlog/TestLogRecordSet.java @@ -17,6 +17,13 @@ */ package com.twitter.distributedlog; +import static com.google.common.base.Charsets.UTF_8; +import static com.twitter.distributedlog.LogRecord.MAX_LOGRECORD_SIZE; +import static com.twitter.distributedlog.LogRecordSet.HEADER_LEN; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + import com.google.common.collect.Lists; import com.twitter.distributedlog.LogRecordSet.Reader; import com.twitter.distributedlog.LogRecordSet.Writer; @@ -25,18 +32,12 @@ import com.twitter.distributedlog.io.CompressionCodec.Type; import com.twitter.util.Await; import com.twitter.util.Future; import com.twitter.util.Promise; -import org.junit.Test; - import java.nio.ByteBuffer; import java.util.List; - -import static com.google.common.base.Charsets.UTF_8; -import static com.twitter.distributedlog.LogRecord.*; -import static com.twitter.distributedlog.LogRecordSet.*; -import static org.junit.Assert.*; +import org.junit.Test; /** - * Test Case for {@link LogRecordSet} + * Test Case for {@link LogRecordSet}. */ public class TestLogRecordSet { http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/3bd16202/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 6cca9ce..a7f60b1 100644 --- a/pom.xml +++ b/pom.xml @@ -83,6 +83,7 @@ </developer> </developers> <modules> + <module>distributedlog-build-tools</module> <module>distributedlog-protocol</module> <module>distributedlog-core</module> <module>distributedlog-client</module>
