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