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.AliasDefaultBehaviorProvider; 034import org.forgerock.opendj.config.BooleanPropertyDefinition; 035import org.forgerock.opendj.config.ClassPropertyDefinition; 036import org.forgerock.opendj.config.client.ConcurrentModificationException; 037import org.forgerock.opendj.config.client.ManagedObject; 038import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 039import org.forgerock.opendj.config.client.OperationRejectedException; 040import org.forgerock.opendj.config.DefaultBehaviorProvider; 041import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; 042import org.forgerock.opendj.config.DNPropertyDefinition; 043import org.forgerock.opendj.config.DurationPropertyDefinition; 044import org.forgerock.opendj.config.EnumPropertyDefinition; 045import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 046import org.forgerock.opendj.config.ManagedObjectDefinition; 047import org.forgerock.opendj.config.ManagedObjectOption; 048import org.forgerock.opendj.config.PropertyException; 049import org.forgerock.opendj.config.PropertyOption; 050import org.forgerock.opendj.config.PropertyProvider; 051import org.forgerock.opendj.config.server.ConfigurationChangeListener; 052import org.forgerock.opendj.config.server.ServerManagedObject; 053import org.forgerock.opendj.config.StringPropertyDefinition; 054import org.forgerock.opendj.config.Tag; 055import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider; 056import org.forgerock.opendj.ldap.DN; 057import org.forgerock.opendj.ldap.LdapException; 058import org.forgerock.opendj.server.config.client.TaskBackendCfgClient; 059import org.forgerock.opendj.server.config.meta.BackendCfgDefn.WritabilityMode; 060import org.forgerock.opendj.server.config.server.BackendCfg; 061import org.forgerock.opendj.server.config.server.TaskBackendCfg; 062 063 064 065/** 066 * An interface for querying the Task Backend managed object 067 * definition meta information. 068 * <p> 069 * The Task Backend provides a mechanism for scheduling tasks in the 070 * OpenDJ directory server. Tasks are intended to provide access to 071 * certain types of administrative functions in the server that may not 072 * be convenient to perform remotely. 073 */ 074public final class TaskBackendCfgDefn extends ManagedObjectDefinition<TaskBackendCfgClient, TaskBackendCfg> { 075 076 /** The singleton configuration definition instance. */ 077 private static final TaskBackendCfgDefn INSTANCE = new TaskBackendCfgDefn(); 078 079 080 081 /** The "java-class" property definition. */ 082 private static final ClassPropertyDefinition PD_JAVA_CLASS; 083 084 085 086 /** The "notification-sender-address" property definition. */ 087 private static final StringPropertyDefinition PD_NOTIFICATION_SENDER_ADDRESS; 088 089 090 091 /** The "task-backing-file" property definition. */ 092 private static final StringPropertyDefinition PD_TASK_BACKING_FILE; 093 094 095 096 /** The "task-retention-time" property definition. */ 097 private static final DurationPropertyDefinition PD_TASK_RETENTION_TIME; 098 099 100 101 /** The "writability-mode" property definition. */ 102 private static final EnumPropertyDefinition<WritabilityMode> PD_WRITABILITY_MODE; 103 104 105 106 /** Build the "java-class" property definition. */ 107 static { 108 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 109 builder.setOption(PropertyOption.MANDATORY); 110 builder.setOption(PropertyOption.ADVANCED); 111 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class")); 112 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.backends.task.TaskBackend"); 113 builder.setDefaultBehaviorProvider(provider); 114 builder.addInstanceOf("org.opends.server.api.Backend"); 115 PD_JAVA_CLASS = builder.getInstance(); 116 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 117 } 118 119 120 121 /** Build the "notification-sender-address" property definition. */ 122 static { 123 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "notification-sender-address"); 124 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "notification-sender-address")); 125 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<String>(INSTANCE, "notification-sender-address")); 126 PD_NOTIFICATION_SENDER_ADDRESS = builder.getInstance(); 127 INSTANCE.registerPropertyDefinition(PD_NOTIFICATION_SENDER_ADDRESS); 128 } 129 130 131 132 /** Build the "task-backing-file" property definition. */ 133 static { 134 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "task-backing-file"); 135 builder.setOption(PropertyOption.MANDATORY); 136 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "task-backing-file")); 137 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 138 PD_TASK_BACKING_FILE = builder.getInstance(); 139 INSTANCE.registerPropertyDefinition(PD_TASK_BACKING_FILE); 140 } 141 142 143 144 /** Build the "task-retention-time" property definition. */ 145 static { 146 DurationPropertyDefinition.Builder builder = DurationPropertyDefinition.createBuilder(INSTANCE, "task-retention-time"); 147 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "task-retention-time")); 148 DefaultBehaviorProvider<Long> provider = new DefinedDefaultBehaviorProvider<Long>("24 hours"); 149 builder.setDefaultBehaviorProvider(provider); 150 PD_TASK_RETENTION_TIME = builder.getInstance(); 151 INSTANCE.registerPropertyDefinition(PD_TASK_RETENTION_TIME); 152 } 153 154 155 156 /** Build the "writability-mode" property definition. */ 157 static { 158 EnumPropertyDefinition.Builder<WritabilityMode> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "writability-mode"); 159 builder.setOption(PropertyOption.MANDATORY); 160 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "writability-mode")); 161 DefaultBehaviorProvider<WritabilityMode> provider = new DefinedDefaultBehaviorProvider<WritabilityMode>("enabled"); 162 builder.setDefaultBehaviorProvider(provider); 163 builder.setEnumClass(WritabilityMode.class); 164 PD_WRITABILITY_MODE = builder.getInstance(); 165 INSTANCE.registerPropertyDefinition(PD_WRITABILITY_MODE); 166 } 167 168 169 170 // Register the options associated with this managed object definition. 171 static { 172 INSTANCE.registerOption(ManagedObjectOption.ADVANCED); 173 } 174 175 176 177 // Register the tags associated with this managed object definition. 178 static { 179 INSTANCE.registerTag(Tag.valueOf("database")); 180 } 181 182 183 184 /** 185 * Get the Task Backend configuration definition singleton. 186 * 187 * @return Returns the Task Backend configuration definition 188 * singleton. 189 */ 190 public static TaskBackendCfgDefn getInstance() { 191 return INSTANCE; 192 } 193 194 195 196 /** 197 * Private constructor. 198 */ 199 private TaskBackendCfgDefn() { 200 super("task-backend", BackendCfgDefn.getInstance()); 201 } 202 203 204 205 /** {@inheritDoc} */ 206 public TaskBackendCfgClient createClientConfiguration( 207 ManagedObject<? extends TaskBackendCfgClient> impl) { 208 return new TaskBackendCfgClientImpl(impl); 209 } 210 211 212 213 /** {@inheritDoc} */ 214 public TaskBackendCfg createServerConfiguration( 215 ServerManagedObject<? extends TaskBackendCfg> impl) { 216 return new TaskBackendCfgServerImpl(impl); 217 } 218 219 220 221 /** {@inheritDoc} */ 222 public Class<TaskBackendCfg> getServerConfigurationClass() { 223 return TaskBackendCfg.class; 224 } 225 226 227 228 /** 229 * Get the "backend-id" property definition. 230 * <p> 231 * Specifies a name to identify the associated backend. 232 * <p> 233 * The name must be unique among all backends in the server. The 234 * backend ID may not be altered after the backend is created in the 235 * server. 236 * 237 * @return Returns the "backend-id" property definition. 238 */ 239 public StringPropertyDefinition getBackendIdPropertyDefinition() { 240 return BackendCfgDefn.getInstance().getBackendIdPropertyDefinition(); 241 } 242 243 244 245 /** 246 * Get the "base-dn" property definition. 247 * <p> 248 * Specifies the base DN(s) for the data that the backend handles. 249 * <p> 250 * A single backend may be responsible for one or more base DNs. 251 * Note that no two backends may have the same base DN although one 252 * backend may have a base DN that is below a base DN provided by 253 * another backend (similar to the use of sub-suffixes in the Sun 254 * Java System Directory Server). If any of the base DNs is 255 * subordinate to a base DN for another backend, then all base DNs 256 * for that backend must be subordinate to that same base DN. 257 * 258 * @return Returns the "base-dn" property definition. 259 */ 260 public DNPropertyDefinition getBaseDNPropertyDefinition() { 261 return BackendCfgDefn.getInstance().getBaseDNPropertyDefinition(); 262 } 263 264 265 266 /** 267 * Get the "enabled" property definition. 268 * <p> 269 * Indicates whether the backend is enabled in the server. 270 * <p> 271 * If a backend is not enabled, then its contents are not accessible 272 * when processing operations. 273 * 274 * @return Returns the "enabled" property definition. 275 */ 276 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 277 return BackendCfgDefn.getInstance().getEnabledPropertyDefinition(); 278 } 279 280 281 282 /** 283 * Get the "java-class" property definition. 284 * <p> 285 * Specifies the fully-qualified name of the Java class that 286 * provides the backend implementation. 287 * 288 * @return Returns the "java-class" property definition. 289 */ 290 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 291 return PD_JAVA_CLASS; 292 } 293 294 295 296 /** 297 * Get the "notification-sender-address" property definition. 298 * <p> 299 * Specifies the email address to use as the sender (that is, the 300 * "From:" address) address for notification mail messages generated 301 * when a task completes execution. 302 * 303 * @return Returns the "notification-sender-address" property definition. 304 */ 305 public StringPropertyDefinition getNotificationSenderAddressPropertyDefinition() { 306 return PD_NOTIFICATION_SENDER_ADDRESS; 307 } 308 309 310 311 /** 312 * Get the "task-backing-file" property definition. 313 * <p> 314 * Specifies the path to the backing file for storing information 315 * about the tasks configured in the server. 316 * <p> 317 * It may be either an absolute path or a relative path to the base 318 * of the OpenDJ directory server instance. 319 * 320 * @return Returns the "task-backing-file" property definition. 321 */ 322 public StringPropertyDefinition getTaskBackingFilePropertyDefinition() { 323 return PD_TASK_BACKING_FILE; 324 } 325 326 327 328 /** 329 * Get the "task-retention-time" property definition. 330 * <p> 331 * Specifies the length of time that task entries should be retained 332 * after processing on the associated task has been completed. 333 * 334 * @return Returns the "task-retention-time" property definition. 335 */ 336 public DurationPropertyDefinition getTaskRetentionTimePropertyDefinition() { 337 return PD_TASK_RETENTION_TIME; 338 } 339 340 341 342 /** 343 * Get the "writability-mode" property definition. 344 * <p> 345 * Specifies the behavior that the backend should use when 346 * processing write operations. 347 * 348 * @return Returns the "writability-mode" property definition. 349 */ 350 public EnumPropertyDefinition<WritabilityMode> getWritabilityModePropertyDefinition() { 351 return PD_WRITABILITY_MODE; 352 } 353 354 355 356 /** 357 * Managed object client implementation. 358 */ 359 private static class TaskBackendCfgClientImpl implements 360 TaskBackendCfgClient { 361 362 /** Private implementation. */ 363 private ManagedObject<? extends TaskBackendCfgClient> impl; 364 365 366 367 /** Private constructor. */ 368 private TaskBackendCfgClientImpl( 369 ManagedObject<? extends TaskBackendCfgClient> impl) { 370 this.impl = impl; 371 } 372 373 374 375 /** {@inheritDoc} */ 376 public String getBackendId() { 377 return impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition()); 378 } 379 380 381 382 /** {@inheritDoc} */ 383 public void setBackendId(String value) throws PropertyException { 384 impl.setPropertyValue(INSTANCE.getBackendIdPropertyDefinition(), value); 385 } 386 387 388 389 /** {@inheritDoc} */ 390 public SortedSet<DN> getBaseDN() { 391 return impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition()); 392 } 393 394 395 396 /** {@inheritDoc} */ 397 public void setBaseDN(Collection<DN> values) { 398 impl.setPropertyValues(INSTANCE.getBaseDNPropertyDefinition(), values); 399 } 400 401 402 403 /** {@inheritDoc} */ 404 public Boolean isEnabled() { 405 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 406 } 407 408 409 410 /** {@inheritDoc} */ 411 public void setEnabled(boolean value) { 412 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 413 } 414 415 416 417 /** {@inheritDoc} */ 418 public String getJavaClass() { 419 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 420 } 421 422 423 424 /** {@inheritDoc} */ 425 public void setJavaClass(String value) { 426 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 427 } 428 429 430 431 /** {@inheritDoc} */ 432 public String getNotificationSenderAddress() { 433 return impl.getPropertyValue(INSTANCE.getNotificationSenderAddressPropertyDefinition()); 434 } 435 436 437 438 /** {@inheritDoc} */ 439 public void setNotificationSenderAddress(String value) { 440 impl.setPropertyValue(INSTANCE.getNotificationSenderAddressPropertyDefinition(), value); 441 } 442 443 444 445 /** {@inheritDoc} */ 446 public String getTaskBackingFile() { 447 return impl.getPropertyValue(INSTANCE.getTaskBackingFilePropertyDefinition()); 448 } 449 450 451 452 /** {@inheritDoc} */ 453 public void setTaskBackingFile(String value) { 454 impl.setPropertyValue(INSTANCE.getTaskBackingFilePropertyDefinition(), value); 455 } 456 457 458 459 /** {@inheritDoc} */ 460 public long getTaskRetentionTime() { 461 return impl.getPropertyValue(INSTANCE.getTaskRetentionTimePropertyDefinition()); 462 } 463 464 465 466 /** {@inheritDoc} */ 467 public void setTaskRetentionTime(Long value) { 468 impl.setPropertyValue(INSTANCE.getTaskRetentionTimePropertyDefinition(), value); 469 } 470 471 472 473 /** {@inheritDoc} */ 474 public WritabilityMode getWritabilityMode() { 475 return impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition()); 476 } 477 478 479 480 /** {@inheritDoc} */ 481 public void setWritabilityMode(WritabilityMode value) { 482 impl.setPropertyValue(INSTANCE.getWritabilityModePropertyDefinition(), value); 483 } 484 485 486 487 /** {@inheritDoc} */ 488 public ManagedObjectDefinition<? extends TaskBackendCfgClient, ? extends TaskBackendCfg> definition() { 489 return INSTANCE; 490 } 491 492 493 494 /** {@inheritDoc} */ 495 public PropertyProvider properties() { 496 return impl; 497 } 498 499 500 501 /** {@inheritDoc} */ 502 public void commit() throws ManagedObjectAlreadyExistsException, 503 MissingMandatoryPropertiesException, ConcurrentModificationException, 504 OperationRejectedException, LdapException { 505 impl.commit(); 506 } 507 508 509 510 /** {@inheritDoc} */ 511 public String toString() { 512 return impl.toString(); 513 } 514 } 515 516 517 518 /** 519 * Managed object server implementation. 520 */ 521 private static class TaskBackendCfgServerImpl implements 522 TaskBackendCfg { 523 524 /** Private implementation. */ 525 private ServerManagedObject<? extends TaskBackendCfg> impl; 526 527 /** The value of the "backend-id" property. */ 528 private final String pBackendId; 529 530 /** The value of the "base-dn" property. */ 531 private final SortedSet<DN> pBaseDN; 532 533 /** The value of the "enabled" property. */ 534 private final boolean pEnabled; 535 536 /** The value of the "java-class" property. */ 537 private final String pJavaClass; 538 539 /** The value of the "notification-sender-address" property. */ 540 private final String pNotificationSenderAddress; 541 542 /** The value of the "task-backing-file" property. */ 543 private final String pTaskBackingFile; 544 545 /** The value of the "task-retention-time" property. */ 546 private final long pTaskRetentionTime; 547 548 /** The value of the "writability-mode" property. */ 549 private final WritabilityMode pWritabilityMode; 550 551 552 553 /** Private constructor. */ 554 private TaskBackendCfgServerImpl(ServerManagedObject<? extends TaskBackendCfg> impl) { 555 this.impl = impl; 556 this.pBackendId = impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition()); 557 this.pBaseDN = impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition()); 558 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 559 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 560 this.pNotificationSenderAddress = impl.getPropertyValue(INSTANCE.getNotificationSenderAddressPropertyDefinition()); 561 this.pTaskBackingFile = impl.getPropertyValue(INSTANCE.getTaskBackingFilePropertyDefinition()); 562 this.pTaskRetentionTime = impl.getPropertyValue(INSTANCE.getTaskRetentionTimePropertyDefinition()); 563 this.pWritabilityMode = impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition()); 564 } 565 566 567 568 /** {@inheritDoc} */ 569 public void addTaskChangeListener( 570 ConfigurationChangeListener<TaskBackendCfg> listener) { 571 impl.registerChangeListener(listener); 572 } 573 574 575 576 /** {@inheritDoc} */ 577 public void removeTaskChangeListener( 578 ConfigurationChangeListener<TaskBackendCfg> listener) { 579 impl.deregisterChangeListener(listener); 580 } 581 /** {@inheritDoc} */ 582 public void addChangeListener( 583 ConfigurationChangeListener<BackendCfg> listener) { 584 impl.registerChangeListener(listener); 585 } 586 587 588 589 /** {@inheritDoc} */ 590 public void removeChangeListener( 591 ConfigurationChangeListener<BackendCfg> listener) { 592 impl.deregisterChangeListener(listener); 593 } 594 595 596 597 /** {@inheritDoc} */ 598 public String getBackendId() { 599 return pBackendId; 600 } 601 602 603 604 /** {@inheritDoc} */ 605 public SortedSet<DN> getBaseDN() { 606 return pBaseDN; 607 } 608 609 610 611 /** {@inheritDoc} */ 612 public boolean isEnabled() { 613 return pEnabled; 614 } 615 616 617 618 /** {@inheritDoc} */ 619 public String getJavaClass() { 620 return pJavaClass; 621 } 622 623 624 625 /** {@inheritDoc} */ 626 public String getNotificationSenderAddress() { 627 return pNotificationSenderAddress; 628 } 629 630 631 632 /** {@inheritDoc} */ 633 public String getTaskBackingFile() { 634 return pTaskBackingFile; 635 } 636 637 638 639 /** {@inheritDoc} */ 640 public long getTaskRetentionTime() { 641 return pTaskRetentionTime; 642 } 643 644 645 646 /** {@inheritDoc} */ 647 public WritabilityMode getWritabilityMode() { 648 return pWritabilityMode; 649 } 650 651 652 653 /** {@inheritDoc} */ 654 public Class<? extends TaskBackendCfg> configurationClass() { 655 return TaskBackendCfg.class; 656 } 657 658 659 660 /** {@inheritDoc} */ 661 public DN dn() { 662 return impl.getDN(); 663 } 664 665 666 667 /** {@inheritDoc} */ 668 public String toString() { 669 return impl.toString(); 670 } 671 } 672}