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 java.util.Collection;
021import org.forgerock.opendj.config.AdministratorAction;
022import org.forgerock.opendj.config.AliasDefaultBehaviorProvider;
023import org.forgerock.opendj.config.BooleanPropertyDefinition;
024import org.forgerock.opendj.config.ClassPropertyDefinition;
025import org.forgerock.opendj.config.client.ConcurrentModificationException;
026import org.forgerock.opendj.config.client.IllegalManagedObjectNameException;
027import org.forgerock.opendj.config.client.ManagedObject;
028import org.forgerock.opendj.config.client.ManagedObjectDecodingException;
029import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
030import org.forgerock.opendj.config.client.OperationRejectedException;
031import org.forgerock.opendj.config.DefaultBehaviorProvider;
032import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider;
033import org.forgerock.opendj.config.DefinitionDecodingException;
034import org.forgerock.opendj.config.DurationPropertyDefinition;
035import org.forgerock.opendj.config.InstantiableRelationDefinition;
036import org.forgerock.opendj.config.IntegerPropertyDefinition;
037import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
038import org.forgerock.opendj.config.ManagedObjectDefinition;
039import org.forgerock.opendj.config.ManagedObjectNotFoundException;
040import org.forgerock.opendj.config.OptionalRelationDefinition;
041import org.forgerock.opendj.config.PropertyException;
042import org.forgerock.opendj.config.PropertyOption;
043import org.forgerock.opendj.config.PropertyProvider;
044import org.forgerock.opendj.config.server.ConfigException;
045import org.forgerock.opendj.config.server.ConfigurationAddListener;
046import org.forgerock.opendj.config.server.ConfigurationChangeListener;
047import org.forgerock.opendj.config.server.ConfigurationDeleteListener;
048import org.forgerock.opendj.config.server.ServerManagedObject;
049import org.forgerock.opendj.config.Tag;
050import org.forgerock.opendj.ldap.DN;
051import org.forgerock.opendj.ldap.LdapException;
052import org.forgerock.opendj.server.config.client.ReplicationDomainCfgClient;
053import org.forgerock.opendj.server.config.client.ReplicationServerCfgClient;
054import org.forgerock.opendj.server.config.client.ReplicationSynchronizationProviderCfgClient;
055import org.forgerock.opendj.server.config.server.ReplicationDomainCfg;
056import org.forgerock.opendj.server.config.server.ReplicationServerCfg;
057import org.forgerock.opendj.server.config.server.ReplicationSynchronizationProviderCfg;
058import org.forgerock.opendj.server.config.server.SynchronizationProviderCfg;
059
060
061
062/**
063 * An interface for querying the Replication Synchronization Provider
064 * managed object definition meta information.
065 * <p>
066 * The Replication Synchronization Provider provides multi-master
067 * replication of data across multiple directory server instances.
068 */
069public final class ReplicationSynchronizationProviderCfgDefn extends ManagedObjectDefinition<ReplicationSynchronizationProviderCfgClient, ReplicationSynchronizationProviderCfg> {
070
071  /** The singleton configuration definition instance. */
072  private static final ReplicationSynchronizationProviderCfgDefn INSTANCE = new ReplicationSynchronizationProviderCfgDefn();
073
074
075
076  /** The "connection-timeout" property definition. */
077  private static final DurationPropertyDefinition PD_CONNECTION_TIMEOUT;
078
079
080
081  /** The "java-class" property definition. */
082  private static final ClassPropertyDefinition PD_JAVA_CLASS;
083
084
085
086  /** The "num-update-replay-threads" property definition. */
087  private static final IntegerPropertyDefinition PD_NUM_UPDATE_REPLAY_THREADS;
088
089
090
091  /** The "replication-domains" relation definition. */
092  private static final InstantiableRelationDefinition<ReplicationDomainCfgClient, ReplicationDomainCfg> RD_REPLICATION_DOMAINS;
093
094
095
096  /** The "replication-server" relation definition. */
097  private static final OptionalRelationDefinition<ReplicationServerCfgClient, ReplicationServerCfg> RD_REPLICATION_SERVER;
098
099
100
101  /** Build the "connection-timeout" property definition. */
102  static {
103      DurationPropertyDefinition.Builder builder = DurationPropertyDefinition.createBuilder(INSTANCE, "connection-timeout");
104      builder.setOption(PropertyOption.ADVANCED);
105      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "connection-timeout"));
106      DefaultBehaviorProvider<Long> provider = new DefinedDefaultBehaviorProvider<Long>("5 seconds");
107      builder.setDefaultBehaviorProvider(provider);
108      builder.setBaseUnit("ms");
109      builder.setLowerLimit("0");
110      PD_CONNECTION_TIMEOUT = builder.getInstance();
111      INSTANCE.registerPropertyDefinition(PD_CONNECTION_TIMEOUT);
112  }
113
114
115
116  /** Build the "java-class" property definition. */
117  static {
118      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
119      builder.setOption(PropertyOption.MANDATORY);
120      builder.setOption(PropertyOption.ADVANCED);
121      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
122      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.replication.plugin.MultimasterReplication");
123      builder.setDefaultBehaviorProvider(provider);
124      builder.addInstanceOf("org.opends.server.api.SynchronizationProvider");
125      PD_JAVA_CLASS = builder.getInstance();
126      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
127  }
128
129
130
131  /** Build the "num-update-replay-threads" property definition. */
132  static {
133      IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "num-update-replay-threads");
134      builder.setOption(PropertyOption.ADVANCED);
135      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "num-update-replay-threads"));
136      builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<Integer>(INSTANCE, "num-update-replay-threads"));
137      builder.setUpperLimit(65535);
138      builder.setLowerLimit(1);
139      PD_NUM_UPDATE_REPLAY_THREADS = builder.getInstance();
140      INSTANCE.registerPropertyDefinition(PD_NUM_UPDATE_REPLAY_THREADS);
141  }
142
143
144
145  // Build the "replication-domains" relation definition.
146  static {
147    InstantiableRelationDefinition.Builder<ReplicationDomainCfgClient, ReplicationDomainCfg> builder =
148      new InstantiableRelationDefinition.Builder<ReplicationDomainCfgClient, ReplicationDomainCfg>(INSTANCE, "replication-domain", "replication-domains", ReplicationDomainCfgDefn.getInstance());
149    RD_REPLICATION_DOMAINS = builder.getInstance();
150    INSTANCE.registerRelationDefinition(RD_REPLICATION_DOMAINS);
151  }
152
153
154
155  // Build the "replication-server" relation definition.
156  static {
157    OptionalRelationDefinition.Builder<ReplicationServerCfgClient, ReplicationServerCfg> builder =
158      new OptionalRelationDefinition.Builder<ReplicationServerCfgClient, ReplicationServerCfg>(INSTANCE, "replication-server", ReplicationServerCfgDefn.getInstance());
159    RD_REPLICATION_SERVER = builder.getInstance();
160    INSTANCE.registerRelationDefinition(RD_REPLICATION_SERVER);
161  }
162
163
164
165  // Register the tags associated with this managed object definition.
166  static {
167    INSTANCE.registerTag(Tag.valueOf("replication"));
168  }
169
170
171
172  /**
173   * Get the Replication Synchronization Provider configuration
174   * definition singleton.
175   *
176   * @return Returns the Replication Synchronization Provider
177   *         configuration definition singleton.
178   */
179  public static ReplicationSynchronizationProviderCfgDefn getInstance() {
180    return INSTANCE;
181  }
182
183
184
185  /**
186   * Private constructor.
187   */
188  private ReplicationSynchronizationProviderCfgDefn() {
189    super("replication-synchronization-provider", SynchronizationProviderCfgDefn.getInstance());
190  }
191
192
193
194  /** {@inheritDoc} */
195  public ReplicationSynchronizationProviderCfgClient createClientConfiguration(
196      ManagedObject<? extends ReplicationSynchronizationProviderCfgClient> impl) {
197    return new ReplicationSynchronizationProviderCfgClientImpl(impl);
198  }
199
200
201
202  /** {@inheritDoc} */
203  public ReplicationSynchronizationProviderCfg createServerConfiguration(
204      ServerManagedObject<? extends ReplicationSynchronizationProviderCfg> impl) {
205    return new ReplicationSynchronizationProviderCfgServerImpl(impl);
206  }
207
208
209
210  /** {@inheritDoc} */
211  public Class<ReplicationSynchronizationProviderCfg> getServerConfigurationClass() {
212    return ReplicationSynchronizationProviderCfg.class;
213  }
214
215
216
217  /**
218   * Get the "connection-timeout" property definition.
219   * <p>
220   * Specifies the timeout used when connecting to peers and when
221   * performing SSL negotiation.
222   *
223   * @return Returns the "connection-timeout" property definition.
224   */
225  public DurationPropertyDefinition getConnectionTimeoutPropertyDefinition() {
226    return PD_CONNECTION_TIMEOUT;
227  }
228
229
230
231  /**
232   * Get the "enabled" property definition.
233   * <p>
234   * Indicates whether the Replication Synchronization Provider is
235   * enabled for use.
236   *
237   * @return Returns the "enabled" property definition.
238   */
239  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
240    return SynchronizationProviderCfgDefn.getInstance().getEnabledPropertyDefinition();
241  }
242
243
244
245  /**
246   * Get the "java-class" property definition.
247   * <p>
248   * Specifies the fully-qualified name of the Java class that
249   * provides the Replication Synchronization Provider implementation.
250   *
251   * @return Returns the "java-class" property definition.
252   */
253  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
254    return PD_JAVA_CLASS;
255  }
256
257
258
259  /**
260   * Get the "num-update-replay-threads" property definition.
261   * <p>
262   * Specifies the number of update replay threads.
263   * <p>
264   * This value is the number of threads created for replaying every
265   * updates received for all the replication domains.
266   *
267   * @return Returns the "num-update-replay-threads" property definition.
268   */
269  public IntegerPropertyDefinition getNumUpdateReplayThreadsPropertyDefinition() {
270    return PD_NUM_UPDATE_REPLAY_THREADS;
271  }
272
273
274
275  /**
276   * Get the "replication-domains" relation definition.
277   *
278   * @return Returns the "replication-domains" relation definition.
279   */
280  public InstantiableRelationDefinition<ReplicationDomainCfgClient,ReplicationDomainCfg> getReplicationDomainsRelationDefinition() {
281    return RD_REPLICATION_DOMAINS;
282  }
283
284
285
286  /**
287   * Get the "replication-server" relation definition.
288   *
289   * @return Returns the "replication-server" relation definition.
290   */
291  public OptionalRelationDefinition<ReplicationServerCfgClient,ReplicationServerCfg> getReplicationServerRelationDefinition() {
292    return RD_REPLICATION_SERVER;
293  }
294
295
296
297  /**
298   * Managed object client implementation.
299   */
300  private static class ReplicationSynchronizationProviderCfgClientImpl implements
301    ReplicationSynchronizationProviderCfgClient {
302
303    /** Private implementation. */
304    private ManagedObject<? extends ReplicationSynchronizationProviderCfgClient> impl;
305
306
307
308    /** Private constructor. */
309    private ReplicationSynchronizationProviderCfgClientImpl(
310        ManagedObject<? extends ReplicationSynchronizationProviderCfgClient> impl) {
311      this.impl = impl;
312    }
313
314
315
316    /** {@inheritDoc} */
317    public long getConnectionTimeout() {
318      return impl.getPropertyValue(INSTANCE.getConnectionTimeoutPropertyDefinition());
319    }
320
321
322
323    /** {@inheritDoc} */
324    public void setConnectionTimeout(Long value) {
325      impl.setPropertyValue(INSTANCE.getConnectionTimeoutPropertyDefinition(), value);
326    }
327
328
329
330    /** {@inheritDoc} */
331    public Boolean isEnabled() {
332      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
333    }
334
335
336
337    /** {@inheritDoc} */
338    public void setEnabled(boolean value) {
339      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
340    }
341
342
343
344    /** {@inheritDoc} */
345    public String getJavaClass() {
346      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
347    }
348
349
350
351    /** {@inheritDoc} */
352    public void setJavaClass(String value) {
353      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
354    }
355
356
357
358    /** {@inheritDoc} */
359    public Integer getNumUpdateReplayThreads() {
360      return impl.getPropertyValue(INSTANCE.getNumUpdateReplayThreadsPropertyDefinition());
361    }
362
363
364
365    /** {@inheritDoc} */
366    public void setNumUpdateReplayThreads(Integer value) {
367      impl.setPropertyValue(INSTANCE.getNumUpdateReplayThreadsPropertyDefinition(), value);
368    }
369
370
371
372    /** {@inheritDoc} */
373    public String[] listReplicationDomains() throws ConcurrentModificationException,
374        LdapException {
375      return impl.listChildren(INSTANCE.getReplicationDomainsRelationDefinition());
376    }
377
378
379
380    /** {@inheritDoc} */
381    public ReplicationDomainCfgClient getReplicationDomain(String name)
382        throws DefinitionDecodingException, ManagedObjectDecodingException,
383        ManagedObjectNotFoundException, ConcurrentModificationException,
384        LdapException {
385      return impl.getChild(INSTANCE.getReplicationDomainsRelationDefinition(), name).getConfiguration();
386    }
387
388
389
390    /** {@inheritDoc} */
391    public <M extends ReplicationDomainCfgClient> M createReplicationDomain(
392        ManagedObjectDefinition<M, ? extends ReplicationDomainCfg> d, String name, Collection<PropertyException> exceptions) throws IllegalManagedObjectNameException {
393      return impl.createChild(INSTANCE.getReplicationDomainsRelationDefinition(), d, name, exceptions).getConfiguration();
394    }
395
396
397
398    /** {@inheritDoc} */
399    public void removeReplicationDomain(String name)
400        throws ManagedObjectNotFoundException, ConcurrentModificationException,
401        OperationRejectedException, LdapException {
402      impl.removeChild(INSTANCE.getReplicationDomainsRelationDefinition(), name);
403    }
404
405
406
407    /** {@inheritDoc} */
408    public boolean hasReplicationServer() throws ConcurrentModificationException,
409        LdapException {
410      return impl.hasChild(INSTANCE.getReplicationServerRelationDefinition());
411    }
412
413
414
415    /** {@inheritDoc} */
416    public ReplicationServerCfgClient getReplicationServer()
417        throws DefinitionDecodingException, ManagedObjectDecodingException,
418        ManagedObjectNotFoundException, ConcurrentModificationException,
419        LdapException {
420      return impl.getChild(INSTANCE.getReplicationServerRelationDefinition()).getConfiguration();
421    }
422
423
424
425    /** {@inheritDoc} */
426    public <M extends ReplicationServerCfgClient> M createReplicationServer(
427        ManagedObjectDefinition<M, ? extends ReplicationServerCfg> d, Collection<PropertyException> exceptions) {
428      return impl.createChild(INSTANCE.getReplicationServerRelationDefinition(), d, exceptions).getConfiguration();
429    }
430
431
432
433    /** {@inheritDoc} */
434    public void removeReplicationServer()
435        throws ManagedObjectNotFoundException, ConcurrentModificationException,
436        OperationRejectedException, LdapException {
437      impl.removeChild(INSTANCE.getReplicationServerRelationDefinition());
438    }
439
440
441
442    /** {@inheritDoc} */
443    public ManagedObjectDefinition<? extends ReplicationSynchronizationProviderCfgClient, ? extends ReplicationSynchronizationProviderCfg> definition() {
444      return INSTANCE;
445    }
446
447
448
449    /** {@inheritDoc} */
450    public PropertyProvider properties() {
451      return impl;
452    }
453
454
455
456    /** {@inheritDoc} */
457    public void commit() throws ManagedObjectAlreadyExistsException,
458        MissingMandatoryPropertiesException, ConcurrentModificationException,
459        OperationRejectedException, LdapException {
460      impl.commit();
461    }
462
463
464
465    /** {@inheritDoc} */
466    public String toString() {
467      return impl.toString();
468    }
469  }
470
471
472
473  /**
474   * Managed object server implementation.
475   */
476  private static class ReplicationSynchronizationProviderCfgServerImpl implements
477    ReplicationSynchronizationProviderCfg {
478
479    /** Private implementation. */
480    private ServerManagedObject<? extends ReplicationSynchronizationProviderCfg> impl;
481
482    /** The value of the "connection-timeout" property. */
483    private final long pConnectionTimeout;
484
485    /** The value of the "enabled" property. */
486    private final boolean pEnabled;
487
488    /** The value of the "java-class" property. */
489    private final String pJavaClass;
490
491    /** The value of the "num-update-replay-threads" property. */
492    private final Integer pNumUpdateReplayThreads;
493
494
495
496    /** Private constructor. */
497    private ReplicationSynchronizationProviderCfgServerImpl(ServerManagedObject<? extends ReplicationSynchronizationProviderCfg> impl) {
498      this.impl = impl;
499      this.pConnectionTimeout = impl.getPropertyValue(INSTANCE.getConnectionTimeoutPropertyDefinition());
500      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
501      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
502      this.pNumUpdateReplayThreads = impl.getPropertyValue(INSTANCE.getNumUpdateReplayThreadsPropertyDefinition());
503    }
504
505
506
507    /** {@inheritDoc} */
508    public void addReplicationChangeListener(
509        ConfigurationChangeListener<ReplicationSynchronizationProviderCfg> listener) {
510      impl.registerChangeListener(listener);
511    }
512
513
514
515    /** {@inheritDoc} */
516    public void removeReplicationChangeListener(
517        ConfigurationChangeListener<ReplicationSynchronizationProviderCfg> listener) {
518      impl.deregisterChangeListener(listener);
519    }
520    /** {@inheritDoc} */
521    public void addChangeListener(
522        ConfigurationChangeListener<SynchronizationProviderCfg> listener) {
523      impl.registerChangeListener(listener);
524    }
525
526
527
528    /** {@inheritDoc} */
529    public void removeChangeListener(
530        ConfigurationChangeListener<SynchronizationProviderCfg> listener) {
531      impl.deregisterChangeListener(listener);
532    }
533
534
535
536    /** {@inheritDoc} */
537    public long getConnectionTimeout() {
538      return pConnectionTimeout;
539    }
540
541
542
543    /** {@inheritDoc} */
544    public boolean isEnabled() {
545      return pEnabled;
546    }
547
548
549
550    /** {@inheritDoc} */
551    public String getJavaClass() {
552      return pJavaClass;
553    }
554
555
556
557    /** {@inheritDoc} */
558    public Integer getNumUpdateReplayThreads() {
559      return pNumUpdateReplayThreads;
560    }
561
562
563
564    /** {@inheritDoc} */
565    public String[] listReplicationDomains() {
566      return impl.listChildren(INSTANCE.getReplicationDomainsRelationDefinition());
567    }
568
569
570
571    /** {@inheritDoc} */
572    public ReplicationDomainCfg getReplicationDomain(String name) throws ConfigException {
573      return impl.getChild(INSTANCE.getReplicationDomainsRelationDefinition(), name).getConfiguration();
574    }
575
576
577
578    /** {@inheritDoc} */
579    public void addReplicationDomainAddListener(
580        ConfigurationAddListener<ReplicationDomainCfg> listener) throws ConfigException {
581      impl.registerAddListener(INSTANCE.getReplicationDomainsRelationDefinition(), listener);
582    }
583
584
585
586    /** {@inheritDoc} */
587    public void removeReplicationDomainAddListener(
588        ConfigurationAddListener<ReplicationDomainCfg> listener) {
589      impl.deregisterAddListener(INSTANCE.getReplicationDomainsRelationDefinition(), listener);
590    }
591
592
593
594    /** {@inheritDoc} */
595    public void addReplicationDomainDeleteListener(
596        ConfigurationDeleteListener<ReplicationDomainCfg> listener) throws ConfigException {
597      impl.registerDeleteListener(INSTANCE.getReplicationDomainsRelationDefinition(), listener);
598    }
599
600
601
602    /** {@inheritDoc} */
603    public void removeReplicationDomainDeleteListener(
604        ConfigurationDeleteListener<ReplicationDomainCfg> listener) {
605      impl.deregisterDeleteListener(INSTANCE.getReplicationDomainsRelationDefinition(), listener);
606    }
607
608
609
610    /** {@inheritDoc} */
611    public boolean hasReplicationServer() {
612      return impl.hasChild(INSTANCE.getReplicationServerRelationDefinition());
613    }
614
615
616
617    /** {@inheritDoc} */
618    public ReplicationServerCfg getReplicationServer() throws ConfigException {
619      return impl.getChild(INSTANCE.getReplicationServerRelationDefinition()).getConfiguration();
620    }
621
622
623
624    /** {@inheritDoc} */
625    public void addReplicationServerAddListener(
626        ConfigurationAddListener<ReplicationServerCfg> listener) throws ConfigException {
627      impl.registerAddListener(INSTANCE.getReplicationServerRelationDefinition(), listener);
628    }
629
630
631
632    /** {@inheritDoc} */
633    public void removeReplicationServerAddListener(
634        ConfigurationAddListener<ReplicationServerCfg> listener) {
635      impl.deregisterAddListener(INSTANCE.getReplicationServerRelationDefinition(), listener);
636    }
637
638
639
640    /** {@inheritDoc} */
641    public void addReplicationServerDeleteListener(
642        ConfigurationDeleteListener<ReplicationServerCfg> listener) throws ConfigException {
643      impl.registerDeleteListener(INSTANCE.getReplicationServerRelationDefinition(), listener);
644    }
645
646
647
648    /** {@inheritDoc} */
649    public void removeReplicationServerDeleteListener(
650        ConfigurationDeleteListener<ReplicationServerCfg> listener) {
651      impl.deregisterDeleteListener(INSTANCE.getReplicationServerRelationDefinition(), listener);
652    }
653
654
655
656    /** {@inheritDoc} */
657    public Class<? extends ReplicationSynchronizationProviderCfg> configurationClass() {
658      return ReplicationSynchronizationProviderCfg.class;
659    }
660
661
662
663    /** {@inheritDoc} */
664    public DN dn() {
665      return impl.getDN();
666    }
667
668
669
670    /** {@inheritDoc} */
671    public String toString() {
672      return impl.toString();
673    }
674  }
675}