+
+ @Override
+ public Status persistConfiguration(List<ConfigurationObject> config, String fileName) {
+ if (!hasBeenSaved()) {
+ return new Status(StatusCode.NOTALLOWED,
+ String.format("Container %s has not been saved yet", containerName));
+ }
+ String destination = String.format("%s%s", root, fileName);
+ return objWriter.write(config, destination);
+ }
+
+ @Override
+ public List<ConfigurationObject> retrieveConfiguration(IObjectReader reader, String fileName) {
+ if (!clusterServices.amICoordinator()) {
+ return Collections.emptyList();
+ }
+ String source = String.format("%s%s", root, fileName);
+ Object obj = objReader.read(reader, source);
+ if (obj == null) {
+ return Collections.<ConfigurationObject> emptyList();
+ }
+ if (obj instanceof ConcurrentMap) {
+ return new ArrayList<ConfigurationObject>(((ConcurrentMap)obj).values());
+ }
+ return (List<ConfigurationObject>) obj;
+ }
+
+ @Override
+ public boolean hasBeenSaved() {
+ try {
+ File configRoot = new File(this.getConfigurationRoot());
+ return configRoot.exists();
+ } catch (Exception e) {
+ return false;
+ }
+
+ }