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