Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
CVTPersonaCache.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 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  */
19 package org.sleuthkit.autopsy.communications;
20 
21 import com.google.common.cache.CacheBuilder;
22 import com.google.common.cache.CacheLoader;
23 import com.google.common.cache.LoadingCache;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.List;
27 import java.util.concurrent.ExecutionException;
28 import java.util.concurrent.TimeUnit;
29 import java.util.logging.Level;
34 import org.sleuthkit.datamodel.Account;
35 
41 final public class CVTPersonaCache {
42 
43  private static final Logger logger = Logger.getLogger(CVTPersonaCache.class.getName());
44  private final LoadingCache<Account, List<PersonaAccount>> accountMap;
45 
46  private static CVTPersonaCache instance;
47 
51  private CVTPersonaCache() {
52  accountMap = CacheBuilder.newBuilder().expireAfterAccess(5, TimeUnit.MINUTES).build(
53  new CacheLoader<Account, List<PersonaAccount>>() {
54  @Override
55  public List<PersonaAccount> load(Account key) {
56  List<PersonaAccount> accountList = new ArrayList<>();
57  try {
59  Collection<PersonaAccount> accounts = PersonaAccount.getPersonaAccountsForAccount(key);
60  accountList.addAll(accounts);
61  }
62  } catch (CentralRepoException ex) {
63  logger.log(Level.WARNING, String.format("Unable to load Persona information for account: %s", key), ex);
64  }
65  return accountList;
66  }
67  }
68  );
69  }
70 
76  private static synchronized CVTPersonaCache getInstance() {
77  if (instance == null) {
78  instance = new CVTPersonaCache();
79  }
80 
81  return instance;
82  }
83 
93  static public synchronized List<PersonaAccount> getPersonaAccounts(Account account) throws ExecutionException {
94  return getInstance().accountMap.get(account);
95  }
96 }
static Collection< PersonaAccount > getPersonaAccountsForAccount(long accountId)
final LoadingCache< Account, List< PersonaAccount > > accountMap
static synchronized List< PersonaAccount > getPersonaAccounts(Account account)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static synchronized CVTPersonaCache getInstance()

Copyright © 2012-2022 Basis Technology. Generated on: Tue Jun 27 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.