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
8124cc8b
Commit
8124cc8b
authored
Jun 07, 2022
by
zengtianlai3
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
简单的负载均衡随机分配策略
parent
91ebb822
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
10 deletions
+67
-10
AuthManager.java
...e/src/main/java/iot/sixiang/license/auth/AuthManager.java
+50
-0
DeviceManager.java
...c/main/java/iot/sixiang/license/device/DeviceManager.java
+0
-4
CreateForwarClientEventHandler.java
...sixiang/license/event/CreateForwarClientEventHandler.java
+15
-2
ForwardManager.java
...main/java/iot/sixiang/license/forward/ForwardManager.java
+1
-3
application.properties
license/src/main/resources/application.properties
+1
-1
No files found.
license/src/main/java/iot/sixiang/license/auth/AuthManager.java
0 → 100644
View file @
8124cc8b
package
iot
.
sixiang
.
license
.
auth
;
import
iot.sixiang.license.entity.Server
;
import
iot.sixiang.license.service.ServerService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.PostConstruct
;
import
java.util.*
;
@Component
@Slf4j
public
class
AuthManager
{
@Autowired
private
ServerService
serverService
;
private
Map
<
String
,
Server
>
allServers
=
null
;
public
AuthManager
()
{
allServers
=
new
HashMap
<
String
,
Server
>();
}
@PostConstruct
public
void
init
()
{
List
<
Server
>
servers
=
serverService
.
getServerList
(
0
,
20
);
for
(
Server
server
:
servers
)
{
String
serverIp
=
server
.
getServerIp
();
allServers
.
put
(
serverIp
,
server
);
}
}
public
Server
getBalanceServer
(){
int
count
=
allServers
.
size
();
if
(
count
==
0
){
return
null
;
}
else
{
Random
random
=
new
Random
();
int
index
=
random
.
nextInt
(
count
);
List
<
Server
>
servers
=
new
ArrayList
<>(
allServers
.
values
());
return
servers
.
get
(
index
);
}
}
}
license/src/main/java/iot/sixiang/license/device/DeviceManager.java
View file @
8124cc8b
...
@@ -27,10 +27,6 @@ public class DeviceManager {
...
@@ -27,10 +27,6 @@ public class DeviceManager {
@Autowired
@Autowired
private
DeviceServerHandler
handler
;
private
DeviceServerHandler
handler
;
@Getter
@Setter
SessionContext
sessionContext
=
null
;
public
DeviceManager
()
{
public
DeviceManager
()
{
sessionContexts
=
new
HashMap
<
String
,
SessionContext
>();
sessionContexts
=
new
HashMap
<
String
,
SessionContext
>();
...
...
license/src/main/java/iot/sixiang/license/event/CreateForwarClientEventHandler.java
View file @
8124cc8b
package
iot
.
sixiang
.
license
.
event
;
package
iot
.
sixiang
.
license
.
event
;
import
iot.sixiang.license.auth.AuthManager
;
import
iot.sixiang.license.entity.Server
;
import
iot.sixiang.license.forward.ForwardManager
;
import
iot.sixiang.license.forward.ForwardManager
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -15,18 +17,29 @@ public class CreateForwarClientEventHandler {
...
@@ -15,18 +17,29 @@ public class CreateForwarClientEventHandler {
ForwardManager
forwardManager
;
ForwardManager
forwardManager
;
@Autowired
@Autowired
EventPublisher
eventPublisher
;
EventPublisher
eventPublisher
;
@Autowired
AuthManager
authManager
;
public
CreateForwarClientEventHandler
()
{
public
CreateForwarClientEventHandler
()
{
}
}
// @Async("asyncExecutor")
@EventListener
@EventListener
public
void
handlerEvent
(
CreateForwarClientEvent
event
)
{
public
void
handlerEvent
(
CreateForwarClientEvent
event
)
{
String
appId
=
event
.
getAppId
();
String
appId
=
event
.
getAppId
();
forwardManager
.
startTcpClient
(
appId
);
Server
balanceServer
=
authManager
.
getBalanceServer
();
if
(
balanceServer
!=
null
)
{
String
serverIp
=
balanceServer
.
getServerIp
();
Integer
port
=
balanceServer
.
getPort
();
forwardManager
.
startTcpClient
(
serverIp
,
port
,
appId
);
}
else
{
log
.
error
(
"balanceServer is null"
);
}
}
}
...
...
license/src/main/java/iot/sixiang/license/forward/ForwardManager.java
View file @
8124cc8b
...
@@ -20,8 +20,6 @@ public class ForwardManager {
...
@@ -20,8 +20,6 @@ public class ForwardManager {
@Autowired
@Autowired
public
ForwardClient
client
;
public
ForwardClient
client
;
String
serviceIP
=
"121.46.25.14"
;
int
port
=
18889
;
private
Map
<
String
,
SessionContext
>
sessionContexts
=
null
;
private
Map
<
String
,
SessionContext
>
sessionContexts
=
null
;
...
@@ -30,7 +28,7 @@ public class ForwardManager {
...
@@ -30,7 +28,7 @@ public class ForwardManager {
}
}
public
void
startTcpClient
(
String
appId
)
{
public
void
startTcpClient
(
String
serviceIP
,
int
port
,
String
appId
)
{
client
.
startTcp
(
serviceIP
,
port
,
appId
);
client
.
startTcp
(
serviceIP
,
port
,
appId
);
}
}
...
...
license/src/main/resources/application.properties
View file @
8124cc8b
server.port
=
8868
server.port
=
8868
logging.level.root
=
debug
logging.level.root
=
debug
spring.datasource.driver-class-name
=
com.mysql.cj.jdbc.Driver
spring.datasource.driver-class-name
=
com.mysql.cj.jdbc.Driver
spring.datasource.url
=
jdbc:mysql://localhost:3306/
firstwork
?serverTimezone=GMT%2B8
spring.datasource.url
=
jdbc:mysql://localhost:3306/
iot_license
?serverTimezone=GMT%2B8
spring.datasource.username
=
root
spring.datasource.username
=
root
spring.datasource.password
=
123456
spring.datasource.password
=
123456
mybatis-plus.mapper-locations
=
classpath:/mapper/**.xml
mybatis-plus.mapper-locations
=
classpath:/mapper/**.xml
...
...
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