VMMessageStore xref

View Javadoc

    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.store.vm;
    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.MessageAck;
    24  import org.codehaus.activemq.service.MessageIdentity;
    25  import org.codehaus.activemq.service.QueueMessageContainer;
    26  import org.codehaus.activemq.store.MessageStore;
    27
    28  import javax.jms.JMSException;
    29  import java.util.Collections;
    30  import java.util.LinkedHashMap;
    31  import java.util.Map;
    32
    33  /***
    34   * An implementation of {@link org.codehaus.activemq.store.MessageStore} which uses a
    35   *
    36   * @version $Revision: 1.1 $
    37   */
    38  public class VMMessageStore implements MessageStore {
    39      private static final Log log = LogFactory.getLog(VMMessageStore.class);
    40
    41      protected Map messageTable;
    42
    43      public VMMessageStore() {
    44          this(new LinkedHashMap());
    45      }
    46
    47      public VMMessageStore(LinkedHashMap messageTable) {
    48          this.messageTable = Collections.synchronizedMap(messageTable);
    49      }
    50
    51      public MessageIdentity addMessage(ActiveMQMessage message) throws JMSException {
    52          messageTable.put(message.getJMSMessageID(), message);
    53          return message.getJMSMessageIdentity();
    54      }
    55
    56      public ActiveMQMessage getMessage(MessageIdentity identity) throws JMSException {
    57          String messageID = identity.getMessageID();
    58          return (ActiveMQMessage) messageTable.get(messageID);
    59      }
    60
    61      public void removeMessage(MessageIdentity identity, MessageAck ack) throws JMSException {
    62          String messageID = identity.getMessageID();
    63          messageTable.remove(messageID);
    64      }
    65
    66      public void recover(QueueMessageContainer container) throws JMSException {
    67      }
    68
    69      public void start() throws JMSException {
    70      }
    71
    72      public void stop() throws JMSException {
    73          messageTable.clear();
    74      }
    75
    76  }