summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRajith Muditha Attapattu <rajith@apache.org>2012-06-15 17:21:42 +0000
committerRajith Muditha Attapattu <rajith@apache.org>2012-06-15 17:21:42 +0000
commit03dc29735d9a20cc62df9aac4c1a9c6a197365ca (patch)
tree5a36b9d89671d11e3150e4afb447130d35bc8db0
parent4dafd70746fa8efb643c46c896a0b9084eb52a3a (diff)
downloadqpid-python-03dc29735d9a20cc62df9aac4c1a9c6a197365ca.tar.gz
QPID-4027 Added sub interfaces for Message class to retrieve specific
content types. Added a MessageFactory to create concrete Message objects with given content. It can also decode a generic message object in a specific content type such as String, Map or List. This is useful if you don't want to cast your message into a specific sub interface type. git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/address-refactor2@1350706 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/java/client-api/src/main/java/org/apache/qpid/messaging/ListMessage.java25
-rw-r--r--qpid/java/client-api/src/main/java/org/apache/qpid/messaging/MapMessage.java25
-rw-r--r--qpid/java/client-api/src/main/java/org/apache/qpid/messaging/Message.java27
-rw-r--r--qpid/java/client-api/src/main/java/org/apache/qpid/messaging/MessageFactory.java50
-rw-r--r--qpid/java/client-api/src/main/java/org/apache/qpid/messaging/StringMessage.java23
-rw-r--r--qpid/java/client-api/src/main/java/org/apache/qpid/messaging/cpp/TextMessage.java219
6 files changed, 149 insertions, 220 deletions
diff --git a/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/ListMessage.java b/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/ListMessage.java
new file mode 100644
index 0000000000..26d1eda1ac
--- /dev/null
+++ b/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/ListMessage.java
@@ -0,0 +1,25 @@
+/* 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.qpid.messaging;
+
+import java.util.List;
+
+public interface ListMessage extends Message
+{
+ public List<Object> getList() throws MessageEncodingException;
+}
diff --git a/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/MapMessage.java b/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/MapMessage.java
new file mode 100644
index 0000000000..941e11ee6d
--- /dev/null
+++ b/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/MapMessage.java
@@ -0,0 +1,25 @@
+/* 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.qpid.messaging;
+
+import java.util.Map;
+
+public interface MapMessage extends Message
+{
+ public Map<String,Object> getMap() throws MessageEncodingException;
+}
diff --git a/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/Message.java b/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/Message.java
index af3019e9ec..8f61b72da8 100644
--- a/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/Message.java
+++ b/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/Message.java
@@ -17,14 +17,39 @@
*/
package org.apache.qpid.messaging;
+import java.nio.ByteBuffer;
import java.util.Map;
/**
* Representation of a message.
+ * The getters/setters are for the message headers.
+ *
+ * To get the content of a message you need to either,
+ * (1) use the generic method @see Message#getContent() which returns a ByteBuffer,
+ *
+ * (2) cast a generic Message, to a specific sub interface type and invoke the specific method.
+ * @see StringMessage#getString()
+ * @see MapMessage#getMap()
+ * @see ListMessage#getList()
+ *
+ * (2) Or use one of the convenience methods provided by the MessageFactory.
+ * @see MessageFactory#getContentAsString(Message)
+ * @see MessageFactory#getContentAsMap(Message)
+ * @see MessageFactory#getContentAsList(Message)
+ *
+ * To create a specific a concrete Message with a specific content type
+ * you need to use one of the following methods from the @see MessageFactory
+ * @see MessageFactory#createMessage(String)
+ * @see MessageFactory#createMessage(byte[])
+ * @see MessageFactory#createMessage(java.nio.ByteBuffer)
+ * @see MessageFactory#createMessage(java.util.Map)
+ * @see MessageFactory#createMessage(java.util.List)
*/
public interface Message
{
- public Object getContent() throws MessagingException;
+ public final static String QPID_SUBJECT = "qpid.subject";
+
+ public ByteBuffer getContent();
public String getMessageId() throws MessagingException;
diff --git a/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/MessageFactory.java b/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/MessageFactory.java
new file mode 100644
index 0000000000..204f7cc35f
--- /dev/null
+++ b/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/MessageFactory.java
@@ -0,0 +1,50 @@
+/* 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.qpid.messaging;
+
+import java.nio.ByteBuffer;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The message factory is responsible for returning
+ * a concrete implementation of the message interface
+ * with the given content.
+ *
+ * A reference to the Message Factory can be obtained via
+ * the Connection object.
+ * @see Connection#getMessageFactory()
+ */
+public interface MessageFactory
+{
+ Message createMessage(String text) throws MessageEncodingException;
+
+ Message createMessage(byte[] bytes) throws MessageEncodingException;
+
+ Message createMessage(ByteBuffer buf) throws MessageEncodingException;
+
+ Message createMessage(Map<String,Object> map) throws MessageEncodingException;
+
+ Message createMessage(List<Object> list) throws MessageEncodingException;
+
+ String getContentAsString(Message m) throws MessageEncodingException;
+
+ Map<String,Object> getContentAsMap(Message m) throws MessageEncodingException;
+
+ List<Object> getContentAsList(Message m) throws MessageEncodingException;
+}
diff --git a/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/StringMessage.java b/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/StringMessage.java
new file mode 100644
index 0000000000..ddf742064e
--- /dev/null
+++ b/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/StringMessage.java
@@ -0,0 +1,23 @@
+/* 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.qpid.messaging;
+
+public interface StringMessage extends Message
+{
+ public String getString() throws MessageEncodingException;
+}
diff --git a/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/cpp/TextMessage.java b/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/cpp/TextMessage.java
deleted file mode 100644
index e9a311c606..0000000000
--- a/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/cpp/TextMessage.java
+++ /dev/null
@@ -1,219 +0,0 @@
-/* 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.qpid.messaging.cpp;
-
-import java.util.Map;
-
-public class TextMessage implements org.apache.qpid.messaging.Message
-{
-
- org.apache.qpid.messaging.cpp.jni.Message _cppMessage;
-
- public TextMessage(String text)
- {
- _cppMessage = new org.apache.qpid.messaging.cpp.jni.Message(text);
- _cppMessage.setContentType("text/plain");
- _cppMessage.setPriority((byte)5);
- }
-
- public TextMessage(org.apache.qpid.messaging.cpp.jni.Message msg)
- {
- _cppMessage = msg;
- }
-
- @Override
- public Object getContent()
- {
- return _cppMessage.getContent();
- }
-
- @Override
- public String getMessageId()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public void setMessageId(String messageId)
- {
- _cppMessage.setMessageId(messageId);
-
- }
-
- @Override
- public String getSubject()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public void setSubject(String subject)
- {
- _cppMessage.setMessageId(subject);
- }
-
- @Override
- public String getContentType()
- {
- return _cppMessage.getContentType();
- }
-
- @Override
- public void setContentType(String contentType)
- {
- _cppMessage.setContentType(contentType);
- }
-
- @Override
- public String getCorrelationId()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public void setCorrelationId(String correlationId)
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public String getReplyTo()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public void setReplyTo(String replyTo)
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public String getUserId()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public void setUserId(String userId)
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public boolean isDurable()
- {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public void setDurable(boolean durable)
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public boolean isRedelivered()
- {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public void setRedelivered(boolean redelivered)
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public int getPriority()
- {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- public void setPriority(int priority)
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public long getTtl()
- {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- public void setTtl(long ttl)
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public long getTimestamp()
- {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- public void setTimestamp(long timestamp)
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public Map<String, Object> getProperties()
- {
- return _cppMessage.getProperties();
- }
-
- @Override
- public void setProperty(String key, Object value)
- {
- _cppMessage.setProperty(key, value);
- }
-
- protected org.apache.qpid.messaging.cpp.jni.Message getCppMessage()
- {
- return _cppMessage;
- }
-
- @Override
- public String toString()
- {
- return _cppMessage.toString();
- }
-
-}