]> git.argeo.org Git - gpl/argeo-slc.git/blob - OsgiExecutionModulesManager.java
4ae06f8b3e53bb154a4a91faed1d83be33aea792
[gpl/argeo-slc.git] / OsgiExecutionModulesManager.java
1 /*
2 * Copyright (C) 2007-2012 Mathieu Baudier
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.slc.osgi;
17
18 import java.lang.management.ManagementFactory;
19 import java.util.ArrayList;
20 import java.util.Dictionary;
21 import java.util.Enumeration;
22 import java.util.HashMap;
23 import java.util.HashSet;
24 import java.util.Iterator;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.Set;
28
29 import javax.management.MBeanServer;
30 import javax.management.ObjectName;
31 import javax.management.StandardMBean;
32
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35 import org.argeo.slc.BasicNameVersion;
36 import org.argeo.slc.NameVersion;
37 import org.argeo.slc.SlcException;
38 import org.argeo.slc.core.execution.AbstractExecutionModulesManager;
39 import org.argeo.slc.core.execution.DefaultExecutionFlowDescriptorConverter;
40 import org.argeo.slc.deploy.Module;
41 import org.argeo.slc.deploy.ModuleDescriptor;
42 import org.argeo.slc.execution.ExecutionContext;
43 import org.argeo.slc.execution.ExecutionFlow;
44 import org.argeo.slc.execution.ExecutionFlowDescriptor;
45 import org.argeo.slc.execution.ExecutionFlowDescriptorConverter;
46 import org.argeo.slc.execution.ExecutionModuleDescriptor;
47 import org.argeo.slc.execution.ExecutionModulesListener;
48 import org.argeo.slc.process.RealizedFlow;
49 import org.osgi.framework.Bundle;
50 import org.osgi.framework.BundleEvent;
51 import org.osgi.framework.BundleException;
52 import org.osgi.framework.BundleListener;
53 import org.osgi.framework.Constants;
54 import org.osgi.framework.launch.Framework;
55 import org.springframework.context.ApplicationContext;
56 import org.springframework.osgi.service.importer.OsgiServiceLifecycleListener;
57
58 /** Execution modules manager implementation based on an OSGi runtime. */
59 public class OsgiExecutionModulesManager extends
60 AbstractExecutionModulesManager implements
61 OsgiServiceLifecycleListener, BundleListener {
62
63 private final static Log log = LogFactory
64 .getLog(OsgiExecutionModulesManager.class);
65
66 private BundlesManager bundlesManager;
67 private Map<OsgiBundle, ExecutionContext> executionContexts = new HashMap<OsgiBundle, ExecutionContext>();
68 private Map<OsgiBundle, ExecutionFlowDescriptorConverter> executionFlowDescriptorConverters = new HashMap<OsgiBundle, ExecutionFlowDescriptorConverter>();
69 private Map<OsgiBundle, Set<ExecutionFlow>> executionFlows = new HashMap<OsgiBundle, Set<ExecutionFlow>>();
70 private ExecutionFlowDescriptorConverter defaultDescriptorConverter = new DefaultExecutionFlowDescriptorConverter();
71
72 private List<ExecutionModulesListener> executionModulesListeners = new ArrayList<ExecutionModulesListener>();
73
74 private Boolean registerFlowsToJmx = false;
75
76 public void init() throws Exception {
77 bundlesManager.getBundleContext().addBundleListener(this);
78
79 final String module = System.getProperty(UNIQUE_LAUNCH_MODULE_PROPERTY);
80 final String flow = System.getProperty(UNIQUE_LAUNCH_FLOW_PROPERTY);
81 if (module != null) {
82 // launch a flow and stops
83 new Thread("Unique Flow") {
84 @Override
85 public void run() {
86 executeFlowAndExit(module, null, flow);
87 }
88 }.start();
89 }
90 }
91
92 public void destroy() {
93 bundlesManager.getBundleContext().removeBundleListener(this);
94 }
95
96 /** Executes a single flow and <b>stops the JVM</b> */
97 protected void executeFlowAndExit(final String module,
98 final String version, final String flow) {
99 if (log.isDebugEnabled())
100 log.debug("Launch unique flow " + flow + " from module " + module);
101 try {
102 OsgiBundle osgiBundle = bundlesManager.findFromPattern(module);
103 Bundle moduleBundle = bundlesManager.findRelatedBundle(osgiBundle);
104 bundlesManager.startSynchronous(moduleBundle);
105 RealizedFlow lastLaunch = findRealizedFlow(module, flow);
106 if (lastLaunch == null)
107 throw new SlcException("Cannot find launch for " + module + " "
108 + flow);
109 execute(lastLaunch);
110 } catch (Exception e) {
111 log.error(
112 "Error in unique flow " + flow + " from module " + module,
113 e);
114 } finally {
115 if (log.isDebugEnabled())
116 log.debug("Shutdown OSGi runtime...");
117 Framework framework = (Framework) bundlesManager.getBundleContext()
118 .getBundle(0);
119 try {
120 // shutdown framework
121 framework.stop();
122 // wait 1 min for shutdown
123 framework.waitForStop(60 * 1000);
124 // close VM
125 System.exit(0);
126 } catch (Exception e) {
127 e.printStackTrace();
128 System.exit(1);
129 }
130 }
131 }
132
133 public synchronized ExecutionModuleDescriptor getExecutionModuleDescriptor(
134 String moduleName, String version) {
135 ExecutionModuleDescriptor md = new ExecutionModuleDescriptor();
136 OsgiBundle osgiBundle = null;
137 BasicNameVersion nameVersion = new BasicNameVersion(moduleName, version);
138 bundles: for (Iterator<OsgiBundle> iterator = executionContexts
139 .keySet().iterator(); iterator.hasNext();) {
140 OsgiBundle ob = iterator.next();
141 if (ob.equals(nameVersion)) {
142 osgiBundle = ob;
143 break bundles;
144 }
145 }
146 if (osgiBundle == null)
147 throw new SlcException("No execution module registered for "
148 + nameVersion);
149 md.setName(osgiBundle.getName());
150 md.setVersion(osgiBundle.getVersion());
151 md.setTitle(osgiBundle.getTitle());
152 md.setDescription(osgiBundle.getDescription());
153
154 ExecutionFlowDescriptorConverter executionFlowDescriptorConverter = getExecutionFlowDescriptorConverter(
155 moduleName, version);
156 if (executionFlowDescriptorConverter == null)
157 throw new SlcException("No flow converter found.");
158 executionFlowDescriptorConverter.addFlowsToDescriptor(md,
159 listFlows(moduleName, version));
160 return md;
161 }
162
163 public synchronized List<ExecutionModuleDescriptor> listExecutionModules() {
164 List<ExecutionModuleDescriptor> descriptors = new ArrayList<ExecutionModuleDescriptor>();
165
166 for (Iterator<OsgiBundle> iterator = executionContexts.keySet()
167 .iterator(); iterator.hasNext();) {
168 OsgiBundle osgiBundle = iterator.next();
169 ExecutionModuleDescriptor md = new ExecutionModuleDescriptor();
170 setMetadataFromBundle(md,
171 bundlesManager.findRelatedBundle(osgiBundle));
172 descriptors.add(md);
173 }
174 return descriptors;
175 }
176
177 protected synchronized Map<String, ExecutionFlow> listFlows(
178 String moduleName, String moduleVersion) {
179
180 Map<String, ExecutionFlow> flows = new HashMap<String, ExecutionFlow>();
181 OsgiBundle key = new OsgiBundle(moduleName, moduleVersion);
182 if (!executionFlows.containsKey(key))
183 return flows;
184 Set<ExecutionFlow> flowsT = executionFlows.get(key);
185 for (ExecutionFlow flow : flowsT)
186 flows.put(flow.getName(), flow);
187 return flows;
188 }
189
190 protected ExecutionFlow findExecutionFlow(String moduleName,
191 String moduleVersion, String flowName) {
192 String filter = "(&(Bundle-SymbolicName=" + moduleName
193 + ")(org.springframework.osgi.bean.name=" + flowName + "))";
194 return bundlesManager.getSingleServiceStrict(ExecutionFlow.class,
195 filter, true);
196 }
197
198 protected ExecutionContext findExecutionContext(String moduleName,
199 String moduleVersion) {
200 String filter = "(&(Bundle-SymbolicName=" + moduleName
201 + ")(Bundle-Version=" + moduleVersion + "))";
202 return bundlesManager.getSingleServiceStrict(ExecutionContext.class,
203 filter, true);
204 }
205
206 protected ExecutionFlowDescriptorConverter findExecutionFlowDescriptorConverter(
207 String moduleName, String moduleVersion) {
208 String filter = "(&(Bundle-SymbolicName=" + moduleName
209 + ")(Bundle-Version=" + moduleVersion + "))";
210 return bundlesManager.getSingleService(
211 ExecutionFlowDescriptorConverter.class, filter, false);
212 }
213
214 /**
215 * Builds a minimal realized flow, based on the provided information
216 * (typically from the command line).
217 *
218 * @param module
219 * a bundle id, or a pattern contained in a bundle symbolic name
220 * @param module
221 * the execution flow name
222 * @return a minimal realized flow, to be used in an execution
223 */
224 public RealizedFlow findRealizedFlow(String module, String executionName) {
225 // First check whether we have a bundleId
226 Long bundleId = null;
227 try {
228 bundleId = Long.parseLong(module);
229 } catch (NumberFormatException e) {
230 // silent
231 }
232
233 // Look for bundle names containing pattern
234 OsgiBundle bundle = null;
235 if (bundleId != null) {
236 bundle = bundlesManager.getBundle(bundleId);
237 } else {
238 bundle = bundlesManager.findFromPattern(module);
239 }
240
241 if (bundle != null) {
242 RealizedFlow launch = new RealizedFlow();
243 launch.setModuleName(bundle.getName());
244 launch.setModuleVersion(bundle.getVersion());
245 ExecutionFlowDescriptor descriptor = new ExecutionFlowDescriptor();
246 descriptor.setName(executionName);
247 launch.setFlowDescriptor(descriptor);
248 return launch;
249 } else {
250 log.warn("Could not find any execution module matching these requirements.");
251 return null;
252 }
253 }
254
255 public void upgrade(NameVersion nameVersion) {
256 OsgiBundle osgiBundle = new OsgiBundle(nameVersion);
257 bundlesManager.upgradeSynchronous(osgiBundle);
258 }
259
260 protected synchronized ExecutionFlowDescriptorConverter getExecutionFlowDescriptorConverter(
261 String moduleName, String moduleVersion) {
262 OsgiBundle osgiBundle = new OsgiBundle(moduleName, moduleVersion);
263 return getExecutionFlowDescriptorConverter(osgiBundle);
264 }
265
266 protected synchronized ExecutionFlowDescriptorConverter getExecutionFlowDescriptorConverter(
267 OsgiBundle osgiBundle) {
268 if (executionFlowDescriptorConverters.containsKey(osgiBundle))
269 return executionFlowDescriptorConverters.get(osgiBundle);
270 else
271 return defaultDescriptorConverter;
272 }
273
274 public ModuleDescriptor getModuleDescriptor(String moduleName,
275 String version) {
276 return getExecutionModuleDescriptor(moduleName, version);
277 }
278
279 public List<ModuleDescriptor> listModules() {
280 Bundle[] bundles = bundlesManager.getBundleContext().getBundles();
281 List<ModuleDescriptor> lst = new ArrayList<ModuleDescriptor>();
282 for (Bundle bundle : bundles) {
283 ModuleDescriptor moduleDescriptor = new ModuleDescriptor();
284 setMetadataFromBundle(moduleDescriptor, bundle);
285 lst.add(moduleDescriptor);
286 }
287 return lst;
288 }
289
290 public void start(NameVersion nameVersion) {
291 try {
292 Bundle bundle = bundlesManager.findRelatedBundle(new OsgiBundle(
293 nameVersion));
294 bundlesManager.startSynchronous(bundle);
295 if (isSpringInstrumented(bundle)) {
296 // Wait for Spring application context to be ready
297 String filter = "(Bundle-SymbolicName="
298 + bundle.getSymbolicName() + ")";
299 try {
300 bundlesManager.getServiceRefSynchronous(
301 ApplicationContext.class.getName(), filter);
302 } catch (Exception e) {
303 // stop if application context not found
304 bundle.stop();
305 throw e;
306 }
307 }
308 } catch (Exception e) {
309 throw new SlcException("Cannot start " + nameVersion, e);
310 }
311 }
312
313 /** Do it calmly in order to avoid NPE */
314 private Boolean isSpringInstrumented(Bundle bundle) {
315 Dictionary<?, ?> headers = bundle.getHeaders();
316 if (headers != null && headers.get("Spring-Context") != null)
317 return true;
318 Enumeration<?> springEntryPaths = bundle
319 .getEntryPaths("/META-INF/spring");
320 if (springEntryPaths != null && springEntryPaths.hasMoreElements())
321 return true;
322 return false;
323 }
324
325 public void stop(NameVersion nameVersion) {
326 try {
327 Bundle bundle = bundlesManager.findRelatedBundle(new OsgiBundle(
328 nameVersion));
329 bundlesManager.stopSynchronous(bundle);
330 } catch (BundleException e) {
331 throw new SlcException("Cannot stop " + nameVersion, e);
332 }
333 }
334
335 protected void setMetadataFromBundle(ModuleDescriptor md, Bundle bundle) {
336 Bundle bdl = bundle;
337 if (bdl == null) {
338 if (md.getName() == null || md.getVersion() == null)
339 throw new SlcException("Name and version not available.");
340
341 Bundle[] bundles = bundlesManager.getBundleContext().getBundles();
342 for (Bundle b : bundles) {
343 if (b.getSymbolicName().equals(md.getName())
344 && md.getVersion().equals(
345 getHeaderSafe(b, Constants.BUNDLE_VERSION))) {
346 bdl = b;
347 break;
348 }
349 }
350
351 }
352
353 if (bdl == null)
354 throw new SlcException("Cannot find bundle.");
355
356 md.setName(bdl.getSymbolicName());
357 md.setVersion(getHeaderSafe(bdl, Constants.BUNDLE_VERSION));
358 md.setTitle(getHeaderSafe(bdl, Constants.BUNDLE_NAME));
359 md.setDescription(getHeaderSafe(bdl, Constants.BUNDLE_DESCRIPTION));
360
361 // copy manifets header to meta data
362 Dictionary<?, ?> headers = bundle.getHeaders();
363 Enumeration<?> keys = headers.keys();
364 while (keys.hasMoreElements()) {
365 Object key = keys.nextElement();
366 Object value = headers.get(key);
367 if (value != null)
368 md.getMetadata().put(key.toString(), value.toString());
369 }
370
371 // check if started
372 if (bundle.getState() == Bundle.ACTIVE
373 || bundle.getState() == Bundle.STARTING)
374 md.setStarted(true);
375 else
376 md.setStarted(false);
377 }
378
379 private String getHeaderSafe(Bundle bundle, Object key) {
380 Object obj = bundle.getHeaders().get(key);
381 if (obj == null)
382 return null;
383 else
384 return obj.toString();
385 }
386
387 /*
388 * REGISTRATION
389 */
390
391 /** Registers an execution context. */
392 public synchronized void register(ExecutionContext executionContext,
393 Map<String, String> properties) {
394 OsgiBundle osgiBundle = asOsgiBundle(properties);
395 Bundle bundle = bundlesManager.findRelatedBundle(osgiBundle);
396 osgiBundle.setTitle(getHeaderSafe(bundle, Constants.BUNDLE_NAME));
397 osgiBundle.setDescription(getHeaderSafe(bundle,
398 Constants.BUNDLE_DESCRIPTION));
399 executionContexts.put(osgiBundle, executionContext);
400 if (log.isTraceEnabled())
401 log.trace("Registered execution context from " + osgiBundle);
402 // Notify
403 ModuleDescriptor md = osgiBundle.getModuleDescriptor();
404 md.setStarted(true);
405 for (ExecutionModulesListener listener : executionModulesListeners)
406 listener.executionModuleAdded(md);
407 }
408
409 /** Unregisters an execution context. */
410 public synchronized void unregister(ExecutionContext executionContext,
411 Map<String, String> properties) {
412 OsgiBundle osgiBundle = asOsgiBundle(properties);
413 if (executionContexts.containsKey(osgiBundle)) {
414 executionContexts.remove(osgiBundle);
415 if (log.isTraceEnabled())
416 log.trace("Removed execution context from " + osgiBundle);
417 // Notify
418 ModuleDescriptor md = osgiBundle.getModuleDescriptor();
419 md.setStarted(false);
420 for (ExecutionModulesListener listener : executionModulesListeners)
421 listener.executionModuleRemoved(md);
422 }
423 }
424
425 /** Registers an execution flow. */
426 public synchronized void register(ExecutionFlow executionFlow,
427 Map<String, String> properties) {
428 OsgiBundle osgiBundle = asOsgiBundle(properties);
429 if (!executionFlows.containsKey(osgiBundle)) {
430 executionFlows.put(osgiBundle, new HashSet<ExecutionFlow>());
431 }
432 executionFlows.get(osgiBundle).add(executionFlow);
433 if (log.isTraceEnabled())
434 log.trace("Registered " + executionFlow + " from " + osgiBundle);
435
436 // notifications
437 if (registerFlowsToJmx)
438 registerMBean(osgiBundle, executionFlow);
439 ExecutionFlowDescriptorConverter efdc = getExecutionFlowDescriptorConverter(osgiBundle);
440 for (ExecutionModulesListener listener : executionModulesListeners)
441 listener.executionFlowAdded(osgiBundle.getModuleDescriptor(),
442 efdc.getExecutionFlowDescriptor(executionFlow));
443 }
444
445 /** Unregisters an execution flow. */
446 public synchronized void unregister(ExecutionFlow executionFlow,
447 Map<String, String> properties) {
448 OsgiBundle osgiBundle = asOsgiBundle(properties);
449 if (executionFlows.containsKey(osgiBundle)) {
450 Set<ExecutionFlow> flows = executionFlows.get(osgiBundle);
451 flows.remove(executionFlow);
452 if (log.isTraceEnabled())
453 log.trace("Removed " + executionFlow + " from " + osgiBundle);
454 if (flows.size() == 0) {
455 executionFlows.remove(osgiBundle);
456 if (log.isTraceEnabled())
457 log.trace("Removed flows set from " + osgiBundle);
458 }
459
460 // notifications
461 if (registerFlowsToJmx)
462 unregisterMBean(osgiBundle, executionFlow);
463 ExecutionFlowDescriptorConverter efdc = getExecutionFlowDescriptorConverter(osgiBundle);
464 for (ExecutionModulesListener listener : executionModulesListeners)
465 listener.executionFlowRemoved(osgiBundle.getModuleDescriptor(),
466 efdc.getExecutionFlowDescriptor(executionFlow));
467 }
468 }
469
470 /** Registers an execution module listener. */
471 public synchronized void register(
472 ExecutionModulesListener executionModulesListener,
473 Map<String, String> properties) {
474 // sync with current state
475 for (OsgiBundle osgiBundle : executionContexts.keySet()) {
476 executionModulesListener.executionModuleAdded(osgiBundle
477 .getModuleDescriptor());
478 }
479 for (OsgiBundle osgiBundle : executionFlows.keySet()) {
480 ExecutionFlowDescriptorConverter efdc = getExecutionFlowDescriptorConverter(osgiBundle);
481 for (ExecutionFlow executionFlow : executionFlows.get(osgiBundle))
482 executionModulesListener.executionFlowAdded(
483 osgiBundle.getModuleDescriptor(),
484 efdc.getExecutionFlowDescriptor(executionFlow));
485 }
486 executionModulesListeners.add(executionModulesListener);
487 }
488
489 /** Unregisters an execution module listener. */
490 public synchronized void unregister(
491 ExecutionModulesListener executionModulesListener,
492 Map<String, String> properties) {
493 executionModulesListeners.remove(executionModulesListener);
494 }
495
496 /*
497 * INTERFACE IMPLEMENTATIONS
498 */
499
500 public void bundleChanged(BundleEvent evt) {
501 Bundle bundle = evt.getBundle();
502 if (bundle.getHeaders().get(
503 ExecutionModuleDescriptor.SLC_EXECUTION_MODULE) != null) {
504 OsgiBundle osgiBundle = new OsgiBundle(bundle);
505 if (evt.getType() == BundleEvent.INSTALLED)
506 for (ExecutionModulesListener listener : executionModulesListeners)
507 listener.executionModuleAdded(osgiBundle
508 .getModuleDescriptor());
509 else if (evt.getType() == BundleEvent.UNINSTALLED)
510 for (ExecutionModulesListener listener : executionModulesListeners)
511 listener.executionModuleRemoved(osgiBundle
512 .getModuleDescriptor());
513 }
514
515 }
516
517 @SuppressWarnings({ "rawtypes" })
518 public synchronized void bind(Object service, Map properties)
519 throws Exception {
520 if (service instanceof ExecutionFlowDescriptorConverter) {
521 ExecutionFlowDescriptorConverter executionFlowDescriptorConverter = (ExecutionFlowDescriptorConverter) service;
522 OsgiBundle osgiBundle = asOsgiBundle(properties);
523 executionFlowDescriptorConverters.put(osgiBundle,
524 executionFlowDescriptorConverter);
525 if (log.isTraceEnabled())
526 log.debug("Registered execution flow descriptor converter from "
527 + osgiBundle);
528 } else {
529 // ignore
530 }
531 }
532
533 @SuppressWarnings("rawtypes")
534 public synchronized void unbind(Object service, Map properties)
535 throws Exception {
536 if (service instanceof ExecutionFlowDescriptorConverter) {
537 OsgiBundle osgiBundle = asOsgiBundle(properties);
538 if (executionFlowDescriptorConverters.containsKey(osgiBundle)) {
539 executionFlowDescriptorConverters.remove(osgiBundle);
540 if (log.isTraceEnabled())
541 log.debug("Removed execution flow descriptor converter from "
542 + osgiBundle);
543 }
544 } else {
545 // ignore
546 }
547 }
548
549 /*
550 * JMX
551 */
552 protected MBeanServer getMBeanServer() {
553 return ManagementFactory.getPlatformMBeanServer();
554 }
555
556 public void registerMBean(Module module, ExecutionFlow executionFlow) {
557 try {
558 StandardMBean mbean = new StandardMBean(executionFlow,
559 ExecutionFlow.class);
560 getMBeanServer().registerMBean(mbean,
561 flowMBeanName(module, executionFlow));
562 } catch (Exception e) {
563 String msg = "Cannot register execution flow " + executionFlow
564 + " as mbean";
565 throw new SlcException(msg, e);
566 }
567 }
568
569 public void unregisterMBean(Module module, ExecutionFlow executionFlow) {
570 try {
571 getMBeanServer().unregisterMBean(
572 flowMBeanName(module, executionFlow));
573 } catch (Exception e) {
574 String msg = "Cannot unregister execution flow " + executionFlow
575 + " as mbean";
576 throw new SlcException(msg, e);
577 }
578 }
579
580 @SuppressWarnings("deprecation")
581 protected ObjectName flowMBeanName(Module module,
582 ExecutionFlow executionFlow) {
583 String executionModulesPrefix = "SLCExecutionModules";
584 String path = executionFlow.getPath();
585 String name = executionFlow.getName();
586 if (path == null && name.indexOf('/') >= 0) {
587 path = name.substring(0, name.lastIndexOf('/'));
588 name = name.substring(name.lastIndexOf('/'));
589 }
590
591 StringBuffer buf = new StringBuffer(executionModulesPrefix + ":"
592 + "module=" + module.getName() + " [" + module.getVersion()
593 + "],");
594
595 if (path != null && !path.equals("")) {
596 int depth = 0;
597 for (String token : path.split("/")) {
598 if (!token.equals("")) {
599 buf.append("path").append(depth).append('=');
600 // in order to have directories first
601 buf.append('/');
602 buf.append(token).append(',');
603 depth++;
604 }
605 }
606 }
607 buf.append("name=").append(name);
608 try {
609 return new ObjectName(buf.toString());
610 } catch (Exception e) {
611 throw new SlcException("Cannot generate object name based on "
612 + buf, e);
613 }
614 }
615
616 /*
617 * UTILITIES
618 */
619 @SuppressWarnings("rawtypes")
620 private OsgiBundle asOsgiBundle(Map properties) {
621 String bundleSymbolicName = checkAndGet(Constants.BUNDLE_SYMBOLICNAME,
622 properties);
623 String bundleVersion = checkAndGet(Constants.BUNDLE_VERSION, properties);
624 return new OsgiBundle(bundleSymbolicName, bundleVersion);
625 }
626
627 @SuppressWarnings("rawtypes")
628 private String checkAndGet(Object key, Map properties) {
629 if (!properties.containsKey(key) || properties.get(key) == null)
630 throw new SlcException(key + " not set in " + properties);
631 else
632 return properties.get(key).toString();
633 }
634
635 public void setBundlesManager(BundlesManager bundlesManager) {
636 this.bundlesManager = bundlesManager;
637 }
638
639 public void setDefaultDescriptorConverter(
640 ExecutionFlowDescriptorConverter defaultDescriptorConverter) {
641 this.defaultDescriptorConverter = defaultDescriptorConverter;
642 }
643
644 public void setRegisterFlowsToJmx(Boolean registerFlowsToJmx) {
645 this.registerFlowsToJmx = registerFlowsToJmx;
646 }
647
648 }