|
2 | 2 |
|
3 | 3 | import com.ss.mqtt.broker.handler.client.DefaultMqttClientReleaseHandler; |
4 | 4 | import com.ss.mqtt.broker.handler.client.MqttClientReleaseHandler; |
5 | | -import com.ss.mqtt.broker.handler.packet.in.*; |
| 5 | +import com.ss.mqtt.broker.handler.packet.in.ConnectInPacketHandler; |
| 6 | +import com.ss.mqtt.broker.handler.packet.in.DisconnetInPacketHandler; |
| 7 | +import com.ss.mqtt.broker.handler.packet.in.PacketInHandler; |
| 8 | +import com.ss.mqtt.broker.handler.packet.in.PublishAckInPacketHandler; |
| 9 | +import com.ss.mqtt.broker.handler.packet.in.PublishCompleteInPacketHandler; |
| 10 | +import com.ss.mqtt.broker.handler.packet.in.PublishInPacketHandler; |
| 11 | +import com.ss.mqtt.broker.handler.packet.in.PublishReceiveInPacketHandler; |
| 12 | +import com.ss.mqtt.broker.handler.packet.in.PublishReleaseInPacketHandler; |
| 13 | +import com.ss.mqtt.broker.handler.packet.in.SubscribeInPacketHandler; |
| 14 | +import com.ss.mqtt.broker.handler.packet.in.UnsubscribeInPacketHandler; |
6 | 15 | import com.ss.mqtt.broker.handler.publish.in.PublishInHandler; |
7 | 16 | import com.ss.mqtt.broker.handler.publish.in.Qos0PublishInHandler; |
8 | 17 | import com.ss.mqtt.broker.handler.publish.in.Qos1PublishInHandler; |
|
12 | 21 | import com.ss.mqtt.broker.handler.publish.out.Qos1PublishOutHandler; |
13 | 22 | import com.ss.mqtt.broker.handler.publish.out.Qos2PublishOutHandler; |
14 | 23 | import com.ss.mqtt.broker.network.packet.PacketType; |
15 | | -import com.ss.mqtt.broker.service.*; |
16 | | -import com.ss.mqtt.broker.service.impl.*; |
| 24 | +import com.ss.mqtt.broker.service.AuthenticationService; |
| 25 | +import com.ss.mqtt.broker.service.ClientIdRegistry; |
| 26 | +import com.ss.mqtt.broker.service.CredentialSource; |
| 27 | +import com.ss.mqtt.broker.service.MqttSessionService; |
| 28 | +import com.ss.mqtt.broker.service.PublishingService; |
| 29 | +import com.ss.mqtt.broker.service.SubscriptionService; |
| 30 | +import com.ss.mqtt.broker.service.impl.DefaultPublishingService; |
| 31 | +import com.ss.mqtt.broker.service.impl.FileCredentialsSource; |
| 32 | +import com.ss.mqtt.broker.service.impl.InMemoryClientIdRegistry; |
| 33 | +import com.ss.mqtt.broker.service.impl.InMemoryMqttSessionService; |
| 34 | +import com.ss.mqtt.broker.service.impl.SimpleAuthenticationService; |
| 35 | +import com.ss.mqtt.broker.service.impl.SimpleSubscriptionService; |
17 | 36 | import lombok.RequiredArgsConstructor; |
18 | 37 | import lombok.extern.log4j.Log4j2; |
19 | | -import org.jetbrains.annotations.NotNull; |
20 | 38 | import org.springframework.context.annotation.Bean; |
21 | 39 | import org.springframework.context.annotation.Configuration; |
22 | 40 | import org.springframework.core.env.Environment; |
|
26 | 44 | @RequiredArgsConstructor |
27 | 45 | public class MqttBrokerConfig { |
28 | 46 |
|
29 | | - private final Environment env; |
| 47 | + private final Environment env; |
30 | 48 |
|
31 | | - @Bean |
32 | | - @NotNull ClientIdRegistry clientIdRegistry() { |
33 | | - return new InMemoryClientIdRegistry( |
34 | | - env.getProperty( |
35 | | - "client.id.available.chars", |
36 | | - "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_" |
37 | | - ), |
38 | | - env.getProperty("client.id.max.length", int.class, 36) |
39 | | - ); |
40 | | - } |
| 49 | + @Bean |
| 50 | + ClientIdRegistry clientIdRegistry() { |
| 51 | + return new InMemoryClientIdRegistry( |
| 52 | + env.getProperty( |
| 53 | + "client.id.available.chars", |
| 54 | + "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_"), |
| 55 | + env.getProperty("client.id.max.length", int.class, 36)); |
| 56 | + } |
41 | 57 |
|
42 | | - @Bean |
43 | | - @NotNull MqttSessionService mqttSessionService() { |
44 | | - return new InMemoryMqttSessionService( |
45 | | - env.getProperty("sessions.clean.thread.interval", int.class, 60000) |
46 | | - ); |
47 | | - } |
| 58 | + @Bean |
| 59 | + MqttSessionService mqttSessionService() { |
| 60 | + return new InMemoryMqttSessionService(env.getProperty("sessions.clean.thread.interval", int.class, 60000)); |
| 61 | + } |
48 | 62 |
|
49 | | - @Bean |
50 | | - @NotNull CredentialSource credentialSource() { |
51 | | - return new FileCredentialsSource(env.getProperty("credentials.source.file.name", "credentials")); |
52 | | - } |
| 63 | + @Bean |
| 64 | + CredentialSource credentialSource() { |
| 65 | + return new FileCredentialsSource(env.getProperty("credentials.source.file.name", "credentials")); |
| 66 | + } |
53 | 67 |
|
54 | | - @Bean |
55 | | - @NotNull AuthenticationService authenticationService(@NotNull CredentialSource credentialSource) { |
56 | | - return new SimpleAuthenticationService( |
57 | | - credentialSource, |
58 | | - env.getProperty("authentication.allow.anonymous", boolean.class, false) |
59 | | - ); |
60 | | - } |
| 68 | + @Bean |
| 69 | + AuthenticationService authenticationService(CredentialSource credentialSource) { |
| 70 | + return new SimpleAuthenticationService( |
| 71 | + credentialSource, |
| 72 | + env.getProperty("authentication.allow.anonymous", boolean.class, false)); |
| 73 | + } |
61 | 74 |
|
62 | | - @Bean |
63 | | - PacketInHandler @NotNull [] packetHandlers( |
64 | | - @NotNull AuthenticationService authenticationService, |
65 | | - @NotNull ClientIdRegistry clientIdRegistry, |
66 | | - @NotNull SubscriptionService subscriptionService, |
67 | | - @NotNull PublishingService publishingService, |
68 | | - @NotNull MqttSessionService mqttSessionService |
69 | | - ) { |
| 75 | + @Bean |
| 76 | + PacketInHandler[] packetHandlers( |
| 77 | + AuthenticationService authenticationService, |
| 78 | + ClientIdRegistry clientIdRegistry, |
| 79 | + SubscriptionService subscriptionService, |
| 80 | + PublishingService publishingService, |
| 81 | + MqttSessionService mqttSessionService) { |
70 | 82 |
|
71 | | - var handlers = new PacketInHandler[PacketType.INVALID.ordinal()]; |
72 | | - handlers[PacketType.CONNECT.ordinal()] = new ConnectInPacketHandler( |
73 | | - clientIdRegistry, |
74 | | - authenticationService, |
75 | | - mqttSessionService, |
76 | | - subscriptionService |
77 | | - ); |
78 | | - handlers[PacketType.SUBSCRIBE.ordinal()] = new SubscribeInPacketHandler(subscriptionService); |
79 | | - handlers[PacketType.UNSUBSCRIBE.ordinal()] = new UnsubscribeInPacketHandler(subscriptionService); |
80 | | - handlers[PacketType.PUBLISH.ordinal()] = new PublishInPacketHandler(publishingService); |
81 | | - handlers[PacketType.DISCONNECT.ordinal()] = new DisconnetInPacketHandler(); |
82 | | - handlers[PacketType.PUBLISH_ACK.ordinal()] = new PublishAckInPacketHandler(); |
83 | | - handlers[PacketType.PUBLISH_RECEIVED.ordinal()] = new PublishReceiveInPacketHandler(); |
84 | | - handlers[PacketType.PUBLISH_RELEASED.ordinal()] = new PublishReleaseInPacketHandler(); |
85 | | - handlers[PacketType.PUBLISH_COMPLETED.ordinal()] = new PublishCompleteInPacketHandler(); |
| 83 | + var handlers = new PacketInHandler[PacketType.INVALID.ordinal()]; |
| 84 | + handlers[PacketType.CONNECT.ordinal()] = new ConnectInPacketHandler( |
| 85 | + clientIdRegistry, |
| 86 | + authenticationService, |
| 87 | + mqttSessionService, |
| 88 | + subscriptionService); |
| 89 | + handlers[PacketType.SUBSCRIBE.ordinal()] = new SubscribeInPacketHandler(subscriptionService); |
| 90 | + handlers[PacketType.UNSUBSCRIBE.ordinal()] = new UnsubscribeInPacketHandler(subscriptionService); |
| 91 | + handlers[PacketType.PUBLISH.ordinal()] = new PublishInPacketHandler(publishingService); |
| 92 | + handlers[PacketType.DISCONNECT.ordinal()] = new DisconnetInPacketHandler(); |
| 93 | + handlers[PacketType.PUBLISH_ACK.ordinal()] = new PublishAckInPacketHandler(); |
| 94 | + handlers[PacketType.PUBLISH_RECEIVED.ordinal()] = new PublishReceiveInPacketHandler(); |
| 95 | + handlers[PacketType.PUBLISH_RELEASED.ordinal()] = new PublishReleaseInPacketHandler(); |
| 96 | + handlers[PacketType.PUBLISH_COMPLETED.ordinal()] = new PublishCompleteInPacketHandler(); |
86 | 97 |
|
87 | | - return handlers; |
88 | | - } |
| 98 | + return handlers; |
| 99 | + } |
89 | 100 |
|
90 | | - @Bean |
91 | | - @NotNull MqttClientReleaseHandler mqttClientReleaseHandler( |
92 | | - @NotNull ClientIdRegistry clientIdRegistry, |
93 | | - @NotNull MqttSessionService mqttSessionService, |
94 | | - @NotNull SubscriptionService subscriptionService |
95 | | - ) { |
96 | | - return new DefaultMqttClientReleaseHandler( |
97 | | - clientIdRegistry, |
98 | | - mqttSessionService, |
99 | | - subscriptionService |
100 | | - ); |
101 | | - } |
| 101 | + @Bean |
| 102 | + MqttClientReleaseHandler mqttClientReleaseHandler( |
| 103 | + ClientIdRegistry clientIdRegistry, |
| 104 | + MqttSessionService mqttSessionService, |
| 105 | + SubscriptionService subscriptionService) { |
| 106 | + return new DefaultMqttClientReleaseHandler(clientIdRegistry, mqttSessionService, subscriptionService); |
| 107 | + } |
102 | 108 |
|
103 | | - @Bean |
104 | | - @NotNull SubscriptionService subscriptionService() { |
105 | | - return new SimpleSubscriptionService(); |
106 | | - } |
| 109 | + @Bean |
| 110 | + SubscriptionService subscriptionService() { |
| 111 | + return new SimpleSubscriptionService(); |
| 112 | + } |
107 | 113 |
|
108 | | - @Bean |
109 | | - @NotNull PublishOutHandler[] publishOutHandlers() { |
110 | | - return new PublishOutHandler[] { |
111 | | - new Qos0PublishOutHandler(), |
112 | | - new Qos1PublishOutHandler(), |
113 | | - new Qos2PublishOutHandler(), |
114 | | - }; |
115 | | - } |
| 114 | + @Bean |
| 115 | + PublishOutHandler[] publishOutHandlers() { |
| 116 | + return new PublishOutHandler[]{ |
| 117 | + new Qos0PublishOutHandler(), |
| 118 | + new Qos1PublishOutHandler(), |
| 119 | + new Qos2PublishOutHandler() |
| 120 | + }; |
| 121 | + } |
116 | 122 |
|
117 | | - @Bean |
118 | | - @NotNull PublishInHandler[] publishInHandlers( |
119 | | - @NotNull SubscriptionService subscriptionService, |
120 | | - @NotNull PublishOutHandler[] publishOutHandlers |
121 | | - ) { |
122 | | - return new PublishInHandler[] { |
123 | | - new Qos0PublishInHandler(subscriptionService, publishOutHandlers), |
124 | | - new Qos1PublishInHandler(subscriptionService, publishOutHandlers), |
125 | | - new Qos2PublishInHandler(subscriptionService, publishOutHandlers), |
126 | | - }; |
127 | | - } |
| 123 | + @Bean |
| 124 | + PublishInHandler[] publishInHandlers( |
| 125 | + SubscriptionService subscriptionService, |
| 126 | + PublishOutHandler[] publishOutHandlers) { |
| 127 | + return new PublishInHandler[]{ |
| 128 | + new Qos0PublishInHandler(subscriptionService, publishOutHandlers), |
| 129 | + new Qos1PublishInHandler(subscriptionService, publishOutHandlers), |
| 130 | + new Qos2PublishInHandler(subscriptionService, publishOutHandlers) |
| 131 | + }; |
| 132 | + } |
128 | 133 |
|
129 | | - @Bean |
130 | | - @NotNull PublishingService publishingService(@NotNull PublishInHandler[] publishInHandlers) { |
131 | | - return new DefaultPublishingService(publishInHandlers); |
132 | | - } |
| 134 | + @Bean |
| 135 | + PublishingService publishingService(PublishInHandler[] publishInHandlers) { |
| 136 | + return new DefaultPublishingService(publishInHandlers); |
| 137 | + } |
133 | 138 | } |
0 commit comments