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