Skip to content

Commit 19411d6

Browse files
authored
Merge pull request #14 from zenuo/feature_remove_spring
remove spring
2 parents 0082c4a + a9ea295 commit 19411d6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+284
-253
lines changed

gogo-server/application.yml

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
# 全局配置
2-
---
3-
spring:
4-
application.name: gogo
5-
...
6-
71
# HTTP客户端设置
8-
---
92
http.client:
103
#最大连接数
114
maxTotal: 40
@@ -17,10 +10,8 @@ http.client:
1710
connectionRequestTimeout: 500
1811
#数据传输的最长时间
1912
socketTimeout: 500
20-
...
2113

2214
# Gogo配置
23-
---
2415
gogo:
2516
# 监听端口
2617
port: 4999
@@ -32,5 +23,4 @@ gogo:
3223
slogan: 欢迎<a href="https://github.com/zenuo/gogo">star</a>,蟹蟹支持🥳
3324
# 搜索结果替换规则
3425
substitute:
35-
- https://zh.wikipedia.org#https://176.122.157.73:3457
36-
...
26+
- https://zh.wikipedia.org#https://176.122.157.73:3457

gogo-server/pom.xml

+37-25
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,17 @@
66

77
<groupId>zenuo</groupId>
88
<artifactId>gogo</artifactId>
9-
<version>1.7.3</version>
9+
<version>1.7.4</version>
1010

1111
<packaging>jar</packaging>
1212

1313
<properties>
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1515
</properties>
1616

17-
<parent>
18-
<groupId>org.springframework.boot</groupId>
19-
<artifactId>spring-boot-starter-parent</artifactId>
20-
<version>2.2.4.RELEASE</version>
21-
</parent>
22-
2317
<build>
2418
<finalName>gogo</finalName>
2519
<plugins>
26-
<plugin>
27-
<groupId>org.springframework.boot</groupId>
28-
<artifactId>spring-boot-maven-plugin</artifactId>
29-
</plugin>
3020
<plugin>
3121
<groupId>org.apache.maven.plugins</groupId>
3222
<artifactId>maven-compiler-plugin</artifactId>
@@ -36,14 +26,31 @@
3626
<target>11</target>
3727
</configuration>
3828
</plugin>
29+
<plugin>
30+
<groupId>org.apache.maven.plugins</groupId>
31+
<artifactId>maven-shade-plugin</artifactId>
32+
<version>3.2.4</version>
33+
<executions>
34+
<execution>
35+
<phase>package</phase>
36+
<goals>
37+
<goal>shade</goal>
38+
</goals>
39+
<configuration>
40+
<transformers>
41+
<transformer
42+
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
43+
<mainClass>zenuo.gogo.GogoApplication</mainClass>
44+
</transformer>
45+
</transformers>
46+
</configuration>
47+
</execution>
48+
</executions>
49+
</plugin>
3950
</plugins>
4051
</build>
4152

4253
<dependencies>
43-
<dependency>
44-
<groupId>org.springframework.boot</groupId>
45-
<artifactId>spring-boot-starter</artifactId>
46-
</dependency>
4754
<dependency>
4855
<groupId>org.jsoup</groupId>
4956
<artifactId>jsoup</artifactId>
@@ -57,7 +64,7 @@
5764
<dependency>
5865
<groupId>com.fasterxml.jackson.core</groupId>
5966
<artifactId>jackson-databind</artifactId>
60-
<version>2.10.2</version>
67+
<version>2.11.1</version>
6168
</dependency>
6269
<dependency>
6370
<groupId>io.netty</groupId>
@@ -80,20 +87,25 @@
8087
<version>3.8.1</version>
8188
</dependency>
8289
<dependency>
83-
<groupId>org.springframework.boot</groupId>
84-
<artifactId>spring-boot-test</artifactId>
90+
<groupId>org.testng</groupId>
91+
<artifactId>testng</artifactId>
92+
<version>7.1.0</version>
8593
<scope>test</scope>
8694
</dependency>
8795
<dependency>
88-
<groupId>org.springframework</groupId>
89-
<artifactId>spring-test</artifactId>
90-
<scope>test</scope>
96+
<groupId>com.fasterxml.jackson.dataformat</groupId>
97+
<artifactId>jackson-dataformat-yaml</artifactId>
98+
<version>2.11.1</version>
9199
</dependency>
92100
<dependency>
93-
<groupId>org.testng</groupId>
94-
<artifactId>testng</artifactId>
95-
<version>7.1.0</version>
96-
<scope>test</scope>
101+
<groupId>org.apache.commons</groupId>
102+
<artifactId>commons-lang3</artifactId>
103+
<version>3.11</version>
104+
</dependency>
105+
<dependency>
106+
<groupId>commons-io</groupId>
107+
<artifactId>commons-io</artifactId>
108+
<version>2.7</version>
97109
</dependency>
98110

99111
<dependency>

gogo-server/src/main/java/zenuo/gogo/GogoApplication.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package zenuo.gogo;
22

3-
import org.springframework.boot.SpringApplication;
4-
import org.springframework.boot.autoconfigure.SpringBootApplication;
3+
import zenuo.gogo.core.Server;
54

65
import java.nio.file.Files;
76
import java.nio.file.Paths;
@@ -12,7 +11,6 @@
1211
* @author zenuo
1312
* 2018-06-02 19:12:15
1413
*/
15-
@SpringBootApplication
1614
public class GogoApplication {
1715
public static void main(String[] args) {
1816
//若当前目录存在配置文件
@@ -22,6 +20,6 @@ public static void main(String[] args) {
2220
System.setProperty("spring.config.location", "file:" + configFilePath);
2321
}
2422
//启动
25-
SpringApplication.run(GogoApplication.class, args);
23+
new Server();
2624
}
2725
}

gogo-server/src/main/java/zenuo/gogo/core/Handler.java

+8-10
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
import io.netty.handler.timeout.IdleState;
1212
import io.netty.handler.timeout.IdleStateEvent;
1313
import lombok.extern.slf4j.Slf4j;
14-
import org.springframework.stereotype.Component;
15-
import zenuo.gogo.core.processor.IProcessor;
14+
import zenuo.gogo.core.processor.IIndexProcessor;
15+
import zenuo.gogo.core.processor.ILintProcessor;
16+
import zenuo.gogo.core.processor.ISearchProcessor;
1617

1718
import java.net.URLDecoder;
1819
import java.nio.charset.StandardCharsets;
20+
import java.util.ServiceLoader;
1921
import java.util.concurrent.ArrayBlockingQueue;
2022
import java.util.concurrent.BlockingQueue;
2123
import java.util.concurrent.ThreadFactory;
@@ -27,24 +29,23 @@
2729
* 处理器类,通道读取事件的回调
2830
*/
2931
@Slf4j
30-
@Component
3132
@ChannelHandler.Sharable
3233
public final class Handler extends SimpleChannelInboundHandler<FullHttpRequest> {
3334

3435
/**
3536
* 首页处理器
3637
*/
37-
private final IProcessor indexProcessor;
38+
private final IIndexProcessor indexProcessor = ServiceLoader.load(IIndexProcessor.class).iterator().next();
3839

3940
/**
4041
* 搜索处理器
4142
*/
42-
private final IProcessor searchProcessor;
43+
private final ISearchProcessor searchProcessor = ServiceLoader.load(ISearchProcessor.class).iterator().next();
4344

4445
/**
4546
* 补全处理器
4647
*/
47-
private final IProcessor lintProcessor;
48+
private final ILintProcessor lintProcessor = ServiceLoader.load(ILintProcessor.class).iterator().next();
4849

4950
/**
5051
* 处理工作者线程池
@@ -56,10 +57,7 @@ public final class Handler extends SimpleChannelInboundHandler<FullHttpRequest>
5657
*/
5758
private final BlockingQueue<Runnable> workQueue;
5859

59-
public Handler(IProcessor indexProcessor, IProcessor searchProcessor, IProcessor lintProcessor) {
60-
this.indexProcessor = indexProcessor;
61-
this.searchProcessor = searchProcessor;
62-
this.lintProcessor = lintProcessor;
60+
public Handler() {
6361
this.workQueue = new ArrayBlockingQueue<>(256);
6462
this.processWorkers = new ThreadPoolExecutor(2, 8,
6563
30, TimeUnit.SECONDS,

gogo-server/src/main/java/zenuo/gogo/core/Server.java

+4-12
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,25 @@
1111
import io.netty.handler.logging.LogLevel;
1212
import io.netty.handler.logging.LoggingHandler;
1313
import io.netty.handler.stream.ChunkedWriteHandler;
14-
import lombok.NonNull;
15-
import lombok.RequiredArgsConstructor;
1614
import lombok.extern.slf4j.Slf4j;
17-
import org.springframework.stereotype.Component;
15+
import zenuo.gogo.core.config.ApplicationConfig;
1816
import zenuo.gogo.core.config.GogoConfig;
1917

20-
import javax.annotation.PostConstruct;
2118

2219
/**
2320
* 服务器
2421
*
2522
* @author zenuo
2623
* @date 2019/05/08
2724
*/
28-
@Component
2925
@Slf4j
30-
@RequiredArgsConstructor
3126
public final class Server {
3227

33-
@NonNull
34-
private final GogoConfig gogoConfig;
28+
private final GogoConfig gogoConfig = ApplicationConfig.gogoConfig();
3529

36-
@NonNull
37-
private final Handler handler;
30+
private final Handler handler = new Handler();
3831

39-
@PostConstruct
40-
private void postConstruct() {
32+
public Server() {
4133
//acceptor
4234
final NioEventLoopGroup boss = new NioEventLoopGroup(1);
4335
//client
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package zenuo.gogo.core.config;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
6+
import lombok.Getter;
7+
import lombok.Setter;
8+
import lombok.extern.slf4j.Slf4j;
9+
10+
import java.io.File;
11+
import java.io.IOException;
12+
13+
/**
14+
* application
15+
*
16+
* @author zenuo
17+
* @version 2020-07-25
18+
*/
19+
@Getter
20+
@Setter
21+
@Slf4j
22+
public class ApplicationConfig {
23+
24+
private static ApplicationConfig INSTANCE;
25+
26+
static {
27+
try {
28+
INSTANCE = new ObjectMapper(new YAMLFactory()).readValue(new File("./application.yml"), ApplicationConfig.class);
29+
} catch (IOException e) {
30+
log.error("loading config error", e);
31+
throw new RuntimeException(e);
32+
}
33+
INSTANCE.gogoConfig.postConstruct();
34+
}
35+
36+
public static void main(String[] args) {
37+
System.out.println(INSTANCE);
38+
}
39+
40+
public static HttpClientConfig httpClientConfig() {
41+
return INSTANCE.httpClientConfig;
42+
}
43+
44+
public static GogoConfig gogoConfig() {
45+
return INSTANCE.gogoConfig;
46+
}
47+
48+
@JsonProperty("http.client")
49+
private HttpClientConfig httpClientConfig;
50+
51+
@JsonProperty("gogo")
52+
private GogoConfig gogoConfig;
53+
}
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,25 @@
11
package zenuo.gogo.core.config;
22

33
import org.ehcache.Cache;
4-
import org.ehcache.CacheManager;
54
import org.ehcache.config.CacheConfiguration;
65
import org.ehcache.config.builders.CacheConfigurationBuilder;
76
import org.ehcache.config.builders.CacheManagerBuilder;
87
import org.ehcache.config.builders.ExpiryPolicyBuilder;
98
import org.ehcache.config.builders.ResourcePoolsBuilder;
109
import org.ehcache.config.units.MemoryUnit;
11-
import org.springframework.context.annotation.Bean;
12-
import org.springframework.stereotype.Component;
1310

1411
import java.time.Duration;
1512

16-
@Component
1713
public class EhcacheConfig {
18-
@Bean
19-
private CacheManager cacheManager() {
14+
public static Cache<String, String> get() {
2015
CacheConfiguration<String, String> config = CacheConfigurationBuilder.newCacheConfigurationBuilder(
2116
String.class, String.class,
2217
ResourcePoolsBuilder.newResourcePoolsBuilder().offheap(16L, MemoryUnit.MB))
2318
.withExpiry(ExpiryPolicyBuilder.timeToIdleExpiration(Duration.ofSeconds(Constants.SEARCH_RESPONSE_CACHE_TTL_IN_SECONDS)))
2419
.build();
2520
return CacheManagerBuilder.newCacheManagerBuilder()
2621
.withCache(Constants.SEARCH_RESULT_CACHE_ALIAS, config)
27-
.build(true);
28-
}
29-
30-
@Bean
31-
private Cache<String, String> cache(CacheManager cacheManager) {
32-
return cacheManager.getCache(Constants.SEARCH_RESULT_CACHE_ALIAS, String.class, String.class);
22+
.build(true)
23+
.getCache(Constants.SEARCH_RESULT_CACHE_ALIAS, String.class, String.class);
3324
}
3425
}

0 commit comments

Comments
 (0)