KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > impl > space > DefaultSpaceFactory


1 /*
2  * $Id: DefaultSpaceFactory.java 3865 2006-11-09 17:11:08Z Lajos $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.impl.space;
12
13 import org.mule.umo.endpoint.UMOImmutableEndpoint;
14 import org.mule.umo.space.UMOSpace;
15 import org.mule.umo.space.UMOSpaceException;
16 import org.mule.umo.space.UMOSpaceFactory;
17 import org.mule.util.queue.CachingPersistenceStrategy;
18 import org.mule.util.queue.MemoryPersistenceStrategy;
19 import org.mule.util.queue.QueueManager;
20 import org.mule.util.queue.QueuePersistenceStrategy;
21 import org.mule.util.xa.ResourceManagerSystemException;
22
23 /**
24  * As Space factory that creates a local, non-shared space. If a Jounaling or DB
25  * persistence strategy is used this can be used in a clustered environment
26  */

27 public abstract class DefaultSpaceFactory implements UMOSpaceFactory
28 {
29     private QueuePersistenceStrategy persistenceStrategy;
30     private QueueManager queueManager;
31     private boolean enableMonitorEvents = true;
32     private int capacity = 0;
33     private boolean enableCaching = false;
34
35     public DefaultSpaceFactory()
36     {
37         super();
38     }
39
40     public DefaultSpaceFactory(boolean enableMonitorEvents)
41     {
42         this.enableMonitorEvents = enableMonitorEvents;
43     }
44
45     public DefaultSpaceFactory(boolean enableMonitorEvents, int capacity)
46     {
47         this.enableMonitorEvents = enableMonitorEvents;
48         this.capacity = capacity;
49     }
50
51     public DefaultSpaceFactory(QueuePersistenceStrategy ps, boolean enableMonitorEvents)
52     {
53         this.persistenceStrategy = ps;
54         this.enableMonitorEvents = enableMonitorEvents;
55     }
56
57     public DefaultSpaceFactory(QueuePersistenceStrategy ps, boolean enableMonitorEvents, int capacity)
58     {
59         this.persistenceStrategy = ps;
60         this.enableMonitorEvents = enableMonitorEvents;
61         this.capacity = capacity;
62     }
63
64     public DefaultSpaceFactory(QueueManager qm, boolean enableMonitorEvents)
65     {
66         this.queueManager = qm;
67         this.enableMonitorEvents = enableMonitorEvents;
68     }
69
70     public boolean isEnableMonitorEvents()
71     {
72         return enableMonitorEvents;
73     }
74
75     public void setEnableMonitorEvents(boolean enableMonitorEvents)
76     {
77         this.enableMonitorEvents = enableMonitorEvents;
78     }
79
80     public int getCapacity()
81     {
82         return capacity;
83     }
84
85     public void setCapacity(int capacity)
86     {
87         this.capacity = capacity;
88     }
89
90     public QueuePersistenceStrategy getPersistenceStrategy()
91     {
92         return persistenceStrategy;
93     }
94
95     public void setPersistenceStrategy(QueuePersistenceStrategy persistenceStrategy)
96     {
97         this.persistenceStrategy = persistenceStrategy;
98     }
99
100     public QueueManager getQueueManager()
101     {
102         return queueManager;
103     }
104
105     public void setQueueManager(QueueManager queueManager)
106     {
107         this.queueManager = queueManager;
108     }
109
110     public boolean isEnableCaching()
111     {
112         return enableCaching;
113     }
114
115     public void setEnableCaching(boolean enableCaching)
116     {
117         this.enableCaching = enableCaching;
118     }
119
120     public UMOSpace create(String JavaDoc name) throws UMOSpaceException
121     {
122
123         if (capacity == 0)
124         {
125             capacity = 1024;
126         }
127         try
128         {
129             if (queueManager != null)
130             {
131                 return new DefaultSpace(name, queueManager, enableMonitorEvents);
132             }
133             else if (persistenceStrategy == null)
134             {
135                 persistenceStrategy = new MemoryPersistenceStrategy();
136             }
137             if (enableCaching)
138             {
139                 persistenceStrategy = new CachingPersistenceStrategy(persistenceStrategy);
140             }
141             return new DefaultSpace(name, persistenceStrategy, enableMonitorEvents, capacity);
142
143         }
144         catch (ResourceManagerSystemException e)
145         {
146             throw new CreateSpaceException(e);
147         }
148     }
149
150     /**
151      * Creates a space based on the endpoint URI and can use additional properties,
152      * transaction info, security info and filters associated with the endpoint
153      *
154      * @param endpoint the endpoint from which to construct the space
155      * @return an new Space object
156      * @throws org.mule.umo.space.UMOSpaceException
157      */

158     public UMOSpace create(UMOImmutableEndpoint endpoint) throws UMOSpaceException
159     {
160         return create(endpoint.getEndpointURI().getAddress());
161     }
162 }
163
Popular Tags