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