<commit_before>package com.ecfront.ez.framework

import com.ecfront.common.{Req, Resp}
import com.ecfront.ez.framework.module.auth.AuthService
import com.ecfront.ez.framework.module.auth.manage.Initiator
import com.ecfront.ez.framework.module.core.CommonUtils
import com.ecfront.ez.framework.module.schedule.ScheduleService
import com.ecfront.ez.framework.rpc.RPC.EChannel
import com.ecfront.ez.framework.rpc.{RPC, Server}
import com.ecfront.ez.framework.service.protocols.{JDBCService, RedisService}
import com.typesafe.scalalogging.slf4j.LazyLogging

trait EZStartup extends App with LazyLogging {

  protected def moduleName: String

  protected def preStartup() = {}

  protected def postStartup() = {}

  protected def customShutdownHook() = {}

  protected def customPublicExecuteInterceptor(method: String, uri: String, parameters: Map[String, String], interceptorInfo: Map[String, String]): Resp[_] = null

  protected def customInnerExecuteInterceptor(method: String, uri: String, parameters: Map[String, String], interceptorInfo: Map[String, String]): Resp[_] = null

  private def startup(): Unit = {
    preStartup()
    RedisService.init()
    JDBCService.init()
    if (ConfigContainer.serversConfig.publicServer != null) {
      publicServer = RPC.server
        .setChannel(EChannel.HTTP)
        .setHost(ConfigContainer.serversConfig.publicServer.host)
        .setPort(ConfigContainer.serversConfig.publicServer.port)
        .setRootUploadPath(ConfigContainer.serversConfig.publicServer.resourcePath)
        .setPreExecuteInterceptor({
          (method, uri, parameters, interceptorInfo) =>
            if (!uri.startsWith(ConfigContainer.serversConfig.publicServer.publicUriPrefix)) {
              val customResult = customPublicExecuteInterceptor(method, uri, parameters, interceptorInfo)
              if (customResult == null) {
                //未使用自定义方法
                if (parameters.contains(CommonUtils.TOKEN)) {
                  AuthService.authorizationPublicServer(method, uri, parameters(CommonUtils.TOKEN))
                } else {
                  Resp.badRequest(s"Missing required field : [ ${CommonUtils.TOKEN} ].")
                }
              } else {
                customResult
              }
            } else {
              Resp.success(Req.anonymousReq)
            }
        }).startup().autoBuilding(ConfigContainer.serversConfig.publicServer.servicePath)
      if (ConfigContainer.serversConfig.publicServer.authManage) {
        Initiator.init()
        publicServer.autoBuilding("com.ecfront.ez.framework.module.auth")
      }
      logger.info(s"Public Server  started at ${ConfigContainer.serversConfig.publicServer.host} : ${ConfigContainer.serversConfig.publicServer.port}")
    }
    if (ConfigContainer.serversConfig.clusterServer != null) {
      innerServer = RPC.server
        .setChannel(EChannel.EVENT_BUS)
        .setHost(ConfigContainer.serversConfig.clusterServer.host)
        .setPreExecuteInterceptor({
          (method, uri, parameters, interceptorInfo) =>
            val customResult = customInnerExecuteInterceptor(method, uri, parameters, interceptorInfo)
            if (customResult == null) {
              //未使用自定义方法
              if (parameters.contains(CommonUtils.TOKEN)) {
                AuthService.authorizationInnerServer(method, uri, parameters(CommonUtils.TOKEN))
              } else {
                Resp.badRequest(s"Missing required field : [ ${CommonUtils.TOKEN} ].")
              }
            } else {
              customResult
            }
        })
        .startup().autoBuilding(ConfigContainer.serversConfig.clusterServer.servicePath)
      logger.info(s"Inner Server  started at ${ConfigContainer.serversConfig.clusterServer.host}")
    }
    ScheduleService.runByModuleName(moduleName)
    postStartup()
    logger.info("RPC Service started.")
  }

  private def shutdownHook(): Unit = {
    sys.addShutdownHook({
      ScheduleService.stop()
      RedisService.close()
      JDBCService.close()
      publicServer.shutdown()
      innerServer.shutdown()
      customShutdownHook()
      logger.info("RPC Service shutdown.")
    })
  }

  startup()
  shutdownHook()
<commit_msg>initialization<commit_after>package com.ecfront.ez.framework

import com.ecfront.common.{Req, Resp}
import com.ecfront.ez.framework.module.auth.AuthService
import com.ecfront.ez.framework.module.auth.manage.Initiator
import com.ecfront.ez.framework.module.core.CommonUtils
import com.ecfront.ez.framework.module.schedule.ScheduleService
import com.ecfront.ez.framework.rpc.RPC.EChannel
import com.ecfront.ez.framework.rpc.{RPC, Server}
import com.ecfront.ez.framework.service.protocols.{JDBCService, RedisService}
import com.typesafe.scalalogging.slf4j.LazyLogging

trait EZStartup extends App with LazyLogging {

  protected def moduleName: String

  protected def preStartup() = {}

  protected def postStartup() = {}

  protected def customShutdownHook() = {}

  protected def customPublicExecuteInterceptor(method: String, uri: String, parameters: Map[String, String], interceptorInfo: Map[String, String]): Resp[_] = null

  protected def customInnerExecuteInterceptor(method: String, uri: String, parameters: Map[String, String], interceptorInfo: Map[String, String]): Resp[_] = null

  private def startup(): Unit = {
    preStartup()
    RedisService.init()
    JDBCService.init()
    if (ConfigContainer.serversConfig.publicServer != null) {
      publicServer = RPC.server
        .setChannel(EChannel.HTTP)
        .setHost(ConfigContainer.serversConfig.publicServer.host)
        .setPort(ConfigContainer.serversConfig.publicServer.port)
        .setRootUploadPath(ConfigContainer.serversConfig.publicServer.resourcePath)
        .setPreExecuteInterceptor({
          (method, uri, parameters, interceptorInfo) =>
            if (!uri.startsWith(ConfigContainer.serversConfig.publicServer.publicUriPrefix)) {
              val customResult = customPublicExecuteInterceptor(method, uri, parameters, interceptorInfo)
              if (customResult == null) {
                //未使用自定义方法
                if (parameters.contains(CommonUtils.TOKEN)) {
                  AuthService.authorizationPublicServer(method, uri, parameters(CommonUtils.TOKEN))
                } else {
                  Resp.badRequest(s"Missing required field : [ ${CommonUtils.TOKEN} ].")
                }
              } else {
                customResult
              }
            } else {
              Resp.success(Req.anonymousReq)
            }
        }).startup().autoBuilding(ConfigContainer.serversConfig.publicServer.servicePath)
      if (ConfigContainer.serversConfig.publicServer.authManage) {
        Initiator.init()
        publicServer.autoBuilding("com.ecfront.ez.framework.module.auth")
      }
      logger.info(s"Public Server  started at ${ConfigContainer.serversConfig.publicServer.host} : ${ConfigContainer.serversConfig.publicServer.port}")
    }
    if (ConfigContainer.serversConfig.clusterServer != null) {
      innerServer = RPC.server
        .setChannel(EChannel.EVENT_BUS)
        .setHost(ConfigContainer.serversConfig.clusterServer.host)
        .setPreExecuteInterceptor({
          (method, uri, parameters, interceptorInfo) =>
            val customResult = customInnerExecuteInterceptor(method, uri, parameters, interceptorInfo)
            if (customResult == null) {
              //未使用自定义方法
              if (parameters.contains(CommonUtils.TOKEN)) {
                AuthService.authorizationInnerServer(method, uri, parameters(CommonUtils.TOKEN))
              } else {
                Resp.badRequest(s"Missing required field : [ ${CommonUtils.TOKEN} ].")
              }
            } else {
              customResult
            }
        })
        .startup().autoBuilding(ConfigContainer.serversConfig.clusterServer.servicePath)
      logger.info(s"Inner Server  started at ${ConfigContainer.serversConfig.clusterServer.host}")
    }
    ScheduleService.runByModuleName(moduleName)
    postStartup()
    logger.info("EZ-Framework started.")
  }

  private def shutdownHook(): Unit = {
    sys.addShutdownHook({
      ScheduleService.stop()
      RedisService.close()
      JDBCService.close()
      publicServer.shutdown()
      innerServer.shutdown()
      customShutdownHook()
      logger.info("EZ-Framework shutdown.")
    })
  }

  startup()
  shutdownHook()

{'fraction_non_alphanumeric': 0.10406000714370758, 'fraction_numerical': 0.0002381235861412073, 'mean_word_length': 2.975390440132513, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5523512', 'n_tokens_mistral': 2304, 'n_tokens_neox': 2275, 'n_words': 376}