Skip to content

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
Made method reportDifferences(...) private since it was exposing
package private class TimeNSize and no code outside of jetty-util
could have used it.

Signed-off-by: Simone Bordet <[email protected]>
  • Loading branch information
sbordet committed Oct 20, 2019
1 parent 95b205a commit dc59add
Showing 1 changed file with 27 additions and 71 deletions.
98 changes: 27 additions & 71 deletions jetty-util/src/main/java/org/eclipse/jetty/util/Scanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public class Scanner extends AbstractLifeCycle
private static int __scannerId = 0;
private int _scanInterval;
private int _scanCount = 0;
private final List<Listener> _listeners = new ArrayList<Listener>();
private final Map<String, TimeNSize> _prevScan = new HashMap<String, TimeNSize>();
private final Map<String, TimeNSize> _currentScan = new HashMap<String, TimeNSize>();
private final List<Listener> _listeners = new ArrayList<>();
private final Map<String, TimeNSize> _prevScan = new HashMap<>();
private final Map<String, TimeNSize> _currentScan = new HashMap<>();
private FilenameFilter _filter;
private final List<File> _scanDirs = new ArrayList<File>();
private final List<File> _scanDirs = new ArrayList<>();
private volatile boolean _running = false;
private boolean _reportExisting = true;
private boolean _reportDirs = true;
Expand All @@ -66,7 +66,7 @@ public enum Notification
ADDED, CHANGED, REMOVED
}

private final Map<String, Notification> _notifications = new HashMap<String, Notification>();
private final Map<String, Notification> _notifications = new HashMap<>();

static class TimeNSize
{
Expand Down Expand Up @@ -411,11 +411,7 @@ public synchronized void scan()
if (l instanceof ScanListener)
((ScanListener)l).scan();
}
catch (Exception e)
{
LOG.warn(e);
}
catch (Error e)
catch (Throwable e)
{
LOG.warn(e);
}
Expand All @@ -427,16 +423,11 @@ public synchronized void scan()
*/
public synchronized void scanFiles()
{
if (_scanDirs == null)
return;

_currentScan.clear();
Iterator<File> itor = _scanDirs.iterator();
while (itor.hasNext())
for (File dir : _scanDirs)
{
File dir = itor.next();

if ((dir != null) && (dir.exists()))
{
try
{
scanFile(dir.getCanonicalFile(), _currentScan, 0);
Expand All @@ -445,6 +436,7 @@ public synchronized void scanFiles()
{
LOG.warn("Error scanning files.", e);
}
}
}
}

Expand All @@ -454,11 +446,11 @@ public synchronized void scanFiles()
* @param currentScan the info from the most recent pass
* @param oldScan info from the previous pass
*/
public synchronized void reportDifferences(Map<String, TimeNSize> currentScan, Map<String, TimeNSize> oldScan)
private synchronized void reportDifferences(Map<String, TimeNSize> currentScan, Map<String, TimeNSize> oldScan)
{
// scan the differences and add what was found to the map of notifications:

Set<String> oldScanKeys = new HashSet<String>(oldScan.keySet());
Set<String> oldScanKeys = new HashSet<>(oldScan.keySet());

// Look for new and changed files
for (Map.Entry<String, TimeNSize> entry : currentScan.entrySet())
Expand All @@ -480,14 +472,8 @@ public synchronized void reportDifferences(Map<String, TimeNSize> currentScan, M
else if (!oldScan.get(file).equals(currentScan.get(file)))
{
Notification old = _notifications.put(file, Notification.CHANGED);
if (old != null)
{
switch (old)
{
case ADDED:
_notifications.put(file, Notification.ADDED);
}
}
if (old == Notification.ADDED)
_notifications.put(file, Notification.ADDED);
}
}

Expand All @@ -497,14 +483,8 @@ else if (!oldScan.get(file).equals(currentScan.get(file)))
if (!currentScan.containsKey(file))
{
Notification old = _notifications.put(file, Notification.REMOVED);
if (old != null)
{
switch (old)
{
case ADDED:
_notifications.remove(file);
}
}
if (old == Notification.ADDED)
_notifications.remove(file);
}
}

Expand All @@ -513,7 +493,7 @@ else if (!oldScan.get(file).equals(currentScan.get(file)))

// Process notifications
// Only process notifications that are for stable files (ie same in old and current scan).
List<String> bulkChanges = new ArrayList<String>();
List<String> bulkChanges = new ArrayList<>();
for (Iterator<Entry<String, Notification>> iter = _notifications.entrySet().iterator(); iter.hasNext(); )
{
Entry<String, Notification> entry = iter.next();
Expand Down Expand Up @@ -565,7 +545,7 @@ private void scanFile(File f, Map<String, TimeNSize> scanInfoMap, int depth)

if (f.isFile() || depth > 0 && _reportDirs && f.isDirectory())
{
if ((_filter == null) || ((_filter != null) && _filter.accept(f.getParentFile(), f.getName())))
if (_filter == null || _filter.accept(f.getParentFile(), f.getName()))
{
if (LOG.isDebugEnabled())
LOG.debug("scan accepted {}", f);
Expand All @@ -585,9 +565,9 @@ private void scanFile(File f, Map<String, TimeNSize> scanInfoMap, int depth)
File[] files = f.listFiles();
if (files != null)
{
for (int i = 0; i < files.length; i++)
for (File file : files)
{
scanFile(files[i], scanInfoMap, depth + 1);
scanFile(file, scanInfoMap, depth + 1);
}
}
else
Expand All @@ -612,20 +592,14 @@ private void warn(Object listener, String filename, Throwable th)
*/
private void reportAddition(String filename)
{
Iterator<Listener> itor = _listeners.iterator();
while (itor.hasNext())
for (Listener l : _listeners)
{
Listener l = itor.next();
try
{
if (l instanceof DiscreteListener)
((DiscreteListener)l).fileAdded(filename);
}
catch (Exception e)
{
warn(l, filename, e);
}
catch (Error e)
catch (Throwable e)
{
warn(l, filename, e);
}
Expand All @@ -639,20 +613,14 @@ private void reportAddition(String filename)
*/
private void reportRemoval(String filename)
{
Iterator<Listener> itor = _listeners.iterator();
while (itor.hasNext())
for (Object l : _listeners)
{
Object l = itor.next();
try
{
if (l instanceof DiscreteListener)
((DiscreteListener)l).fileRemoved(filename);
}
catch (Exception e)
{
warn(l, filename, e);
}
catch (Error e)
catch (Throwable e)
{
warn(l, filename, e);
}
Expand All @@ -666,20 +634,14 @@ private void reportRemoval(String filename)
*/
private void reportChange(String filename)
{
Iterator<Listener> itor = _listeners.iterator();
while (itor.hasNext())
for (Listener l : _listeners)
{
Listener l = itor.next();
try
{
if (l instanceof DiscreteListener)
((DiscreteListener)l).fileChanged(filename);
}
catch (Exception e)
{
warn(l, filename, e);
}
catch (Error e)
catch (Throwable e)
{
warn(l, filename, e);
}
Expand All @@ -688,20 +650,14 @@ private void reportChange(String filename)

private void reportBulkChanges(List<String> filenames)
{
Iterator<Listener> itor = _listeners.iterator();
while (itor.hasNext())
for (Listener l : _listeners)
{
Listener l = itor.next();
try
{
if (l instanceof BulkListener)
((BulkListener)l).filesChanged(filenames);
}
catch (Exception e)
{
warn(l, filenames.toString(), e);
}
catch (Error e)
catch (Throwable e)
{
warn(l, filenames.toString(), e);
}
Expand Down

0 comments on commit dc59add

Please sign in to comment.