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 java.util.Collection; 021import java.util.SortedSet; 022import org.forgerock.opendj.config.AdministratorAction; 023import org.forgerock.opendj.config.BooleanPropertyDefinition; 024import org.forgerock.opendj.config.ClassPropertyDefinition; 025import org.forgerock.opendj.config.client.ConcurrentModificationException; 026import org.forgerock.opendj.config.client.ManagedObject; 027import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 028import org.forgerock.opendj.config.client.OperationRejectedException; 029import org.forgerock.opendj.config.DefaultBehaviorProvider; 030import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; 031import org.forgerock.opendj.config.DNPropertyDefinition; 032import org.forgerock.opendj.config.EnumPropertyDefinition; 033import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 034import org.forgerock.opendj.config.ManagedObjectDefinition; 035import org.forgerock.opendj.config.ManagedObjectOption; 036import org.forgerock.opendj.config.PropertyException; 037import org.forgerock.opendj.config.PropertyOption; 038import org.forgerock.opendj.config.PropertyProvider; 039import org.forgerock.opendj.config.server.ConfigurationChangeListener; 040import org.forgerock.opendj.config.server.ServerManagedObject; 041import org.forgerock.opendj.config.StringPropertyDefinition; 042import org.forgerock.opendj.config.Tag; 043import org.forgerock.opendj.ldap.DN; 044import org.forgerock.opendj.ldap.LdapException; 045import org.forgerock.opendj.server.config.client.MonitorBackendCfgClient; 046import org.forgerock.opendj.server.config.meta.BackendCfgDefn.WritabilityMode; 047import org.forgerock.opendj.server.config.server.BackendCfg; 048import org.forgerock.opendj.server.config.server.MonitorBackendCfg; 049 050 051 052/** 053 * An interface for querying the Monitor Backend managed object 054 * definition meta information. 055 * <p> 056 * The Monitor Backend allows clients to access the information made 057 * available by directory server monitor providers. 058 */ 059public final class MonitorBackendCfgDefn extends ManagedObjectDefinition<MonitorBackendCfgClient, MonitorBackendCfg> { 060 061 /** The singleton configuration definition instance. */ 062 private static final MonitorBackendCfgDefn INSTANCE = new MonitorBackendCfgDefn(); 063 064 065 066 /** The "java-class" property definition. */ 067 private static final ClassPropertyDefinition PD_JAVA_CLASS; 068 069 070 071 /** The "writability-mode" property definition. */ 072 private static final EnumPropertyDefinition<WritabilityMode> PD_WRITABILITY_MODE; 073 074 075 076 /** Build the "java-class" property definition. */ 077 static { 078 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 079 builder.setOption(PropertyOption.MANDATORY); 080 builder.setOption(PropertyOption.ADVANCED); 081 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class")); 082 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.backends.MonitorBackend"); 083 builder.setDefaultBehaviorProvider(provider); 084 builder.addInstanceOf("org.opends.server.api.Backend"); 085 PD_JAVA_CLASS = builder.getInstance(); 086 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 087 } 088 089 090 091 /** Build the "writability-mode" property definition. */ 092 static { 093 EnumPropertyDefinition.Builder<WritabilityMode> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "writability-mode"); 094 builder.setOption(PropertyOption.MANDATORY); 095 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "writability-mode")); 096 DefaultBehaviorProvider<WritabilityMode> provider = new DefinedDefaultBehaviorProvider<WritabilityMode>("disabled"); 097 builder.setDefaultBehaviorProvider(provider); 098 builder.setEnumClass(WritabilityMode.class); 099 PD_WRITABILITY_MODE = builder.getInstance(); 100 INSTANCE.registerPropertyDefinition(PD_WRITABILITY_MODE); 101 } 102 103 104 105 // Register the options associated with this managed object definition. 106 static { 107 INSTANCE.registerOption(ManagedObjectOption.ADVANCED); 108 } 109 110 111 112 // Register the tags associated with this managed object definition. 113 static { 114 INSTANCE.registerTag(Tag.valueOf("database")); 115 } 116 117 118 119 /** 120 * Get the Monitor Backend configuration definition singleton. 121 * 122 * @return Returns the Monitor Backend configuration definition 123 * singleton. 124 */ 125 public static MonitorBackendCfgDefn getInstance() { 126 return INSTANCE; 127 } 128 129 130 131 /** 132 * Private constructor. 133 */ 134 private MonitorBackendCfgDefn() { 135 super("monitor-backend", BackendCfgDefn.getInstance()); 136 } 137 138 139 140 /** {@inheritDoc} */ 141 public MonitorBackendCfgClient createClientConfiguration( 142 ManagedObject<? extends MonitorBackendCfgClient> impl) { 143 return new MonitorBackendCfgClientImpl(impl); 144 } 145 146 147 148 /** {@inheritDoc} */ 149 public MonitorBackendCfg createServerConfiguration( 150 ServerManagedObject<? extends MonitorBackendCfg> impl) { 151 return new MonitorBackendCfgServerImpl(impl); 152 } 153 154 155 156 /** {@inheritDoc} */ 157 public Class<MonitorBackendCfg> getServerConfigurationClass() { 158 return MonitorBackendCfg.class; 159 } 160 161 162 163 /** 164 * Get the "backend-id" property definition. 165 * <p> 166 * Specifies a name to identify the associated backend. 167 * <p> 168 * The name must be unique among all backends in the server. The 169 * backend ID may not be altered after the backend is created in the 170 * server. 171 * 172 * @return Returns the "backend-id" property definition. 173 */ 174 public StringPropertyDefinition getBackendIdPropertyDefinition() { 175 return BackendCfgDefn.getInstance().getBackendIdPropertyDefinition(); 176 } 177 178 179 180 /** 181 * Get the "base-dn" property definition. 182 * <p> 183 * Specifies the base DN(s) for the data that the backend handles. 184 * <p> 185 * A single backend may be responsible for one or more base DNs. 186 * Note that no two backends may have the same base DN although one 187 * backend may have a base DN that is below a base DN provided by 188 * another backend (similar to the use of sub-suffixes in the Sun 189 * Java System Directory Server). If any of the base DNs is 190 * subordinate to a base DN for another backend, then all base DNs 191 * for that backend must be subordinate to that same base DN. 192 * 193 * @return Returns the "base-dn" property definition. 194 */ 195 public DNPropertyDefinition getBaseDNPropertyDefinition() { 196 return BackendCfgDefn.getInstance().getBaseDNPropertyDefinition(); 197 } 198 199 200 201 /** 202 * Get the "enabled" property definition. 203 * <p> 204 * Indicates whether the backend is enabled in the server. 205 * <p> 206 * If a backend is not enabled, then its contents are not accessible 207 * when processing operations. 208 * 209 * @return Returns the "enabled" property definition. 210 */ 211 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 212 return BackendCfgDefn.getInstance().getEnabledPropertyDefinition(); 213 } 214 215 216 217 /** 218 * Get the "java-class" property definition. 219 * <p> 220 * Specifies the fully-qualified name of the Java class that 221 * provides the backend implementation. 222 * 223 * @return Returns the "java-class" property definition. 224 */ 225 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 226 return PD_JAVA_CLASS; 227 } 228 229 230 231 /** 232 * Get the "writability-mode" property definition. 233 * <p> 234 * Specifies the behavior that the backend should use when 235 * processing write operations. 236 * 237 * @return Returns the "writability-mode" property definition. 238 */ 239 public EnumPropertyDefinition<WritabilityMode> getWritabilityModePropertyDefinition() { 240 return PD_WRITABILITY_MODE; 241 } 242 243 244 245 /** 246 * Managed object client implementation. 247 */ 248 private static class MonitorBackendCfgClientImpl implements 249 MonitorBackendCfgClient { 250 251 /** Private implementation. */ 252 private ManagedObject<? extends MonitorBackendCfgClient> impl; 253 254 255 256 /** Private constructor. */ 257 private MonitorBackendCfgClientImpl( 258 ManagedObject<? extends MonitorBackendCfgClient> impl) { 259 this.impl = impl; 260 } 261 262 263 264 /** {@inheritDoc} */ 265 public String getBackendId() { 266 return impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition()); 267 } 268 269 270 271 /** {@inheritDoc} */ 272 public void setBackendId(String value) throws PropertyException { 273 impl.setPropertyValue(INSTANCE.getBackendIdPropertyDefinition(), value); 274 } 275 276 277 278 /** {@inheritDoc} */ 279 public SortedSet<DN> getBaseDN() { 280 return impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition()); 281 } 282 283 284 285 /** {@inheritDoc} */ 286 public void setBaseDN(Collection<DN> values) { 287 impl.setPropertyValues(INSTANCE.getBaseDNPropertyDefinition(), values); 288 } 289 290 291 292 /** {@inheritDoc} */ 293 public Boolean isEnabled() { 294 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 295 } 296 297 298 299 /** {@inheritDoc} */ 300 public void setEnabled(boolean value) { 301 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 302 } 303 304 305 306 /** {@inheritDoc} */ 307 public String getJavaClass() { 308 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 309 } 310 311 312 313 /** {@inheritDoc} */ 314 public void setJavaClass(String value) { 315 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 316 } 317 318 319 320 /** {@inheritDoc} */ 321 public WritabilityMode getWritabilityMode() { 322 return impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition()); 323 } 324 325 326 327 /** {@inheritDoc} */ 328 public void setWritabilityMode(WritabilityMode value) { 329 impl.setPropertyValue(INSTANCE.getWritabilityModePropertyDefinition(), value); 330 } 331 332 333 334 /** {@inheritDoc} */ 335 public ManagedObjectDefinition<? extends MonitorBackendCfgClient, ? extends MonitorBackendCfg> definition() { 336 return INSTANCE; 337 } 338 339 340 341 /** {@inheritDoc} */ 342 public PropertyProvider properties() { 343 return impl; 344 } 345 346 347 348 /** {@inheritDoc} */ 349 public void commit() throws ManagedObjectAlreadyExistsException, 350 MissingMandatoryPropertiesException, ConcurrentModificationException, 351 OperationRejectedException, LdapException { 352 impl.commit(); 353 } 354 355 356 357 /** {@inheritDoc} */ 358 public String toString() { 359 return impl.toString(); 360 } 361 } 362 363 364 365 /** 366 * Managed object server implementation. 367 */ 368 private static class MonitorBackendCfgServerImpl implements 369 MonitorBackendCfg { 370 371 /** Private implementation. */ 372 private ServerManagedObject<? extends MonitorBackendCfg> impl; 373 374 /** The value of the "backend-id" property. */ 375 private final String pBackendId; 376 377 /** The value of the "base-dn" property. */ 378 private final SortedSet<DN> pBaseDN; 379 380 /** The value of the "enabled" property. */ 381 private final boolean pEnabled; 382 383 /** The value of the "java-class" property. */ 384 private final String pJavaClass; 385 386 /** The value of the "writability-mode" property. */ 387 private final WritabilityMode pWritabilityMode; 388 389 390 391 /** Private constructor. */ 392 private MonitorBackendCfgServerImpl(ServerManagedObject<? extends MonitorBackendCfg> impl) { 393 this.impl = impl; 394 this.pBackendId = impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition()); 395 this.pBaseDN = impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition()); 396 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 397 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 398 this.pWritabilityMode = impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition()); 399 } 400 401 402 403 /** {@inheritDoc} */ 404 public void addMonitorChangeListener( 405 ConfigurationChangeListener<MonitorBackendCfg> listener) { 406 impl.registerChangeListener(listener); 407 } 408 409 410 411 /** {@inheritDoc} */ 412 public void removeMonitorChangeListener( 413 ConfigurationChangeListener<MonitorBackendCfg> listener) { 414 impl.deregisterChangeListener(listener); 415 } 416 /** {@inheritDoc} */ 417 public void addChangeListener( 418 ConfigurationChangeListener<BackendCfg> listener) { 419 impl.registerChangeListener(listener); 420 } 421 422 423 424 /** {@inheritDoc} */ 425 public void removeChangeListener( 426 ConfigurationChangeListener<BackendCfg> listener) { 427 impl.deregisterChangeListener(listener); 428 } 429 430 431 432 /** {@inheritDoc} */ 433 public String getBackendId() { 434 return pBackendId; 435 } 436 437 438 439 /** {@inheritDoc} */ 440 public SortedSet<DN> getBaseDN() { 441 return pBaseDN; 442 } 443 444 445 446 /** {@inheritDoc} */ 447 public boolean isEnabled() { 448 return pEnabled; 449 } 450 451 452 453 /** {@inheritDoc} */ 454 public String getJavaClass() { 455 return pJavaClass; 456 } 457 458 459 460 /** {@inheritDoc} */ 461 public WritabilityMode getWritabilityMode() { 462 return pWritabilityMode; 463 } 464 465 466 467 /** {@inheritDoc} */ 468 public Class<? extends MonitorBackendCfg> configurationClass() { 469 return MonitorBackendCfg.class; 470 } 471 472 473 474 /** {@inheritDoc} */ 475 public DN dn() { 476 return impl.getDN(); 477 } 478 479 480 481 /** {@inheritDoc} */ 482 public String toString() { 483 return impl.toString(); 484 } 485 } 486}