diff options
author | Robert Godfrey <rgodfrey@apache.org> | 2012-01-31 23:56:32 +0000 |
---|---|---|
committer | Robert Godfrey <rgodfrey@apache.org> | 2012-01-31 23:56:32 +0000 |
commit | 6c80aafda9ac7e7347c8bfb9ff56a301e6806ba2 (patch) | |
tree | 639a22f379a169b46daf5327bfccf062f0da57b7 /java/client/src | |
parent | a3f300040533210249fa1a7a710e979f1925f9e1 (diff) | |
download | qpid-python-6c80aafda9ac7e7347c8bfb9ff56a301e6806ba2.tar.gz |
QPID-3789 : [Java] Remove duplication of BytesDataOutput inner class, and shared code in SessionAdapt[eo]rs
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1238868 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/client/src')
5 files changed, 199 insertions, 419 deletions
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQQueueSessionAdaptor.java b/java/client/src/main/java/org/apache/qpid/client/AMQQueueSessionAdaptor.java index d1c796c34a..58b52a3cc9 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQQueueSessionAdaptor.java +++ b/java/client/src/main/java/org/apache/qpid/client/AMQQueueSessionAdaptor.java @@ -28,156 +28,57 @@ import java.io.Serializable; * Need this adaptor class to conform to JMS spec and throw IllegalStateException * from createDurableSubscriber, unsubscribe, createTopic & createTemporaryTopic */ -public class AMQQueueSessionAdaptor implements QueueSession, AMQSessionAdapter +class AMQQueueSessionAdaptor extends AMQSessionAdapter<QueueSession> implements QueueSession { - //holds a session for delegation - private final AMQSession _session; - /** * Construct an adaptor with a session to wrap * @param session */ - public AMQQueueSessionAdaptor(Session session) + protected AMQQueueSessionAdaptor(QueueSession session) { - _session = (AMQSession) session; - } - - public TemporaryQueue createTemporaryQueue() throws JMSException { - return _session.createTemporaryQueue(); - } - - public Queue createQueue(String string) throws JMSException { - return _session.createQueue(string); - } - - public QueueReceiver createReceiver(Queue queue) throws JMSException { - return _session.createReceiver(queue); - } - - public QueueReceiver createReceiver(Queue queue, String string) throws JMSException { - return _session.createReceiver(queue, string); - } - - public QueueSender createSender(Queue queue) throws JMSException { - return _session.createSender(queue); - } - - public QueueBrowser createBrowser(Queue queue) throws JMSException { - return _session.createBrowser(queue); - } - - public QueueBrowser createBrowser(Queue queue, String string) throws JMSException { - return _session.createBrowser(queue, string); - } - - public BytesMessage createBytesMessage() throws JMSException { - return _session.createBytesMessage(); - } - - public MapMessage createMapMessage() throws JMSException { - return _session.createMapMessage(); - } - - public Message createMessage() throws JMSException { - return _session.createMessage(); - } - - public ObjectMessage createObjectMessage() throws JMSException { - return _session.createObjectMessage(); - } - - public ObjectMessage createObjectMessage(Serializable serializable) throws JMSException { - return _session.createObjectMessage(serializable); - } - - public StreamMessage createStreamMessage() throws JMSException { - return _session.createStreamMessage(); - } - - public TextMessage createTextMessage() throws JMSException { - return _session.createTextMessage(); - } - - public TextMessage createTextMessage(String string) throws JMSException { - return _session.createTextMessage(string); + super(session); } - public boolean getTransacted() throws JMSException { - return _session.getTransacted(); - } - - public int getAcknowledgeMode() throws JMSException { - return _session.getAcknowledgeMode(); - } - - public void commit() throws JMSException { - _session.commit(); - } - - public void rollback() throws JMSException { - _session.rollback(); - } - - public void close() throws JMSException { - _session.close(); - } - - public void recover() throws JMSException { - _session.recover(); - } - - public MessageListener getMessageListener() throws JMSException { - return _session.getMessageListener(); - } - - public void setMessageListener(MessageListener messageListener) throws JMSException { - _session.setMessageListener(messageListener); - } - - public void run() { - _session.run(); - } - - public MessageProducer createProducer(Destination destination) throws JMSException { - return _session.createProducer(destination); - } - - public MessageConsumer createConsumer(Destination destination) throws JMSException { - return _session.createConsumer(destination); + public QueueReceiver createReceiver(Queue queue) throws JMSException + { + return getSession().createReceiver(queue); } - public MessageConsumer createConsumer(Destination destination, String string) throws JMSException { - return _session.createConsumer(destination,string); + public QueueReceiver createReceiver(Queue queue, String string) throws JMSException + { + return getSession().createReceiver(queue, string); } - public MessageConsumer createConsumer(Destination destination, String string, boolean b) throws JMSException { - return _session.createConsumer(destination,string,b); + public QueueSender createSender(Queue queue) throws JMSException + { + return getSession().createSender(queue); } //The following methods cannot be called from a QueueSession as per JMS spec - public Topic createTopic(String string) throws JMSException { + public Topic createTopic(String string) throws JMSException + { throw new IllegalStateException("Cannot call createTopic from QueueSession"); } - public TopicSubscriber createDurableSubscriber(Topic topic, String string) throws JMSException { + public TopicSubscriber createDurableSubscriber(Topic topic, String string) throws JMSException + { throw new IllegalStateException("Cannot call createDurableSubscriber from QueueSession"); } - public TopicSubscriber createDurableSubscriber(Topic topic, String string, String string1, boolean b) throws JMSException { + public TopicSubscriber createDurableSubscriber(Topic topic, String string, String string1, boolean b) throws JMSException + { throw new IllegalStateException("Cannot call createDurableSubscriber from QueueSession"); } - public TemporaryTopic createTemporaryTopic() throws JMSException { + public TemporaryTopic createTemporaryTopic() throws JMSException + { throw new IllegalStateException("Cannot call createTemporaryTopic from QueueSession"); } - public void unsubscribe(String string) throws JMSException { + public void unsubscribe(String string) throws JMSException + { throw new IllegalStateException("Cannot call unsubscribe from QueueSession"); } - public AMQSession getSession() - { - return _session; - } } diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQSessionAdapter.java b/java/client/src/main/java/org/apache/qpid/client/AMQSessionAdapter.java index 7e257e0c20..e94099f066 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQSessionAdapter.java +++ b/java/client/src/main/java/org/apache/qpid/client/AMQSessionAdapter.java @@ -20,7 +20,172 @@ */ package org.apache.qpid.client; -public interface AMQSessionAdapter +import javax.jms.*; +import java.io.Serializable; + +public abstract class AMQSessionAdapter<T extends Session> implements Session { - public AMQSession getSession(); + private final T _session; + + protected AMQSessionAdapter(final T session) + { + _session = session; + } + + public T getSession() + { + return _session; + } + + public BytesMessage createBytesMessage() throws JMSException + { + return _session.createBytesMessage(); + } + + public MapMessage createMapMessage() throws JMSException + { + return _session.createMapMessage(); + } + + public Message createMessage() throws JMSException + { + return _session.createMessage(); + } + + public ObjectMessage createObjectMessage() throws JMSException + { + return _session.createObjectMessage(); + } + + public ObjectMessage createObjectMessage(final Serializable serializable) throws JMSException + { + return _session.createObjectMessage(serializable); + } + + public StreamMessage createStreamMessage() throws JMSException + { + return _session.createStreamMessage(); + } + + public TextMessage createTextMessage() throws JMSException + { + return _session.createTextMessage(); + } + + public TextMessage createTextMessage(final String s) throws JMSException + { + return _session.createTextMessage(s); + } + + public boolean getTransacted() throws JMSException + { + return _session.getTransacted(); + } + + public int getAcknowledgeMode() throws JMSException + { + return _session.getAcknowledgeMode(); + } + + public void commit() throws JMSException + { + _session.commit(); + } + + public void rollback() throws JMSException + { + _session.rollback(); + } + + public void close() throws JMSException + { + _session.close(); + } + + public void recover() throws JMSException + { + _session.recover(); + } + + public MessageListener getMessageListener() throws JMSException + { + return _session.getMessageListener(); + } + + public void setMessageListener(final MessageListener messageListener) throws JMSException + { + _session.setMessageListener(messageListener); + } + + public void run() + { + _session.run(); + } + + public MessageProducer createProducer(final Destination destination) throws JMSException + { + return _session.createProducer(destination); + } + + public MessageConsumer createConsumer(final Destination destination) throws JMSException + { + return _session.createConsumer(destination); + } + + public MessageConsumer createConsumer(final Destination destination, final String s) throws JMSException + { + return _session.createConsumer(destination, s); + } + + public MessageConsumer createConsumer(final Destination destination, final String s, final boolean b) + throws JMSException + { + return _session.createConsumer(destination, s, b); + } + + public Queue createQueue(final String s) throws JMSException + { + return _session.createQueue(s); + } + + public Topic createTopic(final String s) throws JMSException + { + return _session.createTopic(s); + } + + public TopicSubscriber createDurableSubscriber(final Topic topic, final String s) throws JMSException + { + return _session.createDurableSubscriber(topic, s); + } + + public TopicSubscriber createDurableSubscriber(final Topic topic, final String s, final String s1, final boolean b) + throws JMSException + { + return _session.createDurableSubscriber(topic, s, s1, b); + } + + public QueueBrowser createBrowser(final Queue queue) throws JMSException + { + return _session.createBrowser(queue); + } + + public QueueBrowser createBrowser(final Queue queue, final String s) throws JMSException + { + return _session.createBrowser(queue, s); + } + + public TemporaryQueue createTemporaryQueue() throws JMSException + { + return _session.createTemporaryQueue(); + } + + public TemporaryTopic createTemporaryTopic() throws JMSException + { + return _session.createTemporaryTopic(); + } + + public void unsubscribe(final String s) throws JMSException + { + _session.unsubscribe(s); + } } diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQTopicSessionAdaptor.java b/java/client/src/main/java/org/apache/qpid/client/AMQTopicSessionAdaptor.java index 6e454cdae9..6e0c658db7 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQTopicSessionAdaptor.java +++ b/java/client/src/main/java/org/apache/qpid/client/AMQTopicSessionAdaptor.java @@ -24,158 +24,27 @@ import javax.jms.*; import javax.jms.IllegalStateException; import java.io.Serializable; -public class AMQTopicSessionAdaptor implements TopicSession, AMQSessionAdapter +class AMQTopicSessionAdaptor extends AMQSessionAdapter<TopicSession> implements TopicSession { - private final AMQSession _session; - public AMQTopicSessionAdaptor(Session session) + public AMQTopicSessionAdaptor(TopicSession session) { - _session = (AMQSession) session; - } - - public Topic createTopic(String string) throws JMSException - { - return _session.createTopic(string); + super(session); } public TopicSubscriber createSubscriber(Topic topic) throws JMSException { - return _session.createSubscriber(topic); + return getSession().createSubscriber(topic); } public TopicSubscriber createSubscriber(Topic topic, String string, boolean b) throws JMSException { - return _session.createSubscriber(topic, string, b); - } - - public TopicSubscriber createDurableSubscriber(Topic topic, String string) throws JMSException - { - return _session.createDurableSubscriber(topic, string); - } - - public TopicSubscriber createDurableSubscriber(Topic topic, String string, String string1, boolean b) throws JMSException - { - return _session.createDurableSubscriber(topic, string, string1, b); + return getSession().createSubscriber(topic, string, b); } public TopicPublisher createPublisher(Topic topic) throws JMSException { - return _session.createPublisher(topic); - } - - public TemporaryTopic createTemporaryTopic() throws JMSException - { - return _session.createTemporaryTopic(); - } - - public void unsubscribe(String string) throws JMSException - { - _session.unsubscribe(string); - } - - public BytesMessage createBytesMessage() throws JMSException - { - return _session.createBytesMessage(); - } - - public MapMessage createMapMessage() throws JMSException - { - return _session.createMapMessage(); - } - - public Message createMessage() throws JMSException - { - return _session.createMessage(); - } - - public ObjectMessage createObjectMessage() throws JMSException - { - return _session.createObjectMessage(); - } - - public ObjectMessage createObjectMessage(Serializable serializable) throws JMSException - { - return _session.createObjectMessage(serializable); - } - - public StreamMessage createStreamMessage() throws JMSException - { - return _session.createStreamMessage(); - } - - public TextMessage createTextMessage() throws JMSException - { - return _session.createTextMessage(); - } - - public TextMessage createTextMessage(String string) throws JMSException - { - return _session.createTextMessage(string); - } - - public boolean getTransacted() throws JMSException - { - return _session.getTransacted(); - } - - public int getAcknowledgeMode() throws JMSException - { - return _session.getAcknowledgeMode(); - } - - public void commit() throws JMSException - { - _session.commit(); - } - - public void rollback() throws JMSException - { - _session.rollback(); - } - - public void close() throws JMSException - { - _session.close(); - } - - public void recover() throws JMSException - { - _session.recover(); - } - - public MessageListener getMessageListener() throws JMSException - { - return _session.getMessageListener(); - } - - public void setMessageListener(MessageListener messageListener) throws JMSException - { - _session.setMessageListener(messageListener); - } - - public void run() - { - _session.run(); - } - - public MessageProducer createProducer(Destination destination) throws JMSException - { - return _session.createProducer(destination); - } - - public MessageConsumer createConsumer(Destination destination) throws JMSException - { - return _session.createConsumer(destination); - } - - public MessageConsumer createConsumer(Destination destination, String string) throws JMSException - { - return _session.createConsumer(destination, string); - } - - public MessageConsumer createConsumer(Destination destination, String string, boolean b) throws JMSException - { - return _session.createConsumer(destination, string, b); + return getSession().createPublisher(topic); } //The following methods cannot be called from a TopicSession as per JMS spec @@ -199,8 +68,4 @@ public class AMQTopicSessionAdaptor implements TopicSession, AMQSessionAdapter throw new IllegalStateException("Cannot call createTemporaryQueue from TopicSession"); } - public AMQSession getSession() - { - return _session; - } } diff --git a/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java b/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java index 2bc2d2ef03..6b59a69bc9 100644 --- a/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java +++ b/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java @@ -20,6 +20,7 @@ */ package org.apache.qpid.client.protocol; +import org.apache.qpid.util.BytesDataOutput; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -863,160 +864,6 @@ public class AMQProtocolHandler implements ProtocolEngine return _suggestedProtocolVersion; } - private static class BytesDataOutput implements DataOutput - { - private int _pos = 0; - private byte[] _buf; - - public BytesDataOutput(byte[] buf) - { - _buf = buf; - } - - public void setBuffer(byte[] buf) - { - _buf = buf; - _pos = 0; - } - - public void reset() - { - _pos = 0; - } - - public int length() - { - return _pos; - } - - public void write(int b) - { - _buf[_pos++] = (byte) b; - } - - public void write(byte[] b) - { - System.arraycopy(b, 0, _buf, _pos, b.length); - _pos+=b.length; - } - - - public void write(byte[] b, int off, int len) - { - System.arraycopy(b, off, _buf, _pos, len); - _pos+=len; - - } - - public void writeBoolean(boolean v) - { - _buf[_pos++] = v ? (byte) 1 : (byte) 0; - } - - public void writeByte(int v) - { - _buf[_pos++] = (byte) v; - } - - public void writeShort(int v) - { - _buf[_pos++] = (byte) (v >>> 8); - _buf[_pos++] = (byte) v; - } - - public void writeChar(int v) - { - _buf[_pos++] = (byte) (v >>> 8); - _buf[_pos++] = (byte) v; - } - - public void writeInt(int v) - { - _buf[_pos++] = (byte) (v >>> 24); - _buf[_pos++] = (byte) (v >>> 16); - _buf[_pos++] = (byte) (v >>> 8); - _buf[_pos++] = (byte) v; - } - - public void writeLong(long v) - { - _buf[_pos++] = (byte) (v >>> 56); - _buf[_pos++] = (byte) (v >>> 48); - _buf[_pos++] = (byte) (v >>> 40); - _buf[_pos++] = (byte) (v >>> 32); - _buf[_pos++] = (byte) (v >>> 24); - _buf[_pos++] = (byte) (v >>> 16); - _buf[_pos++] = (byte) (v >>> 8); - _buf[_pos++] = (byte)v; - } - - public void writeFloat(float v) - { - writeInt(Float.floatToIntBits(v)); - } - - public void writeDouble(double v) - { - writeLong(Double.doubleToLongBits(v)); - } - - public void writeBytes(String s) - { - int len = s.length(); - for (int i = 0 ; i < len ; i++) - { - _buf[_pos++] = ((byte)s.charAt(i)); - } - } - - public void writeChars(String s) - { - int len = s.length(); - for (int i = 0 ; i < len ; i++) - { - int v = s.charAt(i); - _buf[_pos++] = (byte) (v >>> 8); - _buf[_pos++] = (byte) v; - } - } - - public void writeUTF(String s) - { - int strlen = s.length(); - - int pos = _pos; - _pos+=2; - - - for (int i = 0; i < strlen; i++) - { - int c = s.charAt(i); - if ((c >= 0x0001) && (c <= 0x007F)) - { - c = s.charAt(i); - _buf[_pos++] = (byte) c; - - } - else if (c > 0x07FF) - { - _buf[_pos++] = (byte) (0xE0 | ((c >> 12) & 0x0F)); - _buf[_pos++] = (byte) (0x80 | ((c >> 6) & 0x3F)); - _buf[_pos++] = (byte) (0x80 | (c & 0x3F)); - } - else - { - _buf[_pos++] = (byte) (0xC0 | ((c >> 6) & 0x1F)); - _buf[_pos++] = (byte) (0x80 | (c & 0x3F)); - } - } - - int len = _pos - (pos + 2); - - _buf[pos++] = (byte) (len >>> 8); - _buf[pos] = (byte) len; - } - - } } diff --git a/java/client/src/main/java/org/apache/qpid/jms/Session.java b/java/client/src/main/java/org/apache/qpid/jms/Session.java index 5287381fae..b4bf2d1d85 100644 --- a/java/client/src/main/java/org/apache/qpid/jms/Session.java +++ b/java/client/src/main/java/org/apache/qpid/jms/Session.java @@ -26,9 +26,11 @@ import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.MessageConsumer; import javax.jms.MessageProducer; +import javax.jms.QueueSession; +import javax.jms.TopicSession; -public interface Session extends javax.jms.Session +public interface Session extends TopicSession, QueueSession { /** * Indicates that no client acknowledgements are required. Broker assumes that once it has delivered |