Updated Branches: refs/heads/trunk 74f37b5a3 -> faf75d4d5
add ThrottledReader classes Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/faf75d4d Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/faf75d4d Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/faf75d4d Branch: refs/heads/trunk Commit: faf75d4d5b99a11bd9708e75972104f887c1a46c Parents: 74f37b5 Author: Jonathan Ellis <jbel...@apache.org> Authored: Tue Apr 30 16:01:14 2013 -0500 Committer: Jonathan Ellis <jbel...@apache.org> Committed: Tue Apr 30 16:01:14 2013 -0500 ---------------------------------------------------------------------- .../io/compress/CompressedThrottledReader.java | 59 +++++++++++++++ .../apache/cassandra/io/util/ThrottledReader.java | 56 ++++++++++++++ 2 files changed, 115 insertions(+), 0 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/faf75d4d/src/java/org/apache/cassandra/io/compress/CompressedThrottledReader.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/io/compress/CompressedThrottledReader.java b/src/java/org/apache/cassandra/io/compress/CompressedThrottledReader.java new file mode 100644 index 0000000..1f05953 --- /dev/null +++ b/src/java/org/apache/cassandra/io/compress/CompressedThrottledReader.java @@ -0,0 +1,59 @@ +package org.apache.cassandra.io.compress; +/* + * + * 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. + * + */ + + +import java.io.File; +import java.io.FileNotFoundException; + +import com.google.common.util.concurrent.RateLimiter; + +import org.apache.cassandra.io.util.PoolingSegmentedFile; +import org.apache.cassandra.io.util.RandomAccessReader; + +public class CompressedThrottledReader extends CompressedRandomAccessReader +{ + private final RateLimiter limiter; + + public CompressedThrottledReader(String file, CompressionMetadata metadata, RateLimiter limiter) throws FileNotFoundException + { + super(file, metadata, null); + this.limiter = limiter; + } + + protected void reBuffer() + { + limiter.acquire(buffer.length); + super.reBuffer(); + } + + public static CompressedThrottledReader open(String file, CompressionMetadata metadata, RateLimiter limiter) + { + try + { + return new CompressedThrottledReader(file, metadata, limiter); + } + catch (FileNotFoundException e) + { + throw new RuntimeException(e); + } + } +} http://git-wip-us.apache.org/repos/asf/cassandra/blob/faf75d4d/src/java/org/apache/cassandra/io/util/ThrottledReader.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/io/util/ThrottledReader.java b/src/java/org/apache/cassandra/io/util/ThrottledReader.java new file mode 100644 index 0000000..b12a8a8 --- /dev/null +++ b/src/java/org/apache/cassandra/io/util/ThrottledReader.java @@ -0,0 +1,56 @@ +package org.apache.cassandra.io.util; +/* + * + * 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. + * + */ + + +import java.io.File; +import java.io.FileNotFoundException; + +import com.google.common.util.concurrent.RateLimiter; + +public class ThrottledReader extends RandomAccessReader +{ + private final RateLimiter limiter; + + protected ThrottledReader(File file, RateLimiter limiter) throws FileNotFoundException + { + super(file, RandomAccessReader.DEFAULT_BUFFER_SIZE, null); + this.limiter = limiter; + } + + protected void reBuffer() + { + limiter.acquire(buffer.length); + super.reBuffer(); + } + + public static ThrottledReader open(File file, RateLimiter limiter) + { + try + { + return new ThrottledReader(file, limiter); + } + catch (FileNotFoundException e) + { + throw new RuntimeException(e); + } + } +}