-
Notifications
You must be signed in to change notification settings - Fork 23
/
MissingURIRecorder.java
96 lines (85 loc) · 2.7 KB
/
MissingURIRecorder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* #%L
* Netarchivesuite - harvester
* %%
* Copyright (C) 2005 - 2018 The Royal Danish Library,
* the National Library of France and the Austrian National Library.
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
package dk.netarkivet.viewerproxy;
import java.net.URI;
import java.util.Collections;
import java.util.Set;
import java.util.TreeSet;
/**
* This class handles recordings of URIs not found during URI lookup.
*/
public class MissingURIRecorder extends URIObserver {
/**
* The recorded list of URIs. We use TreeSet which removes duplicates and sorts the entries.
*/
private Set<URI> uriSet = Collections.synchronizedSortedSet(new TreeSet<URI>());
/**
* Indicates whether we are actively recording reported URIs at the moment.
*/
private boolean recordingURIs;
/**
* Start recording missing URIs.
*/
public void startRecordingURIs() {
recordingURIs = true;
}
/**
* Stop recording missing URIs.
*/
public void stopRecordingURIs() {
recordingURIs = false;
}
/**
* Clear list of missing URIs.
*/
public void clearRecordedURIs() {
uriSet = Collections.synchronizedSortedSet(new TreeSet<URI>());
}
/**
* Getter for the recorded missing URIs.
*
* @return the recorded URIs, as a sorted set. Note that this is the primary copy, so don't modify it!
*/
public Set<URI> getRecordedURIs() {
return uriSet;
}
/**
* If we are recording URIs, and the response code is NOT_FOUND, then add URI to the list of missing URIs.
*
* @param uri The URI observed.
* @param responseCode The responsecode of the uri.
*/
public void notify(URI uri, int responseCode) {
if (recordingURIs && responseCode == URIResolver.NOT_FOUND) {
uriSet.add(uri);
}
}
/**
* Returns whether we are currently collecting URIs.
*
* @return True if we are currently collecting URIs.
*/
public boolean isRecordingURIs() {
return recordingURIs;
}
}