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.forgerock.opendj.server.config.meta; 017 018 019 020import java.util.Collection; 021import java.util.SortedSet; 022import org.forgerock.opendj.config.AdministratorAction; 023import org.forgerock.opendj.config.BooleanPropertyDefinition; 024import org.forgerock.opendj.config.ClassPropertyDefinition; 025import org.forgerock.opendj.config.client.ConcurrentModificationException; 026import org.forgerock.opendj.config.client.ManagedObject; 027import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 028import org.forgerock.opendj.config.client.OperationRejectedException; 029import org.forgerock.opendj.config.DefaultBehaviorProvider; 030import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; 031import org.forgerock.opendj.config.DurationPropertyDefinition; 032import org.forgerock.opendj.config.IntegerPropertyDefinition; 033import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 034import org.forgerock.opendj.config.ManagedObjectDefinition; 035import org.forgerock.opendj.config.PropertyOption; 036import org.forgerock.opendj.config.PropertyProvider; 037import org.forgerock.opendj.config.server.ConfigurationChangeListener; 038import org.forgerock.opendj.config.server.ServerManagedObject; 039import org.forgerock.opendj.config.StringPropertyDefinition; 040import org.forgerock.opendj.config.Tag; 041import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider; 042import org.forgerock.opendj.ldap.DN; 043import org.forgerock.opendj.ldap.LdapException; 044import org.forgerock.opendj.server.config.client.FIFOEntryCacheCfgClient; 045import org.forgerock.opendj.server.config.server.EntryCacheCfg; 046import org.forgerock.opendj.server.config.server.FIFOEntryCacheCfg; 047 048 049 050/** 051 * An interface for querying the FIFO Entry Cache managed object 052 * definition meta information. 053 * <p> 054 * FIFO Entry Caches use a FIFO queue to keep track of the cached 055 * entries. 056 */ 057public final class FIFOEntryCacheCfgDefn extends ManagedObjectDefinition<FIFOEntryCacheCfgClient, FIFOEntryCacheCfg> { 058 059 /** The singleton configuration definition instance. */ 060 private static final FIFOEntryCacheCfgDefn INSTANCE = new FIFOEntryCacheCfgDefn(); 061 062 063 064 /** The "exclude-filter" property definition. */ 065 private static final StringPropertyDefinition PD_EXCLUDE_FILTER; 066 067 068 069 /** The "include-filter" property definition. */ 070 private static final StringPropertyDefinition PD_INCLUDE_FILTER; 071 072 073 074 /** The "java-class" property definition. */ 075 private static final ClassPropertyDefinition PD_JAVA_CLASS; 076 077 078 079 /** The "lock-timeout" property definition. */ 080 private static final DurationPropertyDefinition PD_LOCK_TIMEOUT; 081 082 083 084 /** The "max-entries" property definition. */ 085 private static final IntegerPropertyDefinition PD_MAX_ENTRIES; 086 087 088 089 /** The "max-memory-percent" property definition. */ 090 private static final IntegerPropertyDefinition PD_MAX_MEMORY_PERCENT; 091 092 093 094 /** Build the "exclude-filter" property definition. */ 095 static { 096 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "exclude-filter"); 097 builder.setOption(PropertyOption.MULTI_VALUED); 098 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "exclude-filter")); 099 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 100 PD_EXCLUDE_FILTER = builder.getInstance(); 101 INSTANCE.registerPropertyDefinition(PD_EXCLUDE_FILTER); 102 } 103 104 105 106 /** Build the "include-filter" property definition. */ 107 static { 108 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "include-filter"); 109 builder.setOption(PropertyOption.MULTI_VALUED); 110 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "include-filter")); 111 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 112 PD_INCLUDE_FILTER = builder.getInstance(); 113 INSTANCE.registerPropertyDefinition(PD_INCLUDE_FILTER); 114 } 115 116 117 118 /** Build the "java-class" property definition. */ 119 static { 120 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 121 builder.setOption(PropertyOption.MANDATORY); 122 builder.setOption(PropertyOption.ADVANCED); 123 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class")); 124 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.FIFOEntryCache"); 125 builder.setDefaultBehaviorProvider(provider); 126 builder.addInstanceOf("org.opends.server.api.EntryCache"); 127 PD_JAVA_CLASS = builder.getInstance(); 128 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 129 } 130 131 132 133 /** Build the "lock-timeout" property definition. */ 134 static { 135 DurationPropertyDefinition.Builder builder = DurationPropertyDefinition.createBuilder(INSTANCE, "lock-timeout"); 136 builder.setOption(PropertyOption.ADVANCED); 137 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "lock-timeout")); 138 DefaultBehaviorProvider<Long> provider = new DefinedDefaultBehaviorProvider<Long>("2000.0ms"); 139 builder.setDefaultBehaviorProvider(provider); 140 builder.setAllowUnlimited(true); 141 builder.setBaseUnit("ms"); 142 builder.setLowerLimit("0"); 143 PD_LOCK_TIMEOUT = builder.getInstance(); 144 INSTANCE.registerPropertyDefinition(PD_LOCK_TIMEOUT); 145 } 146 147 148 149 /** Build the "max-entries" property definition. */ 150 static { 151 IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "max-entries"); 152 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "max-entries")); 153 DefaultBehaviorProvider<Integer> provider = new DefinedDefaultBehaviorProvider<Integer>("2147483647"); 154 builder.setDefaultBehaviorProvider(provider); 155 builder.setLowerLimit(0); 156 PD_MAX_ENTRIES = builder.getInstance(); 157 INSTANCE.registerPropertyDefinition(PD_MAX_ENTRIES); 158 } 159 160 161 162 /** Build the "max-memory-percent" property definition. */ 163 static { 164 IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "max-memory-percent"); 165 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "max-memory-percent")); 166 DefaultBehaviorProvider<Integer> provider = new DefinedDefaultBehaviorProvider<Integer>("90"); 167 builder.setDefaultBehaviorProvider(provider); 168 builder.setUpperLimit(100); 169 builder.setLowerLimit(1); 170 PD_MAX_MEMORY_PERCENT = builder.getInstance(); 171 INSTANCE.registerPropertyDefinition(PD_MAX_MEMORY_PERCENT); 172 } 173 174 175 176 // Register the tags associated with this managed object definition. 177 static { 178 INSTANCE.registerTag(Tag.valueOf("database")); 179 } 180 181 182 183 /** 184 * Get the FIFO Entry Cache configuration definition singleton. 185 * 186 * @return Returns the FIFO Entry Cache configuration definition 187 * singleton. 188 */ 189 public static FIFOEntryCacheCfgDefn getInstance() { 190 return INSTANCE; 191 } 192 193 194 195 /** 196 * Private constructor. 197 */ 198 private FIFOEntryCacheCfgDefn() { 199 super("fifo-entry-cache", EntryCacheCfgDefn.getInstance()); 200 } 201 202 203 204 /** {@inheritDoc} */ 205 public FIFOEntryCacheCfgClient createClientConfiguration( 206 ManagedObject<? extends FIFOEntryCacheCfgClient> impl) { 207 return new FIFOEntryCacheCfgClientImpl(impl); 208 } 209 210 211 212 /** {@inheritDoc} */ 213 public FIFOEntryCacheCfg createServerConfiguration( 214 ServerManagedObject<? extends FIFOEntryCacheCfg> impl) { 215 return new FIFOEntryCacheCfgServerImpl(impl); 216 } 217 218 219 220 /** {@inheritDoc} */ 221 public Class<FIFOEntryCacheCfg> getServerConfigurationClass() { 222 return FIFOEntryCacheCfg.class; 223 } 224 225 226 227 /** 228 * Get the "cache-level" property definition. 229 * <p> 230 * Specifies the cache level in the cache order if more than one 231 * instance of the cache is configured. 232 * 233 * @return Returns the "cache-level" property definition. 234 */ 235 public IntegerPropertyDefinition getCacheLevelPropertyDefinition() { 236 return EntryCacheCfgDefn.getInstance().getCacheLevelPropertyDefinition(); 237 } 238 239 240 241 /** 242 * Get the "enabled" property definition. 243 * <p> 244 * Indicates whether the FIFO Entry Cache is enabled. 245 * 246 * @return Returns the "enabled" property definition. 247 */ 248 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 249 return EntryCacheCfgDefn.getInstance().getEnabledPropertyDefinition(); 250 } 251 252 253 254 /** 255 * Get the "exclude-filter" property definition. 256 * <p> 257 * The set of filters that define the entries that should be 258 * excluded from the cache. 259 * 260 * @return Returns the "exclude-filter" property definition. 261 */ 262 public StringPropertyDefinition getExcludeFilterPropertyDefinition() { 263 return PD_EXCLUDE_FILTER; 264 } 265 266 267 268 /** 269 * Get the "include-filter" property definition. 270 * <p> 271 * The set of filters that define the entries that should be 272 * included in the cache. 273 * 274 * @return Returns the "include-filter" property definition. 275 */ 276 public StringPropertyDefinition getIncludeFilterPropertyDefinition() { 277 return PD_INCLUDE_FILTER; 278 } 279 280 281 282 /** 283 * Get the "java-class" property definition. 284 * <p> 285 * Specifies the fully-qualified name of the Java class that 286 * provides the FIFO Entry Cache implementation. 287 * 288 * @return Returns the "java-class" property definition. 289 */ 290 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 291 return PD_JAVA_CLASS; 292 } 293 294 295 296 /** 297 * Get the "lock-timeout" property definition. 298 * <p> 299 * Specifies the length of time to wait while attempting to acquire 300 * a read or write lock. 301 * 302 * @return Returns the "lock-timeout" property definition. 303 */ 304 public DurationPropertyDefinition getLockTimeoutPropertyDefinition() { 305 return PD_LOCK_TIMEOUT; 306 } 307 308 309 310 /** 311 * Get the "max-entries" property definition. 312 * <p> 313 * Specifies the maximum number of entries that we will allow in the 314 * cache. 315 * 316 * @return Returns the "max-entries" property definition. 317 */ 318 public IntegerPropertyDefinition getMaxEntriesPropertyDefinition() { 319 return PD_MAX_ENTRIES; 320 } 321 322 323 324 /** 325 * Get the "max-memory-percent" property definition. 326 * <p> 327 * Specifies the maximum percentage of JVM memory used by the server 328 * before the entry caches stops caching and begins purging itself. 329 * <p> 330 * Very low settings such as 10 or 20 (percent) can prevent this 331 * entry cache from having enough space to hold any of the entries to 332 * cache, making it appear that the server is ignoring or skipping 333 * the entry cache entirely. 334 * 335 * @return Returns the "max-memory-percent" property definition. 336 */ 337 public IntegerPropertyDefinition getMaxMemoryPercentPropertyDefinition() { 338 return PD_MAX_MEMORY_PERCENT; 339 } 340 341 342 343 /** 344 * Managed object client implementation. 345 */ 346 private static class FIFOEntryCacheCfgClientImpl implements 347 FIFOEntryCacheCfgClient { 348 349 /** Private implementation. */ 350 private ManagedObject<? extends FIFOEntryCacheCfgClient> impl; 351 352 353 354 /** Private constructor. */ 355 private FIFOEntryCacheCfgClientImpl( 356 ManagedObject<? extends FIFOEntryCacheCfgClient> impl) { 357 this.impl = impl; 358 } 359 360 361 362 /** {@inheritDoc} */ 363 public Integer getCacheLevel() { 364 return impl.getPropertyValue(INSTANCE.getCacheLevelPropertyDefinition()); 365 } 366 367 368 369 /** {@inheritDoc} */ 370 public void setCacheLevel(int value) { 371 impl.setPropertyValue(INSTANCE.getCacheLevelPropertyDefinition(), value); 372 } 373 374 375 376 /** {@inheritDoc} */ 377 public Boolean isEnabled() { 378 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 379 } 380 381 382 383 /** {@inheritDoc} */ 384 public void setEnabled(boolean value) { 385 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 386 } 387 388 389 390 /** {@inheritDoc} */ 391 public SortedSet<String> getExcludeFilter() { 392 return impl.getPropertyValues(INSTANCE.getExcludeFilterPropertyDefinition()); 393 } 394 395 396 397 /** {@inheritDoc} */ 398 public void setExcludeFilter(Collection<String> values) { 399 impl.setPropertyValues(INSTANCE.getExcludeFilterPropertyDefinition(), values); 400 } 401 402 403 404 /** {@inheritDoc} */ 405 public SortedSet<String> getIncludeFilter() { 406 return impl.getPropertyValues(INSTANCE.getIncludeFilterPropertyDefinition()); 407 } 408 409 410 411 /** {@inheritDoc} */ 412 public void setIncludeFilter(Collection<String> values) { 413 impl.setPropertyValues(INSTANCE.getIncludeFilterPropertyDefinition(), values); 414 } 415 416 417 418 /** {@inheritDoc} */ 419 public String getJavaClass() { 420 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 421 } 422 423 424 425 /** {@inheritDoc} */ 426 public void setJavaClass(String value) { 427 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 428 } 429 430 431 432 /** {@inheritDoc} */ 433 public long getLockTimeout() { 434 return impl.getPropertyValue(INSTANCE.getLockTimeoutPropertyDefinition()); 435 } 436 437 438 439 /** {@inheritDoc} */ 440 public void setLockTimeout(Long value) { 441 impl.setPropertyValue(INSTANCE.getLockTimeoutPropertyDefinition(), value); 442 } 443 444 445 446 /** {@inheritDoc} */ 447 public int getMaxEntries() { 448 return impl.getPropertyValue(INSTANCE.getMaxEntriesPropertyDefinition()); 449 } 450 451 452 453 /** {@inheritDoc} */ 454 public void setMaxEntries(Integer value) { 455 impl.setPropertyValue(INSTANCE.getMaxEntriesPropertyDefinition(), value); 456 } 457 458 459 460 /** {@inheritDoc} */ 461 public int getMaxMemoryPercent() { 462 return impl.getPropertyValue(INSTANCE.getMaxMemoryPercentPropertyDefinition()); 463 } 464 465 466 467 /** {@inheritDoc} */ 468 public void setMaxMemoryPercent(Integer value) { 469 impl.setPropertyValue(INSTANCE.getMaxMemoryPercentPropertyDefinition(), value); 470 } 471 472 473 474 /** {@inheritDoc} */ 475 public ManagedObjectDefinition<? extends FIFOEntryCacheCfgClient, ? extends FIFOEntryCacheCfg> definition() { 476 return INSTANCE; 477 } 478 479 480 481 /** {@inheritDoc} */ 482 public PropertyProvider properties() { 483 return impl; 484 } 485 486 487 488 /** {@inheritDoc} */ 489 public void commit() throws ManagedObjectAlreadyExistsException, 490 MissingMandatoryPropertiesException, ConcurrentModificationException, 491 OperationRejectedException, LdapException { 492 impl.commit(); 493 } 494 495 496 497 /** {@inheritDoc} */ 498 public String toString() { 499 return impl.toString(); 500 } 501 } 502 503 504 505 /** 506 * Managed object server implementation. 507 */ 508 private static class FIFOEntryCacheCfgServerImpl implements 509 FIFOEntryCacheCfg { 510 511 /** Private implementation. */ 512 private ServerManagedObject<? extends FIFOEntryCacheCfg> impl; 513 514 /** The value of the "cache-level" property. */ 515 private final int pCacheLevel; 516 517 /** The value of the "enabled" property. */ 518 private final boolean pEnabled; 519 520 /** The value of the "exclude-filter" property. */ 521 private final SortedSet<String> pExcludeFilter; 522 523 /** The value of the "include-filter" property. */ 524 private final SortedSet<String> pIncludeFilter; 525 526 /** The value of the "java-class" property. */ 527 private final String pJavaClass; 528 529 /** The value of the "lock-timeout" property. */ 530 private final long pLockTimeout; 531 532 /** The value of the "max-entries" property. */ 533 private final int pMaxEntries; 534 535 /** The value of the "max-memory-percent" property. */ 536 private final int pMaxMemoryPercent; 537 538 539 540 /** Private constructor. */ 541 private FIFOEntryCacheCfgServerImpl(ServerManagedObject<? extends FIFOEntryCacheCfg> impl) { 542 this.impl = impl; 543 this.pCacheLevel = impl.getPropertyValue(INSTANCE.getCacheLevelPropertyDefinition()); 544 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 545 this.pExcludeFilter = impl.getPropertyValues(INSTANCE.getExcludeFilterPropertyDefinition()); 546 this.pIncludeFilter = impl.getPropertyValues(INSTANCE.getIncludeFilterPropertyDefinition()); 547 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 548 this.pLockTimeout = impl.getPropertyValue(INSTANCE.getLockTimeoutPropertyDefinition()); 549 this.pMaxEntries = impl.getPropertyValue(INSTANCE.getMaxEntriesPropertyDefinition()); 550 this.pMaxMemoryPercent = impl.getPropertyValue(INSTANCE.getMaxMemoryPercentPropertyDefinition()); 551 } 552 553 554 555 /** {@inheritDoc} */ 556 public void addFIFOChangeListener( 557 ConfigurationChangeListener<FIFOEntryCacheCfg> listener) { 558 impl.registerChangeListener(listener); 559 } 560 561 562 563 /** {@inheritDoc} */ 564 public void removeFIFOChangeListener( 565 ConfigurationChangeListener<FIFOEntryCacheCfg> listener) { 566 impl.deregisterChangeListener(listener); 567 } 568 /** {@inheritDoc} */ 569 public void addChangeListener( 570 ConfigurationChangeListener<EntryCacheCfg> listener) { 571 impl.registerChangeListener(listener); 572 } 573 574 575 576 /** {@inheritDoc} */ 577 public void removeChangeListener( 578 ConfigurationChangeListener<EntryCacheCfg> listener) { 579 impl.deregisterChangeListener(listener); 580 } 581 582 583 584 /** {@inheritDoc} */ 585 public int getCacheLevel() { 586 return pCacheLevel; 587 } 588 589 590 591 /** {@inheritDoc} */ 592 public boolean isEnabled() { 593 return pEnabled; 594 } 595 596 597 598 /** {@inheritDoc} */ 599 public SortedSet<String> getExcludeFilter() { 600 return pExcludeFilter; 601 } 602 603 604 605 /** {@inheritDoc} */ 606 public SortedSet<String> getIncludeFilter() { 607 return pIncludeFilter; 608 } 609 610 611 612 /** {@inheritDoc} */ 613 public String getJavaClass() { 614 return pJavaClass; 615 } 616 617 618 619 /** {@inheritDoc} */ 620 public long getLockTimeout() { 621 return pLockTimeout; 622 } 623 624 625 626 /** {@inheritDoc} */ 627 public int getMaxEntries() { 628 return pMaxEntries; 629 } 630 631 632 633 /** {@inheritDoc} */ 634 public int getMaxMemoryPercent() { 635 return pMaxMemoryPercent; 636 } 637 638 639 640 /** {@inheritDoc} */ 641 public Class<? extends FIFOEntryCacheCfg> configurationClass() { 642 return FIFOEntryCacheCfg.class; 643 } 644 645 646 647 /** {@inheritDoc} */ 648 public DN dn() { 649 return impl.getDN(); 650 } 651 652 653 654 /** {@inheritDoc} */ 655 public String toString() { 656 return impl.toString(); 657 } 658 } 659}