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 legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2008 Sun Microsystems, Inc. 025 */ 026package org.forgerock.opendj.server.config.meta; 027 028 029 030import org.forgerock.opendj.config.AdministratorAction; 031import org.forgerock.opendj.config.BooleanPropertyDefinition; 032import org.forgerock.opendj.config.ClassPropertyDefinition; 033import org.forgerock.opendj.config.client.ConcurrentModificationException; 034import org.forgerock.opendj.config.client.ManagedObject; 035import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 036import org.forgerock.opendj.config.client.OperationRejectedException; 037import org.forgerock.opendj.config.IntegerPropertyDefinition; 038import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 039import org.forgerock.opendj.config.ManagedObjectDefinition; 040import org.forgerock.opendj.config.PropertyOption; 041import org.forgerock.opendj.config.PropertyProvider; 042import org.forgerock.opendj.config.server.ConfigurationChangeListener; 043import org.forgerock.opendj.config.server.ServerManagedObject; 044import org.forgerock.opendj.config.Tag; 045import org.forgerock.opendj.config.TopCfgDefn; 046import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider; 047import org.forgerock.opendj.ldap.DN; 048import org.forgerock.opendj.ldap.LdapException; 049import org.forgerock.opendj.server.config.client.EntryCacheCfgClient; 050import org.forgerock.opendj.server.config.server.EntryCacheCfg; 051 052 053 054/** 055 * An interface for querying the Entry Cache managed object definition 056 * meta information. 057 * <p> 058 * Entry Caches are responsible for caching entries which are likely 059 * to be accessed by client applications in order to improve OpenDJ 060 * directory server performance. 061 */ 062public final class EntryCacheCfgDefn extends ManagedObjectDefinition<EntryCacheCfgClient, EntryCacheCfg> { 063 064 /** The singleton configuration definition instance. */ 065 private static final EntryCacheCfgDefn INSTANCE = new EntryCacheCfgDefn(); 066 067 068 069 /** The "cache-level" property definition. */ 070 private static final IntegerPropertyDefinition PD_CACHE_LEVEL; 071 072 073 074 /** The "enabled" property definition. */ 075 private static final BooleanPropertyDefinition PD_ENABLED; 076 077 078 079 /** The "java-class" property definition. */ 080 private static final ClassPropertyDefinition PD_JAVA_CLASS; 081 082 083 084 /** Build the "cache-level" property definition. */ 085 static { 086 IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "cache-level"); 087 builder.setOption(PropertyOption.MANDATORY); 088 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "cache-level")); 089 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Integer>()); 090 builder.setLowerLimit(1); 091 PD_CACHE_LEVEL = builder.getInstance(); 092 INSTANCE.registerPropertyDefinition(PD_CACHE_LEVEL); 093 } 094 095 096 097 /** Build the "enabled" property definition. */ 098 static { 099 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled"); 100 builder.setOption(PropertyOption.MANDATORY); 101 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled")); 102 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>()); 103 PD_ENABLED = builder.getInstance(); 104 INSTANCE.registerPropertyDefinition(PD_ENABLED); 105 } 106 107 108 109 /** Build the "java-class" property definition. */ 110 static { 111 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 112 builder.setOption(PropertyOption.MANDATORY); 113 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class")); 114 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 115 builder.addInstanceOf("org.opends.server.api.EntryCache"); 116 PD_JAVA_CLASS = builder.getInstance(); 117 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 118 } 119 120 121 122 // Register the tags associated with this managed object definition. 123 static { 124 INSTANCE.registerTag(Tag.valueOf("database")); 125 } 126 127 128 129 /** 130 * Get the Entry Cache configuration definition singleton. 131 * 132 * @return Returns the Entry Cache configuration definition 133 * singleton. 134 */ 135 public static EntryCacheCfgDefn getInstance() { 136 return INSTANCE; 137 } 138 139 140 141 /** 142 * Private constructor. 143 */ 144 private EntryCacheCfgDefn() { 145 super("entry-cache", TopCfgDefn.getInstance()); 146 } 147 148 149 150 /** {@inheritDoc} */ 151 public EntryCacheCfgClient createClientConfiguration( 152 ManagedObject<? extends EntryCacheCfgClient> impl) { 153 return new EntryCacheCfgClientImpl(impl); 154 } 155 156 157 158 /** {@inheritDoc} */ 159 public EntryCacheCfg createServerConfiguration( 160 ServerManagedObject<? extends EntryCacheCfg> impl) { 161 return new EntryCacheCfgServerImpl(impl); 162 } 163 164 165 166 /** {@inheritDoc} */ 167 public Class<EntryCacheCfg> getServerConfigurationClass() { 168 return EntryCacheCfg.class; 169 } 170 171 172 173 /** 174 * Get the "cache-level" property definition. 175 * <p> 176 * Specifies the cache level in the cache order if more than one 177 * instance of the cache is configured. 178 * 179 * @return Returns the "cache-level" property definition. 180 */ 181 public IntegerPropertyDefinition getCacheLevelPropertyDefinition() { 182 return PD_CACHE_LEVEL; 183 } 184 185 186 187 /** 188 * Get the "enabled" property definition. 189 * <p> 190 * Indicates whether the Entry Cache is enabled. 191 * 192 * @return Returns the "enabled" property definition. 193 */ 194 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 195 return PD_ENABLED; 196 } 197 198 199 200 /** 201 * Get the "java-class" property definition. 202 * <p> 203 * Specifies the fully-qualified name of the Java class that 204 * provides the Entry Cache implementation. 205 * 206 * @return Returns the "java-class" property definition. 207 */ 208 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 209 return PD_JAVA_CLASS; 210 } 211 212 213 214 /** 215 * Managed object client implementation. 216 */ 217 private static class EntryCacheCfgClientImpl implements 218 EntryCacheCfgClient { 219 220 /** Private implementation. */ 221 private ManagedObject<? extends EntryCacheCfgClient> impl; 222 223 224 225 /** Private constructor. */ 226 private EntryCacheCfgClientImpl( 227 ManagedObject<? extends EntryCacheCfgClient> impl) { 228 this.impl = impl; 229 } 230 231 232 233 /** {@inheritDoc} */ 234 public Integer getCacheLevel() { 235 return impl.getPropertyValue(INSTANCE.getCacheLevelPropertyDefinition()); 236 } 237 238 239 240 /** {@inheritDoc} */ 241 public void setCacheLevel(int value) { 242 impl.setPropertyValue(INSTANCE.getCacheLevelPropertyDefinition(), value); 243 } 244 245 246 247 /** {@inheritDoc} */ 248 public Boolean isEnabled() { 249 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 250 } 251 252 253 254 /** {@inheritDoc} */ 255 public void setEnabled(boolean value) { 256 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 257 } 258 259 260 261 /** {@inheritDoc} */ 262 public String getJavaClass() { 263 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 264 } 265 266 267 268 /** {@inheritDoc} */ 269 public void setJavaClass(String value) { 270 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 271 } 272 273 274 275 /** {@inheritDoc} */ 276 public ManagedObjectDefinition<? extends EntryCacheCfgClient, ? extends EntryCacheCfg> definition() { 277 return INSTANCE; 278 } 279 280 281 282 /** {@inheritDoc} */ 283 public PropertyProvider properties() { 284 return impl; 285 } 286 287 288 289 /** {@inheritDoc} */ 290 public void commit() throws ManagedObjectAlreadyExistsException, 291 MissingMandatoryPropertiesException, ConcurrentModificationException, 292 OperationRejectedException, LdapException { 293 impl.commit(); 294 } 295 296 297 298 /** {@inheritDoc} */ 299 public String toString() { 300 return impl.toString(); 301 } 302 } 303 304 305 306 /** 307 * Managed object server implementation. 308 */ 309 private static class EntryCacheCfgServerImpl implements 310 EntryCacheCfg { 311 312 /** Private implementation. */ 313 private ServerManagedObject<? extends EntryCacheCfg> impl; 314 315 /** The value of the "cache-level" property. */ 316 private final int pCacheLevel; 317 318 /** The value of the "enabled" property. */ 319 private final boolean pEnabled; 320 321 /** The value of the "java-class" property. */ 322 private final String pJavaClass; 323 324 325 326 /** Private constructor. */ 327 private EntryCacheCfgServerImpl(ServerManagedObject<? extends EntryCacheCfg> impl) { 328 this.impl = impl; 329 this.pCacheLevel = impl.getPropertyValue(INSTANCE.getCacheLevelPropertyDefinition()); 330 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 331 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 332 } 333 334 335 336 /** {@inheritDoc} */ 337 public void addChangeListener( 338 ConfigurationChangeListener<EntryCacheCfg> listener) { 339 impl.registerChangeListener(listener); 340 } 341 342 343 344 /** {@inheritDoc} */ 345 public void removeChangeListener( 346 ConfigurationChangeListener<EntryCacheCfg> listener) { 347 impl.deregisterChangeListener(listener); 348 } 349 350 351 352 /** {@inheritDoc} */ 353 public int getCacheLevel() { 354 return pCacheLevel; 355 } 356 357 358 359 /** {@inheritDoc} */ 360 public boolean isEnabled() { 361 return pEnabled; 362 } 363 364 365 366 /** {@inheritDoc} */ 367 public String getJavaClass() { 368 return pJavaClass; 369 } 370 371 372 373 /** {@inheritDoc} */ 374 public Class<? extends EntryCacheCfg> configurationClass() { 375 return EntryCacheCfg.class; 376 } 377 378 379 380 /** {@inheritDoc} */ 381 public DN dn() { 382 return impl.getDN(); 383 } 384 385 386 387 /** {@inheritDoc} */ 388 public String toString() { 389 return impl.toString(); 390 } 391 } 392}