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