From ea0607a7115b453ccf6cc01cc3b1201463298d4c Mon Sep 17 00:00:00 2001 From: John Blum Date: Wed, 7 Sep 2016 11:47:30 -0700 Subject: [PATCH] SGF-519 - Configure Mcast with annotations. --- .../gemfire/config/annotation/EnableAuth.java | 4 + .../config/annotation/EnableLogging.java | 5 +- .../config/annotation/EnableMcast.java | 134 ++++++++++++++++++ .../annotation/LoggingConfiguration.java | 2 +- .../config/annotation/McastConfiguration.java | 72 ++++++++++ 5 files changed, 215 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/springframework/data/gemfire/config/annotation/EnableMcast.java create mode 100644 src/main/java/org/springframework/data/gemfire/config/annotation/McastConfiguration.java diff --git a/src/main/java/org/springframework/data/gemfire/config/annotation/EnableAuth.java b/src/main/java/org/springframework/data/gemfire/config/annotation/EnableAuth.java index 3d744033..e486ebd2 100644 --- a/src/main/java/org/springframework/data/gemfire/config/annotation/EnableAuth.java +++ b/src/main/java/org/springframework/data/gemfire/config/annotation/EnableAuth.java @@ -28,11 +28,14 @@ import com.gemstone.gemfire.security.AccessControl; import com.gemstone.gemfire.security.AuthInitialize; import com.gemstone.gemfire.security.Authenticator; +import org.springframework.context.annotation.Import; + /** * The EnableAuth annotation marks a Spring {@link org.springframework.context.annotation.Configuration @Configuration} * annotated class to configure and enable GemFire/Geode's Authentication and Authorization framework services. * * @author John Blum + * @see org.springframework.data.gemfire.config.annotation.AuthConfiguration * @see com.gemstone.gemfire.security.AccessControl * @see com.gemstone.gemfire.security.AuthInitialize * @see com.gemstone.gemfire.security.Authenticator @@ -44,6 +47,7 @@ import com.gemstone.gemfire.security.Authenticator; @Retention(RetentionPolicy.RUNTIME) @Inherited @Documented +@Import(AuthConfiguration.class) @SuppressWarnings({ "deprecation", "unused" }) public @interface EnableAuth { diff --git a/src/main/java/org/springframework/data/gemfire/config/annotation/EnableLogging.java b/src/main/java/org/springframework/data/gemfire/config/annotation/EnableLogging.java index d9011c7f..cc58a21a 100644 --- a/src/main/java/org/springframework/data/gemfire/config/annotation/EnableLogging.java +++ b/src/main/java/org/springframework/data/gemfire/config/annotation/EnableLogging.java @@ -24,18 +24,21 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.springframework.context.annotation.Import; + /** * The EnableLogging annotation marks a Spring {@link org.springframework.context.annotation.Configuration @Configuration} * annotated class to configure and enable GemFire/Geode system logging. * * @author John Blum - * @see org.springframework.data.gemfire.config.annotation + * @see org.springframework.data.gemfire.config.annotation.LoggingConfiguration * @since 1.9.0 */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Inherited @Documented +@Import(LoggingConfiguration.class) @SuppressWarnings("unused") public @interface EnableLogging { diff --git a/src/main/java/org/springframework/data/gemfire/config/annotation/EnableMcast.java b/src/main/java/org/springframework/data/gemfire/config/annotation/EnableMcast.java new file mode 100644 index 00000000..7100538a --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/config/annotation/EnableMcast.java @@ -0,0 +1,134 @@ +/* + * 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.Import; + +/** + * The EnableMcast annotation marks a Spring {@link org.springframework.context.annotation.Configuration @Configuration} + * annotated class to configure and enable GemFire/Geode's multi-cast networking support. + * + * @author John Blum + * @see org.springframework.data.gemfire.config.annotation.EnableMcast + * @since 1.9.0 + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Inherited +@Documented +@Import(McastConfiguration.class) +@SuppressWarnings("unused") +public @interface EnableMcast { + + /** + * Address used to discover other members of the distributed system. Only used if {@literal mcast-port} is non-zero. + * This attribute must be consistent across the distributed system. Select different multicast addresses + * and different ports for different distributed systems. Do not just use different addresses. + * Some operating systems may not keep communication separate between systems that use unique addresses + * but the same port number. + * + * This default multicast address was assigned by IANA. Consult the IANA chart when selecting another multicast + * address to use with GemFire. + * + * This setting controls only peer-to-peer communication and does not apply to client/server or multi-site + * communication. If multicast is enabled, distributed regions use it for most communication. Partitioned Regions + * only use multicast for a few purposes and mainly use either TCP or UDP unicast. + * + * Defaults to {@literal 239.192.81.1} for IPv4 and {@literal FF38::1234} for IPv6. + * + * @see IANA chart + */ + String address() default McastConfiguration.DEFAULT_MCAST_ADDRESS; + + /** + * Tuning property for flow-of-control protocol for unicast and multicast no-ack UDP messaging. Compound property + * is made up of three settings separated by commas: {@literal byteAllowance}, {@literal rechargeThreshold}, + * and {@literal rechargeBlockMs}. + * + * Valid values range from these minimums: 10000,0.1,500 to these maximums: no_maximum ,0.5,60000. + * + * This setting controls only peer-to-peer communication, generally between distributed Regions. + * + * Defaults to {@literal 1048576,0.25,5000}. + */ + String flowControl() default McastConfiguration.DEFAULT_MCAST_FLOW_CONTROL; + + /** + * Port used, along with the mcast-address, for multicast communication with other members + * of the distributed system. + * + * If zero, multicast is disabled. If you have values specified for the {@literal locators} property, + * the {@literal mcast-port} property defaults to {@literal 0}. + * + * Valid values are in the range 0..65535. + * + * Select different multicast addresses and ports for different distributed systems. Do not just use + * different addresses. Some operating systems may not keep communication separate between systems + * that use unique addresses but the same port number. + * + * This setting controls only peer-to-peer communication and does not apply to client/server + * or multi-site communication. + * + * Defaults to {@literal 10334}. + */ + int port() default McastConfiguration.DEFAULT_MCAST_PORT; + + /** + * Size of the socket buffer used for incoming multicast transmissions. You should set this high + * if there will be high volumes of messages. + * + * Valid values are in the range 2048.. OS_maximum. + * + * The default setting is higher than the default OS maximum buffer size on Unix, which should be increased + * to at least 1 megabyte to provide high-volume messaging on Unix systems. + * + * This setting controls only peer-to-peer communication and does not apply to client/server + * or multi-site communication. + * + * Defaults to {@literal 1048576} bytes. + */ + int receiveBufferSize() default McastConfiguration.DEFAULT_MCAST_RECEIVE_BUFFER_SIZE; + + /** + * The size of the socket buffer used for outgoing multicast transmissions. + * + * Valid values are in the range 2048.. OS_maximum. + * + * This setting controls only peer-to-peer communication and does not apply to client/server + * or multi-site communication. + * + * Defaults to {@literal 65535}. + */ + int sendBufferSize() default McastConfiguration.DEFAULT_MCAST_SEND_BUFFER_SIZE; + + /** + * How far multicast messaging goes in your network. Lower settings may improve system performance. + * A setting of 0 constrains multicast messaging to the machine. + * + * Defaults to {@literal 32}. + */ + int timeToLive() default 32; + +} diff --git a/src/main/java/org/springframework/data/gemfire/config/annotation/LoggingConfiguration.java b/src/main/java/org/springframework/data/gemfire/config/annotation/LoggingConfiguration.java index cccbc624..1872dec1 100644 --- a/src/main/java/org/springframework/data/gemfire/config/annotation/LoggingConfiguration.java +++ b/src/main/java/org/springframework/data/gemfire/config/annotation/LoggingConfiguration.java @@ -24,7 +24,7 @@ import org.springframework.data.gemfire.config.annotation.support.EmbeddedServic import org.springframework.data.gemfire.util.PropertiesBuilder; /** - * The LoggingConfiguration classis a Spring {@link org.springframework.context.annotation.ImportBeanDefinitionRegistrar} + * The LoggingConfiguration class is a Spring {@link org.springframework.context.annotation.ImportBeanDefinitionRegistrar} * that applies additional GemFire/Geode configuration by way of GemFire/Geode System properties to configure * GemFire/Geode logging. * diff --git a/src/main/java/org/springframework/data/gemfire/config/annotation/McastConfiguration.java b/src/main/java/org/springframework/data/gemfire/config/annotation/McastConfiguration.java new file mode 100644 index 00000000..b2c01663 --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/config/annotation/McastConfiguration.java @@ -0,0 +1,72 @@ +/* + * 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 java.util.Properties; + +import org.springframework.data.gemfire.config.annotation.support.EmbeddedServiceConfigurationSupport; +import org.springframework.data.gemfire.util.PropertiesBuilder; + +/** + * The McastConfiguration class is a Spring {@link org.springframework.context.annotation.ImportBeanDefinitionRegistrar} + * that applies additional GemFire/Geode configuration by way of GemFire/Geode System properties to configure + * GemFire/Geode multi-cast networking rather than the (preferred) Locator-based location services. + * + * @author John Blum + * @see org.springframework.data.gemfire.config.annotation.EnableMcast + * @see org.springframework.data.gemfire.config.annotation.support.EmbeddedServiceConfigurationSupport + * @since 1.9.0 + */ +public class McastConfiguration extends EmbeddedServiceConfigurationSupport { + + public static final int DEFAULT_MCAST_PORT = 10334; + public static final int DEFAULT_MCAST_RECEIVE_BUFFER_SIZE = 1048576; + public static final int DEFAULT_MCAST_SEND_BUFFER_SIZE = 65535; + + public static final String DEFAULT_MCAST_ADDRESS = "239.192.81.1"; + public static final String DEFAULT_MCAST_FLOW_CONTROL = "1048576,0.25,5000"; + + /* (non-Javadoc) */ + @Override + protected Class getAnnotationType() { + return EnableMcast.class; + } + + /* (non-Javadoc) */ + @Override + protected Properties toGemFireProperties(Map annotationAttributes) { + PropertiesBuilder gemfireProperties = PropertiesBuilder.create(); + + gemfireProperties.setPropertyIfNotDefault("mcast-address", + annotationAttributes.get("address"), DEFAULT_MCAST_ADDRESS); + + gemfireProperties.setPropertyIfNotDefault("mcast-flow-control", + annotationAttributes.get("flowControl"), DEFAULT_MCAST_FLOW_CONTROL); + + gemfireProperties.setPropertyIfNotDefault("mcast-port", annotationAttributes.get("port"), DEFAULT_MCAST_PORT); + + gemfireProperties.setPropertyIfNotDefault("mcast-recv-buffer-size", + annotationAttributes.get("receiveBufferSize"), DEFAULT_MCAST_RECEIVE_BUFFER_SIZE); + + gemfireProperties.setPropertyIfNotDefault("mcast-send-buffer-size", + annotationAttributes.get("sendBufferSize"), DEFAULT_MCAST_SEND_BUFFER_SIZE); + + return gemfireProperties.build(); + } +}