1 /***
2 *
3 * Copyright 2004 Protique Ltd
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 **/
18 package org.codehaus.activemq.service.impl;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.codehaus.activemq.message.ActiveMQMessage;
23 import org.codehaus.activemq.message.ConsumerInfo;
24 import org.codehaus.activemq.message.MessageAck;
25 import org.codehaus.activemq.service.MessageIdentity;
26 import org.codehaus.activemq.service.Subscription;
27 import org.codehaus.activemq.service.TopicMessageContainer;
28 import org.codehaus.activemq.store.TopicMessageStore;
29
30 import javax.jms.JMSException;
31
32 /***
33 * A default implemenation of a Durable Topic based
34 * {@link org.codehaus.activemq.service.MessageContainer}
35 * which acts as an adapter between the {@link org.codehaus.activemq.service.MessageContainerManager}
36 * requirements and those of the persistent {@link TopicMessageStore} implementations.
37 *
38 * @version $Revision: 1.14 $
39 */
40 public class DurableTopicMessageContainer implements TopicMessageContainer {
41 private static final Log log = LogFactory.getLog(DurableTopicMessageContainer.class);
42
43 private TopicMessageStore messageStore;
44 private String destinationName;
45 private MessageIdentity lastMessageIdentity;
46
47 public DurableTopicMessageContainer(TopicMessageStore messageStore, String destinationName) {
48 this.messageStore = messageStore;
49 this.destinationName = destinationName;
50 }
51
52 public String getDestinationName() {
53 return destinationName;
54 }
55
56 public MessageIdentity addMessage(ActiveMQMessage message) throws JMSException {
57 MessageIdentity answer = messageStore.addMessage(message);
58 lastMessageIdentity = answer;
59 return answer;
60 }
61
62 public void delete(MessageIdentity messageID, MessageAck ack) throws JMSException {
63
64
65 }
66
67 public boolean containsMessage(MessageIdentity messageIdentity) throws JMSException {
68 /*** TODO: make more optimal implementation */
69 return getMessage(messageIdentity) != null;
70 }
71
72 public ActiveMQMessage getMessage(MessageIdentity messageID) throws JMSException {
73 return messageStore.getMessage(messageID);
74 }
75
76 public void registerMessageInterest(MessageIdentity messageIdentity) throws JMSException {
77 messageStore.incrementMessageCount(messageIdentity);
78 }
79
80 public void unregisterMessageInterest(MessageIdentity messageIdentity, MessageAck ack) throws JMSException {
81 messageStore.decrementMessageCountAndMaybeDelete(messageIdentity, ack);
82 }
83
84
85 public void setLastAcknowledgedMessageID(Subscription subscription, MessageIdentity messageIdentity) throws JMSException {
86 messageStore.setLastAcknowledgedMessageIdentity(subscription, messageIdentity);
87 }
88
89 public void recoverSubscription(Subscription subscription) throws JMSException {
90 messageStore.recoverSubscription(subscription, lastMessageIdentity);
91 }
92
93 public void storeSubscription(ConsumerInfo info, Subscription subscription) throws JMSException {
94 messageStore.setSubscriberEntry(info, subscription.getSubscriptionEntry());
95 }
96
97 public void start() throws JMSException {
98 messageStore.setMessageContainer(this);
99 lastMessageIdentity = messageStore.getLastestMessageIdentity();
100 messageStore.start();
101 }
102
103 public void stop() throws JMSException {
104 messageStore.stop();
105 }
106 }