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