Добавил утилиты для работы с ForkJoinPool
Some checks failed
continuous-integration/drone/tag Build is failing

This commit is contained in:
Struchkov Mark 2022-12-17 16:12:35 +03:00
parent bd235b6b25
commit 87fe31027c
8 changed files with 91 additions and 270 deletions

View File

@ -1,262 +0,0 @@
<?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>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-bom</artifactId>
<version>1.5.0</version>
<packaging>pom</packaging>
<name>Haiti Dependencies</name>
<description>Current versions of the framework dependencies</description>
<url>https://github.com/haiti-projects/haiti-framework</url>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
</license>
</licenses>
<issueManagement>
<system>GitHub</system>
<url>https://github.com/haiti-projects/haiti-framework/issues</url>
</issueManagement>
<properties>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<haiti.ver>${project.version}</haiti.ver>
<haiti.exception.ver>${haiti.ver}</haiti.exception.ver>
<haiti.context.ver>${haiti.ver}</haiti.context.ver>
<haiti.core.ver>${haiti.ver}</haiti.core.ver>
<haiti.filter.api.ver>${haiti.ver}</haiti.filter.api.ver>
<haiti.utils.ver>${haiti.ver}</haiti.utils.ver>
<haiti.database.ver>1.4.0</haiti.database.ver>
<haiti.filter.criteria.ver>0.0.4</haiti.filter.criteria.ver>
<haiti.utils.network.ver>0.0.4</haiti.utils.network.ver>
<haiti.utils.field.constants>0.0.5</haiti.utils.field.constants>
<spring.data.elasticsearch.ver>4.3.1</spring.data.elasticsearch.ver>
<spring.data.jpa.ver>2.6.1</spring.data.jpa.ver>
<spring.data.commons.ver>2.6.1</spring.data.commons.ver>
<hibernate.core.ver>5.6.4.Final</hibernate.core.ver>
<javax.persisttence.api.ver>2.2</javax.persisttence.api.ver>
<elasticsearch.ver>7.16.3</elasticsearch.ver>
<slf4j.ver>1.7.33</slf4j.ver>
<google.auto.service.ver>1.0.1</google.auto.service.ver>
<jetbrains.annotations.ver>23.0.0</jetbrains.annotations.ver>
<plugin.maven.compiler.ver>3.10.1</plugin.maven.compiler.ver>
<plugin.nexus.staging.ver>1.6.13</plugin.nexus.staging.ver>
<plugin.maven.source.ver>3.2.1</plugin.maven.source.ver>
<plugin.maven.javadoc.ver>3.4.0</plugin.maven.javadoc.ver>
<plugin.maven.gpg.ver>3.0.1</plugin.maven.gpg.ver>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-exception</artifactId>
<version>${haiti.exception.ver}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-context</artifactId>
<version>${haiti.context.ver}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-core</artifactId>
<version>${haiti.core.ver}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-filter</artifactId>
<version>${haiti.filter.api.ver}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.haiti.filter</groupId>
<artifactId>haiti-filter-criteria</artifactId>
<version>${haiti.filter.criteria.ver}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-utils</artifactId>
<version>${haiti.utils.ver}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.haiti.utils</groupId>
<artifactId>haiti-utils-network</artifactId>
<version>${haiti.utils.network.ver}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.haiti.data</groupId>
<artifactId>haiti-database</artifactId>
<version>${haiti.database.ver}</version>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>${elasticsearch.ver}</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>${javax.persisttence.api.ver}</version>
</dependency>
<!-- spring -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>${spring.data.elasticsearch.ver}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>${spring.data.commons.ver}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>${spring.data.jpa.ver}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.ver}</version>
</dependency>
<!--database-->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.core.ver}</version>
</dependency>
<!--utils-->
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>${google.auto.service.ver}</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>${jetbrains.annotations.ver}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${plugin.maven.compiler.ver}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>${plugin.nexus.staging.ver}</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${plugin.maven.source.ver}</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${plugin.maven.gpg.ver}</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<scm>
<connection>scm:git:https://github.com/haiti-projects/haiti-framework.git</connection>
<url>https://github.com/haiti-projects/haiti-framework</url>
<developerConnection>scm:git:https://github.com/haiti-projects/haiti-framework.git</developerConnection>
</scm>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<developers>
<developer>
<id>uPagge</id>
<name>Struchkov Mark</name>
<email>mark@struchkov.dev</email>
<url>https://mark.struchkov.dev</url>
</developer>
</developers>
</project>

View File

@ -6,7 +6,7 @@
<parent>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-dependencies</artifactId>
<version>2.2.0</version>
<version>2.3.0</version>
</parent>
<artifactId>haiti-exception</artifactId>

View File

@ -6,7 +6,7 @@
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-external-bom</artifactId>
<version>2.1.0</version>
<version>2.2.0</version>
<packaging>pom</packaging>
<name>Haiti External Dependencies</name>
@ -30,6 +30,10 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<javax.persistence.api.version>2.2</javax.persistence.api.version>
<google.auto.service.version>1.0.1</google.auto.service.version>
<slf4j.api.version>2.0.6</slf4j.api.version>
<plugin.maven.compiler.ver>3.10.1</plugin.maven.compiler.ver>
<plugin.nexus.staging.ver>1.6.13</plugin.nexus.staging.ver>
<plugin.maven.source.ver>3.2.1</plugin.maven.source.ver>
@ -41,12 +45,17 @@
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
<version>${javax.persistence.api.version}</version>
</dependency>
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>1.0.1</version>
<version>${google.auto.service.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.api.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

View File

@ -6,7 +6,7 @@
<parent>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-dependencies</artifactId>
<version>2.2.0</version>
<version>2.3.0</version>
</parent>
<name>Haiti Utils</name>
@ -21,6 +21,10 @@
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-exception</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,6 +1,7 @@
package dev.struchkov.haiti.utils;
import java.util.Collection;
import java.util.Map;
import static dev.struchkov.haiti.utils.Exceptions.utilityClass;
import static dev.struchkov.haiti.utils.Strings.EMPTY;
@ -48,6 +49,10 @@ public final class Checker {
return collection != null && !collection.isEmpty();
}
public static boolean checkNotEmpty(Map<?, ?> map) {
return map != null && !map.isEmpty();
}
/**
* Проверка массива на пустоту
*

View File

@ -0,0 +1,63 @@
package dev.struchkov.haiti.utils.concurrent;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinTask;
import static dev.struchkov.haiti.utils.Exceptions.utilityClass;
public class ForkJoinUtils {
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ForkJoinUtils.class);
private ForkJoinUtils() {
utilityClass();
}
public static <T> List<T> pullTaskResults(List<ForkJoinTask<List<T>>> tasks) {
final List<T> results = new ArrayList<>();
Iterator<ForkJoinTask<List<T>>> iterator = tasks.iterator();
while (!tasks.isEmpty()) {
while (iterator.hasNext()) {
final ForkJoinTask<List<T>> task = iterator.next();
if (task.isDone()) {
final List<T> jsons;
try {
jsons = task.get();
results.addAll(jsons);
} catch (InterruptedException | ExecutionException e) {
log.error(e.getMessage(), e);
Thread.currentThread().interrupt();
}
iterator.remove();
}
}
iterator = tasks.iterator();
}
return results;
}
public static <T> List<T> pullTaskResult(List<ForkJoinTask<T>> tasks) {
final List<T> results = new ArrayList<>();
Iterator<ForkJoinTask<T>> iterator = tasks.iterator();
while (!tasks.isEmpty()) {
while (iterator.hasNext()) {
final ForkJoinTask<T> task = iterator.next();
if (task.isDone()) {
try {
results.add(task.get());
} catch (InterruptedException | ExecutionException e) {
log.error(e.getMessage(), e);
Thread.currentThread().interrupt();
}
iterator.remove();
}
}
iterator = tasks.iterator();
}
return results;
}
}

View File

@ -3,4 +3,6 @@ module haiti.utils {
exports dev.struchkov.haiti.utils.domain;
requires haiti.exception;
requires org.slf4j;
}

View File

@ -6,7 +6,7 @@
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-dependencies</artifactId>
<version>2.2.0</version>
<version>2.3.0</version>
<packaging>pom</packaging>
<name>Haiti Framework</name>
@ -35,8 +35,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<haiti.ver>2.2.0</haiti.ver>
<haiti.external.ver>2.1.0</haiti.external.ver>
<haiti.ver>2.3.0</haiti.ver>
<haiti.external.ver>2.2.0</haiti.external.ver>
<haiti.exception.ver>${haiti.ver}</haiti.exception.ver>
<haiti.context.ver>${haiti.ver}</haiti.context.ver>
<haiti.filter.api.ver>${haiti.ver}</haiti.filter.api.ver>