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.forgerock.opendj.server.config.meta;
027
028
029
030import org.forgerock.opendj.config.AdministratorAction;
031import org.forgerock.opendj.config.AliasDefaultBehaviorProvider;
032import org.forgerock.opendj.config.ClassPropertyDefinition;
033import org.forgerock.opendj.config.client.ConcurrentModificationException;
034import org.forgerock.opendj.config.client.ManagedObject;
035import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
036import org.forgerock.opendj.config.client.OperationRejectedException;
037import org.forgerock.opendj.config.DefaultBehaviorProvider;
038import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider;
039import org.forgerock.opendj.config.IntegerPropertyDefinition;
040import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
041import org.forgerock.opendj.config.ManagedObjectDefinition;
042import org.forgerock.opendj.config.PropertyOption;
043import org.forgerock.opendj.config.PropertyProvider;
044import org.forgerock.opendj.config.server.ConfigurationChangeListener;
045import org.forgerock.opendj.config.server.ServerManagedObject;
046import org.forgerock.opendj.config.Tag;
047import org.forgerock.opendj.ldap.DN;
048import org.forgerock.opendj.ldap.LdapException;
049import org.forgerock.opendj.server.config.client.TraditionalWorkQueueCfgClient;
050import org.forgerock.opendj.server.config.server.TraditionalWorkQueueCfg;
051import org.forgerock.opendj.server.config.server.WorkQueueCfg;
052
053
054
055/**
056 * An interface for querying the Traditional Work Queue managed object
057 * definition meta information.
058 * <p>
059 * The Traditional Work Queue is a type of work queue that uses a
060 * number of worker threads that watch a queue and pick up an operation
061 * to process whenever one becomes available.
062 */
063public final class TraditionalWorkQueueCfgDefn extends ManagedObjectDefinition<TraditionalWorkQueueCfgClient, TraditionalWorkQueueCfg> {
064
065  // The singleton configuration definition instance.
066  private static final TraditionalWorkQueueCfgDefn INSTANCE = new TraditionalWorkQueueCfgDefn();
067
068
069
070  // The "java-class" property definition.
071  private static final ClassPropertyDefinition PD_JAVA_CLASS;
072
073
074
075  // The "max-work-queue-capacity" property definition.
076  private static final IntegerPropertyDefinition PD_MAX_WORK_QUEUE_CAPACITY;
077
078
079
080  // The "num-worker-threads" property definition.
081  private static final IntegerPropertyDefinition PD_NUM_WORKER_THREADS;
082
083
084
085  // Build the "java-class" property definition.
086  static {
087      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
088      builder.setOption(PropertyOption.MANDATORY);
089      builder.setOption(PropertyOption.ADVANCED);
090      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.SERVER_RESTART, INSTANCE, "java-class"));
091      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.TraditionalWorkQueue");
092      builder.setDefaultBehaviorProvider(provider);
093      builder.addInstanceOf("org.opends.server.api.WorkQueue");
094      PD_JAVA_CLASS = builder.getInstance();
095      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
096  }
097
098
099
100  // Build the "max-work-queue-capacity" property definition.
101  static {
102      IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "max-work-queue-capacity");
103      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "max-work-queue-capacity"));
104      DefaultBehaviorProvider<Integer> provider = new DefinedDefaultBehaviorProvider<Integer>("1000");
105      builder.setDefaultBehaviorProvider(provider);
106      builder.setUpperLimit(2147483647);
107      builder.setLowerLimit(1);
108      PD_MAX_WORK_QUEUE_CAPACITY = builder.getInstance();
109      INSTANCE.registerPropertyDefinition(PD_MAX_WORK_QUEUE_CAPACITY);
110  }
111
112
113
114  // Build the "num-worker-threads" property definition.
115  static {
116      IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "num-worker-threads");
117      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "num-worker-threads"));
118      builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<Integer>(INSTANCE, "num-worker-threads"));
119      builder.setUpperLimit(2147483647);
120      builder.setLowerLimit(1);
121      PD_NUM_WORKER_THREADS = builder.getInstance();
122      INSTANCE.registerPropertyDefinition(PD_NUM_WORKER_THREADS);
123  }
124
125
126
127  // Register the tags associated with this managed object definition.
128  static {
129    INSTANCE.registerTag(Tag.valueOf("core-server"));
130  }
131
132
133
134  /**
135   * Get the Traditional Work Queue configuration definition
136   * singleton.
137   *
138   * @return Returns the Traditional Work Queue configuration
139   *         definition singleton.
140   */
141  public static TraditionalWorkQueueCfgDefn getInstance() {
142    return INSTANCE;
143  }
144
145
146
147  /**
148   * Private constructor.
149   */
150  private TraditionalWorkQueueCfgDefn() {
151    super("traditional-work-queue", WorkQueueCfgDefn.getInstance());
152  }
153
154
155
156  /**
157   * {@inheritDoc}
158   */
159  public TraditionalWorkQueueCfgClient createClientConfiguration(
160      ManagedObject<? extends TraditionalWorkQueueCfgClient> impl) {
161    return new TraditionalWorkQueueCfgClientImpl(impl);
162  }
163
164
165
166  /**
167   * {@inheritDoc}
168   */
169  public TraditionalWorkQueueCfg createServerConfiguration(
170      ServerManagedObject<? extends TraditionalWorkQueueCfg> impl) {
171    return new TraditionalWorkQueueCfgServerImpl(impl);
172  }
173
174
175
176  /**
177   * {@inheritDoc}
178   */
179  public Class<TraditionalWorkQueueCfg> getServerConfigurationClass() {
180    return TraditionalWorkQueueCfg.class;
181  }
182
183
184
185  /**
186   * Get the "java-class" property definition.
187   * <p>
188   * Specifies the fully-qualified name of the Java class that
189   * provides the Traditional Work Queue implementation.
190   *
191   * @return Returns the "java-class" property definition.
192   */
193  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
194    return PD_JAVA_CLASS;
195  }
196
197
198
199  /**
200   * Get the "max-work-queue-capacity" property definition.
201   * <p>
202   * Specifies the maximum number of queued operations that can be in
203   * the work queue at any given time.
204   * <p>
205   * If the work queue is already full and additional requests are
206   * received by the server, then the server front end, and possibly
207   * the client, will be blocked until the work queue has available
208   * capacity.
209   *
210   * @return Returns the "max-work-queue-capacity" property definition.
211   */
212  public IntegerPropertyDefinition getMaxWorkQueueCapacityPropertyDefinition() {
213    return PD_MAX_WORK_QUEUE_CAPACITY;
214  }
215
216
217
218  /**
219   * Get the "num-worker-threads" property definition.
220   * <p>
221   * Specifies the number of worker threads to be used for processing
222   * operations placed in the queue.
223   * <p>
224   * If the value is increased, the additional worker threads are
225   * created immediately. If the value is reduced, the appropriate
226   * number of threads are destroyed as operations complete processing.
227   *
228   * @return Returns the "num-worker-threads" property definition.
229   */
230  public IntegerPropertyDefinition getNumWorkerThreadsPropertyDefinition() {
231    return PD_NUM_WORKER_THREADS;
232  }
233
234
235
236  /**
237   * Managed object client implementation.
238   */
239  private static class TraditionalWorkQueueCfgClientImpl implements
240    TraditionalWorkQueueCfgClient {
241
242    // Private implementation.
243    private ManagedObject<? extends TraditionalWorkQueueCfgClient> impl;
244
245
246
247    // Private constructor.
248    private TraditionalWorkQueueCfgClientImpl(
249        ManagedObject<? extends TraditionalWorkQueueCfgClient> impl) {
250      this.impl = impl;
251    }
252
253
254
255    /**
256     * {@inheritDoc}
257     */
258    public String getJavaClass() {
259      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
260    }
261
262
263
264    /**
265     * {@inheritDoc}
266     */
267    public void setJavaClass(String value) {
268      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
269    }
270
271
272
273    /**
274     * {@inheritDoc}
275     */
276    public int getMaxWorkQueueCapacity() {
277      return impl.getPropertyValue(INSTANCE.getMaxWorkQueueCapacityPropertyDefinition());
278    }
279
280
281
282    /**
283     * {@inheritDoc}
284     */
285    public void setMaxWorkQueueCapacity(Integer value) {
286      impl.setPropertyValue(INSTANCE.getMaxWorkQueueCapacityPropertyDefinition(), value);
287    }
288
289
290
291    /**
292     * {@inheritDoc}
293     */
294    public Integer getNumWorkerThreads() {
295      return impl.getPropertyValue(INSTANCE.getNumWorkerThreadsPropertyDefinition());
296    }
297
298
299
300    /**
301     * {@inheritDoc}
302     */
303    public void setNumWorkerThreads(Integer value) {
304      impl.setPropertyValue(INSTANCE.getNumWorkerThreadsPropertyDefinition(), value);
305    }
306
307
308
309    /**
310     * {@inheritDoc}
311     */
312    public ManagedObjectDefinition<? extends TraditionalWorkQueueCfgClient, ? extends TraditionalWorkQueueCfg> definition() {
313      return INSTANCE;
314    }
315
316
317
318    /**
319     * {@inheritDoc}
320     */
321    public PropertyProvider properties() {
322      return impl;
323    }
324
325
326
327    /**
328     * {@inheritDoc}
329     */
330    public void commit() throws ManagedObjectAlreadyExistsException,
331        MissingMandatoryPropertiesException, ConcurrentModificationException,
332        OperationRejectedException, LdapException {
333      impl.commit();
334    }
335
336  }
337
338
339
340  /**
341   * Managed object server implementation.
342   */
343  private static class TraditionalWorkQueueCfgServerImpl implements
344    TraditionalWorkQueueCfg {
345
346    // Private implementation.
347    private ServerManagedObject<? extends TraditionalWorkQueueCfg> impl;
348
349    // The value of the "java-class" property.
350    private final String pJavaClass;
351
352    // The value of the "max-work-queue-capacity" property.
353    private final int pMaxWorkQueueCapacity;
354
355    // The value of the "num-worker-threads" property.
356    private final Integer pNumWorkerThreads;
357
358
359
360    // Private constructor.
361    private TraditionalWorkQueueCfgServerImpl(ServerManagedObject<? extends TraditionalWorkQueueCfg> impl) {
362      this.impl = impl;
363      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
364      this.pMaxWorkQueueCapacity = impl.getPropertyValue(INSTANCE.getMaxWorkQueueCapacityPropertyDefinition());
365      this.pNumWorkerThreads = impl.getPropertyValue(INSTANCE.getNumWorkerThreadsPropertyDefinition());
366    }
367
368
369
370    /**
371     * {@inheritDoc}
372     */
373    public void addTraditionalChangeListener(
374        ConfigurationChangeListener<TraditionalWorkQueueCfg> listener) {
375      impl.registerChangeListener(listener);
376    }
377
378
379
380    /**
381     * {@inheritDoc}
382     */
383    public void removeTraditionalChangeListener(
384        ConfigurationChangeListener<TraditionalWorkQueueCfg> listener) {
385      impl.deregisterChangeListener(listener);
386    }
387    /**
388     * {@inheritDoc}
389     */
390    public void addChangeListener(
391        ConfigurationChangeListener<WorkQueueCfg> listener) {
392      impl.registerChangeListener(listener);
393    }
394
395
396
397    /**
398     * {@inheritDoc}
399     */
400    public void removeChangeListener(
401        ConfigurationChangeListener<WorkQueueCfg> listener) {
402      impl.deregisterChangeListener(listener);
403    }
404
405
406
407    /**
408     * {@inheritDoc}
409     */
410    public String getJavaClass() {
411      return pJavaClass;
412    }
413
414
415
416    /**
417     * {@inheritDoc}
418     */
419    public int getMaxWorkQueueCapacity() {
420      return pMaxWorkQueueCapacity;
421    }
422
423
424
425    /**
426     * {@inheritDoc}
427     */
428    public Integer getNumWorkerThreads() {
429      return pNumWorkerThreads;
430    }
431
432
433
434    /**
435     * {@inheritDoc}
436     */
437    public Class<? extends TraditionalWorkQueueCfg> configurationClass() {
438      return TraditionalWorkQueueCfg.class;
439    }
440
441
442
443    /**
444     * {@inheritDoc}
445     */
446    public DN dn() {
447      return impl.getDN();
448    }
449
450  }
451}