forked from Linyuzai/concept
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tanghanzheng
committed
Apr 26, 2022
1 parent
331172a
commit 54ce5e2
Showing
30 changed files
with
190 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
...com/github/linyuzai/connection/loadbalance/core/concept/ConnectionLoadBalanceConcept.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...ithub/linyuzai/connection/loadbalance/core/concept/ConnectionLoadBalanceConceptAware.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.github.linyuzai.connection.loadbalance.core.concept; | ||
|
||
public interface ConnectionLoadBalanceConceptAware<T extends ConnectionLoadBalanceConcept> { | ||
|
||
void setConnectionLoadBalanceConcept(T concept); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...in/java/com/github/linyuzai/connection/loadbalance/core/select/MessageHeaderSelector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.github.linyuzai.connection.loadbalance.core.select; | ||
|
||
import com.github.linyuzai.connection.loadbalance.core.concept.Connection; | ||
import com.github.linyuzai.connection.loadbalance.core.concept.Connections; | ||
import com.github.linyuzai.connection.loadbalance.core.message.Message; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public abstract class MessageHeaderSelector extends AbstractConnectionSelector { | ||
|
||
private String name; | ||
|
||
@Override | ||
public boolean support(Message message) { | ||
return message.getHeaders().containsKey(name); | ||
} | ||
|
||
@Override | ||
public Connection doSelect(Message message, Collection<Connection> connections) { | ||
String header = message.getHeaders().get(name); | ||
List<Connection> list = connections.stream() | ||
.filter(it -> match(it, header)) | ||
.collect(Collectors.toList()); | ||
return Connections.of(list); | ||
} | ||
|
||
public abstract boolean match(Connection connection, String header); | ||
} |
30 changes: 5 additions & 25 deletions
30
...rc/main/java/com/github/linyuzai/connection/loadbalance/core/select/MetadataSelector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,17 @@ | ||
package com.github.linyuzai.connection.loadbalance.core.select; | ||
|
||
import com.github.linyuzai.connection.loadbalance.core.concept.Connection; | ||
import com.github.linyuzai.connection.loadbalance.core.concept.Connections; | ||
import com.github.linyuzai.connection.loadbalance.core.message.Message; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class MetadataSelector extends AbstractConnectionSelector { | ||
public class MetadataSelector extends MessageHeaderSelector { | ||
|
||
private String name; | ||
|
||
@Override | ||
public boolean support(Message message) { | ||
return message.getHeaders().containsKey(name); | ||
public MetadataSelector(String name) { | ||
super(name); | ||
} | ||
|
||
@Override | ||
public Connection doSelect(Message message, Collection<Connection> connections) { | ||
String header = message.getHeaders().get(name); | ||
List<Connection> list = connections.stream() | ||
.filter(it -> match(it.getMetadata().get(name), header)) | ||
.collect(Collectors.toList()); | ||
return Connections.of(list); | ||
} | ||
|
||
public boolean match(Object metadata, String header) { | ||
return Objects.equals(metadata, header); | ||
public boolean match(Connection connection, String header) { | ||
return Objects.equals(connection.getMetadata().get(getName()), header); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...src/main/java/com/github/linyuzai/connection/loadbalance/core/select/UriPathSelector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.github.linyuzai.connection.loadbalance.core.select; | ||
|
||
import com.github.linyuzai.connection.loadbalance.core.concept.Connection; | ||
|
||
import java.util.Objects; | ||
|
||
public class UriPathSelector extends MessageHeaderSelector { | ||
|
||
public static final String KEY = "uri_path"; | ||
|
||
public UriPathSelector() { | ||
super(KEY); | ||
} | ||
|
||
@Override | ||
public boolean match(Connection connection, String header) { | ||
return Objects.equals(connection.getUri().getPath(), header); | ||
} | ||
} |
10 changes: 0 additions & 10 deletions
10
...ore/src/main/java/com/github/linyuzai/connection/loadbalance/core/select/UriSelector.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
.../github/linyuzai/connection/loadbalance/websocket/concept/WebSocketConnectionFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,7 @@ | ||
package com.github.linyuzai.connection.loadbalance.websocket.concept; | ||
|
||
import com.github.linyuzai.connection.loadbalance.core.concept.AbstractConnectionFactory; | ||
import com.github.linyuzai.connection.loadbalance.core.concept.Connection; | ||
import com.github.linyuzai.connection.loadbalance.core.message.MessageCodecAdapter; | ||
|
||
import java.util.Map; | ||
|
||
public abstract class WebSocketConnectionFactory<T extends WebSocketConnection> | ||
extends AbstractConnectionFactory<T, WebSocketLoadBalanceConcept> { | ||
|
||
@Override | ||
public T doCreate(Object o, Map<Object, Object> metadata, WebSocketLoadBalanceConcept concept) { | ||
T connection = doCreate(o, metadata); | ||
MessageCodecAdapter adapter = concept.getMessageCodecAdapter(); | ||
connection.setMessageEncoder(adapter.getMessageEncoder(Connection.Type.CLIENT)); | ||
connection.setMessageDecoder(adapter.getMessageDecoder(Connection.Type.CLIENT)); | ||
connection.setConcept(concept); | ||
return connection; | ||
} | ||
|
||
public abstract T doCreate(Object o, Map<Object, Object> metadata); | ||
} |
Oops, something went wrong.