forked from apache/fineract
-
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.
FINERACT-2169: New command processing infrastructure
- Loading branch information
Showing
35 changed files
with
1,510 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
description = 'Fineract Command' | ||
|
||
apply plugin: 'java' | ||
apply plugin: 'eclipse' | ||
apply plugin: 'me.champeau.jmh' | ||
|
||
configurations { | ||
asciidoctorExtensions | ||
providedRuntime // needed for Spring Boot executable WAR | ||
providedCompile | ||
compile() { | ||
exclude module: 'hibernate-entitymanager' | ||
exclude module: 'hibernate-validator' | ||
exclude module: 'activation' | ||
exclude module: 'bcmail-jdk14' | ||
exclude module: 'bcprov-jdk14' | ||
exclude module: 'bctsp-jdk14' | ||
exclude module: 'c3p0' | ||
exclude module: 'stax-api' | ||
exclude module: 'jaxb-api' | ||
exclude module: 'jaxb-impl' | ||
exclude module: 'jboss-logging' | ||
exclude module: 'itext-rtf' | ||
exclude module: 'classworlds' | ||
} | ||
runtime | ||
} | ||
|
||
apply from: 'dependencies.gradle' | ||
|
||
// Configuration for the modernizer plugin | ||
// https://github.com/andygoossens/gradle-modernizer-plugin | ||
modernizer { | ||
ignoreClassNamePatterns = [ | ||
'.*AbstractPersistableCustom', | ||
'.*EntityTables', | ||
'.*domain.*' | ||
] | ||
} | ||
|
||
// If we are running Gradle within Eclipse to enhance classes with OpenJPA, | ||
// set the classes directory to point to Eclipse's default build directory | ||
if (project.hasProperty('env') && project.getProperty('env') == 'eclipse') { | ||
sourceSets.main.java.outputDir = new File(rootProject.projectDir, "fineract-command/bin/main") | ||
} | ||
|
||
if (!(project.hasProperty('env') && project.getProperty('env') == 'dev')) { | ||
sourceSets { | ||
test { | ||
java { | ||
exclude '**/core/boot/tests/**' | ||
} | ||
} | ||
} | ||
} | ||
|
||
jmh { | ||
// include = ['.*'] // Include all benchmarks (regex-based filter) | ||
warmupIterations = 3 // Number of warm-up iterations | ||
iterations = 5 // Number of measurement iterations | ||
fork = 2 // Number of forks | ||
timeOnIteration = '1s' // Time per iteration | ||
benchmarkMode = ['thrpt'] // Default benchmark mode | ||
} |
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,60 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
|
||
dependencies { | ||
implementation( | ||
'org.springframework.boot:spring-boot-starter', | ||
'org.springframework.boot:spring-boot-starter-validation', | ||
'io.github.resilience4j:resilience4j-spring-boot3', | ||
|
||
'com.google.guava:guava', | ||
|
||
'org.apache.commons:commons-lang3', | ||
|
||
'com.github.spotbugs:spotbugs-annotations', | ||
'org.mapstruct:mapstruct', | ||
'com.lmax:disruptor:3.4.4', | ||
) | ||
implementation('org.eclipse.persistence:org.eclipse.persistence.jpa') { | ||
exclude group: 'org.eclipse.persistence', module: 'jakarta.persistence' | ||
} | ||
|
||
compileOnly 'org.projectlombok:lombok' | ||
annotationProcessor 'org.projectlombok:lombok' | ||
annotationProcessor 'org.mapstruct:mapstruct-processor' | ||
annotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess:1.37' | ||
|
||
asciidoctorExtensions 'org.springframework.restdocs:spring-restdocs-asciidoctor:3.0.3' | ||
|
||
testImplementation ('org.springframework.boot:spring-boot-starter-test') { | ||
exclude group: 'com.jayway.jsonpath', module: 'json-path' | ||
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' | ||
exclude group: 'jakarta.activation' | ||
exclude group: 'javax.activation' | ||
exclude group: 'org.skyscreamer' | ||
} | ||
testImplementation ( | ||
'org.springframework.boot:spring-boot-starter-web', | ||
'org.mockito:mockito-inline', | ||
'org.openjdk.jmh:jmh-core:1.37', | ||
'org.springframework.restdocs:spring-restdocs-mockmvc:3.0.3', | ||
'org.springframework.restdocs:spring-restdocs-webtestclient:3.0.3', | ||
'org.springframework.restdocs:spring-restdocs-restassured:3.0.3', | ||
) | ||
} |
40 changes: 40 additions & 0 deletions
40
fineract-command/src/main/java/org/apache/fineract/command/core/Command.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,40 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.fineract.command.core; | ||
|
||
import java.io.Serial; | ||
import java.io.Serializable; | ||
import java.time.Instant; | ||
import java.util.UUID; | ||
import lombok.Data; | ||
import lombok.experimental.FieldNameConstants; | ||
|
||
@Data | ||
@FieldNameConstants | ||
public abstract class Command<T> implements Serializable { | ||
|
||
@Serial | ||
private static final long serialVersionUID = 1L; | ||
|
||
private UUID id; | ||
private Instant createdAt; | ||
private String tenantId; | ||
private String username; | ||
private T payload; | ||
} |
27 changes: 27 additions & 0 deletions
27
fineract-command/src/main/java/org/apache/fineract/command/core/CommandConstants.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,27 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.fineract.command.core; | ||
|
||
import lombok.experimental.UtilityClass; | ||
|
||
@UtilityClass | ||
public final class CommandConstants { | ||
|
||
public static final String COMMAND_REQUEST_ID = "x-fineract-request-id"; | ||
} |
26 changes: 26 additions & 0 deletions
26
fineract-command/src/main/java/org/apache/fineract/command/core/CommandExecutor.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,26 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.fineract.command.core; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public interface CommandExecutor { | ||
|
||
<REQ, RES> Supplier<RES> execute(Command<REQ> command); | ||
} |
32 changes: 32 additions & 0 deletions
32
fineract-command/src/main/java/org/apache/fineract/command/core/CommandHandler.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,32 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.fineract.command.core; | ||
|
||
import com.google.common.reflect.TypeToken; | ||
|
||
public interface CommandHandler<REQ, RES> { | ||
|
||
RES handle(Command<REQ> command); | ||
|
||
default boolean matches(Command<REQ> command) { | ||
TypeToken<REQ> handlerType = new TypeToken<>(getClass()) {}; | ||
|
||
return handlerType.getRawType().isAssignableFrom(command.getPayload().getClass()); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
fineract-command/src/main/java/org/apache/fineract/command/core/CommandMiddleware.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,25 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.fineract.command.core; | ||
|
||
@FunctionalInterface | ||
public interface CommandMiddleware { | ||
|
||
void invoke(Command<?> command); | ||
} |
26 changes: 26 additions & 0 deletions
26
fineract-command/src/main/java/org/apache/fineract/command/core/CommandPipeline.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,26 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.fineract.command.core; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public interface CommandPipeline { | ||
|
||
<REQ, RES> Supplier<RES> send(Command<REQ> command); | ||
} |
53 changes: 53 additions & 0 deletions
53
fineract-command/src/main/java/org/apache/fineract/command/core/CommandProperties.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,53 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.fineract.command.core; | ||
|
||
import java.io.Serial; | ||
import java.io.Serializable; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.experimental.FieldNameConstants; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@Builder | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@FieldNameConstants | ||
@ConfigurationProperties(prefix = "fineract.command") | ||
public final class CommandProperties implements Serializable { | ||
|
||
@Serial | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Builder.Default | ||
private Boolean enabled = true; | ||
|
||
@Builder.Default | ||
private CommandExecutorType executor = CommandExecutorType.sync; | ||
|
||
@Builder.Default | ||
private Integer ringBufferSize = 1024; | ||
|
||
public enum CommandExecutorType { | ||
sync, async, disruptor | ||
} | ||
} |
Oops, something went wrong.