1 6 7 package SOFA.SOFAnet.Repository; 8 9 import java.io.*; 10 import java.util.*; 11 12 18 public class LocalInfos extends StorageBase 19 { 20 21 22 public LocalInfos(File baseDir) 23 { 24 super(baseDir, "local", true); 25 init(); 26 fixCrashInconsistency(); 27 } 28 29 35 protected void fixCrashInconsistency() 36 { 37 synchronized (map) 38 { 39 Iterator it = map.values().iterator(); 40 while (it.hasNext()) 41 { 42 LocalInfo localInfo = (LocalInfo)it.next(); 43 Licence licence = localInfo.getLicence(); 44 if (localInfo.isInMemory() && licence.withCopies()) 45 { 46 localInfo.setInMemoryFlag(false); 47 licence.increaseNumberOfCopies(1); 48 localInfo.saveToStorage(); 49 } 50 } 51 } 52 } 53 54 protected StorageItem newItem(String name, File file) 55 { 56 String bundleName = BundleInfo.fileNameToBundleName(name); 57 if (bundleName == null) return null; 58 return new LocalInfo(bundleName, file); 59 } 60 61 68 public LocalInfo getLocalInfo(String bundleName) 69 { 70 return (LocalInfo)map.get(bundleName); 71 } 72 73 79 public boolean deleteLocalInfo(String bundleName) 80 { 81 synchronized (map) 82 { 83 LocalInfo localInfo = (LocalInfo)map.remove(bundleName); 84 if (localInfo != null) 85 { 86 localInfo.deleteFromStorage(); 87 return true; 88 } 89 else return false; 90 } 91 } 92 93 100 public LocalInfo addLocalInfo(String bundleName, 101 Licence licence, 102 int state, 103 ShareGroups smShareGroups, 104 NodeNameFilter smNodeFilter, 105 boolean smEquality, 106 String scManager) 107 { 108 synchronized (map) 109 { 110 if (map.get(bundleName) != null) return null; 111 112 String fileName = BundleInfo.bundleNameToFileName(bundleName); 113 if (fileName == null) return null; 114 LocalInfo localInfo = new LocalInfo(bundleName, new File(baseDir, fileName + ".local")); 115 localInfo.setLicence(licence); 116 localInfo.setState(state); 117 localInfo.setSMShareGroups(smShareGroups); 118 localInfo.setSMNodeFilter(smNodeFilter); 119 localInfo.setSMEquality(smEquality); 120 if (localInfo.isShareManager()) localInfo.setSMClients(new NodeNameList()); 121 localInfo.setSCManager(scManager); 122 localInfo.saveToStorage(); 123 map.put(bundleName, localInfo); 124 return localInfo; 125 } 126 } 127 128 } 129 | Popular Tags |