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