001    /**
002     * 
003     * Copyright 2004 Protique Ltd
004     * 
005     * Licensed under the Apache License, Version 2.0 (the "License"); 
006     * you may not use this file except in compliance with the License. 
007     * You may obtain a copy of the License at 
008     * 
009     * http://www.apache.org/licenses/LICENSE-2.0
010     * 
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS, 
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
014     * See the License for the specific language governing permissions and 
015     * limitations under the License. 
016     * 
017     **/
018    package org.activemq.store.vm;
019    
020    import java.io.File;
021    import java.util.HashMap;
022    import java.util.Iterator;
023    import java.util.Map;
024    
025    import javax.jms.JMSException;
026    
027    import org.activemq.message.ActiveMQDestination;
028    import org.activemq.message.ActiveMQQueue;
029    import org.activemq.store.MessageStore;
030    import org.activemq.store.PersistenceAdapter;
031    import org.activemq.store.TopicMessageStore;
032    import org.activemq.store.TransactionStore;
033    
034    import EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap;
035    
036    /**
037     * @version $Revision: 1.1.1.1 $
038     */
039    public class VMPersistenceAdapter implements PersistenceAdapter {
040    
041        VMTransactionStore transactionStore = null;
042        ConcurrentHashMap destinations = new ConcurrentHashMap();
043        
044        public Map getInitialDestinations() {
045            HashMap rc = new HashMap(destinations.size());
046            for (Iterator iter = destinations.keySet().iterator(); iter.hasNext();) {
047                ActiveMQDestination dest = (ActiveMQDestination) iter.next();
048                rc.put(dest.getPhysicalName(), dest);
049            }
050            return rc;
051        }
052    
053        public static VMPersistenceAdapter newInstance(File file) {
054            return new VMPersistenceAdapter();
055        }
056    
057        public MessageStore createQueueMessageStore(String destinationName) throws JMSException {
058            ActiveMQQueue dest = new ActiveMQQueue(destinationName);
059            MessageStore rc = (MessageStore)destinations.get(dest);
060            if(rc==null) {
061                rc = new VMMessageStore();
062                if( transactionStore !=null ) {
063                    rc = transactionStore.proxy(rc);
064                }
065                destinations.put(dest, rc);
066            }
067            return rc;
068        }
069    
070        public TopicMessageStore createTopicMessageStore(String destinationName) throws JMSException {
071            ActiveMQQueue dest = new ActiveMQQueue(destinationName);
072            TopicMessageStore rc = (TopicMessageStore)destinations.get(dest);
073            if(rc==null) {
074                rc = new VMTopicMessageStore();
075                if( transactionStore !=null ) {
076                    rc = transactionStore.proxy(rc);
077                }
078                destinations.put(dest, rc);
079            }
080            return rc;
081        }
082    
083        public TransactionStore createTransactionStore() throws JMSException {
084            if( transactionStore==null ) {
085                transactionStore = new VMTransactionStore();
086            }
087            return transactionStore;
088        }
089    
090        public void beginTransaction() {
091        }
092    
093        public void commitTransaction() {
094        }
095    
096        public void rollbackTransaction() {
097        }
098    
099        public void start() throws JMSException {
100        }
101    
102        public void stop() throws JMSException {
103        }
104    
105        /**
106         * Verifies if a dead letter has already been sent for a message  
107         * @param seq
108         * @param useLocking to prevent concurrency/dups
109         * @return
110         */
111        public boolean deadLetterAlreadySent(long seq, boolean useLocking) {
112            return false;
113        }
114    }