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