Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/activemq/store/cache/CachePersistenceAdapter.java


1   /** 
2    * 
3    * Copyright 2004 Hiram Chirino
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.activemq.store.cache;
19  
20  import java.io.IOException;
21  import java.util.Map;
22  
23  import javax.jms.JMSException;
24  
25  import org.activemq.store.MessageStore;
26  import org.activemq.store.PersistenceAdapter;
27  import org.activemq.store.TopicMessageStore;
28  import org.activemq.store.TransactionStore;
29  
30  /**
31   * Implements a {@link PersistenceAdapter} designed to
32   * to speed up access to recently added messages by using
33   * a MessageCache .
34   *
35   * @version $Revision: 1.1.1.1 $
36   */
37  public abstract class CachePersistenceAdapter implements PersistenceAdapter {
38  
39      private PersistenceAdapter longTermPersistence;    
40  
41      public CachePersistenceAdapter() {
42      }
43      
44      public CachePersistenceAdapter(PersistenceAdapter longTermPersistence) throws IOException {
45      this.longTermPersistence = longTermPersistence;
46      }
47  
48      public Map getInitialDestinations() {
49          return longTermPersistence.getInitialDestinations();
50      }
51  
52      public MessageStore createQueueMessageStore(String destinationName) throws JMSException {
53          MessageStore longtermStore = longTermPersistence.createQueueMessageStore(destinationName);
54          CacheMessageStore store = new CacheMessageStore(this, longtermStore, createMessageCache(destinationName));
55          return store;
56      }
57  
58    public TopicMessageStore createTopicMessageStore(String destinationName) throws JMSException {
59            TopicMessageStore longtermStore = longTermPersistence.createTopicMessageStore(destinationName);
60          CacheTopicMessageStore store = new CacheTopicMessageStore(this, longtermStore, new SimpleMessageCache());
61          return store;
62      }
63  
64      public TransactionStore createTransactionStore() throws JMSException {
65          return longTermPersistence.createTransactionStore();
66      }
67  
68      public void beginTransaction() throws JMSException {
69        longTermPersistence.beginTransaction();
70      }
71  
72      public void commitTransaction() throws JMSException {
73        longTermPersistence.commitTransaction();
74      }
75  
76      public void rollbackTransaction() {
77        longTermPersistence.rollbackTransaction();
78      }
79  
80      public void start() throws JMSException {
81          longTermPersistence.start();
82      }
83  
84    public void stop() throws JMSException {
85          longTermPersistence.stop();
86      }
87    
88      /**
89       * Verifies if a dead letter has already been sent for a message  
90       * @param seq
91       * @param useLocking to prevent concurrency/dups
92       * @return
93       */
94      public boolean deadLetterAlreadySent(long seq, boolean useLocking) {
95        return longTermPersistence.deadLetterAlreadySent(seq, useLocking);
96      }
97  
98      // Properties
99      //-------------------------------------------------------------------------
100     public PersistenceAdapter getLongTermPersistence() {
101         return longTermPersistence;
102     }
103     
104     public void setLongTermPersistence(PersistenceAdapter longTermPersistence) {
105         this.longTermPersistence = longTermPersistence;
106     }
107 
108     /**
109      * Subclasses should override this method to change the type 
110      * of MessageCache that is used to cache messages.
111      *  
112      * @param destinationName
113      * @return
114      */
115   abstract protected MessageCache createMessageCache(String destinationName);
116 
117 }