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