discord4j.store.jdk.JdkStoreService Java Examples
The following examples show how to use
discord4j.store.jdk.JdkStoreService.
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: GatewayBootstrap.java From Discord4J with GNU Lesser General Public License v3.0 | 6 votes |
private StoreService initStoreService(InvalidationStrategy invalidationStrategy) { if (storeService == null) { Map<Class<? extends StoreService>, Integer> priority = new HashMap<>(); // We want almost minimum priority, so that jdk can beat no-op, but most implementations will beat jdk priority.put(JdkStoreService.class, Integer.MAX_VALUE - 1); StoreServiceLoader storeServiceLoader = new StoreServiceLoader(priority); storeService = storeServiceLoader.getStoreService(); if (storeService instanceof ForwardingStoreService) { ForwardingStoreService forwarding = (ForwardingStoreService) storeService; StoreService delegate = forwarding.getOriginal(); if (!(delegate instanceof JdkStoreService)) { log.info("Found StoreService: {}", delegate); } } else { log.info("Found StoreService: {}", storeService); } } return invalidationStrategy.adaptStoreService(storeService.hasLongObjStores() ? storeService : new ForwardingStoreService(storeService)); }
Example #2
Source File: DisCalClient.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
/** * Creates the DisCal bot client. * * @return The client if successful, otherwise <code>null</code>. */ private static DiscordClient createClient() { DiscordClientBuilder clientBuilder = new DiscordClientBuilder(BotSettings.TOKEN.get()); //Handle shard count and index for multiple java instances clientBuilder.setShardIndex(Integer.valueOf(BotSettings.SHARD_INDEX.get())); clientBuilder.setShardCount(Integer.valueOf(BotSettings.SHARD_COUNT.get())); clientBuilder.setInitialPresence(Presence.online(Activity.playing("Booting Up!"))); //Redis info + store service for caching if (BotSettings.USE_REDIS_STORES.get().equalsIgnoreCase("true")) { RedisURI uri = RedisURI.Builder .redis(BotSettings.REDIS_HOSTNAME.get(), Integer.valueOf(BotSettings.REDIS_PORT.get())) .withPassword(BotSettings.REDIS_PASSWORD.get()) .build(); RedisStoreService rss = new RedisStoreService(RedisClient.create(uri)); MappingStoreService mss = MappingStoreService.create() .setMappings(rss, GuildBean.class, MessageBean.class) .setFallback(new JdkStoreService()); clientBuilder.setStoreService(mss); } else { clientBuilder.setStoreService(new JdkStoreService()); } return clientBuilder.build(); }
Example #3
Source File: ExampleStore.java From Discord4J with GNU Lesser General Public License v3.0 | 5 votes |
public static void main(String[] args) { JacksonResources jackson = JacksonResources.create(); Map<String, AtomicLong> counts = new ConcurrentHashMap<>(); DiscordClientBuilder.create(System.getenv("token")) .setJacksonResources(jackson) .build() .gateway() .setStoreService(MappingStoreService.create() .setMapping(new NoOpStoreService(), MessageData.class) .setFallback(new JdkStoreService())) .withGateway(gateway -> { log.info("Start!"); Mono<Void> server = startHttpServer(gateway, counts, jackson.getObjectMapper()).then(); Mono<Void> listener = gateway.on(GatewayLifecycleEvent.class) .filter(e -> !e.getClass().equals(ReadyEvent.class)) .doOnNext(e -> log.info("[shard={}] {}", e.getShardInfo().format(), e.toString())) .then(); Mono<Void> eventCounter = Flux.fromIterable(reflections.getSubTypesOf(Event.class)) .filter(cls -> reflections.getSubTypesOf(cls).isEmpty()) .flatMap(type -> gateway.on(type).doOnNext(event -> { String key = event.getClass().getSimpleName(); counts.computeIfAbsent(key, k -> new AtomicLong()).addAndGet(1); })) .then(); return Mono.when(server, listener, eventCounter); }) .block(); }
Example #4
Source File: DisCalClient.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 4 votes |
/** * Creates the DisCal bot client. * * @return The client if successful, otherwise <code>null</code>. */ private static DiscordClient createClient() { DiscordClientBuilder clientBuilder = new DiscordClientBuilder(BotSettings.TOKEN.get()); //Handle shard count and index for multiple java instances clientBuilder.setShardIndex(Integer.valueOf(BotSettings.SHARD_INDEX.get())); clientBuilder.setShardCount(Integer.valueOf(BotSettings.SHARD_COUNT.get())); clientBuilder.setInitialPresence(Presence.online(Activity.playing("Booting Up!"))); //Redis info + store service for caching if (BotSettings.USE_REDIS_STORES.get().equalsIgnoreCase("true")) { RedisURI uri = RedisURI.Builder .redis(BotSettings.REDIS_HOSTNAME.get(), Integer.valueOf(BotSettings.REDIS_PORT.get())) .withPassword(BotSettings.REDIS_PASSWORD.get()) .build(); RedisStoreService rss = new RedisStoreService(RedisClient.create(uri)); MappingStoreService mss = MappingStoreService.create() .setMappings(rss, GuildBean.class, MessageBean.class) .setFallback(new JdkStoreService()); clientBuilder.setStoreService(mss); } else { clientBuilder.setStoreService(new JdkStoreService()); } return clientBuilder.build(); }