From 08c743412dce77078395513f276725cf1ce070e9 Mon Sep 17 00:00:00 2001 From: ideal Date: Thu, 29 Nov 2018 12:06:50 +0800 Subject: [PATCH] Remove ideal-common use gadtry --- build.gradle | 172 ++++++------ ideal-common/build.gradle | 8 - .../main/java/ideal/common/base/Files.java | 62 ----- .../main/java/ideal/common/base/Lazys.java | 74 ----- .../common/base/ObjectInputStreamProxy.java | 114 -------- .../java/ideal/common/base/Serializables.java | 70 ----- .../java/ideal/common/base/Throwables.java | 73 ----- .../common/classloader/DirClassLoader.java | 102 ------- .../common/classloader/PluginClassLoader.java | 151 ---------- .../classloader/ThreadContextClassLoader.java | 36 --- .../java/ideal/common/function/Creater.java | 25 -- .../main/java/ideal/common/graph/Graph.java | 35 --- .../java/ideal/common/graph/GraphBuilder.java | 102 ------- .../main/java/ideal/common/graph/Node.java | 51 ---- .../java/ideal/common/graph/impl/DagNode.java | 78 ------ .../ideal/common/graph/impl/DefaultGraph.java | 120 -------- .../ideal/common/graph/impl/DemoNode.java | 64 ----- .../main/java/ideal/common/io/IOUtils.java | 69 ----- .../main/java/ideal/common/ioc/Autowired.java | 31 --- .../src/main/java/ideal/common/ioc/Bean.java | 21 -- .../main/java/ideal/common/ioc/Binder.java | 42 --- .../src/main/java/ideal/common/ioc/Binds.java | 84 ------ .../java/ideal/common/ioc/ClassScanner.java | 125 --------- .../ideal/common/ioc/InjectorException.java | 35 --- .../ideal/common/ioc/InternalContext.java | 165 ----------- .../java/ideal/common/ioc/IocFactory.java | 111 -------- .../java/ideal/common/ioc/IocFactoryImpl.java | 67 ----- .../java/ideal/common/jvm/JVMException.java | 32 --- .../java/ideal/common/jvm/JVMLauncher.java | 199 -------------- .../java/ideal/common/jvm/JVMLaunchers.java | 98 ------- .../main/java/ideal/common/jvm/JVMUtil.java | 41 --- .../java/ideal/common/jvm/VmCallable.java | 24 -- .../main/java/ideal/common/jvm/VmFuture.java | 56 ---- .../common/memory/offheap/MemoryBlock.java | 77 ------ .../common/memory/offheap/UnsafeHelper.java | 156 ----------- .../ideal/common/memory/offheap/Utils.java | 33 --- .../memory/offheap/collection/OffHeapMap.java | 188 ------------- .../java/ideal/common/proxy/DynamicProxy.java | 71 ----- .../common/utils/ParameterizedTypeImpl.java | 258 ------------------ .../ideal/common/base/LazyReferenceTest.java | 44 --- .../java/ideal/common/ioc/IocFactoryTest.java | 63 ----- .../ideal/common/jvm/ComparatorFactory.java | 40 --- .../ideal/common/jvm/JVMLauncherTest.java | 104 ------- .../common/memory/RevisedObjectInHeap.java | 52 ---- .../offheap/collection/OffHeapMapTest.java | 45 --- .../java/ideal/sylph/graph/GraphxTest.java | 54 ---- settings.gradle | 1 - sylph-connectors/build.gradle | 59 ++-- .../sylph-elasticsearch6/build.gradle | 2 +- sylph-connectors/sylph-hdfs/build.gradle | 11 +- sylph-connectors/sylph-kafka/build.gradle | 64 ++--- sylph-connectors/sylph-kafka09/build.gradle | 12 +- sylph-connectors/sylph-mysql/build.gradle | 9 +- sylph-controller/build.gradle | 21 +- .../sylph/controller/AppExceptionMapper.java | 2 +- .../controller/action/JobMangerResurce.java | 2 +- .../controller/action/StreamSqlResource.java | 12 +- .../controller/selvet/WebAppProxyServlet.java | 4 +- sylph-dist/build.gradle | 26 +- sylph-dist/src/bin/launcher | 2 +- sylph-dist/src/bin/run.sh | 31 --- sylph-dist/src/bin/sylph | 180 ++++++++++++ sylph-dist/src/bin/sylph.bat | 88 ++++++ sylph-dist/src/etc/sylph/sylph.properties | 5 +- sylph-docs/build.gradle | 10 +- sylph-etl-api/build.gradle | 2 +- .../ideal/sylph/etl/api/RealTimePipeline.java | 3 +- sylph-main/build.gradle | 12 +- .../ideal/sylph/main/server/RunnerLoader.java | 6 +- .../sylph/main/service/LocalJobStore.java | 4 +- .../main/service/PipelinePluginLoader.java | 4 +- .../sylph/main/service/RunnerManager.java | 4 +- sylph-parser/build.gradle | 26 +- sylph-runners/flink/build.gradle | 7 +- .../ideal/sylph/runner/flink/FlinkBean.java | 4 +- .../runner/flink/FlinkContainerFactory.java | 14 +- .../ideal/sylph/runner/flink/FlinkRunner.java | 6 +- .../actuator/FlinkStreamEtlActuator.java | 10 +- .../actuator/FlinkStreamSqlActuator.java | 8 +- .../flink/actuator/StreamSqlBuilder.java | 2 +- .../runner/flink/etl/FlinkNodeLoader.java | 8 +- .../sylph/runner/flink/local/MiniExec.java | 2 +- .../runner/flink/sql/FlinkSqlParser.java | 2 +- .../flink/yarn/FlinkYarnJobLauncher.java | 2 +- .../runner/flink/jvm/JVMLauncherTest.java | 8 +- sylph-runners/spark/build.gradle | 21 +- .../ideal/sylph/runner/spark/JobHelper.java | 6 +- .../runner/spark/SparkContainerFactory.java | 6 +- .../ideal/sylph/runner/spark/SparkRunner.java | 6 +- .../runner/spark/Stream2EtlActuator.java | 2 +- .../sylph/runner/spark/StreamEtlActuator.java | 2 +- .../runner/spark/yarn/SparkAppLauncher.java | 2 +- .../etl/sparkstreaming/StreamNodeLoader.scala | 2 +- .../etl/structured/StructuredNodeLoader.scala | 2 +- sylph-spi/build.gradle | 18 +- .../java/ideal/sylph/spi/GraphAppUtil.java | 6 +- .../main/java/ideal/sylph/spi/NodeLoader.java | 2 +- .../sylph/spi/job/JobActuatorHandle.java | 3 +- .../spi/model/PipelinePluginManager.java | 2 +- sylph-yarn/build.gradle | 33 +-- .../sylph/runtime/local/LocalContainer.java | 4 +- .../runtime/yarn/YarnJobContainerProxy.java | 4 +- .../ideal/sylph/runtime/yarn/YarnModule.java | 14 +- 103 files changed, 606 insertions(+), 3926 deletions(-) delete mode 100644 ideal-common/build.gradle delete mode 100644 ideal-common/src/main/java/ideal/common/base/Files.java delete mode 100644 ideal-common/src/main/java/ideal/common/base/Lazys.java delete mode 100644 ideal-common/src/main/java/ideal/common/base/ObjectInputStreamProxy.java delete mode 100644 ideal-common/src/main/java/ideal/common/base/Serializables.java delete mode 100644 ideal-common/src/main/java/ideal/common/base/Throwables.java delete mode 100644 ideal-common/src/main/java/ideal/common/classloader/DirClassLoader.java delete mode 100755 ideal-common/src/main/java/ideal/common/classloader/PluginClassLoader.java delete mode 100644 ideal-common/src/main/java/ideal/common/classloader/ThreadContextClassLoader.java delete mode 100644 ideal-common/src/main/java/ideal/common/function/Creater.java delete mode 100644 ideal-common/src/main/java/ideal/common/graph/Graph.java delete mode 100644 ideal-common/src/main/java/ideal/common/graph/GraphBuilder.java delete mode 100644 ideal-common/src/main/java/ideal/common/graph/Node.java delete mode 100644 ideal-common/src/main/java/ideal/common/graph/impl/DagNode.java delete mode 100644 ideal-common/src/main/java/ideal/common/graph/impl/DefaultGraph.java delete mode 100644 ideal-common/src/main/java/ideal/common/graph/impl/DemoNode.java delete mode 100644 ideal-common/src/main/java/ideal/common/io/IOUtils.java delete mode 100644 ideal-common/src/main/java/ideal/common/ioc/Autowired.java delete mode 100644 ideal-common/src/main/java/ideal/common/ioc/Bean.java delete mode 100644 ideal-common/src/main/java/ideal/common/ioc/Binder.java delete mode 100644 ideal-common/src/main/java/ideal/common/ioc/Binds.java delete mode 100644 ideal-common/src/main/java/ideal/common/ioc/ClassScanner.java delete mode 100644 ideal-common/src/main/java/ideal/common/ioc/InjectorException.java delete mode 100644 ideal-common/src/main/java/ideal/common/ioc/InternalContext.java delete mode 100644 ideal-common/src/main/java/ideal/common/ioc/IocFactory.java delete mode 100644 ideal-common/src/main/java/ideal/common/ioc/IocFactoryImpl.java delete mode 100644 ideal-common/src/main/java/ideal/common/jvm/JVMException.java delete mode 100644 ideal-common/src/main/java/ideal/common/jvm/JVMLauncher.java delete mode 100644 ideal-common/src/main/java/ideal/common/jvm/JVMLaunchers.java delete mode 100644 ideal-common/src/main/java/ideal/common/jvm/JVMUtil.java delete mode 100644 ideal-common/src/main/java/ideal/common/jvm/VmCallable.java delete mode 100644 ideal-common/src/main/java/ideal/common/jvm/VmFuture.java delete mode 100644 ideal-common/src/main/java/ideal/common/memory/offheap/MemoryBlock.java delete mode 100644 ideal-common/src/main/java/ideal/common/memory/offheap/UnsafeHelper.java delete mode 100644 ideal-common/src/main/java/ideal/common/memory/offheap/Utils.java delete mode 100644 ideal-common/src/main/java/ideal/common/memory/offheap/collection/OffHeapMap.java delete mode 100644 ideal-common/src/main/java/ideal/common/proxy/DynamicProxy.java delete mode 100644 ideal-common/src/main/java/ideal/common/utils/ParameterizedTypeImpl.java delete mode 100644 ideal-common/src/test/java/ideal/common/base/LazyReferenceTest.java delete mode 100644 ideal-common/src/test/java/ideal/common/ioc/IocFactoryTest.java delete mode 100644 ideal-common/src/test/java/ideal/common/jvm/ComparatorFactory.java delete mode 100644 ideal-common/src/test/java/ideal/common/jvm/JVMLauncherTest.java delete mode 100644 ideal-common/src/test/java/ideal/common/memory/RevisedObjectInHeap.java delete mode 100644 ideal-common/src/test/java/ideal/common/memory/offheap/collection/OffHeapMapTest.java delete mode 100644 ideal-common/src/test/java/ideal/sylph/graph/GraphxTest.java delete mode 100755 sylph-dist/src/bin/run.sh create mode 100755 sylph-dist/src/bin/sylph create mode 100755 sylph-dist/src/bin/sylph.bat diff --git a/build.gradle b/build.gradle index 18a669960..2a7e0a501 100644 --- a/build.gradle +++ b/build.gradle @@ -1,105 +1,105 @@ plugins { - id "com.github.hierynomus.license" version "0.14.0" - id "com.github.harbby.gradle.serviceloader" version "1.1.5" + id "com.github.hierynomus.license" version "0.14.0" + id "com.github.harbby.gradle.serviceloader" version "1.1.5" } -allprojects{ - group 'ideal' - version '0.4.0-SNAPSHOT' +allprojects { + group 'ideal' + version '0.4.0-SNAPSHOT' //SNAPSHOT - apply plugin: 'java' - apply plugin: 'maven' - apply plugin: 'checkstyle' + apply plugin: 'java' + apply plugin: 'maven' + apply plugin: 'checkstyle' - sourceCompatibility = 1.8 - targetCompatibility = 1.8 + sourceCompatibility = 1.8 + targetCompatibility = 1.8 - tasks.withType(JavaCompile) { - options.encoding = 'UTF-8' - } - tasks.withType(ScalaCompile) { - options.encoding = 'UTF-8' - } + tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' + } + tasks.withType(ScalaCompile) { + options.encoding = 'UTF-8' + } - ext.deps = [ - flink: '1.6.1', - jetty: "9.4.6.v20170531", //8.1.17.v20150415 "9.4.6.v20170531" - hadoop: "2.7.4", - spark: "2.3.1", - scala: '2.11.8', - joda_time:'2.9.3', - log4j12:'1.7.21', - guice:'4.2.1', - guava: '25.1-jre', - jackson: '2.9.5', - jersey: '2.27' - ] + ext.deps = [ + flink : '1.6.1', + jetty : "9.4.6.v20170531", //8.1.17.v20150415 "9.4.6.v20170531" + hadoop : "2.7.4", + spark : "2.3.1", + scala : '2.11.8', + joda_time: '2.9.3', + log4j12 : '1.7.21', + guice : '4.2.1', + guava : '25.1-jre', + jackson : '2.9.5', + jersey : '2.27' + ] } -subprojects{ - if (project != rootProject) { - apply plugin: 'com.github.hierynomus.license' - } - - configurations { - testCompile.extendsFrom compileOnly - } +subprojects { + if (project != rootProject) { + apply plugin: 'com.github.hierynomus.license' + } - repositories.add(repositories.mavenLocal()) - if(System.getenv('TRAVIS_BUILD_DIR')!=null){ - println("TRAVIS_BUILD..." + System.getenv('TRAVIS_BUILD_DIR')) - }else { - println("LOCAL_BUILD... ") - repositories.add(repositories.maven {url "http://maven.aliyun.com/nexus/content/groups/public/"}) - } - repositories.add(repositories.mavenCentral()) + configurations { + testCompile.extendsFrom compileOnly + } + repositories.add(repositories.mavenLocal()) + if (System.getenv('TRAVIS_BUILD_DIR') != null) { + println("TRAVIS_BUILD..." + System.getenv('TRAVIS_BUILD_DIR')) + } + else { + println("LOCAL_BUILD... ") + repositories.add(repositories.maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }) + } + repositories.add(repositories.mavenCentral()) - dependencies { - testCompile group: 'junit', name: 'junit', version: '4.12' - } + dependencies { + testCompile group: 'junit', name: 'junit', version: '4.12' + } - checkstyle { - toolVersion '8.11' - showViolations true - } + checkstyle { + toolVersion '8.11' + showViolations true + } - task checkstyle(type: Checkstyle) { - configFile = file("${rootProject.projectDir}/src/checkstyle/facebook_checks.xml") - source 'src' - include '**/*.java' - exclude '**/gen/**', '**/test/**', '**/build/**', '**/module-info.java' - classpath = files() - } + task checkstyle(type: Checkstyle) { + configFile = file("${rootProject.projectDir}/src/checkstyle/facebook_checks.xml") + source 'src' + include '**/*.java' + exclude '**/gen/**', '**/test/**', '**/build/**', '**/module-info.java' + classpath = files() + } // assemble.dependsOn 'checkstyle' - /* 如果依赖版本冲突 则直接失败策略设置*/ - configurations.all { - resolutionStrategy { failOnVersionConflict() } - } - // ./gradlew sylph-runners:sylph-runner-flink:dependencies + /* 如果依赖版本冲突 则直接失败策略设置*/ + configurations.all { + resolutionStrategy { failOnVersionConflict() } + } + // ./gradlew sylph-runners:sylph-runner-flink:dependencies - license { - headerDefinitions { //see: http://code.mycila.com/license-maven-plugin/#supported-comment-types - javadoc_style { - firstLine = "/*" - endLine = " */" - beforeEachLine = " * " - afterEachLine = "" - firstLineDetectionPattern = "(\\s|\\t)*/\\*.*\$" - lastLineDetectionPattern = ".*\\*/(\\s|\\t)*\$" - allowBlankLines = false - padLines = false - //skipLine = "//" - isMultiline = true - } - } - header rootProject.file('src/license/LICENSE-HEADER.txt') - strictCheck true - excludes(["**/*.properties","**/*.sql"]) - //include "**/*.java" + license { + headerDefinitions { //see: http://code.mycila.com/license-maven-plugin/#supported-comment-types + javadoc_style { + firstLine = "/*" + endLine = " */" + beforeEachLine = " * " + afterEachLine = "" + firstLineDetectionPattern = "(\\s|\\t)*/\\*.*\$" + lastLineDetectionPattern = ".*\\*/(\\s|\\t)*\$" + allowBlankLines = false + padLines = false + //skipLine = "//" + isMultiline = true + } } - //assemble.dependsOn 'licenseMain','licenseTest' - //licenseMain.includes - //license.mapping('javascript', 'JAVADOC_STYLE') + header rootProject.file('src/license/LICENSE-HEADER.txt') + strictCheck true + excludes(["**/*.properties", "**/*.sql"]) + //include "**/*.java" + } + //assemble.dependsOn 'licenseMain','licenseTest' + //licenseMain.includes + //license.mapping('javascript', 'JAVADOC_STYLE') } diff --git a/ideal-common/build.gradle b/ideal-common/build.gradle deleted file mode 100644 index fe4a7b07f..000000000 --- a/ideal-common/build.gradle +++ /dev/null @@ -1,8 +0,0 @@ - -dependencies { - compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1' - - compile group: 'com.google.guava', name: 'guava', version: deps.guava - - compile group: 'org.slf4j', name: 'slf4j-log4j12', version: deps.log4j12 -} diff --git a/ideal-common/src/main/java/ideal/common/base/Files.java b/ideal-common/src/main/java/ideal/common/base/Files.java deleted file mode 100644 index d6b7c7b85..000000000 --- a/ideal-common/src/main/java/ideal/common/base/Files.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.base; - -import java.io.File; -import java.io.FileFilter; -import java.util.ArrayList; -import java.util.List; - -public class Files -{ - private Files() {} - - public static List listFiles(File input, boolean recursive) - { - List files = new ArrayList<>(); - scanFiles(input, recursive, (fileName) -> true, files); - return files; - } - - public static List listFiles(File input, boolean recursive, FileFilter filter) - { - List files = new ArrayList<>(); - scanFiles(input, recursive, filter, files); - return files; - } - - private static void scanFiles(File input, boolean recursive, FileFilter filter, List list) - { - if (input.isDirectory()) { - File[] tmp = input.listFiles(filter); - if (tmp == null) { - return; - } - - for (File it : tmp) { - if (it.isFile()) { - list.add(it); - } - else if (recursive) { //Directory() - scanFiles(it, recursive, filter, list); - } - } - } - else { - list.add(input); - } - } -} diff --git a/ideal-common/src/main/java/ideal/common/base/Lazys.java b/ideal-common/src/main/java/ideal/common/base/Lazys.java deleted file mode 100644 index 4ccfa2d3c..000000000 --- a/ideal-common/src/main/java/ideal/common/base/Lazys.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.base; - -import ideal.common.function.Creater; - -import java.io.Serializable; - -import static java.util.Objects.requireNonNull; - -public class Lazys -{ - private Lazys() {} - - public static Creater memoize(Creater delegate) - { - return delegate instanceof LazySupplier ? - delegate : - new LazySupplier<>(requireNonNull(delegate)); - } - - public static Creater goLazy(Creater delegate) - { - return memoize(delegate); - } - - public static class LazySupplier - implements Serializable, Creater - { - private final Creater delegate; - private transient volatile boolean initialized = false; - private transient T value; - private static final long serialVersionUID = 0L; - - LazySupplier(Creater delegate) - { - this.delegate = delegate; - } - - public T get() - { - if (!this.initialized) { - synchronized (this) { - if (!this.initialized) { - T t = this.delegate.get(); - this.value = t; - this.initialized = true; - return t; - } - } - } - - return this.value; - } - - public String toString() - { - return "Lazys.memoize(" + this.delegate + ")"; - } - } -} diff --git a/ideal-common/src/main/java/ideal/common/base/ObjectInputStreamProxy.java b/ideal-common/src/main/java/ideal/common/base/ObjectInputStreamProxy.java deleted file mode 100644 index 472e0c95c..000000000 --- a/ideal-common/src/main/java/ideal/common/base/ObjectInputStreamProxy.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.base; - -import ideal.common.function.Creater; - -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectStreamClass; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Map; - -public class ObjectInputStreamProxy - extends java.io.ObjectInputStream -{ - private static final Creater>> primClasses = - Lazys.goLazy(ObjectInputStreamProxy::getPrimClasses); - - private ClassLoader classLoader; - - public ObjectInputStreamProxy(InputStream in) - throws IOException - { - super(in); - } - - /** - * ObjectInputStreamProxy used by user classLoader - *

- * - * @param classLoader used by loadObject - */ - public ObjectInputStreamProxy(InputStream in, ClassLoader classLoader) - throws IOException - { - super(in); - this.classLoader = classLoader; - } - - /** - * get Method LatestUserDefinedLoader with java.io.ObjectInputStreamProxy - * with jdk.internal.misc.VM.latestUserDefinedLoader() - */ - public static ClassLoader getLatestUserDefinedLoader() - { - //super.latestUserDefinedLoader(); - Class class1 = java.io.ObjectInputStream.class; - try { - Method method = class1.getDeclaredMethod("latestUserDefinedLoader"); - method.setAccessible(true); //必须要加这个才能 - return (ClassLoader) method.invoke(null); - } - catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - throw new RuntimeException("Not compatible with java version"); - } - } - - /** - * get field primClasses with java.io.ObjectInputStreamProxy - */ - private static Map> getPrimClasses() - { - Class class1 = java.io.ObjectInputStream.class; - Map> primClasses = null; - try { - Field field = class1.getDeclaredField("primClasses"); - field.setAccessible(true); - primClasses = (Map>) field.get(class1); - return primClasses; - } - catch (NoSuchFieldException | IllegalAccessException e) { - throw new RuntimeException("Not compatible with java version"); - } - } - - @Override - protected Class resolveClass(ObjectStreamClass desc) - throws IOException, ClassNotFoundException - { - if (classLoader == null) { - return super.resolveClass(desc); - } - - //return super.resolveClass(desc); - String name = desc.getName(); - try { - return Class.forName(name, false, classLoader); - } - catch (ClassNotFoundException ex) { - Class cl = primClasses.get().get(name); - if (cl != null) { - return cl; - } - else { - throw ex; - } - } - } -} diff --git a/ideal-common/src/main/java/ideal/common/base/Serializables.java b/ideal-common/src/main/java/ideal/common/base/Serializables.java deleted file mode 100644 index fbf613c0d..000000000 --- a/ideal-common/src/main/java/ideal/common/base/Serializables.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.base; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; - -public class Serializables -{ - private Serializables() {} - - public static byte[] serialize(Serializable serializable) - throws IOException - { - try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); - ObjectOutputStream os = new ObjectOutputStream(bos) - ) { - os.writeObject(serializable); - return bos.toByteArray(); - } - } - - public static Object byteToObject(byte[] bytes) - throws IOException, ClassNotFoundException - { - return byteToObject(bytes, null); - } - - public static Object byteToObject(InputStream inputStream) - throws IOException, ClassNotFoundException - { - return byteToObject(inputStream, null); - } - - public static Object byteToObject(byte[] bytes, ClassLoader classLoader) - throws IOException, ClassNotFoundException - { - try (ByteArrayInputStream bi = new ByteArrayInputStream(bytes); - ObjectInputStreamProxy oi = new ObjectInputStreamProxy(bi, classLoader) - ) { - return oi.readObject(); - } - } - - public static Object byteToObject(InputStream inputStream, ClassLoader classLoader) - throws IOException, ClassNotFoundException - { - try (ObjectInputStreamProxy oi = new ObjectInputStreamProxy(inputStream, classLoader) - ) { - return oi.readObject(); - } - } -} diff --git a/ideal-common/src/main/java/ideal/common/base/Throwables.java b/ideal-common/src/main/java/ideal/common/base/Throwables.java deleted file mode 100644 index 70fa0b47a..000000000 --- a/ideal-common/src/main/java/ideal/common/base/Throwables.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.base; - -import java.io.PrintWriter; -import java.io.StringWriter; - -/** - * copy code with com.google.common.base.Throwables - */ -public class Throwables -{ - private Throwables() {} - - /** - * Returns a string containing the result of {@link Throwable#toString() toString()}, followed by - * the full, recursive stack trace of {@code throwable}. Note that you probably should not be - * parsing the resulting string; if you need programmatic access to the stack frames, you can call - * {@link Throwable#getStackTrace()}. - */ - // java.io.PrintWriter, java.io.StringWriter - public static String getStackTraceAsString(Throwable throwable) - { - StringWriter stringWriter = new StringWriter(); - throwable.printStackTrace(new PrintWriter(stringWriter)); - return stringWriter.toString(); - } - - /** - * Returns the innermost cause of {@code throwable}. The first throwable in a chain provides - * context from when the error or exception was initially detected. Example usage: - * - *

-     * assertEquals("Unable to assign a customer id", Throwables.getRootCause(e).getMessage());
-     * 
- * - * @throws IllegalArgumentException if there is a loop in the causal chain - */ - public static Throwable getRootCause(Throwable throwable) - { - // Keep a second pointer that slowly walks the causal chain. If the fast pointer ever catches - // the slower pointer, then there's a loop. - Throwable slowPointer = throwable; - boolean advanceSlowPointer = false; - - Throwable cause; - while ((cause = throwable.getCause()) != null) { - throwable = cause; - - if (throwable == slowPointer) { - throw new IllegalArgumentException("Loop in causal chain detected.", throwable); - } - if (advanceSlowPointer) { - slowPointer = slowPointer.getCause(); - } - advanceSlowPointer = !advanceSlowPointer; // only advance every other iteration - } - return throwable; - } -} diff --git a/ideal-common/src/main/java/ideal/common/classloader/DirClassLoader.java b/ideal-common/src/main/java/ideal/common/classloader/DirClassLoader.java deleted file mode 100644 index 9c3556ef6..000000000 --- a/ideal-common/src/main/java/ideal/common/classloader/DirClassLoader.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.classloader; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.net.URLStreamHandlerFactory; -import java.text.DateFormat; -import java.util.Date; - -import static com.google.common.base.MoreObjects.firstNonNull; - -public class DirClassLoader - extends URLClassLoader -{ - private final Date startDate = new Date(); - - public DirClassLoader(URL[] urls, ClassLoader parent) - { - super(firstNonNull(urls, new URL[0]), parent); - } - - public DirClassLoader(ClassLoader parent) - { - super(new URL[0], parent); - } - - public DirClassLoader(URL[] urls) - { - super(urls); - } - - public DirClassLoader(URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory) - { - super(urls, parent, factory); - } - - /** - * Adds a jar file from the filesystems into the jar loader list. - * - * @param jarfile The full path to the jar file. - */ - public void addJarFile(URL jarfile) - { - this.addURL(jarfile); - } - - public void addJarFiles(Iterable jarFiles) - throws MalformedURLException - { - for (File jar : jarFiles) { - this.addJarFile(jar); - } - } - - public void addJarFile(File jarfile) - throws MalformedURLException - { - this.addURL(jarfile.toURI().toURL()); - } - - public void addDir(File path) - throws MalformedURLException - { - if (!path.exists()) { - return; - } - - if (path.isDirectory()) { - File[] files = path.listFiles(); - if (files != null) { - for (File file : files) { - this.addDir(file); - } - } - } - else { //文件 - this.addJarFile(path); - } - } - - @Override - public String toString() - { - return super.toString() + ",time:" + DateFormat.getTimeInstance().format(startDate); - } -} diff --git a/ideal-common/src/main/java/ideal/common/classloader/PluginClassLoader.java b/ideal-common/src/main/java/ideal/common/classloader/PluginClassLoader.java deleted file mode 100755 index 4de99338e..000000000 --- a/ideal-common/src/main/java/ideal/common/classloader/PluginClassLoader.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.classloader; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; - -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URL; -import java.util.Enumeration; -import java.util.List; - -import static java.util.Objects.requireNonNull; - -public class PluginClassLoader - extends DirClassLoader -{ - private static final ClassLoader PLATFORM_CLASS_LOADER = findPlatformClassLoader(); - - private final ClassLoader spiClassLoader; - private final List spiPackages; - private final List spiResources; - - public PluginClassLoader( - List urls, - ClassLoader spiClassLoader, - Iterable spiPackages) - { - this(urls, - spiClassLoader, - spiPackages, - Iterables.transform(spiPackages, PluginClassLoader::classNameToResource)); - } - - private PluginClassLoader( - List urls, - ClassLoader spiClassLoader, - Iterable spiPackages, - Iterable spiResources) - { - // plugins should not have access to the system (application) class loader - super(urls.toArray(new URL[urls.size()]), PLATFORM_CLASS_LOADER); - this.spiClassLoader = requireNonNull(spiClassLoader, "spiClassLoader is null"); - this.spiPackages = ImmutableList.copyOf(spiPackages); - this.spiResources = ImmutableList.copyOf(spiResources); - } - - @Override - protected Class loadClass(String name, boolean resolve) - throws ClassNotFoundException - { - // grab the magic lock - synchronized (getClassLoadingLock(name)) { - // Check if class is in the loaded classes cache - Class cachedClass = findLoadedClass(name); - if (cachedClass != null) { - return resolveClass(cachedClass, resolve); - } - - // If this is an SPI class, only check SPI class loader - if (isSpiClass(name)) { - return resolveClass(spiClassLoader.loadClass(name), resolve); - } - - // Look for class locally - return super.loadClass(name, resolve); - } - } - - private Class resolveClass(Class clazz, boolean resolve) - { - if (resolve) { - resolveClass(clazz); - } - return clazz; - } - - @Override - public URL getResource(String name) - { - // If this is an SPI resource, only check SPI class loader - if (isSpiResource(name)) { - return spiClassLoader.getResource(name); - } - - // Look for resource locally - return super.getResource(name); - } - - @Override - public Enumeration getResources(String name) - throws IOException - { - // If this is an SPI resource, use SPI resources - if (isSpiClass(name)) { - return spiClassLoader.getResources(name); - } - - // Use local resources - return super.getResources(name); - } - - private boolean isSpiClass(String name) - { - // todo maybe make this more precise and only match base package - return spiPackages.stream().anyMatch(name::startsWith); - } - - private boolean isSpiResource(String name) - { - // todo maybe make this more precise and only match base package - return spiResources.stream().anyMatch(name::startsWith); - } - - private static String classNameToResource(String className) - { - return className.replace('.', '/'); - } - - @SuppressWarnings("JavaReflectionMemberAccess") - private static ClassLoader findPlatformClassLoader() - { - try { - // use platform class loader on Java 9 - Method method = ClassLoader.class.getMethod("getPlatformClassLoader"); - return (ClassLoader) method.invoke(null); - } - catch (NoSuchMethodException ignored) { - // use null class loader on Java 8 - return null; - } - catch (IllegalAccessException | InvocationTargetException e) { - throw new AssertionError(e); - } - } -} diff --git a/ideal-common/src/main/java/ideal/common/classloader/ThreadContextClassLoader.java b/ideal-common/src/main/java/ideal/common/classloader/ThreadContextClassLoader.java deleted file mode 100644 index ad224e36e..000000000 --- a/ideal-common/src/main/java/ideal/common/classloader/ThreadContextClassLoader.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.classloader; - -import java.io.Closeable; - -public class ThreadContextClassLoader - implements Closeable -{ - private final ClassLoader originalThreadContextClassLoader; - - public ThreadContextClassLoader(ClassLoader newThreadContextClassLoader) - { - this.originalThreadContextClassLoader = Thread.currentThread().getContextClassLoader(); - Thread.currentThread().setContextClassLoader(newThreadContextClassLoader); - } - - @Override - public void close() - { - Thread.currentThread().setContextClassLoader(originalThreadContextClassLoader); - } -} diff --git a/ideal-common/src/main/java/ideal/common/function/Creater.java b/ideal-common/src/main/java/ideal/common/function/Creater.java deleted file mode 100644 index f020096c6..000000000 --- a/ideal-common/src/main/java/ideal/common/function/Creater.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.function; - -import java.io.Serializable; - -@FunctionalInterface -public interface Creater - extends Serializable, java.util.function.Supplier -{ - T get(); -} diff --git a/ideal-common/src/main/java/ideal/common/graph/Graph.java b/ideal-common/src/main/java/ideal/common/graph/Graph.java deleted file mode 100644 index 1e164c5fc..000000000 --- a/ideal-common/src/main/java/ideal/common/graph/Graph.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.graph; - -public interface Graph -{ - String getName(); - - void show() - throws Exception; - - void run() - throws Exception; - - void run(boolean parallel) - throws Exception; - - static GraphBuilder builder() - { - return new GraphBuilder(); - } -} diff --git a/ideal-common/src/main/java/ideal/common/graph/GraphBuilder.java b/ideal-common/src/main/java/ideal/common/graph/GraphBuilder.java deleted file mode 100644 index 57ebfb51d..000000000 --- a/ideal-common/src/main/java/ideal/common/graph/GraphBuilder.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.graph; - -import ideal.common.graph.impl.DefaultGraph; - -import java.util.HashMap; -import java.util.Map; - -import static com.google.common.base.MoreObjects.toStringHelper; -import static java.util.Objects.requireNonNull; - -public class GraphBuilder -{ - private final Map> rootNodes = new HashMap<>(); - private final Map> nodes = new HashMap<>(); - private String name; - - public GraphBuilder name(String name) - { - this.name = name; - return this; - } - - public GraphBuilder addNode(Node node) - { - nodes.put(node.getId(), node); - rootNodes.put(node.getId(), node); - return this; - } - - public GraphBuilder addEdge(Node inNode, Node outNode) - { - inNode.addNextNode(outNode); - rootNodes.remove(outNode.getId()); //从根节点列表中删除 - return this; - } - - public GraphBuilder addEdge(String node1, String node2) - { - Node inNode = requireNonNull(nodes.get(node1), "Unable to create edge because " + node1 + " does not exist"); - Node outNode = requireNonNull(nodes.get(node2), "Unable to create edge because " + node2 + " does not exist"); - - return addEdge(inNode, outNode); - } - - public Graph build() - { - final Node root = new RootNode<>(); - rootNodes.values().forEach(root::addNextNode); - - return new DefaultGraph<>(name, root); - } - - public static class RootNode - extends Node - { - @Override - public String getId() - { - return "/"; - } - - @Override - public String getName() - { - return getId(); - } - - @Override - public E getOutput() - { - return null; - } - - @Override - public void action(Node parentNode) - { - } - - @Override - public String toString() - { - return toStringHelper(RootNode.this) - .add("id", getId()) - .toString(); - } - } -} diff --git a/ideal-common/src/main/java/ideal/common/graph/Node.java b/ideal-common/src/main/java/ideal/common/graph/Node.java deleted file mode 100644 index 38981919a..000000000 --- a/ideal-common/src/main/java/ideal/common/graph/Node.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.graph; - -import java.util.ArrayList; -import java.util.List; - -public abstract class Node -{ - private List> nextNodes = new ArrayList<>(); - - public abstract String getId(); - - public abstract String getName(); - - /** - * 获取当前节点的临时数据 - */ - public abstract E getOutput(); - - public abstract void action(Node parentNode); - - /** - * 获取当前节点的所有子节点 - */ - public List> nextNodes() - { - return nextNodes; - } - - public void addNextNode(Node node) - { - this.nextNodes.add(node); - } - - @Override - public abstract String toString(); -} diff --git a/ideal-common/src/main/java/ideal/common/graph/impl/DagNode.java b/ideal-common/src/main/java/ideal/common/graph/impl/DagNode.java deleted file mode 100644 index 00eb7873f..000000000 --- a/ideal-common/src/main/java/ideal/common/graph/impl/DagNode.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.graph.impl; - -import ideal.common.graph.GraphBuilder; -import ideal.common.graph.Node; - -import java.util.function.UnaryOperator; - -import static com.google.common.base.MoreObjects.toStringHelper; -import static java.util.Objects.requireNonNull; - -public class DagNode - extends Node -{ - private final String id; - private final String name; - private final UnaryOperator nodeFunc; - - private transient T outData; - - public DagNode(String id, String name, UnaryOperator nodeFunc) - { - this.id = requireNonNull(id, "node id is null"); - this.name = requireNonNull(name, "node name is null"); - this.nodeFunc = requireNonNull(nodeFunc, "nodeFunc is null"); - } - - @Override - public String getId() - { - return id; - } - - public String getName() - { - return name; - } - - @Override - public T getOutput() - { - return outData; - } - - @Override - public void action(Node parentNode) - { - if (parentNode instanceof GraphBuilder.RootNode) { //根节点 - this.outData = nodeFunc.apply(null); //进行变换 - } - else { //叶子节点 - T parentOutput = requireNonNull(parentNode.getOutput(), parentNode.getId() + " return is null"); - this.outData = nodeFunc.apply(parentOutput); //进行变换 - } - } - - @Override - public String toString() - { - return toStringHelper(this) - .add("id", getId()) - .toString(); - } -} diff --git a/ideal-common/src/main/java/ideal/common/graph/impl/DefaultGraph.java b/ideal-common/src/main/java/ideal/common/graph/impl/DefaultGraph.java deleted file mode 100644 index c0ded0f81..000000000 --- a/ideal-common/src/main/java/ideal/common/graph/impl/DefaultGraph.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.graph.impl; - -import com.google.common.collect.ImmutableList; -import ideal.common.graph.Graph; -import ideal.common.graph.Node; - -import java.util.Collection; -import java.util.List; -import java.util.stream.Stream; - -/** - * 默认graph - * 采用普通左二叉树遍历法 - * default 采用普通串行遍历(非并行) - */ -public class DefaultGraph - implements Graph -{ - private final Node root; - private final String name; - - public DefaultGraph( - final String name, - Node root) - { - this.name = name; - this.root = root; - } - - @Override - public String getName() - { - return name; - } - - @Override - public void run() - { - this.run(false); - } - - @Override - public void run(boolean parallel) - { - System.out.println("Traversing the entire graph from the root node..."); - this.show(); - serach(root, parallel); - } - - private void serach(Node node, boolean parallel) - { - Collection> nodes = node.nextNodes(); - Stream> stream = nodes.stream(); - if (parallel) { - stream = stream.parallel(); - } - stream.forEach(x -> { - x.action(node); - serach(x, parallel); - }); - } - - @Override - public void show() - { - ImmutableList.Builder builder = ImmutableList.builder(); - builder.add("/"); - show(builder, ImmutableList.copyOf(root.nextNodes()), "├"); - builder.build().forEach(System.out::println); - } - - private void show(ImmutableList.Builder builder, List> nodes, String header) - { - for (int i = 0; i < nodes.size(); i++) { - Node node = nodes.get(i); - - if (i == nodes.size() - 1) { //end - header = header.substring(0, header.length() - 1) + "└"; - } - String name = node.getId() + "[" + node.getName() + "]"; - String line = header + "────" + name; - builder.add(line); - - String f = (node.nextNodes().size() > 1) ? "├" : "└"; - show(builder, node.nextNodes(), getNextLineHeader(line, name) + f); - } - } - - private static String getNextLineHeader(String lastLine, String id) - { - StringBuilder buffer = new StringBuilder(); - for (int i = 0; i < lastLine.length() - id.length(); i++) { - char a1 = lastLine.charAt(i); - switch (a1) { - case '├': - case '│': - buffer.append("│"); - break; - default: - buffer.append(" "); - } - } - return buffer.toString(); - } -} diff --git a/ideal-common/src/main/java/ideal/common/graph/impl/DemoNode.java b/ideal-common/src/main/java/ideal/common/graph/impl/DemoNode.java deleted file mode 100644 index 11adaed07..000000000 --- a/ideal-common/src/main/java/ideal/common/graph/impl/DemoNode.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.graph.impl; - -import ideal.common.graph.Node; - -public class DemoNode - extends Node -{ - private final String id; - - public DemoNode(String id) - { - this.id = id; - } - - @Override - public String getId() - { - return id; - } - - @Override - public String getName() - { - return getId(); - } - - @Override - public Void getOutput() - { - return null; - } - - @Override - public void action(Node parentNode) - { - if (parentNode == null) { //根节点 - System.out.println("我是: 根节点" + toString()); - } - else { //叶子节点 - System.out.println("我是:" + toString() + "来自:" + parentNode.toString() + "-->" + toString()); - } - } - - @Override - public String toString() - { - return "node:" + getId(); - } -} diff --git a/ideal-common/src/main/java/ideal/common/io/IOUtils.java b/ideal-common/src/main/java/ideal/common/io/IOUtils.java deleted file mode 100644 index 964fdfca2..000000000 --- a/ideal-common/src/main/java/ideal/common/io/IOUtils.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.io; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintStream; - -public class IOUtils -{ - private IOUtils() {} - - /** - * Copies from one stream to another. - * - * @param in InputStrem to read from - * @param out OutputStream to write to - * @param buffSize the size of the buffer - * @param close whether or not close the InputStream and - * OutputStream at the end. The streams are closed in the finally clause. - */ - public static void copyBytes(InputStream in, OutputStream out, int buffSize, boolean close) - throws IOException - { - if (close) { - try (InputStream input = in; OutputStream output = out) { - copyBytes(in, out, buffSize); - } - } - else { - copyBytes(in, out, buffSize); - } - } - - /** - * Copies from one stream to another. - * - * @param in InputStrem to read from - * @param out OutputStream to write to - * @param buffSize the size of the buffer - */ - public static void copyBytes(InputStream in, OutputStream out, int buffSize) - throws IOException - { - PrintStream ps = out instanceof PrintStream ? (PrintStream) out : null; - byte[] buf = new byte[buffSize]; - int bytesRead = -1; - while ((bytesRead = in.read(buf)) >= 0) { - out.write(buf, 0, bytesRead); - if ((ps != null) && ps.checkError()) { - throw new IOException("Unable to write to output stream."); - } - } - } -} diff --git a/ideal-common/src/main/java/ideal/common/ioc/Autowired.java b/ideal-common/src/main/java/ideal/common/ioc/Autowired.java deleted file mode 100644 index c47294422..000000000 --- a/ideal-common/src/main/java/ideal/common/ioc/Autowired.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.ioc; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.CONSTRUCTOR; -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -@Target({CONSTRUCTOR, FIELD}) //add METHOD -@Retention(RUNTIME) -@Documented -public @interface Autowired -{ -} diff --git a/ideal-common/src/main/java/ideal/common/ioc/Bean.java b/ideal-common/src/main/java/ideal/common/ioc/Bean.java deleted file mode 100644 index c8eeffe59..000000000 --- a/ideal-common/src/main/java/ideal/common/ioc/Bean.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.ioc; - -public interface Bean -{ - void configure(Binder binder); -} diff --git a/ideal-common/src/main/java/ideal/common/ioc/Binder.java b/ideal-common/src/main/java/ideal/common/ioc/Binder.java deleted file mode 100644 index 63c7c3dd5..000000000 --- a/ideal-common/src/main/java/ideal/common/ioc/Binder.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.ioc; - -import ideal.common.function.Creater; - -public interface Binder -{ - public void bind(Class key, T instance); - - public BinderBuilder bind(Class key); - - public interface BinderBuilder - extends BindingSetting - { - BindingSetting by(Class createClass); - - void byInstance(T instance); - - BindingSetting byCreater(Creater creater); - - BindingSetting byCreater(Class> createrClass); - } - - public interface BindingSetting - { - public void withSingle(); - } -} diff --git a/ideal-common/src/main/java/ideal/common/ioc/Binds.java b/ideal-common/src/main/java/ideal/common/ioc/Binds.java deleted file mode 100644 index 072843023..000000000 --- a/ideal-common/src/main/java/ideal/common/ioc/Binds.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.ioc; - -import ideal.common.function.Creater; - -import java.util.HashMap; -import java.util.Map; - -interface Binds -{ - default Creater get(Class type) - { - return getOrDefault(type, null); - } - - Creater getOrDefault(Class type, Creater defaultValue); - - public Map, Creater> getAllBeans(); - - static Builder builder() - { - return new Builder(); - } - - static class Builder - { - private final Map, Creater> bindMapping = new HashMap<>(); - - public Builder bind(Class type, Creater creater) - { - Creater oldCreater = bindMapping.get(type); - if (oldCreater != null) { - throw new InjectorException(" Unable to create IocFactory, see the following errors:\n" + - "A binding to " + type.toString() + " was already configured at " + oldCreater); - } - bindMapping.put(type, creater); - return this; - } - - void bindUpdate(Class type, Creater creater) - { - bindMapping.put(type, creater); - } - - public Binds build() - { - return new Binds() - { - @SuppressWarnings("unchecked") - @Override - public Creater getOrDefault(Class type, Creater defaultValue) - { - return (Creater) bindMapping.getOrDefault(type, defaultValue); - } - - @Override - public Map, Creater> getAllBeans() - { - return bindMapping; - } - - @Override - public String toString() - { - return bindMapping.toString(); - } - }; - } - } -} diff --git a/ideal-common/src/main/java/ideal/common/ioc/ClassScanner.java b/ideal-common/src/main/java/ideal/common/ioc/ClassScanner.java deleted file mode 100644 index 4501beade..000000000 --- a/ideal-common/src/main/java/ideal/common/ioc/ClassScanner.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.ioc; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.io.IOException; -import java.net.JarURLConnection; -import java.net.URL; -import java.util.Enumeration; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.function.BiConsumer; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; -import java.util.stream.Collectors; - -import static ideal.common.base.Files.listFiles; - -public class ClassScanner -{ - private ClassScanner() {} - - private static final Logger logger = LoggerFactory.getLogger(ClassScanner.class); - - public static Set> getClasses(String basePackage) - throws IOException - { - //Package slf4j = Package.getPackage("org.slf4j"); - ClassLoader classLoader = sun.misc.VM.latestUserDefinedLoader(); - - return getClasses(basePackage, classLoader, logger::warn); - } - - public static Set> getClasses(String basePackage, ClassLoader classLoader, BiConsumer handler) - throws IOException - { - Set classStrings = scanClasses(basePackage, classLoader); - - Set> classes = new HashSet<>(); - for (String it : classStrings) { - String classString = it.substring(0, it.length() - 6).replace("/", "."); - - try { - Class driver = Class.forName(classString, false, classLoader); //classLoader.loadClass(classString) - classes.add(driver); // - } - catch (Throwable e) { - handler.accept(classString, e); - } - } - return classes; - } - - public static Set scanClasses(String basePackage, ClassLoader classLoader) - throws IOException - { - String packagePath = basePackage.replace('.', '/'); - - Set classStrings = new HashSet<>(); - Enumeration resources = classLoader.getResources(packagePath); - while (resources.hasMoreElements()) { - URL url = resources.nextElement(); - String protocol = url.getProtocol(); - if ("file".equals(protocol)) { - classStrings.addAll(scanFileClass(packagePath, url, true)); - } - else if ("jar".equals(protocol)) { - classStrings.addAll(scanJarClass(packagePath, url)); - } - } - - return classStrings; - } - - private static Set scanJarClass(String packagePath, URL url) - throws IOException - { - JarFile jarFile = ((JarURLConnection) url.openConnection()).getJarFile(); - - Set classSet = new HashSet<>(); - Enumeration entries = jarFile.entries(); - while (entries.hasMoreElements()) { - JarEntry entry = entries.nextElement(); - String name = entry.getName(); - if (name.charAt(0) == '/') { - name = name.substring(1); - } - if (!name.startsWith(packagePath)) { - continue; - } - - if (name.endsWith(".class") && !entry.isDirectory()) { - classSet.add(name); - } - } - return classSet; - } - - private static Set scanFileClass(String packagePath, URL url, boolean recursive) - { - List files = listFiles(new File(url.getPath()), recursive); - return files.stream().map(file -> { - String path = file.getPath(); - int start = path.indexOf(packagePath); - return path.substring(start); - }).collect(Collectors.toSet()); - } -} diff --git a/ideal-common/src/main/java/ideal/common/ioc/InjectorException.java b/ideal-common/src/main/java/ideal/common/ioc/InjectorException.java deleted file mode 100644 index adf212a6c..000000000 --- a/ideal-common/src/main/java/ideal/common/ioc/InjectorException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.ioc; - -public class InjectorException - extends RuntimeException -{ - public InjectorException(String message) - { - super(message); - } - - public InjectorException(Throwable cause) - { - super(cause); - } - - public InjectorException(String message, Throwable cause) - { - super(message, cause); - } -} diff --git a/ideal-common/src/main/java/ideal/common/ioc/InternalContext.java b/ideal-common/src/main/java/ideal/common/ioc/InternalContext.java deleted file mode 100644 index 1bd0f4092..000000000 --- a/ideal-common/src/main/java/ideal/common/ioc/InternalContext.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.ioc; - -import com.google.common.collect.ImmutableList; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.util.HashSet; -import java.util.Set; - -import static com.google.common.base.Preconditions.checkState; - -class InternalContext -{ - private final ThreadLocal>> deps = ThreadLocal.withInitial(HashSet::new); - private final IocFactory.Function, ?> other; - private final Binds binds; - - private InternalContext(Binds binds, IocFactory.Function, ?> other) - { - this.binds = binds; - this.other = other; - } - - public static InternalContext of(Binds binds, IocFactory.Function, ?> other) - { - return new InternalContext(binds, other); - } - - public T get(Class driver) - { - Set> depCLass = deps.get(); - depCLass.clear(); - depCLass.add(driver); - - T t = getInstance(driver); - depCLass.clear(); - return t; - } - - public T getByNew(Class driver) - { - Set> depCLass = deps.get(); - depCLass.clear(); - depCLass.add(driver); - - T t = getNewInstance(driver); - depCLass.clear(); - return t; - } - - private T getInstance(Class driver) - { - return binds.getOrDefault(driver, () -> getNewInstance(driver)).get(); - } - - private T getNewInstance(Class driver) - { - try { - return newInstance(driver); - } - catch (RuntimeException e) { - throw e; - } - catch (InvocationTargetException e) { - if (e.getCause() instanceof RuntimeException) { - throw (RuntimeException) e.getCause(); - } - throw new InjectorException(e.getMessage(), e.getCause()); - } - catch (Exception e) { - throw new InjectorException(e); - } - } - - private boolean check(Class type) - { - return !deps.get().contains(type); - } - - private T newInstance(Class driver) - throws Exception - { - final Constructor constructor = selectConstructor(driver); - constructor.setAccessible(true); - - ImmutableList.Builder builder = ImmutableList.builder(); - for (Class argType : constructor.getParameterTypes()) { - checkState(argType != driver && check(argType), "Found a circular dependency involving " + driver + ", and circular dependencies are disabled."); - - Object otherValue = other.apply(argType); - if (otherValue == null) { - //Object value = binds.get(argType); - Object value = getInstance(argType); - checkState(value != null, String.format("Could not find a suitable constructor in [%s]. Classes must have either one (and only one) constructor annotated with @Autowired or a constructor that is not private(and only one).", argType)); - builder.add(value); - } - else { - checkState(argType.isInstance(otherValue)); - builder.add(otherValue); - } - } - - T instance = constructor.newInstance(builder.build().toArray()); - return buildAnnotationFields(driver, instance); - } - - private T buildAnnotationFields(Class driver, T instance) - throws IllegalAccessException - { - for (Field field : driver.getDeclaredFields()) { - Autowired autowired = field.getAnnotation(Autowired.class); - if (autowired != null) { - field.setAccessible(true); - if (field.getType() == driver) { - field.set(instance, instance); - } - else { - field.set(instance, getInstance(field.getType())); - } - } - } - return instance; - } - - private static Constructor selectConstructor(Class driver) - { - @SuppressWarnings("unchecked") - Constructor[] constructors = (Constructor[]) driver.getConstructors(); //public - - Constructor noParameter = null; - for (Constructor constructor : constructors) { - Autowired autowired = constructor.getAnnotation(Autowired.class); - if (autowired != null) { - return constructor; - } - if (constructor.getParameterCount() == 0) { - //find 'no parameter' Constructor, using class.newInstance()"; - noParameter = constructor; - } - } - - if (noParameter != null) { - return noParameter; - } - - checkState(constructors.length == 1, String.format("%s has multiple public constructors, please ensure that there is only one", driver)); - return constructors[0]; - } -} diff --git a/ideal-common/src/main/java/ideal/common/ioc/IocFactory.java b/ideal-common/src/main/java/ideal/common/ioc/IocFactory.java deleted file mode 100644 index c0172ab83..000000000 --- a/ideal-common/src/main/java/ideal/common/ioc/IocFactory.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.ioc; - -import ideal.common.base.Lazys; -import ideal.common.function.Creater; - -/** - * harbby ioc - */ -public interface IocFactory -{ - /** - * @throws InjectorException - */ - public T getInstance(Class driver); - - /** - * @throws InjectorException - */ - public T getInstance(Class driver, IocFactory.Function, ?> other); - - public Creater getCreater(Class driver); - - public Binds getAllBeans(); - - public static IocFactory create(Bean... beans) - { - final Binds.Builder builder = Binds.builder(); - final InternalContext context = InternalContext.of(builder.build(), (x) -> null); - final Binder binder = new Binder() - { - @Override - public void bind(Class key, T instance) - { - builder.bind(key, () -> instance); - } - - @Override - public BinderBuilder bind(Class key) - { - return new BinderBuilder() - { - @Override - public void withSingle() - { - builder.bind(key, Lazys.goLazy(() -> context.getByNew(key))); - } - - @Override - public BindingSetting by(Class createClass) - { - Creater creater = () -> context.getByNew(createClass); - builder.bind(key, creater); - return () -> builder.bindUpdate(key, Lazys.goLazy(creater)); - } - - @Override - public void byInstance(T instance) - { - builder.bind(key, () -> instance); - } - - @Override - public BindingSetting byCreater(Creater creater) - { - builder.bind(key, creater); - return () -> builder.bindUpdate(key, Lazys.goLazy(creater)); - } - - @Override - public BindingSetting byCreater(Class> createrClass) - { - try { - return this.byCreater(createrClass.newInstance()); - } - catch (InstantiationException | IllegalAccessException e) { - throw new InjectorException(e); - } - } - }; - } - }; - - for (Bean bean : beans) { - bean.configure(binder); - } - Binds binds = builder.build(); - return new IocFactoryImpl(binds); - } - - @FunctionalInterface - public static interface Function - { - F1 apply(F0 f0) - throws Exception; - } -} diff --git a/ideal-common/src/main/java/ideal/common/ioc/IocFactoryImpl.java b/ideal-common/src/main/java/ideal/common/ioc/IocFactoryImpl.java deleted file mode 100644 index d62f34c06..000000000 --- a/ideal-common/src/main/java/ideal/common/ioc/IocFactoryImpl.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.ioc; - -import ideal.common.function.Creater; - -public class IocFactoryImpl - implements IocFactory -{ - private final Binds binds; - - IocFactoryImpl(Binds binds) - { - this.binds = binds; - } - - /** - * @throws InjectorException - */ - public T getInstance(Class driver) - { - return getCreater(driver).get(); - } - - @Override - public Creater getCreater(Class driver) - { - return getCreater(driver, (driverClass) -> null); - } - - @Override - public Binds getAllBeans() - { - return binds; - } - - private Creater getCreater(Class driver, IocFactory.Function, ?> other) - { - return () -> InternalContext.of(binds, other).get(driver); - } - - /** - * @throws InjectorException - */ - public T getInstance(Class driver, IocFactory.Function, ?> other) - { - return getCreater(driver, other).get(); - } - - Binds getBinds() - { - return binds; - } -} diff --git a/ideal-common/src/main/java/ideal/common/jvm/JVMException.java b/ideal-common/src/main/java/ideal/common/jvm/JVMException.java deleted file mode 100644 index 94f6c8fb6..000000000 --- a/ideal-common/src/main/java/ideal/common/jvm/JVMException.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.jvm; - -public class JVMException - extends Exception -{ - private static final long serialVersionUID = -1L; - - public JVMException(String message) - { - super(message); - } - - public JVMException(String message, Throwable cause) - { - super(message, cause); - } -} diff --git a/ideal-common/src/main/java/ideal/common/jvm/JVMLauncher.java b/ideal-common/src/main/java/ideal/common/jvm/JVMLauncher.java deleted file mode 100644 index d8761cc85..000000000 --- a/ideal-common/src/main/java/ideal/common/jvm/JVMLauncher.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.jvm; - -import ideal.common.base.ObjectInputStreamProxy; -import ideal.common.base.Serializables; -import ideal.common.base.Throwables; - -import java.io.BufferedOutputStream; -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.Serializable; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.ServerSocket; -import java.net.Socket; -import java.net.SocketTimeoutException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.function.Consumer; -import java.util.stream.Collectors; - -import static java.nio.charset.StandardCharsets.UTF_8; - -public final class JVMLauncher -{ - private final VmCallable callable; - private final Collection userJars; - private final Consumer consoleHandler; - private final boolean depThisJvm; - private final List otherVmOps; - - private Process process; - - JVMLauncher( - VmCallable callable, - Consumer consoleHandler, - Collection userJars, - boolean depThisJvm, - List otherVmOps) - { - this.callable = callable; - this.userJars = userJars; - this.consoleHandler = consoleHandler; - this.depThisJvm = depThisJvm; - this.otherVmOps = otherVmOps; - } - - public Process getProcess() - { - return process; - } - - public VmFuture startAndGet() - throws JVMException - { - return startAndGet(null); - } - - public VmFuture startAndGet(ClassLoader classLoader) - throws JVMException - { - try (Socket socketClient = startAndGetByte(); - InputStream inputStream = socketClient.getInputStream()) { - VmFuture vmFuture = (VmFuture) Serializables.byteToObject(inputStream, classLoader); - if (!vmFuture.get().isPresent()) { - throw new JVMException(vmFuture.getOnFailure()); - } - return vmFuture; - } - catch (IOException | ClassNotFoundException e) { - throw new JVMException("", e); - } - } - - private Socket startAndGetByte() - throws IOException, JVMException - { - try (ServerSocket sock = new ServerSocket()) { - sock.bind(new InetSocketAddress(InetAddress.getLocalHost(), 0)); - ProcessBuilder builder = new ProcessBuilder(buildMainArg(sock.getLocalPort(), otherVmOps)) - .redirectErrorStream(true); - - this.process = builder.start(); - try (OutputStream os = new BufferedOutputStream(process.getOutputStream())) { - os.write(Serializables.serialize(callable)); //send task - } - //IOUtils.copyBytes(); - try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), UTF_8))) { - String line; - while ((line = reader.readLine()) != null) { - consoleHandler.accept(line); - } - } - //---return Socket io Stream - // 能执行到这里 并跳出上面的where 则说明子进程已经退出 - //set accept timeOut 3s //设置最大3秒等待,防止子进程意外退出时 无限等待 - // 正常情况下子进程在退出时,已经回写完数据, 这里需要设置异常退出时 最大等待时间 - sock.setSoTimeout(3000); - try { - return sock.accept(); - } - catch (SocketTimeoutException e) { - if (process.isAlive()) { - process.destroy(); - } - throw new JVMException("Jvm child process abnormal exit, exit code " + process.exitValue(), e); - } - } - } - - private String getUserAddClasspath() - { - return userJars.stream() - .map(URL::getPath) - .collect(Collectors.joining(File.pathSeparator)); - } - - private List buildMainArg(int port, List otherVmOps) - { - File java = new File(new File(System.getProperty("java.home"), "bin"), "java"); - List ops = new ArrayList<>(); - ops.add(java.toString()); - - ops.addAll(otherVmOps); - - ops.add("-classpath"); - //ops.add(System.getProperty("java.class.path")); - String userSdkJars = getUserAddClasspath(); //编译时还需要 用户的额外jar依赖 - if (depThisJvm) { - ops.add(System.getProperty("java.class.path") + ":" + userSdkJars); - } - else { - ops.add(userSdkJars); - } - - String javaLibPath = System.getProperty("java.library.path"); - if (javaLibPath != null) { - ops.add("-Djava.library.path=" + javaLibPath); - } - ops.add(JVMLauncher.class.getCanonicalName()); //子进程会启动这个类 进行编译 - ops.add(Integer.toString(port)); - return ops; - } - - public static void main(String[] args) - throws Exception - { - System.out.println("vm start ok ..."); - VmFuture future; - - try (ObjectInputStreamProxy ois = new ObjectInputStreamProxy(System.in)) { - System.out.println("vm start init ok ..."); - VmCallable callable = (VmCallable) ois.readObject(); - future = new VmFuture<>(callable.call()); - } - catch (Throwable e) { - future = new VmFuture<>(Throwables.getStackTraceAsString(e)); - } - - try (OutputStream out = chooseOutputStream(args)) { - out.write(Serializables.serialize(future)); - System.out.println("vm exiting ok ..."); - } - } - - private static OutputStream chooseOutputStream(String[] args) - throws IOException - { - if (args.length > 0) { - int port = Integer.parseInt(args[0]); - Socket sock = new Socket(); - sock.connect(new InetSocketAddress(InetAddress.getLocalHost(), port)); - return sock.getOutputStream(); - } - else { - return System.out; - } - } -} diff --git a/ideal-common/src/main/java/ideal/common/jvm/JVMLaunchers.java b/ideal-common/src/main/java/ideal/common/jvm/JVMLaunchers.java deleted file mode 100644 index 76c66fae1..000000000 --- a/ideal-common/src/main/java/ideal/common/jvm/JVMLaunchers.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.jvm; - -import java.io.Serializable; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.function.Consumer; - -import static java.util.Objects.requireNonNull; - -public class JVMLaunchers -{ - private JVMLaunchers() {} - - public static class VmBuilder - { - private VmCallable callable; - private boolean depThisJvm = true; - private Consumer consoleHandler; - private final List tmpJars = new ArrayList<>(); - private final List otherVmOps = new ArrayList<>(); - - public VmBuilder setCallable(VmCallable callable) - { - this.callable = requireNonNull(callable, "callable is null"); - return this; - } - - public VmBuilder setConsole(Consumer consoleHandler) - { - this.consoleHandler = requireNonNull(consoleHandler, "consoleHandler is null"); - return this; - } - - public VmBuilder notDepThisJvmClassPath() - { - depThisJvm = false; - return this; - } - - public VmBuilder addUserURLClassLoader(URLClassLoader vmClassLoader) - { - ClassLoader classLoader = vmClassLoader; - while (classLoader instanceof URLClassLoader) { - Collections.addAll(tmpJars, ((URLClassLoader) classLoader).getURLs()); - classLoader = classLoader.getParent(); - } - return this; - } - - public VmBuilder addUserjars(Collection jars) - { - tmpJars.addAll(jars); - return this; - } - - public VmBuilder setXms(String xms) - { - otherVmOps.add("-Xms" + xms); - return this; - } - - public VmBuilder setXmx(String xmx) - { - otherVmOps.add("-Xmx" + xmx); - return this; - } - - public JVMLauncher build() - { - requireNonNull(consoleHandler, "setConsole(Consumer consoleHandler) not setting"); - return new JVMLauncher(callable, consoleHandler, tmpJars, depThisJvm, otherVmOps); - } - } - - public static VmBuilder newJvm() - { - return new VmBuilder(); - } -} diff --git a/ideal-common/src/main/java/ideal/common/jvm/JVMUtil.java b/ideal-common/src/main/java/ideal/common/jvm/JVMUtil.java deleted file mode 100644 index d4ebd4da4..000000000 --- a/ideal-common/src/main/java/ideal/common/jvm/JVMUtil.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.jvm; - -import java.io.File; -import java.util.Arrays; -import java.util.Set; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - -public class JVMUtil -{ - private JVMUtil() {} - - /** - * 当前class.path里面所有的jar - */ - public static Set systemJars() - { - String[] jars = System.getProperty("java.class.path") - .split(Pattern.quote(File.pathSeparator)); - Set res = Arrays.stream(jars).map(File::new).filter(File::isFile) - .collect(Collectors.toSet()); - //res.forEach(x -> logger.info("systemJars: {}", x)); - //logger.info("flink job systemJars size: {}", res.size()); - return res; - } -} diff --git a/ideal-common/src/main/java/ideal/common/jvm/VmCallable.java b/ideal-common/src/main/java/ideal/common/jvm/VmCallable.java deleted file mode 100644 index da39bdd2d..000000000 --- a/ideal-common/src/main/java/ideal/common/jvm/VmCallable.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.jvm; - -import java.io.Serializable; -import java.util.concurrent.Callable; - -public interface VmCallable - extends Callable, Serializable -{ -} diff --git a/ideal-common/src/main/java/ideal/common/jvm/VmFuture.java b/ideal-common/src/main/java/ideal/common/jvm/VmFuture.java deleted file mode 100644 index 0492a356e..000000000 --- a/ideal-common/src/main/java/ideal/common/jvm/VmFuture.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.jvm; - -import java.io.Serializable; -import java.util.Optional; - -public class VmFuture - implements Serializable -{ - private V result; - private String errorMessage; - - public Optional get() - { - return Optional.ofNullable(result); - } - - public String getOnFailure() - { - return errorMessage; - } - - public VmFuture(Serializable result) - { - this.result = (V) result; - } - - public VmFuture(String errorMessage) - { - this.errorMessage = errorMessage; - } - - public VmFuture(Serializable result, String errorMessage) - { - this.errorMessage = errorMessage; - } - - static VmFuture make(Serializable result, String errorMessage) - { - return new VmFuture<>(result, errorMessage); - } -} diff --git a/ideal-common/src/main/java/ideal/common/memory/offheap/MemoryBlock.java b/ideal-common/src/main/java/ideal/common/memory/offheap/MemoryBlock.java deleted file mode 100644 index a7bfcd795..000000000 --- a/ideal-common/src/main/java/ideal/common/memory/offheap/MemoryBlock.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.memory.offheap; - -import sun.misc.Unsafe; - -public final class MemoryBlock - implements AutoCloseable -{ - private static final Unsafe unsafe = UnsafeHelper.getUnsafe(); - private final long address; - private final int maxOffset; - private volatile boolean isFree = false; - - public MemoryBlock(byte[] value) - { - this.address = unsafe.allocateMemory(value.length); //2 * 1024 * 1024=2M - unsafe.setMemory(address, value.length, (byte) 0xa5); //init - this.maxOffset = value.length; - - for (int i = 0; i < value.length; i++) { - unsafe.putByte(null, address + i, value[i]); - } - } - - public int getSize() - { - return maxOffset; - } - - public byte[] getByteValue() - { - byte[] bytes = new byte[maxOffset]; - for (int i = 0; i < maxOffset; i++) { - bytes[i] = unsafe.getByte(address + i); - } - - return bytes; - } - - private synchronized void free() - { - if (!isFree) { - unsafe.setMemory(address, maxOffset, (byte) 0x5a); //init - unsafe.freeMemory(address); - this.isFree = true; - } - } - - @Override - protected void finalize() - throws Throwable - { - this.free(); - super.finalize(); - //System.out.println(this.getClass() + "[time:" + System.currentTimeMillis() + "] finalize. gc 释放堆外内存" + address); - } - - @Override - public void close() - { - this.free(); - } -} diff --git a/ideal-common/src/main/java/ideal/common/memory/offheap/UnsafeHelper.java b/ideal-common/src/main/java/ideal/common/memory/offheap/UnsafeHelper.java deleted file mode 100644 index ae8a42293..000000000 --- a/ideal-common/src/main/java/ideal/common/memory/offheap/UnsafeHelper.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.memory.offheap; - -import sun.misc.Cleaner; -import sun.misc.Unsafe; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.nio.ByteBuffer; - -public final class UnsafeHelper -{ - private UnsafeHelper() {} - - private static final Unsafe _UNSAFE; - - public static final int BOOLEAN_ARRAY_OFFSET; - - public static final int BYTE_ARRAY_OFFSET; - - public static final int SHORT_ARRAY_OFFSET; - - public static final int INT_ARRAY_OFFSET; - - public static final int LONG_ARRAY_OFFSET; - - public static final int FLOAT_ARRAY_OFFSET; - - public static final int DOUBLE_ARRAY_OFFSET; - - public static Unsafe getUnsafe() - { - return _UNSAFE; - } - - public static long reallocateMemory(long address, long oldSize, long newSize) - { - long newMemory = _UNSAFE.allocateMemory(newSize); - copyMemory(null, address, null, newMemory, oldSize); - _UNSAFE.freeMemory(address); - return newMemory; - } - - /** - * Uses internal JDK APIs to allocate a DirectByteBuffer while ignoring the JVM's - * MaxDirectMemorySize limit (the default limit is too low and we do not want to require users - * to increase it). - */ - @SuppressWarnings("unchecked") - public static ByteBuffer allocateDirectBuffer(int size) - { - try { - Class cls = Class.forName("java.nio.DirectByteBuffer"); - Constructor constructor = cls.getDeclaredConstructor(Long.TYPE, Integer.TYPE); - constructor.setAccessible(true); - Field cleanerField = cls.getDeclaredField("cleaner"); - cleanerField.setAccessible(true); - long memory = _UNSAFE.allocateMemory(size); - ByteBuffer buffer = (ByteBuffer) constructor.newInstance(memory, size); - Cleaner cleaner = Cleaner.create(buffer, () -> _UNSAFE.freeMemory(memory)); - cleanerField.set(buffer, cleaner); - return buffer; - } - catch (Exception e) { - throwException(e); - } - throw new IllegalStateException("unreachable"); - } - - public static void copyMemory( - Object src, long srcOffset, Object dst, long dstOffset, long length) - { - // Check if dstOffset is before or after srcOffset to determine if we should copy - // forward or backwards. This is necessary in case src and dst overlap. - if (dstOffset < srcOffset) { - while (length > 0) { - long size = Math.min(length, UNSAFE_COPY_THRESHOLD); - _UNSAFE.copyMemory(src, srcOffset, dst, dstOffset, size); - length -= size; - srcOffset += size; - dstOffset += size; - } - } - else { - srcOffset += length; - dstOffset += length; - while (length > 0) { - long size = Math.min(length, UNSAFE_COPY_THRESHOLD); - srcOffset -= size; - dstOffset -= size; - _UNSAFE.copyMemory(src, srcOffset, dst, dstOffset, size); - length -= size; - } - } - } - - /** - * Raises an exception bypassing compiler checks for checked exceptions. - */ - public static void throwException(Throwable t) - { - _UNSAFE.throwException(t); - } - - /** - * Limits the number of bytes to copy per {@link Unsafe#copyMemory(long, long, long)} to - * allow safepoint polling during a large copy. - */ - private static final long UNSAFE_COPY_THRESHOLD = 1024L * 1024L; - - static { - sun.misc.Unsafe unsafe; - try { - Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe"); - unsafeField.setAccessible(true); - unsafe = (sun.misc.Unsafe) unsafeField.get(null); - } - catch (Throwable cause) { - unsafe = null; - } - _UNSAFE = unsafe; - - if (_UNSAFE != null) { - BOOLEAN_ARRAY_OFFSET = _UNSAFE.arrayBaseOffset(boolean[].class); - BYTE_ARRAY_OFFSET = _UNSAFE.arrayBaseOffset(byte[].class); - SHORT_ARRAY_OFFSET = _UNSAFE.arrayBaseOffset(short[].class); - INT_ARRAY_OFFSET = _UNSAFE.arrayBaseOffset(int[].class); - LONG_ARRAY_OFFSET = _UNSAFE.arrayBaseOffset(long[].class); - FLOAT_ARRAY_OFFSET = _UNSAFE.arrayBaseOffset(float[].class); - DOUBLE_ARRAY_OFFSET = _UNSAFE.arrayBaseOffset(double[].class); - } - else { - BOOLEAN_ARRAY_OFFSET = 0; - BYTE_ARRAY_OFFSET = 0; - SHORT_ARRAY_OFFSET = 0; - INT_ARRAY_OFFSET = 0; - LONG_ARRAY_OFFSET = 0; - FLOAT_ARRAY_OFFSET = 0; - DOUBLE_ARRAY_OFFSET = 0; - } - } -} diff --git a/ideal-common/src/main/java/ideal/common/memory/offheap/Utils.java b/ideal-common/src/main/java/ideal/common/memory/offheap/Utils.java deleted file mode 100644 index b2813a241..000000000 --- a/ideal-common/src/main/java/ideal/common/memory/offheap/Utils.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.memory.offheap; - -public class Utils -{ - private Utils() {} - - @FunctionalInterface - public interface Serialization - { - public byte[] apply(T t); - } - - @FunctionalInterface - public interface Deserialization - { - public T apply(byte[] bytes); - } -} diff --git a/ideal-common/src/main/java/ideal/common/memory/offheap/collection/OffHeapMap.java b/ideal-common/src/main/java/ideal/common/memory/offheap/collection/OffHeapMap.java deleted file mode 100644 index 3b853f64d..000000000 --- a/ideal-common/src/main/java/ideal/common/memory/offheap/collection/OffHeapMap.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.memory.offheap.collection; - -import ideal.common.memory.offheap.MemoryBlock; -import ideal.common.memory.offheap.Utils; - -import java.lang.reflect.Modifier; -import java.util.Collection; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; - -import static com.google.common.base.Preconditions.checkArgument; -import static java.util.Objects.requireNonNull; - -public class OffHeapMap - implements Map -{ - private final Utils.Serialization serialization; - private final Utils.Deserialization deserialization; - private final Map blockMap; - - public OffHeapMap( - Utils.Serialization serialization, - Utils.Deserialization deserialization) - { - this.serialization = requireNonNull(serialization, "serialization is null"); - this.deserialization = requireNonNull(deserialization, "serialization is null"); - this.blockMap = new ConcurrentHashMap<>(); - } - - public OffHeapMap( - Utils.Serialization serialization, - Utils.Deserialization deserialization, - Class blockMapClass) - { - this.serialization = requireNonNull(serialization, "serialization is null"); - this.deserialization = requireNonNull(deserialization, "serialization is null"); - requireNonNull(blockMapClass, "blockMapClass is null"); - checkArgument(!blockMapClass.isInterface(), "blockMapClass is Interface"); - checkArgument(!Modifier.isAbstract(blockMapClass.getModifiers()), "blockMapClass is Abstract"); - try { - this.blockMap = (Map) blockMapClass.newInstance(); - } - catch (InstantiationException | IllegalAccessException e) { - throw new IllegalArgumentException("blockMapClass init failed", e); - } - } - - @Override - public int size() - { - return blockMap.size(); - } - - @Override - public boolean isEmpty() - { - return blockMap.isEmpty(); - } - - @Override - public boolean containsKey(Object key) - { - return blockMap.containsKey(key); - } - - /** - * Very expensive - */ - @Override - public boolean containsValue(Object value) - { - throw new UnsupportedOperationException("this method have't support!"); - } - - @Override - public V get(Object inKey) - { - K key = (K) inKey; - MemoryBlock memoryAddress = blockMap.get(key); - if (memoryAddress == null) { - return null; - } - byte[] bytes = memoryAddress.getByteValue(); - return deserialization.apply(bytes); - } - - @Override - public V put(K key, V value) - { - byte[] bytes = serialization.apply(value); - try (MemoryBlock old = blockMap.put(key, new MemoryBlock(bytes))) { - if (old != null) { - return deserialization.apply(old.getByteValue()); - } - } - return null; - } - - @Override - public V remove(Object key) - { - try (MemoryBlock memoryBlock = blockMap.remove(key)) { - if (memoryBlock != null) { - return deserialization.apply(memoryBlock.getByteValue()); - } - } - return null; - } - - @Override - public void putAll(Map inMap) - { - requireNonNull(inMap, "inMap is null"); - for (Entry it : inMap.entrySet()) { - this.put(it.getKey(), it.getValue()); - } - } - - @Override - public void clear() - { - synchronized (blockMap) { - for (K k : blockMap.keySet()) { - this.remove(k); - } - } - } - - @Override - public Set keySet() - { - return blockMap.keySet(); - } - - /** - * Very expensive - */ - @Override - public Collection values() - { - return this.keySet() - .stream() - .map(this::get) - .collect(Collectors.toList()); - } - - @Override - public Set> entrySet() - { - return blockMap.entrySet().stream().map(it -> new Entry() - { - @Override - public K getKey() - { - return it.getKey(); - } - - @Override - public V getValue() - { - return deserialization.apply(it.getValue().getByteValue()); - } - - @Override - public V setValue(V value) - { - throw new UnsupportedOperationException("this method have't support!"); - } - }).collect(Collectors.toSet()); - } -} diff --git a/ideal-common/src/main/java/ideal/common/proxy/DynamicProxy.java b/ideal-common/src/main/java/ideal/common/proxy/DynamicProxy.java deleted file mode 100644 index cbc678aca..000000000 --- a/ideal-common/src/main/java/ideal/common/proxy/DynamicProxy.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.proxy; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; - -/** - * yarn job 容器 需要进行动态代理 - */ -public class DynamicProxy - implements InvocationHandler -{ - // 这个就是我们要代理的真实对象 - private Object subject; - - // 构造方法,给我们要代理的真实对象赋初值 - public DynamicProxy(Object subject) - { - this.subject = subject; - } - - public Object getProxy() - { - return getProxy(subject.getClass().getInterfaces()); - } - - public Object getProxy(Class... interfaces) - { - /* - * 通过Proxy的newProxyInstance方法来创建我们的代理对象,我们来看看其三个参数 - * 第一个参数 handler.getClass().getClassLoader() ,我们这里使用handler这个类的ClassLoader对象来加载我们的代理对象 - * 第二个参数realSubject.getClass().getInterfaces(),我们这里为代理对象提供的接口是真实对象所实行的接口,表示我要代理的是该真实对象,这样我就能调用这组接口中的方法了 - * 第三个参数handler, 我们这里将这个代理对象关联到了上方的 InvocationHandler 这个对象上 - */ - return Proxy.newProxyInstance(this.getClass().getClassLoader(), interfaces, this); - } - - // 该方法负责集中处理动态代理类上的所有方法调用。第一个参数既是代理类实例,第二个参数是被调用的方法对象 - // 第三个方法是调用参数。调用处理器根据这三个参数进行预处理或分派到委托类实例上反射执行 - @Override - public Object invoke(Object proxy, Method method, Object[] args) - throws Throwable - { - //  在代理真实对象前我们可以添加一些自己的操作 - //System.out.println("before rent house"); - //System.out.println("Method:" + method); - - // 当代理对象调用真实对象的方法时,其会自动的跳转到代理对象关联的handler对象的invoke方法来进行调用 - Object obj = method.invoke(subject, args); - //System.out.println("我是方法:"+method.getName()); //可以用来判断 是否是某个方法 - - //  在代理真实对象后我们也可以添加一些自己的操作 - //System.out.println("after rent house"); - return obj; - } -} diff --git a/ideal-common/src/main/java/ideal/common/utils/ParameterizedTypeImpl.java b/ideal-common/src/main/java/ideal/common/utils/ParameterizedTypeImpl.java deleted file mode 100644 index ee1caea46..000000000 --- a/ideal-common/src/main/java/ideal/common/utils/ParameterizedTypeImpl.java +++ /dev/null @@ -1,258 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.utils; - -import java.lang.reflect.MalformedParameterizedTypeException; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.lang.reflect.TypeVariable; -import java.util.Arrays; -import java.util.Objects; - -/** - * The following sources and the parameterizedTypeImpl.java source code in jdk8 - * package: sun.reflect.generics.reflectiveObjects - *

- * Jdk9 or above can't find this class - * Alternatives are available: guice-> new MoreTypes.ParameterizedTypeImpl(null, rawType, typeArguments) - * guice see {@link com.google.inject.internal.MoreTypes.ParameterizedTypeImpl(Type, Type, Type)} - * - *

- * Implementing class for ParameterizedType interface. - *

- * demo : ParameterizedTypeImpl.make(Map.class, new Type[]{String.class, String.class}, null) - */ - -public class ParameterizedTypeImpl - implements ParameterizedType -{ - private final Type[] actualTypeArguments; - private final Class rawType; - private final Type ownerType; - - private ParameterizedTypeImpl(Class rawType, - Type[] actualTypeArguments, - Type ownerType) - { - this.actualTypeArguments = actualTypeArguments; - this.rawType = rawType; - this.ownerType = (ownerType != null) ? ownerType : rawType.getDeclaringClass(); - validateConstructorArguments(); - } - - private void validateConstructorArguments() - { - TypeVariable[] formals = rawType.getTypeParameters(); - // check correct arity of actual type args - if (formals.length != actualTypeArguments.length) { - throw new MalformedParameterizedTypeException(); - } - for (int i = 0; i < actualTypeArguments.length; i++) { - // check actuals against formals' bounds - } - } - - /** - * Static factory. Given a (generic) class, actual type arguments - * and an owner type, creates a parameterized type. - * This class can be instantiated with a a raw type that does not - * represent a generic type, provided the list of actual type - * arguments is empty. - * If the ownerType argument is null, the declaring class of the - * raw type is used as the owner type. - *

This method throws a MalformedParameterizedTypeException - * under the following circumstances: - * If the number of actual type arguments (i.e., the size of the - * array typeArgs) does not correspond to the number of - * formal type arguments. - * If any of the actual type arguments is not an instance of the - * bounds on the corresponding formal. - * - * @param rawType the Class representing the generic type declaration being - * instantiated - * @param actualTypeArguments - a (possibly empty) array of types - * representing the actual type arguments to the parameterized type - * @param ownerType - the enclosing type, if known. - * @return An instance of ParameterizedType - * @throws MalformedParameterizedTypeException - if the instantiation - * is invalid - */ - public static ParameterizedTypeImpl make(Class rawType, - Type[] actualTypeArguments, - Type ownerType) - { - return new ParameterizedTypeImpl(rawType, actualTypeArguments, - ownerType); - } - - /** - * Returns an array of Type objects representing the actual type - * arguments to this type. - * - *

Note that in some cases, the returned array be empty. This can occur - * if this type represents a non-parameterized type nested within - * a parameterized type. - * - * @return an array of Type objects representing the actual type - * arguments to this type - * @throws TypeNotPresentException if any of the - * actual type arguments refers to a non-existent type declaration - * @throws MalformedParameterizedTypeException if any of the - * actual type parameters refer to a parameterized type that cannot - * be instantiated for any reason - * @since 1.5 - */ - public Type[] getActualTypeArguments() - { - return actualTypeArguments.clone(); - } - - /** - * Returns the Type object representing the class or interface - * that declared this type. - * - * @return the Type object representing the class or interface - * that declared this type - */ - public Class getRawType() - { - return rawType; - } - - /** - * Returns a Type object representing the type that this type - * is a member of. For example, if this type is O.I, - * return a representation of O. - * - *

If this type is a top-level type, null is returned. - * - * @return a Type object representing the type that - * this type is a member of. If this type is a top-level type, - * null is returned - * @throws TypeNotPresentException if the owner type - * refers to a non-existent type declaration - * @throws MalformedParameterizedTypeException if the owner type - * refers to a parameterized type that cannot be instantiated - * for any reason - */ - public Type getOwnerType() - { - return ownerType; - } - - /* - * From the JavaDoc for java.lang.reflect.ParameterizedType - * "Instances of classes that implement this interface must - * implement an equals() method that equates any two instances - * that share the same generic type declaration and have equal - * type parameters." - */ - @Override - public boolean equals(Object o) - { - if (o instanceof ParameterizedType) { - // Check that information is equivalent - ParameterizedType that = (ParameterizedType) o; - - if (this == that) { - return true; - } - - Type thatOwner = that.getOwnerType(); - Type thatRawType = that.getRawType(); - - if (false) { // Debugging - boolean ownerEquality = (ownerType == null ? - thatOwner == null : - ownerType.equals(thatOwner)); - boolean rawEquality = (rawType == null ? - thatRawType == null : - rawType.equals(thatRawType)); - - boolean typeArgEquality = Arrays.equals(actualTypeArguments, // avoid clone - that.getActualTypeArguments()); - for (Type t : actualTypeArguments) { - System.out.printf("\t\t%s%s%n", t, t.getClass()); - } - - System.out.printf("\towner %s\traw %s\ttypeArg %s%n", - ownerEquality, rawEquality, typeArgEquality); - return ownerEquality && rawEquality && typeArgEquality; - } - - return Objects.equals(ownerType, thatOwner) && - Objects.equals(rawType, thatRawType) && - Arrays.equals(actualTypeArguments, // avoid clone - that.getActualTypeArguments()); - } - else { - return false; - } - } - - @Override - public int hashCode() - { - return Arrays.hashCode(actualTypeArguments) ^ - Objects.hashCode(ownerType) ^ - Objects.hashCode(rawType); - } - - public String toString() - { - StringBuilder sb = new StringBuilder(); - - if (ownerType != null) { - if (ownerType instanceof Class) { - sb.append(((Class) ownerType).getName()); - } - else { - sb.append(ownerType.toString()); - } - - sb.append("."); - - if (ownerType instanceof ParameterizedTypeImpl) { - // Find simple name of nested type by removing the - // shared prefix with owner. - sb.append(rawType.getName().replace(((ParameterizedTypeImpl) ownerType).rawType.getName() + "$", - "")); - } - else { - sb.append(rawType.getName()); - } - } - else { - sb.append(rawType.getName()); - } - - if (actualTypeArguments != null && - actualTypeArguments.length > 0) { - sb.append("<"); - boolean first = true; - for (Type t : actualTypeArguments) { - if (!first) { - sb.append(", "); - } - sb.append(t.getTypeName()); - first = false; - } - sb.append(">"); - } - - return sb.toString(); - } -} diff --git a/ideal-common/src/test/java/ideal/common/base/LazyReferenceTest.java b/ideal-common/src/test/java/ideal/common/base/LazyReferenceTest.java deleted file mode 100644 index 5f58a5b82..000000000 --- a/ideal-common/src/test/java/ideal/common/base/LazyReferenceTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.base; - -import ideal.common.function.Creater; -import org.junit.Assert; -import org.junit.Test; - -import java.io.IOException; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; - -public class LazyReferenceTest -{ - @Test - public void goLazy() - throws IOException - { - final Creater connection = Lazys.goLazy(() -> { - try { - return DriverManager.getConnection("jdbc:url"); - } - catch (SQLException e) { - throw new RuntimeException("Connection create fail", e); - } - }); - - Assert.assertNotNull(Serializables.serialize(connection)); - } -} \ No newline at end of file diff --git a/ideal-common/src/test/java/ideal/common/ioc/IocFactoryTest.java b/ideal-common/src/test/java/ideal/common/ioc/IocFactoryTest.java deleted file mode 100644 index 917918aac..000000000 --- a/ideal-common/src/test/java/ideal/common/ioc/IocFactoryTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.ioc; - -import ideal.common.function.Creater; -import org.junit.Assert; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -public class IocFactoryTest -{ - @Test - public void create() - { - IocFactory iocFactory = IocFactory.create(binder -> { - binder.bind(Set.class).by(HashSet.class).withSingle(); - binder.bind(HashSet.class).withSingle(); - binder.bind(List.class).byCreater(ArrayList::new); //Single object - binder.bind(Object.class, new Object()); - binder.bind(Map.class).byCreater(HashMap::new).withSingle(); //Single object - binder.bind(TestInject.class); - }); - - TestInject testInject = iocFactory.getInstance(TestInject.class); - TestInject testInject2 = iocFactory.getInstance(TestInject.class); - //Object a6546 = iocFactory.getAllBeans(); - - Set a1 = iocFactory.getInstance(Set.class); - Set a2 = iocFactory.getInstance(Set.class); - Assert.assertEquals(true, a1 == a2); // Single object - - Map map1 = iocFactory.getInstance(Map.class); - Map map2 = iocFactory.getInstance(Map.class); - Assert.assertEquals(true, map1 == map2); //Single object,单例对象 - Assert.assertEquals(false, iocFactory.getInstance(List.class) == iocFactory.getInstance(List.class)); - - Assert.assertNotNull(iocFactory.getInstance(HashSet.class)); - - Creater a5 = iocFactory.getCreater(HashSet.class); - Creater a6 = iocFactory.getCreater(HashSet.class); - Assert.assertEquals(false, a5 == a6); - Assert.assertEquals(true, a5.get() == a6.get()); - } -} \ No newline at end of file diff --git a/ideal-common/src/test/java/ideal/common/jvm/ComparatorFactory.java b/ideal-common/src/test/java/ideal/common/jvm/ComparatorFactory.java deleted file mode 100644 index a9ab1fadb..000000000 --- a/ideal-common/src/test/java/ideal/common/jvm/ComparatorFactory.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.jvm; - -import org.junit.Assert; -import org.junit.Test; - -import java.io.Serializable; -import java.util.function.UnaryOperator; - -public class ComparatorFactory -{ - public static UnaryOperator makeComparator() - { - UnaryOperator func = (UnaryOperator & Serializable) (a) -> a + 1; - - return func; - } - - @Test - public void Java8TypeIntersectionTest() - { - UnaryOperator func = makeComparator(); - Assert.assertEquals(func.apply(1).intValue(), 2); - Assert.assertTrue(func instanceof Serializable); - } -} \ No newline at end of file diff --git a/ideal-common/src/test/java/ideal/common/jvm/JVMLauncherTest.java b/ideal-common/src/test/java/ideal/common/jvm/JVMLauncherTest.java deleted file mode 100644 index d3a54e04e..000000000 --- a/ideal-common/src/test/java/ideal/common/jvm/JVMLauncherTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.jvm; - -import org.junit.Assert; -import org.junit.Test; - -import java.io.IOException; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.Collections; -import java.util.Map; - -public class JVMLauncherTest -{ - @Test - public void test1() - throws IOException, ClassNotFoundException, JVMException - { - System.out.println("--- vm test ---"); - JVMLauncher launcher = JVMLaunchers.newJvm() - .setCallable(() -> { - //TimeUnit.SECONDS.sleep(1000000); - System.out.println("************ job start ***************"); - return 1; - }) - .addUserjars(Collections.emptyList()) - .setXms("16m") - .setXmx("16m") - .setConsole((msg) -> System.out.println(msg)) - .build(); - - VmFuture out = launcher.startAndGet(); - Assert.assertEquals(out.get().get().intValue(), 1); - } - - //ops.add("-Xms8G"); - //ops.add("-Xmx8G"); - - @Test - public void test2() - throws IllegalAccessException - { - Class class1 = java.io.ObjectInputStream.class; - try { - Field field = class1.getDeclaredField("primClasses"); //class1.getDeclaredField("primClasses"); - field.setAccessible(true); //必须要加这个才能 - Map map = (Map) field.get(class1); - System.out.println(field.get(map)); - - System.out.println(field.getName()); - System.out.println(field.getType()); - } - catch (NoSuchFieldException e) { - e.printStackTrace(); - } - } - - private final static String hehe = "hehe"; - public final String xixi = "xixi"; - - @Test - public void test() - { - Field[] fields = JVMLauncherTest.class.getDeclaredFields(); - try { - for (Field field : fields) { - field.setAccessible(true); - if (field.getType().toString().endsWith("java.lang.String") && Modifier.isStatic(field.getModifiers())) { - System.out.println(field.getName() + " , " + field.get(JVMLauncherTest.class)); - } - } - } - catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void methodTest() - throws NoSuchMethodException, InvocationTargetException, IllegalAccessException - { - Class class1 = java.io.ObjectInputStream.class; - Method method = class1.getDeclaredMethod("latestUserDefinedLoader"); - method.setAccessible(true); //必须要加这个才能 - Object a1 = method.invoke(null); - Assert.assertTrue(a1 instanceof ClassLoader); - } -} \ No newline at end of file diff --git a/ideal-common/src/test/java/ideal/common/memory/RevisedObjectInHeap.java b/ideal-common/src/test/java/ideal/common/memory/RevisedObjectInHeap.java deleted file mode 100644 index b7170d6af..000000000 --- a/ideal-common/src/test/java/ideal/common/memory/RevisedObjectInHeap.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.memory; - -import ideal.common.memory.offheap.UnsafeHelper; -import sun.misc.Unsafe; - -public class RevisedObjectInHeap -{ - private long address = 0; - - private Unsafe unsafe = UnsafeHelper.getUnsafe(); - - // 让对象占用堆内存,触发[Full GC - private byte[] bytes = null; - - public RevisedObjectInHeap() - { - address = unsafe.allocateMemory(2 * 1024 * 1024); //2M堆外内存 - bytes = new byte[1024 * 1024]; - } - - @Override - protected void finalize() - throws Throwable - { - super.finalize(); - System.out.println("finalize. 释放堆外内存" + address); - unsafe.freeMemory(address); - } - - public static void main(String[] args) - { - while (true) { - RevisedObjectInHeap heap = new RevisedObjectInHeap(); - //System.out.println("memory address=" + heap.address); - } - } -} diff --git a/ideal-common/src/test/java/ideal/common/memory/offheap/collection/OffHeapMapTest.java b/ideal-common/src/test/java/ideal/common/memory/offheap/collection/OffHeapMapTest.java deleted file mode 100644 index df6e64f1b..000000000 --- a/ideal-common/src/test/java/ideal/common/memory/offheap/collection/OffHeapMapTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.common.memory.offheap.collection; - -import org.junit.Assert; -import org.junit.Test; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import static java.nio.charset.StandardCharsets.UTF_8; - -public class OffHeapMapTest -{ - private static final ExecutorService pool = Executors.newFixedThreadPool(5); - private static final String msg = "this off head value dwah jdawhdaw dhawhdawhdawhjdawjd dhawdhaw djawdjaw"; - - @Test - public void testOffHeapMap() - { - final Map offHeapMap = new OffHeapMap<>( - (String str) -> str.getBytes(UTF_8), - (byte[] bytes) -> new String(bytes, UTF_8), - ConcurrentHashMap.class - ); - offHeapMap.put("a1", msg); - Assert.assertEquals(offHeapMap.get("a1"), msg); - offHeapMap.clear(); - } -} \ No newline at end of file diff --git a/ideal-common/src/test/java/ideal/sylph/graph/GraphxTest.java b/ideal-common/src/test/java/ideal/sylph/graph/GraphxTest.java deleted file mode 100644 index ba83081ea..000000000 --- a/ideal-common/src/test/java/ideal/sylph/graph/GraphxTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2018 The Sylph 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 ideal.sylph.graph; - -import ideal.common.graph.Graph; -import ideal.common.graph.impl.DemoNode; -import org.junit.Test; - -import java.util.concurrent.TimeUnit; - -public class GraphxTest -{ - @Test - public void test1() - throws Exception - { - Graph graph = Graph.builder() - .name("test1") - .addNode(new DemoNode("a1")) - .addNode(new DemoNode("a0")) - .addNode(new DemoNode("a22")) - .addNode(new DemoNode("a3")) - - .addEdge("a1", "a22") - .addEdge("a1", "a3") - .addEdge("a0", "a3") - //----------------------------------------- - .addNode(new DemoNode("a4")) - .addNode(new DemoNode("a5")) - .addNode(new DemoNode("a6")) - - .addEdge("a22", "a4") - .addEdge("a22", "a5") - .addEdge("a3", "a6") - .build(); - - //graph.run(); - TimeUnit.MILLISECONDS.sleep(300); - graph.show(); - } -} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 9935afff5..0c22a8a7d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -10,7 +10,6 @@ rootProject.name = 'sylph' include 'sylph-spi' include 'sylph-main' -include 'ideal-common' include 'sylph-controller' include 'sylph-runners' diff --git a/sylph-connectors/build.gradle b/sylph-connectors/build.gradle index e1053fd39..5eef36f80 100644 --- a/sylph-connectors/build.gradle +++ b/sylph-connectors/build.gradle @@ -1,38 +1,39 @@ evaluationDependsOn(':sylph-dist') subprojects { - apply plugin: 'com.github.harbby.gradle.serviceloader' - serviceLoader { - serviceInterface 'ideal.sylph.etl.PipelinePlugin' - } + apply plugin: 'com.github.harbby.gradle.serviceloader' + serviceLoader { + serviceInterface 'ideal.sylph.etl.PipelinePlugin' + } - sourceCompatibility = 1.8 - targetCompatibility = 1.8 + sourceCompatibility = 1.8 + targetCompatibility = 1.8 - configurations.all { - resolutionStrategy { preferProjectModules() } - } + configurations.all { + resolutionStrategy { preferProjectModules() } + } - dependencies { - compileOnly project(":sylph-etl-api") - } + dependencies { + compileOnly project(":sylph-etl-api") + } - def plugins=project(':sylph-dist').buildDir.path + "/etl-plugins/${name}" - task buildPlugins(type:Copy) { - - if(project.name=='sylph-elasticsearch6'){ - println(project) - from(project.files("build/libs")){ - include '*-shaded.jar' //只要这个包 - } - }else{ - from (configurations.runtime) - from(jar) - } - - into plugins - //include '*.jar' + def plugins = project(':sylph-dist').buildDir.path + "/etl-plugins/${name}" + task buildPlugins(type: Copy) { + + if (project.name == 'sylph-elasticsearch6') { + println(project) + from(project.files("build/libs")) { + include '*-shaded.jar' //只要这个包 + } + } + else { + from(configurations.runtime) + from(jar) } - assemble.dependsOn buildPlugins - project(':sylph-dist').dist.dependsOn assemble + + into plugins + //include '*.jar' + } + assemble.dependsOn buildPlugins + project(':sylph-dist').dist.dependsOn assemble } diff --git a/sylph-connectors/sylph-elasticsearch6/build.gradle b/sylph-connectors/sylph-elasticsearch6/build.gradle index 53c1ed213..b83587198 100644 --- a/sylph-connectors/sylph-elasticsearch6/build.gradle +++ b/sylph-connectors/sylph-elasticsearch6/build.gradle @@ -17,7 +17,7 @@ shadowJar { dependencies { exclude(dependency('junit:junit:')) } - + //relocate 'com.google.protobuf', 'shaded.com.google.protobuf' relocate 'com.google.common', 'shaded.elasticsearch6.com.google.common' relocate 'io.netty', 'shaded.elasticsearch6.io.netty' diff --git a/sylph-connectors/sylph-hdfs/build.gradle b/sylph-connectors/sylph-hdfs/build.gradle index bee23b68c..fe6dc8ba8 100644 --- a/sylph-connectors/sylph-hdfs/build.gradle +++ b/sylph-connectors/sylph-hdfs/build.gradle @@ -1,9 +1,8 @@ - dependencies { - compile group: 'org.apache.parquet', name: 'parquet-hadoop' , version: '1.8.3' - compileOnly group: 'org.scala-lang', name: 'scala-library', version: deps.scala - compile group: 'joda-time', name: 'joda-time', version: deps.joda_time - compileOnly group: 'org.apache.hadoop', name: 'hadoop-common', version: deps.hadoop + compile group: 'org.apache.parquet', name: 'parquet-hadoop', version: '1.8.3' + compileOnly group: 'org.scala-lang', name: 'scala-library', version: deps.scala + compile group: 'joda-time', name: 'joda-time', version: deps.joda_time + compileOnly group: 'org.apache.hadoop', name: 'hadoop-common', version: deps.hadoop - compile 'commons-collections:commons-collections:3.2.2' + compile 'commons-collections:commons-collections:3.2.2' } diff --git a/sylph-connectors/sylph-kafka/build.gradle b/sylph-connectors/sylph-kafka/build.gradle index 8728ba9e5..5d95dfc9c 100644 --- a/sylph-connectors/sylph-kafka/build.gradle +++ b/sylph-connectors/sylph-kafka/build.gradle @@ -1,37 +1,37 @@ apply plugin: 'scala' dependencies { - compile group: 'org.apache.flink', name: 'flink-shaded-guava', version: '18.0-4.0' - compileOnly(group: 'org.apache.flink', name: 'flink-streaming-scala_2.11', version: deps.flink) { - exclude(module: 'flink-shaded-hadoop2') - } - compile group: 'org.apache.flink', name: 'flink-connector-kafka-0.10_2.11', version:deps.flink - //--------------------------------------------------spark---------------------------------------------------- - compileOnly (group: 'org.apache.spark', name: 'spark-sql_2.11', version: deps.spark){ - exclude(module: 'spark-core_2.11') - } - compileOnly (group: 'org.apache.spark', name: 'spark-streaming_2.11', version: deps.spark){ - exclude(module: 'spark-core_2.11') - } - compileOnly (group: 'org.apache.spark', name: 'spark-core_2.11', version: deps.spark){ - exclude(module: 'hadoop-client') - } - compileOnly group: 'org.apache.hadoop', name: 'hadoop-client', version: '2.7.3' - - /** - * spark 结构化流 kafka专用 - * */ - compile group: 'org.apache.spark', name: 'spark-sql-kafka-0-10_2.11', version: deps.spark + compile group: 'org.apache.flink', name: 'flink-shaded-guava', version: '18.0-4.0' + compileOnly(group: 'org.apache.flink', name: 'flink-streaming-scala_2.11', version: deps.flink) { + exclude(module: 'flink-shaded-hadoop2') + } + compile group: 'org.apache.flink', name: 'flink-connector-kafka-0.10_2.11', version: deps.flink + //--------------------------------------------------spark---------------------------------------------------- + compileOnly(group: 'org.apache.spark', name: 'spark-sql_2.11', version: deps.spark) { + exclude(module: 'spark-core_2.11') + } + compileOnly(group: 'org.apache.spark', name: 'spark-streaming_2.11', version: deps.spark) { + exclude(module: 'spark-core_2.11') + } + compileOnly(group: 'org.apache.spark', name: 'spark-core_2.11', version: deps.spark) { + exclude(module: 'hadoop-client') + } + compileOnly group: 'org.apache.hadoop', name: 'hadoop-client', version: '2.7.3' - /** - * spark streaming kafka 老流依赖 - * */ - compile (group: 'org.apache.spark', name: 'spark-streaming-kafka-0-10_2.11', version: deps.spark){ - exclude(group: 'org.spark-project.spark') - exclude(group: 'org.scala-lang') - exclude(module: 'spark-tags_2.11') - exclude(module: 'slf4j-log4j12') - exclude(module: 'slf4j-api') - exclude(module: 'snappy-java') - } + /** + * spark 结构化流 kafka专用 + * */ + compile group: 'org.apache.spark', name: 'spark-sql-kafka-0-10_2.11', version: deps.spark + + /** + * spark streaming kafka 老流依赖 + * */ + compile(group: 'org.apache.spark', name: 'spark-streaming-kafka-0-10_2.11', version: deps.spark) { + exclude(group: 'org.spark-project.spark') + exclude(group: 'org.scala-lang') + exclude(module: 'spark-tags_2.11') + exclude(module: 'slf4j-log4j12') + exclude(module: 'slf4j-api') + exclude(module: 'snappy-java') + } } \ No newline at end of file diff --git a/sylph-connectors/sylph-kafka09/build.gradle b/sylph-connectors/sylph-kafka09/build.gradle index e7317db9c..b3a0879db 100644 --- a/sylph-connectors/sylph-kafka09/build.gradle +++ b/sylph-connectors/sylph-kafka09/build.gradle @@ -1,10 +1,10 @@ dependencies { - compileOnly(group: 'org.apache.flink', name: 'flink-streaming-scala_2.11', version: deps.flink) { - exclude(module: 'flink-shaded-hadoop2') - } + compileOnly(group: 'org.apache.flink', name: 'flink-streaming-scala_2.11', version: deps.flink) { + exclude(module: 'flink-shaded-hadoop2') + } - //--table sql--- - compileOnly group: 'org.apache.flink', name: 'flink-table_2.11', version:deps.flink + //--table sql--- + compileOnly group: 'org.apache.flink', name: 'flink-table_2.11', version: deps.flink - compile group: 'org.apache.flink', name: 'flink-connector-kafka-0.9_2.11', version:deps.flink + compile group: 'org.apache.flink', name: 'flink-connector-kafka-0.9_2.11', version: deps.flink } diff --git a/sylph-connectors/sylph-mysql/build.gradle b/sylph-connectors/sylph-mysql/build.gradle index bb09557de..963986dd3 100644 --- a/sylph-connectors/sylph-mysql/build.gradle +++ b/sylph-connectors/sylph-mysql/build.gradle @@ -1,10 +1,9 @@ - dependencies { - compile group: 'org.apache.flink', name: 'flink-shaded-guava', version: '18.0-4.0' + compile group: 'org.apache.flink', name: 'flink-shaded-guava', version: '18.0-4.0' - compileOnly group: 'org.slf4j', name: 'slf4j-api', version: deps.log4j12 + compileOnly group: 'org.slf4j', name: 'slf4j-api', version: deps.log4j12 - //-------- - runtime group: 'mysql', name: 'mysql-connector-java', version:'5.1.38' + //-------- + runtime group: 'mysql', name: 'mysql-connector-java', version: '5.1.38' } diff --git a/sylph-controller/build.gradle b/sylph-controller/build.gradle index 86d32f72a..fb485c347 100644 --- a/sylph-controller/build.gradle +++ b/sylph-controller/build.gradle @@ -32,8 +32,7 @@ node { nodeModulesDir = file("${project.projectDir}/src/main/webapp") } - -task clear(type: Delete){ +task clear(type: Delete) { delete file("${project.projectDir}/src/main/webapp/node_modules"), file("${project.projectDir}/src/main/webapp/app/libs") } @@ -45,41 +44,39 @@ task package_install(type: YarnTask) { // add the express package only args = ['install', '--modules-folder', './app/libs'] } -task build_package(type:YarnTask, dependsOn: package_install){ +task build_package(type: YarnTask, dependsOn: package_install) { //只安装快递包 - args = [ 'run', 'build' ] + args = ['run', 'build'] } -task build_webapp(type: Copy, dependsOn: build_package){ +task build_webapp(type: Copy, dependsOn: build_package) { from('src/main/webapp/app') //from('src/main/webapp/node_modules') - into project(':sylph-dist').buildDir.path+ '/webapp' + into project(':sylph-dist').buildDir.path + '/webapp' } assemble.dependsOn 'build_webapp' dependencies { compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0' compile(project(':sylph-spi')) - compile project(':ideal-common') - compile ('io.airlift:configuration:0.172'){ + compile('io.airlift:configuration:0.172') { exclude(module: 'guice') exclude(module: 'guava') exclude(module: "guice-multibindings") exclude(module: 'commons-lang3') } - compile (group: 'com.google.inject.extensions', name: 'guice-multibindings', version: deps.guice){ + compile(group: 'com.google.inject.extensions', name: 'guice-multibindings', version: deps.guice) { exclude(module: "guava") } - compile (group: 'com.google.inject', name: 'guice', version: deps.guice){ + compile(group: 'com.google.inject', name: 'guice', version: deps.guice) { exclude(module: 'guava') } - + compile group: 'org.eclipse.jetty', name: 'jetty-server', version: deps.jetty compile group: 'org.eclipse.jetty', name: 'jetty-webapp', version: deps.jetty compile group: 'org.eclipse.jetty', name: 'jetty-servlets', version: deps.jetty compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.2' - compile("org.glassfish.jersey.containers:jersey-container-servlet:$deps.jersey") { exclude(module: 'javassist') } diff --git a/sylph-controller/src/main/java/ideal/sylph/controller/AppExceptionMapper.java b/sylph-controller/src/main/java/ideal/sylph/controller/AppExceptionMapper.java index 3c1326b44..03e7c2de5 100644 --- a/sylph-controller/src/main/java/ideal/sylph/controller/AppExceptionMapper.java +++ b/sylph-controller/src/main/java/ideal/sylph/controller/AppExceptionMapper.java @@ -15,7 +15,7 @@ */ package ideal.sylph.controller; -import ideal.common.base.Throwables; +import com.github.harbby.gadtry.base.Throwables; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/sylph-controller/src/main/java/ideal/sylph/controller/action/JobMangerResurce.java b/sylph-controller/src/main/java/ideal/sylph/controller/action/JobMangerResurce.java index 62eeb2de8..6672e9892 100644 --- a/sylph-controller/src/main/java/ideal/sylph/controller/action/JobMangerResurce.java +++ b/sylph-controller/src/main/java/ideal/sylph/controller/action/JobMangerResurce.java @@ -18,8 +18,8 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.github.harbby.gadtry.base.Throwables; import com.google.common.collect.ImmutableMap; -import ideal.common.base.Throwables; import ideal.sylph.spi.SylphContext; import ideal.sylph.spi.job.JobContainer; import org.slf4j.Logger; diff --git a/sylph-controller/src/main/java/ideal/sylph/controller/action/StreamSqlResource.java b/sylph-controller/src/main/java/ideal/sylph/controller/action/StreamSqlResource.java index a632633ed..e6b15b036 100644 --- a/sylph-controller/src/main/java/ideal/sylph/controller/action/StreamSqlResource.java +++ b/sylph-controller/src/main/java/ideal/sylph/controller/action/StreamSqlResource.java @@ -15,9 +15,9 @@ */ package ideal.sylph.controller.action; +import com.github.harbby.gadtry.base.Throwables; +import com.github.harbby.gadtry.jvm.JVMException; import com.google.common.collect.ImmutableMap; -import ideal.common.base.Throwables; -import ideal.common.jvm.JVMException; import ideal.sylph.spi.SylphContext; import ideal.sylph.spi.exception.SylphException; import ideal.sylph.spi.job.Job; @@ -47,11 +47,11 @@ import java.util.Properties; import java.util.stream.Collectors; -import static com.google.common.base.Preconditions.checkArgument; +import static com.github.harbby.gadtry.base.Checks.checkState; +import static com.github.harbby.gadtry.base.Strings.isNotBlank; import static ideal.sylph.spi.exception.StandardErrorCode.ILLEGAL_OPERATION; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Objects.requireNonNull; -import static org.apache.commons.lang3.StringUtils.isNotBlank; @javax.inject.Singleton @Path("/stream_sql") @@ -84,8 +84,8 @@ public Map saveJob(@Context HttpServletRequest request) jobId = requireNonNull(request.getParameter("jobId"), "job jobId is not empty"); String flow = request.getParameter("query"); String configString = request.getParameter("config"); - checkArgument(isNotBlank(jobId), "JobId IS NULL"); - checkArgument(isNotBlank(flow), "SQL query IS NULL"); + checkState(isNotBlank(jobId), "JobId IS NULL"); + checkState(isNotBlank(flow), "SQL query IS NULL"); sylphContext.saveJob(jobId, flow, ImmutableMap.of("type", "StreamSql", "config", parserJobConfig(configString))); Map out = ImmutableMap.of( "jobId", jobId, diff --git a/sylph-controller/src/main/java/ideal/sylph/controller/selvet/WebAppProxyServlet.java b/sylph-controller/src/main/java/ideal/sylph/controller/selvet/WebAppProxyServlet.java index 659cda4a5..d4deaa70d 100644 --- a/sylph-controller/src/main/java/ideal/sylph/controller/selvet/WebAppProxyServlet.java +++ b/sylph-controller/src/main/java/ideal/sylph/controller/selvet/WebAppProxyServlet.java @@ -15,8 +15,8 @@ */ package ideal.sylph.controller.selvet; -import ideal.common.base.Throwables; -import ideal.common.io.IOUtils; +import com.github.harbby.gadtry.base.Throwables; +import com.github.harbby.gadtry.io.IOUtils; import ideal.sylph.spi.SylphContext; import ideal.sylph.spi.exception.SylphException; import ideal.sylph.spi.job.Job; diff --git a/sylph-dist/build.gradle b/sylph-dist/build.gradle index 6618e9de7..55777fd06 100644 --- a/sylph-dist/build.gradle +++ b/sylph-dist/build.gradle @@ -1,12 +1,12 @@ -dependencies{ +dependencies { compile project(':sylph-main') } -task copyLibs(type: Copy){ +task copyLibs(type: Copy) { from(configurations.runtime) - into project.buildDir.path+'/lib' + into project.buildDir.path + '/lib' } -task copyFiles(type: Copy,dependsOn: copyLibs){ +task copyFiles(type: Copy, dependsOn: copyLibs) { from('src') into project.buildDir } @@ -18,34 +18,34 @@ task dist(type: Tar) { classifier = 'bin' extension = 'tgz' compression = Compression.GZIP - def tarpath = baseName+"-${rootProject.version}" + def tarpath = baseName + "-${rootProject.version}" from(configurations.runtime) { - into tarpath+"/lib" + into tarpath + "/lib" } from(project.files('src/bin')) { - into(tarpath+"/bin") + into(tarpath + "/bin") fileMode = 0755 } from(project.files('src/etc')) { - into(tarpath+"/etc") + into(tarpath + "/etc") } from(project.files('src/jobs')) { - into(tarpath+"/jobs") + into(tarpath + "/jobs") } from(project.files('build/webapp')) { - into(tarpath+"/webapp") + into(tarpath + "/webapp") } - from(project.files('build/modules')){ - into tarpath+"/modules" + from(project.files('build/modules')) { + into tarpath + "/modules" } from(project.files('build/etl-plugins')) { - into(tarpath+"/etl-plugins") + into(tarpath + "/etl-plugins") } } diff --git a/sylph-dist/src/bin/launcher b/sylph-dist/src/bin/launcher index 0b768b092..6db090e11 100755 --- a/sylph-dist/src/bin/launcher +++ b/sylph-dist/src/bin/launcher @@ -2,7 +2,7 @@ MAIN_HOME=$(cd `dirname $0`; pwd)/.. -runCmd=$MAIN_HOME/bin/run.sh +runCmd=$MAIN_HOME/bin/sylph pidFile=$MAIN_HOME/logs/server.pid logFile=$MAIN_HOME/logs/server.log diff --git a/sylph-dist/src/bin/run.sh b/sylph-dist/src/bin/run.sh deleted file mode 100755 index 02f8936a4..000000000 --- a/sylph-dist/src/bin/run.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash -cd ${0%/*}/.. -MAIN_HOME=. - -source etc/sylph/sylph-env.sh -#JAVA10_HOME -#echo JAVA10_HOME=$JAVA10_HOME -#export JAVA_HOME=$JAVA10_HOME -#export PATH=$JAVA10_HOME/bin:$PATH -java -version - -#stop 通用 启动脚本 mainClass 为进程坚持程序 必须唯一且可靠 否则请修改pid获取办法 -mainClass=ideal.sylph.main.SylphMaster - - -for jar in $MAIN_HOME/lib/*.jar; -do - CLASSPATH=$CLASSPATH:$jar -done - -if [ -z $GRAPHX_OPTS ]; then - GRAPHX_OPTS=-Xmx1G -fi - -#HADOOP_CONF_DIR=/etc/hadoop/conf -# -exec java $GRAPHX_OPTS -cp lib/*: -Dconfig=etc/sylph/sylph.properties -Dlog4j.file=etc/sylph/sylph-log4j.properties $mainClass "$@" - - -#nohup $cmd > ${0%/*}/../logs/server.log 2>&1 & -#echo "Starting $mainClass,the pid is "$! diff --git a/sylph-dist/src/bin/sylph b/sylph-dist/src/bin/sylph new file mode 100755 index 000000000..9f3893b5b --- /dev/null +++ b/sylph-dist/src/bin/sylph @@ -0,0 +1,180 @@ +#!/bin/bash +cd ${0%/*}/.. +MAIN_HOME=. + +source etc/sylph/sylph-env.sh +#JAVA10_HOME +#echo JAVA10_HOME=$JAVA10_HOME +#export JAVA_HOME=$JAVA10_HOME +#export PATH=$JAVA10_HOME/bin:$PATH +java -version +############################################################################## +## +## sylph start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/.." >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="sylph" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and SYLPH_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Dconfig=etc/sylph/sylph.properties" "-Dlog4j.file=etc/sylph/sylph-log4j.properties"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=lib/*: + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $SYLPH_OPTS -classpath "\"$CLASSPATH\"" ideal.sylph.main.SylphMaster "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/sylph-dist/src/bin/sylph.bat b/sylph-dist/src/bin/sylph.bat new file mode 100755 index 000000000..7031b38f7 --- /dev/null +++ b/sylph-dist/src/bin/sylph.bat @@ -0,0 +1,88 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem sylph startup script for Windows +@rem +@rem ########################################################################## + +cd %DIRNAME%.. +call "etc/sylph/sylph-env.bat" + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME%.. + +@rem Add default JVM options here. You can also use JAVA_OPTS and SYLPH_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Dconfig=etc/sylph/sylph.properties" "-Dlog4j.file=etc/sylph/sylph-log4j.properties" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=lib/*: + +@rem Execute sylph +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %SYLPH_OPTS% -classpath lib\* ideal.sylph.main.SylphMaster %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable SYLPH_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%SYLPH_EXIT_CONSOLE%" exit 1 +pause +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/sylph-dist/src/etc/sylph/sylph.properties b/sylph-dist/src/etc/sylph/sylph.properties index de4684506..62dea783c 100644 --- a/sylph-dist/src/etc/sylph/sylph.properties +++ b/sylph-dist/src/etc/sylph/sylph.properties @@ -1,11 +1,8 @@ # server web port web.server.port=8080 - # metadata path -server.metadata.path =./data - +server.metadata.path=./data # job working dir server.jobstore.workpath=./jobs - # job runtime mode, yarn or local job.runtime.mode=local \ No newline at end of file diff --git a/sylph-docs/build.gradle b/sylph-docs/build.gradle index 443acaf82..e44726f7f 100644 --- a/sylph-docs/build.gradle +++ b/sylph-docs/build.gradle @@ -32,17 +32,17 @@ node { nodeModulesDir = file("${project.projectDir}/src/main/docs") } -task clear(type: Delete){ +task clear(type: Delete) { delete file("${project.projectDir}/src/main/docs/node_modules"), file("${project.projectDir}/src/main/docs/public") } clean.dependsOn 'clear' -task build_docs(type:YarnTask, dependsOn: yarn_install){ +task build_docs(type: YarnTask, dependsOn: yarn_install) { //只安装快递包 - args = [ 'run', 'build' ] + args = ['run', 'build'] } -task run(type:YarnTask, dependsOn: build_docs){ - args = [ 'run', 'server' ] +task run(type: YarnTask, dependsOn: build_docs) { + args = ['run', 'server'] } \ No newline at end of file diff --git a/sylph-etl-api/build.gradle b/sylph-etl-api/build.gradle index 51e4af348..6579c8d4a 100644 --- a/sylph-etl-api/build.gradle +++ b/sylph-etl-api/build.gradle @@ -3,5 +3,5 @@ ext.moduleName = 'ideal.sylph.api' sourceCompatibility = 1.8 targetCompatibility = 1.8 -dependencies{ +dependencies { } \ No newline at end of file diff --git a/sylph-etl-api/src/main/java/ideal/sylph/etl/api/RealTimePipeline.java b/sylph-etl-api/src/main/java/ideal/sylph/etl/api/RealTimePipeline.java index 91a52dd6a..d989bc682 100644 --- a/sylph-etl-api/src/main/java/ideal/sylph/etl/api/RealTimePipeline.java +++ b/sylph-etl-api/src/main/java/ideal/sylph/etl/api/RealTimePipeline.java @@ -20,7 +20,8 @@ public interface RealTimePipeline /** * partition级别的初始化 **/ - boolean open(long partitionId, long version) throws Exception; + boolean open(long partitionId, long version) + throws Exception; /** * partition级别的资源释放 diff --git a/sylph-main/build.gradle b/sylph-main/build.gradle index 75e036601..7ecdef943 100644 --- a/sylph-main/build.gradle +++ b/sylph-main/build.gradle @@ -1,11 +1,17 @@ ext.moduleName = 'ideal.sylph.main' +apply plugin: 'application' + dependencies { compile project(':sylph-controller') compile(project(':sylph-spi')) - compile project(':ideal-common') - - testCompile group: 'org.fusesource.jansi', name: 'jansi', version: '1.17.1' } + +application { + mainClassName = "ideal.sylph.main.SylphMaster" + applicationName = "sylph" + applicationDefaultJvmArgs = ["-Dconfig=etc/sylph/sylph.properties", "-Dlog4j.file=etc/sylph/sylph-log4j.properties"] + //applicationDefaultJvmArgs = ["-Xms512m", "-Xmx512m"] +} diff --git a/sylph-main/src/main/java/ideal/sylph/main/server/RunnerLoader.java b/sylph-main/src/main/java/ideal/sylph/main/server/RunnerLoader.java index 48e4bd472..1879a40d2 100644 --- a/sylph-main/src/main/java/ideal/sylph/main/server/RunnerLoader.java +++ b/sylph-main/src/main/java/ideal/sylph/main/server/RunnerLoader.java @@ -15,10 +15,10 @@ */ package ideal.sylph.main.server; +import com.github.harbby.gadtry.classloader.PluginClassLoader; +import com.github.harbby.gadtry.classloader.ThreadContextClassLoader; import com.google.common.collect.ImmutableList; import com.google.inject.Inject; -import ideal.common.classloader.PluginClassLoader; -import ideal.common.classloader.ThreadContextClassLoader; import ideal.sylph.main.service.RunnerManager; import ideal.sylph.spi.Runner; import org.apache.commons.io.FileUtils; @@ -39,7 +39,7 @@ public class RunnerLoader { private static final ImmutableList SPI_PACKAGES = ImmutableList.builder() .add("ideal.sylph.spi.") - .add("ideal.common.") + .add("com.github.harbby.") .add("ideal.sylph.annotation.") .add("ideal.sylph.etl.") // etl api ? //------------------------------------------------- diff --git a/sylph-main/src/main/java/ideal/sylph/main/service/LocalJobStore.java b/sylph-main/src/main/java/ideal/sylph/main/service/LocalJobStore.java index d5a1be526..7d73afdb2 100644 --- a/sylph-main/src/main/java/ideal/sylph/main/service/LocalJobStore.java +++ b/sylph-main/src/main/java/ideal/sylph/main/service/LocalJobStore.java @@ -15,10 +15,10 @@ */ package ideal.sylph.main.service; +import com.github.harbby.gadtry.base.Throwables; +import com.github.harbby.gadtry.memory.collection.OffHeapMap; import com.google.inject.Inject; import com.google.inject.Singleton; -import ideal.common.base.Throwables; -import ideal.common.memory.offheap.collection.OffHeapMap; import ideal.sylph.main.server.ServerMainConfig; import ideal.sylph.spi.exception.SylphException; import ideal.sylph.spi.job.Flow; diff --git a/sylph-main/src/main/java/ideal/sylph/main/service/PipelinePluginLoader.java b/sylph-main/src/main/java/ideal/sylph/main/service/PipelinePluginLoader.java index 45b99a2fd..a5bd8580d 100644 --- a/sylph-main/src/main/java/ideal/sylph/main/service/PipelinePluginLoader.java +++ b/sylph-main/src/main/java/ideal/sylph/main/service/PipelinePluginLoader.java @@ -15,10 +15,10 @@ */ package ideal.sylph.main.service; +import com.github.harbby.gadtry.classloader.DirClassLoader; +import com.github.harbby.gadtry.ioc.ClassScanner; import com.google.common.annotations.Beta; import com.google.common.collect.ImmutableSet; -import ideal.common.classloader.DirClassLoader; -import ideal.common.ioc.ClassScanner; import ideal.sylph.annotation.Description; import ideal.sylph.annotation.Name; import ideal.sylph.annotation.Version; diff --git a/sylph-main/src/main/java/ideal/sylph/main/service/RunnerManager.java b/sylph-main/src/main/java/ideal/sylph/main/service/RunnerManager.java index 1780a1c8e..467baa561 100644 --- a/sylph-main/src/main/java/ideal/sylph/main/service/RunnerManager.java +++ b/sylph-main/src/main/java/ideal/sylph/main/service/RunnerManager.java @@ -17,11 +17,11 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import com.github.harbby.gadtry.classloader.DirClassLoader; +import com.github.harbby.gadtry.classloader.ThreadContextClassLoader; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.inject.Inject; -import ideal.common.classloader.DirClassLoader; -import ideal.common.classloader.ThreadContextClassLoader; import ideal.sylph.etl.PipelinePlugin; import ideal.sylph.main.server.ServerMainConfig; import ideal.sylph.spi.Runner; diff --git a/sylph-parser/build.gradle b/sylph-parser/build.gradle index 13afa1b0d..808447063 100644 --- a/sylph-parser/build.gradle +++ b/sylph-parser/build.gradle @@ -1,25 +1,25 @@ apply plugin: 'antlr' dependencies { - antlr "org.antlr:antlr4:4.7.1" + antlr "org.antlr:antlr4:4.7.1" - compile group: 'com.google.guava', name: 'guava', version: deps.guava + compile group: 'com.google.guava', name: 'guava', version: deps.guava // - compile (group: 'org.apache.calcite', name: 'calcite-core', version: '1.16.0'){ - exclude(module : 'guava') - exclude(module : 'jsr305') - exclude(module: 'jackson-core') - exclude(module: 'jackson-annotations') - exclude(module: 'commons-logging') - } + compile(group: 'org.apache.calcite', name: 'calcite-core', version: '1.16.0') { + exclude(module: 'guava') + exclude(module: 'jsr305') + exclude(module: 'jackson-core') + exclude(module: 'jackson-annotations') + exclude(module: 'commons-logging') + } } -generateGrammarSource.dependsOn 'licenseMain','licenseTest' +generateGrammarSource.dependsOn 'licenseMain', 'licenseTest' licenseMain.dependsOn 'clean' licenseTest.dependsOn 'clean' license { - excludes(["**/*.g4","**/*.tokens"]) + excludes(["**/*.g4", "**/*.tokens"]) } //sourceSets { @@ -42,7 +42,7 @@ license { //} generateGrammarSource { - maxHeapSize = "64m" - arguments += ["-visitor", "-long-messages"] + maxHeapSize = "64m" + arguments += ["-visitor", "-long-messages"] } diff --git a/sylph-runners/flink/build.gradle b/sylph-runners/flink/build.gradle index 12bc3f515..41f0b9950 100644 --- a/sylph-runners/flink/build.gradle +++ b/sylph-runners/flink/build.gradle @@ -1,8 +1,7 @@ ext.moduleName = 'ideal.sylph.runner.flink' - configurations.all { - resolutionStrategy { preferProjectModules() } + resolutionStrategy { preferProjectModules() } } dependencies { @@ -23,8 +22,8 @@ dependencies { compile "org.apache.flink:flink-cep-scala_2.11:$deps.flink" //--- other---- - compile (project(':sylph-yarn')) - compile (project(':sylph-parser')){ + compile(project(':sylph-yarn')) + compile(project(':sylph-parser')) { exclude(module: 'guava') exclude(module: 'calcite-core') } diff --git a/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/FlinkBean.java b/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/FlinkBean.java index 2ab92735a..8576e5b17 100644 --- a/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/FlinkBean.java +++ b/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/FlinkBean.java @@ -15,8 +15,8 @@ */ package ideal.sylph.runner.flink; -import ideal.common.ioc.Bean; -import ideal.common.ioc.Binder; +import com.github.harbby.gadtry.ioc.Bean; +import com.github.harbby.gadtry.ioc.Binder; import org.apache.flink.table.api.java.StreamTableEnvironment; public class FlinkBean diff --git a/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/FlinkContainerFactory.java b/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/FlinkContainerFactory.java index 887b7588a..b3e54b95d 100644 --- a/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/FlinkContainerFactory.java +++ b/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/FlinkContainerFactory.java @@ -15,11 +15,11 @@ */ package ideal.sylph.runner.flink; -import ideal.common.base.Lazys; -import ideal.common.function.Creater; -import ideal.common.ioc.Autowired; -import ideal.common.ioc.IocFactory; -import ideal.common.jvm.JVMLaunchers; +import com.github.harbby.gadtry.base.Lazys; +import com.github.harbby.gadtry.function.Creator; +import com.github.harbby.gadtry.ioc.Autowired; +import com.github.harbby.gadtry.ioc.IocFactory; +import com.github.harbby.gadtry.jvm.JVMLaunchers; import ideal.sylph.runner.flink.yarn.FlinkYarnJobLauncher; import ideal.sylph.runner.flink.yarn.YarnClusterConfiguration; import ideal.sylph.runtime.local.LocalContainer; @@ -56,7 +56,7 @@ public class FlinkContainerFactory private final Supplier yarnLauncher = Lazys.goLazy(() -> { IocFactory injector = IocFactory.create(new YarnModule(), binder -> { binder.bind(FlinkYarnJobLauncher.class).withSingle(); - binder.bind(YarnClusterConfiguration.class).byCreater(FlinkContainerFactory.YarnClusterConfigurationProvider.class).withSingle(); + binder.bind(YarnClusterConfiguration.class).byCreator(FlinkContainerFactory.YarnClusterConfigurationProvider.class).withSingle(); }); return injector.getInstance(FlinkYarnJobLauncher.class); }); @@ -119,7 +119,7 @@ public JobContainer getK8sContainer(Job job, String lastRunid) } private static class YarnClusterConfigurationProvider - implements Creater + implements Creator { @Autowired private YarnConfiguration yarnConf; diff --git a/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/FlinkRunner.java b/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/FlinkRunner.java index 92df3050a..24a05b72a 100644 --- a/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/FlinkRunner.java +++ b/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/FlinkRunner.java @@ -15,8 +15,8 @@ */ package ideal.sylph.runner.flink; -import ideal.common.classloader.DirClassLoader; -import ideal.common.ioc.IocFactory; +import com.github.harbby.gadtry.classloader.DirClassLoader; +import com.github.harbby.gadtry.ioc.IocFactory; import ideal.sylph.runner.flink.actuator.FlinkStreamEtlActuator; import ideal.sylph.runner.flink.actuator.FlinkStreamSqlActuator; import ideal.sylph.spi.Runner; @@ -66,7 +66,7 @@ public Set create(RunnerContext context) binder.bind(FlinkStreamEtlActuator.class).withSingle(); binder.bind(FlinkStreamSqlActuator.class).withSingle(); //---------------------------------- - binder.bind(PipelinePluginManager.class).byCreater(() -> createPipelinePluginManager(context)).withSingle(); + binder.bind(PipelinePluginManager.class).byCreator(() -> createPipelinePluginManager(context)).withSingle(); }); return Stream.of(FlinkStreamEtlActuator.class, FlinkStreamSqlActuator.class) diff --git a/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/actuator/FlinkStreamEtlActuator.java b/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/actuator/FlinkStreamEtlActuator.java index 5eee2867b..f4cec7a13 100644 --- a/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/actuator/FlinkStreamEtlActuator.java +++ b/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/actuator/FlinkStreamEtlActuator.java @@ -15,11 +15,11 @@ */ package ideal.sylph.runner.flink.actuator; -import ideal.common.ioc.Autowired; -import ideal.common.ioc.IocFactory; -import ideal.common.jvm.JVMLauncher; -import ideal.common.jvm.JVMLaunchers; -import ideal.common.jvm.VmFuture; +import com.github.harbby.gadtry.ioc.Autowired; +import com.github.harbby.gadtry.ioc.IocFactory; +import com.github.harbby.gadtry.jvm.JVMLauncher; +import com.github.harbby.gadtry.jvm.JVMLaunchers; +import com.github.harbby.gadtry.jvm.VmFuture; import ideal.sylph.annotation.Description; import ideal.sylph.annotation.Name; import ideal.sylph.runner.flink.FlinkBean; diff --git a/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/actuator/FlinkStreamSqlActuator.java b/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/actuator/FlinkStreamSqlActuator.java index 7ad89c87d..65c32b0d4 100644 --- a/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/actuator/FlinkStreamSqlActuator.java +++ b/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/actuator/FlinkStreamSqlActuator.java @@ -16,11 +16,11 @@ package ideal.sylph.runner.flink.actuator; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.github.harbby.gadtry.ioc.Autowired; +import com.github.harbby.gadtry.jvm.JVMLauncher; +import com.github.harbby.gadtry.jvm.JVMLaunchers; +import com.github.harbby.gadtry.jvm.VmFuture; import com.google.common.collect.ImmutableSet; -import ideal.common.ioc.Autowired; -import ideal.common.jvm.JVMLauncher; -import ideal.common.jvm.JVMLaunchers; -import ideal.common.jvm.VmFuture; import ideal.sylph.annotation.Description; import ideal.sylph.annotation.Name; import ideal.sylph.etl.PipelinePlugin; diff --git a/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/actuator/StreamSqlBuilder.java b/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/actuator/StreamSqlBuilder.java index d22869f0a..e26a33991 100644 --- a/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/actuator/StreamSqlBuilder.java +++ b/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/actuator/StreamSqlBuilder.java @@ -15,9 +15,9 @@ */ package ideal.sylph.runner.flink.actuator; +import com.github.harbby.gadtry.ioc.IocFactory; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import ideal.common.ioc.IocFactory; import ideal.sylph.etl.SinkContext; import ideal.sylph.parser.SqlParserException; import ideal.sylph.parser.antlr.AntlrSqlParser; diff --git a/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/etl/FlinkNodeLoader.java b/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/etl/FlinkNodeLoader.java index 07eeb7804..fb953190f 100644 --- a/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/etl/FlinkNodeLoader.java +++ b/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/etl/FlinkNodeLoader.java @@ -15,8 +15,8 @@ */ package ideal.sylph.runner.flink.etl; -import ideal.common.ioc.IocFactory; -import ideal.common.utils.ParameterizedTypeImpl; +import com.github.harbby.gadtry.base.JavaType; +import com.github.harbby.gadtry.ioc.IocFactory; import ideal.sylph.etl.PipelinePlugin; import ideal.sylph.etl.api.RealTimeSink; import ideal.sylph.etl.api.RealTimeTransForm; @@ -78,8 +78,8 @@ public UnaryOperator> loadSource(String driverStr, final Map pluginInterface, Class driverClass) { - Type streamRow = ParameterizedTypeImpl.make(DataStream.class, new Type[] {Row.class}, null); - Type checkType = ParameterizedTypeImpl.make(pluginInterface, new Type[] {streamRow}, null); + Type streamRow = JavaType.make(DataStream.class, new Type[] {Row.class}, null); + Type checkType = JavaType.make(pluginInterface, new Type[] {streamRow}, null); for (Type type : driverClass.getGenericInterfaces()) { if (checkType.equals(type)) { diff --git a/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/local/MiniExec.java b/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/local/MiniExec.java index 2985fec12..19ea2ca2e 100644 --- a/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/local/MiniExec.java +++ b/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/local/MiniExec.java @@ -15,7 +15,7 @@ */ package ideal.sylph.runner.flink.local; -import ideal.common.jvm.VmCallable; +import com.github.harbby.gadtry.jvm.VmCallable; import org.apache.flink.api.common.JobExecutionResult; import org.apache.flink.configuration.Configuration; import org.apache.flink.configuration.RestOptions; diff --git a/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/sql/FlinkSqlParser.java b/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/sql/FlinkSqlParser.java index 7f52533dd..a7186c58c 100644 --- a/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/sql/FlinkSqlParser.java +++ b/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/sql/FlinkSqlParser.java @@ -15,7 +15,7 @@ */ package ideal.sylph.runner.flink.sql; -import ideal.common.ioc.IocFactory; +import com.github.harbby.gadtry.ioc.IocFactory; import ideal.sylph.etl.PipelinePlugin; import ideal.sylph.etl.api.RealTimeTransForm; import ideal.sylph.etl.join.JoinContext; diff --git a/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/yarn/FlinkYarnJobLauncher.java b/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/yarn/FlinkYarnJobLauncher.java index 82849d495..62d1612e8 100644 --- a/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/yarn/FlinkYarnJobLauncher.java +++ b/sylph-runners/flink/src/main/java/ideal/sylph/runner/flink/yarn/FlinkYarnJobLauncher.java @@ -15,7 +15,7 @@ */ package ideal.sylph.runner.flink.yarn; -import ideal.common.ioc.Autowired; +import com.github.harbby.gadtry.ioc.Autowired; import ideal.sylph.runner.flink.FlinkJobConfig; import ideal.sylph.runner.flink.FlinkJobHandle; import ideal.sylph.runner.flink.FlinkRunner; diff --git a/sylph-runners/flink/src/test/java/ideal/sylph/runner/flink/jvm/JVMLauncherTest.java b/sylph-runners/flink/src/test/java/ideal/sylph/runner/flink/jvm/JVMLauncherTest.java index 697f2c97d..fc6593cd7 100644 --- a/sylph-runners/flink/src/test/java/ideal/sylph/runner/flink/jvm/JVMLauncherTest.java +++ b/sylph-runners/flink/src/test/java/ideal/sylph/runner/flink/jvm/JVMLauncherTest.java @@ -15,11 +15,11 @@ */ package ideal.sylph.runner.flink.jvm; +import com.github.harbby.gadtry.jvm.JVMException; +import com.github.harbby.gadtry.jvm.JVMLauncher; +import com.github.harbby.gadtry.jvm.JVMLaunchers; +import com.github.harbby.gadtry.jvm.VmFuture; import com.google.common.collect.ImmutableList; -import ideal.common.jvm.JVMException; -import ideal.common.jvm.JVMLauncher; -import ideal.common.jvm.JVMLaunchers; -import ideal.common.jvm.VmFuture; import org.junit.Assert; import org.junit.Before; import org.junit.Test; diff --git a/sylph-runners/spark/build.gradle b/sylph-runners/spark/build.gradle index 4b7c9b996..b2892e5f3 100644 --- a/sylph-runners/spark/build.gradle +++ b/sylph-runners/spark/build.gradle @@ -1,48 +1,43 @@ ext.moduleName = 'ideal.sylph.runner.spark' apply plugin: 'scala' - configurations.all { - resolutionStrategy { preferProjectModules() } + resolutionStrategy { preferProjectModules() } } tasks.compileJava.dependsOn compileScala tasks.compileScala.dependsOn.remove("compileJava") dependencies { - runtime(project(':sylph-spi')){ + runtime(project(':sylph-spi')) { exclude(group: 'com.fasterxml.jackson.dataformat') exclude(group: 'com.fasterxml.jackson.core') exclude(module: 'guava') exclude(module: 'validation-api') exclude(module: 'commons-io') - exclude(module: 'ideal-common') - } - runtime(project(':ideal-common')){ - exclude(module: '*') } - compileOnly (group: 'org.apache.spark', name: 'spark-sql_2.11', version: deps.spark){ + compileOnly(group: 'org.apache.spark', name: 'spark-sql_2.11', version: deps.spark) { exclude(module: 'spark-core_2.11') } - compileOnly (group: 'org.apache.spark', name: 'spark-streaming_2.11', version: deps.spark){ + compileOnly(group: 'org.apache.spark', name: 'spark-streaming_2.11', version: deps.spark) { exclude(module: 'spark-core_2.11') } - compileOnly (group: 'org.apache.spark', name: 'spark-core_2.11', version: deps.spark){ + compileOnly(group: 'org.apache.spark', name: 'spark-core_2.11', version: deps.spark) { exclude(module: 'hadoop-client') } - compileOnly ("org.apache.spark:spark-yarn_2.11:$deps.spark"){ + compileOnly("org.apache.spark:spark-yarn_2.11:$deps.spark") { exclude(module: 'hadoop-client') } compileOnly group: 'org.apache.hadoop', name: 'hadoop-client', version: '2.7.3' - compileOnly (group: 'org.apache.spark', name: 'spark-streaming-kafka-0-10_2.11', version: deps.spark){ + compileOnly(group: 'org.apache.spark', name: 'spark-streaming-kafka-0-10_2.11', version: deps.spark) { //exclude(group: '*') } //--other-- compile group: 'org.fusesource.jansi', name: 'jansi', version: '1.17.1' - compile (project(':sylph-yarn')) + compile(project(':sylph-yarn')) //--- add scala class compileOnly files("$sourceSets.main.scala.outputDir") diff --git a/sylph-runners/spark/src/main/java/ideal/sylph/runner/spark/JobHelper.java b/sylph-runners/spark/src/main/java/ideal/sylph/runner/spark/JobHelper.java index c19171f56..bd69419d5 100644 --- a/sylph-runners/spark/src/main/java/ideal/sylph/runner/spark/JobHelper.java +++ b/sylph-runners/spark/src/main/java/ideal/sylph/runner/spark/JobHelper.java @@ -15,9 +15,9 @@ */ package ideal.sylph.runner.spark; -import ideal.common.ioc.Bean; -import ideal.common.jvm.JVMLauncher; -import ideal.common.jvm.JVMLaunchers; +import com.github.harbby.gadtry.ioc.Bean; +import com.github.harbby.gadtry.jvm.JVMLauncher; +import com.github.harbby.gadtry.jvm.JVMLaunchers; import ideal.sylph.runner.spark.etl.sparkstreaming.StreamNodeLoader; import ideal.sylph.runner.spark.etl.structured.StructuredNodeLoader; import ideal.sylph.spi.App; diff --git a/sylph-runners/spark/src/main/java/ideal/sylph/runner/spark/SparkContainerFactory.java b/sylph-runners/spark/src/main/java/ideal/sylph/runner/spark/SparkContainerFactory.java index 23f04805f..eb713ce24 100644 --- a/sylph-runners/spark/src/main/java/ideal/sylph/runner/spark/SparkContainerFactory.java +++ b/sylph-runners/spark/src/main/java/ideal/sylph/runner/spark/SparkContainerFactory.java @@ -15,9 +15,9 @@ */ package ideal.sylph.runner.spark; -import ideal.common.base.Lazys; -import ideal.common.ioc.IocFactory; -import ideal.common.jvm.JVMLaunchers; +import com.github.harbby.gadtry.base.Lazys; +import com.github.harbby.gadtry.ioc.IocFactory; +import com.github.harbby.gadtry.jvm.JVMLaunchers; import ideal.sylph.runner.spark.yarn.SparkAppLauncher; import ideal.sylph.runtime.local.LocalContainer; import ideal.sylph.runtime.yarn.YarnJobContainer; diff --git a/sylph-runners/spark/src/main/java/ideal/sylph/runner/spark/SparkRunner.java b/sylph-runners/spark/src/main/java/ideal/sylph/runner/spark/SparkRunner.java index 539bdc97d..2322769bd 100644 --- a/sylph-runners/spark/src/main/java/ideal/sylph/runner/spark/SparkRunner.java +++ b/sylph-runners/spark/src/main/java/ideal/sylph/runner/spark/SparkRunner.java @@ -15,8 +15,8 @@ */ package ideal.sylph.runner.spark; -import ideal.common.classloader.DirClassLoader; -import ideal.common.ioc.IocFactory; +import com.github.harbby.gadtry.classloader.DirClassLoader; +import com.github.harbby.gadtry.ioc.IocFactory; import ideal.sylph.spi.Runner; import ideal.sylph.spi.RunnerContext; import ideal.sylph.spi.job.ContainerFactory; @@ -57,7 +57,7 @@ public Set create(RunnerContext context) binder.bind(SparkSubmitActuator.class).withSingle(); //------------------------ binder.bind(PipelinePluginManager.class) - .byCreater(() -> createPipelinePluginManager(context)) + .byCreator(() -> createPipelinePluginManager(context)) .withSingle(); }); diff --git a/sylph-runners/spark/src/main/java/ideal/sylph/runner/spark/Stream2EtlActuator.java b/sylph-runners/spark/src/main/java/ideal/sylph/runner/spark/Stream2EtlActuator.java index 25b42d707..6ad961add 100644 --- a/sylph-runners/spark/src/main/java/ideal/sylph/runner/spark/Stream2EtlActuator.java +++ b/sylph-runners/spark/src/main/java/ideal/sylph/runner/spark/Stream2EtlActuator.java @@ -15,7 +15,7 @@ */ package ideal.sylph.runner.spark; -import ideal.common.ioc.Autowired; +import com.github.harbby.gadtry.ioc.Autowired; import ideal.sylph.annotation.Description; import ideal.sylph.annotation.Name; import ideal.sylph.spi.job.EtlFlow; diff --git a/sylph-runners/spark/src/main/java/ideal/sylph/runner/spark/StreamEtlActuator.java b/sylph-runners/spark/src/main/java/ideal/sylph/runner/spark/StreamEtlActuator.java index 4f6a67049..29766ed3d 100644 --- a/sylph-runners/spark/src/main/java/ideal/sylph/runner/spark/StreamEtlActuator.java +++ b/sylph-runners/spark/src/main/java/ideal/sylph/runner/spark/StreamEtlActuator.java @@ -15,7 +15,7 @@ */ package ideal.sylph.runner.spark; -import ideal.common.ioc.Autowired; +import com.github.harbby.gadtry.ioc.Autowired; import ideal.sylph.annotation.Description; import ideal.sylph.annotation.Name; import ideal.sylph.spi.job.EtlFlow; diff --git a/sylph-runners/spark/src/main/java/ideal/sylph/runner/spark/yarn/SparkAppLauncher.java b/sylph-runners/spark/src/main/java/ideal/sylph/runner/spark/yarn/SparkAppLauncher.java index 4cb909752..391b1e594 100644 --- a/sylph-runners/spark/src/main/java/ideal/sylph/runner/spark/yarn/SparkAppLauncher.java +++ b/sylph-runners/spark/src/main/java/ideal/sylph/runner/spark/yarn/SparkAppLauncher.java @@ -15,9 +15,9 @@ */ package ideal.sylph.runner.spark.yarn; +import com.github.harbby.gadtry.base.Serializables; import com.google.common.collect.ImmutableList; import com.google.inject.Inject; -import ideal.common.base.Serializables; import ideal.sylph.runner.spark.SparkJobHandle; import ideal.sylph.spi.job.Job; import org.apache.commons.lang3.StringUtils; diff --git a/sylph-runners/spark/src/main/scala/ideal/sylph/runner/spark/etl/sparkstreaming/StreamNodeLoader.scala b/sylph-runners/spark/src/main/scala/ideal/sylph/runner/spark/etl/sparkstreaming/StreamNodeLoader.scala index 229354fa8..3be2371c2 100644 --- a/sylph-runners/spark/src/main/scala/ideal/sylph/runner/spark/etl/sparkstreaming/StreamNodeLoader.scala +++ b/sylph-runners/spark/src/main/scala/ideal/sylph/runner/spark/etl/sparkstreaming/StreamNodeLoader.scala @@ -17,7 +17,7 @@ package ideal.sylph.runner.spark.etl.sparkstreaming import java.util.function.UnaryOperator -import ideal.common.ioc.{Bean, Binds, IocFactory} +import com.github.harbby.gadtry.ioc.{Bean, IocFactory} import ideal.sylph.etl.PipelinePlugin import ideal.sylph.etl.api._ import ideal.sylph.runner.spark.etl.{SparkRow, SparkUtil} diff --git a/sylph-runners/spark/src/main/scala/ideal/sylph/runner/spark/etl/structured/StructuredNodeLoader.scala b/sylph-runners/spark/src/main/scala/ideal/sylph/runner/spark/etl/structured/StructuredNodeLoader.scala index 17141ed9b..b8b7d5e27 100644 --- a/sylph-runners/spark/src/main/scala/ideal/sylph/runner/spark/etl/structured/StructuredNodeLoader.scala +++ b/sylph-runners/spark/src/main/scala/ideal/sylph/runner/spark/etl/structured/StructuredNodeLoader.scala @@ -18,7 +18,7 @@ package ideal.sylph.runner.spark.etl.structured import java.util import java.util.function.UnaryOperator -import ideal.common.ioc.{Bean, IocFactory} +import com.github.harbby.gadtry.ioc.{Bean, IocFactory} import ideal.sylph.etl.PipelinePlugin import ideal.sylph.etl.api.{RealTimeSink, RealTimeTransForm, Sink, TransForm} import ideal.sylph.runner.spark.etl.{SparkRow, SparkUtil} diff --git a/sylph-spi/build.gradle b/sylph-spi/build.gradle index 4d38dcc28..3cb9ef082 100644 --- a/sylph-spi/build.gradle +++ b/sylph-spi/build.gradle @@ -1,14 +1,16 @@ ext.moduleName = 'ideal.sylph.spi' dependencies { - compile(project(':sylph-etl-api')) - compile project(':ideal-common') - compile group: 'org.javassist', name: 'javassist', version: '3.23.1-GA' - compile group: 'commons-io', name: 'commons-io', version: '2.6' + compile group: 'org.slf4j', name: 'slf4j-log4j12', version: deps.log4j12 - compile group: 'com.google.guava', name: 'guava', version: deps.guava - compile group: 'javax.validation', name: 'validation-api', version: '1.1.0.Final' + compile(project(':sylph-etl-api')) + compile group: 'com.github.harbby', name: 'gadtry', version: '1.0.0' + compile group: 'org.javassist', name: 'javassist', version: '3.23.1-GA' + compile group: 'commons-io', name: 'commons-io', version: '2.6' - compile group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: deps.jackson - compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: deps.jackson + compile group: 'com.google.guava', name: 'guava', version: deps.guava + compile group: 'javax.validation', name: 'validation-api', version: '1.1.0.Final' + + compile group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: deps.jackson + compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: deps.jackson } diff --git a/sylph-spi/src/main/java/ideal/sylph/spi/GraphAppUtil.java b/sylph-spi/src/main/java/ideal/sylph/spi/GraphAppUtil.java index 689023871..7554d5f58 100644 --- a/sylph-spi/src/main/java/ideal/sylph/spi/GraphAppUtil.java +++ b/sylph-spi/src/main/java/ideal/sylph/spi/GraphAppUtil.java @@ -15,9 +15,9 @@ */ package ideal.sylph.spi; -import ideal.common.graph.Graph; -import ideal.common.graph.GraphBuilder; -import ideal.common.graph.impl.DagNode; +import com.github.harbby.gadtry.graph.Graph; +import com.github.harbby.gadtry.graph.GraphBuilder; +import com.github.harbby.gadtry.graph.impl.DagNode; import ideal.sylph.spi.job.EtlFlow; import ideal.sylph.spi.model.EdgeInfo; import ideal.sylph.spi.model.NodeInfo; diff --git a/sylph-spi/src/main/java/ideal/sylph/spi/NodeLoader.java b/sylph-spi/src/main/java/ideal/sylph/spi/NodeLoader.java index 9265e1dc9..7fd9042d6 100644 --- a/sylph-spi/src/main/java/ideal/sylph/spi/NodeLoader.java +++ b/sylph-spi/src/main/java/ideal/sylph/spi/NodeLoader.java @@ -15,7 +15,7 @@ */ package ideal.sylph.spi; -import ideal.common.ioc.IocFactory; +import com.github.harbby.gadtry.ioc.IocFactory; import ideal.sylph.annotation.Name; import ideal.sylph.etl.PluginConfig; import javassist.CannotCompileException; diff --git a/sylph-spi/src/main/java/ideal/sylph/spi/job/JobActuatorHandle.java b/sylph-spi/src/main/java/ideal/sylph/spi/job/JobActuatorHandle.java index f5a283a50..a3a11c100 100644 --- a/sylph-spi/src/main/java/ideal/sylph/spi/job/JobActuatorHandle.java +++ b/sylph-spi/src/main/java/ideal/sylph/spi/job/JobActuatorHandle.java @@ -15,6 +15,7 @@ */ package ideal.sylph.spi.job; +import com.github.harbby.gadtry.jvm.JVMException; import ideal.sylph.spi.model.PipelinePluginManager; import javax.validation.constraints.NotNull; @@ -35,7 +36,7 @@ public interface JobActuatorHandle * @param jobConfig job config * @param jobId job id * @return JobHandel - * @throws ideal.common.jvm.JVMException Throw it if the child process fails to compile + * @throws JVMException Throw it if the child process fails to compile */ @NotNull default JobHandle formJob(String jobId, Flow flow, JobConfig jobConfig, URLClassLoader jobClassLoader) diff --git a/sylph-spi/src/main/java/ideal/sylph/spi/model/PipelinePluginManager.java b/sylph-spi/src/main/java/ideal/sylph/spi/model/PipelinePluginManager.java index 4f7152bc0..78e764aff 100644 --- a/sylph-spi/src/main/java/ideal/sylph/spi/model/PipelinePluginManager.java +++ b/sylph-spi/src/main/java/ideal/sylph/spi/model/PipelinePluginManager.java @@ -15,10 +15,10 @@ */ package ideal.sylph.spi.model; +import com.github.harbby.gadtry.classloader.DirClassLoader; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableTable; -import ideal.common.classloader.DirClassLoader; import ideal.sylph.etl.PipelinePlugin; import ideal.sylph.spi.Runner; import org.slf4j.Logger; diff --git a/sylph-yarn/build.gradle b/sylph-yarn/build.gradle index cadd23511..d81d50014 100644 --- a/sylph-yarn/build.gradle +++ b/sylph-yarn/build.gradle @@ -1,23 +1,20 @@ - dependencies { - // conflict was found between the following modules: - compileOnly (group: 'org.apache.hadoop', name: 'hadoop-yarn-client', version: deps.hadoop){ - exclude(module: '*') - } - compileOnly (group: 'org.apache.hadoop', name: 'hadoop-yarn-api', version: deps.hadoop){ - exclude(module: '*') - } - compileOnly (group: 'org.apache.hadoop', name: 'hadoop-yarn-common', version: deps.hadoop){ - exclude(module: '*') - } + // conflict was found between the following modules: + compileOnly(group: 'org.apache.hadoop', name: 'hadoop-yarn-client', version: deps.hadoop) { + exclude(module: '*') + } + compileOnly(group: 'org.apache.hadoop', name: 'hadoop-yarn-api', version: deps.hadoop) { + exclude(module: '*') + } + compileOnly(group: 'org.apache.hadoop', name: 'hadoop-yarn-common', version: deps.hadoop) { + exclude(module: '*') + } - compileOnly (group: 'org.apache.hadoop', name: 'hadoop-common', version: deps.hadoop){ - exclude(module: '*') - } + compileOnly(group: 'org.apache.hadoop', name: 'hadoop-common', version: deps.hadoop) { + exclude(module: '*') + } - compileOnly(project(':sylph-spi')) + compileOnly(project(':sylph-spi')) - runtime(project(':ideal-common')){ - exclude(module: '*') - } + runtime group: 'com.github.harbby', name: 'gadtry', version: '1.0.0' } diff --git a/sylph-yarn/src/main/java/ideal/sylph/runtime/local/LocalContainer.java b/sylph-yarn/src/main/java/ideal/sylph/runtime/local/LocalContainer.java index 69f68827b..fc9824427 100644 --- a/sylph-yarn/src/main/java/ideal/sylph/runtime/local/LocalContainer.java +++ b/sylph-yarn/src/main/java/ideal/sylph/runtime/local/LocalContainer.java @@ -15,8 +15,8 @@ */ package ideal.sylph.runtime.local; -import ideal.common.jvm.JVMLauncher; -import ideal.common.jvm.JVMLaunchers; +import com.github.harbby.gadtry.jvm.JVMLauncher; +import com.github.harbby.gadtry.jvm.JVMLaunchers; import ideal.sylph.spi.job.Job; import ideal.sylph.spi.job.JobContainer; import org.slf4j.Logger; diff --git a/sylph-yarn/src/main/java/ideal/sylph/runtime/yarn/YarnJobContainerProxy.java b/sylph-yarn/src/main/java/ideal/sylph/runtime/yarn/YarnJobContainerProxy.java index a61471847..75ae3bde8 100644 --- a/sylph-yarn/src/main/java/ideal/sylph/runtime/yarn/YarnJobContainerProxy.java +++ b/sylph-yarn/src/main/java/ideal/sylph/runtime/yarn/YarnJobContainerProxy.java @@ -15,8 +15,8 @@ */ package ideal.sylph.runtime.yarn; -import ideal.common.classloader.ThreadContextClassLoader; -import ideal.common.proxy.DynamicProxy; +import com.github.harbby.gadtry.classloader.ThreadContextClassLoader; +import com.github.harbby.gadtry.proxy.DynamicProxy; import ideal.sylph.spi.job.JobContainer; import java.lang.reflect.Method; diff --git a/sylph-yarn/src/main/java/ideal/sylph/runtime/yarn/YarnModule.java b/sylph-yarn/src/main/java/ideal/sylph/runtime/yarn/YarnModule.java index 30a8111ea..718a6dc7a 100644 --- a/sylph-yarn/src/main/java/ideal/sylph/runtime/yarn/YarnModule.java +++ b/sylph-yarn/src/main/java/ideal/sylph/runtime/yarn/YarnModule.java @@ -15,10 +15,10 @@ */ package ideal.sylph.runtime.yarn; -import ideal.common.function.Creater; -import ideal.common.ioc.Autowired; -import ideal.common.ioc.Bean; -import ideal.common.ioc.Binder; +import com.github.harbby.gadtry.function.Creator; +import com.github.harbby.gadtry.ioc.Autowired; +import com.github.harbby.gadtry.ioc.Bean; +import com.github.harbby.gadtry.ioc.Binder; import ideal.sylph.spi.exception.SylphException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.yarn.client.api.TimelineClient; @@ -41,12 +41,12 @@ public class YarnModule @Override public void configure(Binder binder) { - binder.bind(YarnConfiguration.class).byCreater(YarnModule::loadYarnConfiguration).withSingle(); - binder.bind(YarnClient.class).byCreater(YarnClientProvider.class).withSingle(); + binder.bind(YarnConfiguration.class).byCreator(YarnModule::loadYarnConfiguration).withSingle(); + binder.bind(YarnClient.class).byCreator(YarnClientProvider.class).withSingle(); } private static class YarnClientProvider - implements Creater + implements Creator { @Autowired private YarnConfiguration yarnConfiguration;