Commit c87f5c71 authored by AfirSraftGarrier's avatar AfirSraftGarrier

格式

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