Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Commit

Permalink
Dependency and code clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzonthemtn committed Mar 21, 2024
1 parent be4544e commit b3698dd
Show file tree
Hide file tree
Showing 20 changed files with 330 additions and 482 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,6 @@
*/
package ai.philterd.entitydb;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

import org.aeonbits.owner.ConfigFactory;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.cache.CacheManager;
import org.springframework.cache.concurrent.ConcurrentMapCache;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.GsonHttpMessageConverter;
import ai.philterd.entitydb.audit.FileAuditLogger;
import ai.philterd.entitydb.audit.FluentdAuditLogger;
import ai.philterd.entitydb.caching.memcached.MemcachedCache;
Expand All @@ -66,6 +37,8 @@
import ai.philterd.entitydb.model.metrics.MetricReporter;
import ai.philterd.entitydb.model.queue.QueueConsumer;
import ai.philterd.entitydb.model.queue.QueuePublisher;
import ai.philterd.entitydb.model.rulesengine.RulesEngine;
import ai.philterd.entitydb.model.rulesengine.RulesEngineException;
import ai.philterd.entitydb.model.search.IndexedEntity;
import ai.philterd.entitydb.model.search.Indexer;
import ai.philterd.entitydb.model.search.SearchIndex;
Expand All @@ -80,13 +53,38 @@
import ai.philterd.entitydb.search.ElasticSearchIndex;
import ai.philterd.entitydb.search.EmbeddedElasticsearchServer;
import ai.philterd.entitydb.search.indexer.ElasticSearchIndexer;

import net.spy.memcached.AddrUtil;
import net.spy.memcached.ConnectionFactoryBuilder;
import net.spy.memcached.MemcachedClient;
import org.aeonbits.owner.ConfigFactory;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cache.CacheManager;
import org.springframework.cache.concurrent.ConcurrentMapCache;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.GsonHttpMessageConverter;

import ai.philterd.entitydb.model.rulesengine.RulesEngine;
import ai.philterd.entitydb.model.rulesengine.RulesEngineException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

// Auto-configuration for MongoDB: http://stackoverflow.com/a/34415014/1428388
// Auto-configuration for Jackson: http://www.leveluplunch.com/java/tutorials/023-configure-integrate-gson-spring-boot/
Expand All @@ -101,7 +99,7 @@
@SpringBootApplication(exclude = { JacksonAutoConfiguration.class, MongoAutoConfiguration.class, MongoDataAutoConfiguration.class })
@PropertySource(value = {"file:entitydb.properties"}, ignoreResourceNotFound = false)
@Configuration
public class EntityDbApplication extends SpringBootServletInitializer {
public class EntityDbApplication extends SpringBootServletInitializer {

private static final Logger LOGGER = LogManager.getLogger(EntityDbApplication.class);

Expand Down Expand Up @@ -268,7 +266,7 @@ public SearchIndex getSearchIndex() {

if(StringUtils.equalsIgnoreCase(EntityDbProperties.INTERNAL, properties.getSearchIndexProvider())) {

EmbeddedElasticsearchServer embeddedElasticsearchServer = new EmbeddedElasticsearchServer();
final EmbeddedElasticsearchServer embeddedElasticsearchServer = new EmbeddedElasticsearchServer();
embeddedElasticsearchServer.start();

LOGGER.warn("Using the internal search index is not recommended for production systems.");
Expand Down Expand Up @@ -389,10 +387,10 @@ public QueuePublisher getQueuePublisher() {

@Bean
public QueueConsumer getQueueConsumer() {

QueueConsumer queueConsumer = null;
String queue = properties.getQueueProvider();

final String queue = properties.getQueueProvider();

if(StringUtils.equalsIgnoreCase(EntityDbProperties.SQS, queue)) {

Expand Down Expand Up @@ -429,11 +427,11 @@ public QueueConsumer getQueueConsumer() {
queueConsumer = new InternalQueueConsumer(getEntityStore(), getRulesEngines(), getAuditLogger(), getMetricReporter(), getIndexerCache());

} else {

LOGGER.warn("Invalid queue {}. Using the internal queue.", queue);

queueConsumer = new InternalQueueConsumer(getEntityStore(), getRulesEngines(), getAuditLogger(), getMetricReporter(), getIndexerCache());

}

return queueConsumer;
Expand All @@ -442,7 +440,6 @@ public QueueConsumer getQueueConsumer() {

@Bean
public MetricReporter getMetricReporter() {


if(StringUtils.equalsIgnoreCase(EntityDbProperties.INFLUXDB, properties.getMetricsProvider())) {

Expand Down Expand Up @@ -486,16 +483,16 @@ public HttpMessageConverters customConverters() {
@Bean
public ConcurrentLinkedQueue<IndexedEntity> getIndexerCache() {

return new ConcurrentLinkedQueue<IndexedEntity>();
return new ConcurrentLinkedQueue<>();

}
@Bean(destroyMethod="shutdown")

@Bean
public CacheManager cacheManager() {

LOGGER.info("Creating cache manager.");
List<String> cacheNames = new LinkedList<String>();

final List<String> cacheNames = new LinkedList<>();

cacheNames.add("nonExpiredContinuousQueries");
cacheNames.add("continuousQueriesByUser");
Expand All @@ -507,8 +504,8 @@ public CacheManager cacheManager() {
if(StringUtils.equalsIgnoreCase(properties.getCache(), "memcached")) {

try {
MemcachedClient memcachedClient = new MemcachedClient(

final MemcachedClient memcachedClient = new MemcachedClient(
new ConnectionFactoryBuilder()
.setProtocol(ConnectionFactoryBuilder.Protocol.BINARY)
.build(),
Expand All @@ -518,10 +515,8 @@ public CacheManager cacheManager() {

final Collection<MemcachedCache> caches = new ArrayList<MemcachedCache>();

for(String cacheName : cacheNames) {

for(final String cacheName : cacheNames) {
caches.add(new MemcachedCache(memcachedClient, cacheName, properties.getCacheTtl()));

}

return new MemcachedCacheManager(caches);
Expand All @@ -536,14 +531,12 @@ public CacheManager cacheManager() {

LOGGER.info("Using internal cache.");

SimpleCacheManager simpleCacheManager = new SimpleCacheManager();
List<ConcurrentMapCache> caches = new LinkedList<ConcurrentMapCache>();
final SimpleCacheManager simpleCacheManager = new SimpleCacheManager();

final List<ConcurrentMapCache> caches = new LinkedList<>();

for(String cacheName : cacheNames) {

caches.add(new ConcurrentMapCache(cacheName));

}

simpleCacheManager.setCaches(caches);
Expand Down
7 changes: 1 addition & 6 deletions entitydb-caching/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@
<artifactId>commons-io</artifactId>
<version>${commons.io.version}</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>${ehcache.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
Expand Down Expand Up @@ -80,7 +75,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${log4j.version}</version>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public class MemcachedCache implements Cache {

private static final Logger LOGGER = LogManager.getLogger(MemcachedCache.class);

private String name;
private MemcachedClient client;
private int ttl;
private final String name;
private final MemcachedClient client;
private final int ttl;

/**
* Creates a new implementation of {@link Cache} for memcached.
Expand Down
Loading

0 comments on commit b3698dd

Please sign in to comment.