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.FIFOEntryCacheCfgClient;
053 import org.opends.server.admin.std.server.EntryCacheCfg;
054 import org.opends.server.admin.std.server.FIFOEntryCacheCfg;
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 FIFO Entry Cache managed object
064 * definition meta information.
065 * <p>
066 * FIFO Entry Caches use a FIFO queue to keep track of the cached
067 * entries.
068 */
069 public final class FIFOEntryCacheCfgDefn extends ManagedObjectDefinition<FIFOEntryCacheCfgClient, FIFOEntryCacheCfg> {
070
071 // The singleton configuration definition instance.
072 private static final FIFOEntryCacheCfgDefn INSTANCE = new FIFOEntryCacheCfgDefn();
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 // The "max-entries" property definition.
097 private static final IntegerPropertyDefinition PD_MAX_ENTRIES;
098
099
100
101 // The "max-memory-percent" property definition.
102 private static final IntegerPropertyDefinition PD_MAX_MEMORY_PERCENT;
103
104
105
106 // Build the "exclude-filter" property definition.
107 static {
108 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "exclude-filter");
109 builder.setOption(PropertyOption.MULTI_VALUED);
110 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "exclude-filter"));
111 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
112 PD_EXCLUDE_FILTER = builder.getInstance();
113 INSTANCE.registerPropertyDefinition(PD_EXCLUDE_FILTER);
114 }
115
116
117
118 // Build the "include-filter" property definition.
119 static {
120 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "include-filter");
121 builder.setOption(PropertyOption.MULTI_VALUED);
122 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "include-filter"));
123 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
124 PD_INCLUDE_FILTER = builder.getInstance();
125 INSTANCE.registerPropertyDefinition(PD_INCLUDE_FILTER);
126 }
127
128
129
130 // Build the "java-class" property definition.
131 static {
132 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
133 builder.setOption(PropertyOption.MANDATORY);
134 builder.setOption(PropertyOption.ADVANCED);
135 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
136 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.FIFOEntryCache");
137 builder.setDefaultBehaviorProvider(provider);
138 builder.addInstanceOf("org.opends.server.api.EntryCache");
139 PD_JAVA_CLASS = builder.getInstance();
140 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
141 }
142
143
144
145 // Build the "lock-timeout" property definition.
146 static {
147 DurationPropertyDefinition.Builder builder = DurationPropertyDefinition.createBuilder(INSTANCE, "lock-timeout");
148 builder.setOption(PropertyOption.ADVANCED);
149 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "lock-timeout"));
150 DefaultBehaviorProvider<Long> provider = new DefinedDefaultBehaviorProvider<Long>("2000.0ms");
151 builder.setDefaultBehaviorProvider(provider);
152 builder.setAllowUnlimited(true);
153 builder.setBaseUnit("ms");
154 builder.setLowerLimit("0");
155 PD_LOCK_TIMEOUT = builder.getInstance();
156 INSTANCE.registerPropertyDefinition(PD_LOCK_TIMEOUT);
157 }
158
159
160
161 // Build the "max-entries" property definition.
162 static {
163 IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "max-entries");
164 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "max-entries"));
165 DefaultBehaviorProvider<Integer> provider = new DefinedDefaultBehaviorProvider<Integer>("2147483647");
166 builder.setDefaultBehaviorProvider(provider);
167 builder.setLowerLimit(0);
168 PD_MAX_ENTRIES = builder.getInstance();
169 INSTANCE.registerPropertyDefinition(PD_MAX_ENTRIES);
170 }
171
172
173
174 // Build the "max-memory-percent" property definition.
175 static {
176 IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "max-memory-percent");
177 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "max-memory-percent"));
178 DefaultBehaviorProvider<Integer> provider = new DefinedDefaultBehaviorProvider<Integer>("90");
179 builder.setDefaultBehaviorProvider(provider);
180 builder.setUpperLimit(100);
181 builder.setLowerLimit(1);
182 PD_MAX_MEMORY_PERCENT = builder.getInstance();
183 INSTANCE.registerPropertyDefinition(PD_MAX_MEMORY_PERCENT);
184 }
185
186
187
188 // Register the tags associated with this managed object definition.
189 static {
190 INSTANCE.registerTag(Tag.valueOf("database"));
191 }
192
193
194
195 /**
196 * Get the FIFO Entry Cache configuration definition singleton.
197 *
198 * @return Returns the FIFO Entry Cache configuration definition
199 * singleton.
200 */
201 public static FIFOEntryCacheCfgDefn getInstance() {
202 return INSTANCE;
203 }
204
205
206
207 /**
208 * Private constructor.
209 */
210 private FIFOEntryCacheCfgDefn() {
211 super("fifo-entry-cache", EntryCacheCfgDefn.getInstance());
212 }
213
214
215
216 /**
217 * {@inheritDoc}
218 */
219 public FIFOEntryCacheCfgClient createClientConfiguration(
220 ManagedObject<? extends FIFOEntryCacheCfgClient> impl) {
221 return new FIFOEntryCacheCfgClientImpl(impl);
222 }
223
224
225
226 /**
227 * {@inheritDoc}
228 */
229 public FIFOEntryCacheCfg createServerConfiguration(
230 ServerManagedObject<? extends FIFOEntryCacheCfg> impl) {
231 return new FIFOEntryCacheCfgServerImpl(impl);
232 }
233
234
235
236 /**
237 * {@inheritDoc}
238 */
239 public Class<FIFOEntryCacheCfg> getServerConfigurationClass() {
240 return FIFOEntryCacheCfg.class;
241 }
242
243
244
245 /**
246 * Get the "cache-level" property definition.
247 * <p>
248 * Specifies the cache level in the cache order if more than one
249 * instance of the cache is configured.
250 *
251 * @return Returns the "cache-level" property definition.
252 */
253 public IntegerPropertyDefinition getCacheLevelPropertyDefinition() {
254 return EntryCacheCfgDefn.getInstance().getCacheLevelPropertyDefinition();
255 }
256
257
258
259 /**
260 * Get the "enabled" property definition.
261 * <p>
262 * Indicates whether the FIFO Entry Cache is enabled.
263 *
264 * @return Returns the "enabled" property definition.
265 */
266 public BooleanPropertyDefinition getEnabledPropertyDefinition() {
267 return EntryCacheCfgDefn.getInstance().getEnabledPropertyDefinition();
268 }
269
270
271
272 /**
273 * Get the "exclude-filter" property definition.
274 * <p>
275 * The set of filters that define the entries that should be
276 * excluded from the cache.
277 *
278 * @return Returns the "exclude-filter" property definition.
279 */
280 public StringPropertyDefinition getExcludeFilterPropertyDefinition() {
281 return PD_EXCLUDE_FILTER;
282 }
283
284
285
286 /**
287 * Get the "include-filter" property definition.
288 * <p>
289 * The set of filters that define the entries that should be
290 * included in the cache.
291 *
292 * @return Returns the "include-filter" property definition.
293 */
294 public StringPropertyDefinition getIncludeFilterPropertyDefinition() {
295 return PD_INCLUDE_FILTER;
296 }
297
298
299
300 /**
301 * Get the "java-class" property definition.
302 * <p>
303 * Specifies the fully-qualified name of the Java class that
304 * provides the FIFO Entry Cache implementation.
305 *
306 * @return Returns the "java-class" property definition.
307 */
308 public ClassPropertyDefinition getJavaClassPropertyDefinition() {
309 return PD_JAVA_CLASS;
310 }
311
312
313
314 /**
315 * Get the "lock-timeout" property definition.
316 * <p>
317 * Specifies the length of time to wait while attempting to acquire
318 * a read or write lock.
319 *
320 * @return Returns the "lock-timeout" property definition.
321 */
322 public DurationPropertyDefinition getLockTimeoutPropertyDefinition() {
323 return PD_LOCK_TIMEOUT;
324 }
325
326
327
328 /**
329 * Get the "max-entries" property definition.
330 * <p>
331 * Specifies the maximum number of entries that we will allow in the
332 * cache.
333 *
334 * @return Returns the "max-entries" property definition.
335 */
336 public IntegerPropertyDefinition getMaxEntriesPropertyDefinition() {
337 return PD_MAX_ENTRIES;
338 }
339
340
341
342 /**
343 * Get the "max-memory-percent" property definition.
344 * <p>
345 * Specifies the maximum memory usage for the entry cache as a
346 * percentage of the total JVM memory.
347 *
348 * @return Returns the "max-memory-percent" property definition.
349 */
350 public IntegerPropertyDefinition getMaxMemoryPercentPropertyDefinition() {
351 return PD_MAX_MEMORY_PERCENT;
352 }
353
354
355
356 /**
357 * Managed object client implementation.
358 */
359 private static class FIFOEntryCacheCfgClientImpl implements
360 FIFOEntryCacheCfgClient {
361
362 // Private implementation.
363 private ManagedObject<? extends FIFOEntryCacheCfgClient> impl;
364
365
366
367 // Private constructor.
368 private FIFOEntryCacheCfgClientImpl(
369 ManagedObject<? extends FIFOEntryCacheCfgClient> impl) {
370 this.impl = impl;
371 }
372
373
374
375 /**
376 * {@inheritDoc}
377 */
378 public Integer getCacheLevel() {
379 return impl.getPropertyValue(INSTANCE.getCacheLevelPropertyDefinition());
380 }
381
382
383
384 /**
385 * {@inheritDoc}
386 */
387 public void setCacheLevel(int value) {
388 impl.setPropertyValue(INSTANCE.getCacheLevelPropertyDefinition(), value);
389 }
390
391
392
393 /**
394 * {@inheritDoc}
395 */
396 public Boolean isEnabled() {
397 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
398 }
399
400
401
402 /**
403 * {@inheritDoc}
404 */
405 public void setEnabled(boolean value) {
406 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
407 }
408
409
410
411 /**
412 * {@inheritDoc}
413 */
414 public SortedSet<String> getExcludeFilter() {
415 return impl.getPropertyValues(INSTANCE.getExcludeFilterPropertyDefinition());
416 }
417
418
419
420 /**
421 * {@inheritDoc}
422 */
423 public void setExcludeFilter(Collection<String> values) {
424 impl.setPropertyValues(INSTANCE.getExcludeFilterPropertyDefinition(), values);
425 }
426
427
428
429 /**
430 * {@inheritDoc}
431 */
432 public SortedSet<String> getIncludeFilter() {
433 return impl.getPropertyValues(INSTANCE.getIncludeFilterPropertyDefinition());
434 }
435
436
437
438 /**
439 * {@inheritDoc}
440 */
441 public void setIncludeFilter(Collection<String> values) {
442 impl.setPropertyValues(INSTANCE.getIncludeFilterPropertyDefinition(), values);
443 }
444
445
446
447 /**
448 * {@inheritDoc}
449 */
450 public String getJavaClass() {
451 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
452 }
453
454
455
456 /**
457 * {@inheritDoc}
458 */
459 public void setJavaClass(String value) {
460 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
461 }
462
463
464
465 /**
466 * {@inheritDoc}
467 */
468 public long getLockTimeout() {
469 return impl.getPropertyValue(INSTANCE.getLockTimeoutPropertyDefinition());
470 }
471
472
473
474 /**
475 * {@inheritDoc}
476 */
477 public void setLockTimeout(Long value) {
478 impl.setPropertyValue(INSTANCE.getLockTimeoutPropertyDefinition(), value);
479 }
480
481
482
483 /**
484 * {@inheritDoc}
485 */
486 public int getMaxEntries() {
487 return impl.getPropertyValue(INSTANCE.getMaxEntriesPropertyDefinition());
488 }
489
490
491
492 /**
493 * {@inheritDoc}
494 */
495 public void setMaxEntries(Integer value) {
496 impl.setPropertyValue(INSTANCE.getMaxEntriesPropertyDefinition(), value);
497 }
498
499
500
501 /**
502 * {@inheritDoc}
503 */
504 public int getMaxMemoryPercent() {
505 return impl.getPropertyValue(INSTANCE.getMaxMemoryPercentPropertyDefinition());
506 }
507
508
509
510 /**
511 * {@inheritDoc}
512 */
513 public void setMaxMemoryPercent(Integer value) {
514 impl.setPropertyValue(INSTANCE.getMaxMemoryPercentPropertyDefinition(), value);
515 }
516
517
518
519 /**
520 * {@inheritDoc}
521 */
522 public ManagedObjectDefinition<? extends FIFOEntryCacheCfgClient, ? extends FIFOEntryCacheCfg> definition() {
523 return INSTANCE;
524 }
525
526
527
528 /**
529 * {@inheritDoc}
530 */
531 public PropertyProvider properties() {
532 return impl;
533 }
534
535
536
537 /**
538 * {@inheritDoc}
539 */
540 public void commit() throws ManagedObjectAlreadyExistsException,
541 MissingMandatoryPropertiesException, ConcurrentModificationException,
542 OperationRejectedException, AuthorizationException,
543 CommunicationException {
544 impl.commit();
545 }
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 }