View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.api.ldap.extras.extended.gracefulDisconnect;
21  
22  
23  import org.apache.directory.api.i18n.I18n;
24  import org.apache.directory.api.ldap.model.message.ExtendedResponseImpl;
25  import org.apache.directory.api.ldap.model.message.Referral;
26  import org.apache.directory.api.ldap.model.message.ReferralImpl;
27  import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
28  
29  
30  /**
31   * An unsolicited notification, extended response, intended for notifying
32   * clients of up coming disconnection due to intended service windows. Unlike the
33   * {@link org.apache.directory.api.ldap.model.message.extended.NoticeOfDisconnect} this response contains additional information about
34   * the amount of time the server will be offline and exactly when it intends to
35   * shutdown.
36   * 
37   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
38   */
39  public class GracefulDisconnectResponseImpl extends ExtendedResponseImpl implements GracefulDisconnectResponse
40  {
41      /** Offline time after disconnection */
42      private int timeOffline;
43  
44      /** Delay before disconnection */
45      private int delay;
46  
47      /** String based LDAP URL that may be followed for replicated namingContexts */
48      private Referral replicatedContexts = new ReferralImpl();
49  
50  
51      /**
52       * Instantiates a new graceful disconnect.
53       */
54      public GracefulDisconnectResponseImpl()
55      {
56          super( 0, EXTENSION_OID );
57      }
58  
59  
60      /**
61       * Instantiates a new graceful disconnect.
62       *
63       * @param timeOffline the offline time after disconnect, in minutes
64       * @param delay the delay before disconnect, in seconds
65       */
66      public GracefulDisconnectResponseImpl( int timeOffline, int delay )
67      {
68          super( 0, EXTENSION_OID );
69          responseName = EXTENSION_OID;
70          this.timeOffline = timeOffline;
71          this.delay = delay;
72  
73          StringBuffer buf = new StringBuffer();
74          buf.append( "The server will disconnect and will be unavailable for " ).append( timeOffline );
75          buf.append( " minutes in " ).append( delay ).append( " seconds." );
76  
77          ldapResult.setDiagnosticMessage( buf.toString() );
78          ldapResult.setMatchedDn( null );
79          ldapResult.setResultCode( ResultCodeEnum.UNAVAILABLE );
80      }
81  
82  
83      /**
84       * Gets the OID uniquely identifying this extended response (a.k.a. its
85       * name).
86       * 
87       * @return the OID of the extended response type.
88       */
89      public String getResponseName()
90      {
91          return EXTENSION_OID;
92      }
93  
94  
95      /**
96       * Sets the OID uniquely identifying this extended response (a.k.a. its
97       * name).
98       * 
99       * @param oid the OID of the extended response type.
100      */
101     public void setResponseName( String oid )
102     {
103         throw new UnsupportedOperationException( I18n.err( I18n.ERR_04168, EXTENSION_OID ) );
104     }
105 
106 
107     // -----------------------------------------------------------------------
108     // Parameters of the Extended Response Value
109     // -----------------------------------------------------------------------
110     /**
111      * {@inheritDoc}
112      */
113     public int getDelay()
114     {
115         return delay;
116     }
117 
118 
119     /**
120      * {@inheritDoc}
121      */
122     public void setDelay( int delay )
123     {
124         this.delay = delay;
125     }
126 
127 
128     /**
129      * {@inheritDoc}
130      */
131     public int getTimeOffline()
132     {
133         return timeOffline;
134     }
135 
136 
137     /**
138      * {@inheritDoc}
139      */
140     public void setTimeOffline( int timeOffline )
141     {
142         this.timeOffline = timeOffline;
143     }
144 
145 
146     public Referral getReplicatedContexts()
147     {
148         return replicatedContexts;
149     }
150     
151 
152 
153     /**
154      * {@inheritDoc}
155      */
156     public void addReplicatedContexts( String replicatedContext )
157     {
158         replicatedContexts.addLdapUrl( replicatedContext );
159     }
160 }