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
010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012 * See the License for the specific language governing permissions
013 * and limitations under the License.
014 *
015 * When distributing Covered Code, include this CDDL HEADER in each
016 * file and include the License file at
017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
018 * add the following below this CDDL HEADER, with the fields enclosed
019 * by brackets "[]" replaced with your own identifying information:
020 * Portions Copyright [yyyy] [name of copyright owner]
021 *
022 * CDDL HEADER END
023 *
024 *
025 * Copyright 2008 Sun Microsystems, Inc.
026 */
027 package org.opends.server.admin.std.meta;
028
029
030
031 import org.opends.server.admin.AdministratorAction;
032 import org.opends.server.admin.AliasDefaultBehaviorProvider;
033 import org.opends.server.admin.ClassPropertyDefinition;
034 import org.opends.server.admin.client.AuthorizationException;
035 import org.opends.server.admin.client.CommunicationException;
036 import org.opends.server.admin.client.ConcurrentModificationException;
037 import org.opends.server.admin.client.ManagedObject;
038 import org.opends.server.admin.client.MissingMandatoryPropertiesException;
039 import org.opends.server.admin.client.OperationRejectedException;
040 import org.opends.server.admin.DefaultBehaviorProvider;
041 import org.opends.server.admin.DefinedDefaultBehaviorProvider;
042 import org.opends.server.admin.IntegerPropertyDefinition;
043 import org.opends.server.admin.ManagedObjectAlreadyExistsException;
044 import org.opends.server.admin.ManagedObjectDefinition;
045 import org.opends.server.admin.PropertyOption;
046 import org.opends.server.admin.PropertyProvider;
047 import org.opends.server.admin.server.ConfigurationChangeListener;
048 import org.opends.server.admin.server.ServerManagedObject;
049 import org.opends.server.admin.std.client.TraditionalWorkQueueCfgClient;
050 import org.opends.server.admin.std.server.TraditionalWorkQueueCfg;
051 import org.opends.server.admin.std.server.WorkQueueCfg;
052 import org.opends.server.admin.Tag;
053 import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
054 import org.opends.server.types.DN;
055
056
057
058 /**
059 * An interface for querying the Traditional Work Queue managed object
060 * definition meta information.
061 * <p>
062 * The Traditional Work Queue is a type of work queue that uses a
063 * number of worker threads that watch a queue and pick up an operation
064 * to process whenever one becomes available.
065 */
066 public final class TraditionalWorkQueueCfgDefn extends ManagedObjectDefinition<TraditionalWorkQueueCfgClient, TraditionalWorkQueueCfg> {
067
068 // The singleton configuration definition instance.
069 private static final TraditionalWorkQueueCfgDefn INSTANCE = new TraditionalWorkQueueCfgDefn();
070
071
072
073 // The "java-class" property definition.
074 private static final ClassPropertyDefinition PD_JAVA_CLASS;
075
076
077
078 // The "max-work-queue-capacity" property definition.
079 private static final IntegerPropertyDefinition PD_MAX_WORK_QUEUE_CAPACITY;
080
081
082
083 // The "num-worker-threads" property definition.
084 private static final IntegerPropertyDefinition PD_NUM_WORKER_THREADS;
085
086
087
088 // Build the "java-class" property definition.
089 static {
090 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
091 builder.setOption(PropertyOption.MANDATORY);
092 builder.setOption(PropertyOption.ADVANCED);
093 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.SERVER_RESTART, INSTANCE, "java-class"));
094 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.TraditionalWorkQueue");
095 builder.setDefaultBehaviorProvider(provider);
096 builder.addInstanceOf("org.opends.server.api.WorkQueue");
097 PD_JAVA_CLASS = builder.getInstance();
098 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
099 }
100
101
102
103 // Build the "max-work-queue-capacity" property definition.
104 static {
105 IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "max-work-queue-capacity");
106 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.SERVER_RESTART, INSTANCE, "max-work-queue-capacity"));
107 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<Integer>(INSTANCE, "max-work-queue-capacity"));
108 builder.setUpperLimit(2147483647);
109 builder.setLowerLimit(0);
110 PD_MAX_WORK_QUEUE_CAPACITY = builder.getInstance();
111 INSTANCE.registerPropertyDefinition(PD_MAX_WORK_QUEUE_CAPACITY);
112 }
113
114
115
116 // Build the "num-worker-threads" property definition.
117 static {
118 IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "num-worker-threads");
119 builder.setOption(PropertyOption.MANDATORY);
120 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "num-worker-threads"));
121 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Integer>());
122 builder.setUpperLimit(2147483647);
123 builder.setLowerLimit(1);
124 PD_NUM_WORKER_THREADS = builder.getInstance();
125 INSTANCE.registerPropertyDefinition(PD_NUM_WORKER_THREADS);
126 }
127
128
129
130 // Register the tags associated with this managed object definition.
131 static {
132 INSTANCE.registerTag(Tag.valueOf("core-server"));
133 }
134
135
136
137 /**
138 * Get the Traditional Work Queue configuration definition
139 * singleton.
140 *
141 * @return Returns the Traditional Work Queue configuration
142 * definition singleton.
143 */
144 public static TraditionalWorkQueueCfgDefn getInstance() {
145 return INSTANCE;
146 }
147
148
149
150 /**
151 * Private constructor.
152 */
153 private TraditionalWorkQueueCfgDefn() {
154 super("traditional-work-queue", WorkQueueCfgDefn.getInstance());
155 }
156
157
158
159 /**
160 * {@inheritDoc}
161 */
162 public TraditionalWorkQueueCfgClient createClientConfiguration(
163 ManagedObject<? extends TraditionalWorkQueueCfgClient> impl) {
164 return new TraditionalWorkQueueCfgClientImpl(impl);
165 }
166
167
168
169 /**
170 * {@inheritDoc}
171 */
172 public TraditionalWorkQueueCfg createServerConfiguration(
173 ServerManagedObject<? extends TraditionalWorkQueueCfg> impl) {
174 return new TraditionalWorkQueueCfgServerImpl(impl);
175 }
176
177
178
179 /**
180 * {@inheritDoc}
181 */
182 public Class<TraditionalWorkQueueCfg> getServerConfigurationClass() {
183 return TraditionalWorkQueueCfg.class;
184 }
185
186
187
188 /**
189 * Get the "java-class" property definition.
190 * <p>
191 * Specifies the fully-qualified name of the Java class that
192 * provides the Traditional Work Queue implementation.
193 *
194 * @return Returns the "java-class" property definition.
195 */
196 public ClassPropertyDefinition getJavaClassPropertyDefinition() {
197 return PD_JAVA_CLASS;
198 }
199
200
201
202 /**
203 * Get the "max-work-queue-capacity" property definition.
204 * <p>
205 * Specifies the maximum number of queued operations that can be in
206 * the work queue at any given time.
207 * <p>
208 * If the work queue is already full and additional requests are
209 * received by the server, the requests are rejected. A value of zero
210 * indicates that there is no limit to the size of the queue.
211 *
212 * @return Returns the "max-work-queue-capacity" property definition.
213 */
214 public IntegerPropertyDefinition getMaxWorkQueueCapacityPropertyDefinition() {
215 return PD_MAX_WORK_QUEUE_CAPACITY;
216 }
217
218
219
220 /**
221 * Get the "num-worker-threads" property definition.
222 * <p>
223 * Specifies the number of worker threads to be used for processing
224 * operations placed in the queue.
225 * <p>
226 * If the value is increased, the additional worker threads are
227 * created immediately. If the value is reduced, the appropriate
228 * number of threads are destroyed as operations complete processing.
229 *
230 * @return Returns the "num-worker-threads" property definition.
231 */
232 public IntegerPropertyDefinition getNumWorkerThreadsPropertyDefinition() {
233 return PD_NUM_WORKER_THREADS;
234 }
235
236
237
238 /**
239 * Managed object client implementation.
240 */
241 private static class TraditionalWorkQueueCfgClientImpl implements
242 TraditionalWorkQueueCfgClient {
243
244 // Private implementation.
245 private ManagedObject<? extends TraditionalWorkQueueCfgClient> impl;
246
247
248
249 // Private constructor.
250 private TraditionalWorkQueueCfgClientImpl(
251 ManagedObject<? extends TraditionalWorkQueueCfgClient> impl) {
252 this.impl = impl;
253 }
254
255
256
257 /**
258 * {@inheritDoc}
259 */
260 public String getJavaClass() {
261 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
262 }
263
264
265
266 /**
267 * {@inheritDoc}
268 */
269 public void setJavaClass(String value) {
270 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
271 }
272
273
274
275 /**
276 * {@inheritDoc}
277 */
278 public Integer getMaxWorkQueueCapacity() {
279 return impl.getPropertyValue(INSTANCE.getMaxWorkQueueCapacityPropertyDefinition());
280 }
281
282
283
284 /**
285 * {@inheritDoc}
286 */
287 public void setMaxWorkQueueCapacity(Integer value) {
288 impl.setPropertyValue(INSTANCE.getMaxWorkQueueCapacityPropertyDefinition(), value);
289 }
290
291
292
293 /**
294 * {@inheritDoc}
295 */
296 public Integer getNumWorkerThreads() {
297 return impl.getPropertyValue(INSTANCE.getNumWorkerThreadsPropertyDefinition());
298 }
299
300
301
302 /**
303 * {@inheritDoc}
304 */
305 public void setNumWorkerThreads(int value) {
306 impl.setPropertyValue(INSTANCE.getNumWorkerThreadsPropertyDefinition(), value);
307 }
308
309
310
311 /**
312 * {@inheritDoc}
313 */
314 public ManagedObjectDefinition<? extends TraditionalWorkQueueCfgClient, ? extends TraditionalWorkQueueCfg> definition() {
315 return INSTANCE;
316 }
317
318
319
320 /**
321 * {@inheritDoc}
322 */
323 public PropertyProvider properties() {
324 return impl;
325 }
326
327
328
329 /**
330 * {@inheritDoc}
331 */
332 public void commit() throws ManagedObjectAlreadyExistsException,
333 MissingMandatoryPropertiesException, ConcurrentModificationException,
334 OperationRejectedException, AuthorizationException,
335 CommunicationException {
336 impl.commit();
337 }
338
339 }
340
341
342
343 /**
344 * Managed object server implementation.
345 */
346 private static class TraditionalWorkQueueCfgServerImpl implements
347 TraditionalWorkQueueCfg {
348
349 // Private implementation.
350 private ServerManagedObject<? extends TraditionalWorkQueueCfg> impl;
351
352 // The value of the "java-class" property.
353 private final String pJavaClass;
354
355 // The value of the "max-work-queue-capacity" property.
356 private final Integer pMaxWorkQueueCapacity;
357
358 // The value of the "num-worker-threads" property.
359 private final int pNumWorkerThreads;
360
361
362
363 // Private constructor.
364 private TraditionalWorkQueueCfgServerImpl(ServerManagedObject<? extends TraditionalWorkQueueCfg> impl) {
365 this.impl = impl;
366 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
367 this.pMaxWorkQueueCapacity = impl.getPropertyValue(INSTANCE.getMaxWorkQueueCapacityPropertyDefinition());
368 this.pNumWorkerThreads = impl.getPropertyValue(INSTANCE.getNumWorkerThreadsPropertyDefinition());
369 }
370
371
372
373 /**
374 * {@inheritDoc}
375 */
376 public void addTraditionalChangeListener(
377 ConfigurationChangeListener<TraditionalWorkQueueCfg> listener) {
378 impl.registerChangeListener(listener);
379 }
380
381
382
383 /**
384 * {@inheritDoc}
385 */
386 public void removeTraditionalChangeListener(
387 ConfigurationChangeListener<TraditionalWorkQueueCfg> listener) {
388 impl.deregisterChangeListener(listener);
389 }
390 /**
391 * {@inheritDoc}
392 */
393 public void addChangeListener(
394 ConfigurationChangeListener<WorkQueueCfg> listener) {
395 impl.registerChangeListener(listener);
396 }
397
398
399
400 /**
401 * {@inheritDoc}
402 */
403 public void removeChangeListener(
404 ConfigurationChangeListener<WorkQueueCfg> listener) {
405 impl.deregisterChangeListener(listener);
406 }
407
408
409
410 /**
411 * {@inheritDoc}
412 */
413 public String getJavaClass() {
414 return pJavaClass;
415 }
416
417
418
419 /**
420 * {@inheritDoc}
421 */
422 public Integer getMaxWorkQueueCapacity() {
423 return pMaxWorkQueueCapacity;
424 }
425
426
427
428 /**
429 * {@inheritDoc}
430 */
431 public int getNumWorkerThreads() {
432 return pNumWorkerThreads;
433 }
434
435
436
437 /**
438 * {@inheritDoc}
439 */
440 public Class<? extends TraditionalWorkQueueCfg> configurationClass() {
441 return TraditionalWorkQueueCfg.class;
442 }
443
444
445
446 /**
447 * {@inheritDoc}
448 */
449 public DN dn() {
450 return impl.getDN();
451 }
452
453 }
454 }