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   *    https://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.AbstractExtendedResponse;
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 AbstractExtendedResponse 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          StringBuilder buf = new StringBuilder();
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       * Sets the OID uniquely identifying this extended response (a.k.a. its
85       * name).
86       * 
87       * @param oid the OID of the extended response type.
88       */
89      @Override
90      public void setResponseName( String oid )
91      {
92          throw new UnsupportedOperationException( I18n.err( I18n.ERR_13504_FIX_OID, EXTENSION_OID ) );
93      }
94  
95  
96      // -----------------------------------------------------------------------
97      // Parameters of the Extended Response Value
98      // -----------------------------------------------------------------------
99      /**
100      * {@inheritDoc}
101      */
102     @Override
103     public int getDelay()
104     {
105         return delay;
106     }
107 
108 
109     /**
110      * {@inheritDoc}
111      */
112     @Override
113     public void setDelay( int delay )
114     {
115         this.delay = delay;
116     }
117 
118 
119     /**
120      * {@inheritDoc}
121      */
122     @Override
123     public int getTimeOffline()
124     {
125         return timeOffline;
126     }
127 
128 
129     /**
130      * {@inheritDoc}
131      */
132     @Override
133     public void setTimeOffline( int timeOffline )
134     {
135         this.timeOffline = timeOffline;
136     }
137 
138 
139     /**
140      * {@inheritDoc}
141      */
142     @Override
143     public Referral getReplicatedContexts()
144     {
145         return replicatedContexts;
146     }
147     
148 
149 
150     /**
151      * {@inheritDoc}
152      */
153     @Override
154     public void addReplicatedContexts( String replicatedContext )
155     {
156         replicatedContexts.addLdapUrl( replicatedContext );
157     }
158 }