All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gemstone.gemfire.internal.modules.util.RegionConfiguration Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
 *
 * 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. See accompanying
 * LICENSE file.
 */
package com.gemstone.gemfire.internal.modules.util;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import com.gemstone.gemfire.DataSerializable;
import com.gemstone.gemfire.DataSerializer;
import com.gemstone.gemfire.Instantiator;
import com.gemstone.gemfire.cache.CacheWriter;
import com.gemstone.gemfire.cache.CustomExpiry;

/**
 * Class RegionConfiguration encapsulates the configuration
 * attributes for a Region to be created on the server.
 *
 * @author Barry Oglesby
 *
 * @since 6.5
 */
@SuppressWarnings({"serial","unchecked"})
public class RegionConfiguration implements DataSerializable {

  /**
   * The name of the Region to be created
   */
  private String regionName;
  
  /**
   * The id of the RegionAttributes to be used
   */
  private String regionAttributesId;
  
  /**
   * The default max inactive interval. The default value is -1.
   */
  public static final int DEFAULT_MAX_INACTIVE_INTERVAL = -1;

  /**
   * The maximum time interval in seconds before entries are expired
   */
  private int maxInactiveInterval = DEFAULT_MAX_INACTIVE_INTERVAL;
  
  /**
   * The CustomExpiry to be used
   */
  private CustomExpiry customExpiry;
  
  /**
   * Whether delta replication across a Gateway is enabled.
   */
  private boolean enableGatewayDeltaReplication = false;
  
  /**
   * Whether replication across a Gateway is enabled.
   */
  private boolean enableGatewayReplication = false;
  
  /**
   * Whether to add a DebugCacheListener to the Region.
   */
  private boolean enableDebugListener = false;
  
  /**
   * name for the CacheWriter to be associated with this region. This cache writer must have a
   * zero arg constructor and must be present on the classpath on the server.
   */
  private String cacheWriterName;
  
  /**
   * Default constructor used by the DataSerialiable interface
   */
  public RegionConfiguration() {}
  
  /**
   * Sets the name of the Region to be created
   * 
   * @param regionName
   *          The name of the Region to be created
   */
  public void setRegionName(String regionName) {
    this.regionName = regionName;
  }
  
  /**
   * Returns the name of the Region to be created
   * 
   * @return the name of the Region to be created
   */
  public String getRegionName() {
    return this.regionName;
  }
  
  /**
   * Sets the id of the RegionAttributes to be used
   * 
   * @param regionAttributesId
   *          The id of the RegionAttributes to be used
   */
  public void setRegionAttributesId(String regionAttributesId) {
    this.regionAttributesId = regionAttributesId;
  }

  /**
   * Returns the id of the RegionAttributes to be used
   * 
   * @return the id of the RegionAttributes to be used
   */
  public String getRegionAttributesId() {
    return this.regionAttributesId;
  }
  
  /**
   * Sets the maximum time interval in seconds before entries are expired
   * 
   * @param maxInactiveInterval
   *          The maximum time interval in seconds before entries are expired
   */
  public void setMaxInactiveInterval(int maxInactiveInterval) {
    this.maxInactiveInterval = maxInactiveInterval;
  }
  
  /**
   * Returns the maximum time interval in seconds entries are expired
   * 
   * @return the maximum time interval in seconds before entries are expired
   */
  public int getMaxInactiveInterval() {
    return this.maxInactiveInterval;
  }

  /**
   * Sets the CustomExpiry to be used
   * 
   * @param customExpiry
   *          The CustomExpiry to be used
   */
  public void setCustomExpiry(CustomExpiry customExpiry) {
    this.customExpiry = customExpiry;
  }
  
  /**
   * Returns the CustomExpiry to be used
   * 
   * @return the CustomExpiry to be used
   */
  public CustomExpiry getCustomExpiry() {
    return this.customExpiry;
  }
  
  /**
   * Enables/disables delta replication across a Gateway.
   * 
   * @param enableGatewayDeltaReplication
   *          true to enable, false to disable gateway delta replication.
   */
  public void setEnableGatewayDeltaReplication(boolean enableGatewayDeltaReplication) {
    this.enableGatewayDeltaReplication = enableGatewayDeltaReplication;
  }

  /**
   * Returns whether delta replication across a Gateway is enabled.
   *
   * @return whether delta replication across a Gateway is enabled
   */
  public boolean getEnableGatewayDeltaReplication() {
    return this.enableGatewayDeltaReplication;
  }

  /**
   * Enables/disables replication across a Gateway.
   * 
   * @param enableGatewayReplication
   *          true to enable, false to disable gateway replication.
   */
  public void setEnableGatewayReplication(boolean enableGatewayReplication) {
    this.enableGatewayReplication = enableGatewayReplication;
  }

  /**
   * Returns whether replication across a Gateway is enabled.
   *
   * @return whether replication across a Gateway is enabled
   */
  public boolean getEnableGatewayReplication() {
    return this.enableGatewayReplication;
  }

  /**
   * Enables/disables a debug CacheListener.
   * 
   * @param enableDebugListener
   *          true to enable, false to disable debug CacheListener.
   */
  public void setEnableDebugListener(boolean enableDebugListener) {
    this.enableDebugListener = enableDebugListener;
  }
  
  /**
   * Returns whether a debug CacheListener is enabled.
   * 
   * @return whether a debug CacheListener is enabled
   */
  public boolean getEnableDebugListener() {
    return this.enableDebugListener;
  }

  public void toData(DataOutput out) throws IOException {
    DataSerializer.writeString(this.regionName, out);
    DataSerializer.writeString(this.regionAttributesId, out);
    DataSerializer.writePrimitiveInt(this.maxInactiveInterval, out);
    DataSerializer.writeObject(this.customExpiry, out);
    DataSerializer.writeBoolean(this.enableGatewayDeltaReplication, out);
    DataSerializer.writeBoolean(this.enableGatewayReplication, out);
    DataSerializer.writeBoolean(this.enableDebugListener, out);
    DataSerializer.writeString(this.cacheWriterName, out);
  }

  public void fromData(DataInput in) throws IOException, ClassNotFoundException {
    this.regionName = DataSerializer.readString(in);
    this.regionAttributesId = DataSerializer.readString(in);
    this.maxInactiveInterval = DataSerializer.readPrimitiveInt(in);
    this.customExpiry = DataSerializer.readObject(in);
    this.enableGatewayDeltaReplication = DataSerializer.readBoolean(in);
    this.enableGatewayReplication = DataSerializer.readBoolean(in);
    this.enableDebugListener = DataSerializer.readBoolean(in);
    this.cacheWriterName = DataSerializer.readString(in);
  }

  /**
   * Registers an Instantiator for the
   * SessionConfiguration class
   */
  public static void registerInstantiator(int id) {
    Instantiator.register(new Instantiator(RegionConfiguration.class, id) {
      public DataSerializable newInstance() {
        return new RegionConfiguration();
      }
    });
  }
  
  public String toString() {
    return new StringBuilder()
      .append("RegionConfiguration[")
      .append("regionName=")
      .append(this.regionName)
      .append("; regionAttributesId=")
      .append(this.regionAttributesId)
      .append("; maxInactiveInterval=")
      .append(this.maxInactiveInterval)
      .append("; enableGatewayDeltaReplication=")
      .append(this.enableGatewayDeltaReplication)
      .append("; enableGatewayReplication=")
      .append(this.enableGatewayReplication)
      .append("; enableDebugListener=")
      .append(this.enableDebugListener)
      .append("; cacheWriter=")
      .append(this.cacheWriterName)
      .append("]")
      .toString();
  }

  /**
   * set the fully qualified name of the {@link CacheWriter} to be created on
   * the server. The cacheWriter must have a zero arg constructor, and must be
   * present on the classpath on the server.
   * @param cacheWriterName fully qualified class name of the cacheWriter
   */
  public void setCacheWriterName(String cacheWriterName) {
    this.cacheWriterName = cacheWriterName;
  }

  public String getCacheWriterName() {
    return cacheWriterName;
  }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy