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