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