Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/activemq/message/ResponseReceipt.java


1   /** 
2    * 
3    * Copyright 2004 Hiram Chirino
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); 
6    * you may not use this file except in compliance with the License. 
7    * You may obtain a copy of the License at 
8    * 
9    * http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, 
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
14   * See the License for the specific language governing permissions and 
15   * limitations under the License. 
16   * 
17   **/
18  package org.activemq.message;
19  
20  import java.io.IOException;
21  import java.io.Serializable;
22  
23  import javax.jms.JMSException;
24  
25  import org.activemq.util.SerializationHelper;
26  
27  /**
28   * A receipt that also carries a response object.
29   */
30  public class ResponseReceipt extends Receipt {
31  
32      private Serializable result;
33      private byte[] resultBytes;
34  
35      /**
36       * @see org.activemq.message.Receipt#getPacketType()
37       */
38      public int getPacketType() {
39          return RESPONSE_RECEIPT_INFO;
40      }
41  
42      /**
43       * @Transient
44       *
45       * @return Returns the result.
46       */
47      public Serializable getResult() throws JMSException {
48          if (result == null) {
49              if (resultBytes == null) {
50                  return null;
51              }
52              try {
53                  result = (Serializable) SerializationHelper.readObject(resultBytes);
54              }
55              catch (Exception e) {
56                  throw ((JMSException) new JMSException("Invalid network mesage received.").initCause(e));
57              }
58          }
59          return result;
60      }
61  
62      /**
63       * @param result The result to set.
64       */
65      public void setResult(Serializable result) {
66          this.result = result;
67          this.resultBytes = null;
68      }
69  
70      /**
71       * @param data
72       */
73      public void setResultBytes(byte[] resultBytes) {
74          this.resultBytes = resultBytes;
75          this.result = null;
76      }
77  
78      /**
79       * @return Returns the resultBytes.
80       */
81      public byte[] getResultBytes() throws IOException {
82          if (resultBytes == null) {
83              if (result == null) {
84                  return null;
85              }
86              resultBytes = SerializationHelper.writeObject(result);
87          }
88          return resultBytes;
89      }
90  
91      public String toString() {
92          return super.toString() + " ResponseReceipt{ " +
93                  "result = " + result +
94                  ", resultBytes = " + resultBytes +
95                  " }";
96      }
97  }