Skip to content

Commit

Permalink
connection netty
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghanzheng committed Apr 20, 2022
1 parent 73165fb commit 3e7df74
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 1 deletion.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ allprojects {
set('cglibVersion', "3.3.0")
set('okhttpVersion', "4.9.3")
set('jacksonVersion', "2.13.1")
set('nettyVersion', "4.1.72.Final")
set('lombokVersion', "1.18.22")
set('junitJupiterVersion', "5.8.1")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public T addMessageFactories(Collection<? extends MessageFactory> factories) {
return (T) this;
}

public void preBuild() {
protected void preBuild() {
if (connectionServerProvider == null) {
throw new ConnectionLoadBalanceException("ConnectionServerProvider is null");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
plugins {
id 'java'
}

apply from: '../version.gradle'

group 'com.github.linyuzai'
version "${conceptConnectionLoadbalanceVersion}"
sourceCompatibility = '1.8'

repositories {
mavenCentral()
}

dependencies {
compileOnly project(path: ':concept-connection-loadbalance:concept-connection-loadbalance-core', configuration: 'default')

compileOnly "io.netty:netty-all:${nettyVersion}"

compileOnly "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}"
}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.github.linyuzai.connection.loadbalance.netty.concept;

public class NettyLoadBalanceConcept {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
plugins {
id 'java'
}

apply from: '../version.gradle'

group 'com.github.linyuzai'
version "${conceptConnectionLoadbalanceVersion}"
sourceCompatibility = '1.8'

repositories {
mavenCentral()
}

dependencies {

compileOnly project(':concept-connection-loadbalance:concept-connection-loadbalance-core')
compileOnly project(':concept-connection-loadbalance:concept-connection-loadbalance-discovery')
compileOnly project(':concept-connection-loadbalance:concept-connection-loadbalance-websocket')

compileOnly "org.springframework.boot:spring-boot-starter:${springBootVersion}"
compileOnly "org.springframework.cloud:spring-cloud-starter:${springCloudVersion}"
compileOnly "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}"
}

test {
useJUnitPlatform()
}

//apply from: '../publish.gradle'
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.github.linyuzai.connection.loadbalance.autoconfigure.websocket;

import com.github.linyuzai.connection.loadbalance.core.event.DefaultConnectionEventPublisher;
import lombok.AllArgsConstructor;
import org.springframework.context.ApplicationEventPublisher;

@AllArgsConstructor
public class ApplicationConnectionEventPublisher extends DefaultConnectionEventPublisher {

private ApplicationEventPublisher publisher;

@Override
public void publish(Object event) {
super.publish(event);
publisher.publishEvent(event);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.github.linyuzai.connection.loadbalance.autoconfigure.websocket;

import org.springframework.context.annotation.Import;

import java.lang.annotation.*;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Import({WebSocketDiscoveryConfiguration.class, WebSocketLoadBalanceConfiguration.class})
public @interface EnableWebSocketLoadBalanceConcept {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.github.linyuzai.connection.loadbalance.autoconfigure.websocket;

import com.github.linyuzai.connection.loadbalance.core.server.ConnectionServerProvider;
import com.github.linyuzai.connection.loadbalance.discovery.DiscoveryConnectionServerProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({DiscoveryClient.class, Registration.class})
public class WebSocketDiscoveryConfiguration {

@Bean
@ConditionalOnMissingBean
public ConnectionServerProvider connectionServerProvider(DiscoveryClient client, Registration registration) {
return new DiscoveryConnectionServerProvider(client, registration);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.github.linyuzai.connection.loadbalance.autoconfigure.websocket;

import com.github.linyuzai.connection.loadbalance.core.concept.ConnectionFactory;
import com.github.linyuzai.connection.loadbalance.core.event.ConnectionEventPublisher;
import com.github.linyuzai.connection.loadbalance.core.message.MessageFactory;
import com.github.linyuzai.connection.loadbalance.core.proxy.ConnectionProxy;
import com.github.linyuzai.connection.loadbalance.core.select.ConnectionSelector;
import com.github.linyuzai.connection.loadbalance.core.server.ConnectionServerProvider;
import com.github.linyuzai.connection.loadbalance.websocket.concept.WebSocketLoadBalanceConcept;
import com.github.linyuzai.connection.loadbalance.websocket.proxy.WebSocketConnectionProxy;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration(proxyBeanMethods = false)
public class WebSocketLoadBalanceConfiguration {

@Bean
@ConditionalOnMissingBean
public ConnectionProxy connectionProxy() {
return new WebSocketConnectionProxy();
}

@Bean
@ConditionalOnMissingBean
public ConnectionEventPublisher connectionEventPublisher(ApplicationEventPublisher publisher) {
return new ApplicationConnectionEventPublisher(publisher);
}

@Bean
@ConditionalOnMissingBean
public WebSocketLoadBalanceConcept webSocketLoadBalanceConcept(
ConnectionServerProvider provider,
ConnectionProxy proxy,
List<ConnectionFactory> connectionFactories,
List<ConnectionSelector> connectionSelectors,
List<MessageFactory> messageFactories,
ConnectionEventPublisher publisher) {
return new WebSocketLoadBalanceConcept.Builder()
.connectionServerProvider(provider)
.connectionProxy(proxy)
.addConnectionFactories(connectionFactories)
.addConnectionSelectors(connectionSelectors)
.addMessageFactories(messageFactories)
.eventPublisher(publisher)
.build();
}
}
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ rootProject.name = 'concept'
include 'concept-connection-loadbalance'
include 'concept-connection-loadbalance:concept-connection-loadbalance-core'
include 'concept-connection-loadbalance:concept-connection-loadbalance-discovery'
include 'concept-connection-loadbalance:concept-connection-loadbalance-netty'
include 'concept-connection-loadbalance:concept-connection-loadbalance-websocket'
include 'concept-connection-loadbalance:concept-connection-loadbalance-spring-boot-starter'
include 'concept-download'
include 'concept-download:concept-download-core'
include 'concept-download:concept-download-source-okhttp'
Expand Down

0 comments on commit 3e7df74

Please sign in to comment.