RequiredDeliveryException.java
01 /*
02  *
03  * Licensed to the Apache Software Foundation (ASF) under one
04  * or more contributor license agreements.  See the NOTICE file
05  * distributed with this work for additional information
06  * regarding copyright ownership.  The ASF licenses this file
07  * to you under the Apache License, Version 2.0 (the
08  * "License"); you may not use this file except in compliance
09  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  */
21 package org.apache.qpid.server;
22 
23 import org.apache.qpid.AMQException;
24 import org.apache.qpid.protocol.AMQConstant;
25 import org.apache.qpid.server.queue.AMQMessage;
26 
27 /**
28  * Signals that a required delivery could not be made. This could be bacuse of the immediate flag being set and the
29  * queue having no consumers, or the mandatory flag being set and the exchange having no valid bindings.
30  *
31  <p/>The failed message is associated with this error condition, by taking a reference to it. This enables the
32  * correct compensating action to be taken against the message, for example, bouncing it back to the sender.
33  *
34  <p/><table id="crc"><caption>CRC Card</caption>
35  <tr><th> Responsibilities <th> Collaborations
36  <tr><td> Represent failure to deliver a message that must be delivered.
37  <tr><td> Associate the failed message with the error condition. <td> {@link AMQMessage}
38  </table>
39  */
40 public abstract class RequiredDeliveryException extends AMQException
41 {
42     private AMQMessage _amqMessage;
43 
44     public RequiredDeliveryException(String message, AMQMessage payload)
45     {
46         super(message);
47 
48         setMessage(payload);
49     }
50 
51 
52     public RequiredDeliveryException(String message)
53     {
54         super(message);
55     }
56 
57     public void setMessage(final AMQMessage payload)
58     {
59         // we need to keep this message around so we can return it in the
60         // handler.
61         // Messages are all kept in memory now. Only queues can push messages out of memory.
62         _amqMessage = payload;
63     }
64 
65     public AMQMessage getAMQMessage()
66     {
67         return _amqMessage;
68     }
69 
70     public AMQConstant getErrorCode()
71     {
72         return getReplyCode();
73     }
74 
75     public abstract AMQConstant getReplyCode();
76 }