VSensorLoader extends Thread { public void releaseStreamSource(StreamSource streamSource) { final AbstractWrapper wrapper = streamSource.getWrapper ( ); streamSource.getInputStream().getRenamingMapping().remove(streamSource.getAlias()); try { wrapper.removeListener(streamSource); } catch (SQLException e) { logger.error("Release the resources failed !" + e.getMessage()); } } VSensorLoader();  VSensorLoader( String pluginsPath ); void addVSensorStateChangeListener(VSensorStateChangeListener listener); void removeVSensorStateChangeListener(VSensorStateChangeListener listener); boolean fireVSensorLoading(VSensorConfig config); boolean fireVSensorUnLoading(VSensorConfig config); static VSensorLoader getInstance(String path); void startLoading(); void run( ); synchronized void loadVirtualSensor(String vsConfigurationFileContent, String fileName); static String getVSConfigurationFilePath(String fileName); synchronized void loadPlugin(); synchronized boolean loadPlugin(String fileFilterName); boolean isVirtualSensorValid(VSensorConfig configuration); void removeAllVSResources( VirtualSensor pool ); void releaseStreamSource(StreamSource streamSource); static Modifications getUpdateStatus(String virtualSensorsPath); static Modifications getUpdateStatus(String virtualSensorsPath, String filterFileName); boolean createInputStreams( VirtualSensor pool ); AbstractWrapper createWrapper(AddressBean addressBean); boolean prepareStreamSource( VSensorConfig vsensorConfig,InputStream inputStream , StreamSource streamSource  ); boolean prepareStreamSource( StreamSource streamSource ,DataField[] outputformat, AbstractWrapper wrapper ); void stopLoading( ); static final String VSENSOR_POOL; static final String STREAM_SOURCE; static final String INPUT_STREAM; }
@Test public void testReloadingVirtualSensor() throws InstantiationException, IllegalAccessException, SQLException { VSensorLoader loader = new VSensorLoader(); InputStream is = new InputStream(); StreamSource ss = new StreamSource().setAlias("my-stream1").setAddressing(addressing).setSqlQuery("select * from wrapper").setRawHistorySize("2").setInputStream(is); ss.setSamplingRate(1); assertTrue(ss.validate()); assertTrue(sm.tableExists(ss.getWrapper().getDBAliasInStr())); assertTrue(sm.tableExists(ss.getUIDStr())); assertFalse(is.getRenamingMapping().isEmpty()); loader.releaseStreamSource(ss); assertTrue(is.getRenamingMapping().isEmpty()); assertFalse(sm.tableExists(ss.getUIDStr())); assertFalse(ss.getWrapper().isActive()); assertFalse(sm.tableExists(ss.getWrapper().getDBAliasInStr())); assertTrue(is.getRenamingMapping().isEmpty()); ss = new StreamSource().setAlias("my-stream1").setAddressing(addressing).setSqlQuery("select * from wrapper").setRawHistorySize("2").setInputStream(is); ss.setSamplingRate(1); }