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.ManagedObjectAlreadyExistsException; 042import org.forgerock.opendj.config.ManagedObjectDefinition; 043import org.forgerock.opendj.config.PropertyOption; 044import org.forgerock.opendj.config.PropertyProvider; 045import org.forgerock.opendj.config.server.ConfigurationChangeListener; 046import org.forgerock.opendj.config.server.ServerManagedObject; 047import org.forgerock.opendj.config.StringPropertyDefinition; 048import org.forgerock.opendj.config.Tag; 049import org.forgerock.opendj.ldap.DN; 050import org.forgerock.opendj.ldap.LdapException; 051import org.forgerock.opendj.server.config.client.JMXAlertHandlerCfgClient; 052import org.forgerock.opendj.server.config.server.AlertHandlerCfg; 053import org.forgerock.opendj.server.config.server.JMXAlertHandlerCfg; 054 055 056 057/** 058 * An interface for querying the JMX Alert Handler managed object 059 * definition meta information. 060 * <p> 061 * The JMX Alert Handler is used to generate JMX notifications to 062 * alert administrators of significant events that occur within the 063 * server. 064 */ 065public final class JMXAlertHandlerCfgDefn extends ManagedObjectDefinition<JMXAlertHandlerCfgClient, JMXAlertHandlerCfg> { 066 067 // The singleton configuration definition instance. 068 private static final JMXAlertHandlerCfgDefn INSTANCE = new JMXAlertHandlerCfgDefn(); 069 070 071 072 // The "java-class" property definition. 073 private static final ClassPropertyDefinition PD_JAVA_CLASS; 074 075 076 077 // Build the "java-class" property definition. 078 static { 079 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 080 builder.setOption(PropertyOption.MANDATORY); 081 builder.setOption(PropertyOption.ADVANCED); 082 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class")); 083 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.JMXAlertHandler"); 084 builder.setDefaultBehaviorProvider(provider); 085 builder.addInstanceOf("org.opends.server.api.AlertHandler"); 086 PD_JAVA_CLASS = builder.getInstance(); 087 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 088 } 089 090 091 092 // Register the tags associated with this managed object definition. 093 static { 094 INSTANCE.registerTag(Tag.valueOf("core-server")); 095 } 096 097 098 099 /** 100 * Get the JMX Alert Handler configuration definition singleton. 101 * 102 * @return Returns the JMX Alert Handler configuration definition 103 * singleton. 104 */ 105 public static JMXAlertHandlerCfgDefn getInstance() { 106 return INSTANCE; 107 } 108 109 110 111 /** 112 * Private constructor. 113 */ 114 private JMXAlertHandlerCfgDefn() { 115 super("jmx-alert-handler", AlertHandlerCfgDefn.getInstance()); 116 } 117 118 119 120 /** 121 * {@inheritDoc} 122 */ 123 public JMXAlertHandlerCfgClient createClientConfiguration( 124 ManagedObject<? extends JMXAlertHandlerCfgClient> impl) { 125 return new JMXAlertHandlerCfgClientImpl(impl); 126 } 127 128 129 130 /** 131 * {@inheritDoc} 132 */ 133 public JMXAlertHandlerCfg createServerConfiguration( 134 ServerManagedObject<? extends JMXAlertHandlerCfg> impl) { 135 return new JMXAlertHandlerCfgServerImpl(impl); 136 } 137 138 139 140 /** 141 * {@inheritDoc} 142 */ 143 public Class<JMXAlertHandlerCfg> getServerConfigurationClass() { 144 return JMXAlertHandlerCfg.class; 145 } 146 147 148 149 /** 150 * Get the "disabled-alert-type" property definition. 151 * <p> 152 * Specifies the names of the alert types that are disabled for this 153 * alert handler. 154 * <p> 155 * If there are any values for this attribute, then no alerts with 156 * any of the specified types are allowed. If there are no values for 157 * this attribute, then only alerts with a type included in the set 158 * of enabled alert types are allowed, or if there are no values for 159 * the enabled alert types option, then all alert types are allowed. 160 * 161 * @return Returns the "disabled-alert-type" property definition. 162 */ 163 public StringPropertyDefinition getDisabledAlertTypePropertyDefinition() { 164 return AlertHandlerCfgDefn.getInstance().getDisabledAlertTypePropertyDefinition(); 165 } 166 167 168 169 /** 170 * Get the "enabled" property definition. 171 * <p> 172 * Indicates whether the JMX Alert Handler is enabled. 173 * 174 * @return Returns the "enabled" property definition. 175 */ 176 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 177 return AlertHandlerCfgDefn.getInstance().getEnabledPropertyDefinition(); 178 } 179 180 181 182 /** 183 * Get the "enabled-alert-type" property definition. 184 * <p> 185 * Specifies the names of the alert types that are enabled for this 186 * alert handler. 187 * <p> 188 * If there are any values for this attribute, then only alerts with 189 * one of the specified types are allowed (unless they are also 190 * included in the disabled alert types). If there are no values for 191 * this attribute, then any alert with a type not included in the 192 * list of disabled alert types is allowed. 193 * 194 * @return Returns the "enabled-alert-type" property definition. 195 */ 196 public StringPropertyDefinition getEnabledAlertTypePropertyDefinition() { 197 return AlertHandlerCfgDefn.getInstance().getEnabledAlertTypePropertyDefinition(); 198 } 199 200 201 202 /** 203 * Get the "java-class" property definition. 204 * <p> 205 * Specifies the fully-qualified name of the Java class that 206 * provides the JMX Alert Handler implementation. 207 * 208 * @return Returns the "java-class" property definition. 209 */ 210 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 211 return PD_JAVA_CLASS; 212 } 213 214 215 216 /** 217 * Managed object client implementation. 218 */ 219 private static class JMXAlertHandlerCfgClientImpl implements 220 JMXAlertHandlerCfgClient { 221 222 // Private implementation. 223 private ManagedObject<? extends JMXAlertHandlerCfgClient> impl; 224 225 226 227 // Private constructor. 228 private JMXAlertHandlerCfgClientImpl( 229 ManagedObject<? extends JMXAlertHandlerCfgClient> impl) { 230 this.impl = impl; 231 } 232 233 234 235 /** 236 * {@inheritDoc} 237 */ 238 public SortedSet<String> getDisabledAlertType() { 239 return impl.getPropertyValues(INSTANCE.getDisabledAlertTypePropertyDefinition()); 240 } 241 242 243 244 /** 245 * {@inheritDoc} 246 */ 247 public void setDisabledAlertType(Collection<String> values) { 248 impl.setPropertyValues(INSTANCE.getDisabledAlertTypePropertyDefinition(), values); 249 } 250 251 252 253 /** 254 * {@inheritDoc} 255 */ 256 public Boolean isEnabled() { 257 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 258 } 259 260 261 262 /** 263 * {@inheritDoc} 264 */ 265 public void setEnabled(boolean value) { 266 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 267 } 268 269 270 271 /** 272 * {@inheritDoc} 273 */ 274 public SortedSet<String> getEnabledAlertType() { 275 return impl.getPropertyValues(INSTANCE.getEnabledAlertTypePropertyDefinition()); 276 } 277 278 279 280 /** 281 * {@inheritDoc} 282 */ 283 public void setEnabledAlertType(Collection<String> values) { 284 impl.setPropertyValues(INSTANCE.getEnabledAlertTypePropertyDefinition(), values); 285 } 286 287 288 289 /** 290 * {@inheritDoc} 291 */ 292 public String getJavaClass() { 293 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 294 } 295 296 297 298 /** 299 * {@inheritDoc} 300 */ 301 public void setJavaClass(String value) { 302 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 303 } 304 305 306 307 /** 308 * {@inheritDoc} 309 */ 310 public ManagedObjectDefinition<? extends JMXAlertHandlerCfgClient, ? extends JMXAlertHandlerCfg> definition() { 311 return INSTANCE; 312 } 313 314 315 316 /** 317 * {@inheritDoc} 318 */ 319 public PropertyProvider properties() { 320 return impl; 321 } 322 323 324 325 /** 326 * {@inheritDoc} 327 */ 328 public void commit() throws ManagedObjectAlreadyExistsException, 329 MissingMandatoryPropertiesException, ConcurrentModificationException, 330 OperationRejectedException, LdapException { 331 impl.commit(); 332 } 333 334 } 335 336 337 338 /** 339 * Managed object server implementation. 340 */ 341 private static class JMXAlertHandlerCfgServerImpl implements 342 JMXAlertHandlerCfg { 343 344 // Private implementation. 345 private ServerManagedObject<? extends JMXAlertHandlerCfg> impl; 346 347 // The value of the "disabled-alert-type" property. 348 private final SortedSet<String> pDisabledAlertType; 349 350 // The value of the "enabled" property. 351 private final boolean pEnabled; 352 353 // The value of the "enabled-alert-type" property. 354 private final SortedSet<String> pEnabledAlertType; 355 356 // The value of the "java-class" property. 357 private final String pJavaClass; 358 359 360 361 // Private constructor. 362 private JMXAlertHandlerCfgServerImpl(ServerManagedObject<? extends JMXAlertHandlerCfg> impl) { 363 this.impl = impl; 364 this.pDisabledAlertType = impl.getPropertyValues(INSTANCE.getDisabledAlertTypePropertyDefinition()); 365 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 366 this.pEnabledAlertType = impl.getPropertyValues(INSTANCE.getEnabledAlertTypePropertyDefinition()); 367 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 368 } 369 370 371 372 /** 373 * {@inheritDoc} 374 */ 375 public void addJMXChangeListener( 376 ConfigurationChangeListener<JMXAlertHandlerCfg> listener) { 377 impl.registerChangeListener(listener); 378 } 379 380 381 382 /** 383 * {@inheritDoc} 384 */ 385 public void removeJMXChangeListener( 386 ConfigurationChangeListener<JMXAlertHandlerCfg> listener) { 387 impl.deregisterChangeListener(listener); 388 } 389 /** 390 * {@inheritDoc} 391 */ 392 public void addChangeListener( 393 ConfigurationChangeListener<AlertHandlerCfg> listener) { 394 impl.registerChangeListener(listener); 395 } 396 397 398 399 /** 400 * {@inheritDoc} 401 */ 402 public void removeChangeListener( 403 ConfigurationChangeListener<AlertHandlerCfg> listener) { 404 impl.deregisterChangeListener(listener); 405 } 406 407 408 409 /** 410 * {@inheritDoc} 411 */ 412 public SortedSet<String> getDisabledAlertType() { 413 return pDisabledAlertType; 414 } 415 416 417 418 /** 419 * {@inheritDoc} 420 */ 421 public boolean isEnabled() { 422 return pEnabled; 423 } 424 425 426 427 /** 428 * {@inheritDoc} 429 */ 430 public SortedSet<String> getEnabledAlertType() { 431 return pEnabledAlertType; 432 } 433 434 435 436 /** 437 * {@inheritDoc} 438 */ 439 public String getJavaClass() { 440 return pJavaClass; 441 } 442 443 444 445 /** 446 * {@inheritDoc} 447 */ 448 public Class<? extends JMXAlertHandlerCfg> configurationClass() { 449 return JMXAlertHandlerCfg.class; 450 } 451 452 453 454 /** 455 * {@inheritDoc} 456 */ 457 public DN dn() { 458 return impl.getDN(); 459 } 460 461 } 462}