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