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.DurationPropertyDefinition; 042 import org.opends.server.admin.ManagedObjectAlreadyExistsException; 043 import org.opends.server.admin.ManagedObjectDefinition; 044 import org.opends.server.admin.PropertyOption; 045 import org.opends.server.admin.PropertyProvider; 046 import org.opends.server.admin.server.ConfigurationChangeListener; 047 import org.opends.server.admin.server.ServerManagedObject; 048 import org.opends.server.admin.std.client.TimeLimitLogRotationPolicyCfgClient; 049 import org.opends.server.admin.std.server.LogRotationPolicyCfg; 050 import org.opends.server.admin.std.server.TimeLimitLogRotationPolicyCfg; 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 Time Limit Log Rotation Policy 059 * managed object definition meta information. 060 * <p> 061 * Rotation policy based on the time since last rotation. 062 */ 063 public final class TimeLimitLogRotationPolicyCfgDefn extends ManagedObjectDefinition<TimeLimitLogRotationPolicyCfgClient, TimeLimitLogRotationPolicyCfg> { 064 065 // The singleton configuration definition instance. 066 private static final TimeLimitLogRotationPolicyCfgDefn INSTANCE = new TimeLimitLogRotationPolicyCfgDefn(); 067 068 069 070 // The "java-class" property definition. 071 private static final ClassPropertyDefinition PD_JAVA_CLASS; 072 073 074 075 // The "rotation-interval" property definition. 076 private static final DurationPropertyDefinition PD_ROTATION_INTERVAL; 077 078 079 080 // Build the "java-class" property definition. 081 static { 082 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 083 builder.setOption(PropertyOption.MANDATORY); 084 builder.setOption(PropertyOption.ADVANCED); 085 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class")); 086 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.loggers.TimeLimitRotationPolicy"); 087 builder.setDefaultBehaviorProvider(provider); 088 builder.addInstanceOf("org.opends.server.loggers.RotationPolicy"); 089 PD_JAVA_CLASS = builder.getInstance(); 090 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 091 } 092 093 094 095 // Build the "rotation-interval" property definition. 096 static { 097 DurationPropertyDefinition.Builder builder = DurationPropertyDefinition.createBuilder(INSTANCE, "rotation-interval"); 098 builder.setOption(PropertyOption.MANDATORY); 099 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "rotation-interval")); 100 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Long>()); 101 builder.setBaseUnit("ms"); 102 builder.setLowerLimit("1"); 103 PD_ROTATION_INTERVAL = builder.getInstance(); 104 INSTANCE.registerPropertyDefinition(PD_ROTATION_INTERVAL); 105 } 106 107 108 109 // Register the tags associated with this managed object definition. 110 static { 111 INSTANCE.registerTag(Tag.valueOf("logging")); 112 } 113 114 115 116 /** 117 * Get the Time Limit Log Rotation Policy configuration definition 118 * singleton. 119 * 120 * @return Returns the Time Limit Log Rotation Policy configuration 121 * definition singleton. 122 */ 123 public static TimeLimitLogRotationPolicyCfgDefn getInstance() { 124 return INSTANCE; 125 } 126 127 128 129 /** 130 * Private constructor. 131 */ 132 private TimeLimitLogRotationPolicyCfgDefn() { 133 super("time-limit-log-rotation-policy", LogRotationPolicyCfgDefn.getInstance()); 134 } 135 136 137 138 /** 139 * {@inheritDoc} 140 */ 141 public TimeLimitLogRotationPolicyCfgClient createClientConfiguration( 142 ManagedObject<? extends TimeLimitLogRotationPolicyCfgClient> impl) { 143 return new TimeLimitLogRotationPolicyCfgClientImpl(impl); 144 } 145 146 147 148 /** 149 * {@inheritDoc} 150 */ 151 public TimeLimitLogRotationPolicyCfg createServerConfiguration( 152 ServerManagedObject<? extends TimeLimitLogRotationPolicyCfg> impl) { 153 return new TimeLimitLogRotationPolicyCfgServerImpl(impl); 154 } 155 156 157 158 /** 159 * {@inheritDoc} 160 */ 161 public Class<TimeLimitLogRotationPolicyCfg> getServerConfigurationClass() { 162 return TimeLimitLogRotationPolicyCfg.class; 163 } 164 165 166 167 /** 168 * Get the "java-class" property definition. 169 * <p> 170 * Specifies the fully-qualified name of the Java class that 171 * provides the Time Limit Log Rotation Policy implementation. 172 * 173 * @return Returns the "java-class" property definition. 174 */ 175 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 176 return PD_JAVA_CLASS; 177 } 178 179 180 181 /** 182 * Get the "rotation-interval" property definition. 183 * <p> 184 * Specifies the time interval between rotations. 185 * 186 * @return Returns the "rotation-interval" property definition. 187 */ 188 public DurationPropertyDefinition getRotationIntervalPropertyDefinition() { 189 return PD_ROTATION_INTERVAL; 190 } 191 192 193 194 /** 195 * Managed object client implementation. 196 */ 197 private static class TimeLimitLogRotationPolicyCfgClientImpl implements 198 TimeLimitLogRotationPolicyCfgClient { 199 200 // Private implementation. 201 private ManagedObject<? extends TimeLimitLogRotationPolicyCfgClient> impl; 202 203 204 205 // Private constructor. 206 private TimeLimitLogRotationPolicyCfgClientImpl( 207 ManagedObject<? extends TimeLimitLogRotationPolicyCfgClient> impl) { 208 this.impl = impl; 209 } 210 211 212 213 /** 214 * {@inheritDoc} 215 */ 216 public String getJavaClass() { 217 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 218 } 219 220 221 222 /** 223 * {@inheritDoc} 224 */ 225 public void setJavaClass(String value) { 226 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 227 } 228 229 230 231 /** 232 * {@inheritDoc} 233 */ 234 public Long getRotationInterval() { 235 return impl.getPropertyValue(INSTANCE.getRotationIntervalPropertyDefinition()); 236 } 237 238 239 240 /** 241 * {@inheritDoc} 242 */ 243 public void setRotationInterval(long value) { 244 impl.setPropertyValue(INSTANCE.getRotationIntervalPropertyDefinition(), value); 245 } 246 247 248 249 /** 250 * {@inheritDoc} 251 */ 252 public ManagedObjectDefinition<? extends TimeLimitLogRotationPolicyCfgClient, ? extends TimeLimitLogRotationPolicyCfg> 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 TimeLimitLogRotationPolicyCfgServerImpl implements 285 TimeLimitLogRotationPolicyCfg { 286 287 // Private implementation. 288 private ServerManagedObject<? extends TimeLimitLogRotationPolicyCfg> impl; 289 290 // The value of the "java-class" property. 291 private final String pJavaClass; 292 293 // The value of the "rotation-interval" property. 294 private final long pRotationInterval; 295 296 297 298 // Private constructor. 299 private TimeLimitLogRotationPolicyCfgServerImpl(ServerManagedObject<? extends TimeLimitLogRotationPolicyCfg> impl) { 300 this.impl = impl; 301 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 302 this.pRotationInterval = impl.getPropertyValue(INSTANCE.getRotationIntervalPropertyDefinition()); 303 } 304 305 306 307 /** 308 * {@inheritDoc} 309 */ 310 public void addTimeLimitChangeListener( 311 ConfigurationChangeListener<TimeLimitLogRotationPolicyCfg> listener) { 312 impl.registerChangeListener(listener); 313 } 314 315 316 317 /** 318 * {@inheritDoc} 319 */ 320 public void removeTimeLimitChangeListener( 321 ConfigurationChangeListener<TimeLimitLogRotationPolicyCfg> 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 String getJavaClass() { 348 return pJavaClass; 349 } 350 351 352 353 /** 354 * {@inheritDoc} 355 */ 356 public long getRotationInterval() { 357 return pRotationInterval; 358 } 359 360 361 362 /** 363 * {@inheritDoc} 364 */ 365 public Class<? extends TimeLimitLogRotationPolicyCfg> configurationClass() { 366 return TimeLimitLogRotationPolicyCfg.class; 367 } 368 369 370 371 /** 372 * {@inheritDoc} 373 */ 374 public DN dn() { 375 return impl.getDN(); 376 } 377 378 } 379 }