001/*
002 * Copyright 2009 Red Hat, Inc.
003 * Red Hat licenses this file to you under the Apache License, version
004 * 2.0 (the "License"); you may not use this file except in compliance
005 * with the License.  You may obtain a copy of the License at
006 *    http://www.apache.org/licenses/LICENSE-2.0
007 * Unless required by applicable law or agreed to in writing, software
008 * distributed under the License is distributed on an "AS IS" BASIS,
009 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
010 * implied.  See the License for the specific language governing
011 * permissions and limitations under the License.
012 */
013
014package org.hornetq.api.core;
015
016/**
017 * 
018 * HornetQException is the root exception for HornetQ API. 
019 * 
020 * @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
021 *
022 */
023public class HornetQException extends Exception
024{
025   private static final long serialVersionUID = -4802014152804997417L;
026
027   // Error codes -------------------------------------------------
028
029   /**
030    * Internal error which prevented HornetQ to perform.
031    */
032   public static final int INTERNAL_ERROR = 000;
033
034   /**
035    * A packet of unsupported type was received by HornetQ PacketHandler.
036    */
037   public static final int UNSUPPORTED_PACKET = 001;
038
039   /**
040    * A client is not able to connect to HornetQ server.
041    */
042   public static final int NOT_CONNECTED = 002;
043
044   /**
045    * A client timed out will connecting to HornetQ server.
046    */
047   public static final int CONNECTION_TIMEDOUT = 003;
048
049   /**
050    * A client was disconnected from HornetQ server when the server has shut down.
051    */
052   public static final int DISCONNECTED = 004;
053
054   /**
055    * A blocking call from a client was unblocked during failover.
056    */
057   public static final int UNBLOCKED = 005;
058
059   /**
060    * Unexpected I/O error occured on the server.
061    */
062   public static final int IO_ERROR = 006;
063
064   /**
065    * An operation failed because a queue does not exist on the server.
066    */
067   public static final int QUEUE_DOES_NOT_EXIST = 100;
068
069   /**
070    * An operation failed because a queue exists on the server.
071    */
072   public static final int QUEUE_EXISTS = 101;
073
074   /**
075    * A client operation failed because the calling resource
076    * (ClientSession, ClientProducer, etc.) is closed.
077    */
078   public static final int OBJECT_CLOSED = 102;
079
080   /**
081    * An filter expression has not been validated
082    */
083   public static final int INVALID_FILTER_EXPRESSION = 103;
084
085   /**
086    * A HornetQ resource is not in a legal state (e.g. calling 
087    * ClientConsumer.receive() if a MessageHandler is set)
088    */
089   public static final int ILLEGAL_STATE = 104;
090
091   /**
092    * A security problem occured (authentication issues, permission issues,...)
093    */
094   public static final int SECURITY_EXCEPTION = 105;
095
096   /**
097    * An operation failed because an address does not exist on the server.
098    */
099   public static final int ADDRESS_DOES_NOT_EXIST = 106;
100
101   /**
102    * An operation failed because an address exists on the server.
103    */
104   public static final int ADDRESS_EXISTS = 107;
105
106   /**
107    * A incompatibility between HornetQ versions on the client and the server has been detected
108    */
109   public static final int INCOMPATIBLE_CLIENT_SERVER_VERSIONS = 108;
110
111   /**
112    * An operation failed because a session exists on the server.
113    */
114   public static final int SESSION_EXISTS = 109;
115
116   /**
117    * An problem occurred while manipulating the body of a large message.
118    */
119   public static final int LARGE_MESSAGE_ERROR_BODY = 110;
120
121   /**
122    * A transaction was rolled back.
123    */
124   public static final int TRANSACTION_ROLLED_BACK = 111;
125
126   /**
127    * The creation of a session was rejected by the server (e.g. if the
128    * server is starting and has not finish to be initialized)
129    */
130   public static final int SESSION_CREATION_REJECTED = 112;
131   
132   /**
133    * A DuplicateID was rejected.
134    */
135   public static final int DUPLICATE_ID_REJECTED = 113;
136
137   
138   /**
139    * A Session Metadata was set in duplication 
140    */
141   public static final int DUPLICATE_METADATA = 114;
142
143   
144   // Native Error codes ----------------------------------------------
145
146   /**
147    * A internal error occured in the AIO native code
148    */
149   public static final int NATIVE_ERROR_INTERNAL = 200;
150
151   /**
152    * A buffer is invalid in the AIO native code
153    */
154   public static final int NATIVE_ERROR_INVALID_BUFFER = 201;
155
156   /**
157    * Alignment error in the AIO native code
158    */
159   public static final int NATIVE_ERROR_NOT_ALIGNED = 202;
160
161   /**
162    * AIO has not been properly initialized
163    */
164   public static final int NATIVE_ERROR_CANT_INITIALIZE_AIO = 203;
165
166   /**
167    * AIO has not been properly released
168    */
169   public static final int NATIVE_ERROR_CANT_RELEASE_AIO = 204;
170
171   /**
172    * A closed file has not be properly reopened
173    */
174   public static final int NATIVE_ERROR_CANT_OPEN_CLOSE_FILE = 205;
175
176   /**
177    * An error occured while allocating a queue in AIO native code
178    */
179   public static final int NATIVE_ERROR_CANT_ALLOCATE_QUEUE = 206;
180
181   /**
182    * An error occured while pre-allocating a file in AIO native code
183    */
184   public static final int NATIVE_ERROR_PREALLOCATE_FILE = 208;
185
186   /**
187    * An error occurred while allocating memory in the AIO native code
188    */
189   public static final int NATIVE_ERROR_ALLOCATE_MEMORY = 209;
190
191   /**
192    * AIO is full
193    */
194   public static final int NATIVE_ERROR_AIO_FULL = 211;
195
196   private int code;
197
198   public HornetQException()
199   {
200   }
201
202   public HornetQException(final int code)
203   {
204      this.code = code;
205   }
206
207   public HornetQException(final int code, final String msg)
208   {
209      super(msg);
210
211      this.code = code;
212   }
213
214   public HornetQException(final int code, final String msg, final Throwable cause)
215   {
216      super(msg, cause);
217
218      this.code = code;
219   }
220
221   public int getCode()
222   {
223      return code;
224   }
225
226   @Override
227   public String toString()
228   {
229      return "HornetQException[errorCode=" + code + " message=" + getMessage() + "]";
230   }
231
232}