001/* 002 * GWTEventService 003 * Copyright (c) 2011 and beyond, strawbill UG (haftungsbeschr?nkt) 004 * 005 * This is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU Lesser General Public License as 007 * published by the Free Software Foundation; either version 3 of 008 * the License, or (at your option) any later version. 009 * Other licensing for GWTEventService may also be possible on request. 010 * Please view the license.txt of the project for more information. 011 * 012 * This software is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public 018 * License along with this software; if not, write to the Free 019 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 020 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 021 */ 022package de.novanic.eventservice.config; 023 024import de.novanic.eventservice.util.PlatformUtil; 025 026import java.util.HashMap; 027import java.util.Map; 028 029/** 030 * An EventServiceConfiguration holds the configuration for {@link de.novanic.eventservice.client.event.service.EventService}. 031 * The time for a timeout and the min- and max-waiting-time can be configured. 032 * <br> 033 * <br>- Min waiting time - Listening should hold at least for min waiting time. 034 * <br>- Max waiting time - Listening shouldn't hold longer than max waiting time. 035 * <br>- Timeout time - Max time for a listen cycle. If the timeout time is exceeded, the client will be deregistered. 036 * 037 * @author sstrohschein 038 * <br>Date: 09.08.2008 039 * <br>Time: 23:17:38 040 */ 041public class RemoteEventServiceConfiguration implements EventServiceConfiguration 042{ 043 private final String myConfigDescription; 044 045 private Map<ConfigParameter, Object> myConfigMap; 046 047 /** 048 * Creates a new RemoteEventServiceConfiguration. 049 * @param aConfigDescription description of the configuration (for example the location) 050 * @param aMinWaitingTime min waiting time before listen returns (in milliseconds) 051 * @param aMaxWaitingTime max waiting time before listen returns, when no events recognized (in milliseconds) 052 * @param aTimeoutTime timeout time for a listen cycle (in milliseconds) 053 * @param aReconnectAttemptCount number of reconnect attempts 054 * @param aConnectionIdGeneratorClassName class name of the configured {@link de.novanic.eventservice.service.connection.id.ConnectionIdGenerator} to generate unique client ids 055 * @param aConnectionStrategyClientClassName class name of the configured connection strategy (client side part) 056 * @param aConnectionStrategyServerClassName class name of the configured connection strategy (server side part) 057 * @param aConnectionStrategyEncoding encoding / charset which is used by the connection strategies 058 */ 059 public RemoteEventServiceConfiguration(String aConfigDescription, Integer aMinWaitingTime, Integer aMaxWaitingTime, Integer aTimeoutTime, 060 Integer aReconnectAttemptCount, 061 String aConnectionIdGeneratorClassName, String aConnectionStrategyClientClassName, String aConnectionStrategyServerClassName, String aConnectionStrategyEncoding, 062 Integer aMaxEvents) { 063 myConfigDescription = aConfigDescription; 064 myConfigMap = new HashMap<ConfigParameter, Object>(); 065 myConfigMap.put(ConfigParameter.MIN_WAITING_TIME_TAG, aMinWaitingTime); 066 myConfigMap.put(ConfigParameter.MAX_WAITING_TIME_TAG, aMaxWaitingTime); 067 myConfigMap.put(ConfigParameter.TIMEOUT_TIME_TAG, aTimeoutTime); 068 myConfigMap.put(ConfigParameter.RECONNECT_ATTEMPT_COUNT_TAG, aReconnectAttemptCount); 069 myConfigMap.put(ConfigParameter.CONNECTION_ID_GENERATOR, aConnectionIdGeneratorClassName); 070 myConfigMap.put(ConfigParameter.CONNECTION_STRATEGY_CLIENT_CONNECTOR, aConnectionStrategyClientClassName); 071 myConfigMap.put(ConfigParameter.CONNECTION_STRATEGY_SERVER_CONNECTOR, aConnectionStrategyServerClassName); 072 myConfigMap.put(ConfigParameter.CONNECTION_STRATEGY_ENCODING, aConnectionStrategyEncoding); 073 myConfigMap.put(ConfigParameter.MAX_EVENTS, aMaxEvents); 074 } 075 076 /** 077 * Returns the description of the configuration (for example the location). 078 * @return configuration description 079 */ 080 public String getConfigDescription() { 081 return myConfigDescription; 082 } 083 084 /** 085 * Returns the min waiting time. Listening should hold at least for min waiting time. 086 * @see de.novanic.eventservice.config.ConfigParameter#MIN_WAITING_TIME_TAG 087 * @return min waiting time 088 */ 089 public Integer getMinWaitingTime() { 090 return (Integer)myConfigMap.get(ConfigParameter.MIN_WAITING_TIME_TAG); 091 } 092 093 /** 094 * Returns the max waiting time. Listening shouldn't hold longer than max waiting time. 095 * @see de.novanic.eventservice.config.ConfigParameter#MAX_WAITING_TIME_TAG 096 * @return max waiting time 097 */ 098 public Integer getMaxWaitingTime() { 099 return (Integer)myConfigMap.get(ConfigParameter.MAX_WAITING_TIME_TAG); 100 } 101 102 /** 103 * Returns the timeout time (max time for a listen cycle). 104 * @see de.novanic.eventservice.config.ConfigParameter#TIMEOUT_TIME_TAG 105 * @return timeout time 106 */ 107 public Integer getTimeoutTime() { 108 return (Integer)myConfigMap.get(ConfigParameter.TIMEOUT_TIME_TAG); 109 } 110 111 /** 112 * Returns the number of reconnect attempts to execute. 113 * @see de.novanic.eventservice.config.ConfigParameter#RECONNECT_ATTEMPT_COUNT_TAG 114 * @return reconnect attempt count 115 */ 116 public Integer getReconnectAttemptCount() { 117 return (Integer)myConfigMap.get(ConfigParameter.RECONNECT_ATTEMPT_COUNT_TAG); 118 } 119 120 /** 121 * Returns the class name of the configured {@link de.novanic.eventservice.service.connection.id.ConnectionIdGenerator}. 122 * The {@link de.novanic.eventservice.service.connection.id.ConnectionIdGenerator} generates unique ids to identify the clients. 123 * @see de.novanic.eventservice.config.ConfigParameter#CONNECTION_ID_GENERATOR 124 * @return class name of the configured {@link de.novanic.eventservice.service.connection.id.ConnectionIdGenerator} 125 */ 126 public String getConnectionIdGeneratorClassName() { 127 return (String)myConfigMap.get(ConfigParameter.CONNECTION_ID_GENERATOR); 128 } 129 130 /** 131 * Returns the class name of the configured connection strategy (client side part). 132 * @see de.novanic.eventservice.config.ConfigParameter#CONNECTION_STRATEGY_CLIENT_CONNECTOR 133 * @return connection strategy (client side part) 134 */ 135 public String getConnectionStrategyClientConnectorClassName() { 136 return (String)myConfigMap.get(ConfigParameter.CONNECTION_STRATEGY_CLIENT_CONNECTOR); 137 } 138 139 /** 140 * Returns the class name of the configured connection strategy (server side part). 141 * @see de.novanic.eventservice.config.ConfigParameter#CONNECTION_STRATEGY_SERVER_CONNECTOR 142 * @return connection strategy (server side part) 143 */ 144 public String getConnectionStrategyServerConnectorClassName() { 145 return (String)myConfigMap.get(ConfigParameter.CONNECTION_STRATEGY_SERVER_CONNECTOR); 146 } 147 148 /** 149 * Returns the configured encoding / charset for the connection strategy. 150 * @see de.novanic.eventservice.config.ConfigParameter#CONNECTION_STRATEGY_ENCODING 151 * @return configured encoding / charset 152 */ 153 public String getConnectionStrategyEncoding() { 154 return (String)myConfigMap.get(ConfigParameter.CONNECTION_STRATEGY_ENCODING); 155 } 156 157 /** 158 * Returns the configured maximum amount of events which should be transferred to the client at once. 159 * @return configured maximum amount of events at once 160 */ 161 public Integer getMaxEvents() { 162 return (Integer)myConfigMap.get(ConfigParameter.MAX_EVENTS); 163 } 164 165 /** 166 * Returns the configurations as a {@link java.util.Map} with {@link de.novanic.eventservice.config.ConfigParameter} 167 * instances as the key. 168 * @return {@link java.util.Map} with the configurations with {@link de.novanic.eventservice.config.ConfigParameter} 169 * instances as the key 170 */ 171 public Map<ConfigParameter, Object> getConfigMap() { 172 return myConfigMap; 173 } 174 175 public boolean equals(Object anObject) { 176 if(this == anObject) { 177 return true; 178 } 179 if(anObject == null || getClass() != anObject.getClass()) { 180 return false; 181 } 182 183 EventServiceConfiguration theConfiguration = (EventServiceConfiguration)anObject; 184 185 return (getConfigMap().equals(theConfiguration.getConfigMap()) 186 && myConfigDescription.equals(theConfiguration.getConfigDescription())); 187 188 } 189 190 public int hashCode() { 191 int theResult = getConfigMap().hashCode(); 192 theResult = 31 * theResult + myConfigDescription.hashCode(); 193 return theResult; 194 } 195 196 public String toString() { 197 final String UNDEFINED = "<undefined>"; 198 final Integer theMinWaitingTime = getMinWaitingTime(); 199 final Integer theMaxWaitingTime = getMaxWaitingTime(); 200 final Integer theTimeoutTime = getTimeoutTime(); 201 202 StringBuilder theConfigStringBuilder = new StringBuilder(120); 203 theConfigStringBuilder.append("EventServiceConfiguration ("); 204 theConfigStringBuilder.append(getConfigDescription()); 205 theConfigStringBuilder.append(')'); 206 //print time settings 207 theConfigStringBuilder.append(PlatformUtil.getNewLine()); 208 theConfigStringBuilder.append(" Min.: "); 209 if(theMinWaitingTime != null) { 210 theConfigStringBuilder.append(theMinWaitingTime); 211 } else { 212 theConfigStringBuilder.append(UNDEFINED); 213 } 214 theConfigStringBuilder.append("ms; Max.: "); 215 if(theMaxWaitingTime != null) { 216 theConfigStringBuilder.append(theMaxWaitingTime); 217 } else { 218 theConfigStringBuilder.append(UNDEFINED); 219 } 220 theConfigStringBuilder.append("ms; Timeout: "); 221 if(theTimeoutTime != null) { 222 theConfigStringBuilder.append(theTimeoutTime); 223 } else { 224 theConfigStringBuilder.append(UNDEFINED); 225 } 226 theConfigStringBuilder.append("ms"); 227 return theConfigStringBuilder.toString(); 228 } 229}