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 named counter in the datastore and allows for shard-initialization and shard-association. Note that this entity does not have a count property since counts are stored in CounterShardData entities and aggregated by com.theupswell.appengine.counter.service.ShardedCounterService implementations.

Author(s):
David Fuelling
 
 @ToString(callSuper = true)
 public class CounterData extends AbstractEntity
 {
 
 	// Used by the Get methods to indicate the state of a CounterData while it
 	// is deleting.
 	public static enum CounterStatus
 	{
 		// This Counter is available to be incremented, decremented, or deleted.
 		AVAILABLE,
 		// This Counter is not available to be incremented or decremented, though its details can be updated.
 		READ_ONLY_COUNT,
 		// This Counter is expanding the number of shards it holds internally, and may not be incremented, decremented,
 		// or deleted, or mutated.
 		EXPANDING_SHARDS,
 		// This Counter is contracting the number of shards it holds internally, and may not be incremented,
 		// decremented, or deleted, or mutated.
 		CONTRACTING_SHARDS,
 		// This Counter is in the process of being deleted, and may not be incremented or decremented and its details
 		// may not be changed.
 		DELETING
 	}
 
 	// ////////////////
 	// @Id -- The counterName is the @Id of this entity, found in AbstractEntity
 	// ////////////////
 
 	// This is necessary to know in order to be able to evenly distribute amongst all shards for a given counterName
 	private int numShards = 1;
 
 
 	// This is AVAILABLE by default, which means it can be incremented and
 	// decremented
Default Constructor for Objectify

Deprecated:
Use the param-based constructors instead.
 
 	public CounterData()
 	{
 		// Implement for Objectify
 		this.setNumShards(1);
 	}

The param-based constructor

Parameters:
counterName The name of this CounterData. May not be null, blank, or empty.
numShards The number of shards this counter will contain.
 
 	public CounterData(final String counterNamefinal int numShards)
 	{
 		super(counterName);
		Preconditions.checkArgument(!StringUtils.isBlank(counterName),
			"CounterData Names may not be null, blank, or empty!");
		Preconditions.checkArgument(numShards > 0);
		this.setNumShards(numShards);
	}
	// //////////////////////////////
	// Getters/Setters
	// //////////////////////////////

Returns:
The name of this counter
	{
		return this.getId();
	}
	public void setNumShards(final int numShards)
	{
		Preconditions.checkArgument(numShards > 0, "A Counter must have at least 1 CounterShard!");
		this. = numShards;
	}

Create a Key<CounterData>. 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 The name of the Counter to create a Key for.
Returns:
A com.googlecode.objectify.Key
	public static Key<CounterDatakey(final String counterName)
	{
		Preconditions.checkNotNull(counterName);
		Preconditions.checkArgument(!StringUtils.isBlank(counterName),
			"CounterData Names may not be null, blank, or empty!");
		return Key.create(CounterData.classcounterName);
	}
New to GrepCode? Check out our FAQ X