Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hank-cp committed Dec 23, 2021
1 parent 940c62f commit 73b2c7c
Show file tree
Hide file tree
Showing 25 changed files with 2,247 additions and 4 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: CI Test

on: [push]

jobs:
openjdk8:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v1
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Set up JDK 8
uses: actions/setup-java@v1
with:
java-version: 8
- run: ./gradlew check
23 changes: 23 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Release

on:
release:
types: published

jobs:
openjdk8:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v1
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Set up JDK 8
uses: actions/setup-java@v1
with:
java-version: 8
- run: ./gradlew jar
- run: ./gradlew publish -Pversion=${GITHUB_REF##*/} -P'signing.keyId=${{ secrets.signingKeyId }}' -P'signing.password=${{ secrets.signingPassword }}' -P'sonatypeUsername=${{ secrets.sonatypeUsername }}' -P'sonatypePassword=${{ secrets.sonatypePassword }}'
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Created by .ignore support plugin (hsz.mobi)

out
build
.gradle
.idea
*.iml

/local.properties

/.gradletasknamecache

*.log
**/*.log

tmp
**/libs

transaction-logs
6 changes: 3 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@
APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright {yyyy} {name of copyright owner}

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -198,4 +198,4 @@
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.
limitations under the License.
70 changes: 69 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,70 @@
# YaaTask4j
Yet another async task manager for java to simplify multi-thread task execution on Java
Yet another async task manager for java to simplify multi-thread task execution on Java.

### Setup
* Maven
```
<dependency>
<groupId>org.laxture</groupId>
<artifactId>yaaTask4j</artifactId>
<version>0.1.0</version>
</dependency>
```
* Gradle
```
dependencies {
implementation 'org.laxture:yaaTask4j:0.1.0'
}
```
### Usage
```java
ImmediateTaskManager.getInstance().queue(TaskBuilder.build(() -> {
// hello world
}));
```

### Features
* `YaaTasks` with same id will be executed only once in a `TaskManager`
* `TaskManager` interface
* Execution
* `queue(task)` put the task to the end of execution queue.
* `queueAndAwait(task)` put the task to the end of execution queue and wait for it finished.
* `push(task)` put the task to the head of execution queue.
* `pushAndAwait(task)` put the task to the head of execution queue and wait for it finished.
* Management
* `getRunningTaskCount()` get currently running tasks count.
* `getPendingTaskCount()` get currently pending tasks count.
* `getRunningTasks()` get currently running tasks
* `getPendingTasks()` get currently pending tasks
* `getAllTasks()` get all tasks
* `findTask(taskId)` find task by task id
* `findTaskInQueue(taskId)` find pending task by task id
* `cancelAll()` cancel all tasks execution, include running tasks
* `cancelByTag(taskTag)` cancel tasks by provided tag execution, include running tasks
* `cancel(task)` cancel specific task execution
* Three `TaskManager` is provided for different purposes
* `ImmediateTaskManager` runs task immediately.
* `SerialTaskManager` runs task one by one in serial.
* `QueueTaskManager` runs task in a concurrent queue, maximum concurrent count is default
to host machine's CPU core count.

### License

```
/*
* Copyright (C) 2019-present the original author or 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.
*/
```
188 changes: 188 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
def checkProperty(Project project, String propName) {
if (!project.hasProperty(propName)) return false
String prop = project.property(propName)
return prop != null && prop.length() > 0
}

def getPropertyOrElse(Project project, String propName, String alternative) {
if (!checkProperty(project, propName)) return alternative
return project.property(propName)
}

buildscript {
ext.lombokVersion = '1.18.8'

repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'ch.raffael.markdown-doclet:markdown-doclet:1.4'
}
}

plugins {
id 'idea'
}

//*************************************************************************
// IDEA
//*************************************************************************

idea {
module {
inheritOutputDirs = true
downloadSources = true
}
}

//*************************************************************************
// Sub Project Config
//*************************************************************************

repositories {
jcenter()
mavenCentral()
}

apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'maven-publish'
apply plugin: 'signing'

//*************************************************************************
// Properties
//*************************************************************************

Properties localProp = new Properties()
try {
localProp.load(project.rootProject.file('local.properties').newDataInputStream())
} catch(Exception ignored) {}
for (String propKey in localProp.keys()) {
ext.set(propKey, localProp.get(propKey))
}
ext."signing.secretKeyRingFile" = rootProject.file('publish.gpg')

task setProperties {
doFirst {
project.ext.executable = "$project.name"
}
}

//*************************************************************************
// Compile & Assemble
//*************************************************************************

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

tasks.withType(AbstractCompile) {
options.encoding = 'UTF-8'
}
tasks.withType(Javadoc) {
options.encoding = 'UTF-8'
}

jar {
manifest.attributes provider: 'gradle'
enabled true
doFirst {
archiveFileName = "$project.name-$version.${archiveExtension.get()}"
}
}

test {
testLogging.showStandardStreams = true
workingDir = project.rootDir
testLogging {
events "failed"
exceptionFormat "short"
}
}

dependencies {
compile "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
testAnnotationProcessor "org.projectlombok:lombok:${lombokVersion}"
implementation 'com.networknt:slf4j-logback:2.0.32'
implementation 'org.apache.commons:commons-lang3:3.12.0'

testImplementation 'junit:junit:4.13.2'
}

//*************************************************************************
// Maven
//*************************************************************************

task sourcesJar(type: Jar, dependsOn: classes) {
archiveClassifier.set('sources')
from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn: javadoc) {
archiveClassifier.set('javadoc')
from javadoc.destinationDir
}

artifacts {
archives jar
archives sourcesJar
archives javadocJar
}

group = 'org.laxture'

publishing {
publications {
mavenJava(MavenPublication) {
groupId = project.getGroup()
from components.java
artifact sourcesJar
artifact javadocJar
pom {
name = project.name
description = 'Yet another async task manager for java to simplify multi-thread task execution on Java.'
url = 'https://github.com/hank-cp/yaaTask4j'
organization {
name = 'org.laxture'
url = 'https://laxture.org'
}
issueManagement {
system = 'GitHub'
url = 'https://github.com/hank-cp/yaaTask4j/issues'
}
license {
name = 'Apache License 2.0'
url = 'https://github.com/hank-cp/yaaTask4j/blob/master/LICENSE'
distribution = 'repo'
}
scm {
url = 'https://github.com/hank-cp/yaaTask4j'
connection = 'scm:git:git://github.com/hank-cp/yaaTask4j.git'
developerConnection = 'scm:git:ssh://git@github.com:hank-cp/yaaTask4j.git'
}
developers {
developer {
name = 'Hank CP'
email = 'true.cp@gmail.com'
}
}
}
repositories {
maven {
def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots"
def stagingRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2"
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : stagingRepoUrl
credentials {
username getPropertyOrElse(project, 'sonatypeUsername', '')
password getPropertyOrElse(project, 'sonatypePassword', '')
}
}
}
}
}
}

signing {
sign publishing.publications.mavenJava
}
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
org.gradle.daemon=true

version=0.1.0
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Thu Jan 17 21:21:01 CST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
Loading

0 comments on commit 73b2c7c

Please sign in to comment.