001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 *
019 */
020
021 package org.apache.directory.server.ldap.replication;
022
023
024 import org.apache.directory.shared.ldap.codec.util.LdapURLEncodingException;
025 import org.apache.directory.shared.ldap.exception.LdapInvalidDnException;
026 import org.apache.directory.shared.ldap.name.DN;
027 import org.apache.directory.shared.ldap.util.LdapURL;
028 import org.apache.directory.shared.ldap.util.StringTools;
029
030 /**
031 * A configuration for a replica peer. We may have many replications relation
032 * set for a server, each one of them being described with this structure.
033 *
034 * @org.apache.xbean.XBean
035 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
036 * @version $Rev$, $Date$
037 */
038 public class ReplicaPeerConfiguration
039 {
040 /** A flag used when the replication use the RefreshOnly system */
041 private boolean refreshOnly;
042
043 /** The time to wait between two consecutive RefreshOnly replication*/
044 private long interval;
045
046 /** Default interval is 5 minutes */
047 private static final long DEFAULT_INTERVAL = 1000L*5L*60L;
048
049 /** The default host */
050 private static final String DEFAULT_HOST = "localhost";
051
052 /** The default ssl port */
053 private static final int DEFAULT_PORT = 10389;
054
055 /** The default port */
056 private static final int DEFAULT_SSL_PORT = 10636;
057
058 /** The producer we want to replicate */
059 private LdapURL producer;
060
061 /** The principal to use to connect to the producer */
062 private DN principalDN;
063
064 /** The principal's password */
065 private String password;
066
067 /** The producer's host */
068 private String host;
069
070 /** The producer's port */
071 private int port;
072
073 /** The base DN used for replication */
074 private DN baseDN;
075
076 /** A flag to tell the server to use an SSL connection */
077 private boolean useSSL;
078
079
080 /**
081 *
082 * Creates a new instance of ConsumerConfiguration.
083 *
084 */
085 public ReplicaPeerConfiguration()
086 {
087 interval = DEFAULT_INTERVAL;
088 }
089
090 /**
091 * Set the type of replication wanted. If false, it will default
092 * to RefreshAndPersist.
093 * @param refreshOnly true if the refreshOnly replication is requested
094 */
095 public void setRefreshOnly( boolean refreshOnly )
096 {
097 this.refreshOnly = refreshOnly;
098 }
099
100 /**
101 * @return the refreshOnly flag
102 */
103 public boolean isRefreshOnly()
104 {
105 return refreshOnly;
106 }
107
108 /**
109 * Set the delay between two RefreshOnly replication. Its given in seconds.
110 * @param interval the interval to set
111 */
112 public void setInterval( long interval )
113 {
114 // Convert to milliseconds
115 this.interval = interval*1000L;
116 }
117
118 /**
119 * @return the interval
120 */
121 public long getInterval()
122 {
123 return interval;
124 }
125
126 /**
127 * @return the baseDN
128 */
129 public DN getBaseDN()
130 {
131 return baseDN;
132 }
133
134 /**
135 * @param principalDN the principalDN to set
136 */
137 public void setPrincipalDN( String principalDN ) throws LdapInvalidDnException
138 {
139 this.principalDN = new DN( principalDN );
140 }
141
142
143 /**
144 * @return the principalDN
145 */
146 public DN getPrincipalDN()
147 {
148 return principalDN;
149 }
150
151
152 /**
153 * @param password the password to set
154 */
155 public void setPassword( String password )
156 {
157 this.password = password;
158 }
159
160 /**
161 * @return the password
162 */
163 public String getPassword()
164 {
165 return password;
166 }
167
168 /**
169 * @param producer the producer to set
170 */
171 public void setProducer( String producer ) throws LdapURLEncodingException
172 {
173 this.producer = new LdapURL( producer );
174
175 // Update the other fields
176 baseDN = this.producer.getDn();
177 useSSL = "ldaps".equalsIgnoreCase( this.producer.getScheme() );
178 host = this.producer.getHost();
179
180 if ( StringTools.isEmpty( host ) )
181 {
182 host = DEFAULT_HOST;
183 }
184
185 port = this.producer.getPort();
186
187 if ( port == -1 )
188 {
189 if ( useSSL )
190 {
191 port = DEFAULT_SSL_PORT;
192 }
193 else
194 {
195 port = DEFAULT_PORT;
196 }
197 }
198 }
199
200
201 /**
202 * @return the producer
203 */
204 public LdapURL getProducer()
205 {
206 return producer;
207 }
208
209
210 /**
211 * @return true if the connection with the producer is done using SSL
212 */
213 public boolean isUseSSL()
214 {
215 return useSSL;
216 }
217
218
219 /**
220 * @return the producer's host
221 */
222 public String getHost()
223 {
224 return host;
225 }
226
227
228 /**
229 * @return the producer's port
230 */
231 public int getPort()
232 {
233 return port;
234 }
235 }