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