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