-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
server => 1.修改common包pom文件版本管理 2.添加Vessel管理所有依赖
- Loading branch information
Showing
8 changed files
with
145 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
common/src/main/java/com/toocol/common/BasisInitAfter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
common/src/main/java/com/toocol/common/akka/AkkaSystemConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
38
common/src/main/java/com/toocol/common/vessel/AbstractVessel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
common/src/main/java/com/toocol/common/vessel/DefaultVessel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
common/src/main/java/com/toocol/common/vessel/IBasisVessel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters