Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_42566577
o2oa
提交
1bc40fee
o2oa
项目概览
weixin_42566577
/
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,发现更多精彩内容 >>
提交
1bc40fee
编写于
9月 18, 2021
作者:
O
o2null
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修正log引起的console命令无法执行
上级
5f565993
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
51 addition
and
48 deletion
+51
-48
o2server/x_console/src/main/java/com/x/server/console/Shadow.java
.../x_console/src/main/java/com/x/server/console/Shadow.java
+51
-48
未找到文件。
o2server/x_console/src/main/java/com/x/server/console/Shadow.java
浏览文件 @
1bc40fee
...
...
@@ -9,71 +9,74 @@ import java.nio.MappedByteBuffer;
import
java.nio.channels.FileChannel
;
import
java.nio.channels.FileChannel.MapMode
;
import
java.nio.channels.FileLock
;
import
java.util.Date
;
import
org.apache.commons.lang3.StringUtils
;
import
com.x.base.core.project.config.Config
;
import
com.x.base.core.project.tools.DateTools
;
import
com.x.base.core.project.logger.Logger
;
import
com.x.base.core.project.logger.LoggerFactory
;
public
class
Shadow
{
private
static
boolean
tag
=
true
;
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
Shadow
.
class
)
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
tag
=
true
;
File
logFile
=
new
File
(
Config
.
base
(),
"logs/"
+
DateTools
.
format
(
new
Date
(),
"yyyy_MM_dd"
)
+
".out.log"
);
public
static
void
main
(
String
...
args
)
throws
Exception
{
File
logFile
=
new
File
(
Config
.
base
(),
"logs/out.log"
);
if
(!
logFile
.
exists
())
{
System
.
out
.
println
(
"can not find log file,server not running."
);
logger
.
print
(
"can not find log file,server not running."
);
}
else
{
new
Thread
()
{
@Override
public
void
run
()
{
try
(
FileReader
fr
=
new
FileReader
(
logFile
);
BufferedReader
br
=
new
BufferedReader
(
fr
))
{
System
.
out
.
println
(
"console start, type close to exit console."
);
br
.
skip
(
logFile
.
length
());
String
line
=
null
;
while
(
tag
)
{
if
((
line
=
br
.
readLine
())
!=
null
)
{
System
.
out
.
println
(
line
);
continue
;
}
try
{
Thread
.
sleep
(
2000L
);
}
catch
(
InterruptedException
e
)
{
Thread
.
currentThread
().
interrupt
();
break
;
}
new
Thread
(()
->
{
try
(
FileReader
fr
=
new
FileReader
(
logFile
);
BufferedReader
br
=
new
BufferedReader
(
fr
))
{
logger
.
print
(
"console start, type close to exit console."
);
br
.
skip
(
logFile
.
length
());
String
line
=
null
;
while
(
true
)
{
if
((
line
=
br
.
readLine
())
!=
null
)
{
logger
.
debug
(
"line:{}."
,
line
);
System
.
out
.
println
(
line
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
sleep
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}.
start
();
try
(
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
System
.
in
)))
{
String
cmd
=
""
;
while
(
tag
)
{
cmd
=
reader
.
readLine
();
if
((
null
==
cmd
)
||
(
StringUtils
.
equalsIgnoreCase
(
"close"
,
StringUtils
.
trim
(
cmd
))))
{
tag
=
false
;
System
.
exit
(
0
);
}
try
(
RandomAccessFile
raf
=
new
RandomAccessFile
(
getBasePath
()
+
"/command.swap"
,
"rw"
))
{
FileChannel
fc
=
raf
.
getChannel
();
MappedByteBuffer
mbb
=
fc
.
map
(
MapMode
.
READ_WRITE
,
0
,
256
);
FileLock
flock
=
null
;
flock
=
fc
.
lock
();
mbb
.
put
(
cmd
.
getBytes
());
flock
.
release
();
}
},
Shadow
.
class
.
getName
()).
start
();
readCommand
();
}
}
private
static
void
readCommand
()
{
try
(
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
System
.
in
)))
{
String
cmd
=
""
;
while
(
true
)
{
cmd
=
reader
.
readLine
();
if
((
null
==
cmd
)
||
(
StringUtils
.
equalsIgnoreCase
(
"close"
,
StringUtils
.
trim
(
cmd
))))
{
System
.
exit
(
0
);
break
;
}
try
(
RandomAccessFile
raf
=
new
RandomAccessFile
(
getBasePath
()
+
"/command.swap"
,
"rw"
))
{
FileChannel
fc
=
raf
.
getChannel
();
MappedByteBuffer
mbb
=
fc
.
map
(
MapMode
.
READ_WRITE
,
0
,
256
);
FileLock
flock
=
null
;
flock
=
fc
.
lock
();
mbb
.
put
(
cmd
.
getBytes
());
flock
.
release
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
private
static
void
sleep
()
{
try
{
Thread
.
sleep
(
1500L
);
}
catch
(
InterruptedException
e
)
{
Thread
.
currentThread
().
interrupt
();
}
}
private
static
String
getBasePath
()
throws
Exception
{
private
static
String
getBasePath
()
{
String
path
=
Main
.
class
.
getProtectionDomain
().
getCodeSource
().
getLocation
().
getPath
();
File
file
=
new
File
(
path
);
if
(!
file
.
isDirectory
())
{
...
...
@@ -86,7 +89,7 @@ public class Shadow {
}
file
=
file
.
getParentFile
();
}
throw
new
Exception
(
"can not define o2server base directory."
);
throw
new
IllegalState
Exception
(
"can not define o2server base directory."
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录