001package io.ebean.config;
002
003import java.util.Properties;
004
005/**
006 * Configuration for the container that holds the Database instances.
007 * <p>
008 * Provides configuration for cluster communication (if clustering is used). The cluster communication is
009 * used to invalidate appropriate parts of the L2 cache across the cluster.
010 */
011public class ContainerConfig {
012
013  private boolean active;
014  private String serviceName;
015  private String namespace;
016  private String podName;
017  private int port;
018
019  private Properties properties;
020
021  /**
022   * Return the service name.
023   */
024  public String getServiceName() {
025    return serviceName;
026  }
027
028  /**
029   * Set the service name.
030   */
031  public void setServiceName(String serviceName) {
032    this.serviceName = serviceName;
033  }
034
035  /**
036   * Return the namespace.
037   */
038  public String getNamespace() {
039    return namespace;
040  }
041
042  /**
043   * Set the namespace.
044   */
045  public void setNamespace(String namespace) {
046    this.namespace = namespace;
047  }
048
049  /**
050   * Return the pod name.
051   */
052  public String getPodName() {
053    return podName;
054  }
055
056  /**
057   * Set the pod name.
058   */
059  public void setPodName(String podName) {
060    this.podName = podName;
061  }
062
063  /**
064   * Return the port to use.
065   */
066  public int getPort() {
067    return port;
068  }
069
070  /**
071   * Set the port to use.
072   */
073  public void setPort(int port) {
074    this.port = port;
075  }
076
077  /**
078   * Return true if clustering is active.
079   */
080  public boolean isActive() {
081    return active;
082  }
083
084  /**
085   * Set to true for clustering to be active.
086   */
087  public void setActive(boolean active) {
088    this.active = active;
089  }
090
091  /**
092   * Return the deployment properties.
093   */
094  public Properties getProperties() {
095    return properties;
096  }
097
098  /**
099   * Set the deployment properties.
100   */
101  public void setProperties(Properties properties) {
102    this.properties = properties;
103  }
104
105  /**
106   * Load the settings from properties.
107   */
108  public void loadFromProperties(Properties properties) {
109    this.properties = properties;
110    this.active = getProperty(properties, "ebean.cluster.active", active);
111    this.serviceName = properties.getProperty("ebean.cluster.serviceName", serviceName);
112    this.namespace = properties.getProperty("ebean.cluster.namespace", namespace);
113    this.podName = properties.getProperty("ebean.cluster.podName", podName);
114    String portParam = properties.getProperty("ebean.cluster.port");
115    if (portParam != null) {
116      this.port = Integer.parseInt(portParam);
117    }
118  }
119
120  /**
121   * Return the boolean property setting.
122   */
123  protected boolean getProperty(Properties properties, String key, boolean defaultValue) {
124    return "true".equalsIgnoreCase(properties.getProperty(key, Boolean.toString(defaultValue)));
125  }
126
127}