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