Java Code Examples for com.google.common.cache.CacheLoader#InvalidCacheLoadException
The following examples show how to use
com.google.common.cache.CacheLoader#InvalidCacheLoadException .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReportService.java From poli with MIT License | 6 votes |
public List<Report> getReportsByUser(User user) { if (StringUtils.isEmpty(user)) { return Collections.emptyList(); } try { List<Report> rt = USER_REPORT_CACHE.get(user.getId(), () -> { List<Report> reports = new ArrayList<>(); if (Constants.SYS_ROLE_VIEWER.equals(user.getSysRole())) { reports = reportDao.findByViewer(user.getId()); } else { reports = reportDao.findAll(); } return reports; }); return rt; } catch (ExecutionException | CacheLoader.InvalidCacheLoadException e) { return Collections.emptyList(); } }
Example 2
Source File: SharedReportService.java From poli with MIT License | 6 votes |
public SharedLinkInfo getSharedLinkInfoByShareKey(String shareKey) { if (StringUtils.isEmpty(shareKey)) { return null; } try { SharedLinkInfo info = SHARE_LINK_INFO_CACHE.get(shareKey, () -> { User u = userDao.findByShareKey(shareKey); u.setUserAttributes(userDao.findUserAttributes(u.getId())); SharedReport sharedReport = sharedReportDao.findByShareKey(shareKey); long reportId = sharedReport.getReportId(); List<Component> components = componentDao.findByReportId(reportId); Set<String> componentQueryUrls = new HashSet<>(); for (Component component : components) { componentQueryUrls.add("/ws/jdbcquery/component/" + component.getId()); } return new SharedLinkInfo(u, reportId, componentQueryUrls); }); return info; } catch (ExecutionException | CacheLoader.InvalidCacheLoadException e) { return null; } }
Example 3
Source File: UserService.java From poli with MIT License | 6 votes |
public User getUserBySessionKey(String sessionKey) { if (StringUtils.isEmpty(sessionKey)) { return null; } try { User user = SESSION_USER_CACHE.get(sessionKey, () -> { User u = userDao.findBySessionKey(sessionKey); u.setUserAttributes(userDao.findUserAttributes(u.getId())); return u; }); return user; } catch (ExecutionException | CacheLoader.InvalidCacheLoadException e) { return null; } }
Example 4
Source File: UserService.java From poli with MIT License | 6 votes |
public User getUserByApiKey(String apiKey) { if (StringUtils.isEmpty(apiKey)) { return null; } try { User user = API_KEY_USER_CACHE.get(apiKey, () -> { User u = userDao.findByApiKey(apiKey); u.setUserAttributes(userDao.findUserAttributes(u.getId())); return u; }); return user; } catch (ExecutionException | CacheLoader.InvalidCacheLoadException e) { return null; } }
Example 5
Source File: PriceLookup.java From 07kit with GNU General Public License v3.0 | 6 votes |
public static List<PriceInfo> search(String term, int limit) { try { Request request = Request.Get(API_URL + "search?term=" + URLEncoder.encode(term, "UTF-8") + "&limit=" + limit); request.addHeader(AUTH_HEADER_KEY, "Bearer " + Session.get().getApiToken()); HttpResponse response = Executor.newInstance(HttpUtil.getClient()).execute(request).returnResponse(); if (response != null) { if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { byte[] bytes = EntityUtils.toByteArray(response.getEntity()); return GSON.fromJson(new String(bytes), PRICE_INFO_LIST_TYPE); } } return new ArrayList<>(); } catch (IOException | CacheLoader.InvalidCacheLoadException e) { e.printStackTrace(); return new ArrayList<>(); } }
Example 6
Source File: JdbcDataSourceService.java From poli with MIT License | 5 votes |
public DataSource getDataSource(long dataSourceId) { if (dataSourceId == 0) { return null; } try { DataSource hiDs = DATA_SOURCE_CACHE.get(dataSourceId, () -> { JdbcDataSource dataSource = jdbcDataSourceDao.findById(dataSourceId); if (dataSource == null) { return null; } HikariDataSource newHiDs = new HikariDataSource(); newHiDs.setJdbcUrl(dataSource.getConnectionUrl()); newHiDs.setUsername(dataSource.getUsername()); newHiDs.setPassword(dataSource.getPassword()); if (!StringUtils.isEmpty(dataSource.getDriverClassName())) { newHiDs.setDriverClassName(dataSource.getDriverClassName()); } newHiDs.setMaximumPoolSize(appProperties.getDatasourceMaximumPoolSize()); newHiDs.setLeakDetectionThreshold(LEAK_DETECTION_THRESHOLD); return newHiDs; }); return hiDs; } catch (ExecutionException | CacheLoader.InvalidCacheLoadException e) { return null; } }
Example 7
Source File: TokenManagerImpl.java From dremio-oss with Apache License 2.0 | 5 votes |
private SessionState getSessionState(final String token) { checkArgument(token != null, "invalid token"); final SessionState value; try { value = tokenCache.getUnchecked(token); } catch (CacheLoader.InvalidCacheLoadException ignored) { throw new IllegalArgumentException("invalid token"); } return value; }
Example 8
Source File: PriceLookup.java From 07kit with GNU General Public License v3.0 | 4 votes |
public static Map<Integer, Integer> getPrices(Collection<Integer> ids) { try { Map<Integer, Integer> prices = new HashMap<>(); List<Integer> idsClone = new ArrayList<>(ids); idsClone.forEach(id -> { if (id == 995) { prices.put(id, 1); } else { PriceInfo info = PRICE_INFO_CACHE.getIfPresent(String.valueOf(id)); if (info != null) { prices.put(info.getItemId(), info.getBuyAverage()); } } }); idsClone.removeAll(prices.keySet()); if (idsClone.size() == 0) { return prices; } Request request = Request.Post(API_URL + "ids"); request.addHeader(AUTH_HEADER_KEY, "Bearer " + Session.get().getApiToken()); request.bodyString(GSON.toJson(idsClone), ContentType.APPLICATION_JSON); HttpResponse response = Executor.newInstance(HttpUtil.getClient()).execute(request).returnResponse(); if (response != null) { if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { byte[] bytes = EntityUtils.toByteArray(response.getEntity()); List<PriceInfo> infos = GSON.fromJson(new String(bytes), PRICE_INFO_LIST_TYPE); infos.forEach(i -> { PRICE_INFO_CACHE.put(String.valueOf(i.getItemId()), i); prices.put(i.getItemId(), i.getBuyAverage()); }); } } return prices; } catch (IOException | CacheLoader.InvalidCacheLoadException e) { e.printStackTrace(); return new HashMap<>(); } }
Example 9
Source File: MantaroListener.java From MantaroBot with GNU General Public License v3.0 | 4 votes |
private void logDelete(GuildMessageDeleteEvent event) { try { String hour = df.format(new Date(System.currentTimeMillis())); final ManagedDatabase db = MantaroData.db(); final DBGuild dbGuild = db.getGuild(event.getGuild()); final GuildData data = dbGuild.getData(); String logChannel = data.getGuildLogChannel(); if (logChannel != null) { TextChannel tc = event.getGuild().getTextChannelById(logChannel); if (tc == null) return; CachedMessage deletedMessage = messageCache.get(event.getMessageIdLong(), Optional::empty).orElse(null); if (deletedMessage != null && !deletedMessage.getContent().isEmpty() && !event.getChannel().getId().equals(logChannel) && !deletedMessage.getAuthor().getId().equals(event.getJDA().getSelfUser().getId())) { if (data.getModlogBlacklistedPeople().contains(deletedMessage.getAuthor().getId())) { return; } if (data.getLogExcludedChannels().contains(event.getChannel().getId())) { return; } if (!data.getModLogBlacklistWords().isEmpty()) { //This is not efficient at all I'm pretty sure, is there a better way? List<String> splitMessage = Arrays.asList(deletedMessage.getContent().split("\\s+")); if (data.getModLogBlacklistWords().stream().anyMatch(splitMessage::contains)) { return; } } String message; if (data.getDeleteMessageLog() != null) { message = new DynamicModifiers() .set("hour", hour) .set("content", deletedMessage.getContent().replace("```", "")) .mapEvent("event", event) .mapChannel("event.channel", event.getChannel()) .mapUser("event.user", deletedMessage.getAuthor()) .set("event.message.id", event.getMessageId()) .resolve(data.getDeleteMessageLog()); } else { message = String.format(EmoteReference.WARNING + "`[%s]` Message (ID: %s) created by **%s#%s** (ID: %s) in channel **%s** was deleted.\n" + "```diff\n-%s```", hour, event.getMessageId(), deletedMessage.getAuthor().getName(), deletedMessage.getAuthor().getDiscriminator(), deletedMessage.getAuthor().getId(), event.getChannel().getName(), deletedMessage.getContent().replace("```", "")); } logTotal++; tc.sendMessage(message).queue(); } } } catch (Exception e) { if (!(e instanceof IllegalArgumentException) && !(e instanceof NullPointerException) && !(e instanceof CacheLoader.InvalidCacheLoadException) && !(e instanceof PermissionException)) { log.warn("Unexpected exception while logging a deleted message.", e); } } }
Example 10
Source File: MantaroListener.java From MantaroBot with GNU General Public License v3.0 | 4 votes |
private void logEdit(GuildMessageUpdateEvent event) { try { String hour = df.format(new Date(System.currentTimeMillis())); final ManagedDatabase db = MantaroData.db(); final GuildData guildData = db.getGuild(event.getGuild()).getData(); String logChannel = guildData.getGuildLogChannel(); if (logChannel != null) { TextChannel tc = event.getGuild().getTextChannelById(logChannel); if (tc == null) return; User author = event.getAuthor(); CachedMessage editedMessage = messageCache.get(event.getMessage().getIdLong(), Optional::empty).orElse(null); if (editedMessage != null && !editedMessage.getContent().isEmpty() && !event.getChannel().getId().equals(logChannel)) { //Update message in cache in any case. messageCache.put(event.getMessage().getIdLong(), Optional.of(new CachedMessage(event.getAuthor().getIdLong(), event.getMessage().getContentDisplay()))); if (guildData.getLogExcludedChannels().contains(event.getChannel().getId())) { return; } if (guildData.getModlogBlacklistedPeople().contains(editedMessage.getAuthor().getId())) { return; } //Don't log if content is equal but update in cache (cc: message is still relevant). if (event.getMessage().getContentDisplay().equals(editedMessage.getContent())) return; if (!guildData.getModLogBlacklistWords().isEmpty()) { //This is not efficient at all I'm pretty sure, is there a better way? List<String> splitMessage = Arrays.asList(editedMessage.getContent().split("\\s+")); if (guildData.getModLogBlacklistWords().stream().anyMatch(splitMessage::contains)) { return; } } String message; if (guildData.getEditMessageLog() != null) { message = new DynamicModifiers() .set("hour", hour) .set("old", editedMessage.getContent().replace("```", "")) .set("new", event.getMessage().getContentDisplay().replace("```", "")) .mapEvent("event", event) .mapChannel("event.channel", event.getChannel()) .mapUser("event.user", editedMessage.getAuthor()) .mapMessage("event.message", event.getMessage()) .resolve(guildData.getEditMessageLog()); } else { message = String.format(EmoteReference.WARNING + "`[%s]` Message (ID: %s) created by **%s#%s** in channel **%s** was modified.\n```diff\n-%s\n+%s```", hour, event.getMessage().getId(), author.getName(), author.getDiscriminator(), event.getChannel().getName(), editedMessage.getContent().replace("```", ""), event.getMessage().getContentDisplay().replace("```", "")); } tc.sendMessage(message).queue(); logTotal++; } } } catch (Exception e) { if (!(e instanceof NullPointerException) && !(e instanceof IllegalArgumentException) && !(e instanceof CacheLoader.InvalidCacheLoadException) && !(e instanceof PermissionException)) { log.warn("Unexpected error while logging a edit.", e); } } }