Skip to content

Commit

Permalink
♻️ Refactor change stream to use mongo sync driver now possible thank…
Browse files Browse the repository at this point in the history
…s to virtual threads
  • Loading branch information
ujibang committed Feb 17, 2024
1 parent 85e6b31 commit b39b610
Show file tree
Hide file tree
Showing 30 changed files with 482 additions and 791 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ jobs:
restore-keys: |
${{ runner.os }}-maven-
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
distribution: "temurin"
java-version: "17"
java-version: "21"

- name: Set VERSION and SHA
id: vars
Expand Down
4 changes: 0 additions & 4 deletions commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-reactivestreams</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down
10 changes: 10 additions & 0 deletions commons/src/main/java/org/restheart/utils/BsonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class BsonUtils {
static final Logger LOGGER = LoggerFactory.getLogger(BsonUtils.class);

private static final BsonArrayCodec BSON_ARRAY_CODEC = new BsonArrayCodec(CodecRegistries.fromProviders(new BsonValueCodecProvider()));
private static final CodecRegistry REGISTRY = CodecRegistries.fromCodecs(new DocumentCodec());

private static final String ESCAPED_DOLLAR = "_$";
private static final String ESCAPED_DOT = "::";
Expand Down Expand Up @@ -951,6 +952,15 @@ public static Document bsonToDocument(BsonDocument bsonDocument) {
return codec.decode(new BsonDocumentReader(bsonDocument), decoderContext);
}

/**
* convert Document to BsonDocument
* @param document
* @return
*/
public static BsonValue documentToBson(Document document) {
return document == null ? BsonNull.VALUE : document.toBsonDocument(BsonDocument.class, REGISTRY);
}

/**
*
* @return a DocumentBuilder to help building BsonDocument
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/restheart/services/PingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
secure = false,
enabledByDefault = true,
defaultURI = "/ping",
blocking = false)
blocking = true)
public class PingService implements ByteArrayService {
private String msg = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,6 @@
"allDeclaredMethods":true,
"allDeclaredConstructors":true
},
{
"name":"com.mongodb.reactivestreams.client.MongoClient"
},
{
"name":"com.sun.akuma.CLibrary",
"methods":[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ jwtTokenManager:
# - foo # property name
# - /nested/property # xpath expr for nested properties

# Provider the MongoClient via @Inject('mclient') and @Inject('mclient-reactive')
# Provider the MongoClient via @Inject('mclient')
mclient:
enabled: false
# see https://docs.mongodb.com/manual/reference/connection-string/
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/restheart-default-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ jwtTokenManager:
# - foo # property name
# - /nested/property # xpath expr for nested properties

# Provider the MongoClient via @Inject('mclient') and @Inject('mclient-reactive')
# Provider the MongoClient via @Inject('mclient')
mclient:
# see https://docs.mongodb.com/manual/reference/connection-string/
connection-string: mongodb://127.0.0.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public abstract class AbstactIT {

LOG.info("BASE_URL={}", HTTP_HOST.toURI());
LOG.info("mongo-uri={}", MONGO_URI.toString());
RHMongoClients.setClients(com.mongodb.client.MongoClients.create(MONGO_URI), null);
RHMongoClients.setClients(com.mongodb.client.MongoClients.create(MONGO_URI));
}

/**
Expand Down
4 changes: 0 additions & 4 deletions mongoclient/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-reactivestreams</artifactId>
</dependency>
<!-- BEGIN Test dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ public void init() {

// force first connection to MongoDb
MongoClientSingleton.getInstance().client();

// init the reactive client
MongoReactiveClientProvider.init(mongoConnetion);
}

@Override
Expand Down

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions mongodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-reactivestreams</artifactId>
</dependency>
<dependency>
<groupId>com.github.everit-org.json-schema</groupId>
<artifactId>org.everit.json.schema</artifactId>
Expand Down
19 changes: 5 additions & 14 deletions mongodb/src/main/java/org/restheart/mongodb/RHMongoClients.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,26 @@
import org.restheart.plugins.RegisterPlugin;

import com.google.common.annotations.VisibleForTesting;
import com.mongodb.client.MongoClient;

/**
*
* @author Andrea Di Cesare {@literal <[email protected]>}
*/
@RegisterPlugin(name = "mongoClients",
description = "helper singleton that holds the MongoClients",
description = "helper singleton that holds the MongoClient",
initPoint = InitPoint.BEFORE_STARTUP,
priority = -10)
public class RHMongoClients implements Initializer {

@Inject("mclient")
private com.mongodb.client.MongoClient mclient;
private MongoClient mclient;

@Inject("mclient-reactive")
private com.mongodb.reactivestreams.client.MongoClient mclientReactive;

private static com.mongodb.client.MongoClient MC_HOLDER;
private static com.mongodb.reactivestreams.client.MongoClient MCR_HOLDER;
private static MongoClient MC_HOLDER;

@OnInit
public void onInit() {
MC_HOLDER = mclient;
MCR_HOLDER = mclientReactive;
}

@Override
Expand All @@ -61,13 +57,8 @@ public static com.mongodb.client.MongoClient mclient() {
return MC_HOLDER;
}

public static com.mongodb.reactivestreams.client.MongoClient mclientReactive() {
return MCR_HOLDER;
}

@VisibleForTesting
public static void setClients(com.mongodb.client.MongoClient mclient, com.mongodb.reactivestreams.client.MongoClient mclientReactive) {
public static void setClients(MongoClient mclient) {
MC_HOLDER = mclient;
MCR_HOLDER = mclientReactive;
}
}
Loading

0 comments on commit b39b610

Please sign in to comment.