001 /* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at 010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE 011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE. 012 * See the License for the specific language governing permissions 013 * and limitations under the License. 014 * 015 * When distributing Covered Code, include this CDDL HEADER in each 016 * file and include the License file at 017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, 018 * add the following below this CDDL HEADER, with the fields enclosed 019 * by brackets "[]" replaced with your own identifying information: 020 * Portions Copyright [yyyy] [name of copyright owner] 021 * 022 * CDDL HEADER END 023 * 024 * 025 * Copyright 2008 Sun Microsystems, Inc. 026 */ 027 package org.opends.server.admin.std.meta; 028 029 030 031 import org.opends.server.admin.AdministratorAction; 032 import org.opends.server.admin.ClassPropertyDefinition; 033 import org.opends.server.admin.client.AuthorizationException; 034 import org.opends.server.admin.client.CommunicationException; 035 import org.opends.server.admin.client.ConcurrentModificationException; 036 import org.opends.server.admin.client.ManagedObject; 037 import org.opends.server.admin.client.MissingMandatoryPropertiesException; 038 import org.opends.server.admin.client.OperationRejectedException; 039 import org.opends.server.admin.DefaultBehaviorProvider; 040 import org.opends.server.admin.DefinedDefaultBehaviorProvider; 041 import org.opends.server.admin.ManagedObjectAlreadyExistsException; 042 import org.opends.server.admin.ManagedObjectDefinition; 043 import org.opends.server.admin.PropertyOption; 044 import org.opends.server.admin.PropertyProvider; 045 import org.opends.server.admin.server.ConfigurationChangeListener; 046 import org.opends.server.admin.server.ServerManagedObject; 047 import org.opends.server.admin.SizePropertyDefinition; 048 import org.opends.server.admin.std.client.SizeLimitLogRotationPolicyCfgClient; 049 import org.opends.server.admin.std.server.LogRotationPolicyCfg; 050 import org.opends.server.admin.std.server.SizeLimitLogRotationPolicyCfg; 051 import org.opends.server.admin.Tag; 052 import org.opends.server.admin.UndefinedDefaultBehaviorProvider; 053 import org.opends.server.types.DN; 054 055 056 057 /** 058 * An interface for querying the Size Limit Log Rotation Policy 059 * managed object definition meta information. 060 * <p> 061 * Rotation policy based on the size of the log file. 062 */ 063 public final class SizeLimitLogRotationPolicyCfgDefn extends ManagedObjectDefinition<SizeLimitLogRotationPolicyCfgClient, SizeLimitLogRotationPolicyCfg> { 064 065 // The singleton configuration definition instance. 066 private static final SizeLimitLogRotationPolicyCfgDefn INSTANCE = new SizeLimitLogRotationPolicyCfgDefn(); 067 068 069 070 // The "file-size-limit" property definition. 071 private static final SizePropertyDefinition PD_FILE_SIZE_LIMIT; 072 073 074 075 // The "java-class" property definition. 076 private static final ClassPropertyDefinition PD_JAVA_CLASS; 077 078 079 080 // Build the "file-size-limit" property definition. 081 static { 082 SizePropertyDefinition.Builder builder = SizePropertyDefinition.createBuilder(INSTANCE, "file-size-limit"); 083 builder.setOption(PropertyOption.MANDATORY); 084 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "file-size-limit")); 085 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Long>()); 086 builder.setLowerLimit("1"); 087 PD_FILE_SIZE_LIMIT = builder.getInstance(); 088 INSTANCE.registerPropertyDefinition(PD_FILE_SIZE_LIMIT); 089 } 090 091 092 093 // Build the "java-class" property definition. 094 static { 095 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 096 builder.setOption(PropertyOption.MANDATORY); 097 builder.setOption(PropertyOption.ADVANCED); 098 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class")); 099 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.loggers.SizeBasedRotationPolicy"); 100 builder.setDefaultBehaviorProvider(provider); 101 builder.addInstanceOf("org.opends.server.loggers.RotationPolicy"); 102 PD_JAVA_CLASS = builder.getInstance(); 103 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 104 } 105 106 107 108 // Register the tags associated with this managed object definition. 109 static { 110 INSTANCE.registerTag(Tag.valueOf("logging")); 111 } 112 113 114 115 /** 116 * Get the Size Limit Log Rotation Policy configuration definition 117 * singleton. 118 * 119 * @return Returns the Size Limit Log Rotation Policy configuration 120 * definition singleton. 121 */ 122 public static SizeLimitLogRotationPolicyCfgDefn getInstance() { 123 return INSTANCE; 124 } 125 126 127 128 /** 129 * Private constructor. 130 */ 131 private SizeLimitLogRotationPolicyCfgDefn() { 132 super("size-limit-log-rotation-policy", LogRotationPolicyCfgDefn.getInstance()); 133 } 134 135 136 137 /** 138 * {@inheritDoc} 139 */ 140 public SizeLimitLogRotationPolicyCfgClient createClientConfiguration( 141 ManagedObject<? extends SizeLimitLogRotationPolicyCfgClient> impl) { 142 return new SizeLimitLogRotationPolicyCfgClientImpl(impl); 143 } 144 145 146 147 /** 148 * {@inheritDoc} 149 */ 150 public SizeLimitLogRotationPolicyCfg createServerConfiguration( 151 ServerManagedObject<? extends SizeLimitLogRotationPolicyCfg> impl) { 152 return new SizeLimitLogRotationPolicyCfgServerImpl(impl); 153 } 154 155 156 157 /** 158 * {@inheritDoc} 159 */ 160 public Class<SizeLimitLogRotationPolicyCfg> getServerConfigurationClass() { 161 return SizeLimitLogRotationPolicyCfg.class; 162 } 163 164 165 166 /** 167 * Get the "file-size-limit" property definition. 168 * <p> 169 * Specifies the maximum size that a log file can reach before it is 170 * rotated. 171 * 172 * @return Returns the "file-size-limit" property definition. 173 */ 174 public SizePropertyDefinition getFileSizeLimitPropertyDefinition() { 175 return PD_FILE_SIZE_LIMIT; 176 } 177 178 179 180 /** 181 * Get the "java-class" property definition. 182 * <p> 183 * Specifies the fully-qualified name of the Java class that 184 * provides the Size Limit Log Rotation Policy implementation. 185 * 186 * @return Returns the "java-class" property definition. 187 */ 188 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 189 return PD_JAVA_CLASS; 190 } 191 192 193 194 /** 195 * Managed object client implementation. 196 */ 197 private static class SizeLimitLogRotationPolicyCfgClientImpl implements 198 SizeLimitLogRotationPolicyCfgClient { 199 200 // Private implementation. 201 private ManagedObject<? extends SizeLimitLogRotationPolicyCfgClient> impl; 202 203 204 205 // Private constructor. 206 private SizeLimitLogRotationPolicyCfgClientImpl( 207 ManagedObject<? extends SizeLimitLogRotationPolicyCfgClient> impl) { 208 this.impl = impl; 209 } 210 211 212 213 /** 214 * {@inheritDoc} 215 */ 216 public Long getFileSizeLimit() { 217 return impl.getPropertyValue(INSTANCE.getFileSizeLimitPropertyDefinition()); 218 } 219 220 221 222 /** 223 * {@inheritDoc} 224 */ 225 public void setFileSizeLimit(long value) { 226 impl.setPropertyValue(INSTANCE.getFileSizeLimitPropertyDefinition(), value); 227 } 228 229 230 231 /** 232 * {@inheritDoc} 233 */ 234 public String getJavaClass() { 235 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 236 } 237 238 239 240 /** 241 * {@inheritDoc} 242 */ 243 public void setJavaClass(String value) { 244 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 245 } 246 247 248 249 /** 250 * {@inheritDoc} 251 */ 252 public ManagedObjectDefinition<? extends SizeLimitLogRotationPolicyCfgClient, ? extends SizeLimitLogRotationPolicyCfg> definition() { 253 return INSTANCE; 254 } 255 256 257 258 /** 259 * {@inheritDoc} 260 */ 261 public PropertyProvider properties() { 262 return impl; 263 } 264 265 266 267 /** 268 * {@inheritDoc} 269 */ 270 public void commit() throws ManagedObjectAlreadyExistsException, 271 MissingMandatoryPropertiesException, ConcurrentModificationException, 272 OperationRejectedException, AuthorizationException, 273 CommunicationException { 274 impl.commit(); 275 } 276 277 } 278 279 280 281 /** 282 * Managed object server implementation. 283 */ 284 private static class SizeLimitLogRotationPolicyCfgServerImpl implements 285 SizeLimitLogRotationPolicyCfg { 286 287 // Private implementation. 288 private ServerManagedObject<? extends SizeLimitLogRotationPolicyCfg> impl; 289 290 // The value of the "file-size-limit" property. 291 private final long pFileSizeLimit; 292 293 // The value of the "java-class" property. 294 private final String pJavaClass; 295 296 297 298 // Private constructor. 299 private SizeLimitLogRotationPolicyCfgServerImpl(ServerManagedObject<? extends SizeLimitLogRotationPolicyCfg> impl) { 300 this.impl = impl; 301 this.pFileSizeLimit = impl.getPropertyValue(INSTANCE.getFileSizeLimitPropertyDefinition()); 302 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 303 } 304 305 306 307 /** 308 * {@inheritDoc} 309 */ 310 public void addSizeLimitChangeListener( 311 ConfigurationChangeListener<SizeLimitLogRotationPolicyCfg> listener) { 312 impl.registerChangeListener(listener); 313 } 314 315 316 317 /** 318 * {@inheritDoc} 319 */ 320 public void removeSizeLimitChangeListener( 321 ConfigurationChangeListener<SizeLimitLogRotationPolicyCfg> listener) { 322 impl.deregisterChangeListener(listener); 323 } 324 /** 325 * {@inheritDoc} 326 */ 327 public void addChangeListener( 328 ConfigurationChangeListener<LogRotationPolicyCfg> listener) { 329 impl.registerChangeListener(listener); 330 } 331 332 333 334 /** 335 * {@inheritDoc} 336 */ 337 public void removeChangeListener( 338 ConfigurationChangeListener<LogRotationPolicyCfg> listener) { 339 impl.deregisterChangeListener(listener); 340 } 341 342 343 344 /** 345 * {@inheritDoc} 346 */ 347 public long getFileSizeLimit() { 348 return pFileSizeLimit; 349 } 350 351 352 353 /** 354 * {@inheritDoc} 355 */ 356 public String getJavaClass() { 357 return pJavaClass; 358 } 359 360 361 362 /** 363 * {@inheritDoc} 364 */ 365 public Class<? extends SizeLimitLogRotationPolicyCfg> configurationClass() { 366 return SizeLimitLogRotationPolicyCfg.class; 367 } 368 369 370 371 /** 372 * {@inheritDoc} 373 */ 374 public DN dn() { 375 return impl.getDN(); 376 } 377 378 } 379 }