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.ClassPropertyDefinition; 032import org.forgerock.opendj.config.client.ConcurrentModificationException; 033import org.forgerock.opendj.config.client.ManagedObject; 034import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 035import org.forgerock.opendj.config.client.OperationRejectedException; 036import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 037import org.forgerock.opendj.config.ManagedObjectDefinition; 038import org.forgerock.opendj.config.PropertyOption; 039import org.forgerock.opendj.config.PropertyProvider; 040import org.forgerock.opendj.config.server.ConfigurationChangeListener; 041import org.forgerock.opendj.config.server.ServerManagedObject; 042import org.forgerock.opendj.config.Tag; 043import org.forgerock.opendj.config.TopCfgDefn; 044import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider; 045import org.forgerock.opendj.ldap.DN; 046import org.forgerock.opendj.ldap.LdapException; 047import org.forgerock.opendj.server.config.client.WorkQueueCfgClient; 048import org.forgerock.opendj.server.config.server.WorkQueueCfg; 049 050 051 052/** 053 * An interface for querying the Work Queue managed object definition 054 * meta information. 055 * <p> 056 * The Work Queue provides the configuration for the server work queue 057 * and is responsible for ensuring that requests received from clients 058 * are processed in a timely manner. 059 */ 060public final class WorkQueueCfgDefn extends ManagedObjectDefinition<WorkQueueCfgClient, WorkQueueCfg> { 061 062 /** The singleton configuration definition instance. */ 063 private static final WorkQueueCfgDefn INSTANCE = new WorkQueueCfgDefn(); 064 065 066 067 /** The "java-class" property definition. */ 068 private static final ClassPropertyDefinition PD_JAVA_CLASS; 069 070 071 072 /** Build the "java-class" property definition. */ 073 static { 074 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 075 builder.setOption(PropertyOption.MANDATORY); 076 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.SERVER_RESTART, INSTANCE, "java-class")); 077 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 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 // Register the tags associated with this managed object definition. 086 static { 087 INSTANCE.registerTag(Tag.valueOf("core-server")); 088 } 089 090 091 092 /** 093 * Get the Work Queue configuration definition singleton. 094 * 095 * @return Returns the Work Queue configuration definition 096 * singleton. 097 */ 098 public static WorkQueueCfgDefn getInstance() { 099 return INSTANCE; 100 } 101 102 103 104 /** 105 * Private constructor. 106 */ 107 private WorkQueueCfgDefn() { 108 super("work-queue", TopCfgDefn.getInstance()); 109 } 110 111 112 113 /** {@inheritDoc} */ 114 public WorkQueueCfgClient createClientConfiguration( 115 ManagedObject<? extends WorkQueueCfgClient> impl) { 116 return new WorkQueueCfgClientImpl(impl); 117 } 118 119 120 121 /** {@inheritDoc} */ 122 public WorkQueueCfg createServerConfiguration( 123 ServerManagedObject<? extends WorkQueueCfg> impl) { 124 return new WorkQueueCfgServerImpl(impl); 125 } 126 127 128 129 /** {@inheritDoc} */ 130 public Class<WorkQueueCfg> getServerConfigurationClass() { 131 return WorkQueueCfg.class; 132 } 133 134 135 136 /** 137 * Get the "java-class" property definition. 138 * <p> 139 * Specifies the fully-qualified name of the Java class that 140 * provides the Work Queue implementation. 141 * 142 * @return Returns the "java-class" property definition. 143 */ 144 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 145 return PD_JAVA_CLASS; 146 } 147 148 149 150 /** 151 * Managed object client implementation. 152 */ 153 private static class WorkQueueCfgClientImpl implements 154 WorkQueueCfgClient { 155 156 /** Private implementation. */ 157 private ManagedObject<? extends WorkQueueCfgClient> impl; 158 159 160 161 /** Private constructor. */ 162 private WorkQueueCfgClientImpl( 163 ManagedObject<? extends WorkQueueCfgClient> impl) { 164 this.impl = impl; 165 } 166 167 168 169 /** {@inheritDoc} */ 170 public String getJavaClass() { 171 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 172 } 173 174 175 176 /** {@inheritDoc} */ 177 public void setJavaClass(String value) { 178 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 179 } 180 181 182 183 /** {@inheritDoc} */ 184 public ManagedObjectDefinition<? extends WorkQueueCfgClient, ? extends WorkQueueCfg> definition() { 185 return INSTANCE; 186 } 187 188 189 190 /** {@inheritDoc} */ 191 public PropertyProvider properties() { 192 return impl; 193 } 194 195 196 197 /** {@inheritDoc} */ 198 public void commit() throws ManagedObjectAlreadyExistsException, 199 MissingMandatoryPropertiesException, ConcurrentModificationException, 200 OperationRejectedException, LdapException { 201 impl.commit(); 202 } 203 204 205 206 /** {@inheritDoc} */ 207 public String toString() { 208 return impl.toString(); 209 } 210 } 211 212 213 214 /** 215 * Managed object server implementation. 216 */ 217 private static class WorkQueueCfgServerImpl implements 218 WorkQueueCfg { 219 220 /** Private implementation. */ 221 private ServerManagedObject<? extends WorkQueueCfg> impl; 222 223 /** The value of the "java-class" property. */ 224 private final String pJavaClass; 225 226 227 228 /** Private constructor. */ 229 private WorkQueueCfgServerImpl(ServerManagedObject<? extends WorkQueueCfg> impl) { 230 this.impl = impl; 231 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 232 } 233 234 235 236 /** {@inheritDoc} */ 237 public void addChangeListener( 238 ConfigurationChangeListener<WorkQueueCfg> listener) { 239 impl.registerChangeListener(listener); 240 } 241 242 243 244 /** {@inheritDoc} */ 245 public void removeChangeListener( 246 ConfigurationChangeListener<WorkQueueCfg> listener) { 247 impl.deregisterChangeListener(listener); 248 } 249 250 251 252 /** {@inheritDoc} */ 253 public String getJavaClass() { 254 return pJavaClass; 255 } 256 257 258 259 /** {@inheritDoc} */ 260 public Class<? extends WorkQueueCfg> configurationClass() { 261 return WorkQueueCfg.class; 262 } 263 264 265 266 /** {@inheritDoc} */ 267 public DN dn() { 268 return impl.getDN(); 269 } 270 271 272 273 /** {@inheritDoc} */ 274 public String toString() { 275 return impl.toString(); 276 } 277 } 278}