Skip to content

Commit 8fdc3b8

Browse files
committed
review code.
1 parent d9000d0 commit 8fdc3b8

File tree

6 files changed

+32
-28
lines changed

6 files changed

+32
-28
lines changed

orion-net/src/main/java/com/orion/net/remote/channel/SessionHolder.java

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public class SessionHolder {
2828

2929
public final JSch ch;
3030

31+
public SessionHolder() {
32+
this(new JSch());
33+
}
34+
3135
public SessionHolder(JSch ch) {
3236
Valid.notNull(ch, "jsch is null");
3337
this.ch = ch;
@@ -45,9 +49,9 @@ public static SessionHolder getHolder() {
4549
/**
4650
* 设置日志等级
4751
*/
48-
public static void setLogger(SessionLogger logger) {
52+
public void setLogger(SessionLogger logger) {
4953
int loggerLevel = logger.getLevel();
50-
JSch.setLogger(new Logger() {
54+
ch.setInstanceLogger(new Logger() {
5155
@Override
5256
public boolean isEnabled(int level) {
5357
return loggerLevel <= level;
@@ -60,26 +64,6 @@ public void log(int level, String message) {
6064
});
6165
}
6266

63-
/**
64-
* 获取配置信息
65-
*
66-
* @param key key
67-
* @return value
68-
*/
69-
public static String getConfig(String key) {
70-
return JSch.getConfig(key);
71-
}
72-
73-
/**
74-
* 设置配置信息
75-
*
76-
* @param key key
77-
* @param value value
78-
*/
79-
public static void setConfig(String key, String value) {
80-
JSch.setConfig(key, value);
81-
}
82-
8367
/**
8468
* 添加公钥登陆文件
8569
*

orion-net/src/main/java/com/orion/net/remote/channel/SessionStore.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,26 @@ public SessionStore daemonThread(boolean daemon) {
172172
return this;
173173
}
174174

175+
/**
176+
* 获取配置信息
177+
*
178+
* @param key key
179+
* @return value
180+
*/
181+
public String getConfig(String key) {
182+
return session.getConfig(key);
183+
}
184+
185+
/**
186+
* 设置配置信息
187+
*
188+
* @param key key
189+
* @param value value
190+
*/
191+
public void setConfig(String key, String value) {
192+
session.setConfig(key, value);
193+
}
194+
175195
/**
176196
* 建立连接
177197
*

orion-net/src/test/java/com/orion/net/remote/channel/CommandExecutorTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void init() {
2828

2929
@Test
3030
public void ls() {
31-
SessionHolder.setLogger(SessionLogger.ERROR);
31+
SessionHolder.HOLDER.setLogger(SessionLogger.ERROR);
3232
CommandExecutor e = s.getCommandExecutor("ls -la /root");
3333
e.callback(exe -> {
3434
System.out.println("end....");
@@ -45,7 +45,7 @@ public void ls() {
4545

4646
@Test
4747
public void echo() {
48-
SessionHolder.setLogger(SessionLogger.INFO);
48+
SessionHolder.HOLDER.setLogger(SessionLogger.INFO);
4949
CommandExecutor e = s.getCommandExecutor("echo $PATH");
5050
e.inherit();
5151
e.streamHandler(ReaderLineConsumer.getDefaultPrint());

orion-net/src/test/java/com/orion/net/remote/channel/SftpExecutorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class SftpExecutorTests {
2828

2929
@Before
3030
public void before() {
31-
SessionHolder.setLogger(SessionLogger.ERROR);
31+
SessionHolder.HOLDER.setLogger(SessionLogger.ERROR);
3232
this.e = SessionHolder.HOLDER.getSession("192.168.146.230", "root")
3333
.password("admin123")
3434
.timeout(20000)

orion-net/src/test/java/com/orion/net/remote/channel/ShellExecutorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
public class ShellExecutorTests {
1313

1414
public static void main(String[] args) {
15-
SessionHolder.setLogger(SessionLogger.INFO);
15+
SessionHolder.HOLDER.setLogger(SessionLogger.INFO);
1616
ShellExecutor e = SessionHolder.HOLDER.getSession("192.168.146.230", "root")
1717
.password("admin123")
1818
// ShellExecutor e = SessionHolder.getSession("192.168.146.230", "root")

orion-net/src/test/java/com/orion/net/remote/connection/CommandTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void before() {
2929

3030
@Test
3131
public void ls() {
32-
SessionHolder.setLogger(SessionLogger.ERROR);
32+
SessionHolder.HOLDER.setLogger(SessionLogger.ERROR);
3333
CommandExecutor e = c.getCommandExecutor("ls -la /root");
3434
e.callback(exe -> {
3535
System.out.println("end....");
@@ -45,7 +45,7 @@ public void ls() {
4545

4646
@Test
4747
public void echo() {
48-
SessionHolder.setLogger(SessionLogger.INFO);
48+
SessionHolder.HOLDER.setLogger(SessionLogger.INFO);
4949
CommandExecutor e = c.getCommandExecutor("echo $PATH");
5050
e.inherit();
5151
e.streamHandler(ReaderLineConsumer.getDefaultPrint());

0 commit comments

Comments
 (0)