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  /** {@inheritDoc} */
157  public TraditionalWorkQueueCfgClient createClientConfiguration(
158      ManagedObject<? extends TraditionalWorkQueueCfgClient> impl) {
159    return new TraditionalWorkQueueCfgClientImpl(impl);
160  }
161
162
163
164  /** {@inheritDoc} */
165  public TraditionalWorkQueueCfg createServerConfiguration(
166      ServerManagedObject<? extends TraditionalWorkQueueCfg> impl) {
167    return new TraditionalWorkQueueCfgServerImpl(impl);
168  }
169
170
171
172  /** {@inheritDoc} */
173  public Class<TraditionalWorkQueueCfg> getServerConfigurationClass() {
174    return TraditionalWorkQueueCfg.class;
175  }
176
177
178
179  /**
180   * Get the "java-class" property definition.
181   * <p>
182   * Specifies the fully-qualified name of the Java class that
183   * provides the Traditional Work Queue implementation.
184   *
185   * @return Returns the "java-class" property definition.
186   */
187  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
188    return PD_JAVA_CLASS;
189  }
190
191
192
193  /**
194   * Get the "max-work-queue-capacity" property definition.
195   * <p>
196   * Specifies the maximum number of queued operations that can be in
197   * the work queue at any given time.
198   * <p>
199   * If the work queue is already full and additional requests are
200   * received by the server, then the server front end, and possibly
201   * the client, will be blocked until the work queue has available
202   * capacity.
203   *
204   * @return Returns the "max-work-queue-capacity" property definition.
205   */
206  public IntegerPropertyDefinition getMaxWorkQueueCapacityPropertyDefinition() {
207    return PD_MAX_WORK_QUEUE_CAPACITY;
208  }
209
210
211
212  /**
213   * Get the "num-worker-threads" property definition.
214   * <p>
215   * Specifies the number of worker threads to be used for processing
216   * operations placed in the queue.
217   * <p>
218   * If the value is increased, the additional worker threads are
219   * created immediately. If the value is reduced, the appropriate
220   * number of threads are destroyed as operations complete processing.
221   *
222   * @return Returns the "num-worker-threads" property definition.
223   */
224  public IntegerPropertyDefinition getNumWorkerThreadsPropertyDefinition() {
225    return PD_NUM_WORKER_THREADS;
226  }
227
228
229
230  /**
231   * Managed object client implementation.
232   */
233  private static class TraditionalWorkQueueCfgClientImpl implements
234    TraditionalWorkQueueCfgClient {
235
236    /** Private implementation. */
237    private ManagedObject<? extends TraditionalWorkQueueCfgClient> impl;
238
239
240
241    /** Private constructor. */
242    private TraditionalWorkQueueCfgClientImpl(
243        ManagedObject<? extends TraditionalWorkQueueCfgClient> impl) {
244      this.impl = impl;
245    }
246
247
248
249    /** {@inheritDoc} */
250    public String getJavaClass() {
251      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
252    }
253
254
255
256    /** {@inheritDoc} */
257    public void setJavaClass(String value) {
258      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
259    }
260
261
262
263    /** {@inheritDoc} */
264    public int getMaxWorkQueueCapacity() {
265      return impl.getPropertyValue(INSTANCE.getMaxWorkQueueCapacityPropertyDefinition());
266    }
267
268
269
270    /** {@inheritDoc} */
271    public void setMaxWorkQueueCapacity(Integer value) {
272      impl.setPropertyValue(INSTANCE.getMaxWorkQueueCapacityPropertyDefinition(), value);
273    }
274
275
276
277    /** {@inheritDoc} */
278    public Integer getNumWorkerThreads() {
279      return impl.getPropertyValue(INSTANCE.getNumWorkerThreadsPropertyDefinition());
280    }
281
282
283
284    /** {@inheritDoc} */
285    public void setNumWorkerThreads(Integer value) {
286      impl.setPropertyValue(INSTANCE.getNumWorkerThreadsPropertyDefinition(), value);
287    }
288
289
290
291    /** {@inheritDoc} */
292    public ManagedObjectDefinition<? extends TraditionalWorkQueueCfgClient, ? extends TraditionalWorkQueueCfg> definition() {
293      return INSTANCE;
294    }
295
296
297
298    /** {@inheritDoc} */
299    public PropertyProvider properties() {
300      return impl;
301    }
302
303
304
305    /** {@inheritDoc} */
306    public void commit() throws ManagedObjectAlreadyExistsException,
307        MissingMandatoryPropertiesException, ConcurrentModificationException,
308        OperationRejectedException, LdapException {
309      impl.commit();
310    }
311
312
313
314    /** {@inheritDoc} */
315    public String toString() {
316      return impl.toString();
317    }
318  }
319
320
321
322  /**
323   * Managed object server implementation.
324   */
325  private static class TraditionalWorkQueueCfgServerImpl implements
326    TraditionalWorkQueueCfg {
327
328    /** Private implementation. */
329    private ServerManagedObject<? extends TraditionalWorkQueueCfg> impl;
330
331    /** The value of the "java-class" property. */
332    private final String pJavaClass;
333
334    /** The value of the "max-work-queue-capacity" property. */
335    private final int pMaxWorkQueueCapacity;
336
337    /** The value of the "num-worker-threads" property. */
338    private final Integer pNumWorkerThreads;
339
340
341
342    /** Private constructor. */
343    private TraditionalWorkQueueCfgServerImpl(ServerManagedObject<? extends TraditionalWorkQueueCfg> impl) {
344      this.impl = impl;
345      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
346      this.pMaxWorkQueueCapacity = impl.getPropertyValue(INSTANCE.getMaxWorkQueueCapacityPropertyDefinition());
347      this.pNumWorkerThreads = impl.getPropertyValue(INSTANCE.getNumWorkerThreadsPropertyDefinition());
348    }
349
350
351
352    /** {@inheritDoc} */
353    public void addTraditionalChangeListener(
354        ConfigurationChangeListener<TraditionalWorkQueueCfg> listener) {
355      impl.registerChangeListener(listener);
356    }
357
358
359
360    /** {@inheritDoc} */
361    public void removeTraditionalChangeListener(
362        ConfigurationChangeListener<TraditionalWorkQueueCfg> listener) {
363      impl.deregisterChangeListener(listener);
364    }
365    /** {@inheritDoc} */
366    public void addChangeListener(
367        ConfigurationChangeListener<WorkQueueCfg> listener) {
368      impl.registerChangeListener(listener);
369    }
370
371
372
373    /** {@inheritDoc} */
374    public void removeChangeListener(
375        ConfigurationChangeListener<WorkQueueCfg> listener) {
376      impl.deregisterChangeListener(listener);
377    }
378
379
380
381    /** {@inheritDoc} */
382    public String getJavaClass() {
383      return pJavaClass;
384    }
385
386
387
388    /** {@inheritDoc} */
389    public int getMaxWorkQueueCapacity() {
390      return pMaxWorkQueueCapacity;
391    }
392
393
394
395    /** {@inheritDoc} */
396    public Integer getNumWorkerThreads() {
397      return pNumWorkerThreads;
398    }
399
400
401
402    /** {@inheritDoc} */
403    public Class<? extends TraditionalWorkQueueCfg> configurationClass() {
404      return TraditionalWorkQueueCfg.class;
405    }
406
407
408
409    /** {@inheritDoc} */
410    public DN dn() {
411      return impl.getDN();
412    }
413
414
415
416    /** {@inheritDoc} */
417    public String toString() {
418      return impl.toString();
419    }
420  }
421}