Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
fuyue82
o2oa
提交
57215c57
o2oa
项目概览
fuyue82
/
o2oa
与 Fork 源项目一致
Fork自
浙江兰德纵横网络技术股份有限公司 / o2oa
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
o2oa
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
57215c57
编写于
10月 18, 2021
作者:
O
o2null
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
退出时关闭druid DataSource
上级
51473ad1
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
59 addition
and
27 deletion
+59
-27
o2server/x_console/src/main/java/com/x/server/console/Main.java
...er/x_console/src/main/java/com/x/server/console/Main.java
+3
-1
o2server/x_console/src/main/java/com/x/server/console/ResourceFactory.java
...e/src/main/java/com/x/server/console/ResourceFactory.java
+56
-26
未找到文件。
o2server/x_console/src/main/java/com/x/server/console/Main.java
浏览文件 @
57215c57
...
...
@@ -117,7 +117,7 @@ public class Main {
cleanTempDir
(
base
);
createTempClassesDirectory
(
base
);
Log4j2Configuration
.
reconfigure
();
ResourceFactory
.
bind
();
ResourceFactory
.
init
();
CommandFactory
.
printStartHelp
();
// 初始化hadoop环境
Hadoop
.
init
();
...
...
@@ -433,7 +433,9 @@ public class Main {
private
static
void
exit
()
{
stopAll
();
ResourceFactory
.
destory
();
System
.
exit
(
0
);
}
private
static
void
restart
()
{
...
...
o2server/x_console/src/main/java/com/x/server/console/ResourceFactory.java
浏览文件 @
57215c57
...
...
@@ -14,8 +14,9 @@ import java.util.Properties;
import
java.util.TreeMap
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
import
javax.naming.NamingException
;
...
...
@@ -50,23 +51,33 @@ import io.github.classgraph.ClassGraph;
import
io.github.classgraph.ClassInfo
;
import
io.github.classgraph.ScanResult
;
/**
*
* @author ray
*
*/
public
class
ResourceFactory
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ResourceFactory
.
class
);
private
static
final
int
TOKENTHRESHOLDSMAXSIZE
=
2000
;
/**
* 用于销毁时的对象
*/
private
static
List
<
DruidDataSourceC3P0Adapter
>
dataSources
=
new
ArrayList
<>();
private
ResourceFactory
()
{
// nothing
}
public
static
void
bind
()
throws
Exception
{
public
static
void
init
()
throws
Exception
{
ClassLoader
cl
=
ClassLoaderTools
.
urlClassLoader
(
true
,
false
,
true
,
true
,
true
,
unzipCustomWar
());
try
(
ScanResult
sr
=
new
ClassGraph
().
addClassLoader
(
cl
).
enableAnnotationInfo
().
scan
())
{
node
(
cl
,
sr
);
node
();
containerEntities
(
cl
,
sr
);
containerEntityNames
(
cl
,
sr
);
stroageContainerEntityNames
(
cl
,
sr
);
containerEntityNames
(
sr
);
stroageContainerEntityNames
(
sr
);
}
if
(
BooleanUtils
.
isTrue
(
Config
.
externalDataSources
().
enable
()))
{
external
();
...
...
@@ -77,12 +88,21 @@ public class ResourceFactory {
tokenThresholds
();
}
/**
* 需要将custom模块中的entity加入到扫描目录中, <br/>
* 所以需要对custom中的web-inf/classes目录下的实体类进行扫描<br/>
* 先把war解压到临时目录然后读取classes目录下的类
*
* @return
* @throws Exception
*/
private
static
Path
[]
unzipCustomWar
()
throws
Exception
{
FileUtils
.
cleanDirectory
(
Config
.
dir_local_temp_custom
(
true
));
List
<
String
>
list
=
new
ArrayList
<>();
File
dir
=
Config
.
dir_custom
(
true
);
if
(
null
!=
dir
)
{
for
(
String
str
:
dir
.
list
(
new
WildcardFileFilter
(
"*"
+
PathTools
.
DOT_WAR
)))
{
String
[]
wars
=
dir
.
list
(
new
WildcardFileFilter
(
"*"
+
PathTools
.
DOT_WAR
));
if
(
null
!=
wars
)
{
for
(
String
str
:
wars
)
{
list
.
add
(
FilenameUtils
.
getBaseName
(
str
));
}
}
...
...
@@ -97,20 +117,20 @@ public class ResourceFactory {
return
paths
.
toArray
(
new
Path
[
paths
.
size
()]);
}
private
static
void
node
(
ClassLoader
classLoader
,
ScanResult
sr
)
throws
Exception
{
private
static
void
node
()
throws
Exception
{
LinkedBlockingQueue
<
JsonElement
>
eventQueue
=
new
LinkedBlockingQueue
<>();
EventQueueExecutor
eventQueueExecutor
=
new
EventQueueExecutor
(
eventQueue
);
eventQueueExecutor
.
start
();
new
Resource
(
Config
.
RESOURCE_NODE_EVENTQUEUE
,
eventQueue
);
new
Resource
(
Config
.
RESOURCE_NODE_EVENTQUEUEEXECUTOR
,
eventQueueExecutor
);
new
Resource
(
Config
.
RESOURCE_NODE_APPLICATIONS
,
new
ConcurrentHashMap
<
String
,
Object
>());
new
Resource
(
Config
.
RESOURCE_NODE_APPLICATIONS
,
new
ConcurrentHashMap
<
String
,
Object
>(
10
));
Entry
<
String
,
CenterServer
>
entry
=
Config
.
nodes
().
centerServers
().
first
();
Config
.
resource_node_centersPirmaryNode
(
entry
.
getKey
());
Config
.
resource_node_centersPirmaryPort
(
entry
.
getValue
().
getPort
());
Config
.
resource_node_centersPirmarySslEnable
(
entry
.
getValue
().
getSslEnable
());
}
private
static
void
containerEntityNames
(
ClassLoader
classLoader
,
ScanResult
sr
)
throws
Exception
{
private
static
void
containerEntityNames
(
ScanResult
sr
)
throws
Naming
Exception
{
List
<
String
>
list
=
new
ArrayList
<>();
for
(
ClassInfo
info
:
sr
.
getClassesWithAnnotation
(
ContainerEntity
.
class
.
getName
()))
{
list
.
add
(
info
.
getName
());
...
...
@@ -119,7 +139,7 @@ public class ResourceFactory {
new
Resource
(
Config
.
RESOURCE_CONTAINERENTITYNAMES
,
ListUtils
.
unmodifiableList
(
list
));
}
private
static
void
stroageContainerEntityNames
(
ClassLoader
classLoader
,
ScanResult
sr
)
throws
Exception
{
private
static
void
stroageContainerEntityNames
(
ScanResult
sr
)
throws
Naming
Exception
{
List
<
String
>
list
=
new
ArrayList
<>();
for
(
ClassInfo
info
:
sr
.
getClassesWithAnnotation
(
Storage
.
class
.
getName
()))
{
list
.
add
(
info
.
getName
());
...
...
@@ -128,7 +148,8 @@ public class ResourceFactory {
new
Resource
(
Config
.
RESOURCE_STORAGECONTAINERENTITYNAMES
,
ListUtils
.
unmodifiableList
(
list
));
}
private
static
void
containerEntities
(
ClassLoader
classLoader
,
ScanResult
sr
)
throws
Exception
{
private
static
void
containerEntities
(
ClassLoader
classLoader
,
ScanResult
sr
)
throws
NamingException
,
ClassNotFoundException
{
Map
<
String
,
List
<
String
>>
map
=
new
TreeMap
<>();
for
(
ClassInfo
info
:
sr
.
getClassesWithAnnotation
(
Module
.
class
.
getName
()))
{
Class
<?>
cls
=
classLoader
.
loadClass
(
info
.
getName
());
...
...
@@ -139,10 +160,11 @@ public class ResourceFactory {
}
private
static
void
external
()
throws
Exception
{
external_druid_c3p0
(
);
dataSources
.
addAll
(
externalDruidC3p0
()
);
}
private
static
void
external_druid_c3p0
()
throws
Exception
{
private
static
List
<
DruidDataSourceC3P0Adapter
>
externalDruidC3p0
()
throws
Exception
{
List
<
DruidDataSourceC3P0Adapter
>
list
=
new
ArrayList
<>();
for
(
ExternalDataSource
ds
:
Config
.
externalDataSources
())
{
if
(
BooleanUtils
.
isNotTrue
(
ds
.
getEnable
()))
{
continue
;
...
...
@@ -170,14 +192,26 @@ public class ResourceFactory {
dataSource
.
setAutoCommitOnClose
(
ds
.
getAutoCommit
());
String
name
=
Config
.
externalDataSources
().
name
(
ds
);
new
Resource
(
Config
.
RESOURCE_JDBC_PREFIX
+
name
,
dataSource
);
list
.
add
(
dataSource
);
}
return
list
;
}
private
static
void
internal
()
throws
Exception
{
internal_driud_c3p0
(
);
dataSources
.
addAll
(
internalDriudC3p0
()
);
}
private
static
void
internal_driud_c3p0
()
throws
Exception
{
/**
* @author ray Druid DataSource 是需要close的.
*/
public
static
void
destory
()
{
for
(
DruidDataSourceC3P0Adapter
dataSource
:
dataSources
)
{
dataSource
.
close
();
}
}
private
static
List
<
DruidDataSourceC3P0Adapter
>
internalDriudC3p0
()
throws
Exception
{
List
<
DruidDataSourceC3P0Adapter
>
list
=
new
ArrayList
<>();
for
(
Entry
<
String
,
DataServer
>
entry
:
Config
.
nodes
().
dataServers
().
entrySet
())
{
DruidDataSourceC3P0Adapter
dataSource
=
new
DruidDataSourceC3P0Adapter
();
String
url
=
"jdbc:h2:tcp://"
+
entry
.
getKey
()
+
":"
+
entry
.
getValue
().
getTcpPort
()
...
...
@@ -202,22 +236,18 @@ public class ResourceFactory {
dataSource
.
setAutoCommitOnClose
(
false
);
String
name
=
Config
.
nodes
().
dataServers
().
name
(
entry
.
getValue
());
new
Resource
(
Config
.
RESOURCE_JDBC_PREFIX
+
name
,
dataSource
);
list
.
add
(
dataSource
);
}
return
list
;
}
// private static void auditLog() throws Exception {
// RolloverFileOutputStream rolloverFileOutputStream = new RolloverFileOutputStream(
// Config.dir_logs(true).getAbsolutePath() + "/yyyy_mm_dd.audit.log", true,
// Config.logLevel().audit().logSize());
// new Resource(Config.RESOURCE_AUDITLOGPRINTSTREAM,
// new PrintStream(rolloverFileOutputStream, true, DefaultCharset.name_iso_utf_8));
// }
private
static
void
processPlatformExecutors
()
throws
Exception
{
ExecutorService
[]
services
=
new
ExecutorService
[
Config
.
processPlatform
().
getExecutorCount
()];
for
(
int
i
=
0
;
i
<
Config
.
processPlatform
().
getExecutorCount
();
i
++)
{
services
[
i
]
=
Executors
.
newFixedThreadPool
(
1
,
new
BasicThreadFactory
.
Builder
()
.
namingPattern
(
"ProcessPlatformExecutor-"
+
i
).
daemon
(
true
).
build
());
// 等价于 Executors.newFixedThreadPool
services
[
i
]
=
new
ThreadPoolExecutor
(
1
,
1
,
0L
,
TimeUnit
.
MILLISECONDS
,
new
LinkedBlockingQueue
<
Runnable
>(),
new
BasicThreadFactory
.
Builder
().
namingPattern
(
"ProcessPlatformExecutor-"
+
i
).
daemon
(
true
)
.
build
());
}
new
Resource
(
Config
.
RESOURCE_NODE_PROCESSPLATFORMEXECUTORS
,
services
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录