Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
Installer.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2015 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.keywordsearch;
20 
21 import com.google.common.util.concurrent.ThreadFactoryBuilder;
22 import java.util.concurrent.ExecutorService;
23 import java.util.concurrent.Executors;
24 import java.util.logging.Level;
25 import org.apache.solr.client.solrj.SolrServerException;
26 import org.openide.modules.ModuleInstall;
27 import org.openide.util.NbBundle;
28 import org.openide.windows.WindowManager;
33 
41 class Installer extends ModuleInstall {
42 
43  private static final Logger logger = Logger.getLogger(Installer.class.getName());
44  private static final long serialVersionUID = 1L;
45  private static final String KWS_START_THREAD_NAME = "KWS-server-start-%d";
46 
47  @Override
48  public void restored() {
49  //Setup the default KeywordSearch configuration files
50  KeywordSearchSettings.setDefaults();
51 
52  final Server server = KeywordSearch.getServer();
53 
54  ExecutorService jobProcessingExecutor = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat(KWS_START_THREAD_NAME).build());
55  Runnable kwsStartTask = new Runnable() {
56  public void run() {
57  try {
58  server.start();
59  } catch (SolrServerNoPortException ex) {
60  logger.log(Level.SEVERE, "Failed to start Keyword Search server: ", ex); //NON-NLS
61  if (ex.getPortNumber() == server.getLocalSolrServerPort()) {
62  reportPortError(ex.getPortNumber());
63  } else {
64  reportStopPortError(ex.getPortNumber());
65  }
66  } catch (KeywordSearchModuleException | SolrServerException ex) {
67  logger.log(Level.SEVERE, "Failed to start Keyword Search server: ", ex); //NON-NLS
68  reportInitError(ex.getMessage());
69  }
70  }
71  };
72 
73  // start KWS service on the background thread. Currently all it does is start the embedded Solr server.
74  jobProcessingExecutor.submit(kwsStartTask);
75  jobProcessingExecutor.shutdown(); // tell executor no more work is coming
76  }
77 
78  @Override
79  public boolean closing() {
80  //platform about to close
81 
82  KeywordSearch.getServer().stop();
83 
84  return true;
85  }
86 
87  @Override
88  public void uninstalled() {
89  //module is being unloaded
90  KeywordSearch.getServer().stop();
91 
92  }
93 
94  private void reportPortError(final int curFailPort) {
95  WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
96  @Override
97  public void run() {
98  final String msg = NbBundle.getMessage(this.getClass(), "Installer.reportPortError", curFailPort, Version.getName(), Server.PROPERTIES_CURRENT_SERVER_PORT, Server.PROPERTIES_FILE);
99  MessageNotifyUtil.Notify.error(NbBundle.getMessage(this.getClass(), "Installer.errorInitKsmMsg"), msg);
100  }
101  });
102  }
103 
104  private void reportStopPortError(final int curFailPort) {
105  WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
106  @Override
107  public void run() {
108  final String msg = NbBundle.getMessage(this.getClass(), "Installer.reportStopPortError", curFailPort, Server.PROPERTIES_CURRENT_STOP_PORT, Server.PROPERTIES_FILE);
109  MessageNotifyUtil.Notify.error(NbBundle.getMessage(this.getClass(), "Installer.errorInitKsmMsg"), msg);
110  }
111  });
112  }
113 
114  private void reportInitError(final String msg) {
115  WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
116  @Override
117  public void run() {
118  MessageNotifyUtil.Notify.error(NbBundle.getMessage(this.getClass(), "Installer.errorInitKsmMsg"), msg);
119  }
120  });
121  }
122 }

Copyright © 2012-2022 Basis Technology. Generated on: Fri Oct 7 2022
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.