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