Skip to content
This repository was archived by the owner on Aug 18, 2019. It is now read-only.

Configuration (Spring)

David Fuelling edited this page Jul 7, 2016 · 3 revisions

Spring: Default Configuration

To utilize the ShardedCounterService with Spring, use the following glue code to provide a default configuration:

<bean id="shardedCounterService"
	class="ShardedCounterServiceImpl">
</bean>

Or, using JavaConfig:

@Config
public class AppengineCounterConfig {
    @Bean
    ShardedCounterService shardedCounterService(){
        return new ShardedCounterServiceImpl();
    }
}

Spring: Custom Configuration

If you want to control the configuration of the ShardedCounterService, you will need to configure an instance of ShardedCounterServiceConfiguration.Builder as follows:

<bean id="shardedCounterServiceConfigurationBuilder"
	class="ShardedCounterServiceConfiguration.Builder">

	<!-- The number of shards to create when a new counter is created -->
	<property name="numInitialShards">
		<value>3</value>
	</property>

	<!-- The default Memcache expiration for counter objects in seconds. -->
	<property name="defaultCounterCountExpiration">
		<value>300</value>
	</property>

	<!-- The name of the Queue for counter-deletion.  If this property is omitted, the default appengine queue is used -->
	<property name="deleteCounterShardQueueName">
		<value>deleteCounterShardQueue</value>
	</property>

	<!-- The URL callback path that appengine will use to process delete-counter message.  If this property is ommitted, the default appengine queue is used -->
	<property name="relativeUrlPathForDeleteTaskQueue">
		<value>/_ah/queue/deleteCounterShardQueue</value>
	</property>
</bean>

Next, use the builder defined above to populate a ShardedCounterServiceConfiguration:

<bean id="shardedCounterServiceConfiguration"
	class="ShardedCounterServiceConfiguration">

	<constructor-arg>
		<ref bean="shardedCounterServiceConfigurationBuilder" />
	</constructor-arg>

</bean>

Finally, use the configuration defined above to create a ShardedCounterService bean. Notice that you will also need to provide spring-bean configurations for the MemcacheService:

<bean id="memcacheService" 
	class="com.google.appengine.api.memcache.MemcacheServiceFactory"
	factory-method="getMemcacheService">
</bean>

<bean id="shardedCounterService"
	class="ShardedCounterService">

	<constructor-arg>
		<ref bean="memcacheService" />
	</constructor-arg>

	<constructor-arg>
		<ref bean="shardedCounterServiceConfiguration" />
	</constructor-arg>

</bean>

Or, using JavaConfig:

@Config
public class AppengineCounterConfig {
    
    @Bean
    MemcachService memcacheService(){
        return MemcacheServiceFactory.getMemcacheService();
    }

    @Bean
    ShardedCounterService shardedCounterService(final MemcacheService memcacheService) 
    {
        final ShardedCounterServiceConfiguration builder = new Builder()
        .withDeleteCounterShardQueueName("deleteCounterShardQueue")
        .withNumInitialShards(5)
        .withRelativeUrlPathForDeleteTaskQueue("/_ah/queue/deleteCounterShardQueue")
        .build();
        return new ShardedCounterServiceImpl(memcacheService, builder);
    }
}

Clone this wiki locally