Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
ioc_sixiang_license
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zengtianlai3
ioc_sixiang_license
Commits
3afb5e5e
Commit
3afb5e5e
authored
Jun 10, 2022
by
zengtianlai3
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
运维模块修改以及代码整理
parent
9bbdf799
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
45 additions
and
88 deletions
+45
-88
OperateSAMStatusRequestEvent.java
...t/sixiang/license/event/OperateSAMStatusRequestEvent.java
+1
-1
OperateSAMStatusRequestEventHandler.java
...ng/license/event/OperateSAMStatusRequestEventHandler.java
+3
-5
OperateSAMStatusResponseEvent.java
.../sixiang/license/event/OperateSAMStatusResponseEvent.java
+1
-1
OperateSAMStatusResponseEventHandler.java
...g/license/event/OperateSAMStatusResponseEventHandler.java
+6
-8
SamInfo.java
license/src/main/java/iot/sixiang/license/model/SamInfo.java
+1
-1
OperateClientHandler.java
...ava/iot/sixiang/license/operate/OperateClientHandler.java
+10
-32
OperateConnectionListener.java
...ot/sixiang/license/operate/OperateConnectionListener.java
+1
-3
OperateDecoder.java
...main/java/iot/sixiang/license/operate/OperateDecoder.java
+6
-15
OperateEncoder.java
...main/java/iot/sixiang/license/operate/OperateEncoder.java
+3
-10
OperateManager.java
...main/java/iot/sixiang/license/operate/OperateManager.java
+13
-12
No files found.
license/src/main/java/iot/sixiang/license/event/OperateSAMStatus
Query
Event.java
→
license/src/main/java/iot/sixiang/license/event/OperateSAMStatus
Request
Event.java
View file @
3afb5e5e
...
...
@@ -5,7 +5,7 @@ import iot.sixiang.license.device.DeviceProtocol;
import
lombok.Data
;
@Data
public
class
OperateSAMStatus
Query
Event
extends
BaseEvent
{
public
class
OperateSAMStatus
Request
Event
extends
BaseEvent
{
private
SocketChannel
channel
;
private
DeviceProtocol
protocol
;
}
license/src/main/java/iot/sixiang/license/event/OperateSAMStatus
Query
EventHandler.java
→
license/src/main/java/iot/sixiang/license/event/OperateSAMStatus
Request
EventHandler.java
View file @
3afb5e5e
...
...
@@ -9,18 +9,16 @@ import org.springframework.stereotype.Component;
@Component
@Slf4j
public
class
OperateSAMStatus
Query
EventHandler
{
public
OperateSAMStatus
Query
EventHandler
()
{
public
class
OperateSAMStatus
Request
EventHandler
{
public
OperateSAMStatus
Request
EventHandler
()
{
}
@EventListener
public
void
handlerEvent
(
OperateSAMStatus
Query
Event
event
)
{
public
void
handlerEvent
(
OperateSAMStatus
Request
Event
event
)
{
SocketChannel
channel
=
event
.
getChannel
();
DeviceProtocol
protocol
=
event
.
getProtocol
();
channel
.
writeAndFlush
(
protocol
);
log
.
debug
(
"OperateSAMStatusQueryEventHandler"
);
}
...
...
license/src/main/java/iot/sixiang/license/event/OperateSAMStatusEvent.java
→
license/src/main/java/iot/sixiang/license/event/OperateSAMStatus
Response
Event.java
View file @
3afb5e5e
...
...
@@ -7,7 +7,7 @@ import lombok.Data;
* Created by m33 on 2022/6/9 21:38
*/
@Data
public
class
OperateSAMStatusEvent
extends
BaseEvent
{
public
class
OperateSAMStatus
Response
Event
extends
BaseEvent
{
private
String
ip
;
private
DeviceProtocol
protocol
;
}
license/src/main/java/iot/sixiang/license/event/OperateSAMStatusEventHandler.java
→
license/src/main/java/iot/sixiang/license/event/OperateSAMStatus
Response
EventHandler.java
View file @
3afb5e5e
package
iot
.
sixiang
.
license
.
event
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
Object
;
import
iot.sixiang.license.device.DeviceProtocol
;
import
iot.sixiang.license.model.SamInfo
;
import
iot.sixiang.license.model.SamMonitor
;
import
iot.sixiang.license.model.msg.SamInfoMsg
;
import
iot.sixiang.license.operate.OperateManager
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -19,20 +18,19 @@ import java.util.List;
@Component
@Slf4j
public
class
OperateSAMStatusEventHandler
{
public
class
OperateSAMStatus
Response
EventHandler
{
@Autowired
public
OperateManager
operateManager
;
public
OperateSAMStatusEventHandler
()
{
public
OperateSAMStatus
Response
EventHandler
()
{
}
@EventListener
public
void
handlerEvent
(
OperateSAMStatusEvent
event
)
{
public
void
handlerEvent
(
OperateSAMStatus
Response
Event
event
)
{
DeviceProtocol
protocol
=
event
.
getProtocol
();
String
serverIp
=
event
.
getIp
();
String
jsonOperateStatus
=
new
String
(
protocol
.
getContent
(),
0
,
protocol
.
getContent
().
length
);
SamInfoMsg
samInfoMsg
=
JSON
.
parseObject
(
jsonOperateStatus
,
SamInfoMsg
.
class
);
List
<
SamInfo
>
samInfoList
=
samInfoMsg
.
getList
();
List
<
SamInfo
>
samInfoList
=
JSONObject
.
parseArray
(
jsonOperateStatus
,
SamInfo
.
class
);
int
samCount
=
samInfoList
.
size
();
int
onlineCount
=
0
;
for
(
SamInfo
samInfo
:
samInfoList
)
{
...
...
@@ -40,11 +38,11 @@ public class OperateSAMStatusEventHandler {
onlineCount
++;
}
}
SamMonitor
samMonitor
=
new
SamMonitor
();
samMonitor
.
setServerIp
(
serverIp
);
samMonitor
.
setOnlineCount
(
onlineCount
);
samMonitor
.
setSamCount
(
samCount
);
operateManager
.
putSamMonitorMap
(
serverIp
,
samMonitor
);
log
.
debug
(
"OperateSAMStatusEventHandler"
);
}
}
license/src/main/java/iot/sixiang/license/model/SamInfo.java
View file @
3afb5e5e
...
...
@@ -8,6 +8,6 @@ import lombok.Data;
@Data
public
class
SamInfo
{
private
int
index
;
private
int
samid
;
private
String
samid
;
private
int
status
;
}
license/src/main/java/iot/sixiang/license/operate/OperateClientHandler.java
View file @
3afb5e5e
...
...
@@ -6,7 +6,7 @@ import io.netty.channel.SimpleChannelInboundHandler;
import
io.netty.channel.socket.SocketChannel
;
import
iot.sixiang.license.device.DeviceProtocol
;
import
iot.sixiang.license.event.EventPublisher
;
import
iot.sixiang.license.event.OperateSAMStatusEvent
;
import
iot.sixiang.license.event.OperateSAMStatus
Response
Event
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
...
...
@@ -21,12 +21,8 @@ public class OperateClientHandler extends SimpleChannelInboundHandler<Object> {
@Autowired
EventPublisher
eventPublisher
;
private
byte
[]
obj
=
new
byte
[
0
];
// 特殊的instance变量
private
String
nodeType
=
"rsretail"
;
public
OperateClientHandler
()
{
super
();
log
.
debug
(
"ProxyNodeClientHandler ****"
);
}
@Override
...
...
@@ -35,8 +31,7 @@ public class OperateClientHandler extends SimpleChannelInboundHandler<Object> {
String
remoteIp
=
socketAddr
.
getHostString
();
DeviceProtocol
protocol
=
(
DeviceProtocol
)
msg
;
OperateSAMStatusEvent
event
=
new
OperateSAMStatusEvent
();
OperateSAMStatusResponseEvent
event
=
new
OperateSAMStatusResponseEvent
();
event
.
setProtocol
(
protocol
);
event
.
setIp
(
remoteIp
);
eventPublisher
.
publishEvent
(
event
);
...
...
@@ -46,10 +41,10 @@ public class OperateClientHandler extends SimpleChannelInboundHandler<Object> {
@Override
public
void
channelRegistered
(
ChannelHandlerContext
ctx
)
{
// TODO Auto-generated method stub
try
{
super
.
channelRegistered
(
ctx
);
log
.
debug
(
"channelRegistered----------->"
);
SocketChannel
channel
=
(
SocketChannel
)
ctx
.
channel
();
log
.
debug
(
"channelRegistered "
+
ctx
.
channel
().
id
().
asLongText
());
}
catch
(
Exception
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
...
...
@@ -62,20 +57,7 @@ public class OperateClientHandler extends SimpleChannelInboundHandler<Object> {
super
.
channelActive
(
ctx
);
try
{
SocketChannel
channel
=
(
SocketChannel
)
ctx
.
channel
();
log
.
debug
(
"channelActive********"
+
ctx
.
channel
().
id
().
asLongText
());
// InetSocketAddress socketAddr = (InetSocketAddress) ctx.channel().remoteAddress();
// String clientIp = socketAddr.getHostString();
// int port = socketAddr.getPort();
//
// SessionContext session = new SessionContext();
// session.setRemoteIp(clientIp);
// session.setRemotePort(port);
// session.setClientChannel(channel);
//
// ForwardManager forwardManager = SpringUtil.getBean(ForwardManager.class);
// log.debug("channelActive.getClientChannel:" + channel);
// forwardManager.setSessionContexts(session);
log
.
debug
(
"channelActive "
+
ctx
.
channel
().
id
().
asLongText
());
}
catch
(
Exception
e
)
{
// TODO Auto-generated catch block
...
...
@@ -88,10 +70,7 @@ public class OperateClientHandler extends SimpleChannelInboundHandler<Object> {
// TODO Auto-generated method stub
super
.
channelInactive
(
ctx
);
SocketChannel
channel
=
(
SocketChannel
)
ctx
.
channel
();
String
channelId
=
channel
.
id
().
asLongText
();
// ForwardClientInactiveEvent forwardClientInactiveEvent = new ForwardClientInactiveEvent();
// forwardClientInactiveEvent.setChannelId(channelId);
// eventPublisher.publishEvent(forwardClientInactiveEvent);
log
.
debug
(
"channelInactive "
+
ctx
.
channel
().
id
().
asLongText
());
ctx
.
close
();
}
...
...
@@ -99,19 +78,18 @@ public class OperateClientHandler extends SimpleChannelInboundHandler<Object> {
public
void
channelReadComplete
(
ChannelHandlerContext
ctx
)
throws
Exception
{
// TODO Auto-generated method stub
super
.
channelReadComplete
(
ctx
);
log
.
debug
(
"channelReadComplete"
);
SocketChannel
channel
=
(
SocketChannel
)
ctx
.
channel
();
log
.
debug
(
"channelReadComplete "
+
ctx
.
channel
().
id
().
asLongText
());
}
@Override
public
void
exceptionCaught
(
ChannelHandlerContext
ctx
,
Throwable
cause
)
throws
Exception
{
// TODO Auto-generated method stub
super
.
exceptionCaught
(
ctx
,
cause
);
InetSocketAddress
socketAddr
=
(
InetSocketAddress
)
ctx
.
channel
().
remoteAddress
();
String
clientIp
=
socketAddr
.
getHostString
();
int
port
=
socketAddr
.
getPort
();
SocketChannel
channel
=
(
SocketChannel
)
ctx
.
channel
();
log
.
debug
(
"exceptionCaught "
+
ctx
.
channel
().
id
().
asLongText
());
cause
.
printStackTrace
();
ctx
.
close
();
log
.
error
(
"client has error,ip:"
+
clientIp
+
",port:"
+
port
);
}
@Override
...
...
license/src/main/java/iot/sixiang/license/operate/OperateConnectionListener.java
View file @
3afb5e5e
...
...
@@ -22,15 +22,13 @@ public class OperateConnectionListener extends BaseConnectionListener {
//TODO 查询SAM状态
OperateSAMStatus
QueryEvent
operateSAMStatusQueryEvent
=
new
OperateSAMStatusQuery
Event
();
OperateSAMStatus
RequestEvent
operateSAMStatusQueryEvent
=
new
OperateSAMStatusRequest
Event
();
short
stx
=
21930
;
int
len
=
2
;
byte
cmd
=
0x5f
;
// byte cmd = 0x5b;
byte
ack
=
0x00
;
byte
end
=
0x5f
;
// byte end = 0x5b;
SocketChannel
channel
=
(
SocketChannel
)
channelFuture
.
channel
();
DeviceProtocol
protocol
=
new
DeviceProtocol
(
stx
,
len
,
cmd
,
ack
,
null
,
end
);
...
...
license/src/main/java/iot/sixiang/license/operate/OperateDecoder.java
View file @
3afb5e5e
...
...
@@ -18,10 +18,6 @@ public class OperateDecoder extends ByteToMessageDecoder {
protected
void
decode
(
ChannelHandlerContext
ctx
,
ByteBuf
buffer
,
List
<
Object
>
out
)
{
// 可读长度必须大于等于基本长度
try
{
byte
[]
packet
=
new
byte
[
buffer
.
readableBytes
()];
buffer
.
readBytes
(
packet
);
buffer
.
resetReaderIndex
();
Util
.
DEBUG_HEX
(
"SERVER -> IN"
,
packet
,
packet
.
length
);
if
(
buffer
.
readableBytes
()
<
BASE_LENGTH
)
{
return
;
...
...
@@ -29,25 +25,21 @@ public class OperateDecoder extends ByteToMessageDecoder {
buffer
.
markReaderIndex
();
short
stx
=
buffer
.
readShort
();
//55AA->21930
short
stx
=
buffer
.
readShort
();
short
len
=
buffer
.
readShortLE
();
log
.
debug
(
"msg rece len:"
+
packet
.
length
+
",decode len:"
+
len
);
len
=
2677
;
byte
cmd
=
buffer
.
readByte
();
byte
ack
=
buffer
.
readByte
();
////stx:21930,len:52,cmd:-112,ack:0
byte
cmd
=
buffer
.
readByte
();
byte
ack
=
buffer
.
readByte
();
log
.
debug
(
"stx:"
+
stx
+
",len:"
+
len
);
int
real_len
=
len
;
int
cmd_ack_len
=
2
;
if
(
buffer
.
readableBytes
()
<
real_len
-
cmd_ack_len
+
1
)
{
if
(
buffer
.
readableBytes
()
<
real_len
-
cmd_ack_len
+
1
)
{
buffer
.
resetReaderIndex
();
return
;
}
// buffer.resetReaderIndex();//复位
// 读取data数据
byte
[]
content
=
new
byte
[
real_len
-
cmd_ack_len
];
...
...
@@ -55,14 +47,13 @@ public class OperateDecoder extends ByteToMessageDecoder {
byte
end
=
buffer
.
readByte
();
log
.
debug
(
"OperateDecoder.msg.getLen()...."
+
real_len
);
DeviceProtocol
protocol
=
new
DeviceProtocol
(
stx
,
real_len
,
cmd
,
ack
,
content
,
end
);
DeviceProtocol
protocol
=
new
DeviceProtocol
(
stx
,
real_len
,
cmd
,
ack
,
content
,
end
);
out
.
add
(
protocol
);
}
catch
(
Exception
e
)
{
// TODO Auto-generated catch block
log
.
error
(
"DeviceDecoder error!"
);
log
.
error
(
e
.
getMessage
()
);
}
}
...
...
license/src/main/java/iot/sixiang/license/operate/OperateEncoder.java
View file @
3afb5e5e
...
...
@@ -11,23 +11,16 @@ import lombok.extern.slf4j.Slf4j;
public
class
OperateEncoder
extends
MessageToByteEncoder
<
DeviceProtocol
>
{
@Override
protected
void
encode
(
ChannelHandlerContext
tcx
,
DeviceProtocol
msg
,
ByteBuf
out
)
throws
Exception
{
protected
void
encode
(
ChannelHandlerContext
tcx
,
DeviceProtocol
msg
,
ByteBuf
out
)
{
try
{
// short stx = in.readShort();//55AA->21930
// short len = in.readShortLE();
out
.
writeShort
(
msg
.
getStx
());
// out.writeShort(msg.getLen());
out
.
writeShortLE
(
msg
.
getLen
());
out
.
writeByte
(
msg
.
getCmd
());
out
.
writeByte
(
msg
.
getAck
());
log
.
debug
(
"OperateEncoder.msg.getLen()...."
+
msg
.
getLen
());
if
(
msg
.
getContent
()
==
null
)
{
// log
ger
.debug("body数据为空");
// log.debug("body数据为空");
}
else
{
out
.
writeBytes
(
msg
.
getContent
());
}
...
...
@@ -35,7 +28,7 @@ public class OperateEncoder extends MessageToByteEncoder<DeviceProtocol> {
}
catch
(
Exception
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
log
.
error
(
"DeviceEncoder error---->"
);
log
.
error
(
e
.
getMessage
()
);
}
}
}
license/src/main/java/iot/sixiang/license/operate/OperateManager.java
View file @
3afb5e5e
...
...
@@ -46,8 +46,8 @@ public class OperateManager {
allServers
.
put
(
serverIp
,
server
);
}
createProxyClient
();
//
createProxyClient();
// test();
}
public
void
createProxyClient
()
{
...
...
@@ -57,19 +57,20 @@ public class OperateManager {
Server
server
=
next
.
getValue
();
//TODO 创建运维客户端去查询相关的运维消息
// for(int i =0;i<5;i++){
String
serverIp
=
server
.
getServerIp
();
Integer
port
=
server
.
getPort
();
serverIp
=
"192.168.1.56"
;
// serverIp = "172.17.115.81";
// port = 777;
this
.
startTcpClient
(
serverIp
,
port
);
// }
String
serverIp
=
server
.
getServerIp
();
Integer
port
=
server
.
getPort
();
this
.
startTcpClient
(
serverIp
,
port
);
}
}
private
void
test
()
{
String
serverIp
=
"192.168.1.56"
;
int
port
=
18889
;
// serverIp = "172.17.115.81";
// port = 777;
this
.
startTcpClient
(
serverIp
,
port
);
}
public
void
startTcpClient
(
String
serviceIP
,
int
port
)
{
client
.
startTcp
(
serviceIP
,
port
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment