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              case OPERATIONS_ERROR:
51              case INSUFFICIENT_ACCESS_RIGHTS:
52                  break;
53  
54              default:
55                  throw new IllegalArgumentException( I18n.err( I18n.ERR_04166, ResultCodeEnum.SUCCESS,
56                      ResultCodeEnum.OPERATIONS_ERROR, ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS ) );
57          }
58  
59          super.getLdapResult().setMatchedDn( null );
60          super.getLdapResult().setResultCode( rcode );
61      }
62  
63  
64      /**
65       * Instantiates a new graceful shutdown response.
66       *
67       * @param messageId the message id
68       */
69      public GracefulShutdownResponseImpl( int messageId )
70      {
71          super( messageId, EXTENSION_OID );
72          super.getLdapResult().setMatchedDn( null );
73          super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
74      }
75  
76  
77      /**
78       * Instantiates a new graceful shutdown response.
79       */
80      public GracefulShutdownResponseImpl()
81      {
82          super( EXTENSION_OID );
83          super.getLdapResult().setMatchedDn( null );
84          super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
85      }
86  
87  
88      // ------------------------------------------------------------------------
89      // ExtendedResponse Interface Method Implementations
90      // ------------------------------------------------------------------------
91  
92      /**
93       * Gets the OID uniquely identifying this extended response (a.k.a. its
94       * name).
95       * 
96       * @return the OID of the extended response type.
97       */
98      @Override
99      public String getResponseName()
100     {
101         return EXTENSION_OID;
102     }
103 
104 
105     /**
106      * Sets the OID uniquely identifying this extended response (a.k.a. its
107      * name).
108      * 
109      * @param oid
110      *            the OID of the extended response type.
111      */
112     @Override
113     public void setResponseName( String oid )
114     {
115         throw new UnsupportedOperationException( I18n.err( I18n.ERR_04168, EXTENSION_OID ) );
116     }
117 
118 
119     /**
120      * {@inheritDoc}
121      */
122     @Override
123     public int hashCode()
124     {
125         int hash = 37;
126         // Seems simple but look at the equals() method ...
127         hash = hash * 17 + getClass().getName().hashCode();
128 
129         return hash;
130     }
131 
132 
133     /**
134      * {@inheritDoc}
135      */
136     @Override
137     public boolean equals( Object obj )
138     {
139         if ( obj == this )
140         {
141             return true;
142         }
143 
144         return obj instanceof GracefulShutdownResponseImpl;
145     }
146 }