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