[go: nahoru, domu]

Skip to content

Commit

Permalink
server => 1.修改common包pom文件版本管理 2.添加Vessel管理所有依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
Joezeo committed Jul 31, 2021
1 parent c918d37 commit 7f3b8de
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 7 deletions.
28 changes: 21 additions & 7 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
<properties>
<java.version>1.8</java.version>

<fastjson.version>1.2.75</fastjson.version>
<commons.lang3.version>3.11</commons.lang3.version>
<guava.version>30.1-jre</guava.version>
<thirdpart.dependency.version>0.0.1-SNAPSHOT</thirdpart.dependency.version>
</properties>

<dependencies>

<!-- SpringBoot relative dependencies.-->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -50,25 +49,40 @@
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons.lang3.version}</version>
<scope>provided</scope>
</dependency>

<!-- common third part dependency, not exclude -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.12</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.toocol</groupId>
<artifactId>thirdpart-dependency</artifactId>
<version>${thirdpart.dependency.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<finalName>guitarchive.common.${version}</finalName>
</build>
Expand Down
18 changes: 18 additions & 0 deletions common/src/main/java/com/toocol/common/BasisInitAfter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.toocol.common;

import com.toocol.common.utils.SpringGetter;
import com.toocol.common.vessel.AbstractVessel;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
* @author Joezeo
* @date 2021/8/1 0:28
*/
@Component
public class BasisInitAfter implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
SpringGetter.getBean(AbstractVessel.class).ifPresent(AbstractVessel::init);
}
}
19 changes: 19 additions & 0 deletions common/src/main/java/com/toocol/common/akka/AkkaSystemConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.toocol.common.akka;

import akka.actor.ActorSystem;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* @author Joezeo
* @date 2021/8/1 0:26
*/
@Configuration
public class AkkaSystemConfig {

@Bean("actorSystem")
public ActorSystem actorSystem() {
return ActorSystem.apply("guitarchive-actor-system");
}

}
38 changes: 38 additions & 0 deletions common/src/main/java/com/toocol/common/vessel/AbstractVessel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.toocol.common.vessel;

import com.toocol.common.utils.SpringGetter;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* this abstract vessel is provided for product side.
*
* @author Joezeo
* @date 2021/7/31 23:41
*/
public abstract class AbstractVessel {

public void init() {
Class<?> superClass = this.getClass();
List<Field> fields = new ArrayList<>();
do {
fields.addAll(Arrays.asList(superClass.getDeclaredFields()));
superClass = superClass.getSuperclass();
} while (superClass != null);

fields.forEach(field -> {
try {
field.setAccessible(true);
field.set(this, SpringGetter.getBean(field.getType()).orElse(null));
} catch (IllegalAccessException e) {
e.printStackTrace();
System.out.println("inject field:" + field.getName() + " into vessel failed, stop the server.");
System.exit(-1);
}
});
}

}
18 changes: 18 additions & 0 deletions common/src/main/java/com/toocol/common/vessel/DefaultVessel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.toocol.common.vessel;

import akka.actor.ActorSystem;
import org.springframework.stereotype.Component;

/**
* every son server should has its own Vessel and annotated {@link org.springframework.context.annotation.Primary},
* if it doesnt, we just use this DefaultVessel
*
* @author Joezeo
* @date 2021/7/31 23:47
*/
@Component
public class DefaultVessel extends AbstractVessel{

public ActorSystem actorSystem;

}
19 changes: 19 additions & 0 deletions common/src/main/java/com/toocol/common/vessel/IBasisVessel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.toocol.common.vessel;

/**
* to put and manage the spring injected object.
* this interface is provided for the consume side.
*
* @author Joezeo
* @date 2021/7/31 23:39
*/
public interface IBasisVessel<T extends AbstractVessel> {

/**
* get the vessel object
*
* @return
*/
T vessel();

}
5 changes: 5 additions & 0 deletions parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.12</artifactId>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down
7 changes: 7 additions & 0 deletions thirdpart-dependency/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<selenium.version>4.0.0-beta-2</selenium.version>
<hutool.version>5.5.6</hutool.version>
<guava.version>30.1-jre</guava.version>
<akka.version>2.5.21</akka.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -51,6 +52,12 @@
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>

<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.12</artifactId>
<version>${akka.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>

0 comments on commit 7f3b8de

Please sign in to comment.