0.3.0 完成可以开发使用的库
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package com.synebula.gaea.app
|
||||
|
||||
import com.synebula.gaea.domain.service.ICommand
|
||||
import com.synebula.gaea.domain.service.IService
|
||||
import com.synebula.gaea.log.ILogger
|
||||
|
||||
/**
|
||||
* 指令服务,同时实现ICommandApp
|
||||
*
|
||||
* @param name 业务名称
|
||||
* @param service 业务domain服务
|
||||
* @param logger 日志组件
|
||||
*/
|
||||
open class CommandApp<TCommand : ICommand, TKey>(
|
||||
override var name: String,
|
||||
override var service: IService<TKey>?,
|
||||
override var logger: ILogger) : ICommandApp<TCommand, TKey> {
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.synebula.gaea.app
|
||||
|
||||
import com.synebula.gaea.app.components.HttpMessage
|
||||
import com.synebula.gaea.app.component.HttpMessage
|
||||
import com.synebula.gaea.data.message.Status
|
||||
import com.synebula.gaea.log.ILogger
|
||||
|
||||
@@ -24,12 +24,12 @@ interface IApplication {
|
||||
val msg = HttpMessage(Status.Success)
|
||||
try {
|
||||
process(msg)
|
||||
logger.debug("$name business execute success")
|
||||
logger.debug(this, "$name business execute success")
|
||||
} catch (ex: Exception) {
|
||||
msg.status = Status.Error
|
||||
msg.message = if (error.isEmpty()) ex.message ?: "" else error
|
||||
msg.data = ex.message
|
||||
logger.error(ex, "$error: ${ex.message}")
|
||||
logger.error(this, "$error: ${ex.message}")
|
||||
}
|
||||
return msg
|
||||
}
|
||||
@@ -41,9 +41,9 @@ interface IApplication {
|
||||
val msg = HttpMessage(Status.Success)
|
||||
try {
|
||||
process(msg)
|
||||
logger.debug("$name business execute success")
|
||||
logger.debug(this, "$name business execute success")
|
||||
} catch (ex: Exception) {
|
||||
logger.error(ex, "$error。异常消息将抛出!: ${ex.message}")
|
||||
logger.error(this, ex, "$error。异常消息将抛出!: ${ex.message}")
|
||||
throw RuntimeException(error, ex)
|
||||
}
|
||||
return msg
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.synebula.gaea.app
|
||||
|
||||
import com.synebula.gaea.app.components.HttpMessage
|
||||
import com.synebula.gaea.app.component.HttpMessage
|
||||
import com.synebula.gaea.data.message.Status
|
||||
import com.synebula.gaea.domain.service.ICommand
|
||||
import com.synebula.gaea.domain.service.IService
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.synebula.gaea.app
|
||||
|
||||
import com.synebula.gaea.app.components.HttpMessage
|
||||
import com.synebula.gaea.app.component.HttpMessage
|
||||
import com.synebula.gaea.data.message.Status
|
||||
import com.synebula.gaea.query.IQuery
|
||||
import com.synebula.gaea.query.PagingParam
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.synebula.gaea.app
|
||||
|
||||
import com.synebula.gaea.log.ILogger
|
||||
import com.synebula.gaea.query.IQuery
|
||||
|
||||
/**
|
||||
* 联合服务,同时实现了ICommandApp和IQueryApp接口
|
||||
*
|
||||
* @param name 业务名称
|
||||
* @param query 业务查询服务
|
||||
* @param logger 日志组件
|
||||
*/
|
||||
open class QueryApp<TView, TKey>(
|
||||
override var name: String,
|
||||
override var query: IQuery<TView, TKey>?,
|
||||
override var logger: ILogger) : IQueryApp<TView, TKey> {
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.synebula.gaea.app
|
||||
|
||||
import com.synebula.gaea.domain.service.ICommand
|
||||
import com.synebula.gaea.domain.service.IService
|
||||
import com.synebula.gaea.log.ILogger
|
||||
import com.synebula.gaea.query.IQuery
|
||||
|
||||
/**
|
||||
* 联合服务,同时实现了ICommandApp和IQueryApp接口
|
||||
*
|
||||
* @param name 业务名称
|
||||
* @param service 业务domain服务
|
||||
* @param query 业务查询服务
|
||||
* @param logger 日志组件
|
||||
*/
|
||||
open class UnionApp<TCommand : ICommand, TView, TKey>(
|
||||
override var name: String,
|
||||
override var service: IService<TKey>?,
|
||||
override var query: IQuery<TView, TKey>?,
|
||||
override var logger: ILogger)
|
||||
: ICommandApp<TCommand, TKey>, IQueryApp<TView, TKey> {
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.synebula.gaea.app.component
|
||||
|
||||
import org.springframework.core.type.classreading.MetadataReader
|
||||
import org.springframework.core.type.classreading.MetadataReaderFactory
|
||||
import org.springframework.core.type.filter.TypeFilter
|
||||
|
||||
class AllTypeFilter : TypeFilter {
|
||||
override fun match(metadataReader: MetadataReader, metadataReaderFactory: MetadataReaderFactory): Boolean {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.synebula.gaea.app.component
|
||||
|
||||
import com.synebula.gaea.data.IObjectConverter
|
||||
import org.dozer.DozerBeanMapper
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Component
|
||||
class DozerConverter : IObjectConverter {
|
||||
private val converter = DozerBeanMapper()
|
||||
|
||||
override fun <T> convert(src: Any, dest: Class<T>): T = converter.map(src, dest)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.synebula.gaea.app.components
|
||||
package com.synebula.gaea.app.component
|
||||
|
||||
import com.synebula.gaea.data.message.Status
|
||||
import com.synebula.gaea.data.message.Message
|
||||
@@ -0,0 +1,276 @@
|
||||
package com.synebula.gaea.app.component
|
||||
|
||||
import com.synebula.gaea.log.ILogger
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
/**
|
||||
* 使用 log4j進行日志记录。
|
||||
*
|
||||
* @author reize
|
||||
* @version 0.0.1
|
||||
* @since 2016年9月18日 下午2:13:43
|
||||
*/
|
||||
@Component
|
||||
class Logger : ILogger {
|
||||
|
||||
override val name: String
|
||||
get() {
|
||||
return this.logger.name
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认日志记录
|
||||
*/
|
||||
private val logger = LoggerFactory.getLogger(Logger::class.java)
|
||||
|
||||
/**
|
||||
* 特殊日志记录字典
|
||||
*/
|
||||
private val loggers = ConcurrentHashMap<Class<*>, org.slf4j.Logger>()
|
||||
|
||||
init {
|
||||
loggers[Logger::class.java] = logger
|
||||
}
|
||||
|
||||
override val isTraceEnabled: Boolean
|
||||
get() {
|
||||
return this.logger.isTraceEnabled
|
||||
}
|
||||
|
||||
|
||||
override fun trace(t: Throwable) {
|
||||
this.logger.trace(t.toString())
|
||||
}
|
||||
|
||||
|
||||
override fun trace(format: String, vararg args: Any) {
|
||||
if (this.logger.isTraceEnabled) {
|
||||
val message = String.format(format, *args)
|
||||
this.logger.trace(message)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun trace(t: Throwable, format: String, vararg args: Any) {
|
||||
if (this.logger.isTraceEnabled) {
|
||||
val message = String.format(format, *args)
|
||||
this.logger.trace(message, t)
|
||||
}
|
||||
}
|
||||
|
||||
override fun trace(obj: Any, format: String, vararg args: Any) {
|
||||
if (this.logger.isTraceEnabled) {
|
||||
val real = this.getLogger(obj)
|
||||
val message = String.format(format, *args)
|
||||
real.trace(message)
|
||||
}
|
||||
}
|
||||
|
||||
override fun trace(obj: Any, t: Throwable?, format: String, vararg args: Any) {
|
||||
if (this.logger.isTraceEnabled) {
|
||||
val real = this.getLogger(obj)
|
||||
val message = String.format(format, *args)
|
||||
real.trace(message, t)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* debug start
|
||||
*/
|
||||
override val isDebugEnabled: Boolean
|
||||
get() {
|
||||
return this.logger.isDebugEnabled
|
||||
}
|
||||
|
||||
|
||||
override fun debug(t: Throwable) {
|
||||
if (this.logger.isDebugEnabled) {
|
||||
this.logger.debug(t.toString())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun debug(format: String, vararg args: Any) {
|
||||
if (this.logger.isDebugEnabled) {
|
||||
val message = String.format(format, *args)
|
||||
this.logger.debug(message)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun debug(t: Throwable, format: String, vararg args: Any) {
|
||||
if (this.logger.isDebugEnabled) {
|
||||
val message = String.format(format, *args)
|
||||
this.logger.debug(message, t)
|
||||
}
|
||||
}
|
||||
|
||||
override fun debug(obj: Any, format: String, vararg args: Any) {
|
||||
if (this.logger.isDebugEnabled) {
|
||||
val real = this.getLogger(obj)
|
||||
val message = String.format(format, *args)
|
||||
real.debug(message)
|
||||
}
|
||||
}
|
||||
|
||||
override fun debug(obj: Any, t: Throwable?, format: String, vararg args: Any) {
|
||||
if (this.logger.isDebugEnabled) {
|
||||
val real = this.getLogger(obj)
|
||||
val message = String.format(format, *args)
|
||||
real.debug(message, t)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* info start
|
||||
*/
|
||||
override val isInfoEnabled: Boolean
|
||||
get() {
|
||||
return this.logger.isInfoEnabled
|
||||
}
|
||||
|
||||
override fun info(t: Throwable) {
|
||||
if (this.logger.isInfoEnabled) {
|
||||
this.logger.info(t.toString())
|
||||
}
|
||||
}
|
||||
|
||||
override fun info(format: String, vararg args: Any) {
|
||||
if (this.logger.isInfoEnabled) {
|
||||
val message = String.format(format, *args)
|
||||
this.logger.info(message)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun info(t: Throwable, format: String, vararg args: Any) {
|
||||
if (this.logger.isInfoEnabled) {
|
||||
val message = String.format(format, *args)
|
||||
this.logger.info(message, t)
|
||||
}
|
||||
}
|
||||
|
||||
override fun info(obj: Any, format: String, vararg args: Any) {
|
||||
if (this.logger.isInfoEnabled) {
|
||||
val real = this.getLogger(obj)
|
||||
val message = String.format(format, *args)
|
||||
real.info(message)
|
||||
}
|
||||
}
|
||||
|
||||
override fun info(obj: Any, t: Throwable?, format: String, vararg args: Any) {
|
||||
if (this.logger.isInfoEnabled) {
|
||||
val real = this.getLogger(obj)
|
||||
val message = String.format(format, *args)
|
||||
real.info(message, t)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* warn start
|
||||
*/
|
||||
override val isWarnEnabled: Boolean
|
||||
get() {
|
||||
return this.logger.isWarnEnabled
|
||||
}
|
||||
|
||||
override fun warn(t: Throwable) {
|
||||
if (this.logger.isWarnEnabled) {
|
||||
this.logger.warn(t.toString())
|
||||
}
|
||||
}
|
||||
|
||||
override fun warn(format: String, vararg args: Any) {
|
||||
if (this.logger.isWarnEnabled) {
|
||||
val message = String.format(format, *args)
|
||||
this.logger.warn(message)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun warn(t: Throwable, format: String, vararg args: Any) {
|
||||
if (this.logger.isWarnEnabled) {
|
||||
val message = String.format(format, *args)
|
||||
this.logger.warn(message, t)
|
||||
}
|
||||
}
|
||||
|
||||
override fun warn(obj: Any, format: String, vararg args: Any) {
|
||||
if (this.logger.isWarnEnabled) {
|
||||
val real = this.getLogger(obj)
|
||||
val message = String.format(format, *args)
|
||||
real.warn(message)
|
||||
}
|
||||
}
|
||||
|
||||
override fun warn(obj: Any, t: Throwable?, format: String, vararg args: Any) {
|
||||
if (this.logger.isWarnEnabled) {
|
||||
val real = this.getLogger(obj)
|
||||
val message = String.format(format, *args)
|
||||
real.warn(message, t)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* error start
|
||||
*/
|
||||
override val isErrorEnabled: Boolean
|
||||
get() {
|
||||
return this.logger.isErrorEnabled
|
||||
}
|
||||
|
||||
override fun error(t: Throwable) {
|
||||
if (this.logger.isErrorEnabled) {
|
||||
this.logger.error(t.toString())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun error(format: String, vararg args: Any) {
|
||||
if (this.logger.isErrorEnabled) {
|
||||
val message = String.format(format, *args)
|
||||
this.logger.error(message)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun error(t: Throwable, format: String, vararg args: Any) {
|
||||
if (this.logger.isErrorEnabled) {
|
||||
val message = String.format(format, *args)
|
||||
this.logger.error(message, t)
|
||||
}
|
||||
}
|
||||
|
||||
override fun error(obj: Any, format: String, vararg args: Any) {
|
||||
if (this.logger.isErrorEnabled) {
|
||||
val real = this.getLogger(obj)
|
||||
val message = String.format(format, *args)
|
||||
real.error(message)
|
||||
}
|
||||
}
|
||||
|
||||
override fun error(obj: Any, t: Throwable?, format: String, vararg args: Any) {
|
||||
if (this.logger.isErrorEnabled) {
|
||||
val real = this.getLogger(obj)
|
||||
val message = String.format(format, *args)
|
||||
real.error(message, t)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取日志记录器
|
||||
*/
|
||||
private fun getLogger(obj: Any): org.slf4j.Logger {
|
||||
var real = this.loggers.getOrDefault(obj.javaClass, null)
|
||||
if (real == null) {
|
||||
real = LoggerFactory.getLogger(obj::class.java)
|
||||
this.loggers[obj::class.java] = real
|
||||
}
|
||||
return real!!
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user