class DataSetDefDeployer {

    protected synchronized void doDeploy() {
        if (!StringUtils.isBlank(directory)) {

            // Look for data sets deploy
            File[] files = new File(directory).listFiles(_deployFilter);
            if (files != null) {
                for (File f : files) {
                    try {
                        // Avoid repetitions
                        f.delete();

                        // Get the .dset file
                        File dsetFile = new File(f.getAbsolutePath().replace(".deploy", ""));
                        if (!dsetFile.exists()) continue;

                        // Read & parse the data set
                        FileReader fileReader = new FileReader(dsetFile);
                        String json = IOUtils.toString(fileReader);
                        DataSetDef def = jsonMarshaller.fromJson(json);
                        if (StringUtils.isBlank(def.getUUID())) def.setUUID(dsetFile.getName());

                        // CSV specific ...
                        if (def instanceof CSVDataSetDef) {
                            CSVDataSetDef csvDef = (CSVDataSetDef) def;
                            File csvFile = getCSVFile(csvDef);
                            if (csvFile != null) {
                                csvDef.setFilePath(csvFile.getAbsolutePath());
                            } else {
                                log.error("Data set CSV file not found: " + f.getName());
                                continue;
                            }
                        }

                        // Check if the data set really needs to be registered.
                        DataSetDef existingDef = dataSetDefRegistry.getDataSetDef(def.getUUID());
                        if (existingDef != null && jsonMarshaller.toJsonString(existingDef).equals(jsonMarshaller.toJsonString(def))) {
                            // Avoid redundant deployments
                            log.info("Data set already deployed: " + def.getUUID());
                        } else {
                            // Register the data set
                            dataSetDefRegistry.registerDataSetDef(def, "system", "deploy(" + def.getUUID() + ")");
                            log.info("Data set deployed: " + def.getUUID());
                        }
                    } catch (Exception e) {
                        log.error("Data set deployment error: " + f.getName(), e);
                    }
                }
            }

            // Look for data sets undeploy
            files = new File(directory).listFiles(_undeployFilter);
            if (files != null) {
                for (File f : files) {
                    try {
                        // Avoid repetitions
                        f.delete();

                        // Un-deploy the given uuid
                        String uuid = f.getName().replace(".undeploy", "");
                        DataSetDef def = dataSetDefRegistry.getDataSetDef(uuid);
                        if (def != null) {
                            dataSetDefRegistry.removeDataSetDef(uuid, "system", "undeploy(" + uuid + ")");
                            log.info("Data set deleted: " + def.getName());
                        } else {
                            log.error("Data set not found: " + uuid);
                        }
                    } catch (Exception e) {
                        log.error("Data set un-deploy error: " + f.getName(), e);
                    }
                }
            }
        }
    }

    public  DataSetDefDeployer();
    public  DataSetDefDeployer(DataSetDefJSONMarshaller jsonMarshaller, DataSetDefRegistry dataSetDefRegistry);

}