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