http://git-wip-us.apache.org/repos/asf/activemq-6/blob/23e8edd9/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQNotConnectedException.java ---------------------------------------------------------------------- diff --git a/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQNotConnectedException.java b/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQNotConnectedException.java new file mode 100644 index 0000000..ededf30 --- /dev/null +++ b/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQNotConnectedException.java @@ -0,0 +1,35 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package org.apache.activemq6.api.core; + +import static org.apache.activemq6.api.core.HornetQExceptionType.NOT_CONNECTED; + +/** + * A client is not able to connect to HornetQ server. + * @author <a href="mailto:[email protected]">Andy Taylor</a> 4/30/12 + */ +public final class HornetQNotConnectedException extends HornetQException +{ + private static final long serialVersionUID = -3489189971813613325L; + + public HornetQNotConnectedException(String message) + { + super(NOT_CONNECTED, message); + } + + public HornetQNotConnectedException() + { + super(NOT_CONNECTED); + } +}
http://git-wip-us.apache.org/repos/asf/activemq-6/blob/23e8edd9/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQObjectClosedException.java ---------------------------------------------------------------------- diff --git a/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQObjectClosedException.java b/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQObjectClosedException.java new file mode 100644 index 0000000..3923cdb --- /dev/null +++ b/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQObjectClosedException.java @@ -0,0 +1,36 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package org.apache.activemq6.api.core; + +import static org.apache.activemq6.api.core.HornetQExceptionType.OBJECT_CLOSED; + +/** + * A client operation failed because the calling resource (ClientSession, ClientProducer, etc.) is + * closed. + * @author <a href="mailto:[email protected]">Andy Taylor</a> 4/30/12 + */ +public final class HornetQObjectClosedException extends HornetQException +{ + private static final long serialVersionUID = 809024052184914812L; + + public HornetQObjectClosedException() + { + super(OBJECT_CLOSED); + } + + public HornetQObjectClosedException(String msg) + { + super(OBJECT_CLOSED, msg); + } +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/23e8edd9/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQPropertyConversionException.java ---------------------------------------------------------------------- diff --git a/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQPropertyConversionException.java b/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQPropertyConversionException.java new file mode 100644 index 0000000..320489d --- /dev/null +++ b/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQPropertyConversionException.java @@ -0,0 +1,30 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.apache.activemq6.api.core; + +/** + * A PropertyConversionException is thrown by {@code org.apache.activemq6.api.core.Message} methods when a + * property can not be converted to the expected type. + * @author <a href="mailto:[email protected]">Jeff Mesnil</a> + * @see org.apache.activemq6.api.core.Message + */ +public final class HornetQPropertyConversionException extends RuntimeException +{ + + private static final long serialVersionUID = -3010008708334904332L; + + public HornetQPropertyConversionException(final String message) + { + super(message); + } +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/23e8edd9/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQQueueExistsException.java ---------------------------------------------------------------------- diff --git a/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQQueueExistsException.java b/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQQueueExistsException.java new file mode 100644 index 0000000..8dc26f4 --- /dev/null +++ b/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQQueueExistsException.java @@ -0,0 +1,35 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package org.apache.activemq6.api.core; + +import static org.apache.activemq6.api.core.HornetQExceptionType.QUEUE_EXISTS; + +/** + * An operation failed because a queue exists on the server. + * @author <a href="mailto:[email protected]">Andy Taylor</a> 4/30/12 + */ +public final class HornetQQueueExistsException extends HornetQException +{ + private static final long serialVersionUID = -405552292451883063L; + + public HornetQQueueExistsException() + { + super(QUEUE_EXISTS); + } + + public HornetQQueueExistsException(String msg) + { + super(QUEUE_EXISTS, msg); + } +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/23e8edd9/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQSecurityException.java ---------------------------------------------------------------------- diff --git a/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQSecurityException.java b/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQSecurityException.java new file mode 100644 index 0000000..f5f46f3 --- /dev/null +++ b/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQSecurityException.java @@ -0,0 +1,35 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package org.apache.activemq6.api.core; + +import static org.apache.activemq6.api.core.HornetQExceptionType.SECURITY_EXCEPTION; + +/** + * A security problem occurred (authentication issues, permission issues,...) + * @author <a href="mailto:[email protected]">Andy Taylor</a> 5/2/12 + */ +public final class HornetQSecurityException extends HornetQException +{ + private static final long serialVersionUID = 3291210307590756881L; + + public HornetQSecurityException() + { + super(SECURITY_EXCEPTION); + } + + public HornetQSecurityException(String msg) + { + super(SECURITY_EXCEPTION, msg); + } +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/23e8edd9/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQSessionCreationException.java ---------------------------------------------------------------------- diff --git a/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQSessionCreationException.java b/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQSessionCreationException.java new file mode 100644 index 0000000..b2191a8 --- /dev/null +++ b/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQSessionCreationException.java @@ -0,0 +1,36 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package org.apache.activemq6.api.core; + +import static org.apache.activemq6.api.core.HornetQExceptionType.SESSION_CREATION_REJECTED; + +/** + * The creation of a session was rejected by the server (e.g. if the server is starting and has not + * finish to be initialized. + * @author <a href="mailto:[email protected]">Andy Taylor</a> 5/2/12 + */ +public final class HornetQSessionCreationException extends HornetQException +{ + private static final long serialVersionUID = -4486139158452585895L; + + public HornetQSessionCreationException() + { + super(SESSION_CREATION_REJECTED); + } + + public HornetQSessionCreationException(String msg) + { + super(SESSION_CREATION_REJECTED, msg); + } +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/23e8edd9/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQTransactionOutcomeUnknownException.java ---------------------------------------------------------------------- diff --git a/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQTransactionOutcomeUnknownException.java b/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQTransactionOutcomeUnknownException.java new file mode 100644 index 0000000..c3f5585 --- /dev/null +++ b/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQTransactionOutcomeUnknownException.java @@ -0,0 +1,35 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package org.apache.activemq6.api.core; + +import static org.apache.activemq6.api.core.HornetQExceptionType.TRANSACTION_OUTCOME_UNKNOWN; + +/** + * The outcome of a transaction is unknown. + * @author <a href="mailto:[email protected]">Andy Taylor</a> 5/2/12 + */ +public final class HornetQTransactionOutcomeUnknownException extends HornetQException +{ + private static final long serialVersionUID = 7940794286427650558L; + + public HornetQTransactionOutcomeUnknownException() + { + super(TRANSACTION_OUTCOME_UNKNOWN); + } + + public HornetQTransactionOutcomeUnknownException(String msg) + { + super(TRANSACTION_OUTCOME_UNKNOWN, msg); + } +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/23e8edd9/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQTransactionRolledBackException.java ---------------------------------------------------------------------- diff --git a/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQTransactionRolledBackException.java b/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQTransactionRolledBackException.java new file mode 100644 index 0000000..d568780 --- /dev/null +++ b/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQTransactionRolledBackException.java @@ -0,0 +1,35 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package org.apache.activemq6.api.core; + +import static org.apache.activemq6.api.core.HornetQExceptionType.TRANSACTION_ROLLED_BACK; + +/** + * A transaction was rolled back. + * @author <a href="mailto:[email protected]">Andy Taylor</a> 5/2/12 + */ +public final class HornetQTransactionRolledBackException extends HornetQException +{ + private static final long serialVersionUID = 5823412198677126300L; + + public HornetQTransactionRolledBackException() + { + super(TRANSACTION_ROLLED_BACK); + } + + public HornetQTransactionRolledBackException(String msg) + { + super(TRANSACTION_ROLLED_BACK, msg); + } +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/23e8edd9/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQUnBlockedException.java ---------------------------------------------------------------------- diff --git a/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQUnBlockedException.java b/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQUnBlockedException.java new file mode 100644 index 0000000..f8ff6f7 --- /dev/null +++ b/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQUnBlockedException.java @@ -0,0 +1,35 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package org.apache.activemq6.api.core; + +import static org.apache.activemq6.api.core.HornetQExceptionType.UNBLOCKED; + +/** + * A blocking call from a client was unblocked during failover. + * @author <a href="mailto:[email protected]">Andy Taylor</a> 4/30/12 + */ +public final class HornetQUnBlockedException extends HornetQException +{ + private static final long serialVersionUID = -4507889261891160608L; + + public HornetQUnBlockedException() + { + super(UNBLOCKED); + } + + public HornetQUnBlockedException(String msg) + { + super(UNBLOCKED, msg); + } +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/23e8edd9/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQUnsupportedPacketException.java ---------------------------------------------------------------------- diff --git a/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQUnsupportedPacketException.java b/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQUnsupportedPacketException.java new file mode 100644 index 0000000..7544832 --- /dev/null +++ b/activemq6-commons/src/main/java/org/apache/activemq6/api/core/HornetQUnsupportedPacketException.java @@ -0,0 +1,35 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package org.apache.activemq6.api.core; + +import static org.apache.activemq6.api.core.HornetQExceptionType.UNSUPPORTED_PACKET; + +/** + * A packet of unsupported type was received by HornetQ PacketHandler. + * @author <a href="mailto:[email protected]">Andy Taylor</a> 4/30/12 + */ +public final class HornetQUnsupportedPacketException extends HornetQException +{ + private static final long serialVersionUID = -7074681529482463675L; + + public HornetQUnsupportedPacketException() + { + super(UNSUPPORTED_PACKET); + } + + public HornetQUnsupportedPacketException(String msg) + { + super(UNSUPPORTED_PACKET, msg); + } +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/23e8edd9/activemq6-commons/src/main/java/org/apache/activemq6/api/core/Pair.java ---------------------------------------------------------------------- diff --git a/activemq6-commons/src/main/java/org/apache/activemq6/api/core/Pair.java b/activemq6-commons/src/main/java/org/apache/activemq6/api/core/Pair.java new file mode 100644 index 0000000..74b3804 --- /dev/null +++ b/activemq6-commons/src/main/java/org/apache/activemq6/api/core/Pair.java @@ -0,0 +1,105 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package org.apache.activemq6.api.core; + +import java.io.Serializable; + +/** + * A Pair is a holder for 2 objects. + * <p> + * This is a utility class. + * @author <a href="mailto:[email protected]">Tim Fox</a> + */ +public final class Pair<A, B> implements Serializable +{ + private static final long serialVersionUID = -2496357457812368127L; + + public Pair(final A a, final B b) + { + this.a = a; + + this.b = b; + } + + private A a; + + private B b; + + private int hash = -1; + + @Override + public int hashCode() + { + if (hash == -1) + { + if (a == null && b == null) + { + return super.hashCode(); + } + else + { + hash = (a == null ? 0 : a.hashCode()) + 37 * (b == null ? 0 : b.hashCode()); + } + } + + return hash; + } + + @Override + public boolean equals(final Object other) + { + if (other == this) + { + return true; + } + + if (other instanceof Pair == false) + { + return false; + } + + Pair<A, B> pother = (Pair<A, B>)other; + + return (pother.a == null ? a == null : pother.a.equals(a)) && (pother.b == null ? b == null : pother.b.equals(b)); + + } + + @Override + public String toString() + { + return "Pair[a=" + a + ", b=" + b + "]"; + } + + public void setA(A a) + { + hash = -1; + this.a = a; + } + + public A getA() + { + return a; + } + + public void setB(B b) + { + hash = -1; + this.b = b; + } + + public B getB() + { + return b; + } +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/23e8edd9/activemq6-commons/src/main/java/org/apache/activemq6/api/core/SimpleString.java ---------------------------------------------------------------------- diff --git a/activemq6-commons/src/main/java/org/apache/activemq6/api/core/SimpleString.java b/activemq6-commons/src/main/java/org/apache/activemq6/api/core/SimpleString.java new file mode 100644 index 0000000..1c62423 --- /dev/null +++ b/activemq6-commons/src/main/java/org/apache/activemq6/api/core/SimpleString.java @@ -0,0 +1,452 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package org.apache.activemq6.api.core; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import org.apache.activemq6.utils.DataConstants; + +/** + * A simple String class that can store all characters, and stores as simple {@code byte[]}, this + * minimises expensive copying between String objects. + * <p> + * This object is used heavily throughout HornetQ for performance reasons. + * + * @author <a href="mailto:[email protected]">Tim Fox</a> + */ +public final class SimpleString implements CharSequence, Serializable, Comparable<SimpleString> +{ + private static final long serialVersionUID = 4204223851422244307L; + + // Attributes + // ------------------------------------------------------------------------ + private final byte[] data; + + private transient int hash; + + // Cache the string + private transient String str; + + // Static + // ---------------------------------------------------------------------- + + /** + * Returns a SimpleString constructed from the {@code string} parameter. + * <p> + * If {@code string} is {@code null}, the return value will be {@code null} too. + * + * @param string String used to instantiate a SimpleString. + */ + public static SimpleString toSimpleString(final String string) + { + if (string == null) + { + return null; + } + return new SimpleString(string); + } + + // Constructors + // ---------------------------------------------------------------------- + + /** + * creates a SimpleString from a conventional String + * + * @param string the string to transform + */ + public SimpleString(final String string) + { + int len = string.length(); + + data = new byte[len << 1]; + + int j = 0; + + for (int i = 0; i < len; i++) + { + char c = string.charAt(i); + + byte low = (byte) (c & 0xFF); // low byte + + data[j++] = low; + + byte high = (byte) (c >> 8 & 0xFF); // high byte + + data[j++] = high; + } + + str = string; + } + + /** + * creates a SimpleString from a byte array + * + * @param data the byte array to use + */ + public SimpleString(final byte[] data) + { + this.data = data; + } + + // CharSequence implementation + // --------------------------------------------------------------------------- + + public int length() + { + return data.length >> 1; + } + + public char charAt(int pos) + { + if (pos < 0 || pos >= data.length >> 1) + { + throw new IndexOutOfBoundsException(); + } + pos <<= 1; + + return (char) ((data[pos] & 0xFF) | (data[pos + 1] << 8) & 0xFF00); + } + + public CharSequence subSequence(final int start, final int end) + { + int len = data.length >> 1; + + if (end < start || start < 0 || end > len) + { + throw new IndexOutOfBoundsException(); + } + else + { + int newlen = end - start << 1; + byte[] bytes = new byte[newlen]; + + System.arraycopy(data, start << 1, bytes, 0, newlen); + + return new SimpleString(bytes); + } + } + + // Comparable implementation ------------------------------------- + + public int compareTo(final SimpleString o) + { + return toString().compareTo(o.toString()); + } + + // Public + // --------------------------------------------------------------------------- + + /** + * returns the underlying byte array of this SimpleString + * + * @return the byte array + */ + public byte[] getData() + { + return data; + } + + /** + * returns true if the SimpleString parameter starts with the same data as this one. false if not. + * + * @param other the SimpleString to look for + * @return true if this SimpleString starts with the same data + */ + public boolean startsWith(final SimpleString other) + { + byte[] otherdata = other.data; + + if (otherdata.length > data.length) + { + return false; + } + + for (int i = 0; i < otherdata.length; i++) + { + if (data[i] != otherdata[i]) + { + return false; + } + } + + return true; + } + + @Override + public String toString() + { + if (str == null) + { + int len = data.length >> 1; + + char[] chars = new char[len]; + + int j = 0; + + for (int i = 0; i < len; i++) + { + int low = data[j++] & 0xFF; + + int high = data[j++] << 8 & 0xFF00; + + chars[i] = (char) (low | high); + } + + str = new String(chars); + } + + return str; + } + + @Override + public boolean equals(final Object other) + { + if (this == other) + { + return true; + } + + if (other instanceof SimpleString) + { + SimpleString s = (SimpleString) other; + + if (data.length != s.data.length) + { + return false; + } + + for (int i = 0; i < data.length; i++) + { + if (data[i] != s.data[i]) + { + return false; + } + } + + return true; + } + else + { + return false; + } + } + + @Override + public int hashCode() + { + if (hash == 0) + { + int tmphash = 0; + for (byte element : data) + { + tmphash = (tmphash << 5) - tmphash + element; // (hash << 5) - hash is same as hash * 31 + } + hash = tmphash; + } + + return hash; + } + + /** + * Splits this SimpleString into an array of SimpleString using the char param as the delimiter. + * i.e. "a.b" would return "a" and "b" if . was the delimiter + * + * @param delim + */ + public SimpleString[] split(final char delim) + { + List<SimpleString> all = null; + + byte low = (byte) (delim & 0xFF); // low byte + byte high = (byte) (delim >> 8 & 0xFF); // high byte + + int lasPos = 0; + for (int i = 0; i < data.length; i += 2) + { + if (data[i] == low && data[i + 1] == high) + { + byte[] bytes = new byte[i - lasPos]; + System.arraycopy(data, lasPos, bytes, 0, bytes.length); + lasPos = i + 2; + + // We will create the ArrayList lazily + if (all == null) + { + // There will be at least 2 strings on this case (which is the actual common usecase) + // For that reason I'm allocating the ArrayList with 2 already + // I have thought about using LinkedList here but I think this will be good enough already + // Note by Clebert + all = new ArrayList<SimpleString>(2); + } + all.add(new SimpleString(bytes)); + } + } + + if (all == null) + { + return new SimpleString[]{this}; + } + else + { + // Adding the last one + byte[] bytes = new byte[data.length - lasPos]; + System.arraycopy(data, lasPos, bytes, 0, bytes.length); + all.add(new SimpleString(bytes)); + + // Converting it to arrays + SimpleString[] parts = new SimpleString[all.size()]; + return all.toArray(parts); + } + } + + /** + * checks to see if this SimpleString contains the char parameter passed in + * + * @param c the char to check for + * @return true if the char is found, false otherwise. + */ + public boolean contains(final char c) + { + final byte low = (byte) (c & 0xFF); // low byte + final byte high = (byte) (c >> 8 & 0xFF); // high byte + + for (int i = 0; i < data.length; i += 2) + { + if (data[i] == low && data[i + 1] == high) + { + return true; + } + } + return false; + } + + /** + * Concatenates a SimpleString and a String + * + * @param toAdd the String to concatenate with. + * @return the concatenated SimpleString + */ + public SimpleString concat(final String toAdd) + { + return concat(new SimpleString(toAdd)); + } + + /** + * Concatenates 2 SimpleString's + * + * @param toAdd the SimpleString to concatenate with. + * @return the concatenated SimpleString + */ + public SimpleString concat(final SimpleString toAdd) + { + byte[] bytes = new byte[data.length + toAdd.getData().length]; + System.arraycopy(data, 0, bytes, 0, data.length); + System.arraycopy(toAdd.getData(), 0, bytes, data.length, toAdd.getData().length); + return new SimpleString(bytes); + } + + /** + * Concatenates a SimpleString and a char + * + * @param c the char to concate with. + * @return the concatenated SimpleString + */ + public SimpleString concat(final char c) + { + byte[] bytes = new byte[data.length + 2]; + System.arraycopy(data, 0, bytes, 0, data.length); + bytes[data.length] = (byte) (c & 0xFF); + bytes[data.length + 1] = (byte) (c >> 8 & 0xFF); + return new SimpleString(bytes); + } + + /** + * returns the size of this SimpleString + * + * @return the size + */ + public int sizeof() + { + return DataConstants.SIZE_INT + data.length; + } + + /** + * returns the size of a SimpleString + * + * @param str the SimpleString to check + * @return the size + */ + public static int sizeofString(final SimpleString str) + { + return str.sizeof(); + } + + /** + * returns the size of a SimpleString which could be null + * + * @param str the SimpleString to check + * @return the size + */ + public static int sizeofNullableString(final SimpleString str) + { + if (str == null) + { + return 1; + } + else + { + return 1 + str.sizeof(); + } + } + + /** + * This method performs a similar function to {@link String#getChars(int, int, char[], int)}. + * This is mainly used by the Parsers on Filters + * + * @param srcBegin + * @param srcEnd + * @param dst + * @param dstPos + */ + public void getChars(final int srcBegin, final int srcEnd, final char[] dst, final int dstPos) + { + if (srcBegin < 0) + { + throw new StringIndexOutOfBoundsException(srcBegin); + } + if (srcEnd > length()) + { + throw new StringIndexOutOfBoundsException(srcEnd); + } + if (srcBegin > srcEnd) + { + throw new StringIndexOutOfBoundsException(srcEnd - srcBegin); + } + + int j = srcBegin * 2; + int d = dstPos; + + for (int i = srcBegin; i < srcEnd; i++) + { + int low = data[j++] & 0xFF; + + int high = data[j++] << 8 & 0xFF00; + + dst[d++] = (char) (low | high); + } + } + +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/23e8edd9/activemq6-commons/src/main/java/org/apache/activemq6/core/buffers/impl/ChannelBufferWrapper.java ---------------------------------------------------------------------- diff --git a/activemq6-commons/src/main/java/org/apache/activemq6/core/buffers/impl/ChannelBufferWrapper.java b/activemq6-commons/src/main/java/org/apache/activemq6/core/buffers/impl/ChannelBufferWrapper.java new file mode 100644 index 0000000..8f7336c --- /dev/null +++ b/activemq6-commons/src/main/java/org/apache/activemq6/core/buffers/impl/ChannelBufferWrapper.java @@ -0,0 +1,623 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package org.apache.activemq6.core.buffers.impl; + +import java.nio.ByteBuffer; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import org.apache.activemq6.api.core.HornetQBuffer; +import org.apache.activemq6.api.core.SimpleString; +import org.apache.activemq6.utils.DataConstants; +import org.apache.activemq6.utils.UTF8Util; + +/** + * A ChannelBufferWrapper + * + * @author Tim Fox + */ +public class ChannelBufferWrapper implements HornetQBuffer +{ + protected ByteBuf buffer; // NO_UCD (use final) + private final boolean releasable; + + public ChannelBufferWrapper(final ByteBuf buffer) + { + this(buffer, false); + } + + public ChannelBufferWrapper(final ByteBuf buffer, boolean releasable) + { + if (!releasable) + { + this.buffer = Unpooled.unreleasableBuffer(buffer); + } + else + { + this.buffer = buffer; + } + this.releasable = releasable; + } + + public boolean readBoolean() + { + return readByte() != 0; + } + + public SimpleString readNullableSimpleString() + { + int b = buffer.readByte(); + if (b == DataConstants.NULL) + { + return null; + } + return readSimpleStringInternal(); + } + + public String readNullableString() + { + int b = buffer.readByte(); + if (b == DataConstants.NULL) + { + return null; + } + return readStringInternal(); + } + + public SimpleString readSimpleString() + { + return readSimpleStringInternal(); + } + + private SimpleString readSimpleStringInternal() + { + int len = buffer.readInt(); + byte[] data = new byte[len]; + buffer.readBytes(data); + return new SimpleString(data); + } + + public String readString() + { + return readStringInternal(); + } + + private String readStringInternal() + { + int len = buffer.readInt(); + + if (len < 9) + { + char[] chars = new char[len]; + for (int i = 0; i < len; i++) + { + chars[i] = (char)buffer.readShort(); + } + return new String(chars); + } + else if (len < 0xfff) + { + return readUTF(); + } + else + { + return readSimpleStringInternal().toString(); + } + } + + public String readUTF() + { + return UTF8Util.readUTF(this); + } + + public void writeBoolean(final boolean val) + { + buffer.writeByte((byte)(val ? -1 : 0)); + } + + public void writeNullableSimpleString(final SimpleString val) + { + if (val == null) + { + buffer.writeByte(DataConstants.NULL); + } + else + { + buffer.writeByte(DataConstants.NOT_NULL); + writeSimpleStringInternal(val); + } + } + + public void writeNullableString(final String val) + { + if (val == null) + { + buffer.writeByte(DataConstants.NULL); + } + else + { + buffer.writeByte(DataConstants.NOT_NULL); + writeStringInternal(val); + } + } + + public void writeSimpleString(final SimpleString val) + { + writeSimpleStringInternal(val); + } + + private void writeSimpleStringInternal(final SimpleString val) + { + byte[] data = val.getData(); + buffer.writeInt(data.length); + buffer.writeBytes(data); + } + + public void writeString(final String val) + { + writeStringInternal(val); + } + + private void writeStringInternal(final String val) + { + int length = val.length(); + + buffer.writeInt(length); + + if (length < 9) + { + // If very small it's more performant to store char by char + for (int i = 0; i < val.length(); i++) + { + buffer.writeShort((short)val.charAt(i)); + } + } + else if (length < 0xfff) + { + // Store as UTF - this is quicker than char by char for most strings + writeUTF(val); + } + else + { + // Store as SimpleString, since can't store utf > 0xffff in length + writeSimpleStringInternal(new SimpleString(val)); + } + } + + public void writeUTF(final String utf) + { + UTF8Util.saveUTF(this, utf); + } + + public int capacity() + { + return buffer.capacity(); + } + + public ByteBuf byteBuf() + { + return buffer; + } + + public void clear() + { + buffer.clear(); + } + + public HornetQBuffer copy() + { + return new ChannelBufferWrapper(buffer.copy(), releasable); + } + + public HornetQBuffer copy(final int index, final int length) + { + return new ChannelBufferWrapper(buffer.copy(index, length), releasable); + } + + public void discardReadBytes() + { + buffer.discardReadBytes(); + } + + public HornetQBuffer duplicate() + { + return new ChannelBufferWrapper(buffer.duplicate(), releasable); + } + + public byte getByte(final int index) + { + return buffer.getByte(index); + } + + public void getBytes(final int index, final byte[] dst, final int dstIndex, final int length) + { + buffer.getBytes(index, dst, dstIndex, length); + } + + public void getBytes(final int index, final byte[] dst) + { + buffer.getBytes(index, dst); + } + + public void getBytes(final int index, final ByteBuffer dst) + { + buffer.getBytes(index, dst); + } + + public void getBytes(final int index, final HornetQBuffer dst, final int dstIndex, final int length) + { + buffer.getBytes(index, dst.byteBuf(), dstIndex, length); + } + + public void getBytes(final int index, final HornetQBuffer dst, final int length) + { + buffer.getBytes(index, dst.byteBuf(), length); + } + + public void getBytes(final int index, final HornetQBuffer dst) + { + buffer.getBytes(index, dst.byteBuf()); + } + + public char getChar(final int index) + { + return (char)buffer.getShort(index); + } + + public double getDouble(final int index) + { + return Double.longBitsToDouble(buffer.getLong(index)); + } + + public float getFloat(final int index) + { + return Float.intBitsToFloat(buffer.getInt(index)); + } + + public int getInt(final int index) + { + return buffer.getInt(index); + } + + public long getLong(final int index) + { + return buffer.getLong(index); + } + + public short getShort(final int index) + { + return buffer.getShort(index); + } + + public short getUnsignedByte(final int index) + { + return buffer.getUnsignedByte(index); + } + + public long getUnsignedInt(final int index) + { + return buffer.getUnsignedInt(index); + } + + public int getUnsignedShort(final int index) + { + return buffer.getUnsignedShort(index); + } + + public void markReaderIndex() + { + buffer.markReaderIndex(); + } + + public void markWriterIndex() + { + buffer.markWriterIndex(); + } + + public boolean readable() + { + return buffer.isReadable(); + } + + public int readableBytes() + { + return buffer.readableBytes(); + } + + public byte readByte() + { + return buffer.readByte(); + } + + public void readBytes(final byte[] dst, final int dstIndex, final int length) + { + buffer.readBytes(dst, dstIndex, length); + } + + public void readBytes(final byte[] dst) + { + buffer.readBytes(dst); + } + + public void readBytes(final ByteBuffer dst) + { + buffer.readBytes(dst); + } + + public void readBytes(final HornetQBuffer dst, final int dstIndex, final int length) + { + buffer.readBytes(dst.byteBuf(), dstIndex, length); + } + + public void readBytes(final HornetQBuffer dst, final int length) + { + buffer.readBytes(dst.byteBuf(), length); + } + + public void readBytes(final HornetQBuffer dst) + { + buffer.readBytes(dst.byteBuf()); + } + + public HornetQBuffer readBytes(final int length) + { + return new ChannelBufferWrapper(buffer.readBytes(length), releasable); + } + + public char readChar() + { + return (char)buffer.readShort(); + } + + public double readDouble() + { + return Double.longBitsToDouble(buffer.readLong()); + } + + public int readerIndex() + { + return buffer.readerIndex(); + } + + public void readerIndex(final int readerIndex) + { + buffer.readerIndex(readerIndex); + } + + public float readFloat() + { + return Float.intBitsToFloat(buffer.readInt()); + } + + public int readInt() + { + return buffer.readInt(); + } + + public long readLong() + { + return buffer.readLong(); + } + + public short readShort() + { + return buffer.readShort(); + } + + public HornetQBuffer readSlice(final int length) + { + return new ChannelBufferWrapper(buffer.readSlice(length), releasable); + } + + public short readUnsignedByte() + { + return buffer.readUnsignedByte(); + } + + public long readUnsignedInt() + { + return buffer.readUnsignedInt(); + } + + public int readUnsignedShort() + { + return buffer.readUnsignedShort(); + } + + public void resetReaderIndex() + { + buffer.resetReaderIndex(); + } + + public void resetWriterIndex() + { + buffer.resetWriterIndex(); + } + + public void setByte(final int index, final byte value) + { + buffer.setByte(index, value); + } + + public void setBytes(final int index, final byte[] src, final int srcIndex, final int length) + { + buffer.setBytes(index, src, srcIndex, length); + } + + public void setBytes(final int index, final byte[] src) + { + buffer.setBytes(index, src); + } + + public void setBytes(final int index, final ByteBuffer src) + { + buffer.setBytes(index, src); + } + + public void setBytes(final int index, final HornetQBuffer src, final int srcIndex, final int length) + { + buffer.setBytes(index, src.byteBuf(), srcIndex, length); + } + + public void setBytes(final int index, final HornetQBuffer src, final int length) + { + buffer.setBytes(index, src.byteBuf(), length); + } + + public void setBytes(final int index, final HornetQBuffer src) + { + buffer.setBytes(index, src.byteBuf()); + } + + public void setChar(final int index, final char value) + { + buffer.setShort(index, (short)value); + } + + public void setDouble(final int index, final double value) + { + buffer.setLong(index, Double.doubleToLongBits(value)); + } + + public void setFloat(final int index, final float value) + { + buffer.setInt(index, Float.floatToIntBits(value)); + } + + public void setIndex(final int readerIndex, final int writerIndex) + { + buffer.setIndex(readerIndex, writerIndex); + } + + public void setInt(final int index, final int value) + { + buffer.setInt(index, value); + } + + public void setLong(final int index, final long value) + { + buffer.setLong(index, value); + } + + public void setShort(final int index, final short value) + { + buffer.setShort(index, value); + } + + public void skipBytes(final int length) + { + buffer.skipBytes(length); + } + + public HornetQBuffer slice() + { + return new ChannelBufferWrapper(buffer.slice(), releasable); + } + + public HornetQBuffer slice(final int index, final int length) + { + return new ChannelBufferWrapper(buffer.slice(index, length), releasable); + } + + public ByteBuffer toByteBuffer() + { + return buffer.nioBuffer(); + } + + public ByteBuffer toByteBuffer(final int index, final int length) + { + return buffer.nioBuffer(index, length); + } + + public boolean writable() + { + return buffer.isWritable(); + } + + public int writableBytes() + { + return buffer.writableBytes(); + } + + public void writeByte(final byte value) + { + buffer.writeByte(value); + } + + public void writeBytes(final byte[] src, final int srcIndex, final int length) + { + buffer.writeBytes(src, srcIndex, length); + } + + public void writeBytes(final byte[] src) + { + buffer.writeBytes(src); + } + + public void writeBytes(final ByteBuffer src) + { + buffer.writeBytes(src); + } + + public void writeBytes(final HornetQBuffer src, final int srcIndex, final int length) + { + buffer.writeBytes(src.byteBuf(), srcIndex, length); + } + + public void writeBytes(final HornetQBuffer src, final int length) + { + buffer.writeBytes(src.byteBuf(), length); + } + + public void writeChar(final char chr) + { + buffer.writeShort((short)chr); + } + + public void writeDouble(final double value) + { + buffer.writeLong(Double.doubleToLongBits(value)); + } + + public void writeFloat(final float value) + { + buffer.writeInt(Float.floatToIntBits(value)); + } + + public void writeInt(final int value) + { + buffer.writeInt(value); + } + + public void writeLong(final long value) + { + buffer.writeLong(value); + } + + public int writerIndex() + { + return buffer.writerIndex(); + } + + public void writerIndex(final int writerIndex) + { + buffer.writerIndex(writerIndex); + } + + public void writeShort(final short value) + { + buffer.writeShort(value); + } + +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/23e8edd9/activemq6-commons/src/main/java/org/apache/activemq6/core/server/HornetQComponent.java ---------------------------------------------------------------------- diff --git a/activemq6-commons/src/main/java/org/apache/activemq6/core/server/HornetQComponent.java b/activemq6-commons/src/main/java/org/apache/activemq6/core/server/HornetQComponent.java new file mode 100644 index 0000000..95a5fdd --- /dev/null +++ b/activemq6-commons/src/main/java/org/apache/activemq6/core/server/HornetQComponent.java @@ -0,0 +1,31 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package org.apache.activemq6.core.server; + +/** + * A HornetQComponent + * + * @author <a href="mailto:[email protected]">Tim Fox</a> + * @version <tt>$Revision: 2796 $</tt> + * + * + */ +public interface HornetQComponent +{ + void start() throws Exception; + + void stop() throws Exception; + + boolean isStarted(); +}
