@SuppressWarnings("unchecked") @Test public void updateEmptyConfiguration() throws ConfigurationException { Bundle bundle = mock(Bundle.class); BundleContext bundleContext = mock(BundleContext.class); when(bundle.getBundleContext()).thenReturn(bundleContext); ManagedProcessEngineFactoryImpl factory = new ManagedProcessEngineFactoryImpl(bundle); factory.updated("id", new Hashtable<String, String>()); verify(bundleContext, never()).registerService(eq(ProcessEngine.class), any(ProcessEngine.class), any(Dictionary.class)); }
@Override public void updated(String pid, Dictionary properties) throws ConfigurationException { if (existingEngines.containsKey(pid)) { existingEngines.get(pid).close(); existingEngines.remove(pid); existingRegisteredEngines.get(pid).unregister(); existingRegisteredEngines.remove(pid); } if (!hasPropertiesConfiguration(properties)) { return; } ClassLoader previous = Thread.currentThread().getContextClassLoader(); ProcessEngine engine; try { ClassLoader cl = new BundleDelegatingClassLoader(bundle); Thread.currentThread().setContextClassLoader( new ClassLoaderWrapper(cl, ProcessEngineFactory.class.getClassLoader(), ProcessEngineConfiguration.class.getClassLoader(), previous)); ProcessEngineConfiguration processEngineConfiguration = createProcessEngineConfiguration(properties); processEngineConfiguration.setClassLoader(cl); engine = processEngineConfiguration.buildProcessEngine(); } finally { Thread.currentThread().setContextClassLoader(previous); } existingEngines.put(pid, engine); Hashtable<String, Object> props = new Hashtable<String, Object>(); props.put("process-engine-name", engine.getName()); ServiceRegistration<ProcessEngine> serviceRegistration = this.bundle.getBundleContext().registerService(ProcessEngine.class, engine, props); existingRegisteredEngines.put(pid, serviceRegistration); }
ManagedProcessEngineFactoryImpl implements ManagedProcessEngineFactory { @Override public void updated(String pid, Dictionary properties) throws ConfigurationException { if (existingEngines.containsKey(pid)) { existingEngines.get(pid).close(); existingEngines.remove(pid); existingRegisteredEngines.get(pid).unregister(); existingRegisteredEngines.remove(pid); } if (!hasPropertiesConfiguration(properties)) { return; } ClassLoader previous = Thread.currentThread().getContextClassLoader(); ProcessEngine engine; try { ClassLoader cl = new BundleDelegatingClassLoader(bundle); Thread.currentThread().setContextClassLoader( new ClassLoaderWrapper(cl, ProcessEngineFactory.class.getClassLoader(), ProcessEngineConfiguration.class.getClassLoader(), previous)); ProcessEngineConfiguration processEngineConfiguration = createProcessEngineConfiguration(properties); processEngineConfiguration.setClassLoader(cl); engine = processEngineConfiguration.buildProcessEngine(); } finally { Thread.currentThread().setContextClassLoader(previous); } existingEngines.put(pid, engine); Hashtable<String, Object> props = new Hashtable<String, Object>(); props.put("process-engine-name", engine.getName()); ServiceRegistration<ProcessEngine> serviceRegistration = this.bundle.getBundleContext().registerService(ProcessEngine.class, engine, props); existingRegisteredEngines.put(pid, serviceRegistration); } }
ManagedProcessEngineFactoryImpl implements ManagedProcessEngineFactory { @Override public void updated(String pid, Dictionary properties) throws ConfigurationException { if (existingEngines.containsKey(pid)) { existingEngines.get(pid).close(); existingEngines.remove(pid); existingRegisteredEngines.get(pid).unregister(); existingRegisteredEngines.remove(pid); } if (!hasPropertiesConfiguration(properties)) { return; } ClassLoader previous = Thread.currentThread().getContextClassLoader(); ProcessEngine engine; try { ClassLoader cl = new BundleDelegatingClassLoader(bundle); Thread.currentThread().setContextClassLoader( new ClassLoaderWrapper(cl, ProcessEngineFactory.class.getClassLoader(), ProcessEngineConfiguration.class.getClassLoader(), previous)); ProcessEngineConfiguration processEngineConfiguration = createProcessEngineConfiguration(properties); processEngineConfiguration.setClassLoader(cl); engine = processEngineConfiguration.buildProcessEngine(); } finally { Thread.currentThread().setContextClassLoader(previous); } existingEngines.put(pid, engine); Hashtable<String, Object> props = new Hashtable<String, Object>(); props.put("process-engine-name", engine.getName()); ServiceRegistration<ProcessEngine> serviceRegistration = this.bundle.getBundleContext().registerService(ProcessEngine.class, engine, props); existingRegisteredEngines.put(pid, serviceRegistration); } ManagedProcessEngineFactoryImpl();  ManagedProcessEngineFactoryImpl(Bundle bundle); }
ManagedProcessEngineFactoryImpl implements ManagedProcessEngineFactory { @Override public void updated(String pid, Dictionary properties) throws ConfigurationException { if (existingEngines.containsKey(pid)) { existingEngines.get(pid).close(); existingEngines.remove(pid); existingRegisteredEngines.get(pid).unregister(); existingRegisteredEngines.remove(pid); } if (!hasPropertiesConfiguration(properties)) { return; } ClassLoader previous = Thread.currentThread().getContextClassLoader(); ProcessEngine engine; try { ClassLoader cl = new BundleDelegatingClassLoader(bundle); Thread.currentThread().setContextClassLoader( new ClassLoaderWrapper(cl, ProcessEngineFactory.class.getClassLoader(), ProcessEngineConfiguration.class.getClassLoader(), previous)); ProcessEngineConfiguration processEngineConfiguration = createProcessEngineConfiguration(properties); processEngineConfiguration.setClassLoader(cl); engine = processEngineConfiguration.buildProcessEngine(); } finally { Thread.currentThread().setContextClassLoader(previous); } existingEngines.put(pid, engine); Hashtable<String, Object> props = new Hashtable<String, Object>(); props.put("process-engine-name", engine.getName()); ServiceRegistration<ProcessEngine> serviceRegistration = this.bundle.getBundleContext().registerService(ProcessEngine.class, engine, props); existingRegisteredEngines.put(pid, serviceRegistration); } ManagedProcessEngineFactoryImpl();  ManagedProcessEngineFactoryImpl(Bundle bundle); @Override String getName(); @Override void updated(String pid, Dictionary properties); @Override void deleted(String pid); }
ManagedProcessEngineFactoryImpl implements ManagedProcessEngineFactory { @Override public void updated(String pid, Dictionary properties) throws ConfigurationException { if (existingEngines.containsKey(pid)) { existingEngines.get(pid).close(); existingEngines.remove(pid); existingRegisteredEngines.get(pid).unregister(); existingRegisteredEngines.remove(pid); } if (!hasPropertiesConfiguration(properties)) { return; } ClassLoader previous = Thread.currentThread().getContextClassLoader(); ProcessEngine engine; try { ClassLoader cl = new BundleDelegatingClassLoader(bundle); Thread.currentThread().setContextClassLoader( new ClassLoaderWrapper(cl, ProcessEngineFactory.class.getClassLoader(), ProcessEngineConfiguration.class.getClassLoader(), previous)); ProcessEngineConfiguration processEngineConfiguration = createProcessEngineConfiguration(properties); processEngineConfiguration.setClassLoader(cl); engine = processEngineConfiguration.buildProcessEngine(); } finally { Thread.currentThread().setContextClassLoader(previous); } existingEngines.put(pid, engine); Hashtable<String, Object> props = new Hashtable<String, Object>(); props.put("process-engine-name", engine.getName()); ServiceRegistration<ProcessEngine> serviceRegistration = this.bundle.getBundleContext().registerService(ProcessEngine.class, engine, props); existingRegisteredEngines.put(pid, serviceRegistration); } ManagedProcessEngineFactoryImpl();  ManagedProcessEngineFactoryImpl(Bundle bundle); @Override String getName(); @Override void updated(String pid, Dictionary properties); @Override void deleted(String pid);  }