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 java.util.Collection; 031import java.util.SortedSet; 032import org.forgerock.opendj.config.AdministratorAction; 033import org.forgerock.opendj.config.BooleanPropertyDefinition; 034import org.forgerock.opendj.config.ClassPropertyDefinition; 035import org.forgerock.opendj.config.client.ConcurrentModificationException; 036import org.forgerock.opendj.config.client.ManagedObject; 037import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 038import org.forgerock.opendj.config.client.OperationRejectedException; 039import org.forgerock.opendj.config.DefaultBehaviorProvider; 040import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; 041import org.forgerock.opendj.config.DurationPropertyDefinition; 042import org.forgerock.opendj.config.IntegerPropertyDefinition; 043import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 044import org.forgerock.opendj.config.ManagedObjectDefinition; 045import org.forgerock.opendj.config.PropertyOption; 046import org.forgerock.opendj.config.PropertyProvider; 047import org.forgerock.opendj.config.server.ConfigurationChangeListener; 048import org.forgerock.opendj.config.server.ServerManagedObject; 049import org.forgerock.opendj.config.StringPropertyDefinition; 050import org.forgerock.opendj.config.Tag; 051import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider; 052import org.forgerock.opendj.ldap.DN; 053import org.forgerock.opendj.ldap.LdapException; 054import org.forgerock.opendj.server.config.client.SoftReferenceEntryCacheCfgClient; 055import org.forgerock.opendj.server.config.server.EntryCacheCfg; 056import org.forgerock.opendj.server.config.server.SoftReferenceEntryCacheCfg; 057 058 059 060/** 061 * An interface for querying the Soft Reference Entry Cache managed 062 * object definition meta information. 063 * <p> 064 * The Soft Reference Entry Cache is a directory server entry cache 065 * implementation that uses soft references to manage objects to allow 066 * them to be freed if the JVM is running low on memory. 067 */ 068public final class SoftReferenceEntryCacheCfgDefn extends ManagedObjectDefinition<SoftReferenceEntryCacheCfgClient, SoftReferenceEntryCacheCfg> { 069 070 /** The singleton configuration definition instance. */ 071 private static final SoftReferenceEntryCacheCfgDefn INSTANCE = new SoftReferenceEntryCacheCfgDefn(); 072 073 074 075 /** The "exclude-filter" property definition. */ 076 private static final StringPropertyDefinition PD_EXCLUDE_FILTER; 077 078 079 080 /** The "include-filter" property definition. */ 081 private static final StringPropertyDefinition PD_INCLUDE_FILTER; 082 083 084 085 /** The "java-class" property definition. */ 086 private static final ClassPropertyDefinition PD_JAVA_CLASS; 087 088 089 090 /** The "lock-timeout" property definition. */ 091 private static final DurationPropertyDefinition PD_LOCK_TIMEOUT; 092 093 094 095 /** Build the "exclude-filter" property definition. */ 096 static { 097 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "exclude-filter"); 098 builder.setOption(PropertyOption.MULTI_VALUED); 099 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "exclude-filter")); 100 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 101 PD_EXCLUDE_FILTER = builder.getInstance(); 102 INSTANCE.registerPropertyDefinition(PD_EXCLUDE_FILTER); 103 } 104 105 106 107 /** Build the "include-filter" property definition. */ 108 static { 109 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "include-filter"); 110 builder.setOption(PropertyOption.MULTI_VALUED); 111 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "include-filter")); 112 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 113 PD_INCLUDE_FILTER = builder.getInstance(); 114 INSTANCE.registerPropertyDefinition(PD_INCLUDE_FILTER); 115 } 116 117 118 119 /** Build the "java-class" property definition. */ 120 static { 121 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 122 builder.setOption(PropertyOption.MANDATORY); 123 builder.setOption(PropertyOption.ADVANCED); 124 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class")); 125 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.SoftReferenceEntryCache"); 126 builder.setDefaultBehaviorProvider(provider); 127 builder.addInstanceOf("org.opends.server.api.EntryCache"); 128 PD_JAVA_CLASS = builder.getInstance(); 129 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 130 } 131 132 133 134 /** Build the "lock-timeout" property definition. */ 135 static { 136 DurationPropertyDefinition.Builder builder = DurationPropertyDefinition.createBuilder(INSTANCE, "lock-timeout"); 137 builder.setOption(PropertyOption.ADVANCED); 138 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "lock-timeout")); 139 DefaultBehaviorProvider<Long> provider = new DefinedDefaultBehaviorProvider<Long>("3000ms"); 140 builder.setDefaultBehaviorProvider(provider); 141 builder.setAllowUnlimited(true); 142 builder.setBaseUnit("ms"); 143 builder.setLowerLimit("0"); 144 PD_LOCK_TIMEOUT = builder.getInstance(); 145 INSTANCE.registerPropertyDefinition(PD_LOCK_TIMEOUT); 146 } 147 148 149 150 // Register the tags associated with this managed object definition. 151 static { 152 INSTANCE.registerTag(Tag.valueOf("database")); 153 } 154 155 156 157 /** 158 * Get the Soft Reference Entry Cache configuration definition 159 * singleton. 160 * 161 * @return Returns the Soft Reference Entry Cache configuration 162 * definition singleton. 163 */ 164 public static SoftReferenceEntryCacheCfgDefn getInstance() { 165 return INSTANCE; 166 } 167 168 169 170 /** 171 * Private constructor. 172 */ 173 private SoftReferenceEntryCacheCfgDefn() { 174 super("soft-reference-entry-cache", EntryCacheCfgDefn.getInstance()); 175 } 176 177 178 179 /** {@inheritDoc} */ 180 public SoftReferenceEntryCacheCfgClient createClientConfiguration( 181 ManagedObject<? extends SoftReferenceEntryCacheCfgClient> impl) { 182 return new SoftReferenceEntryCacheCfgClientImpl(impl); 183 } 184 185 186 187 /** {@inheritDoc} */ 188 public SoftReferenceEntryCacheCfg createServerConfiguration( 189 ServerManagedObject<? extends SoftReferenceEntryCacheCfg> impl) { 190 return new SoftReferenceEntryCacheCfgServerImpl(impl); 191 } 192 193 194 195 /** {@inheritDoc} */ 196 public Class<SoftReferenceEntryCacheCfg> getServerConfigurationClass() { 197 return SoftReferenceEntryCacheCfg.class; 198 } 199 200 201 202 /** 203 * Get the "cache-level" property definition. 204 * <p> 205 * Specifies the cache level in the cache order if more than one 206 * instance of the cache is configured. 207 * 208 * @return Returns the "cache-level" property definition. 209 */ 210 public IntegerPropertyDefinition getCacheLevelPropertyDefinition() { 211 return EntryCacheCfgDefn.getInstance().getCacheLevelPropertyDefinition(); 212 } 213 214 215 216 /** 217 * Get the "enabled" property definition. 218 * <p> 219 * Indicates whether the Soft Reference Entry Cache is enabled. 220 * 221 * @return Returns the "enabled" property definition. 222 */ 223 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 224 return EntryCacheCfgDefn.getInstance().getEnabledPropertyDefinition(); 225 } 226 227 228 229 /** 230 * Get the "exclude-filter" property definition. 231 * <p> 232 * The set of filters that define the entries that should be 233 * excluded from the cache. 234 * 235 * @return Returns the "exclude-filter" property definition. 236 */ 237 public StringPropertyDefinition getExcludeFilterPropertyDefinition() { 238 return PD_EXCLUDE_FILTER; 239 } 240 241 242 243 /** 244 * Get the "include-filter" property definition. 245 * <p> 246 * The set of filters that define the entries that should be 247 * included in the cache. 248 * 249 * @return Returns the "include-filter" property definition. 250 */ 251 public StringPropertyDefinition getIncludeFilterPropertyDefinition() { 252 return PD_INCLUDE_FILTER; 253 } 254 255 256 257 /** 258 * Get the "java-class" property definition. 259 * <p> 260 * Specifies the fully-qualified name of the Java class that 261 * provides the Soft Reference Entry Cache implementation. 262 * 263 * @return Returns the "java-class" property definition. 264 */ 265 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 266 return PD_JAVA_CLASS; 267 } 268 269 270 271 /** 272 * Get the "lock-timeout" property definition. 273 * <p> 274 * Specifies the length of time in milliseconds to wait while 275 * attempting to acquire a read or write lock. 276 * 277 * @return Returns the "lock-timeout" property definition. 278 */ 279 public DurationPropertyDefinition getLockTimeoutPropertyDefinition() { 280 return PD_LOCK_TIMEOUT; 281 } 282 283 284 285 /** 286 * Managed object client implementation. 287 */ 288 private static class SoftReferenceEntryCacheCfgClientImpl implements 289 SoftReferenceEntryCacheCfgClient { 290 291 /** Private implementation. */ 292 private ManagedObject<? extends SoftReferenceEntryCacheCfgClient> impl; 293 294 295 296 /** Private constructor. */ 297 private SoftReferenceEntryCacheCfgClientImpl( 298 ManagedObject<? extends SoftReferenceEntryCacheCfgClient> impl) { 299 this.impl = impl; 300 } 301 302 303 304 /** {@inheritDoc} */ 305 public Integer getCacheLevel() { 306 return impl.getPropertyValue(INSTANCE.getCacheLevelPropertyDefinition()); 307 } 308 309 310 311 /** {@inheritDoc} */ 312 public void setCacheLevel(int value) { 313 impl.setPropertyValue(INSTANCE.getCacheLevelPropertyDefinition(), value); 314 } 315 316 317 318 /** {@inheritDoc} */ 319 public Boolean isEnabled() { 320 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 321 } 322 323 324 325 /** {@inheritDoc} */ 326 public void setEnabled(boolean value) { 327 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 328 } 329 330 331 332 /** {@inheritDoc} */ 333 public SortedSet<String> getExcludeFilter() { 334 return impl.getPropertyValues(INSTANCE.getExcludeFilterPropertyDefinition()); 335 } 336 337 338 339 /** {@inheritDoc} */ 340 public void setExcludeFilter(Collection<String> values) { 341 impl.setPropertyValues(INSTANCE.getExcludeFilterPropertyDefinition(), values); 342 } 343 344 345 346 /** {@inheritDoc} */ 347 public SortedSet<String> getIncludeFilter() { 348 return impl.getPropertyValues(INSTANCE.getIncludeFilterPropertyDefinition()); 349 } 350 351 352 353 /** {@inheritDoc} */ 354 public void setIncludeFilter(Collection<String> values) { 355 impl.setPropertyValues(INSTANCE.getIncludeFilterPropertyDefinition(), values); 356 } 357 358 359 360 /** {@inheritDoc} */ 361 public String getJavaClass() { 362 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 363 } 364 365 366 367 /** {@inheritDoc} */ 368 public void setJavaClass(String value) { 369 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 370 } 371 372 373 374 /** {@inheritDoc} */ 375 public long getLockTimeout() { 376 return impl.getPropertyValue(INSTANCE.getLockTimeoutPropertyDefinition()); 377 } 378 379 380 381 /** {@inheritDoc} */ 382 public void setLockTimeout(Long value) { 383 impl.setPropertyValue(INSTANCE.getLockTimeoutPropertyDefinition(), value); 384 } 385 386 387 388 /** {@inheritDoc} */ 389 public ManagedObjectDefinition<? extends SoftReferenceEntryCacheCfgClient, ? extends SoftReferenceEntryCacheCfg> definition() { 390 return INSTANCE; 391 } 392 393 394 395 /** {@inheritDoc} */ 396 public PropertyProvider properties() { 397 return impl; 398 } 399 400 401 402 /** {@inheritDoc} */ 403 public void commit() throws ManagedObjectAlreadyExistsException, 404 MissingMandatoryPropertiesException, ConcurrentModificationException, 405 OperationRejectedException, LdapException { 406 impl.commit(); 407 } 408 409 410 411 /** {@inheritDoc} */ 412 public String toString() { 413 return impl.toString(); 414 } 415 } 416 417 418 419 /** 420 * Managed object server implementation. 421 */ 422 private static class SoftReferenceEntryCacheCfgServerImpl implements 423 SoftReferenceEntryCacheCfg { 424 425 /** Private implementation. */ 426 private ServerManagedObject<? extends SoftReferenceEntryCacheCfg> impl; 427 428 /** The value of the "cache-level" property. */ 429 private final int pCacheLevel; 430 431 /** The value of the "enabled" property. */ 432 private final boolean pEnabled; 433 434 /** The value of the "exclude-filter" property. */ 435 private final SortedSet<String> pExcludeFilter; 436 437 /** The value of the "include-filter" property. */ 438 private final SortedSet<String> pIncludeFilter; 439 440 /** The value of the "java-class" property. */ 441 private final String pJavaClass; 442 443 /** The value of the "lock-timeout" property. */ 444 private final long pLockTimeout; 445 446 447 448 /** Private constructor. */ 449 private SoftReferenceEntryCacheCfgServerImpl(ServerManagedObject<? extends SoftReferenceEntryCacheCfg> impl) { 450 this.impl = impl; 451 this.pCacheLevel = impl.getPropertyValue(INSTANCE.getCacheLevelPropertyDefinition()); 452 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 453 this.pExcludeFilter = impl.getPropertyValues(INSTANCE.getExcludeFilterPropertyDefinition()); 454 this.pIncludeFilter = impl.getPropertyValues(INSTANCE.getIncludeFilterPropertyDefinition()); 455 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 456 this.pLockTimeout = impl.getPropertyValue(INSTANCE.getLockTimeoutPropertyDefinition()); 457 } 458 459 460 461 /** {@inheritDoc} */ 462 public void addSoftReferenceChangeListener( 463 ConfigurationChangeListener<SoftReferenceEntryCacheCfg> listener) { 464 impl.registerChangeListener(listener); 465 } 466 467 468 469 /** {@inheritDoc} */ 470 public void removeSoftReferenceChangeListener( 471 ConfigurationChangeListener<SoftReferenceEntryCacheCfg> listener) { 472 impl.deregisterChangeListener(listener); 473 } 474 /** {@inheritDoc} */ 475 public void addChangeListener( 476 ConfigurationChangeListener<EntryCacheCfg> listener) { 477 impl.registerChangeListener(listener); 478 } 479 480 481 482 /** {@inheritDoc} */ 483 public void removeChangeListener( 484 ConfigurationChangeListener<EntryCacheCfg> listener) { 485 impl.deregisterChangeListener(listener); 486 } 487 488 489 490 /** {@inheritDoc} */ 491 public int getCacheLevel() { 492 return pCacheLevel; 493 } 494 495 496 497 /** {@inheritDoc} */ 498 public boolean isEnabled() { 499 return pEnabled; 500 } 501 502 503 504 /** {@inheritDoc} */ 505 public SortedSet<String> getExcludeFilter() { 506 return pExcludeFilter; 507 } 508 509 510 511 /** {@inheritDoc} */ 512 public SortedSet<String> getIncludeFilter() { 513 return pIncludeFilter; 514 } 515 516 517 518 /** {@inheritDoc} */ 519 public String getJavaClass() { 520 return pJavaClass; 521 } 522 523 524 525 /** {@inheritDoc} */ 526 public long getLockTimeout() { 527 return pLockTimeout; 528 } 529 530 531 532 /** {@inheritDoc} */ 533 public Class<? extends SoftReferenceEntryCacheCfg> configurationClass() { 534 return SoftReferenceEntryCacheCfg.class; 535 } 536 537 538 539 /** {@inheritDoc} */ 540 public DN dn() { 541 return impl.getDN(); 542 } 543 544 545 546 /** {@inheritDoc} */ 547 public String toString() { 548 return impl.toString(); 549 } 550 } 551}