Revision 95b6f6f5
Added by Cherian Mathew almost 9 years ago
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationRemoteController.java | ||
---|---|---|
58 | 58 |
* @param listeners |
59 | 59 |
* @return |
60 | 60 |
*/ |
61 |
public static CdmApplicationRemoteController NewInstance(Resource applicationContextResource, |
|
62 |
ICdmRemoteSource remoteSource, |
|
63 |
boolean omitTermLoading, |
|
64 |
IProgressMonitor progressMonitor, |
|
65 |
List<ApplicationListener> listeners) { |
|
66 |
return new CdmApplicationRemoteController(applicationContextResource, |
|
67 |
remoteSource, |
|
68 |
omitTermLoading, |
|
69 |
progressMonitor, |
|
70 |
listeners); |
|
71 |
|
|
72 |
} |
|
61 |
// public static CdmApplicationRemoteController NewInstance(Resource applicationContextResource, |
|
62 |
// ICdmRemoteSource remoteSource, |
|
63 |
// IProgressMonitor progressMonitor, |
|
64 |
// List<ApplicationListener> listeners) { |
|
65 |
// return new CdmApplicationRemoteController(applicationContextResource, |
|
66 |
// remoteSource, |
|
67 |
// false, |
|
68 |
// progressMonitor, |
|
69 |
// listeners); |
|
70 |
// |
|
71 |
// } |
|
73 | 72 |
/** |
74 | 73 |
* Creates new instance of CdmApplicationRemoteController |
75 | 74 |
* |
... | ... | |
81 | 80 |
* @return |
82 | 81 |
*/ |
83 | 82 |
public static CdmApplicationRemoteController NewInstance(ICdmRemoteSource remoteSource, |
84 |
boolean omitTermLoading, |
|
85 | 83 |
IProgressMonitor progressMonitor, |
86 | 84 |
List<ApplicationListener> listeners) { |
87 | 85 |
|
88 | 86 |
return new CdmApplicationRemoteController(DEFAULT_REMOTE_APPLICATION_CONTEXT_RESOURCE, |
89 | 87 |
remoteSource, |
90 |
omitTermLoading, |
|
88 |
false, |
|
89 |
progressMonitor, |
|
90 |
listeners); |
|
91 |
|
|
92 |
} |
|
93 |
|
|
94 |
public static CdmApplicationRemoteController NewInstance(ICdmRemoteSource remoteSource, |
|
95 |
boolean validateXml, |
|
96 |
IProgressMonitor progressMonitor, |
|
97 |
List<ApplicationListener> listeners) { |
|
98 |
|
|
99 |
return new CdmApplicationRemoteController(DEFAULT_REMOTE_APPLICATION_CONTEXT_RESOURCE, |
|
100 |
remoteSource, |
|
101 |
validateXml, |
|
91 | 102 |
progressMonitor, |
92 | 103 |
listeners); |
93 | 104 |
|
... | ... | |
104 | 115 |
*/ |
105 | 116 |
private CdmApplicationRemoteController(Resource applicationContextResource, |
106 | 117 |
ICdmRemoteSource remoteSource, |
107 |
boolean omitTermLoading,
|
|
118 |
boolean validateXml,
|
|
108 | 119 |
IProgressMonitor progressMonitor, |
109 | 120 |
List<ApplicationListener> listeners){ |
110 | 121 |
logger.info("Start CdmApplicationRemoteController with remote source: " + remoteSource.getName()); |
111 | 122 |
this.applicationContextResource = |
112 | 123 |
applicationContextResource != null ? applicationContextResource : DEFAULT_REMOTE_APPLICATION_CONTEXT_RESOURCE; |
113 | 124 |
this.progressMonitor = progressMonitor != null ? progressMonitor : new NullProgressMonitor(); |
114 |
|
|
115 |
setNewRemoteSource(remoteSource, omitTermLoading, listeners); |
|
125 |
setNewRemoteSource(remoteSource, validateXml, listeners); |
|
116 | 126 |
|
117 | 127 |
} |
118 | 128 |
|
... | ... | |
127 | 137 |
* @param listeners |
128 | 138 |
* @return |
129 | 139 |
*/ |
130 |
protected boolean setNewRemoteSource(ICdmRemoteSource remoteSource,
|
|
131 |
boolean omitTermLoading,
|
|
140 |
public boolean setNewRemoteSource(ICdmRemoteSource remoteSource,
|
|
141 |
boolean validateXml,
|
|
132 | 142 |
List<ApplicationListener> listeners){ |
133 | 143 |
|
134 | 144 |
logger.info("Connecting to '" + remoteSource.getName() + "'"); |
135 | 145 |
|
136 |
GenericApplicationContext applicationContext |
|
137 |
= generateApplicationContext(remoteSource, applicationContextResource, listeners, progressMonitor, false); |
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
//progressMonitor.beginTask("Connecting to '" + remoteSource.getName() + "'", nTasks); |
|
142 |
applicationContext.refresh(); |
|
143 |
applicationContext.start(); |
|
144 |
|
|
145 |
|
|
146 |
progressMonitor.subTask("Cleaning up."); |
|
147 |
setApplicationContext(applicationContext); |
|
148 |
progressMonitor.worked(1); |
|
146 |
GenericApplicationContext applicationContext = new GenericApplicationContext(); |
|
149 | 147 |
|
150 |
progressMonitor.done(); |
|
151 |
return true; |
|
152 |
} |
|
153 |
|
|
154 |
public static GenericApplicationContext generateApplicationContext(ICdmRemoteSource remoteSource, |
|
155 |
Resource applicationContextResource, |
|
156 |
List<ApplicationListener> listeners, |
|
157 |
IProgressMonitor progressMonitor, |
|
158 |
boolean validateXml) { |
|
159 |
RemotingMonitoredGenericApplicationContext applicationContext = new RemotingMonitoredGenericApplicationContext(); |
|
160 |
int refreshTasks = 45; |
|
161 |
int nTasks = 5 + refreshTasks; |
|
148 |
int nTasks = 5; |
|
162 | 149 |
|
163 |
progressMonitor.subTask("Registering remote source."); |
|
164 |
applicationContext.getEnvironment().setActiveProfiles("remoting"); |
|
165 |
progressMonitor.worked(1); |
|
150 |
progressMonitor.beginTask("Connecting to '" + remoteSource.getName() + "'", nTasks); |
|
166 | 151 |
|
152 |
progressMonitor.subTask("Loading context beans ..."); |
|
167 | 153 |
PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer(); |
168 | 154 |
Properties properties = new Properties(); |
169 | 155 |
properties.setProperty("remoteServer", remoteSource.getServer()); |
... | ... | |
171 | 157 |
properties.setProperty("remoteContext", remoteSource.getContextPath()); |
172 | 158 |
pspc.setProperties(properties); |
173 | 159 |
applicationContext.addBeanFactoryPostProcessor(pspc); |
174 |
|
|
160 |
applicationContext.getEnvironment().setActiveProfiles("remoting"); |
|
175 | 161 |
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(applicationContext); |
176 | 162 |
if(!validateXml) { |
177 |
xmlReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
|
163 |
xmlReader.setValidating(false);
|
|
178 | 164 |
} |
179 |
progressMonitor.subTask("Registering resources."); |
|
180 | 165 |
xmlReader.loadBeanDefinitions(applicationContextResource); |
181 |
progressMonitor.worked(1); |
|
182 |
|
|
183 | 166 |
if (listeners != null){ |
184 | 167 |
for(ApplicationListener listener : listeners){ |
185 | 168 |
applicationContext.addApplicationListener(listener); |
186 | 169 |
} |
187 | 170 |
} |
171 |
progressMonitor.worked(1); |
|
188 | 172 |
|
189 |
return applicationContext; |
|
173 |
progressMonitor.subTask("Refreshing / Starting context ..."); |
|
174 |
applicationContext.refresh(); |
|
175 |
applicationContext.start(); |
|
176 |
progressMonitor.worked(1); |
|
177 |
|
|
178 |
progressMonitor.subTask("Cleaning up ..."); |
|
179 |
setApplicationContext(applicationContext); |
|
180 |
progressMonitor.worked(1); |
|
181 |
|
|
182 |
return true; |
|
190 | 183 |
} |
191 | 184 |
|
185 |
|
|
186 |
|
|
192 | 187 |
/* (non-Javadoc) |
193 | 188 |
* @see eu.etaxonomy.cdm.api.application.CdmApplicationController#init() |
194 | 189 |
*/ |
195 | 190 |
@Override |
196 | 191 |
protected void init(){ |
192 |
progressMonitor.subTask("Loading configuration ..."); |
|
197 | 193 |
configuration = (ICdmApplicationConfiguration)applicationContext.getBean("cdmApplicationRemoteConfiguration"); |
198 | 194 |
AbstractLazyInitializer.setConfiguration((CdmApplicationRemoteConfiguration)configuration); |
199 | 195 |
AbstractPersistentCollection.setConfiguration((CdmApplicationRemoteConfiguration)configuration); |
196 |
progressMonitor.worked(1); |
|
200 | 197 |
|
198 |
progressMonitor.subTask("Loading CDM config cache ..."); |
|
201 | 199 |
CdmModelCacher cmdmc = new CdmModelCacher(); |
202 | 200 |
cmdmc.cacheGetterFields(); |
201 |
progressMonitor.worked(1); |
|
203 | 202 |
|
203 |
progressMonitor.done(); |
|
204 | 204 |
} |
205 | 205 |
|
206 | 206 |
public ICdmEntitySessionManager getCdmEntitySessionManager() { |
Also available in: Unified diff
CdmApplicationRemoteController : refactoring code to simplify application context loading and making it performant
CdmModelCacher : removed unused method
CdmRemoteCacheManager : moved cache from disk to memory
httpInvokerServiceClients : lazy initializing all service beans
remotingApplicationContext : merged imported bean definition files into this one
CdmApplicationRemoteControllerTest : test for application controller
RemotingMonitoredGenericApplicationContext, RemotingMonitoredListableBeanFactory : removed since specific monitoring is not required in remoting
remoting_persistence_security.xml, remoting_services_security.xml : merged into remotingApplicationContext