gluu
公開メンバ関数 | 非公開メンバ関数 | 非公開変数類 | 静的非公開変数類 | 全メンバ一覧
org.gluu.oxtrust.ldap.cache.service.CacheRefreshSnapshotFileService クラス
org.gluu.oxtrust.ldap.cache.service.CacheRefreshSnapshotFileService 連携図
Collaboration graph

公開メンバ関数

boolean prepareSnapshotsFolder (CacheRefreshConfiguration cacheRefreshConfiguration)
 
boolean createSnapshot (CacheRefreshConfiguration cacheRefreshConfiguration, Map< String, Integer > inumWithEntryHashCodeMap)
 
Map< String, Integer > readSnapshot (CacheRefreshConfiguration cacheRefreshConfiguration, String snapshotFileName)
 
Map< String, Integer > readLastSnapshot (CacheRefreshConfiguration cacheRefreshConfiguration)
 
boolean retainSnapshots (CacheRefreshConfiguration cacheRefreshConfiguration, int count)
 
List< String > readProblemList (CacheRefreshConfiguration cacheRefreshConfiguration)
 
boolean writeProblemList (CacheRefreshConfiguration cacheRefreshConfiguration, Set< String > changedInums)
 

非公開メンバ関数

String [] getSnapshotsList (CacheRefreshConfiguration cacheRefreshConfiguration)
 

非公開変数類

Logger log
 

静的非公開変数類

static final String SNAPSHOT_FILE_NAME_PATTERN = "inum-snapshot-%s.txt"
 
static final String PROBLEM_LIST_FILE_NAME = "problem-inum-list.txt"
 
static final String SNAPSHOT_FILE_NAME_DATE_PATTERN = "yyyy-MM-dd-HH-mm"
 

詳解

Helper service to work with snapshots

著者
Yuriy Movchan Date: 06.09.2011

関数詳解

◆ createSnapshot()

boolean org.gluu.oxtrust.ldap.cache.service.CacheRefreshSnapshotFileService.createSnapshot ( CacheRefreshConfiguration  cacheRefreshConfiguration,
Map< String, Integer >  inumWithEntryHashCodeMap 
)
inline
70  {
71  if (!prepareSnapshotsFolder(cacheRefreshConfiguration)) {
72  return false;
73  }
74 
75  DateFormat fileNameDateFormat = new SimpleDateFormat(SNAPSHOT_FILE_NAME_DATE_PATTERN);
76  String snapshotFileName = String.format(SNAPSHOT_FILE_NAME_PATTERN, fileNameDateFormat.format(new Date()));
77 
78  File file = new File(cacheRefreshConfiguration.getSnapshotFolder() + File.separator + snapshotFileName);
79  BufferedWriter bos;
80  try {
81  bos = new BufferedWriter(new FileWriter(file));
82  } catch (IOException ex) {
83  log.error("Failed to create snapshot file '{}'", file.getAbsolutePath(), ex);
84  return false;
85  }
86 
87  try {
88  for (Entry<String, Integer> entry : inumWithEntryHashCodeMap.entrySet()) {
89  bos.write(String.format("%s:%d\n", entry.getKey(), entry.getValue()));
90  }
91  bos.flush();
92  } catch (IOException ex) {
93  log.error("Failed to create snapshot file '{}'", file.getAbsolutePath(), ex);
94  return false;
95  } finally {
96  IOUtils.closeQuietly(bos);
97  }
98 
99  return true;
100  }
boolean prepareSnapshotsFolder(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshSnapshotFileService.java:54
static final String SNAPSHOT_FILE_NAME_PATTERN
Definition: CacheRefreshSnapshotFileService.java:50
Logger log
Definition: CacheRefreshSnapshotFileService.java:48
static final String SNAPSHOT_FILE_NAME_DATE_PATTERN
Definition: CacheRefreshSnapshotFileService.java:52

◆ getSnapshotsList()

String [] org.gluu.oxtrust.ldap.cache.service.CacheRefreshSnapshotFileService.getSnapshotsList ( CacheRefreshConfiguration  cacheRefreshConfiguration)
inlineprivate
160  {
161  File file = new File(cacheRefreshConfiguration.getSnapshotFolder());
162  String[] files = file.list(new WildcardFileFilter(String.format(SNAPSHOT_FILE_NAME_PATTERN, "*")));
163  Arrays.sort(files);
164 
165  return files;
166  }
static final String SNAPSHOT_FILE_NAME_PATTERN
Definition: CacheRefreshSnapshotFileService.java:50

◆ prepareSnapshotsFolder()

boolean org.gluu.oxtrust.ldap.cache.service.CacheRefreshSnapshotFileService.prepareSnapshotsFolder ( CacheRefreshConfiguration  cacheRefreshConfiguration)
inline
54  {
55  String snapshotFolder = cacheRefreshConfiguration.getSnapshotFolder();
56 
57  try {
58  File dir = new File(snapshotFolder);
59  if (!dir.exists()) {
60  FileUtils.forceMkdir(dir);
61  }
62  } catch (IOException ex) {
63  log.error("Failed to create snapshot folder '{}'", snapshotFolder, ex);
64  return false;
65  }
66 
67  return true;
68  }
Logger log
Definition: CacheRefreshSnapshotFileService.java:48

◆ readLastSnapshot()

Map<String, Integer> org.gluu.oxtrust.ldap.cache.service.CacheRefreshSnapshotFileService.readLastSnapshot ( CacheRefreshConfiguration  cacheRefreshConfiguration)
inline
147  {
148  if (!prepareSnapshotsFolder(cacheRefreshConfiguration)) {
149  return null;
150  }
151 
152  String[] snapshots = getSnapshotsList(cacheRefreshConfiguration);
153  if (ArrayHelper.isEmpty(snapshots)) {
154  return null;
155  }
156 
157  return readSnapshot(cacheRefreshConfiguration, snapshots[snapshots.length - 1]);
158  }
String [] getSnapshotsList(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshSnapshotFileService.java:160
boolean prepareSnapshotsFolder(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshSnapshotFileService.java:54
Map< String, Integer > readSnapshot(CacheRefreshConfiguration cacheRefreshConfiguration, String snapshotFileName)
Definition: CacheRefreshSnapshotFileService.java:102

◆ readProblemList()

List<String> org.gluu.oxtrust.ldap.cache.service.CacheRefreshSnapshotFileService.readProblemList ( CacheRefreshConfiguration  cacheRefreshConfiguration)
inline
188  {
189  if (!prepareSnapshotsFolder(cacheRefreshConfiguration)) {
190  return null;
191  }
192 
193  File file = new File(cacheRefreshConfiguration.getSnapshotFolder() + File.separator + PROBLEM_LIST_FILE_NAME);
194  if (!file.exists()) {
195  return null;
196  }
197 
198  BufferedReader bis;
199  try {
200  bis = new BufferedReader(new FileReader(file));
201  } catch (FileNotFoundException ex) {
202  log.error("Failed to load problem list from file '{}'", file.getAbsolutePath(), ex);
203  return null;
204  }
205 
206  List<String> result = new ArrayList<String>();
207  try {
208  String line;
209  while ((line = bis.readLine()) != null) {
210  result.add(line);
211  }
212  } catch (IOException ex) {
213  log.error("Failed to load problem list from file '{}'", file.getAbsolutePath(), ex);
214  return null;
215  } finally {
216  IOUtils.closeQuietly(bis);
217  }
218 
219  return result;
220  }
boolean prepareSnapshotsFolder(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshSnapshotFileService.java:54
static final String PROBLEM_LIST_FILE_NAME
Definition: CacheRefreshSnapshotFileService.java:51
Logger log
Definition: CacheRefreshSnapshotFileService.java:48

◆ readSnapshot()

Map<String, Integer> org.gluu.oxtrust.ldap.cache.service.CacheRefreshSnapshotFileService.readSnapshot ( CacheRefreshConfiguration  cacheRefreshConfiguration,
String  snapshotFileName 
)
inline
102  {
103  if (!prepareSnapshotsFolder(cacheRefreshConfiguration)) {
104  return null;
105  }
106 
107  File file = new File(cacheRefreshConfiguration.getSnapshotFolder() + File.separator + snapshotFileName);
108  if (!file.exists()) {
109  return null;
110  }
111 
112  BufferedReader bis;
113  try {
114  bis = new BufferedReader(new FileReader(file));
115  } catch (FileNotFoundException ex) {
116  log.error("Failed to load snapshot file '{}'", file.getAbsolutePath(), ex);
117  return null;
118  }
119 
120  Map<String, Integer> result = new HashMap<String, Integer>();
121  try {
122  String line;
123  while ((line = bis.readLine()) != null) {
124  String[] lineValues = line.split(":");
125  if (lineValues.length != 2) {
126  log.error("Failed to parse line: {}", line);
127  return null;
128  }
129 
130  try {
131  result.put(lineValues[0], Integer.valueOf(lineValues[1]));
132  } catch (RuntimeException ex) {
133  log.error("Failed to parse '{}' to integer", lineValues[1], ex);
134  return null;
135  }
136  }
137  } catch (IOException ex) {
138  log.error("Failed to load snapshot file '{}'", file.getAbsolutePath(), ex);
139  return null;
140  } finally {
141  IOUtils.closeQuietly(bis);
142  }
143 
144  return result;
145  }
boolean prepareSnapshotsFolder(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshSnapshotFileService.java:54
Logger log
Definition: CacheRefreshSnapshotFileService.java:48

◆ retainSnapshots()

boolean org.gluu.oxtrust.ldap.cache.service.CacheRefreshSnapshotFileService.retainSnapshots ( CacheRefreshConfiguration  cacheRefreshConfiguration,
int  count 
)
inline
168  {
169  if (!prepareSnapshotsFolder(cacheRefreshConfiguration)) {
170  return false;
171  }
172 
173  String[] snapshots = getSnapshotsList(cacheRefreshConfiguration);
174  if (ArrayHelper.isEmpty(snapshots)) {
175  return true;
176  }
177 
178  for (int i = 0; i < snapshots.length - count; i++) {
179  File file = new File(cacheRefreshConfiguration.getSnapshotFolder() + File.separator + snapshots[i]);
180  if (!file.delete()) {
181  log.error("Failed to remove snaphost file '{}'", file.getAbsolutePath());
182  }
183  }
184 
185  return true;
186  }
String [] getSnapshotsList(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshSnapshotFileService.java:160
boolean prepareSnapshotsFolder(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshSnapshotFileService.java:54
Logger log
Definition: CacheRefreshSnapshotFileService.java:48

◆ writeProblemList()

boolean org.gluu.oxtrust.ldap.cache.service.CacheRefreshSnapshotFileService.writeProblemList ( CacheRefreshConfiguration  cacheRefreshConfiguration,
Set< String >  changedInums 
)
inline
222  {
223  if (!prepareSnapshotsFolder(cacheRefreshConfiguration)) {
224  return false;
225  }
226 
227  File file = new File(cacheRefreshConfiguration.getSnapshotFolder() + File.separator + PROBLEM_LIST_FILE_NAME);
228  BufferedWriter bos;
229  try {
230  bos = new BufferedWriter(new FileWriter(file));
231  } catch (IOException ex) {
232  log.error("Failed to write problem list to file '{}'", file.getAbsolutePath(), ex);
233  return false;
234  }
235 
236  try {
237  for (String changedInum : changedInums) {
238  bos.write(String.format("%s\n", changedInum));
239  }
240  bos.flush();
241  } catch (IOException ex) {
242  log.error("Failed to write problem list to file '{}'", file.getAbsolutePath(), ex);
243  return false;
244  } finally {
245  IOUtils.closeQuietly(bos);
246  }
247 
248  return true;
249  }
boolean prepareSnapshotsFolder(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshSnapshotFileService.java:54
static final String PROBLEM_LIST_FILE_NAME
Definition: CacheRefreshSnapshotFileService.java:51
Logger log
Definition: CacheRefreshSnapshotFileService.java:48

メンバ詳解

◆ log

Logger org.gluu.oxtrust.ldap.cache.service.CacheRefreshSnapshotFileService.log
private

◆ PROBLEM_LIST_FILE_NAME

final String org.gluu.oxtrust.ldap.cache.service.CacheRefreshSnapshotFileService.PROBLEM_LIST_FILE_NAME = "problem-inum-list.txt"
staticprivate

◆ SNAPSHOT_FILE_NAME_DATE_PATTERN

final String org.gluu.oxtrust.ldap.cache.service.CacheRefreshSnapshotFileService.SNAPSHOT_FILE_NAME_DATE_PATTERN = "yyyy-MM-dd-HH-mm"
staticprivate

◆ SNAPSHOT_FILE_NAME_PATTERN

final String org.gluu.oxtrust.ldap.cache.service.CacheRefreshSnapshotFileService.SNAPSHOT_FILE_NAME_PATTERN = "inum-snapshot-%s.txt"
staticprivate

このクラス詳解は次のファイルから抽出されました: