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.ClassPropertyDefinition;
032import org.forgerock.opendj.config.client.ConcurrentModificationException;
033import org.forgerock.opendj.config.client.ManagedObject;
034import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
035import org.forgerock.opendj.config.client.OperationRejectedException;
036import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
037import org.forgerock.opendj.config.ManagedObjectDefinition;
038import org.forgerock.opendj.config.PropertyOption;
039import org.forgerock.opendj.config.PropertyProvider;
040import org.forgerock.opendj.config.server.ConfigurationChangeListener;
041import org.forgerock.opendj.config.server.ServerManagedObject;
042import org.forgerock.opendj.config.Tag;
043import org.forgerock.opendj.config.TopCfgDefn;
044import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
045import org.forgerock.opendj.ldap.DN;
046import org.forgerock.opendj.ldap.LdapException;
047import org.forgerock.opendj.server.config.client.WorkQueueCfgClient;
048import org.forgerock.opendj.server.config.server.WorkQueueCfg;
049
050
051
052/**
053 * An interface for querying the Work Queue managed object definition
054 * meta information.
055 * <p>
056 * The Work Queue provides the configuration for the server work queue
057 * and is responsible for ensuring that requests received from clients
058 * are processed in a timely manner.
059 */
060public final class WorkQueueCfgDefn extends ManagedObjectDefinition<WorkQueueCfgClient, WorkQueueCfg> {
061
062  // The singleton configuration definition instance.
063  private static final WorkQueueCfgDefn INSTANCE = new WorkQueueCfgDefn();
064
065
066
067  // The "java-class" property definition.
068  private static final ClassPropertyDefinition PD_JAVA_CLASS;
069
070
071
072  // Build the "java-class" property definition.
073  static {
074      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
075      builder.setOption(PropertyOption.MANDATORY);
076      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.SERVER_RESTART, INSTANCE, "java-class"));
077      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
078      builder.addInstanceOf("org.opends.server.api.WorkQueue");
079      PD_JAVA_CLASS = builder.getInstance();
080      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
081  }
082
083
084
085  // Register the tags associated with this managed object definition.
086  static {
087    INSTANCE.registerTag(Tag.valueOf("core-server"));
088  }
089
090
091
092  /**
093   * Get the Work Queue configuration definition singleton.
094   *
095   * @return Returns the Work Queue configuration definition
096   *         singleton.
097   */
098  public static WorkQueueCfgDefn getInstance() {
099    return INSTANCE;
100  }
101
102
103
104  /**
105   * Private constructor.
106   */
107  private WorkQueueCfgDefn() {
108    super("work-queue", TopCfgDefn.getInstance());
109  }
110
111
112
113  /**
114   * {@inheritDoc}
115   */
116  public WorkQueueCfgClient createClientConfiguration(
117      ManagedObject<? extends WorkQueueCfgClient> impl) {
118    return new WorkQueueCfgClientImpl(impl);
119  }
120
121
122
123  /**
124   * {@inheritDoc}
125   */
126  public WorkQueueCfg createServerConfiguration(
127      ServerManagedObject<? extends WorkQueueCfg> impl) {
128    return new WorkQueueCfgServerImpl(impl);
129  }
130
131
132
133  /**
134   * {@inheritDoc}
135   */
136  public Class<WorkQueueCfg> getServerConfigurationClass() {
137    return WorkQueueCfg.class;
138  }
139
140
141
142  /**
143   * Get the "java-class" property definition.
144   * <p>
145   * Specifies the fully-qualified name of the Java class that
146   * provides the Work Queue implementation.
147   *
148   * @return Returns the "java-class" property definition.
149   */
150  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
151    return PD_JAVA_CLASS;
152  }
153
154
155
156  /**
157   * Managed object client implementation.
158   */
159  private static class WorkQueueCfgClientImpl implements
160    WorkQueueCfgClient {
161
162    // Private implementation.
163    private ManagedObject<? extends WorkQueueCfgClient> impl;
164
165
166
167    // Private constructor.
168    private WorkQueueCfgClientImpl(
169        ManagedObject<? extends WorkQueueCfgClient> impl) {
170      this.impl = impl;
171    }
172
173
174
175    /**
176     * {@inheritDoc}
177     */
178    public String getJavaClass() {
179      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
180    }
181
182
183
184    /**
185     * {@inheritDoc}
186     */
187    public void setJavaClass(String value) {
188      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
189    }
190
191
192
193    /**
194     * {@inheritDoc}
195     */
196    public ManagedObjectDefinition<? extends WorkQueueCfgClient, ? extends WorkQueueCfg> definition() {
197      return INSTANCE;
198    }
199
200
201
202    /**
203     * {@inheritDoc}
204     */
205    public PropertyProvider properties() {
206      return impl;
207    }
208
209
210
211    /**
212     * {@inheritDoc}
213     */
214    public void commit() throws ManagedObjectAlreadyExistsException,
215        MissingMandatoryPropertiesException, ConcurrentModificationException,
216        OperationRejectedException, LdapException {
217      impl.commit();
218    }
219
220  }
221
222
223
224  /**
225   * Managed object server implementation.
226   */
227  private static class WorkQueueCfgServerImpl implements
228    WorkQueueCfg {
229
230    // Private implementation.
231    private ServerManagedObject<? extends WorkQueueCfg> impl;
232
233    // The value of the "java-class" property.
234    private final String pJavaClass;
235
236
237
238    // Private constructor.
239    private WorkQueueCfgServerImpl(ServerManagedObject<? extends WorkQueueCfg> impl) {
240      this.impl = impl;
241      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
242    }
243
244
245
246    /**
247     * {@inheritDoc}
248     */
249    public void addChangeListener(
250        ConfigurationChangeListener<WorkQueueCfg> listener) {
251      impl.registerChangeListener(listener);
252    }
253
254
255
256    /**
257     * {@inheritDoc}
258     */
259    public void removeChangeListener(
260        ConfigurationChangeListener<WorkQueueCfg> listener) {
261      impl.deregisterChangeListener(listener);
262    }
263
264
265
266    /**
267     * {@inheritDoc}
268     */
269    public String getJavaClass() {
270      return pJavaClass;
271    }
272
273
274
275    /**
276     * {@inheritDoc}
277     */
278    public Class<? extends WorkQueueCfg> configurationClass() {
279      return WorkQueueCfg.class;
280    }
281
282
283
284    /**
285     * {@inheritDoc}
286     */
287    public DN dn() {
288      return impl.getDN();
289    }
290
291  }
292}