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