Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
RefreshThrottler.java
Go to the documentation of this file.
1/*
2 * Autopsy Forensic Browser
3 *
4 * Copyright 2011-2020 Basis Technology Corp.
5 * Contact: carrier <at> sleuthkit <dot> org
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19package org.sleuthkit.autopsy.guiutils;
20
21import com.google.common.util.concurrent.ThreadFactoryBuilder;
22import java.beans.PropertyChangeEvent;
23import java.beans.PropertyChangeListener;
24import java.util.EnumSet;
25import java.util.Set;
26import java.util.concurrent.ScheduledThreadPoolExecutor;
27import java.util.concurrent.TimeUnit;
28import java.util.concurrent.atomic.AtomicReference;
29import org.sleuthkit.autopsy.ingest.IngestManager;
30
36public class RefreshThrottler {
37
42 public interface Refresher {
43
48 void refresh();
49
57 boolean isRefreshRequired(PropertyChangeEvent evt);
58 }
59
60 static ScheduledThreadPoolExecutor refreshExecutor = new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder().setNameFormat("Node Refresh Thread").build());
61 // Keep a thread safe reference to the current refresh task (if any)
62 private final AtomicReference<RefreshTask> refreshTaskRef;
63
64 // The factory instance that will be called when a refresh is due.
65 private final Refresher refresher;
66
67 private static final long MIN_SECONDS_BETWEEN_REFRESH = 5;
68
73
78 private final class RefreshTask implements Runnable {
79
80 @Override
81 public void run() {
82 // Call refresh on the factory
83 refresher.refresh();
84 // Clear the refresh task reference
85 refreshTaskRef.set(null);
86 }
87 }
88
93 private final PropertyChangeListener pcl;
94
96 this.refreshTaskRef = new AtomicReference<>(null);
97 refresher = r;
98
99 pcl = (PropertyChangeEvent evt) -> {
100 String eventType = evt.getPropertyName();
101 if (eventType.equals(IngestManager.IngestModuleEvent.DATA_ADDED.toString())
102 || eventType.equals(IngestManager.IngestModuleEvent.CONTENT_CHANGED.toString())
103 || eventType.equals(IngestManager.IngestModuleEvent.FILE_DONE.toString())) {
104 if (!refresher.isRefreshRequired(evt)) {
105 return;
106 }
107
108 RefreshTask task = new RefreshTask();
109 if (refreshTaskRef.compareAndSet(null, task)) {
110 refreshExecutor.schedule(task, MIN_SECONDS_BETWEEN_REFRESH, TimeUnit.SECONDS);
111 }
112 }
113 };
114 }
115
122
129}
static final Set< IngestManager.IngestModuleEvent > INGEST_MODULE_EVENTS_OF_INTEREST
final AtomicReference< RefreshTask > refreshTaskRef
static synchronized IngestManager getInstance()
void removeIngestModuleEventListener(final PropertyChangeListener listener)
void addIngestModuleEventListener(final PropertyChangeListener listener)
boolean isRefreshRequired(PropertyChangeEvent evt)

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.