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.i18n.I18n;
24  import org.apache.directory.api.ldap.model.message.ExtendedResponseImpl;
25  import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
26  
27  
28  /**
29   * The response sent back from the server when a {@link GracefulShutdownRequestImpl}
30   * extended operation is sent. Delivery of this response may block until all
31   * connected clients are sent a GracefulDisconnect unsolicited notification.
32   * 
33   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
34   */
35  public class GracefulShutdownResponseImpl extends ExtendedResponseImpl implements GracefulShutdownResponse
36  {
37      /**
38       * Instantiates a new graceful shutdown response.
39       *
40       * @param messageId the message id
41       * @param rcode the result code
42       */
43      public GracefulShutdownResponseImpl( int messageId, ResultCodeEnum rcode )
44      {
45          super( messageId, EXTENSION_OID );
46  
47          switch ( rcode )
48          {
49              case SUCCESS:
50                  break;
51  
52              case OPERATIONS_ERROR:
53                  break;
54  
55              case INSUFFICIENT_ACCESS_RIGHTS:
56                  break;
57  
58              default:
59                  throw new IllegalArgumentException( I18n.err( I18n.ERR_04166, ResultCodeEnum.SUCCESS,
60                      ResultCodeEnum.OPERATIONS_ERROR, ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS ) );
61          }
62  
63          super.getLdapResult().setMatchedDn( null );
64          super.getLdapResult().setResultCode( rcode );
65      }
66  
67  
68      /**
69       * Instantiates a new graceful shutdown response.
70       *
71       * @param messageId the message id
72       */
73      public GracefulShutdownResponseImpl( int messageId )
74      {
75          super( messageId, EXTENSION_OID );
76          super.getLdapResult().setMatchedDn( null );
77          super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
78      }
79  
80  
81      /**
82       * Instantiates a new graceful shutdown response.
83       */
84      public GracefulShutdownResponseImpl()
85      {
86          super( EXTENSION_OID );
87          super.getLdapResult().setMatchedDn( null );
88          super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
89      }
90  
91  
92      // ------------------------------------------------------------------------
93      // ExtendedResponse Interface Method Implementations
94      // ------------------------------------------------------------------------
95  
96      /**
97       * Gets the OID uniquely identifying this extended response (a.k.a. its
98       * name).
99       * 
100      * @return the OID of the extended response type.
101      */
102     public String getResponseName()
103     {
104         return EXTENSION_OID;
105     }
106 
107 
108     /**
109      * Sets the OID uniquely identifying this extended response (a.k.a. its
110      * name).
111      * 
112      * @param oid
113      *            the OID of the extended response type.
114      */
115     public void setResponseName( String oid )
116     {
117         throw new UnsupportedOperationException( I18n.err( I18n.ERR_04168, EXTENSION_OID ) );
118     }
119 
120 
121     /**
122      * {@inheritDoc}
123      */
124     @Override
125     public int hashCode()
126     {
127         int hash = 37;
128         // Seems simple but look at the equals() method ...
129         hash = hash * 17 + getClass().getName().hashCode();
130 
131         return hash;
132     }
133 
134 
135     /**
136      * {@inheritDoc}
137      */
138     @Override
139     public boolean equals( Object obj )
140     {
141         if ( obj == this )
142         {
143             return true;
144         }
145 
146         return ( obj instanceof GracefulShutdownResponseImpl );
147     }
148 }