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