mirror of
https://gitee.com/BTAJL/repchain.git
synced 2024-12-05 21:28:05 +08:00
重构提交8
This commit is contained in:
parent
b1e8bb7ec4
commit
061865d8c6
@ -16,10 +16,10 @@
|
|||||||
|
|
||||||
package rep.network.module
|
package rep.network.module
|
||||||
|
|
||||||
import akka.actor.{ActorRef, Props}
|
import akka.actor.{ ActorRef, Props }
|
||||||
import com.typesafe.config.{Config}
|
import com.typesafe.config.{ Config }
|
||||||
import rep.app.conf.SystemProfile.Trans_Create_Type_Enum
|
import rep.app.conf.SystemProfile.Trans_Create_Type_Enum
|
||||||
import rep.app.conf.{SystemProfile, TimePolicy}
|
import rep.app.conf.{ SystemProfile, TimePolicy }
|
||||||
import rep.network.PeerHelper
|
import rep.network.PeerHelper
|
||||||
import rep.network.base.ModuleBase
|
import rep.network.base.ModuleBase
|
||||||
import rep.network.cache.TransactionPool
|
import rep.network.cache.TransactionPool
|
||||||
@ -27,9 +27,9 @@ import rep.network.persistence.Storager
|
|||||||
import rep.network.tools.Statistic.StatisticCollection
|
import rep.network.tools.Statistic.StatisticCollection
|
||||||
import rep.ui.web.EventServer
|
import rep.ui.web.EventServer
|
||||||
import rep.network.cluster.MemberListener
|
import rep.network.cluster.MemberListener
|
||||||
import rep.network.sync.{SynchronizeResponser,SynchronizeRequester}
|
import rep.network.sync.{ SynchronizeResponser, SynchronizeRequester }
|
||||||
|
|
||||||
import rep.network.consensus.block.{GenesisBlocker,ConfirmOfBlock,EndorseCollector,Blocker}
|
import rep.network.consensus.block.{ GenesisBlocker, ConfirmOfBlock, EndorseCollector, Blocker }
|
||||||
import rep.network.consensus.endorse.Endorser
|
import rep.network.consensus.endorse.Endorser
|
||||||
import rep.network.consensus.transaction.PreloaderForTransaction
|
import rep.network.consensus.transaction.PreloaderForTransaction
|
||||||
import rep.network.consensus.vote.Voter
|
import rep.network.consensus.vote.Voter
|
||||||
@ -42,20 +42,19 @@ import rep.log.trace.LogType
|
|||||||
import rep.crypto.cert.SignTool
|
import rep.crypto.cert.SignTool
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by shidianyue on 2017/9/22.
|
* Created by shidianyue on 2017/9/22.
|
||||||
*/
|
*/
|
||||||
object ModuleManager {
|
object ModuleManager {
|
||||||
def props(name: String, sysTag: String,enableStatistic:Boolean,enableWebSocket:Boolean,isStartup:Boolean): Props = Props(classOf[ ModuleManager ], name, sysTag,enableStatistic:Boolean,enableWebSocket:Boolean,isStartup:Boolean)
|
def props(name: String, sysTag: String, enableStatistic: Boolean, enableWebSocket: Boolean, isStartup: Boolean): Props = Props(classOf[ModuleManager], name, sysTag, enableStatistic: Boolean, enableWebSocket: Boolean, isStartup: Boolean)
|
||||||
}
|
}
|
||||||
|
|
||||||
class ModuleManager(moduleName: String, sysTag: String,enableStatistic:Boolean,enableWebSocket:Boolean,isStartup:Boolean) extends ModuleBase(moduleName) {
|
class ModuleManager(moduleName: String, sysTag: String, enableStatistic: Boolean, enableWebSocket: Boolean, isStartup: Boolean) extends ModuleBase(moduleName) {
|
||||||
|
|
||||||
private val conf = context.system.settings.config
|
private val conf = context.system.settings.config
|
||||||
|
|
||||||
init()
|
init()
|
||||||
loadModule
|
loadModule
|
||||||
|
|
||||||
|
|
||||||
def init(): Unit = {
|
def init(): Unit = {
|
||||||
val (ip, port) = ActorUtils.getIpAndPort(selfAddr)
|
val (ip, port) = ActorUtils.getIpAndPort(selfAddr)
|
||||||
pe.setIpAndPort(ip, port)
|
pe.setIpAndPort(ip, port)
|
||||||
@ -64,54 +63,51 @@ class ModuleManager(moduleName: String, sysTag: String,enableStatistic:Boolean,e
|
|||||||
confHeler.init()
|
confHeler.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def loadModule = {
|
def loadModule = {
|
||||||
loadClusterModule
|
loadClusterModule
|
||||||
loadApiModule
|
loadApiModule
|
||||||
loadSystemModule
|
loadSystemModule
|
||||||
loadConsensusModule
|
loadConsensusModule
|
||||||
|
|
||||||
if(isStartup){
|
if (isStartup) {
|
||||||
pe.getActorRef(ActorType.voter) ! Voter.VoteOfBlocker
|
pe.getActorRef(ActorType.voter) ! Voter.VoteOfBlocker
|
||||||
}
|
}
|
||||||
|
|
||||||
logMsg(LogType.INFO, moduleName+"~"+ s"ModuleManager ${sysTag} start")
|
logMsg(LogType.INFO, moduleName + "~" + s"ModuleManager ${sysTag} start")
|
||||||
}
|
}
|
||||||
|
|
||||||
def loadConsensusModule={
|
def loadConsensusModule = {
|
||||||
val typeConsensus = context.system.settings.config.getString("system.consensus.type")
|
val typeConsensus = context.system.settings.config.getString("system.consensus.type")
|
||||||
if(typeConsensus == "CRFD"){
|
if (typeConsensus == "CRFD") {
|
||||||
context.actorOf(Blocker.props("blocker"), "blocker")
|
context.actorOf(Blocker.props("blocker"), "blocker")
|
||||||
context.actorOf(GenesisBlocker.props("gensisblock"), "gensisblock")
|
context.actorOf(GenesisBlocker.props("gensisblock"), "gensisblock")
|
||||||
context.actorOf(ConfirmOfBlock.props("confirmerofblock"), "confirmerofblock")
|
context.actorOf(ConfirmOfBlock.props("confirmerofblock"), "confirmerofblock")
|
||||||
context.actorOf(EndorseCollector.props("endorsementcollectioner"), "endorsementcollectioner")
|
context.actorOf(EndorseCollector.props("endorsementcollectioner"), "endorsementcollectioner")
|
||||||
context.actorOf(Endorser.props("endorser"), "endorser")
|
context.actorOf(Endorser.props("endorser"), "endorser")
|
||||||
context.actorOf(PreloaderForTransaction.props("preloaderoftransaction",context.actorOf(TransProcessor.props("sandbox", "", self),"sandboxProcessor")),"preloaderoftransaction")
|
context.actorOf(PreloaderForTransaction.props("preloaderoftransaction", context.actorOf(TransProcessor.props("sandbox", "", self), "sandboxProcessor")), "preloaderoftransaction")
|
||||||
context.actorOf(Endorser.props("endorser"), "endorser")
|
//context.actorOf(Endorser.props("endorser"), "endorser")
|
||||||
context.actorOf(Voter.props("voter"), "voter")
|
context.actorOf(Voter.props("voter"), "voter")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def loadApiModule={
|
def loadApiModule = {
|
||||||
if(enableStatistic) context.actorOf(Props[StatisticCollection],"statistic")
|
if (enableStatistic) context.actorOf(Props[StatisticCollection], "statistic")
|
||||||
if (enableWebSocket) context.actorOf(Props[ EventServer ], "webapi")
|
if (enableWebSocket) context.actorOf(Props[EventServer], "webapi")
|
||||||
}
|
}
|
||||||
|
|
||||||
def loadSystemModule={
|
def loadSystemModule = {
|
||||||
context.actorOf(Storager.props("storager"), "storager")
|
context.actorOf(Storager.props("storager"), "storager")
|
||||||
context.actorOf(SynchronizeRequester.props("synchrequester"), "synchrequester")
|
context.actorOf(SynchronizeRequester.props("synchrequester"), "synchrequester")
|
||||||
context.actorOf(SynchronizeResponser.props("synchresponser"), "synchresponser")
|
context.actorOf(SynchronizeResponser.props("synchresponser"), "synchresponser")
|
||||||
context.actorOf(TransactionPool.props("transactionpool"), "transactionpool")
|
context.actorOf(TransactionPool.props("transactionpool"), "transactionpool")
|
||||||
if(SystemProfile.getTransCreateType==Trans_Create_Type_Enum.AUTO){
|
if (SystemProfile.getTransCreateType == Trans_Create_Type_Enum.AUTO) {
|
||||||
context.actorOf(PeerHelper.props("peerhelper"), "peerhelper")
|
context.actorOf(PeerHelper.props("peerhelper"), "peerhelper")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def loadClusterModule={
|
|
||||||
context.actorOf( MemberListener.props("memberlistener"), "memberlistener")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
def loadClusterModule = {
|
||||||
|
context.actorOf(MemberListener.props("memberlistener"), "memberlistener")
|
||||||
|
}
|
||||||
|
|
||||||
//除了广播消息,P2P的跨域消息都通过其中转(同步,存储等)
|
//除了广播消息,P2P的跨域消息都通过其中转(同步,存储等)
|
||||||
override def receive: Receive = {
|
override def receive: Receive = {
|
||||||
@ -119,7 +115,6 @@ class ModuleManager(moduleName: String, sysTag: String,enableStatistic:Boolean,e
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ConfigerHelper(conf: Config, tag: String, dbTag: String) {
|
class ConfigerHelper(conf: Config, tag: String, dbTag: String) {
|
||||||
|
|
||||||
def init(): Unit = {
|
def init(): Unit = {
|
||||||
@ -130,13 +125,13 @@ class ConfigerHelper(conf: Config, tag: String, dbTag: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Authorization module init
|
* Authorization module init
|
||||||
*
|
*
|
||||||
* @param jksFilePath
|
* @param jksFilePath
|
||||||
* @param pwd
|
* @param pwd
|
||||||
* @param trustJksFilePath
|
* @param trustJksFilePath
|
||||||
* @param trustPwd
|
* @param trustPwd
|
||||||
*/
|
*/
|
||||||
private def authInit(sysTag: String, jksFilePath: String, pwd: String, trustJksFilePath: String, trustPwd: String): Unit = {
|
private def authInit(sysTag: String, jksFilePath: String, pwd: String, trustJksFilePath: String, trustPwd: String): Unit = {
|
||||||
//init the ECDSA param
|
//init the ECDSA param
|
||||||
SignTool.loadPrivateKey(sysTag, pwd, jksFilePath)
|
SignTool.loadPrivateKey(sysTag, pwd, jksFilePath)
|
||||||
@ -146,8 +141,8 @@ class ConfigerHelper(conf: Config, tag: String, dbTag: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据配置初始化本地安全配置
|
* 根据配置初始化本地安全配置
|
||||||
*/
|
*/
|
||||||
private def authInitByCfg(sysTag: String): Unit = {
|
private def authInitByCfg(sysTag: String): Unit = {
|
||||||
val mykeyPath = conf.getString("akka.remote.netty.ssl.security.base-path") + sysTag + ".jks"
|
val mykeyPath = conf.getString("akka.remote.netty.ssl.security.base-path") + sysTag + ".jks"
|
||||||
val psw = conf.getString("akka.remote.netty.ssl.security.key-store-password")
|
val psw = conf.getString("akka.remote.netty.ssl.security.key-store-password")
|
||||||
@ -157,29 +152,29 @@ class ConfigerHelper(conf: Config, tag: String, dbTag: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化DB信息
|
* 初始化DB信息
|
||||||
*
|
*
|
||||||
* @param dbTag
|
* @param dbTag
|
||||||
*/
|
*/
|
||||||
private def dbInit(dbTag: String): Unit = {
|
private def dbInit(dbTag: String): Unit = {
|
||||||
ImpDataAccess.GetDataAccess(dbTag)
|
ImpDataAccess.GetDataAccess(dbTag)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化系统相关配置
|
* 初始化系统相关配置
|
||||||
*
|
*
|
||||||
* @param config
|
* @param config
|
||||||
*/
|
*/
|
||||||
private def sysInit(config: Config): Unit = {
|
private def sysInit(config: Config): Unit = {
|
||||||
SystemProfile.initConfigSystem(config)
|
SystemProfile.initConfigSystem(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化时间策略配置
|
* 初始化时间策略配置
|
||||||
*
|
*
|
||||||
* @param config
|
* @param config
|
||||||
*/
|
*/
|
||||||
private def timePolicyInit(config: Config): Unit = {
|
private def timePolicyInit(config: Config): Unit = {
|
||||||
TimePolicy.initTimePolicy(config)
|
TimePolicy.initTimePolicy(config)
|
||||||
}
|
}
|
||||||
|
@ -73,12 +73,12 @@ object GlobalUtils {
|
|||||||
val synchrequester = 9
|
val synchrequester = 9
|
||||||
val transactionpool = 10
|
val transactionpool = 10
|
||||||
val storager = 11
|
val storager = 11
|
||||||
|
val synchresponser = 12
|
||||||
val statiscollecter = 13
|
val statiscollecter = 13
|
||||||
val endorsementcollectioner = 14
|
val endorsementcollectioner = 14
|
||||||
val endorsementrequester = 15
|
val endorsementrequester = 15
|
||||||
val confirmerofblock = 16
|
val confirmerofblock = 16
|
||||||
val gensisblock = 17
|
val gensisblock = 17
|
||||||
val synchresponser = 18
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user