Skip to content
Merged
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
12 changes: 10 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ compile() {
errcheck $?
}

format() {
mvn spotless:apply
errcheck $?
}

test() {
mvn test
errcheck $?
Expand Down Expand Up @@ -60,9 +65,9 @@ deploy() {

if [[ "$#" == "0" ]]; then
clean
format
jar
javadoc
#trace_test
native_test
else
for a in "$@"; do
Expand All @@ -73,6 +78,9 @@ else
compile)
compile
;;
format)
format
;;
test)
test
;;
Expand All @@ -88,7 +96,7 @@ else
sver)
sver $2
;;
'trace_test')
'trace-test')
trace_test
;;
'native-test')
Expand Down
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.3</version>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.44.5</version>
<configuration>
<java>
<googleJavaFormat/>
</java>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
6 changes: 1 addition & 5 deletions src/main/java/com/github/sttk/sabi/AsyncGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@
*/
package com.github.sttk.sabi;

import com.github.sttk.errs.Exc;

import java.util.Map;
import java.util.HashMap;

public interface AsyncGroup {
record RunnerFailed() {}

record RunnerInterrupted() {}

void add(final Runner runner);
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/github/sttk/sabi/DataConn.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@

public interface DataConn {
void commit(AsyncGroup ag) throws Exc;

default void preCommit(AsyncGroup ag) throws Exc {}

default void postCommit(AsyncGroup ag) {}
default boolean shouldForceBack() { return false; }

default boolean shouldForceBack() {
return false;
}

void rollback(AsyncGroup ag);

default void forceBack(AsyncGroup ag) {}

void close();
}
15 changes: 11 additions & 4 deletions src/main/java/com/github/sttk/sabi/DataHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,29 @@
*/
package com.github.sttk.sabi;

import com.github.sttk.sabi.internal.DataHubInner;
import com.github.sttk.errs.Exc;
import com.github.sttk.sabi.internal.DataHubInner;
import java.util.Map;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicBoolean;

public class DataHub implements DataAcc, AutoCloseable {
public class DataHub implements DataAcc, AutoCloseable {
public record FailToSetupGlobalDataSrcs(Map<String, Exc> errors) {}

public record FailToSetupLocalDataSrcs(Map<String, Exc> errors) {}

public record FailToCommitDataConn(Map<String, Exc> errors) {}

public record FailToPreCommitDataConn(Map<String, Exc> errors) {}

public record NoDataSrcToCreateDataConn(String name, String dataConnType) {}

public record FailToCreateDataConn(String name, String dataConnType) {}

public record CreatedDataConnIsNull(String name, String dataConnType) {}

public record FailToCastDataConn(String name, String castToType) {}

public record FailToCastDataHub(String castFromType) {}

public record RuntimeExceptionOccured() {}

private final DataHubInner inner = new DataHubInner();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/github/sttk/sabi/DataSrc.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

public interface DataSrc {
void setup(AsyncGroup ag) throws Exc;

void close();

DataConn createDataConn() throws Exc;
}
11 changes: 4 additions & 7 deletions src/main/java/com/github/sttk/sabi/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@

import com.github.sttk.errs.Exc;

/**
* {@code Runner} is the interface that runs any procedure.
*/
/** {@code Runner} is the interface that runs any procedure. */
@FunctionalInterface
public interface Runner {

/**
* Runs the procedure that this instance represents.
* This method takes no argument and returns nothing.
* And this method throws an {@link Exc} exception if this method failed.
* Runs the procedure that this instance represents. This method takes no argument and returns
* nothing. And this method throws an {@link Exc} exception if this method failed.
*
* @throws Exc If this method failed.
* @throws Exc If this method failed.
*/
void run() throws Exc;
}
6 changes: 1 addition & 5 deletions src/main/java/com/github/sttk/sabi/Sabi.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
*/
package com.github.sttk.sabi;

import com.github.sttk.sabi.internal.DataHubInner;
import com.github.sttk.errs.Exc;
import java.util.Map;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import com.github.sttk.sabi.internal.DataHubInner;

public final class Sabi {
private Sabi() {}
Expand All @@ -21,4 +18,3 @@ public static AutoCloseable setup() throws Exc {
return DataHubInner.setupGlobals();
}
}

22 changes: 12 additions & 10 deletions src/main/java/com/github/sttk/sabi/internal/AsyncGroupImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import com.github.sttk.errs.Exc;
import com.github.sttk.sabi.AsyncGroup;
import com.github.sttk.sabi.Runner;

import java.util.Map;
import java.util.HashMap;

public class AsyncGroupImpl implements AsyncGroup {
private ExcEntry excHead;
Expand All @@ -23,13 +21,16 @@ public AsyncGroupImpl() {}
@Override
public void add(final Runner runner) {
final var name = this.name;
var vth = Thread.ofVirtual().start(() -> {
try {
runner.run();
} catch (Exc | RuntimeException e) {
addExc(name, e);
}
});
var vth =
Thread.ofVirtual()
.start(
() -> {
try {
runner.run();
} catch (Exc | RuntimeException e) {
addExc(name, e);
}
});

var ent = new VthEntry(name, vth);
if (this.vthLast == null) {
Expand Down Expand Up @@ -72,7 +73,8 @@ void joinAndIgnoreExcs() {
for (var ent = this.vthHead; ent != null; ent = ent.next) {
try {
ent.thread.join();
} catch (InterruptedException e) {}
} catch (InterruptedException e) {
}
}
clear();
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/github/sttk/sabi/internal/DataConnList.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
*/
package com.github.sttk.sabi.internal;

import com.github.sttk.errs.Exc;

public class DataConnList {
DataConnContainer head;
DataConnContainer last;
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/com/github/sttk/sabi/internal/DataHubInner.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@
*/
package com.github.sttk.sabi.internal;

import com.github.sttk.sabi.DataSrc;
import com.github.sttk.errs.Exc;
import com.github.sttk.sabi.DataConn;
import com.github.sttk.sabi.DataHub;
import com.github.sttk.errs.Exc;
import java.util.Map;
import com.github.sttk.sabi.DataSrc;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;

public class DataHubInner {

final static DataSrcList GLOBAL_DATA_SRC_LIST = new DataSrcList(false);
static final DataSrcList GLOBAL_DATA_SRC_LIST = new DataSrcList(false);
static AtomicBoolean GLOBAL_DATA_SRCS_FIXED = new AtomicBoolean(false);

public static void usesGlobal(String name, DataSrc ds) {
if (! GLOBAL_DATA_SRCS_FIXED.get()) {
if (!GLOBAL_DATA_SRCS_FIXED.get()) {
GLOBAL_DATA_SRC_LIST.addDataSrc(name, ds);
}
}

public static AutoCloseable setupGlobals() throws Exc {
if (GLOBAL_DATA_SRCS_FIXED.compareAndSet(false, true)) {
var excMap = GLOBAL_DATA_SRC_LIST.setupDataSrcs();
if (! excMap.isEmpty()) {
if (!excMap.isEmpty()) {
GLOBAL_DATA_SRC_LIST.closeDataSrcs();
throw new Exc(new DataHub.FailToSetupGlobalDataSrcs(excMap));
}
Expand Down Expand Up @@ -89,7 +89,7 @@ public void begin() throws Exc {
var excMap = this.localDataSrcList.setupDataSrcs();
this.localDataSrcList.copyContainerPtrsDidSetupInto(this.dataSrcMap);

if (! excMap.isEmpty()) {
if (!excMap.isEmpty()) {
throw new Exc(new DataHub.FailToSetupLocalDataSrcs(excMap));
}
}
Expand All @@ -114,7 +114,7 @@ public void commit() throws Exc {
}
ag.joinAndPutExcsInto(excMap);

if (! excMap.isEmpty()) {
if (!excMap.isEmpty()) {
throw new Exc(new DataHub.FailToPreCommitDataConn(excMap));
}

Expand All @@ -135,7 +135,7 @@ public void commit() throws Exc {
}
ag.joinAndPutExcsInto(excMap);

if (! excMap.isEmpty()) {
if (!excMap.isEmpty()) {
throw new Exc(new DataHub.FailToCommitDataConn(excMap));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/github/sttk/sabi/internal/DataSrcList.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class DataSrcList {

DataSrcList(boolean local) {
this.local = local;
}
}

void appendContainerPtrNotSetup(DataSrcContainer ptr) {
ptr.next = null;
Expand Down Expand Up @@ -150,7 +150,7 @@ Map<String, Exc> setupDataSrcs() {
ptr = this.notSetupHead;
while (ptr != null && ptr != firstPtrNotSetupYet) {
var next = ptr.next;
if (! excMap.containsKey(ptr.name)) {
if (!excMap.containsKey(ptr.name)) {
this.removeContainerPtrNotSetup(ptr);
this.appendContainerPtrDidSetup(ptr);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
/**
* Defines the APIs of Sabi framework.
*
* This module includes the interfaces that abstracts data accesses to the external data stores
* <p>This module includes the interfaces that abstracts data accesses to the external data stores
* and the classes to execute a logic function with or without transaction operations.
*/
module com.github.sttk.sabi {
exports com.github.sttk.sabi;

requires transitive com.github.sttk.errs;
}
Loading
Loading