Autopsy  4.7.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
LoggedTask.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-14 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  */
19 package org.sleuthkit.autopsy.coreutils;
20 
21 import java.util.concurrent.ExecutionException;
22 import java.util.logging.Level;
23 import javafx.concurrent.Task;
24 import org.openide.util.Cancellable;
25 
29 public abstract class LoggedTask<T> extends Task<T> implements Cancellable {
30 
31  private static final Logger LOGGER = Logger.getLogger(LoggedTask.class.getName());
32 
33  private final boolean logStateChanges;
34 
35  public LoggedTask(String taskName, boolean logStateChanges) {
36  updateTitle(taskName);
37  this.logStateChanges = logStateChanges;
38  }
39 
40  @Override
41  protected void cancelled() {
42  super.cancelled();
43  if (logStateChanges) {
44  // LOGGER.log(Level.WARNING, "{0} cancelled!", getTitle());
45  }
46  }
47 
48  @Override
49  protected void failed() {
50  super.failed();
51  LOGGER.log(Level.SEVERE, getTitle() + " failed!", getException()); //NON-NLS
52 
53  }
54 
55  @Override
56  protected void scheduled() {
57  super.scheduled();
58  if (logStateChanges) {
59  // LOGGER.log(Level.INFO, "{0} scheduled", getTitle());
60  }
61  }
62 
63  @Override
64  protected void succeeded() {
65  super.succeeded();
66  try {
67  get();
68  } catch (InterruptedException | ExecutionException ex) {
69  LOGGER.log(Level.SEVERE, getTitle() + " threw unexpected exception: ", ex); // NON-NLS
70  }
71  if (logStateChanges) {
72  // LOGGER.log(Level.INFO, "{0} succeeded", getTitle());
73  }
74  }
75 }
LoggedTask(String taskName, boolean logStateChanges)
Definition: LoggedTask.java:35
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2016 Basis Technology. Generated on: Mon Jun 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.