SGF-511 - Add ability to enable additional CacheServers using annotation config.

This commit is contained in:
John Blum
2016-08-15 11:30:06 -07:00
parent a161d72749
commit 20301c1e4e
12 changed files with 363 additions and 25 deletions

View File

@@ -0,0 +1,90 @@
/*
* Copyright 2012 the original author or authors.
*
* 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 org.springframework.data.gemfire.config.annotation;
import java.util.Map;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.data.gemfire.config.GemfireConstants;
import org.springframework.data.gemfire.server.CacheServerFactoryBean;
/**
* The AddCacheServerConfiguration class is a Spring {@link ImportBeanDefinitionRegistrar} that registers
* a {@link CacheServerFactoryBean} definition for the {@link com.gemstone.gemfire.cache.server.CacheServer}
* configuration meta-data.
*
* @author John Blum
* @see org.springframework.context.annotation.ImportBeanDefinitionRegistrar
* @see org.springframework.data.gemfire.config.annotation.EnableCacheServer
* @since 1.9.0
*/
public class AddCacheServerConfiguration implements ImportBeanDefinitionRegistrar {
/*
* (non-Javadoc)
* @see org.springframework.context.annotation.ImportBeanDefinitionRegistrar#registerBeanDefinitions(AnnotationMetadata, BeanDefinitionRegistry)
*/
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
if (importingClassMetadata.hasAnnotation(EnableCacheServer.class.getName())) {
Map<String, Object> enableCacheServerAttributes = importingClassMetadata.getAnnotationAttributes(
EnableCacheServer.class.getName());
addCacheServerFactoryBeanDefinition(enableCacheServerAttributes, registry);
}
}
/**
* Registers a {@link CacheServerFactoryBean} bean definition for the given {@link EnableCacheServer} annotation
* configuration meta-data.
*
* @param annotationAttributes attributes for the {@link EnableCacheServer} annotation.
* @param registry {@link BeanDefinitionRegistry} used to register the {@link CacheServerFactoryBean}
* bean definition.
* @see org.springframework.beans.factory.support.BeanDefinitionBuilder
* @see org.springframework.beans.factory.support.BeanDefinitionRegistry
* @see org.springframework.data.gemfire.server.CacheServerFactoryBean
*/
protected void addCacheServerFactoryBeanDefinition(Map<String, Object> annotationAttributes,
BeanDefinitionRegistry registry) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CacheServerFactoryBean.class);
builder.addPropertyReference("cache", GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME);
builder.addPropertyValue("autoStartup", annotationAttributes.get("autoStartup"));
builder.addPropertyValue("bindAddress", annotationAttributes.get("bindAddress"));
builder.addPropertyValue("hostNameForClients", annotationAttributes.get("hostnameForClients"));
builder.addPropertyValue("loadPollInterval", annotationAttributes.get("loadPollInterval"));
builder.addPropertyValue("maxConnections", annotationAttributes.get("maxConnections"));
builder.addPropertyValue("maxMessageCount", annotationAttributes.get("maxMessageCount"));
builder.addPropertyValue("maxThreads", annotationAttributes.get("maxThreads"));
builder.addPropertyValue("maxTimeBetweenPings", annotationAttributes.get("maxTimeBetweenPings"));
builder.addPropertyValue("messageTimeToLive", annotationAttributes.get("messageTimeToLive"));
builder.addPropertyValue("port", annotationAttributes.get("port"));
builder.addPropertyValue("socketBufferSize", annotationAttributes.get("socketBufferSize"));
builder.addPropertyValue("subscriptionCapacity", annotationAttributes.get("subscriptionCapacity"));
builder.addPropertyValue("subscriptionDiskStore", annotationAttributes.get("subscriptionDiskStoreName"));
builder.addPropertyValue("subscriptionEvictionPolicy", annotationAttributes.get("subscriptionEvictionPolicy"));
BeanDefinitionReaderUtils.registerWithGeneratedName(builder.getBeanDefinition(), registry);
}
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright 2012 the original author or authors.
*
* 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 org.springframework.data.gemfire.config.annotation;
import java.util.Map;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;
/**
* The AddCacheServersConfiguration class registers {@link org.springframework.data.gemfire.server.CacheServerFactoryBean}
* bean definitions for all {@link EnableCacheServer} annotation configuration meta-data defined in
* the {@link EnableCacheServers} annotation on the GemFire cache application class.
*
* @author John Blum
* @see org.springframework.data.gemfire.config.annotation.AddCacheServerConfiguration
* @see org.springframework.data.gemfire.config.annotation.EnableCacheServers
* @since 1.9.0
*/
public class AddCacheServersConfiguration extends AddCacheServerConfiguration {
/*
* (non-Javadoc)
* @see org.springframework.context.annotation.ImportBeanDefinitionRegistrar#registerBeanDefinitions(AnnotationMetadata, BeanDefinitionRegistry)
*/
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
if (importingClassMetadata.hasAnnotation(EnableCacheServers.class.getName())) {
Map<String, Object> enableCacheServersAttributes = importingClassMetadata.getAnnotationAttributes(
EnableCacheServers.class.getName());
AnnotationAttributes[] serversAttributes =
(AnnotationAttributes[]) enableCacheServersAttributes.get("servers");
for (AnnotationAttributes enableCacheServerAttributes : serversAttributes) {
addCacheServerFactoryBeanDefinition(enableCacheServerAttributes, registry);
}
}
}
}

View File

@@ -50,8 +50,8 @@ import org.springframework.data.gemfire.server.SubscriptionEvictionPolicy;
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Documented
@Configuration
@Import(CacheServerConfiguration.class)
@SuppressWarnings("unused")
@@ -69,7 +69,7 @@ public @interface CacheServerApplication {
*
* @see com.gemstone.gemfire.cache.server.CacheServer#DEFAULT_BIND_ADDRESS
*/
String bindAddress() default "localhost";
String bindAddress() default CacheServer.DEFAULT_BIND_ADDRESS;
/**
* Indicates whether the "copy on read" is enabled for this cache.

View File

@@ -45,8 +45,8 @@ import org.springframework.data.gemfire.GemfireUtils;
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Documented
@Configuration
@Import(ClientCacheConfiguration.class)
@SuppressWarnings("unused")

View File

@@ -152,8 +152,7 @@ public class ClientCacheConfiguration extends AbstractCacheConfiguration {
setSubscriptionEnabled(Boolean.TRUE.equals(clientCacheApplicationAttributes.get("subscriptionEnabled")));
setSubscriptionMessageTrackingTimeout((Integer) clientCacheApplicationAttributes.get("subscriptionMessageTrackingTimeout"));
setSubscriptionRedundancy((Integer) clientCacheApplicationAttributes.get("subscriptionRedundancy"));
setThreadLocalConnections(Boolean.TRUE.equals(
clientCacheApplicationAttributes.get("threadLocalConnections")));
setThreadLocalConnections(Boolean.TRUE.equals(clientCacheApplicationAttributes.get("threadLocalConnections")));
configureLocatorOrServer(clientCacheApplicationAttributes);
}

View File

@@ -0,0 +1,146 @@
/*
* Copyright 2012 the original author or authors.
*
* 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 org.springframework.data.gemfire.config.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import com.gemstone.gemfire.cache.server.CacheServer;
import com.gemstone.gemfire.cache.server.ClientSubscriptionConfig;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.gemfire.server.SubscriptionEvictionPolicy;
/**
* The EnableCacheServer class...
*
* @author John Blum
* @since 1.0.0
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
@Configuration
@Import(AddCacheServerConfiguration.class)
@SuppressWarnings("unused")
public @interface EnableCacheServer {
/**
* Configures whether the {@link CacheServer} should start automatically at runtime.
*
* Default is {@literal true).
*/
boolean autoStartup() default true;
/**
* Configures the ip address or host name that this cache server will listen on.
*
* @see com.gemstone.gemfire.cache.server.CacheServer#DEFAULT_BIND_ADDRESS
*/
String bindAddress() default CacheServer.DEFAULT_BIND_ADDRESS;
/**
* Configures the ip address or host name that server locators will tell clients that this cache server
* is listening on.
*
* @see com.gemstone.gemfire.cache.server.CacheServer#DEFAULT_HOSTNAME_FOR_CLIENTS
*/
String hostnameForClients() default CacheServer.DEFAULT_HOSTNAME_FOR_CLIENTS;
/**
* Configures the frequency in milliseconds to poll the load probe on this cache server.
*
* @see com.gemstone.gemfire.cache.server.CacheServer#DEFAULT_LOAD_POLL_INTERVAL
*/
long loadPollInterval() default CacheServer.DEFAULT_LOAD_POLL_INTERVAL;
/**
* Configures the maximum allowed client connections.
*
* @see com.gemstone.gemfire.cache.server.CacheServer#DEFAULT_MAX_CONNECTIONS
*/
int maxConnections() default CacheServer.DEFAULT_MAX_CONNECTIONS;
/**
* Configures he maximum number of messages that can be enqueued in a client-queue.
*
* @see com.gemstone.gemfire.cache.server.CacheServer#DEFAULT_MAXIMUM_MESSAGE_COUNT
*/
int maxMessageCount() default CacheServer.DEFAULT_MAXIMUM_MESSAGE_COUNT;
/**
* Configures the maximum number of threads allowed in this cache server to service client requests.
*
* @see com.gemstone.gemfire.cache.server.CacheServer#DEFAULT_MAX_THREADS
*/
int maxThreads() default CacheServer.DEFAULT_MAX_THREADS;
/**
* Configures the maximum amount of time between client pings.
*
* @see com.gemstone.gemfire.cache.server.CacheServer#DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS
*/
int maxTimeBetweenPings() default CacheServer.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS;
/**
* Configures the time (in seconds ) after which a message in the client queue will expire.
*
* @see com.gemstone.gemfire.cache.server.CacheServer#DEFAULT_MESSAGE_TIME_TO_LIVE
*/
int messageTimeToLive() default CacheServer.DEFAULT_MESSAGE_TIME_TO_LIVE;
/**
* Configures the port on which this cache server listens for clients.
*
* @see com.gemstone.gemfire.cache.server.CacheServer#DEFAULT_PORT
*/
int port() default CacheServer.DEFAULT_PORT;
/**
* Configures the configured buffer size of the socket connection for this CacheServer.
*
* @see com.gemstone.gemfire.cache.server.CacheServer#DEFAULT_SOCKET_BUFFER_SIZE
*/
int socketBufferSize() default CacheServer.DEFAULT_SOCKET_BUFFER_SIZE;
/**
* Configures the capacity of the client queue.
*
* @see com.gemstone.gemfire.cache.server.ClientSubscriptionConfig#DEFAULT_CAPACITY
*/
int subscriptionCapacity() default ClientSubscriptionConfig.DEFAULT_CAPACITY;
/**
* Configures the disk store name for overflow.
*/
String subscriptionDiskStoreName() default "";
/**
* Configures the eviction policy that is executed when capacity of the client queue is reached.
*
* Defaults to {@link SubscriptionEvictionPolicy#NONE}.
*/
SubscriptionEvictionPolicy subscriptionEvictionPolicy() default SubscriptionEvictionPolicy.NONE;
}

View File

@@ -0,0 +1,47 @@
/*
* Copyright 2012 the original author or authors.
*
* 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 org.springframework.data.gemfire.config.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* The EnableCacheServers class...
*
* @author John Blum
* @since 1.0.0
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
@Configuration
@Import(AddCacheServersConfiguration.class)
@SuppressWarnings("unused")
public @interface EnableCacheServers {
EnableCacheServer[] servers() default {};
}

View File

@@ -27,21 +27,21 @@ import java.lang.annotation.Target;
import org.springframework.context.annotation.Import;
/**
* The EnableEmbeddedLocator annotation marks a Spring {@link org.springframework.context.annotation.Configuration @Configuration}
* The EnableLocator annotation marks a Spring {@link org.springframework.context.annotation.Configuration @Configuration}
* annotated class to start an embedded GemFire Locator service in this GemFire server/data node.
*
* @author John Blum
* @see org.springframework.context.annotation.Import
* @see org.springframework.data.gemfire.config.annotation.EmbeddedLocatorConfiguration
* @see LocatorConfiguration
* @since 1.9.0
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
@Import(EmbeddedLocatorConfiguration.class)
@Import(LocatorConfiguration.class)
@SuppressWarnings("unused")
public @interface EnableEmbeddedLocator {
public @interface EnableLocator {
/**
* Configures the host/IP address on which the embedded Locator service will bind to for accepting connections
@@ -49,7 +49,7 @@ public @interface EnableEmbeddedLocator {
*
* Default is {@literal localhost}.
*/
String host() default EmbeddedLocatorConfiguration.DEFAULT_HOST;
String host() default LocatorConfiguration.DEFAULT_HOST;
/**
* Configures the port on which the embedded Locator service will bind to listening for client connections
@@ -57,6 +57,6 @@ public @interface EnableEmbeddedLocator {
*
* Default is {@literal 10334}.
*/
int port() default EmbeddedLocatorConfiguration.DEFAULT_LOCATOR_PORT;
int port() default LocatorConfiguration.DEFAULT_LOCATOR_PORT;
}

View File

@@ -27,21 +27,21 @@ import java.lang.annotation.Target;
import org.springframework.context.annotation.Import;
/**
* The EnableEmbeddedManager annotation marks a Spring {@link org.springframework.context.annotation.Configuration @Configuration}
* The EnableManager annotation marks a Spring {@link org.springframework.context.annotation.Configuration @Configuration}
* annotated class to embed and start a GemFire Manager service in the GemFire server/data node.
*
* @author John Blum
* @see org.springframework.context.annotation.Import
* @see org.springframework.data.gemfire.config.annotation.EmbeddedManagerConfiguration
* @see ManagerConfiguration
* @since 1.9.0
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
@Import(EmbeddedManagerConfiguration.class)
@Import(ManagerConfiguration.class)
@SuppressWarnings("unused")
public @interface EnableEmbeddedManager {
public @interface EnableManager {
/**
* If {@literal true} then this member is willing to be a JMX Manager. All the other JMX Manager properties will be
@@ -97,7 +97,7 @@ public @interface EnableEmbeddedManager {
*
* Defaults to {@literal 1099}.
*/
int jmxManagerPort() default EmbeddedManagerConfiguration.DEFAULT_JMX_MANAGER_PORT;
int jmxManagerPort() default ManagerConfiguration.DEFAULT_JMX_MANAGER_PORT;
/**
* Enables or disables SSL for connections to the JMX Manager. If {@literal true} and {@literal jmx-manager-port}

View File

@@ -25,16 +25,16 @@ import org.springframework.data.gemfire.config.annotation.support.EmbeddedServic
import org.springframework.data.gemfire.util.PropertiesBuilder;
/**
* The EmbeddedLocatorConfiguration class is a Spring {@link org.springframework.context.annotation.ImportBeanDefinitionRegistrar}
* The LocatorConfiguration class is a Spring {@link org.springframework.context.annotation.ImportBeanDefinitionRegistrar}
* that applies additional GemFire configuration by way of GemFire System properties to configure
* an embedded GemFire Locator.
*
* @author John Blum
* @see org.springframework.data.gemfire.config.annotation.EnableEmbeddedLocator
* @see EnableLocator
* @see org.springframework.data.gemfire.config.annotation.support.EmbeddedServiceConfigurationSupport
* @since 1.9.0
*/
public class EmbeddedLocatorConfiguration extends EmbeddedServiceConfigurationSupport {
public class LocatorConfiguration extends EmbeddedServiceConfigurationSupport {
protected static final int DEFAULT_LOCATOR_PORT = GemfireUtils.DEFAULT_LOCATOR_PORT;
@@ -42,7 +42,7 @@ public class EmbeddedLocatorConfiguration extends EmbeddedServiceConfigurationSu
@Override
protected Class getAnnotationType() {
return EnableEmbeddedLocator.class;
return EnableLocator.class;
}
@Override

View File

@@ -24,22 +24,22 @@ import org.springframework.data.gemfire.config.annotation.support.EmbeddedServic
import org.springframework.data.gemfire.util.PropertiesBuilder;
/**
* The EmbeddedManagerConfiguration class is a Spring {@link org.springframework.context.annotation.ImportBeanDefinitionRegistrar}
* The ManagerConfiguration class is a Spring {@link org.springframework.context.annotation.ImportBeanDefinitionRegistrar}
* that applies additional GemFire configuration by way of GemFire System properties to configure
* an embedded GemFire Manager.
*
* @author John Blum
* @see org.springframework.data.gemfire.config.annotation.EnableEmbeddedManager
* @see EnableManager
* @see org.springframework.data.gemfire.config.annotation.support.EmbeddedServiceConfigurationSupport
* @since 1.9.0
*/
public class EmbeddedManagerConfiguration extends EmbeddedServiceConfigurationSupport {
public class ManagerConfiguration extends EmbeddedServiceConfigurationSupport {
protected static final int DEFAULT_JMX_MANAGER_PORT = 1099;
@Override
protected Class getAnnotationType() {
return EnableEmbeddedManager.class;
return EnableManager.class;
}
@Override

View File

@@ -42,8 +42,8 @@ import org.springframework.context.annotation.Import;
*/
@Target({ ElementType.ANNOTATION_TYPE, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Documented
@Configuration
@Import(PeerCacheConfiguration.class)
@SuppressWarnings("unused")