Autopsy 4.22.1
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 */
19package org.sleuthkit.autopsy.communications;
20
21import com.google.common.cache.CacheBuilder;
22import com.google.common.cache.CacheLoader;
23import com.google.common.cache.LoadingCache;
24import java.util.ArrayList;
25import java.util.Collection;
26import java.util.List;
27import java.util.concurrent.ExecutionException;
28import java.util.concurrent.TimeUnit;
29import java.util.logging.Level;
30import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoException;
31import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepository;
32import org.sleuthkit.autopsy.centralrepository.datamodel.PersonaAccount;
33import org.sleuthkit.autopsy.coreutils.Logger;
34import org.sleuthkit.datamodel.Account;
35
41final 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) {
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)
static synchronized CVTPersonaCache getInstance()
synchronized static Logger getLogger(String name)
Definition Logger.java:124

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