Skip to content

[WIP]refactor: refactor java-sdk modules #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README-zh.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@

sdk-runtime/sdk-reactor
↑ ↑
sdk-domain -> sdk-grpc
↑ ↑
sdk-infrastructure spec-pb

## 如何使用java sdk
### 1. import sdk
对于 Maven 项目,将以下配置添加进 `pom.xml` 文件:
Expand Down
1 change: 1 addition & 0 deletions examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package io.mosn.layotto.examples.file;

import io.mosn.layotto.v1.RuntimeClientBuilder;
import io.mosn.layotto.v1.config.RuntimeProperties;
import io.mosn.layotto.v1.infrastructure.config.RuntimeProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import spec.sdk.runtime.v1.client.RuntimeClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package io.mosn.layotto.examples.helloworld;

import io.mosn.layotto.v1.RuntimeClientBuilder;
import io.mosn.layotto.v1.config.RuntimeProperties;
import io.mosn.layotto.v1.infrastructure.config.RuntimeProperties;
import spec.sdk.runtime.v1.client.RuntimeClient;

public class Hello {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package io.mosn.layotto.examples.pubsub.publisher;

import io.mosn.layotto.v1.RuntimeClientBuilder;
import io.mosn.layotto.v1.config.RuntimeProperties;
import io.mosn.layotto.v1.infrastructure.config.RuntimeProperties;
import spec.sdk.runtime.v1.client.RuntimeClient;

public class Publisher {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
package io.mosn.layotto.examples.pubsub.subscriber.impl;

import io.mosn.layotto.v1.callback.component.pubsub.Subscriber;
import io.mosn.layotto.v1.grpc.callback.component.pubsub.Subscriber;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import spec.sdk.runtime.v1.domain.pubsub.TopicEventRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package io.mosn.layotto.examples.state;

import io.mosn.layotto.v1.RuntimeClientBuilder;
import io.mosn.layotto.v1.config.RuntimeProperties;
import io.mosn.layotto.v1.infrastructure.config.RuntimeProperties;
import spec.sdk.runtime.v1.client.RuntimeClient;
import spec.sdk.runtime.v1.domain.state.GetBulkStateRequest;
import spec.sdk.runtime.v1.domain.state.State;
Expand All @@ -25,6 +25,7 @@
import java.util.List;

public class RedisCRUD {

static String storeName = "redis";
static String key1 = "key1";
static String key2 = "key2";
Expand Down
35 changes: 34 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
<url>https://github.com/mosn/layotto</url>

<modules>
<module>sdk</module>
<module>examples</module>
<module>sdk</module>
<module>sdk-reactor</module>
<module>spec</module>
<module>sdk-grpc</module>
<module>sdk-domain-rx</module>
<module>sdk-domain</module>
<module>sdk-infrastructure</module>
</modules>

<properties>
Expand All @@ -36,11 +40,37 @@
<artifactId>runtime-sdk</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.mosn.layotto</groupId>
<artifactId>runtime-sdk-reactor</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.mosn.layotto</groupId>
<artifactId>runtime-spec-pb</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.mosn.layotto</groupId>
<artifactId>runtime-sdk-grpc</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.mosn.layotto</groupId>
<artifactId>runtime-sdk-domain-rx</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.mosn.layotto</groupId>
<artifactId>runtime-sdk-domain</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.mosn.layotto</groupId>
<artifactId>runtime-sdk-infrastructure</artifactId>
<version>${project.version}</version>
</dependency>

<!-- json -->
<dependency>
<groupId>com.alibaba</groupId>
Expand Down Expand Up @@ -76,6 +106,7 @@
<artifactId>grpc-stub</artifactId>
<version>${grpc.version}</version>
</dependency>

<!-- unit test -->
<dependency>
<groupId>org.mockito</groupId>
Expand Down Expand Up @@ -203,6 +234,7 @@
<url>http://github.com/mosn/layotto</url>
<connection>scm:git:https://github.com/mosn/layotto.git</connection>
</scm>

<profiles>
<profile>
<id>release</id>
Expand Down Expand Up @@ -260,4 +292,5 @@
</distributionManagement>
</profile>
</profiles>

</project>
35 changes: 35 additions & 0 deletions sdk-domain-rx/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>runtime-sdk-parent</artifactId>
<groupId>io.mosn.layotto</groupId>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>runtime-sdk-domain-rx</artifactId>
<name>runtime-sdk-domain-rx</name>
<description>Reactor domain definition for Runtime</description>
<packaging>jar</packaging>

<properties>
<reactor-core.version>3.4.12</reactor-core.version>
</properties>

<dependencies>
<dependency>
<groupId>io.mosn.layotto</groupId>
<artifactId>runtime-sdk-domain</artifactId>
</dependency>

<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>${reactor-core.version}</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright 2021 Layotto Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package spec.sdk.runtime.v1.domain.rx;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import spec.sdk.runtime.v1.domain.ConfigurationRuntime;
import spec.sdk.runtime.v1.domain.configuration.ConfigurationItem;
import spec.sdk.runtime.v1.domain.configuration.ConfigurationRequestItem;
import spec.sdk.runtime.v1.domain.configuration.SaveConfigurationRequest;
import spec.sdk.runtime.v1.domain.configuration.SubConfigurationResp;

import java.util.List;

public interface ConfigurationRxRuntime extends ConfigurationRuntime {

/**
* Gets configuration from configuration store
*
* @param configurationRequestItem Request object.
*/
@Override
default List<ConfigurationItem> getConfiguration(ConfigurationRequestItem configurationRequestItem) {
return getConfigurationAsync(configurationRequestItem).block();
}

Mono<List<ConfigurationItem>> getConfigurationAsync(ConfigurationRequestItem configurationRequestItem);

/**
* Saves configuration into configuration store.
* ø
*
* @param saveConfigurationRequest Request object.
*/
@Override
default void saveConfiguration(SaveConfigurationRequest saveConfigurationRequest) {
saveConfigurationAsync(saveConfigurationRequest).block();
}

Mono<Void> saveConfigurationAsync(SaveConfigurationRequest saveConfigurationRequest);

/**
* Deletes configuration from configuration store.
*
* @param configurationRequestItem Request object.
*/
@Override
default void deleteConfiguration(ConfigurationRequestItem configurationRequestItem) {
deleteConfigurationAsync(configurationRequestItem).block();
}

Mono<Void> deleteConfigurationAsync(ConfigurationRequestItem configurationRequestItem);

/**
* Gets configuration from configuration store and subscribe the updates.
*
* @param configurationRequestItem Request object.
*/
@Override
default void subscribeConfiguration(ConfigurationRequestItem configurationRequestItem, Subscriber subscriber) {
Flux<SubConfigurationResp> subscribeConfigurationAsync = subscribeConfigurationAsync(configurationRequestItem);
subscribeConfigurationAsync.subscribe(
subscriber::onNext,
subscriber::onError,
subscriber::onComplete);
}

Flux<SubConfigurationResp> subscribeConfigurationAsync(ConfigurationRequestItem configurationRequestItem);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright 2021 Layotto Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package spec.sdk.runtime.v1.domain.rx;

import reactor.core.publisher.Mono;
import spec.sdk.runtime.v1.domain.FileRuntime;
import spec.sdk.runtime.v1.domain.file.DelFileRequest;
import spec.sdk.runtime.v1.domain.file.DelFileResponse;
import spec.sdk.runtime.v1.domain.file.GetFileRequest;
import spec.sdk.runtime.v1.domain.file.GetFileResponse;
import spec.sdk.runtime.v1.domain.file.GetMetaRequest;
import spec.sdk.runtime.v1.domain.file.GetMeteResponse;
import spec.sdk.runtime.v1.domain.file.ListFileRequest;
import spec.sdk.runtime.v1.domain.file.ListFileResponse;
import spec.sdk.runtime.v1.domain.file.PutFileRequest;
import spec.sdk.runtime.v1.domain.file.PutFileResponse;

public interface FileRxRuntime extends FileRuntime {

/**
* save or update file
*
* @param request the put request
* @param timeoutMs If the time is less than or equal to zero, the method will not wait at all.
* @throws Exception Instance of RuntimeClientException Or StatusRuntimeException
*/
@Override
default PutFileResponse putFile(PutFileRequest request, int timeoutMs) throws Exception {
return putFileAsync(request, timeoutMs).block();
}

Mono<PutFileResponse> putFileAsync(PutFileRequest request, int timeoutMs) throws Exception;

/**
* @param request the get request
* @param timeoutMs If the time is less than or equal to zero, the method will not wait at all.
* @throws Exception Instance of RuntimeClientException Or StatusRuntimeException
*/
@Override
default GetFileResponse getFile(GetFileRequest request, int timeoutMs) throws Exception {
return getFileAsync(request, timeoutMs).block();
}

Mono<GetFileResponse> getFileAsync(GetFileRequest request, int timeoutMs) throws Exception;

/**
* @param request the list requset
* @param timeoutMs If the time is less than or equal to zero, the method will not wait at all.
* @throws Exception Instance of RuntimeClientException Or StatusRuntimeException
*/
@Override
default ListFileResponse listFile(ListFileRequest request, int timeoutMs) throws Exception {
return listFileAsync(request, timeoutMs).block();
}

Mono<ListFileResponse> listFileAsync(ListFileRequest request, int timeoutMs) throws Exception;

/**
* @param request the del request
* @param timeoutMs If the time is less than or equal to zero, the method will not wait at all.
* @throws Exception Instance of RuntimeClientException Or StatusRuntimeException
*/
@Override
default DelFileResponse delFile(DelFileRequest request, int timeoutMs) throws Exception {
return delFileAsync(request, timeoutMs).block();
}

Mono<DelFileResponse> delFileAsync(DelFileRequest request, int timeoutMs) throws Exception;

/**
* @param request the get meta request
* @param timeoutMs If the time is less than or equal to zero, the method will not wait at all.
* @throws Exception Instance of RuntimeClientException Or StatusRuntimeException
*/
@Override
default GetMeteResponse getFileMeta(GetMetaRequest request, int timeoutMs) throws Exception {
return getFileMetaAsync(request, timeoutMs).block();
}

Mono<GetMeteResponse> getFileMetaAsync(GetMetaRequest request, int timeoutMs) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.mosn.layotto.v1.config;
package spec.sdk.runtime.v1.domain.rx;

/**
* Boolean configuration property.
*/
public class BooleanProperty extends Property<Boolean> {
import reactor.core.publisher.Mono;
import spec.sdk.runtime.v1.domain.HelloRuntime;

public interface HelloRxRuntime extends HelloRuntime {

/**
* {@inheritDoc}
*/
BooleanProperty(String name, String envName, Boolean defaultValue) {
super(name, envName, defaultValue);
@Override
default String sayHello(String name) {
return sayHelloAsync(name).block();
}

/**
* {@inheritDoc}
*/
Mono<String> sayHelloAsync(String name);

@Override
protected Boolean parse(String value) {
return Boolean.valueOf(value);
default String sayHello(String name, int timeoutMillisecond) {
return sayHelloAsync(name, timeoutMillisecond).block();
}

Mono<String> sayHelloAsync(String name, int timeoutMillisecond);
}
Loading