Commit c87f5c71 authored by AfirSraftGarrier's avatar AfirSraftGarrier

格式

parent 176c9dcb
......@@ -5,7 +5,7 @@ import lombok.Data;
@Data
public class DeviceProtocol {
// |STX |LEN |CMD |ACK |DATA |END
// |STX |LEN |CMD |ACK |DATA |END
private short stx;//
private int len;//
......@@ -15,7 +15,7 @@ public class DeviceProtocol {
private byte[] content;// 数据
private byte end;
public DeviceProtocol(short stx, int len, byte cmd, byte ack, byte[] content,byte end) {
public DeviceProtocol(short stx, int len, byte cmd, byte ack, byte[] content, byte end) {
super();
this.stx = stx;
this.len = len;
......
......@@ -8,7 +8,7 @@ import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.SocketChannel;
import iot.sixiang.license.auth.AuthManager;
import iot.sixiang.license.consts.Consts;
import iot.sixiang.license.event.CreateForwarClientEvent;
import iot.sixiang.license.event.CreateForwardClientEvent;
import iot.sixiang.license.event.DeviceClientInactiveEvent;
import iot.sixiang.license.event.EventPublisher;
import iot.sixiang.license.event.ForwardClientRequestEvent;
......@@ -27,7 +27,6 @@ import java.net.InetSocketAddress;
@ChannelHandler.Sharable
@Slf4j
public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
@Autowired
EventPublisher eventPublisher;
......@@ -139,7 +138,7 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
deviceManager.putSession(appId, session);
// TODO 创建透传的客户端
CreateForwarClientEvent event = new CreateForwarClientEvent();
CreateForwardClientEvent event = new CreateForwardClientEvent();
event.setAppId(appId);
eventPublisher.publishEvent(event);
}
......
......@@ -11,8 +11,6 @@ import org.springframework.stereotype.Component;
@Component
@Slf4j
public class CreateForwarClientEventHandler {
@Autowired
ForwardManager forwardManager;
@Autowired
......@@ -20,14 +18,11 @@ public class CreateForwarClientEventHandler {
@Autowired
BalanceManager balanceManager;
public CreateForwarClientEventHandler() {
}
@EventListener
public void handlerEvent(CreateForwarClientEvent event) {
public void handlerEvent(CreateForwardClientEvent event) {
String appId = event.getAppId();
Server balanceServer = balanceManager.getBalanceServer();
......@@ -38,9 +33,5 @@ public class CreateForwarClientEventHandler {
} else {
log.error("balanceServer is null");
}
}
}
......@@ -5,7 +5,6 @@ package iot.sixiang.license.event;
import lombok.Data;
@Data
public class CreateForwarClientEvent extends BaseEvent {
public class CreateForwardClientEvent extends BaseEvent {
private String appId;
}
package iot.sixiang.license.event;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class EventPublisher {
@Autowired
private ApplicationEventPublisher applicationEventPublisher;
......
package iot.sixiang.license.event;
import io.netty.channel.socket.SocketChannel;
import iot.sixiang.license.device.DeviceProtocol;
import lombok.Data;
......@@ -9,5 +8,4 @@ public class ForwardClientRequestEvent extends BaseEvent {
private String appId;
private String deviceChannelId;
private DeviceProtocol protocol;
}
\ No newline at end of file
......@@ -22,7 +22,6 @@ public class ForwardClientRequestEventHandler {
public ForwardClientRequestEventHandler() {
}
@EventListener
......@@ -37,8 +36,5 @@ public class ForwardClientRequestEventHandler {
log.debug("forward client request:" + appId + "," + forwardSessionContext);
SocketChannel clientChannel = forwardSessionContext.getClientChannel();
clientChannel.writeAndFlush(protocol);
}
}
......@@ -15,8 +15,6 @@ import javax.annotation.PostConstruct;
@Component
@Slf4j
public class ForwardClient {
private TcpClient client = null;
private ForwardChannelInitializer channelInitializer;
private Bootstrap bootstrap;
......@@ -25,11 +23,10 @@ public class ForwardClient {
ForwardClientHandler handler;
public ForwardClient() {
}
@PostConstruct
public void init(){
public void init() {
channelInitializer = new ForwardChannelInitializer(handler);
EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
bootstrap = new Bootstrap();
......@@ -42,7 +39,6 @@ public class ForwardClient {
} catch (IllegalStateException ex) {
log.error(ex.getMessage());
}
}
public void startTcp(String host, int port, String appId) {
......@@ -54,5 +50,4 @@ public class ForwardClient {
client = new TcpClient(host, port, channelInitializer, listener, bootstrap);
client.start();
}
}
......@@ -21,12 +21,7 @@ public class TcpClient {
}
public void start() {
ChannelFuture future = bootstrap.connect(host, port);
future.addListener(connectionListener);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment