1
2
3
4
5
6
7
8
9
10
11 package org.mule.config;
12
13 import org.mule.api.MuleContext;
14 import org.mule.api.config.MuleProperties;
15 import org.mule.api.context.MuleContextAware;
16 import org.mule.api.lifecycle.InitialisationException;
17 import org.mule.api.store.ListableObjectStore;
18 import org.mule.util.queue.QueueConfiguration;
19 import org.mule.util.queue.QueueManager;
20
21 import java.io.Serializable;
22
23
24
25
26
27
28 public class QueueProfile
29 {
30 private int maxOutstandingMessages = 0;
31 private ListableObjectStore<Serializable> objectStore;
32
33 public static QueueProfile newInstancePersistingToDefaultMemoryQueueStore(MuleContext muleContext)
34 {
35 ListableObjectStore<Serializable> defaultMemoryObjectStore =
36 muleContext.getRegistry().lookupObject(MuleProperties.OBJECT_STORE_DEFAULT_IN_MEMORY_NAME);
37 return new QueueProfile(defaultMemoryObjectStore);
38 }
39
40 public QueueProfile(ListableObjectStore<Serializable> objectStore)
41 {
42 this.objectStore = objectStore;
43 }
44
45
46 public QueueProfile(QueueProfile queueProfile)
47 {
48 this.maxOutstandingMessages = queueProfile.getMaxOutstandingMessages();
49 this.objectStore = queueProfile.objectStore;
50 }
51
52 public QueueProfile(int maxOutstandingMessages, ListableObjectStore<Serializable> objectStore)
53 {
54 this.maxOutstandingMessages = maxOutstandingMessages;
55 this.objectStore = objectStore;
56 }
57
58
59
60
61
62
63
64 public int getMaxOutstandingMessages()
65 {
66 return maxOutstandingMessages;
67 }
68
69
70
71
72
73
74
75 public void setMaxOutstandingMessages(int maxOutstandingMessages)
76 {
77 this.maxOutstandingMessages = maxOutstandingMessages;
78 }
79
80 public QueueConfiguration configureQueue(MuleContext context, String component, QueueManager queueManager) throws InitialisationException
81 {
82 if (objectStore instanceof MuleContextAware)
83 {
84 ((MuleContextAware) objectStore).setMuleContext(context);
85 }
86 QueueConfiguration qc = new QueueConfiguration(context, maxOutstandingMessages, objectStore);
87 queueManager.setQueueConfiguration(component, qc);
88 return qc;
89 }
90
91 public ListableObjectStore<Serializable> getObjectStore()
92 {
93 return objectStore;
94 }
95
96 public void setQueueStore(ListableObjectStore<Serializable> objectStore)
97 {
98 this.objectStore = objectStore;
99 }
100
101 public void addQueueStore(ListableObjectStore<Serializable> objectStore)
102 {
103 this.objectStore = objectStore;
104 }
105
106 @Override
107 public String toString()
108 {
109 return "QueueProfile{maxOutstandingMessage=" + maxOutstandingMessages + ", storeType="
110 + objectStore.getClass() + "}";
111 }
112 }