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    /** {@inheritDoc} */
284    public String toString() {
285      return impl.toString();
286    }
287  }
288
289
290
291  /**
292   * Managed object server implementation.
293   */
294  private static class ParallelWorkQueueCfgServerImpl implements
295    ParallelWorkQueueCfg {
296
297    // Private implementation.
298    private ServerManagedObject<? extends ParallelWorkQueueCfg> impl;
299
300    // The value of the "java-class" property.
301    private final String pJavaClass;
302
303    // The value of the "num-worker-threads" property.
304    private final Integer pNumWorkerThreads;
305
306
307
308    // Private constructor.
309    private ParallelWorkQueueCfgServerImpl(ServerManagedObject<? extends ParallelWorkQueueCfg> impl) {
310      this.impl = impl;
311      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
312      this.pNumWorkerThreads = impl.getPropertyValue(INSTANCE.getNumWorkerThreadsPropertyDefinition());
313    }
314
315
316
317    /**
318     * {@inheritDoc}
319     */
320    public void addParallelChangeListener(
321        ConfigurationChangeListener<ParallelWorkQueueCfg> listener) {
322      impl.registerChangeListener(listener);
323    }
324
325
326
327    /**
328     * {@inheritDoc}
329     */
330    public void removeParallelChangeListener(
331        ConfigurationChangeListener<ParallelWorkQueueCfg> listener) {
332      impl.deregisterChangeListener(listener);
333    }
334    /**
335     * {@inheritDoc}
336     */
337    public void addChangeListener(
338        ConfigurationChangeListener<WorkQueueCfg> listener) {
339      impl.registerChangeListener(listener);
340    }
341
342
343
344    /**
345     * {@inheritDoc}
346     */
347    public void removeChangeListener(
348        ConfigurationChangeListener<WorkQueueCfg> listener) {
349      impl.deregisterChangeListener(listener);
350    }
351
352
353
354    /**
355     * {@inheritDoc}
356     */
357    public String getJavaClass() {
358      return pJavaClass;
359    }
360
361
362
363    /**
364     * {@inheritDoc}
365     */
366    public Integer getNumWorkerThreads() {
367      return pNumWorkerThreads;
368    }
369
370
371
372    /**
373     * {@inheritDoc}
374     */
375    public Class<? extends ParallelWorkQueueCfg> configurationClass() {
376      return ParallelWorkQueueCfg.class;
377    }
378
379
380
381    /**
382     * {@inheritDoc}
383     */
384    public DN dn() {
385      return impl.getDN();
386    }
387
388
389
390    /** {@inheritDoc} */
391    public String toString() {
392      return impl.toString();
393    }
394  }
395}