diff options
author | Rafael H. Schloming <rhs@apache.org> | 2008-05-23 19:16:04 +0000 |
---|---|---|
committer | Rafael H. Schloming <rhs@apache.org> | 2008-05-23 19:16:04 +0000 |
commit | 51db72d6d1fdbaebfc2f91fec611cf26d35ea8f5 (patch) | |
tree | 31e58d40ccc2d898b840c21b5a32030a671091d2 /java/common | |
parent | 896d94f7c27e958806b96b537a7a96208ede145a (diff) | |
download | qpid-python-51db72d6d1fdbaebfc2f91fec611cf26d35ea8f5.tar.gz |
QPID-901: Track and report session exceptions, modified generator validate values before trying to encode them. Also, moved createDurableSubscriber from AMQSession_0_10 -> AMQSession.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@659631 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/common')
8 files changed, 261 insertions, 3 deletions
diff --git a/java/common/Composite.tpl b/java/common/Composite.tpl index 4e1a54de81..4f72279bcc 100644 --- a/java/common/Composite.tpl +++ b/java/common/Composite.tpl @@ -8,6 +8,7 @@ import java.util.UUID; import org.apache.qpidity.transport.codec.Decoder; import org.apache.qpidity.transport.codec.Encodable; import org.apache.qpidity.transport.codec.Encoder; +import org.apache.qpidity.transport.codec.Validator; import org.apache.qpidity.transport.network.Frame; @@ -136,6 +137,7 @@ for f in fields: } public final $name $(f.set)($(f.type) value) { + $(f.check) this.$(f.name) = value; this.has_$(f.name) = true; this.dirty = true; @@ -143,6 +145,7 @@ for f in fields: } public final $name $(f.name)($(f.type) value) { + $(f.check) this.$(f.name) = value; this.has_$(f.name) = true; this.dirty = true; diff --git a/java/common/genutil.py b/java/common/genutil.py index 4aba529182..dac0d65611 100644 --- a/java/common/genutil.py +++ b/java/common/genutil.py @@ -152,15 +152,18 @@ class Field: if self.type_node.name == "struct": self.read = "(%s) dec.readStruct(%s.TYPE)" % (tname, tname) self.write = "enc.writeStruct(%s.TYPE, check(struct).%s)" % (tname, self.name) + self.check = "" self.coder = "Struct" elif self.type_node.name == "domain": self.coder = camel(0, resolve_type(self.type_node)["@name"]) self.read = "%s.get(dec.read%s())" % (tname, self.coder) self.write = "enc.write%s(check(struct).%s.getValue())" % (self.coder, self.name) + self.check = "" else: self.coder = camel(0, self.type_node["@name"]) self.read = "dec.read%s()" % self.coder self.write = "enc.write%s(check(struct).%s)" % (self.coder, self.name) + self.check = "Validator.check%s(value);" % self.coder self.type = jtype(self.type_node) self.default = DEFAULTS.get(self.type, "null") self.has = camel(1, "has", self.name) diff --git a/java/common/src/main/java/org/apache/qpidity/transport/ChannelDelegate.java b/java/common/src/main/java/org/apache/qpidity/transport/ChannelDelegate.java index 7f4365f515..5361613e1e 100644 --- a/java/common/src/main/java/org/apache/qpidity/transport/ChannelDelegate.java +++ b/java/common/src/main/java/org/apache/qpidity/transport/ChannelDelegate.java @@ -47,4 +47,9 @@ class ChannelDelegate extends MethodDelegate<Channel> // weak hash map in connection. } + public @Override void sessionDetach(Channel channel, SessionDetach dtc) + { + channel.getSession().closed(); + } + } diff --git a/java/common/src/main/java/org/apache/qpidity/transport/Session.java b/java/common/src/main/java/org/apache/qpidity/transport/Session.java index a61f5c2aa3..4e82e893d7 100644 --- a/java/common/src/main/java/org/apache/qpidity/transport/Session.java +++ b/java/common/src/main/java/org/apache/qpidity/transport/Session.java @@ -26,6 +26,7 @@ import org.apache.qpidity.transport.network.Frame; import org.apache.qpidity.transport.util.Logger; import java.nio.ByteBuffer; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -310,7 +311,7 @@ public class Session extends Invoker { if (closed.get()) { - throw new RuntimeException("session closed"); + throw new SessionException(getExceptions()); } else { @@ -322,6 +323,8 @@ public class Session extends Invoker private Map<Integer,ResultFuture<?>> results = new HashMap<Integer,ResultFuture<?>>(); + private List<ExecutionException> exceptions = + new ArrayList<ExecutionException>(); void result(int command, Struct result) { @@ -333,6 +336,22 @@ public class Session extends Invoker future.set(result); } + void addException(ExecutionException exc) + { + synchronized (exceptions) + { + exceptions.add(exc); + } + } + + List<ExecutionException> getExceptions() + { + synchronized (exceptions) + { + return new ArrayList<ExecutionException>(exceptions); + } + } + protected <T> Future<T> invoke(Method m, Class<T> klass) { synchronized (commands) @@ -395,7 +414,7 @@ public class Session extends Invoker } else if (closed.get()) { - throw new RuntimeException("session closed"); + throw new SessionException(getExceptions()); } else { diff --git a/java/common/src/main/java/org/apache/qpidity/transport/SessionDelegate.java b/java/common/src/main/java/org/apache/qpidity/transport/SessionDelegate.java index 0cc3d5393a..8d9b2e730e 100644 --- a/java/common/src/main/java/org/apache/qpidity/transport/SessionDelegate.java +++ b/java/common/src/main/java/org/apache/qpidity/transport/SessionDelegate.java @@ -59,6 +59,11 @@ public abstract class SessionDelegate ssn.result(result.getCommandId(), result.getValue()); } + @Override public void executionException(Session ssn, ExecutionException exc) + { + ssn.addException(exc); + } + @Override public void sessionCompleted(Session ssn, SessionCompleted cmp) { RangeSet ranges = cmp.getCommands(); diff --git a/java/common/src/main/java/org/apache/qpidity/transport/SessionException.java b/java/common/src/main/java/org/apache/qpidity/transport/SessionException.java new file mode 100644 index 0000000000..fc866f3694 --- /dev/null +++ b/java/common/src/main/java/org/apache/qpidity/transport/SessionException.java @@ -0,0 +1,46 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.qpidity.transport; + +import java.util.List; + +/** + * SessionException + * + */ + +public class SessionException extends RuntimeException +{ + + private List<ExecutionException> exceptions; + + public SessionException(List<ExecutionException> exceptions) + { + super(exceptions.isEmpty() ? "" : exceptions.toString()); + this.exceptions = exceptions; + } + + public List<ExecutionException> getExceptions() + { + return exceptions; + } + +} diff --git a/java/common/src/main/java/org/apache/qpidity/transport/codec/AbstractEncoder.java b/java/common/src/main/java/org/apache/qpidity/transport/codec/AbstractEncoder.java index 3596c48956..4e9f918b61 100644 --- a/java/common/src/main/java/org/apache/qpidity/transport/codec/AbstractEncoder.java +++ b/java/common/src/main/java/org/apache/qpidity/transport/codec/AbstractEncoder.java @@ -340,7 +340,7 @@ abstract class AbstractEncoder implements Encoder } } - private Type resolve(Class klass) + static final Type resolve(Class klass) { Type type = ENCODINGS.get(klass); if (type != null) diff --git a/java/common/src/main/java/org/apache/qpidity/transport/codec/Validator.java b/java/common/src/main/java/org/apache/qpidity/transport/codec/Validator.java new file mode 100644 index 0000000000..743e9f3cae --- /dev/null +++ b/java/common/src/main/java/org/apache/qpidity/transport/codec/Validator.java @@ -0,0 +1,177 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.qpidity.transport.codec; + +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.qpidity.transport.RangeSet; +import org.apache.qpidity.transport.Struct; + + +/** + * Validator + * + */ + +public class Validator +{ + + public static final void checkBit(boolean b) + { + // no illegal values + } + + public static final void checkUint8(short s) + { + if (s > 0xFF || s < 0) + { + throw new IllegalArgumentException("" + s); + } + } + + public static final void checkUint16(int i) + { + if (i > 0xFFFF || i < 0) + { + throw new IllegalArgumentException("" + i); + } + } + + public static final void checkUint32(long l) + { + // XXX: we can't currently validate this because we do thinks + // like pass in -1 for 0xFFFFFFFF + // if (l > 0xFFFFFFFFL || l < 0) + // { + // throw new IllegalArgumentException("" + l); + // } + } + + public static final void checkSequenceNo(int s) + { + // no illegal values + } + + public static final void checkUint64(long l) + { + // no illegal values + } + + public static final void checkDatetime(long l) + { + // no illegal values + } + + public static final void checkUuid(UUID u) + { + // no illegal values + } + + public static final void checkStr8(String value) + { + if (value != null && value.length() > 255) + { + throw new IllegalArgumentException("" + value); + } + } + + public static final void checkStr16(String value) + { + if (value != null && value.length() > 0xFFFF) + { + throw new IllegalArgumentException("" + value); + } + } + + public static final void checkVbin8(byte[] value) + { + if (value != null && value.length > 255) + { + throw new IllegalArgumentException("" + value); + } + } + + public static final void checkVbin16(byte[] value) + { + if (value != null && value.length > 0xFFFF) + { + throw new IllegalArgumentException("" + value); + } + } + + public static final void checkByteRanges(RangeSet r) + { + // no illegal values + } + + public static final void checkSequenceSet(RangeSet r) + { + // no illegal values + } + + public static final void checkVbin32(byte[] value) + { + // no illegal values + } + + public static final void checkStruct32(Struct s) + { + // no illegal values + } + + public static final void checkArray(List<Object> array) + { + if (array == null) + { + return; + } + + for (Object o : array) + { + checkObject(o); + } + } + + public static final void checkMap(Map<String,Object> map) + { + if (map == null) + { + return; + } + + for (Map.Entry<String,Object> entry : map.entrySet()) + { + checkStr8(entry.getKey()); + checkObject(entry.getValue()); + } + } + + public static final void checkObject(Object o) + { + if (o != null && AbstractEncoder.resolve(o.getClass()) == null) + { + throw new IllegalArgumentException("cannot encode " + o.getClass()); + } + } + +} |