001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2008 Sun Microsystems, Inc. 015 */ 016package org.forgerock.opendj.server.config.meta; 017 018 019 020import org.forgerock.opendj.config.AdministratorAction; 021import org.forgerock.opendj.config.BooleanPropertyDefinition; 022import org.forgerock.opendj.config.ClassPropertyDefinition; 023import org.forgerock.opendj.config.client.ConcurrentModificationException; 024import org.forgerock.opendj.config.client.ManagedObject; 025import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 026import org.forgerock.opendj.config.client.OperationRejectedException; 027import org.forgerock.opendj.config.DefaultBehaviorProvider; 028import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; 029import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 030import org.forgerock.opendj.config.ManagedObjectDefinition; 031import org.forgerock.opendj.config.PropertyOption; 032import org.forgerock.opendj.config.PropertyProvider; 033import org.forgerock.opendj.config.server.ConfigurationChangeListener; 034import org.forgerock.opendj.config.server.ServerManagedObject; 035import org.forgerock.opendj.config.Tag; 036import org.forgerock.opendj.ldap.DN; 037import org.forgerock.opendj.ldap.LdapException; 038import org.forgerock.opendj.server.config.client.EntryCacheMonitorProviderCfgClient; 039import org.forgerock.opendj.server.config.server.EntryCacheMonitorProviderCfg; 040import org.forgerock.opendj.server.config.server.MonitorProviderCfg; 041 042 043 044/** 045 * An interface for querying the Entry Cache Monitor Provider managed 046 * object definition meta information. 047 * <p> 048 * The Entry Cache Monitor Provider exposes monitor information about 049 * the state of OpenDJ directory server entry caches. 050 */ 051public final class EntryCacheMonitorProviderCfgDefn extends ManagedObjectDefinition<EntryCacheMonitorProviderCfgClient, EntryCacheMonitorProviderCfg> { 052 053 /** The singleton configuration definition instance. */ 054 private static final EntryCacheMonitorProviderCfgDefn INSTANCE = new EntryCacheMonitorProviderCfgDefn(); 055 056 057 058 /** The "java-class" property definition. */ 059 private static final ClassPropertyDefinition PD_JAVA_CLASS; 060 061 062 063 /** Build the "java-class" property definition. */ 064 static { 065 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 066 builder.setOption(PropertyOption.MANDATORY); 067 builder.setOption(PropertyOption.ADVANCED); 068 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class")); 069 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.monitors.EntryCacheMonitorProvider"); 070 builder.setDefaultBehaviorProvider(provider); 071 builder.addInstanceOf("org.opends.server.api.MonitorProvider"); 072 PD_JAVA_CLASS = builder.getInstance(); 073 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 074 } 075 076 077 078 // Register the tags associated with this managed object definition. 079 static { 080 INSTANCE.registerTag(Tag.valueOf("core-server")); 081 } 082 083 084 085 /** 086 * Get the Entry Cache Monitor Provider configuration definition 087 * singleton. 088 * 089 * @return Returns the Entry Cache Monitor Provider configuration 090 * definition singleton. 091 */ 092 public static EntryCacheMonitorProviderCfgDefn getInstance() { 093 return INSTANCE; 094 } 095 096 097 098 /** 099 * Private constructor. 100 */ 101 private EntryCacheMonitorProviderCfgDefn() { 102 super("entry-cache-monitor-provider", MonitorProviderCfgDefn.getInstance()); 103 } 104 105 106 107 /** {@inheritDoc} */ 108 public EntryCacheMonitorProviderCfgClient createClientConfiguration( 109 ManagedObject<? extends EntryCacheMonitorProviderCfgClient> impl) { 110 return new EntryCacheMonitorProviderCfgClientImpl(impl); 111 } 112 113 114 115 /** {@inheritDoc} */ 116 public EntryCacheMonitorProviderCfg createServerConfiguration( 117 ServerManagedObject<? extends EntryCacheMonitorProviderCfg> impl) { 118 return new EntryCacheMonitorProviderCfgServerImpl(impl); 119 } 120 121 122 123 /** {@inheritDoc} */ 124 public Class<EntryCacheMonitorProviderCfg> getServerConfigurationClass() { 125 return EntryCacheMonitorProviderCfg.class; 126 } 127 128 129 130 /** 131 * Get the "enabled" property definition. 132 * <p> 133 * Indicates whether the Entry Cache Monitor Provider is enabled for 134 * use. 135 * 136 * @return Returns the "enabled" property definition. 137 */ 138 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 139 return MonitorProviderCfgDefn.getInstance().getEnabledPropertyDefinition(); 140 } 141 142 143 144 /** 145 * Get the "java-class" property definition. 146 * <p> 147 * Specifies the fully-qualified name of the Java class that 148 * provides the Entry Cache Monitor Provider implementation. 149 * 150 * @return Returns the "java-class" property definition. 151 */ 152 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 153 return PD_JAVA_CLASS; 154 } 155 156 157 158 /** 159 * Managed object client implementation. 160 */ 161 private static class EntryCacheMonitorProviderCfgClientImpl implements 162 EntryCacheMonitorProviderCfgClient { 163 164 /** Private implementation. */ 165 private ManagedObject<? extends EntryCacheMonitorProviderCfgClient> impl; 166 167 168 169 /** Private constructor. */ 170 private EntryCacheMonitorProviderCfgClientImpl( 171 ManagedObject<? extends EntryCacheMonitorProviderCfgClient> impl) { 172 this.impl = impl; 173 } 174 175 176 177 /** {@inheritDoc} */ 178 public Boolean isEnabled() { 179 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 180 } 181 182 183 184 /** {@inheritDoc} */ 185 public void setEnabled(boolean value) { 186 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 187 } 188 189 190 191 /** {@inheritDoc} */ 192 public String getJavaClass() { 193 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 194 } 195 196 197 198 /** {@inheritDoc} */ 199 public void setJavaClass(String value) { 200 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 201 } 202 203 204 205 /** {@inheritDoc} */ 206 public ManagedObjectDefinition<? extends EntryCacheMonitorProviderCfgClient, ? extends EntryCacheMonitorProviderCfg> definition() { 207 return INSTANCE; 208 } 209 210 211 212 /** {@inheritDoc} */ 213 public PropertyProvider properties() { 214 return impl; 215 } 216 217 218 219 /** {@inheritDoc} */ 220 public void commit() throws ManagedObjectAlreadyExistsException, 221 MissingMandatoryPropertiesException, ConcurrentModificationException, 222 OperationRejectedException, LdapException { 223 impl.commit(); 224 } 225 226 227 228 /** {@inheritDoc} */ 229 public String toString() { 230 return impl.toString(); 231 } 232 } 233 234 235 236 /** 237 * Managed object server implementation. 238 */ 239 private static class EntryCacheMonitorProviderCfgServerImpl implements 240 EntryCacheMonitorProviderCfg { 241 242 /** Private implementation. */ 243 private ServerManagedObject<? extends EntryCacheMonitorProviderCfg> impl; 244 245 /** The value of the "enabled" property. */ 246 private final boolean pEnabled; 247 248 /** The value of the "java-class" property. */ 249 private final String pJavaClass; 250 251 252 253 /** Private constructor. */ 254 private EntryCacheMonitorProviderCfgServerImpl(ServerManagedObject<? extends EntryCacheMonitorProviderCfg> impl) { 255 this.impl = impl; 256 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 257 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 258 } 259 260 261 262 /** {@inheritDoc} */ 263 public void addEntryCacheChangeListener( 264 ConfigurationChangeListener<EntryCacheMonitorProviderCfg> listener) { 265 impl.registerChangeListener(listener); 266 } 267 268 269 270 /** {@inheritDoc} */ 271 public void removeEntryCacheChangeListener( 272 ConfigurationChangeListener<EntryCacheMonitorProviderCfg> listener) { 273 impl.deregisterChangeListener(listener); 274 } 275 /** {@inheritDoc} */ 276 public void addChangeListener( 277 ConfigurationChangeListener<MonitorProviderCfg> listener) { 278 impl.registerChangeListener(listener); 279 } 280 281 282 283 /** {@inheritDoc} */ 284 public void removeChangeListener( 285 ConfigurationChangeListener<MonitorProviderCfg> listener) { 286 impl.deregisterChangeListener(listener); 287 } 288 289 290 291 /** {@inheritDoc} */ 292 public boolean isEnabled() { 293 return pEnabled; 294 } 295 296 297 298 /** {@inheritDoc} */ 299 public String getJavaClass() { 300 return pJavaClass; 301 } 302 303 304 305 /** {@inheritDoc} */ 306 public Class<? extends EntryCacheMonitorProviderCfg> configurationClass() { 307 return EntryCacheMonitorProviderCfg.class; 308 } 309 310 311 312 /** {@inheritDoc} */ 313 public DN dn() { 314 return impl.getDN(); 315 } 316 317 318 319 /** {@inheritDoc} */ 320 public String toString() { 321 return impl.toString(); 322 } 323 } 324}