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