Permalink
Browse files

Removed all of the Override annotation since this is not required when

build a jdk 1.6 target.

The MessageCreator has been updated as a generic instance instead where
the sub-classes will be Message specific.  For instance, the
TextMessageCreator will create a TextMessage instance and expects a
TextMessage to be passed.

Created the BytesMessageCreator, MapMessageCreator, ObjectMessageCreator
and StreamMessageCreator classes.
  • Loading branch information...
1 parent a736504 commit 56b9fe9f89b9d430d31c6b48e462fd23464e96cf @ccorsi committed Nov 23, 2011
@@ -26,14 +26,13 @@
* @author Claudio Corsi
*
*/
-public abstract class AbstractMessageCreator implements MessageCreator {
+public abstract class AbstractMessageCreator<T extends Message> implements MessageCreator {
private MessageChain chain = new NoopMessageChain();
/* (non-Javadoc)
* @see com.fusesource.support.producers.MessageCreator#add(com.fusesource.support.message.chains.MessageChain)
*/
- @Override
public void add(MessageChain chain) {
this.chain.chain(chain);
}
@@ -42,7 +41,7 @@ public void add(MessageChain chain) {
* @param message
* @throws JMSException
*/
- protected void apply(Message message) throws JMSException {
+ protected void apply(T message) throws JMSException {
MessageChain current = this.chain;
while(current != null) {
current.apply(message);
@@ -0,0 +1,48 @@
+/**
+ * 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 com.fusesource.support.message.creator;
+
+import javax.jms.BytesMessage;
+import javax.jms.JMSException;
+import javax.jms.Session;
+
+/**
+ * @author Claudio Corsi
+ *
+ */
+public class BytesMessageCreator extends AbstractMessageCreator<BytesMessage> {
+
+ private Session session;
+
+ public BytesMessageCreator(Session session) {
+ this.session = session;
+ }
+
+ /* (non-Javadoc)
+ * @see com.fusesource.support.message.creator.MessageCreator#create()
+ */
+ @Override
+ public BytesMessage create() throws JMSException {
+ // Create a bytes message
+ BytesMessage message = session.createBytesMessage();
+ // apply chain to the message
+ apply(message);
+ // return created message
+ return message;
+ }
+
+}
@@ -0,0 +1,48 @@
+/**
+ * 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 com.fusesource.support.message.creator;
+
+import javax.jms.JMSException;
+import javax.jms.MapMessage;
+import javax.jms.Session;
+
+/**
+ * @author Claudio Corsi
+ *
+ */
+public class MapMessageCreator extends AbstractMessageCreator<MapMessage> {
+
+ private Session session;
+
+ public MapMessageCreator(Session session) {
+ this.session = session;
+ }
+
+ /* (non-Javadoc)
+ * @see com.fusesource.support.message.creator.MessageCreator#create()
+ */
+ @Override
+ public MapMessage create() throws JMSException {
+ // create a map message
+ MapMessage message = session.createMapMessage();
+ // apply the chains
+ apply(message);
+ // return the created message
+ return message;
+ }
+
+}
@@ -0,0 +1,48 @@
+/**
+ * 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 com.fusesource.support.message.creator;
+
+import javax.jms.JMSException;
+import javax.jms.ObjectMessage;
+import javax.jms.Session;
+
+/**
+ * @author Claudio Corsi
+ *
+ */
+public class ObjectMessageCreator extends AbstractMessageCreator<ObjectMessage> {
+
+ private Session session;
+
+ public ObjectMessageCreator(Session session) {
+ this.session = session;
+ }
+
+ /* (non-Javadoc)
+ * @see com.fusesource.support.message.creator.MessageCreator#create()
+ */
+ @Override
+ public ObjectMessage create() throws JMSException {
+ // create an object message instance
+ ObjectMessage message = session.createObjectMessage();
+ // apply the chains to the message
+ apply(message);
+ // return the created message
+ return message;
+ }
+
+}
@@ -0,0 +1,48 @@
+/**
+ * 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 com.fusesource.support.message.creator;
+
+import javax.jms.JMSException;
+import javax.jms.Session;
+import javax.jms.StreamMessage;
+
+/**
+ * @author Claudio Corsi
+ *
+ */
+public class StreamMessageCreator extends AbstractMessageCreator<StreamMessage> {
+
+ private Session session;
+
+ StreamMessageCreator(Session session) {
+ this.session = session;
+ }
+
+ /* (non-Javadoc)
+ * @see com.fusesource.support.message.creator.MessageCreator#create()
+ */
+ @Override
+ public StreamMessage create() throws JMSException {
+ // Create a simple stream message
+ StreamMessage message = session.createStreamMessage();
+ // Apply the chain updates to the stream message
+ apply(message);
+ // return the newly created message
+ return message;
+ }
+
+}
@@ -17,14 +17,14 @@
package com.fusesource.support.message.creator;
import javax.jms.JMSException;
-import javax.jms.Message;
import javax.jms.Session;
+import javax.jms.TextMessage;
/**
* @author Claudio Corsi
*
*/
-public class TextMessageCreator extends AbstractMessageCreator {
+public class TextMessageCreator extends AbstractMessageCreator<TextMessage> {
private Session session;
private int cnt = 0;
@@ -36,10 +36,9 @@ public TextMessageCreator(Session session) {
/* (non-Javadoc)
* @see com.fusesource.support.producers.MessageCreator#create()
*/
- @Override
- public Message create() throws JMSException {
+ public TextMessage create() throws JMSException {
// Create the message
- Message message = session.createTextMessage("Message:" + cnt++);
+ TextMessage message = session.createTextMessage("Message:" + cnt++);
// Apply all chained settings
this.apply(message);
// Return newly created message
@@ -145,7 +145,6 @@ public void execute() throws JMSException, InterruptedException {
MessageConsumer consumer = spokeSession.createConsumer(spokeDestination);
consumer.setMessageListener(new MessageListener() {
- @Override
public void onMessage(Message message) {
System.out.println(Thread.currentThread().getName() + " - RECEIVED MESSAGE: " + message);
}
@@ -255,7 +254,6 @@ public void ProducerExecutorManagerTest() throws JMSException, InterruptedExcept
MessageConsumer consumer = spokeSession.createConsumer(spokeDestination);
consumer.setMessageListener(new MessageListener() {
- @Override
public void onMessage(Message message) {
System.out.println(Thread.currentThread().getName() + " - RECEIVED MESSAGE: " + message);
}

0 comments on commit 56b9fe9

Please sign in to comment.