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.client.AuthorizationException;
035    import org.opends.server.admin.client.CommunicationException;
036    import org.opends.server.admin.client.ConcurrentModificationException;
037    import org.opends.server.admin.client.ManagedObject;
038    import org.opends.server.admin.client.MissingMandatoryPropertiesException;
039    import org.opends.server.admin.client.OperationRejectedException;
040    import org.opends.server.admin.DefaultBehaviorProvider;
041    import org.opends.server.admin.DefinedDefaultBehaviorProvider;
042    import org.opends.server.admin.DurationPropertyDefinition;
043    import org.opends.server.admin.IntegerPropertyDefinition;
044    import org.opends.server.admin.ManagedObjectAlreadyExistsException;
045    import org.opends.server.admin.ManagedObjectDefinition;
046    import org.opends.server.admin.PropertyIsReadOnlyException;
047    import org.opends.server.admin.PropertyOption;
048    import org.opends.server.admin.PropertyProvider;
049    import org.opends.server.admin.server.ConfigurationChangeListener;
050    import org.opends.server.admin.server.ServerManagedObject;
051    import org.opends.server.admin.std.client.ReplicationServerCfgClient;
052    import org.opends.server.admin.std.server.ReplicationServerCfg;
053    import org.opends.server.admin.StringPropertyDefinition;
054    import org.opends.server.admin.Tag;
055    import org.opends.server.admin.TopCfgDefn;
056    import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
057    import org.opends.server.types.DN;
058    
059    
060    
061    /**
062     * An interface for querying the Replication Server managed object
063     * definition meta information.
064     * <p>
065     * Replication Servers publish updates to Directory Servers within a
066     * Replication Domain.
067     */
068    public final class ReplicationServerCfgDefn extends ManagedObjectDefinition<ReplicationServerCfgClient, ReplicationServerCfg> {
069    
070      // The singleton configuration definition instance.
071      private static final ReplicationServerCfgDefn INSTANCE = new ReplicationServerCfgDefn();
072    
073    
074    
075      // The "queue-size" property definition.
076      private static final IntegerPropertyDefinition PD_QUEUE_SIZE;
077    
078    
079    
080      // The "replication-db-directory" property definition.
081      private static final StringPropertyDefinition PD_REPLICATION_DB_DIRECTORY;
082    
083    
084    
085      // The "replication-port" property definition.
086      private static final IntegerPropertyDefinition PD_REPLICATION_PORT;
087    
088    
089    
090      // The "replication-purge-delay" property definition.
091      private static final DurationPropertyDefinition PD_REPLICATION_PURGE_DELAY;
092    
093    
094    
095      // The "replication-server" property definition.
096      private static final StringPropertyDefinition PD_REPLICATION_SERVER;
097    
098    
099    
100      // The "replication-server-id" property definition.
101      private static final IntegerPropertyDefinition PD_REPLICATION_SERVER_ID;
102    
103    
104    
105      // The "window-size" property definition.
106      private static final IntegerPropertyDefinition PD_WINDOW_SIZE;
107    
108    
109    
110      // Build the "queue-size" property definition.
111      static {
112          IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "queue-size");
113          builder.setOption(PropertyOption.ADVANCED);
114          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "queue-size"));
115          DefaultBehaviorProvider<Integer> provider = new DefinedDefaultBehaviorProvider<Integer>("10000");
116          builder.setDefaultBehaviorProvider(provider);
117          PD_QUEUE_SIZE = builder.getInstance();
118          INSTANCE.registerPropertyDefinition(PD_QUEUE_SIZE);
119      }
120    
121    
122    
123      // Build the "replication-db-directory" property definition.
124      static {
125          StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "replication-db-directory");
126          builder.setOption(PropertyOption.READ_ONLY);
127          builder.setOption(PropertyOption.MANDATORY);
128          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "replication-db-directory"));
129          DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("changelogDb");
130          builder.setDefaultBehaviorProvider(provider);
131          PD_REPLICATION_DB_DIRECTORY = builder.getInstance();
132          INSTANCE.registerPropertyDefinition(PD_REPLICATION_DB_DIRECTORY);
133      }
134    
135    
136    
137      // Build the "replication-port" property definition.
138      static {
139          IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "replication-port");
140          builder.setOption(PropertyOption.MANDATORY);
141          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "replication-port"));
142          builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Integer>());
143          builder.setUpperLimit(65535);
144          builder.setLowerLimit(1);
145          PD_REPLICATION_PORT = builder.getInstance();
146          INSTANCE.registerPropertyDefinition(PD_REPLICATION_PORT);
147      }
148    
149    
150    
151      // Build the "replication-purge-delay" property definition.
152      static {
153          DurationPropertyDefinition.Builder builder = DurationPropertyDefinition.createBuilder(INSTANCE, "replication-purge-delay");
154          builder.setOption(PropertyOption.ADVANCED);
155          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "replication-purge-delay"));
156          DefaultBehaviorProvider<Long> provider = new DefinedDefaultBehaviorProvider<Long>("86400s");
157          builder.setDefaultBehaviorProvider(provider);
158          builder.setAllowUnlimited(false);
159          builder.setBaseUnit("s");
160          PD_REPLICATION_PURGE_DELAY = builder.getInstance();
161          INSTANCE.registerPropertyDefinition(PD_REPLICATION_PURGE_DELAY);
162      }
163    
164    
165    
166      // Build the "replication-server" property definition.
167      static {
168          StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "replication-server");
169          builder.setOption(PropertyOption.MULTI_VALUED);
170          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "replication-server"));
171          builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
172          builder.setPattern("^.+:[0-9]+$", "HOST:PORT");
173          PD_REPLICATION_SERVER = builder.getInstance();
174          INSTANCE.registerPropertyDefinition(PD_REPLICATION_SERVER);
175      }
176    
177    
178    
179      // Build the "replication-server-id" property definition.
180      static {
181          IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "replication-server-id");
182          builder.setOption(PropertyOption.READ_ONLY);
183          builder.setOption(PropertyOption.MANDATORY);
184          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "replication-server-id"));
185          builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Integer>());
186          builder.setUpperLimit(65535);
187          builder.setLowerLimit(1);
188          PD_REPLICATION_SERVER_ID = builder.getInstance();
189          INSTANCE.registerPropertyDefinition(PD_REPLICATION_SERVER_ID);
190      }
191    
192    
193    
194      // Build the "window-size" property definition.
195      static {
196          IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "window-size");
197          builder.setOption(PropertyOption.ADVANCED);
198          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "window-size"));
199          DefaultBehaviorProvider<Integer> provider = new DefinedDefaultBehaviorProvider<Integer>("100");
200          builder.setDefaultBehaviorProvider(provider);
201          PD_WINDOW_SIZE = builder.getInstance();
202          INSTANCE.registerPropertyDefinition(PD_WINDOW_SIZE);
203      }
204    
205    
206    
207      // Register the tags associated with this managed object definition.
208      static {
209        INSTANCE.registerTag(Tag.valueOf("replication"));
210      }
211    
212    
213    
214      /**
215       * Get the Replication Server configuration definition singleton.
216       *
217       * @return Returns the Replication Server configuration definition
218       *         singleton.
219       */
220      public static ReplicationServerCfgDefn getInstance() {
221        return INSTANCE;
222      }
223    
224    
225    
226      /**
227       * Private constructor.
228       */
229      private ReplicationServerCfgDefn() {
230        super("replication-server", TopCfgDefn.getInstance());
231      }
232    
233    
234    
235      /**
236       * {@inheritDoc}
237       */
238      public ReplicationServerCfgClient createClientConfiguration(
239          ManagedObject<? extends ReplicationServerCfgClient> impl) {
240        return new ReplicationServerCfgClientImpl(impl);
241      }
242    
243    
244    
245      /**
246       * {@inheritDoc}
247       */
248      public ReplicationServerCfg createServerConfiguration(
249          ServerManagedObject<? extends ReplicationServerCfg> impl) {
250        return new ReplicationServerCfgServerImpl(impl);
251      }
252    
253    
254    
255      /**
256       * {@inheritDoc}
257       */
258      public Class<ReplicationServerCfg> getServerConfigurationClass() {
259        return ReplicationServerCfg.class;
260      }
261    
262    
263    
264      /**
265       * Get the "queue-size" property definition.
266       * <p>
267       * Specifies the number of changes that are kept in memory for each
268       * Directory Server in the Replication Domain.
269       *
270       * @return Returns the "queue-size" property definition.
271       */
272      public IntegerPropertyDefinition getQueueSizePropertyDefinition() {
273        return PD_QUEUE_SIZE;
274      }
275    
276    
277    
278      /**
279       * Get the "replication-db-directory" property definition.
280       * <p>
281       * The path where the Replication Server stores all persistent
282       * information.
283       *
284       * @return Returns the "replication-db-directory" property definition.
285       */
286      public StringPropertyDefinition getReplicationDBDirectoryPropertyDefinition() {
287        return PD_REPLICATION_DB_DIRECTORY;
288      }
289    
290    
291    
292      /**
293       * Get the "replication-port" property definition.
294       * <p>
295       * The port on which this Replication Server waits for connections
296       * from other Replication Servers or Directory Servers.
297       *
298       * @return Returns the "replication-port" property definition.
299       */
300      public IntegerPropertyDefinition getReplicationPortPropertyDefinition() {
301        return PD_REPLICATION_PORT;
302      }
303    
304    
305    
306      /**
307       * Get the "replication-purge-delay" property definition.
308       * <p>
309       * The time (in seconds) after which the Replication Server erases
310       * all persistent information.
311       *
312       * @return Returns the "replication-purge-delay" property definition.
313       */
314      public DurationPropertyDefinition getReplicationPurgeDelayPropertyDefinition() {
315        return PD_REPLICATION_PURGE_DELAY;
316      }
317    
318    
319    
320      /**
321       * Get the "replication-server" property definition.
322       * <p>
323       * Specifies the addresses of other Replication Servers to which
324       * this Replication Server tries to connect at startup time.
325       * <p>
326       * Addresses must be specified using the syntax: hostname:port
327       *
328       * @return Returns the "replication-server" property definition.
329       */
330      public StringPropertyDefinition getReplicationServerPropertyDefinition() {
331        return PD_REPLICATION_SERVER;
332      }
333    
334    
335    
336      /**
337       * Get the "replication-server-id" property definition.
338       * <p>
339       * Specifies a unique identifier for the Replication Server.
340       * <p>
341       * Each Replication Server must have a different server ID.
342       *
343       * @return Returns the "replication-server-id" property definition.
344       */
345      public IntegerPropertyDefinition getReplicationServerIdPropertyDefinition() {
346        return PD_REPLICATION_SERVER_ID;
347      }
348    
349    
350    
351      /**
352       * Get the "window-size" property definition.
353       * <p>
354       * Specifies the window size that the Replication Server uses when
355       * communicating with other Replication Servers.
356       *
357       * @return Returns the "window-size" property definition.
358       */
359      public IntegerPropertyDefinition getWindowSizePropertyDefinition() {
360        return PD_WINDOW_SIZE;
361      }
362    
363    
364    
365      /**
366       * Managed object client implementation.
367       */
368      private static class ReplicationServerCfgClientImpl implements
369        ReplicationServerCfgClient {
370    
371        // Private implementation.
372        private ManagedObject<? extends ReplicationServerCfgClient> impl;
373    
374    
375    
376        // Private constructor.
377        private ReplicationServerCfgClientImpl(
378            ManagedObject<? extends ReplicationServerCfgClient> impl) {
379          this.impl = impl;
380        }
381    
382    
383    
384        /**
385         * {@inheritDoc}
386         */
387        public int getQueueSize() {
388          return impl.getPropertyValue(INSTANCE.getQueueSizePropertyDefinition());
389        }
390    
391    
392    
393        /**
394         * {@inheritDoc}
395         */
396        public void setQueueSize(Integer value) {
397          impl.setPropertyValue(INSTANCE.getQueueSizePropertyDefinition(), value);
398        }
399    
400    
401    
402        /**
403         * {@inheritDoc}
404         */
405        public String getReplicationDBDirectory() {
406          return impl.getPropertyValue(INSTANCE.getReplicationDBDirectoryPropertyDefinition());
407        }
408    
409    
410    
411        /**
412         * {@inheritDoc}
413         */
414        public void setReplicationDBDirectory(String value) throws PropertyIsReadOnlyException {
415          impl.setPropertyValue(INSTANCE.getReplicationDBDirectoryPropertyDefinition(), value);
416        }
417    
418    
419    
420        /**
421         * {@inheritDoc}
422         */
423        public Integer getReplicationPort() {
424          return impl.getPropertyValue(INSTANCE.getReplicationPortPropertyDefinition());
425        }
426    
427    
428    
429        /**
430         * {@inheritDoc}
431         */
432        public void setReplicationPort(int value) {
433          impl.setPropertyValue(INSTANCE.getReplicationPortPropertyDefinition(), value);
434        }
435    
436    
437    
438        /**
439         * {@inheritDoc}
440         */
441        public long getReplicationPurgeDelay() {
442          return impl.getPropertyValue(INSTANCE.getReplicationPurgeDelayPropertyDefinition());
443        }
444    
445    
446    
447        /**
448         * {@inheritDoc}
449         */
450        public void setReplicationPurgeDelay(Long value) {
451          impl.setPropertyValue(INSTANCE.getReplicationPurgeDelayPropertyDefinition(), value);
452        }
453    
454    
455    
456        /**
457         * {@inheritDoc}
458         */
459        public SortedSet<String> getReplicationServer() {
460          return impl.getPropertyValues(INSTANCE.getReplicationServerPropertyDefinition());
461        }
462    
463    
464    
465        /**
466         * {@inheritDoc}
467         */
468        public void setReplicationServer(Collection<String> values) {
469          impl.setPropertyValues(INSTANCE.getReplicationServerPropertyDefinition(), values);
470        }
471    
472    
473    
474        /**
475         * {@inheritDoc}
476         */
477        public Integer getReplicationServerId() {
478          return impl.getPropertyValue(INSTANCE.getReplicationServerIdPropertyDefinition());
479        }
480    
481    
482    
483        /**
484         * {@inheritDoc}
485         */
486        public void setReplicationServerId(int value) throws PropertyIsReadOnlyException {
487          impl.setPropertyValue(INSTANCE.getReplicationServerIdPropertyDefinition(), value);
488        }
489    
490    
491    
492        /**
493         * {@inheritDoc}
494         */
495        public int getWindowSize() {
496          return impl.getPropertyValue(INSTANCE.getWindowSizePropertyDefinition());
497        }
498    
499    
500    
501        /**
502         * {@inheritDoc}
503         */
504        public void setWindowSize(Integer value) {
505          impl.setPropertyValue(INSTANCE.getWindowSizePropertyDefinition(), value);
506        }
507    
508    
509    
510        /**
511         * {@inheritDoc}
512         */
513        public ManagedObjectDefinition<? extends ReplicationServerCfgClient, ? extends ReplicationServerCfg> definition() {
514          return INSTANCE;
515        }
516    
517    
518    
519        /**
520         * {@inheritDoc}
521         */
522        public PropertyProvider properties() {
523          return impl;
524        }
525    
526    
527    
528        /**
529         * {@inheritDoc}
530         */
531        public void commit() throws ManagedObjectAlreadyExistsException,
532            MissingMandatoryPropertiesException, ConcurrentModificationException,
533            OperationRejectedException, AuthorizationException,
534            CommunicationException {
535          impl.commit();
536        }
537    
538      }
539    
540    
541    
542      /**
543       * Managed object server implementation.
544       */
545      private static class ReplicationServerCfgServerImpl implements
546        ReplicationServerCfg {
547    
548        // Private implementation.
549        private ServerManagedObject<? extends ReplicationServerCfg> impl;
550    
551        // The value of the "queue-size" property.
552        private final int pQueueSize;
553    
554        // The value of the "replication-db-directory" property.
555        private final String pReplicationDBDirectory;
556    
557        // The value of the "replication-port" property.
558        private final int pReplicationPort;
559    
560        // The value of the "replication-purge-delay" property.
561        private final long pReplicationPurgeDelay;
562    
563        // The value of the "replication-server" property.
564        private final SortedSet<String> pReplicationServer;
565    
566        // The value of the "replication-server-id" property.
567        private final int pReplicationServerId;
568    
569        // The value of the "window-size" property.
570        private final int pWindowSize;
571    
572    
573    
574        // Private constructor.
575        private ReplicationServerCfgServerImpl(ServerManagedObject<? extends ReplicationServerCfg> impl) {
576          this.impl = impl;
577          this.pQueueSize = impl.getPropertyValue(INSTANCE.getQueueSizePropertyDefinition());
578          this.pReplicationDBDirectory = impl.getPropertyValue(INSTANCE.getReplicationDBDirectoryPropertyDefinition());
579          this.pReplicationPort = impl.getPropertyValue(INSTANCE.getReplicationPortPropertyDefinition());
580          this.pReplicationPurgeDelay = impl.getPropertyValue(INSTANCE.getReplicationPurgeDelayPropertyDefinition());
581          this.pReplicationServer = impl.getPropertyValues(INSTANCE.getReplicationServerPropertyDefinition());
582          this.pReplicationServerId = impl.getPropertyValue(INSTANCE.getReplicationServerIdPropertyDefinition());
583          this.pWindowSize = impl.getPropertyValue(INSTANCE.getWindowSizePropertyDefinition());
584        }
585    
586    
587    
588        /**
589         * {@inheritDoc}
590         */
591        public void addChangeListener(
592            ConfigurationChangeListener<ReplicationServerCfg> listener) {
593          impl.registerChangeListener(listener);
594        }
595    
596    
597    
598        /**
599         * {@inheritDoc}
600         */
601        public void removeChangeListener(
602            ConfigurationChangeListener<ReplicationServerCfg> listener) {
603          impl.deregisterChangeListener(listener);
604        }
605    
606    
607    
608        /**
609         * {@inheritDoc}
610         */
611        public int getQueueSize() {
612          return pQueueSize;
613        }
614    
615    
616    
617        /**
618         * {@inheritDoc}
619         */
620        public String getReplicationDBDirectory() {
621          return pReplicationDBDirectory;
622        }
623    
624    
625    
626        /**
627         * {@inheritDoc}
628         */
629        public int getReplicationPort() {
630          return pReplicationPort;
631        }
632    
633    
634    
635        /**
636         * {@inheritDoc}
637         */
638        public long getReplicationPurgeDelay() {
639          return pReplicationPurgeDelay;
640        }
641    
642    
643    
644        /**
645         * {@inheritDoc}
646         */
647        public SortedSet<String> getReplicationServer() {
648          return pReplicationServer;
649        }
650    
651    
652    
653        /**
654         * {@inheritDoc}
655         */
656        public int getReplicationServerId() {
657          return pReplicationServerId;
658        }
659    
660    
661    
662        /**
663         * {@inheritDoc}
664         */
665        public int getWindowSize() {
666          return pWindowSize;
667        }
668    
669    
670    
671        /**
672         * {@inheritDoc}
673         */
674        public Class<? extends ReplicationServerCfg> configurationClass() {
675          return ReplicationServerCfg.class;
676        }
677    
678    
679    
680        /**
681         * {@inheritDoc}
682         */
683        public DN dn() {
684          return impl.getDN();
685        }
686    
687      }
688    }