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