001package com.avaje.ebeaninternal.server.cluster; 002 003import java.util.ArrayList; 004import java.util.List; 005import java.util.Properties; 006 007/** 008 * Configuration for clustering using TCP sockets. 009 */ 010public class SocketConfig { 011 012 /** 013 * This local server in host:port format. 014 */ 015 private String localHostPort; 016 017 /** 018 * All the cluster members in host:port format. 019 */ 020 private List<String> members = new ArrayList<String>(); 021 022 /** 023 * core threads for the associated thread pool. 024 */ 025 private int coreThreads = 2; 026 027 /** 028 * Max threads for the associated thread pool. 029 */ 030 private int maxThreads = 16; 031 032 private String threadPoolName = "EbeanCluster"; 033 034 private Properties properties; 035 036 /** 037 * Return the host and port for this server instance. 038 */ 039 public String getLocalHostPort() { 040 return localHostPort; 041 } 042 043 /** 044 * Set the host and port for this server instance. 045 */ 046 public void setLocalHostPort(String localHostPort) { 047 this.localHostPort = localHostPort; 048 } 049 050 /** 051 * Return all the host and port for all the members of the cluster. 052 */ 053 public List<String> getMembers() { 054 return members; 055 } 056 057 /** 058 * Set all the host and port for all the members of the cluster. 059 */ 060 public void setMembers(List<String> members) { 061 this.members = members; 062 } 063 064 /** 065 * Return the number of core threads to use. 066 */ 067 public int getCoreThreads() { 068 return coreThreads; 069 } 070 071 /** 072 * Set the number of core threads to use. 073 */ 074 public void setCoreThreads(int coreThreads) { 075 this.coreThreads = coreThreads; 076 } 077 078 /** 079 * Return the number of max threads to use. 080 */ 081 public int getMaxThreads() { 082 return maxThreads; 083 } 084 085 /** 086 * Set the number of max threads to use. 087 */ 088 public void setMaxThreads(int maxThreads) { 089 this.maxThreads = maxThreads; 090 } 091 092 /** 093 * Return the thread pool name. 094 */ 095 public String getThreadPoolName() { 096 return threadPoolName; 097 } 098 099 /** 100 * Set the thread pool name. 101 */ 102 public void setThreadPoolName(String threadPoolName) { 103 this.threadPoolName = threadPoolName; 104 } 105 106 /** 107 * Load the properties into the configuration. 108 */ 109 public void loadFromProperties(Properties properties) { 110 111 this.properties = properties; 112 this.threadPoolName = getProperty("ebean.cluster.threadPoolName", threadPoolName); 113 this.localHostPort = getProperty("ebean.cluster.localHostPort", localHostPort); 114 this.coreThreads = getInt("ebean.cluster.coreThreads", coreThreads); 115 this.maxThreads = getInt("ebean.cluster.maxThreads", maxThreads); 116 117 String rawMembers = getProperty("ebean.cluster.members", ""); 118 String[] split = rawMembers.split("[,;]"); 119 for (String rawMember : split) { 120 members.add(rawMember.trim()); 121 } 122 } 123 124 private int getInt(String key, int value) { 125 return Integer.parseInt(getProperty(key, Integer.toString(value))); 126 } 127 128 private String getProperty(String key, String defaultValue) { 129 String value = properties.getProperty(key.toLowerCase()); 130 if (value != null) { 131 return value.trim(); 132 } 133 value = properties.getProperty(key, defaultValue); 134 return (value == null) ? null : value.trim(); 135 } 136}