Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2014 UpSwell LLC (developers@theupswell.com) 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.theupswell.appengine.counter.data;
 
 import lombok.Getter;
 import lombok.Setter;
 
 
Represents a discrete shard belonging to a named counter.

An individual shard is written to infrequently to allow the counter in aggregate to be incremented rapidly.

Author(s):
David Fuelling
 
 @ToString(callSuper = true)
 public class CounterShardData extends AbstractEntity
 {
 	static final String COUNTER_SHARD_KEY_SEPARATOR = "-";
 
 	// The id of a CounterShardData is the name of the counter (for easy lookup
 	// via a starts-with query) combined with the shardNumber. E.g.,
 	// "CounterName-2" would be the counter with name "CounterName" and Shard
 	// number 2.
 
 	// The total of this shard's counter (not the total counter count)
 	private long count;

Default Constructor for Objectify

Deprecated:
Use the param-based constructors instead.
 
 	public CounterShardData()
 	{
 		// Implemented for Objectify
 	}

Param-based Constructor

Parameters:
counterName
shardNumber
 
 	public CounterShardData(final String counterNamefinal int shardNumber)
 	{
 		// Preconditions checked by #constructCounterShardIdentifier
 		setId(constructCounterShardIdentifier(counterNameshardNumber));
 	}

Param-based Constructor

Parameters:
counterShardDataKey
 
 	public CounterShardData(final Key<CounterShardDatacounterShardDataKey)
 	{
 		Preconditions.checkNotNull(counterShardDataKey);
 		setId(counterShardDataKey.getName());
 	}
 
 	// /////////////////////////
 	// Getters/Setters
 	// /////////////////////////
 

Returns:
The last dateTime that an increment occurred.
 
 	{
 		return getUpdatedDateTime();
	}

Set the amount of this shard with a new count.

Parameters:
count
	public void setCount(long count)
	{
		this. = count;
	}

Helper method to set the internal identifier for this entity.

Parameters:
counterName
shardNumber A unique identifier to distinguish shards for the same counterName from each other.
	static String constructCounterShardIdentifier(final String counterNamefinal int shardNumber)
	{
		Preconditions.checkNotNull(counterName);
		Preconditions.checkArgument(!StringUtils.isBlank(counterName),
			"CounterData Names may not be null, blank, or empty!");
		Preconditions.checkArgument(shardNumber >= 0, "shardNumber must be greater than or equal to 0!");
		return counterName +  + shardNumber;
	}

Create a Key<CounterShardData>. Keys for this entity are not "parented" so that they can be added under high volume load in a given application. Note that CounterData will be in a namespace specific.

Parameters:
counterName
shardNumber
Returns:
	public static Key<CounterShardDatakey(final String counterNamefinal int shardNumber)
	{
		// Preconditions checked by #constructCounterShardIdentifier
		return Key.create(CounterShardData.classconstructCounterShardIdentifier(counterNameshardNumber));
	}
New to GrepCode? Check out our FAQ X