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.gracefulShutdown;
21  
22  
23  import org.apache.directory.api.ldap.model.message.AbstractExtendedRequest;
24  
25  
26  /**
27   * An extended operation requesting the server to shutdown it's LDAP service
28   * port while allowing established clients to complete or abandon operations
29   * already in progress. More information about this extended request is
30   * available here: <a href="http://docs.safehaus.org:8080/x/GR">LDAP Extensions
31   * for Graceful Shutdown</a>.
32   * 
33   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
34   */
35  public class GracefulShutdownRequestImpl extends AbstractExtendedRequest implements GracefulShutdownRequest
36  {
37      /** Offline time after disconnection */
38      private int timeOffline;
39  
40      /** Delay before disconnection */
41      private int delay;
42  
43  
44      /**
45       * Instantiates a new graceful shutdown request.
46       *
47       * @param messageId the message id
48       */
49      public GracefulShutdownRequestImpl( int messageId )
50      {
51          this( messageId, UNDETERMINED, NOW );
52      }
53  
54  
55      /**
56       * Instantiates a new graceful shutdown request.
57       */
58      public GracefulShutdownRequestImpl()
59      {
60          setRequestName( EXTENSION_OID );
61      }
62  
63  
64      /**
65       * Instantiates a new graceful shutdown request.
66       *
67       * @param messageId the message id
68       * @param timeOffline the offline time after disconnection, in minutes
69       * @param delay the delay before disconnection, in seconds
70       */
71      public GracefulShutdownRequestImpl( int messageId, int timeOffline, int delay )
72      {
73          super( messageId );
74          setRequestName( EXTENSION_OID );
75          this.timeOffline = timeOffline;
76          this.delay = delay;
77      }
78  
79  
80      // -----------------------------------------------------------------------
81      // Parameters of the Extended Request Payload
82      // -----------------------------------------------------------------------
83  
84      /**
85       * {@inheritDoc}
86       */
87      @Override
88      public int getDelay()
89      {
90          return delay;
91      }
92  
93  
94      /**
95       * {@inheritDoc}
96       */
97      @Override
98      public void setDelay( int delay )
99      {
100         this.delay = delay;
101     }
102 
103 
104     /**
105      * {@inheritDoc}
106      */
107     @Override
108     public int getTimeOffline()
109     {
110         return timeOffline;
111     }
112 
113 
114     /**
115      * {@inheritDoc}
116      */
117     @Override
118     public void setTimeOffline( int timeOffline )
119     {
120         this.timeOffline = timeOffline;
121     }
122 
123 
124     @Override
125     public GracefulShutdownResponse getResultResponse()
126     {
127         if ( getResponse() == null )
128         {
129             setResponse( new GracefulShutdownResponseImpl() );
130         }
131 
132         return ( GracefulShutdownResponse ) getResponse();
133     }
134 }