com.netflix.astyanax.recipes.queue.shard.ShardReaderPolicy Maven / Gradle / Ivy
/**
* Copyright 2013 Netflix, Inc.
*
* Licensed 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.
*/
package com.netflix.astyanax.recipes.queue.shard;
import java.util.Collection;
import java.util.Map;
import com.netflix.astyanax.recipes.queue.MessageQueueMetadata;
import com.netflix.astyanax.recipes.queue.MessageQueueShard;
import com.netflix.astyanax.recipes.queue.MessageQueueShardStats;
/**
* Policy for scheduling shards to be processed
*
* @author elandau
*
*/
public interface ShardReaderPolicy {
public static interface Factory {
public ShardReaderPolicy create(MessageQueueMetadata metadata);
}
/**
* Acquire the next shard to be processed. Must call releaseShard when done reading
* from the shard
* @return A reference to the acquired shard.
* @throws InterruptedException
*/
public MessageQueueShard nextShard() throws InterruptedException;
/**
* Release a shard after acquiring and reading messages
* @param shard
*/
public void releaseShard(MessageQueueShard shard, int messagesRead);
/**
* @return List all the shards
*/
public Collection listShards();
/**
* @return Return map of all shard stats
*/
public Map getShardStats();
/**
* @return number of shards in the work or active queue
*/
public int getWorkQueueDepth();
/**
* @return number of shards in the idle queue
*/
public int getIdleQueueDepth();
/**
* a ShardReaderPolicy is in catch up mode when more than two time buckets are in the work or active queue.
* @return is the shard reader catching up.
*/
public boolean isCatchingUp();
/**
* @return the correct polling interval. if in catch up mode returns the catchUpPollInterval otherwise
* returns the "normal" pollInterval
*/
public long getPollInterval();
}