public void addProduct( URL path, User owner, final List<Collection> collections, String origin, Scanner scanner, FileScannerWrapper wrapper) throws DataStoreAlreadyExistException { if (productDao.exists(path)) { throw new DataStoreAlreadyExistException( "Product \"" + path.toExternalForm() + "\" already present in the system."); } /* **** CRITICAL SECTION *** */ /** THIS SECTION SHALL NEVER BE STOPPED BY CNTRL-C OR OTHER SIGNALS */ /* TODO: check if shutdownHook can protect this section */ Product product = new Product(); product.setPath(path); product.setOrigin(origin); List<User> users = new ArrayList<User>(); if (owner != null) { product.setOwner(owner); users.add(userDao.read(owner.getId())); product.setAuthorizedUsers(new HashSet<User>(users)); } product = productDao.create(product); // FIX product = productDao.read(product.getId()); /* **** CRITICAL SECTION *** */ processProduct(product, owner, collections, scanner, wrapper); }