001 /** 002 * 003 * Copyright 2004 Protique Ltd 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 * 017 **/ 018 019 package org.activemq.message; 020 021 import java.io.StringWriter; 022 import java.io.PrintWriter; 023 024 /** 025 * Sent in receipt of a Packet 026 */ 027 028 public class Receipt extends AbstractPacket { 029 030 private short correlationId; 031 private String brokerName; 032 private String clusterName; 033 private Throwable exception; 034 private boolean failed; 035 private int brokerMessageCapacity = 100; 036 037 038 /** 039 * @return Returns the jmsException. 040 * 041 * @Transient 042 */ 043 public Throwable getException() { 044 return exception; 045 } 046 047 /** 048 * @param exception The exception to set. 049 */ 050 public void setException(Throwable exception) { 051 this.exception = exception; 052 } 053 054 /** 055 * Return the type of Packet 056 * 057 * @return integer representation of the type of Packet 058 */ 059 060 public int getPacketType() { 061 return RECEIPT_INFO; 062 } 063 064 /** 065 * @return true, this is a receipt packet 066 */ 067 public boolean isReceipt() { 068 return true; 069 } 070 071 /** 072 * @return Returns the correlationId. 073 */ 074 public short getCorrelationId() { 075 return this.correlationId; 076 } 077 078 /** 079 * @param newCorrelationId The correlationId to set. 080 */ 081 public void setCorrelationId(short newCorrelationId) { 082 this.correlationId = newCorrelationId; 083 } 084 085 /** 086 * @return Returns the failed. 087 */ 088 public boolean isFailed() { 089 return this.failed; 090 } 091 092 /** 093 * @param newFailed The failed to set. 094 */ 095 public void setFailed(boolean newFailed) { 096 this.failed = newFailed; 097 } 098 099 /** 100 * @return Returns the brokerMessageCapacity. 101 */ 102 public int getBrokerMessageCapacity() { 103 return brokerMessageCapacity; 104 } 105 /** 106 * @param brokerMessageCapacity The brokerMessageCapacity to set. 107 */ 108 public void setBrokerMessageCapacity(int brokerMessageCapacity) { 109 this.brokerMessageCapacity = brokerMessageCapacity; 110 } 111 /** 112 * @return Returns the brokerName. 113 */ 114 public String getBrokerName() { 115 return brokerName; 116 } 117 /** 118 * @param brokerName The brokerName to set. 119 */ 120 public void setBrokerName(String brokerName) { 121 this.brokerName = brokerName; 122 } 123 /** 124 * @return Returns the clusterName. 125 */ 126 public String getClusterName() { 127 return clusterName; 128 } 129 /** 130 * @param clusterName The clusterName to set. 131 */ 132 public void setClusterName(String clusterName) { 133 this.clusterName = clusterName; 134 } 135 136 /** 137 * OpenWire helper method 138 */ 139 public String getExceptionAsString() { 140 if (exception == null) { 141 return null; 142 } 143 StringWriter buffer = new StringWriter(); 144 PrintWriter out = new PrintWriter(buffer); 145 out.println(exception.getMessage()); 146 exception.printStackTrace(out); 147 out.close(); 148 return buffer.toString(); 149 } 150 151 /** 152 * OpenWire helper method 153 */ 154 public void setExceptionAsString(String text) { 155 Exception answer = null; 156 if (text != null && text.length() > 0) { 157 answer = new Exception(answer); 158 } 159 setException(answer); 160 } 161 162 163 /** 164 * @return pretty print of a Receipt 165 */ 166 public String toString() { 167 return super.toString() + " Receipt{ " + 168 "brokerMessageCapacity = " + brokerMessageCapacity + 169 ", correlationId = '" + correlationId + "' " + 170 ", brokerName = '" + brokerName + "' " + 171 ", clusterName = '" + clusterName + "' " + 172 ", exception = " + exception + 173 ", failed = " + failed + 174 " }"; 175 } 176 }