Source code: org/activemq/store/cache/SimpleCachePersistenceAdapterGBean.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.util.Map;
21
22 import javax.jms.JMSException;
23
24 import org.apache.geronimo.gbean.GBeanInfo;
25 import org.apache.geronimo.gbean.GBeanInfoBuilder;
26 import org.apache.geronimo.gbean.GBeanLifecycle;
27 import org.activemq.store.MessageStore;
28 import org.activemq.store.PersistenceAdapter;
29 import org.activemq.store.TopicMessageStore;
30 import org.activemq.store.TransactionStore;
31
32 /**
33 *
34 */
35 public class SimpleCachePersistenceAdapterGBean implements GBeanLifecycle, PersistenceAdapter {
36
37 private final PersistenceAdapter longTermPersistence;
38 private SimpleCachePersistenceAdapter persistenceAdapter;
39 private final int cacheSize;
40
41 public SimpleCachePersistenceAdapterGBean() {
42 this(null, 0);
43 }
44
45 public SimpleCachePersistenceAdapterGBean(PersistenceAdapter longTermPersistence, int cacheSize) {
46 this.longTermPersistence = longTermPersistence;
47 this.cacheSize = cacheSize;
48 }
49
50 public void doStart() throws Exception {
51 persistenceAdapter = new SimpleCachePersistenceAdapter();
52 persistenceAdapter.setLongTermPersistence(longTermPersistence);
53 persistenceAdapter.setCacheSize(cacheSize);
54 persistenceAdapter.start();
55 }
56
57 public void doStop() throws Exception {
58 persistenceAdapter.stop();
59 persistenceAdapter = null;
60 }
61
62 public void doFail() {
63 }
64
65 public static final GBeanInfo GBEAN_INFO;
66 static {
67 GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("ActiveMQ Persistence Cache", SimpleCachePersistenceAdapterGBean.class, "JMSPersistence");
68 infoFactory.addReference("longTermPersistence", PersistenceAdapter.class);
69 infoFactory.addAttribute("cacheSize", int.class, true);
70 infoFactory.addInterface(PersistenceAdapter.class);
71 infoFactory.setConstructor(new String[]{"longTermPersistence", "cacheSize"});
72 GBEAN_INFO = infoFactory.getBeanInfo();
73 }
74 public static GBeanInfo getGBeanInfo() {
75 return GBEAN_INFO;
76 }
77
78 public void beginTransaction() throws JMSException {
79 persistenceAdapter.beginTransaction();
80 }
81 public void commitTransaction() throws JMSException {
82 persistenceAdapter.commitTransaction();
83 }
84 public MessageStore createQueueMessageStore(String destinationName) throws JMSException {
85 return persistenceAdapter.createQueueMessageStore(destinationName);
86 }
87 public TopicMessageStore createTopicMessageStore(String destinationName) throws JMSException {
88 return persistenceAdapter.createTopicMessageStore(destinationName);
89 }
90 public TransactionStore createTransactionStore() throws JMSException {
91 return persistenceAdapter.createTransactionStore();
92 }
93 public Map getInitialDestinations() {
94 return persistenceAdapter.getInitialDestinations();
95 }
96 public void rollbackTransaction() {
97 persistenceAdapter.rollbackTransaction();
98 }
99 public void start() throws JMSException {
100 }
101 public void stop() throws JMSException {
102 }
103
104 public boolean deadLetterAlreadySent(long seq, boolean useDatabaseLocking) {
105 return persistenceAdapter.deadLetterAlreadySent(seq, useDatabaseLocking);
106 }
107
108
109 }