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