├── hugegraph-common ├── src │ ├── test │ │ ├── java │ │ │ └── org │ │ │ │ └── apache │ │ │ │ └── hugegraph │ │ │ │ └── unit │ │ │ │ ├── config │ │ │ │ ├── test-check-error.conf │ │ │ │ ├── test-type-error.conf │ │ │ │ ├── test-list-error.conf │ │ │ │ └── test.conf │ │ │ │ ├── version │ │ │ │ └── VersionTest.java │ │ │ │ ├── perf │ │ │ │ ├── testclass │ │ │ │ │ ├── TestLightClass.java │ │ │ │ │ ├── TestPerfClass.java │ │ │ │ │ ├── TestPerfLightClass.java │ │ │ │ │ └── TestClass.java │ │ │ │ └── testclass2 │ │ │ │ │ └── TestClass4Package.java │ │ │ │ ├── util │ │ │ │ └── LogTest.java │ │ │ │ ├── rest │ │ │ │ └── AbstractRestClientTest.java │ │ │ │ ├── license │ │ │ │ ├── LicenseInstallParamTest.java │ │ │ │ ├── LicenseExtraParamTest.java │ │ │ │ ├── LicenseParamsTest.java │ │ │ │ └── MachineInfoTest.java │ │ │ │ ├── concurrent │ │ │ │ ├── AtomicLockTest.java │ │ │ │ └── PausableScheduledThreadPoolTest.java │ │ │ │ └── BaseUnitTest.java │ │ └── resources │ │ │ ├── verify-license.json │ │ │ ├── META-INF │ │ │ └── MANIFEST.MF │ │ │ ├── create-license.json │ │ │ ├── mockito-extensions │ │ │ └── org.mockito.plugins.MockMaker │ │ │ └── log4j2.xml │ └── main │ │ └── java │ │ └── org │ │ └── apache │ │ └── hugegraph │ │ ├── func │ │ └── TriFunction.java │ │ ├── iterator │ │ ├── Metadatable.java │ │ ├── CIter.java │ │ ├── MapperIterator.java │ │ ├── FilterIterator.java │ │ ├── FlatMapperFilterIterator.java │ │ ├── LimitIterator.java │ │ ├── ListIterator.java │ │ ├── FlatMapperIterator.java │ │ ├── ExtendableIterator.java │ │ └── WrappedIterator.java │ │ ├── event │ │ ├── EventListener.java │ │ └── Event.java │ │ ├── util │ │ ├── Log.java │ │ ├── CheckSocket.java │ │ ├── HashUtil.java │ │ ├── ExceptionUtil.java │ │ ├── TimeUtil.java │ │ ├── InsertionOrderUtil.java │ │ ├── E.java │ │ ├── DateUtil.java │ │ └── JsonUtilCommon.java │ │ ├── version │ │ └── CommonVersion.java │ │ ├── license │ │ ├── LicenseManager.java │ │ ├── LicenseManagerFactory.java │ │ ├── LicenseParams.java │ │ ├── LicenseInstallParam.java │ │ ├── LicenseCreateParam.java │ │ ├── LicenseExtraParam.java │ │ └── LicenseCommonParam.java │ │ ├── rest │ │ ├── SerializeException.java │ │ ├── ClientException.java │ │ ├── RestClientConfig.java │ │ ├── OkHttpBasicAuthInterceptor.java │ │ ├── OkHttpTokenInterceptor.java │ │ ├── RestClient.java │ │ └── RestHeaders.java │ │ ├── config │ │ ├── ConfigException.java │ │ ├── ConfigOption.java │ │ ├── ConfigConvOption.java │ │ ├── OptionHolder.java │ │ ├── ConfigListConvOption.java │ │ ├── ConfigListOption.java │ │ └── OptionChecker.java │ │ ├── date │ │ └── SafeDateFormat.java │ │ └── concurrent │ │ ├── LockManager.java │ │ ├── PausableScheduledThreadPool.java │ │ ├── AtomicLock.java │ │ └── LockGroup.java ├── build.sh └── README.md ├── NOTICE ├── hugegraph-dist └── release-docs │ └── licenses │ ├── LICENSE-jackson-dataformat-yaml.txt │ ├── LICENSE-jackson-jaxrs-base.txt │ ├── LICENSE-jackson-jaxrs-base-2.14.0.txt │ ├── LICENSE-jackson-jaxrs-json-provider.txt │ ├── LICENSE-jackson-jaxrs-json-provider-2.14.0.txt │ ├── LICENSE-jackson-module-jaxb-annotations.txt │ ├── LICENSE-jackson-module-jaxb-annotations-2.14.0.txt │ ├── LICENSE-swagger-models.txt │ ├── LICENSE-swagger-annotations.txt │ ├── LICENSE-animal-sniffer.txt │ ├── LICENSE-checker-qual.txt │ ├── LICENSE-slf4j.txt │ ├── LICENSE-jaxb-ri.txt │ ├── LICENSE-api-client-staging.txt │ ├── LICENSE-JavaHamcrest.txt │ ├── LICENSE-jaf-api.txt │ ├── LICENSE-jakarta.activation-api.txt │ └── LICENSE-protobuf.txt ├── hugegraph-rpc ├── README.md └── src │ ├── test │ ├── resources │ │ ├── rpc-client.properties │ │ ├── rpc-server-random.properties │ │ ├── rpc-server.properties │ │ ├── rpc-server3.properties │ │ ├── rpc-server4.properties │ │ ├── rpc-server5.properties │ │ ├── rpc-server1-client.properties │ │ ├── rpc-server2-client.properties │ │ ├── rpc-client67.properties │ │ ├── rpc-client-lb.properties │ │ ├── rpc-client345.properties │ │ ├── rpc-client346.properties │ │ ├── rpc-server-adaptive.properties │ │ └── log4j2.xml │ └── java │ │ └── org │ │ └── apache │ │ └── hugegraph │ │ └── unit │ │ ├── UnitTestSuite.java │ │ ├── VersionTest.java │ │ ├── BaseUnitTest.java │ │ └── ExceptionTest.java │ └── main │ └── java │ └── org │ └── apache │ └── hugegraph │ ├── rpc │ ├── RpcServiceConfig4Server.java │ ├── RpcServiceConfig4Client.java │ ├── RpcException.java │ ├── RpcCommonConfig.java │ ├── RpcClientProvider.java │ └── RpcProviderConfig.java │ └── version │ └── RpcVersion.java ├── DISCLAIMER └── .editorconfig /hugegraph-common/src/test/java/org/apache/hugegraph/unit/config/test-check-error.conf: -------------------------------------------------------------------------------- 1 | group1.int_check_error=101 2 | -------------------------------------------------------------------------------- /hugegraph-common/src/test/java/org/apache/hugegraph/unit/config/test-type-error.conf: -------------------------------------------------------------------------------- 1 | group1.int_type_error=string 2 | -------------------------------------------------------------------------------- /hugegraph-common/src/test/java/org/apache/hugegraph/unit/config/test-list-error.conf: -------------------------------------------------------------------------------- 1 | group1.list_for_list_error=[1,2,3] 2 | 3 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Apache HugeGraph(incubating) 2 | Copyright 2022-2023 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | 7 | The initial codebase was donated to the ASF by HugeGraph Authors, copyright 2017-2021. 8 | -------------------------------------------------------------------------------- /hugegraph-common/src/test/resources/verify-license.json: -------------------------------------------------------------------------------- 1 | { 2 | "subject": "hugegraph-evaluation", 3 | "public_alias": "publiccert", 4 | "store_ticket": "a123456", 5 | "publickey_path": "src/test/resources/publicCerts.store", 6 | "license_path": "src/test/resources/hugegraph-evaluation.license" 7 | } 8 | -------------------------------------------------------------------------------- /hugegraph-common/src/test/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Implementation-Version: 1.8.8.0 3 | Archiver-Version: Plexus Archiver 4 | Built-By: jermy 5 | Specification-Title: hugegraph-common 6 | Created-By: Apache Maven 3.3.9 7 | Build-Jdk: 1.8.0_111 8 | Specification-Version: 1.8.8 9 | 10 | -------------------------------------------------------------------------------- /hugegraph-dist/release-docs/licenses/LICENSE-jackson-dataformat-yaml.txt: -------------------------------------------------------------------------------- 1 | This copy of Jackson JSON processor YAML module is licensed under the 2 | Apache (Software) License, version 2.0 ("the License"). 3 | See the License for details about distribution rights, and the 4 | specific rights regarding derivate works. 5 | 6 | You may obtain a copy of the License at: 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | -------------------------------------------------------------------------------- /hugegraph-dist/release-docs/licenses/LICENSE-jackson-jaxrs-base.txt: -------------------------------------------------------------------------------- 1 | This copy of Jackson JSON processor databind module is licensed under the 2 | Apache (Software) License, version 2.0 ("the License"). 3 | See the License for details about distribution rights, and the 4 | specific rights regarding derivate works. 5 | 6 | You may obtain a copy of the License at: 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | -------------------------------------------------------------------------------- /hugegraph-dist/release-docs/licenses/LICENSE-jackson-jaxrs-base-2.14.0.txt: -------------------------------------------------------------------------------- 1 | This copy of Jackson JSON processor databind module is licensed under the 2 | Apache (Software) License, version 2.0 ("the License"). 3 | See the License for details about distribution rights, and the 4 | specific rights regarding derivate works. 5 | 6 | You may obtain a copy of the License at: 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | -------------------------------------------------------------------------------- /hugegraph-dist/release-docs/licenses/LICENSE-jackson-jaxrs-json-provider.txt: -------------------------------------------------------------------------------- 1 | This copy of Jackson JSON processor databind module is licensed under the 2 | Apache (Software) License, version 2.0 ("the License"). 3 | See the License for details about distribution rights, and the 4 | specific rights regarding derivate works. 5 | 6 | You may obtain a copy of the License at: 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | -------------------------------------------------------------------------------- /hugegraph-dist/release-docs/licenses/LICENSE-jackson-jaxrs-json-provider-2.14.0.txt: -------------------------------------------------------------------------------- 1 | This copy of Jackson JSON processor databind module is licensed under the 2 | Apache (Software) License, version 2.0 ("the License"). 3 | See the License for details about distribution rights, and the 4 | specific rights regarding derivate works. 5 | 6 | You may obtain a copy of the License at: 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | -------------------------------------------------------------------------------- /hugegraph-dist/release-docs/licenses/LICENSE-jackson-module-jaxb-annotations.txt: -------------------------------------------------------------------------------- 1 | This copy of Jackson JSON processor `jackson-module-jaxb-annotations` module is licensed under the 2 | Apache (Software) License, version 2.0 ("the License"). 3 | See the License for details about distribution rights, and the 4 | specific rights regarding derivate works. 5 | 6 | You may obtain a copy of the License at: 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | -------------------------------------------------------------------------------- /hugegraph-dist/release-docs/licenses/LICENSE-jackson-module-jaxb-annotations-2.14.0.txt: -------------------------------------------------------------------------------- 1 | This copy of Jackson JSON processor `jackson-module-jaxb-annotations` module is licensed under the 2 | Apache (Software) License, version 2.0 ("the License"). 3 | See the License for details about distribution rights, and the 4 | specific rights regarding derivate works. 5 | 6 | You may obtain a copy of the License at: 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | -------------------------------------------------------------------------------- /hugegraph-rpc/README.md: -------------------------------------------------------------------------------- 1 | # HugeGraph-RPC 2 | 3 | HugeGraph Database RPC component, currently it's based on [Sofa-RPC](https://github.com/sofastack/sofa-rpc) 4 | 5 | ## Features 6 | 7 | ## Learn More 8 | 9 | The [project homepage](https://hugegraph.github.io/hugegraph-doc/) contains more information on 10 | HugeGraph and provides links to documentation, getting-started guides and release downloads. 11 | 12 | ## License 13 | 14 | HugeGraph is licensed under Apache 2.0 License. 15 | -------------------------------------------------------------------------------- /hugegraph-common/src/test/java/org/apache/hugegraph/unit/config/test.conf: -------------------------------------------------------------------------------- 1 | group1.text1=file-text1-value 2 | group1.text2=file-text2-value 3 | group1.text3=CHOICE-3 4 | 5 | group1.int1=2 6 | group1.int2=0 7 | group1.int3=1 8 | group1.long1=99 9 | 10 | group1.float1=66 11 | group1.double1=66 12 | 13 | group1.bool=false 14 | 15 | group1.class=java.lang.String 16 | 17 | group1.list=[file-v1, file-v2, file-v3] 18 | group1.map=[key1:value1, key3:value3] 19 | 20 | group1.weekday=SUNDAY 21 | group1.weekdays=[SATURDAY, FRIDAY] 22 | 23 | group1.no-used=value 24 | -------------------------------------------------------------------------------- /DISCLAIMER: -------------------------------------------------------------------------------- 1 | Apache HugeGraph (incubating) is an effort undergoing incubation at The Apache Software Foundation (ASF), sponsored by the Apache Incubator PMC. 2 | 3 | Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, 4 | and decision making process have stabilized in a manner consistent with other successful ASF projects. 5 | 6 | While incubation status is not necessarily a reflection of the completeness or stability of the code, 7 | it does indicate that the project has yet to be fully endorsed by the ASF. 8 | -------------------------------------------------------------------------------- /hugegraph-common/src/test/resources/create-license.json: -------------------------------------------------------------------------------- 1 | { 2 | "subject": "hugegraph-evaluation", 3 | "private_alias": "privatekey", 4 | "key_ticket": "a123456", 5 | "store_ticket": "a123456", 6 | "privatekey_path": "src/test/resources/privateKeys.store", 7 | "license_path": "src/test/resources/hugegraph-evaluation.license", 8 | "issued_time": "2019-08-01 00:00:00", 9 | "not_before": "2019-08-01 00:00:00", 10 | "not_after": "2029-08-01 00:00:00", 11 | "consumer_type": "user", 12 | "consumer_amount": 1, 13 | "extra_params": [ 14 | { 15 | "id": "server-1", 16 | "graphs": 3 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /hugegraph-dist/release-docs/licenses/LICENSE-swagger-models.txt: -------------------------------------------------------------------------------- 1 | Copyright 2016 SmartBear Software 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0) 6 | 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. -------------------------------------------------------------------------------- /hugegraph-dist/release-docs/licenses/LICENSE-swagger-annotations.txt: -------------------------------------------------------------------------------- 1 | Copyright 2016 SmartBear Software 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0) 6 | 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. -------------------------------------------------------------------------------- /hugegraph-common/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with this 4 | # work for additional information regarding copyright ownership. The ASF 5 | # licenses this file to You under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | # License for the specific language governing permissions and limitations 15 | # under the License. 16 | # 17 | mock-maker-inline 18 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/func/TriFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.func; 19 | 20 | public interface TriFunction { 21 | 22 | R apply(T1 v1, T2 v2, T3 v3); 23 | } 24 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/iterator/Metadatable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.iterator; 19 | 20 | public interface Metadatable { 21 | 22 | Object metadata(String meta, Object... args); 23 | } 24 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/iterator/CIter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.iterator; 19 | 20 | import java.util.Iterator; 21 | 22 | public interface CIter extends Iterator, AutoCloseable, Metadatable { 23 | } 24 | -------------------------------------------------------------------------------- /hugegraph-common/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Licensed to the Apache Software Foundation (ASF) under one or more 4 | # contributor license agreements. See the NOTICE file distributed with 5 | # this work for additional information regarding copyright ownership. 6 | # The ASF licenses this file to You under the Apache License, Version 2.0 7 | # (the "License"); you may not use this file except in compliance with 8 | # the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | export MAVEN_HOME=/home/scmtools/buildkit/maven/apache-maven-3.3.9/ 20 | export JAVA_HOME=/home/scmtools/buildkit/java/jdk1.8.0_25/ 21 | export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH 22 | 23 | mvn clean test -Dtest=UnitTestSuite 24 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | root = true 19 | 20 | [*] 21 | charset = utf-8 22 | end_of_line = lf 23 | insert_final_newline = true 24 | 25 | [*.{java, xml, py}] 26 | indent_style = space 27 | indent_size = 4 28 | 29 | [*.{java, xml}] 30 | # Ignore the IDEA unsupported warning & it works well (indeed) 31 | continuation_indent_size = 8 32 | -------------------------------------------------------------------------------- /hugegraph-rpc/src/test/resources/rpc-client.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with this 4 | # work for additional information regarding copyright ownership. The ASF 5 | # licenses this file to You under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | # License for the specific language governing permissions and limitations 15 | # under the License. 16 | # 17 | 18 | #rpc.server_host=127.0.0.1 19 | #rpc.server_port=8090 20 | #rpc.server_timeout=30 21 | rpc.remote_url=127.0.0.1:8090 22 | #rpc.client_connect_timeout=20 23 | #rpc.client_reconnect_period=10 24 | #rpc.client_read_timeout=40 25 | #rpc.client_retries=3 26 | #rpc.client_load_balancer=consistentHash 27 | -------------------------------------------------------------------------------- /hugegraph-rpc/src/test/resources/rpc-server-random.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with this 4 | # work for additional information regarding copyright ownership. The ASF 5 | # licenses this file to You under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | # License for the specific language governing permissions and limitations 15 | # under the License. 16 | # 17 | 18 | rpc.server_host=127.0.0.1 19 | rpc.server_port=0 20 | #rpc.server_timeout=30 21 | #rpc.remote_url=127.0.0.1:8090 22 | #rpc.client_connect_timeout=20 23 | #rpc.client_reconnect_period=10 24 | #rpc.client_read_timeout=40 25 | #rpc.client_retries=3 26 | #rpc.client_load_balancer=consistentHash 27 | -------------------------------------------------------------------------------- /hugegraph-rpc/src/test/resources/rpc-server.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with this 4 | # work for additional information regarding copyright ownership. The ASF 5 | # licenses this file to You under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | # License for the specific language governing permissions and limitations 15 | # under the License. 16 | # 17 | 18 | rpc.server_host=127.0.0.1 19 | rpc.server_port=8090 20 | #rpc.server_timeout=30 21 | #rpc.remote_url=127.0.0.1:8090 22 | #rpc.client_connect_timeout=20 23 | #rpc.client_reconnect_period=10 24 | #rpc.client_read_timeout=40 25 | #rpc.client_retries=3 26 | #rpc.client_load_balancer=consistentHash 27 | -------------------------------------------------------------------------------- /hugegraph-rpc/src/test/resources/rpc-server3.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with this 4 | # work for additional information regarding copyright ownership. The ASF 5 | # licenses this file to You under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | # License for the specific language governing permissions and limitations 15 | # under the License. 16 | # 17 | 18 | rpc.server_host=127.0.0.1 19 | rpc.server_port=8093 20 | #rpc.server_timeout=30 21 | #rpc.remote_url=127.0.0.1:8090 22 | #rpc.client_connect_timeout=20 23 | #rpc.client_reconnect_period=10 24 | #rpc.client_read_timeout=40 25 | #rpc.client_retries=3 26 | #rpc.client_load_balancer=consistentHash 27 | -------------------------------------------------------------------------------- /hugegraph-rpc/src/test/resources/rpc-server4.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with this 4 | # work for additional information regarding copyright ownership. The ASF 5 | # licenses this file to You under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | # License for the specific language governing permissions and limitations 15 | # under the License. 16 | # 17 | 18 | rpc.server_host=127.0.0.1 19 | rpc.server_port=8094 20 | #rpc.server_timeout=30 21 | #rpc.remote_url=127.0.0.1:8090 22 | #rpc.client_connect_timeout=20 23 | #rpc.client_reconnect_period=10 24 | #rpc.client_read_timeout=40 25 | #rpc.client_retries=3 26 | #rpc.client_load_balancer=consistentHash 27 | -------------------------------------------------------------------------------- /hugegraph-rpc/src/test/resources/rpc-server5.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with this 4 | # work for additional information regarding copyright ownership. The ASF 5 | # licenses this file to You under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | # License for the specific language governing permissions and limitations 15 | # under the License. 16 | # 17 | 18 | rpc.server_host=127.0.0.1 19 | rpc.server_port=8095 20 | #rpc.server_timeout=30 21 | #rpc.remote_url=127.0.0.1:8090 22 | #rpc.client_connect_timeout=20 23 | #rpc.client_reconnect_period=10 24 | #rpc.client_read_timeout=40 25 | #rpc.client_retries=3 26 | #rpc.client_load_balancer=consistentHash 27 | -------------------------------------------------------------------------------- /hugegraph-rpc/src/test/resources/rpc-server1-client.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with this 4 | # work for additional information regarding copyright ownership. The ASF 5 | # licenses this file to You under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | # License for the specific language governing permissions and limitations 15 | # under the License. 16 | # 17 | 18 | rpc.server_host=127.0.0.1 19 | rpc.server_port=8091 20 | #rpc.server_timeout=30 21 | rpc.remote_url=127.0.0.1:8092 22 | #rpc.client_connect_timeout=20 23 | #rpc.client_reconnect_period=10 24 | #rpc.client_read_timeout=40 25 | #rpc.client_retries=3 26 | #rpc.client_load_balancer=consistentHash 27 | -------------------------------------------------------------------------------- /hugegraph-rpc/src/test/resources/rpc-server2-client.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with this 4 | # work for additional information regarding copyright ownership. The ASF 5 | # licenses this file to You under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | # License for the specific language governing permissions and limitations 15 | # under the License. 16 | # 17 | 18 | rpc.server_host=127.0.0.1 19 | rpc.server_port=8092 20 | #rpc.server_timeout=30 21 | rpc.remote_url=127.0.0.1:8091 22 | #rpc.client_connect_timeout=20 23 | #rpc.client_reconnect_period=10 24 | #rpc.client_read_timeout=40 25 | #rpc.client_retries=3 26 | #rpc.client_load_balancer=consistentHash 27 | -------------------------------------------------------------------------------- /hugegraph-dist/release-docs/licenses/LICENSE-animal-sniffer.txt: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2009 codehaus.org. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /hugegraph-rpc/src/test/resources/rpc-client67.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with this 4 | # work for additional information regarding copyright ownership. The ASF 5 | # licenses this file to You under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | # License for the specific language governing permissions and limitations 15 | # under the License. 16 | # 17 | 18 | #rpc.server_host=127.0.0.1 19 | #rpc.server_port=8090 20 | #rpc.server_timeout=30 21 | rpc.remote_url=127.0.0.1:8096,127.0.0.1:8097 22 | #rpc.client_connect_timeout=20 23 | #rpc.client_reconnect_period=10 24 | #rpc.client_read_timeout=40 25 | #rpc.client_retries=3 26 | #rpc.client_load_balancer=consistentHash 27 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/event/EventListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.event; 19 | 20 | public interface EventListener extends java.util.EventListener { 21 | /** 22 | * The event callback 23 | * @param event object 24 | * @return event result 25 | */ 26 | Object event(Event event); 27 | } 28 | -------------------------------------------------------------------------------- /hugegraph-rpc/src/test/resources/rpc-client-lb.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with this 4 | # work for additional information regarding copyright ownership. The ASF 5 | # licenses this file to You under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | # License for the specific language governing permissions and limitations 15 | # under the License. 16 | # 17 | 18 | #rpc.server_host=127.0.0.1 19 | #rpc.server_port=8090 20 | #rpc.server_timeout=30 21 | rpc.remote_url=127.0.0.1:8093,127.0.0.1:8094,127.0.0.1:8095 22 | #rpc.client_connect_timeout=20 23 | #rpc.client_reconnect_period=10 24 | #rpc.client_read_timeout=40 25 | #rpc.client_retries=3 26 | rpc.client_load_balancer=consistentHash 27 | -------------------------------------------------------------------------------- /hugegraph-rpc/src/test/resources/rpc-client345.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with this 4 | # work for additional information regarding copyright ownership. The ASF 5 | # licenses this file to You under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | # License for the specific language governing permissions and limitations 15 | # under the License. 16 | # 17 | 18 | #rpc.server_host=127.0.0.1 19 | #rpc.server_port=8090 20 | #rpc.server_timeout=30 21 | rpc.remote_url=127.0.0.1:8093,127.0.0.1:8094,127.0.0.1:8095 22 | #rpc.client_connect_timeout=20 23 | #rpc.client_reconnect_period=10 24 | #rpc.client_read_timeout=40 25 | #rpc.client_retries=3 26 | #rpc.client_load_balancer=consistentHash 27 | -------------------------------------------------------------------------------- /hugegraph-rpc/src/test/resources/rpc-client346.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with this 4 | # work for additional information regarding copyright ownership. The ASF 5 | # licenses this file to You under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | # License for the specific language governing permissions and limitations 15 | # under the License. 16 | # 17 | 18 | #rpc.server_host=127.0.0.1 19 | #rpc.server_port=8090 20 | #rpc.server_timeout=30 21 | rpc.remote_url=127.0.0.1:8093,127.0.0.1:8094,127.0.0.1:8096 22 | #rpc.client_connect_timeout=20 23 | #rpc.client_reconnect_period=10 24 | #rpc.client_read_timeout=40 25 | #rpc.client_retries=3 26 | #rpc.client_load_balancer=consistentHash 27 | -------------------------------------------------------------------------------- /hugegraph-rpc/src/test/resources/rpc-server-adaptive.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with this 4 | # work for additional information regarding copyright ownership. The ASF 5 | # licenses this file to You under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | # License for the specific language governing permissions and limitations 15 | # under the License. 16 | # 17 | 18 | rpc.server_host=127.0.0.1 19 | rpc.server_port=8098 20 | rpc.server_adaptive_port=true 21 | #rpc.server_timeout=30 22 | #rpc.remote_url=127.0.0.1:8090 23 | #rpc.client_connect_timeout=20 24 | #rpc.client_reconnect_period=10 25 | #rpc.client_read_timeout=40 26 | #rpc.client_retries=3 27 | #rpc.client_load_balancer=consistentHash 28 | -------------------------------------------------------------------------------- /hugegraph-rpc/src/test/java/org/apache/hugegraph/unit/UnitTestSuite.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.unit; 19 | 20 | import org.junit.runner.RunWith; 21 | import org.junit.runners.Suite; 22 | 23 | @RunWith(Suite.class) 24 | @Suite.SuiteClasses({ 25 | VersionTest.class, 26 | ExceptionTest.class, 27 | ServerClientTest.class 28 | }) 29 | public class UnitTestSuite { 30 | } 31 | -------------------------------------------------------------------------------- /hugegraph-dist/release-docs/licenses/LICENSE-checker-qual.txt: -------------------------------------------------------------------------------- 1 | Checker Framework qualifiers 2 | Copyright 2004-present by the Checker Framework developers 3 | 4 | MIT License: 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /hugegraph-dist/release-docs/licenses/LICENSE-slf4j.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2004-2022 QOS.ch Sarl (Switzerland) 2 | All rights reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | 24 | -------------------------------------------------------------------------------- /hugegraph-rpc/src/main/java/org/apache/hugegraph/rpc/RpcServiceConfig4Server.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.rpc; 19 | 20 | public interface RpcServiceConfig4Server { 21 | 22 | String addService(Class clazz, S serviceImpl); 23 | 24 | String addService(String graph, Class clazz, S serviceImpl); 25 | 26 | void removeService(String serviceId); 27 | 28 | void removeAllService(); 29 | } 30 | -------------------------------------------------------------------------------- /hugegraph-rpc/src/main/java/org/apache/hugegraph/version/RpcVersion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.version; 19 | 20 | import org.apache.hugegraph.util.VersionUtil.Version; 21 | 22 | public class RpcVersion { 23 | 24 | public static final String NAME = "hugegraph-rpc"; 25 | 26 | // The second parameter of Version.of() is for all-in-one JAR 27 | public static final Version VERSION = Version.of(RpcVersion.class, "1.3.0"); 28 | } 29 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/util/Log.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.util; 19 | 20 | import org.slf4j.Logger; 21 | import org.slf4j.LoggerFactory; 22 | 23 | public final class Log { 24 | 25 | public static Logger logger(String name) { 26 | return LoggerFactory.getLogger(name); 27 | } 28 | 29 | public static Logger logger(Class clazz) { 30 | return LoggerFactory.getLogger(clazz); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/version/CommonVersion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.version; 19 | 20 | import org.apache.hugegraph.util.VersionUtil.Version; 21 | 22 | public class CommonVersion { 23 | 24 | public static final String NAME = "hugegraph-common"; 25 | 26 | // The second parameter of Version.of() is for all-in-one JAR 27 | public static final Version VERSION = Version.of(CommonVersion.class, "1.3.0"); 28 | } 29 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/license/LicenseManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.license; 19 | 20 | public interface LicenseManager { 21 | 22 | LicenseParams installLicense() throws Exception; 23 | 24 | void uninstallLicense() throws Exception; 25 | 26 | LicenseParams verifyLicense() throws Exception; 27 | 28 | interface VerifyCallback { 29 | 30 | void onVerifyLicense(LicenseParams params) throws Exception; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/license/LicenseManagerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.license; 19 | 20 | import org.apache.commons.lang.NotImplementedException; 21 | 22 | import org.apache.hugegraph.license.LicenseManager.VerifyCallback; 23 | 24 | public class LicenseManagerFactory { 25 | 26 | public static LicenseManager create(LicenseInstallParam param, 27 | VerifyCallback veryfyCallback) { 28 | throw new NotImplementedException("No LicenseManager available"); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /hugegraph-rpc/src/main/java/org/apache/hugegraph/rpc/RpcServiceConfig4Client.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.rpc; 19 | 20 | public interface RpcServiceConfig4Client { 21 | 22 | T serviceProxy(String interfaceId); 23 | 24 | T serviceProxy(String graph, String interfaceId); 25 | 26 | default T serviceProxy(Class clazz) { 27 | return this.serviceProxy(clazz.getName()); 28 | } 29 | 30 | default T serviceProxy(String graph, Class clazz) { 31 | return this.serviceProxy(graph, clazz.getName()); 32 | } 33 | 34 | void removeAllServiceProxy(); 35 | } 36 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/rest/SerializeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.rest; 19 | 20 | public class SerializeException extends ClientException { 21 | 22 | private static final long serialVersionUID = -4622753445618619311L; 23 | 24 | public SerializeException(String message, Throwable e) { 25 | super(message, e); 26 | } 27 | 28 | public SerializeException(String message, Object... args) { 29 | super(message, args); 30 | } 31 | 32 | public SerializeException(String message, Throwable e, Object... args) { 33 | super(message, e, args); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/util/CheckSocket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.util; 19 | 20 | import static java.lang.System.exit; 21 | 22 | import java.net.InetAddress; 23 | import java.net.Socket; 24 | 25 | public final class CheckSocket { 26 | 27 | public static void main(String[] args) { 28 | try { 29 | // Check if the socket connection can be closed normally 30 | new Socket(InetAddress.getByName(args[0]), Integer.parseInt(args[1])).close(); 31 | exit(0); 32 | } catch (Exception e) { 33 | e.printStackTrace(); 34 | exit(-1); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/rest/ClientException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.rest; 19 | 20 | public class ClientException extends RuntimeException { 21 | 22 | private static final long serialVersionUID = 814572040103754705L; 23 | 24 | public ClientException(String message, Throwable cause) { 25 | super(message, cause); 26 | } 27 | 28 | public ClientException(String message, Object... args) { 29 | super(String.format(message, args)); 30 | } 31 | 32 | public ClientException(String message, Throwable cause, Object... args) { 33 | super(String.format(message, args), cause); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /hugegraph-rpc/src/test/java/org/apache/hugegraph/unit/VersionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.unit; 19 | 20 | import org.junit.Test; 21 | 22 | import org.apache.hugegraph.testutil.Assert; 23 | import org.apache.hugegraph.util.VersionUtil; 24 | import org.apache.hugegraph.version.RpcVersion; 25 | 26 | public class VersionTest { 27 | 28 | @Test 29 | public void testGetRpcVersion() { 30 | String pomVersion = VersionUtil.getPomVersion(); 31 | Assert.assertNotNull(pomVersion); 32 | String version = RpcVersion.VERSION.get(); 33 | Assert.assertNotNull(version); 34 | Assert.assertEquals(pomVersion, version); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /hugegraph-common/src/test/java/org/apache/hugegraph/unit/version/VersionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.unit.version; 19 | 20 | import org.apache.hugegraph.util.VersionUtil; 21 | import org.junit.Test; 22 | 23 | import org.apache.hugegraph.testutil.Assert; 24 | import org.apache.hugegraph.version.CommonVersion; 25 | 26 | public class VersionTest { 27 | 28 | @Test 29 | public void testGetCommonVersion() { 30 | String pomVersion = VersionUtil.getPomVersion(); 31 | Assert.assertNotNull(pomVersion); 32 | String version = CommonVersion.VERSION.get(); 33 | Assert.assertNotNull(version); 34 | Assert.assertEquals(pomVersion, version); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /hugegraph-dist/release-docs/licenses/LICENSE-jaxb-ri.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 | 5 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 | 7 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 8 | 9 | Neither the name of the Eclipse Foundation, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 10 | 11 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /hugegraph-common/README.md: -------------------------------------------------------------------------------- 1 | # hugegraph-common 2 | 3 | [![License](https://img.shields.io/badge/license-Apache%202-0E78BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) 4 | [![Build Status](https://travis-ci.org/hugegraph/hugegraph-common.svg?branch=master)](https://travis-ci.org/hugegraph/hugegraph-common) 5 | [![codecov](https://codecov.io/gh/hugegraph/hugegraph-common/branch/master/graph/badge.svg)](https://codecov.io/gh/hugegraph/hugegraph-common) 6 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.hugegraph/hugegraph-common/badge.svg)](https://mvnrepository.com/artifact/org.apache.hugegraph/hugegraph-common) 7 | 8 | hugegraph-common is a common module for [HugeGraph](https://github.com/hugegraph/hugegraph) and its peripheral components. 9 | hugegraph-common encapsulates locks, configurations, events, iterators, rest and some 10 | numeric or collection util classes to simplify the development of HugeGraph and 11 | its components. 12 | 13 | ## Components 14 | 15 | - Lock: atomic lock, key lock, lock group and lock manger 16 | - Config: register and load config option with security check 17 | - Event: listening and notification, do something asynchronously 18 | - Iterator: some iterators with extra functions, map, filter, extend, etc. 19 | - Rest: RESTful client implemented on Jersey, POST, PUT, GET and DELETE 20 | - Util: Performance analyzer, version checker, numeric and Collection utils, log and exception utils, etc. 21 | 22 | ## Licence 23 | The same as HugeGraph, hugegraph-common is also licensed under Apache 2.0 License. 24 | -------------------------------------------------------------------------------- /hugegraph-rpc/src/main/java/org/apache/hugegraph/rpc/RpcException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.rpc; 19 | 20 | public class RpcException extends RuntimeException { 21 | 22 | private static final long serialVersionUID = -6067652498161184537L; 23 | 24 | public RpcException(String message) { 25 | super(message); 26 | } 27 | 28 | public RpcException(String message, Throwable cause) { 29 | super(message, cause); 30 | } 31 | 32 | public RpcException(String message, Object... args) { 33 | super(String.format(message, args)); 34 | } 35 | 36 | public RpcException(String message, Throwable cause, Object... args) { 37 | super(String.format(message, args), cause); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /hugegraph-dist/release-docs/licenses/LICENSE-api-client-staging.txt: -------------------------------------------------------------------------------- 1 | Copyright 2016, Google Inc. 2 | All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above 9 | copyright notice, this list of conditions and the following disclaimer 10 | in the documentation and/or other materials provided with the 11 | distribution. 12 | * Neither the name of Google Inc. nor the names of its 13 | contributors may be used to endorse or promote products derived from 14 | this software without specific prior written permission. 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/config/ConfigException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.config; 19 | 20 | public class ConfigException extends RuntimeException { 21 | 22 | private static final long serialVersionUID = -8711375282196157058L; 23 | 24 | public ConfigException(String message) { 25 | super(message); 26 | } 27 | 28 | public ConfigException(String message, Throwable cause) { 29 | super(message, cause); 30 | } 31 | 32 | public ConfigException(String message, Object... args) { 33 | super(String.format(message, args)); 34 | } 35 | 36 | public ConfigException(String message, Throwable cause, Object... args) { 37 | super(String.format(message, args), cause); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /hugegraph-dist/release-docs/licenses/LICENSE-JavaHamcrest.txt: -------------------------------------------------------------------------------- 1 | BSD License 2 | 3 | Copyright (c) 2000-2015 www.hamcrest.org 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | Redistributions of source code must retain the above copyright notice, this list of 10 | conditions and the following disclaimer. Redistributions in binary form must reproduce 11 | the above copyright notice, this list of conditions and the following disclaimer in 12 | the documentation and/or other materials provided with the distribution. 13 | 14 | Neither the name of Hamcrest nor the names of its contributors may be used to endorse 15 | or promote products derived from this software without specific prior written 16 | permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 21 | SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 23 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 24 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 26 | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 27 | DAMAGE. 28 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/config/ConfigOption.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.config; 19 | 20 | import com.google.common.base.Predicate; 21 | 22 | public class ConfigOption extends TypedOption { 23 | 24 | public ConfigOption(String name, String desc, T value) { 25 | this(name, desc, null, value); 26 | } 27 | 28 | @SuppressWarnings("unchecked") 29 | public ConfigOption(String name, String desc, Predicate pred, T value) { 30 | this(name, false, desc, pred, (Class) value.getClass(), value); 31 | } 32 | 33 | public ConfigOption(String name, boolean required, String desc, 34 | Predicate pred, Class type, T value) { 35 | super(name, required, desc, pred, type, value); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /hugegraph-common/src/test/java/org/apache/hugegraph/unit/perf/testclass/TestLightClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.unit.perf.testclass; 19 | 20 | import org.apache.hugegraph.perf.PerfUtil.Watched; 21 | 22 | public class TestLightClass { 23 | 24 | @Watched 25 | public void test() { 26 | new Foo().bar(); 27 | } 28 | 29 | public static class Foo { 30 | 31 | @Watched(prefix="foo") 32 | public void foo() { 33 | this.bar(); 34 | } 35 | 36 | @Watched(prefix="foo") 37 | public void bar() {} 38 | } 39 | 40 | public static class Bar { 41 | 42 | @Watched(prefix="bar") 43 | public void foo() { 44 | this.bar(); 45 | } 46 | 47 | @Watched(prefix="bar") 48 | public void bar() {} 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/util/HashUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.util; 19 | 20 | import java.nio.charset.Charset; 21 | 22 | import com.google.common.base.Charsets; 23 | import com.google.common.hash.Hashing; 24 | 25 | public final class HashUtil { 26 | 27 | private static final Charset CHARSET = Charsets.UTF_8; 28 | 29 | public static byte[] hash(byte[] bytes) { 30 | return Hashing.murmur3_32().hashBytes(bytes).asBytes(); 31 | } 32 | 33 | public static String hash(String value) { 34 | return Hashing.murmur3_32().hashString(value, CHARSET).toString(); 35 | } 36 | 37 | public static byte[] hash128(byte[] bytes) { 38 | return Hashing.murmur3_128().hashBytes(bytes).asBytes(); 39 | } 40 | 41 | public static String hash128(String value) { 42 | return Hashing.murmur3_128().hashString(value, CHARSET).toString(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /hugegraph-common/src/test/java/org/apache/hugegraph/unit/util/LogTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.unit.util; 19 | 20 | import org.junit.Test; 21 | import org.slf4j.Logger; 22 | 23 | import org.apache.hugegraph.unit.BaseUnitTest; 24 | import org.apache.hugegraph.util.Log; 25 | import org.apache.hugegraph.testutil.Assert; 26 | 27 | public class LogTest extends BaseUnitTest { 28 | 29 | @Test 30 | public void testLog() { 31 | Logger log1 = Log.logger(LogTest.class); 32 | Logger log2 = Log.logger("org.apache.hugegraph.unit.util.LogTest"); 33 | Logger log3 = Log.logger("test"); 34 | 35 | Assert.assertEquals(log1, log2); 36 | Assert.assertNotEquals(log1, log3); 37 | 38 | log1.info("Info: testLog({})", LogTest.class); 39 | log2.info("Info: testLog({})", "org.apache.hugegraph.unit.util.LogTest"); 40 | log3.info("Info: testLog({})", "test"); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /hugegraph-dist/release-docs/licenses/LICENSE-jaf-api.txt: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of the Eclipse Foundation, Inc. nor the names of its 16 | contributors may be used to endorse or promote products derived 17 | from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 20 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /hugegraph-dist/release-docs/licenses/LICENSE-jakarta.activation-api.txt: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | - Neither the name of the Eclipse Foundation, Inc. nor the names of its 16 | contributors may be used to endorse or promote products derived 17 | from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 20 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/license/LicenseParams.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.license; 19 | 20 | import java.util.Date; 21 | import java.util.List; 22 | 23 | public class LicenseParams extends LicenseCommonParam { 24 | 25 | public LicenseParams() { 26 | super(); 27 | } 28 | 29 | public LicenseParams(String subject, String description, 30 | Date issued, Date notBefore, Date notAfter, 31 | String consumerType, int consumerAmount, 32 | List extraParams) { 33 | super(subject, description, issued, notBefore, notAfter, 34 | consumerType, consumerAmount, extraParams); 35 | } 36 | 37 | public LicenseExtraParam matchParam(String id) { 38 | for (LicenseExtraParam param : this.extraParams()) { 39 | if (param.id().equals(id)) { 40 | return param; 41 | } 42 | } 43 | return null; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /hugegraph-dist/release-docs/licenses/LICENSE-protobuf.txt: -------------------------------------------------------------------------------- 1 | Copyright 2008 Google Inc. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | Code generated by the Protocol Buffer compiler is owned by the owner 30 | of the input file used when generating it. This code is not 31 | standalone and requires a support library to be linked with it. This 32 | support library is itself covered by the above license. -------------------------------------------------------------------------------- /hugegraph-rpc/src/main/java/org/apache/hugegraph/rpc/RpcCommonConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.rpc; 19 | 20 | import java.util.Map; 21 | 22 | import com.alipay.sofa.rpc.common.RpcConfigs; 23 | import org.apache.hugegraph.config.HugeConfig; 24 | import org.apache.hugegraph.config.RpcOptions; 25 | 26 | public class RpcCommonConfig { 27 | 28 | public static void initRpcConfigs(HugeConfig config) { 29 | RpcConfigs.putValue("rpc.config.order", 30 | config.get(RpcOptions.RPC_CONFIG_ORDER)); 31 | RpcConfigs.putValue("logger.impl", 32 | config.get(RpcOptions.RPC_LOGGER_IMPL)); 33 | } 34 | 35 | public static void initRpcConfigs(String key, Object value) { 36 | RpcConfigs.putValue(key, value); 37 | } 38 | 39 | public static void initRpcConfigs(Map conf) { 40 | for (Map.Entry entry : conf.entrySet()) { 41 | RpcConfigs.putValue(entry.getKey(), entry.getValue()); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/rest/RestClientConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.rest; 19 | 20 | import java.util.function.Consumer; 21 | 22 | import lombok.Builder; 23 | import lombok.Getter; 24 | import lombok.Setter; 25 | import okhttp3.OkHttpClient; 26 | 27 | @Builder 28 | @Getter 29 | @Setter 30 | @SuppressWarnings("unused") 31 | public class RestClientConfig { 32 | 33 | private String user; 34 | private String password; 35 | private String token; 36 | /** 37 | * @deprecated use connectTimeout and readTimeout instead 38 | */ 39 | @Deprecated 40 | private Integer timeout; 41 | /** unit in milliseconds */ 42 | private Integer connectTimeout; 43 | /** unit in milliseconds */ 44 | private Integer readTimeout; 45 | private Integer maxConns; 46 | private Integer maxConnsPerRoute; 47 | // unit in seconds 48 | private Integer idleTime = 30; 49 | private Integer maxIdleConns = 5; 50 | private String trustStoreFile; 51 | private String trustStorePassword; 52 | private Consumer builderCallback; 53 | } 54 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/config/ConfigConvOption.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.config; 19 | 20 | import java.util.function.Function; 21 | 22 | import org.apache.hugegraph.util.E; 23 | import com.google.common.base.Predicate; 24 | 25 | public class ConfigConvOption extends TypedOption { 26 | 27 | private final Function converter; 28 | 29 | public ConfigConvOption(String name, String desc, Predicate pred, 30 | Function convert, T value) { 31 | this(name, false, desc, pred, convert, value); 32 | } 33 | 34 | @SuppressWarnings("unchecked") 35 | public ConfigConvOption(String name, boolean required, String desc, 36 | Predicate pred, Function convert, 37 | T value) { 38 | super(name, required, desc, pred, (Class) value.getClass(), value); 39 | E.checkNotNull(convert, "convert"); 40 | this.converter = convert; 41 | } 42 | 43 | @Override 44 | public R convert(T value) { 45 | return this.converter.apply(value); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/util/ExceptionUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.util; 19 | 20 | import java.util.concurrent.ExecutionException; 21 | import java.util.concurrent.Future; 22 | 23 | public final class ExceptionUtil { 24 | 25 | public static Throwable rootCause(Throwable e) { 26 | Throwable cause = e; 27 | while (cause.getCause() != null) { 28 | cause = cause.getCause(); 29 | } 30 | return cause; 31 | } 32 | 33 | public static RuntimeException transToRuntimeException(Throwable e) { 34 | if (e instanceof RuntimeException) { 35 | return (RuntimeException) e; 36 | } 37 | return new RuntimeException(rootCause(e).getMessage(), e); 38 | } 39 | 40 | public static T futureGet(Future future) { 41 | try { 42 | return future.get(); 43 | } catch (InterruptedException e) { 44 | throw ExceptionUtil.transToRuntimeException(e); 45 | } catch (ExecutionException e) { 46 | throw ExceptionUtil.transToRuntimeException(e.getCause()); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/iterator/MapperIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.iterator; 19 | 20 | import java.util.Iterator; 21 | import java.util.function.Function; 22 | 23 | public class MapperIterator extends WrappedIterator { 24 | 25 | private final Iterator originIterator; 26 | private final Function mapperCallback; 27 | 28 | public MapperIterator(Iterator origin, Function mapper) { 29 | this.originIterator = origin; 30 | this.mapperCallback = mapper; 31 | } 32 | 33 | @Override 34 | protected Iterator originIterator() { 35 | return this.originIterator; 36 | } 37 | 38 | @Override 39 | protected final boolean fetch() { 40 | while (this.originIterator.hasNext()) { 41 | T next = this.originIterator.next(); 42 | R result = this.mapperCallback.apply(next); 43 | if (result != null) { 44 | assert this.current == none(); 45 | this.current = result; 46 | return true; 47 | } 48 | } 49 | return false; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/iterator/FilterIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.iterator; 19 | 20 | import java.util.Iterator; 21 | import java.util.function.Function; 22 | 23 | public class FilterIterator extends WrappedIterator { 24 | 25 | private final Iterator originIterator; 26 | private final Function filterCallback; 27 | 28 | public FilterIterator(Iterator origin, Function filter) { 29 | this.originIterator = origin; 30 | this.filterCallback = filter; 31 | } 32 | 33 | @Override 34 | protected Iterator originIterator() { 35 | return this.originIterator; 36 | } 37 | 38 | @Override 39 | protected final boolean fetch() { 40 | while (this.originIterator.hasNext()) { 41 | T next = this.originIterator.next(); 42 | // Do filter 43 | if (next != null && this.filterCallback.apply(next)) { 44 | assert this.current == none(); 45 | this.current = next; 46 | return true; 47 | } 48 | } 49 | return false; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /hugegraph-common/src/test/java/org/apache/hugegraph/unit/perf/testclass2/TestClass4Package.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.unit.perf.testclass2; 19 | 20 | import org.apache.hugegraph.perf.PerfUtil.Watched; 21 | 22 | public class TestClass4Package { 23 | 24 | @Watched 25 | public void test() { 26 | new Foo().bar(); 27 | } 28 | 29 | public static class Foo extends FooBase { 30 | 31 | @Watched 32 | public void foo() { 33 | this.bar(); 34 | } 35 | 36 | @Watched 37 | public void bar() {} 38 | } 39 | 40 | public static class FooBase {} 41 | 42 | public static class Bar { 43 | 44 | @Watched 45 | public void foo() { 46 | this.bar(); 47 | } 48 | 49 | @Watched 50 | public void bar() {} 51 | } 52 | 53 | public static class Base { 54 | 55 | @Watched 56 | public void func() {} 57 | } 58 | 59 | public static class Sub extends Base { 60 | 61 | @Watched 62 | public void func1() {} 63 | 64 | public void func2() {} 65 | 66 | @Watched 67 | public void func3() {} 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/license/LicenseInstallParam.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.license; 19 | 20 | import com.fasterxml.jackson.annotation.JsonAlias; 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | 23 | public class LicenseInstallParam { 24 | 25 | @JsonProperty("subject") 26 | private String subject; 27 | 28 | @JsonProperty("public_alias") 29 | private String publicAlias; 30 | 31 | @JsonAlias("store_ticket") 32 | @JsonProperty("store_password") 33 | private String storePassword; 34 | 35 | @JsonProperty("publickey_path") 36 | private String publicKeyPath; 37 | 38 | @JsonProperty("license_path") 39 | private String licensePath; 40 | 41 | public String subject() { 42 | return this.subject; 43 | } 44 | 45 | public String publicAlias() { 46 | return this.publicAlias; 47 | } 48 | 49 | public String storePassword() { 50 | return this.storePassword; 51 | } 52 | 53 | public String licensePath() { 54 | return this.licensePath; 55 | } 56 | 57 | public String publicKeyPath() { 58 | return this.publicKeyPath; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/rest/OkHttpBasicAuthInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.rest; 19 | 20 | import java.io.IOException; 21 | 22 | import okhttp3.Credentials; 23 | import okhttp3.Interceptor; 24 | import okhttp3.Request; 25 | import okhttp3.Response; 26 | 27 | public class OkHttpBasicAuthInterceptor implements Interceptor { 28 | 29 | private final String credentials; 30 | 31 | public OkHttpBasicAuthInterceptor(String user, String password) { 32 | this.credentials = Credentials.basic(user, password); 33 | } 34 | 35 | @Override 36 | public Response intercept(Chain chain) throws IOException { 37 | Request request = chain.request(); 38 | if (request.header(RestHeaders.AUTHORIZATION) == null) { 39 | Request authenticatedRequest = request.newBuilder() 40 | .header(RestHeaders.AUTHORIZATION, 41 | this.credentials) 42 | .build(); 43 | return chain.proceed(authenticatedRequest); 44 | } 45 | return chain.proceed(request); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /hugegraph-rpc/src/test/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /hugegraph-common/src/test/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/rest/OkHttpTokenInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.rest; 19 | 20 | import static org.apache.hugegraph.rest.RestHeaders.AUTHORIZATION; 21 | import static org.apache.hugegraph.rest.RestHeaders.BEARER_PREFIX; 22 | 23 | import java.io.IOException; 24 | 25 | import okhttp3.Interceptor; 26 | import okhttp3.Request; 27 | import okhttp3.Response; 28 | 29 | 30 | public class OkHttpTokenInterceptor implements Interceptor { 31 | 32 | private final String token; 33 | 34 | public OkHttpTokenInterceptor(String token) { 35 | this.token = token; 36 | } 37 | 38 | @Override 39 | public Response intercept(Chain chain) throws IOException { 40 | Request request = chain.request(); 41 | if (request.header(AUTHORIZATION) == null) { 42 | Request authenticatedRequest = request.newBuilder() 43 | .header(AUTHORIZATION, 44 | BEARER_PREFIX + this.token) 45 | .build(); 46 | return chain.proceed(authenticatedRequest); 47 | } 48 | return chain.proceed(request); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/iterator/FlatMapperFilterIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.iterator; 19 | 20 | import java.util.Iterator; 21 | import java.util.function.Function; 22 | 23 | import org.apache.hugegraph.util.E; 24 | 25 | public class FlatMapperFilterIterator extends FlatMapperIterator { 26 | 27 | private final Function filterCallback; 28 | 29 | public FlatMapperFilterIterator(Iterator origin, 30 | Function> mapper, 31 | Function filter) { 32 | super(origin, mapper); 33 | this.filterCallback = filter; 34 | } 35 | 36 | @Override 37 | protected final boolean fetchFromBatch() { 38 | E.checkNotNull(this.batchIterator, "mapper results"); 39 | while (this.batchIterator.hasNext()) { 40 | R result = this.batchIterator.next(); 41 | if (result != null && this.filterCallback.apply(result)) { 42 | assert this.current == none(); 43 | this.current = result; 44 | return true; 45 | } 46 | } 47 | this.resetBatchIterator(); 48 | return false; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/license/LicenseCreateParam.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.license; 19 | 20 | import com.fasterxml.jackson.annotation.JsonAlias; 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | 23 | public class LicenseCreateParam extends LicenseCommonParam { 24 | 25 | @JsonProperty("private_alias") 26 | private String privateAlias; 27 | 28 | @JsonAlias("key_ticket") 29 | @JsonProperty("key_password") 30 | private String keyPassword; 31 | 32 | @JsonAlias("store_ticket") 33 | @JsonProperty("store_password") 34 | private String storePassword; 35 | 36 | @JsonProperty("privatekey_path") 37 | private String privateKeyPath; 38 | 39 | @JsonProperty("license_path") 40 | private String licensePath; 41 | 42 | public String privateAlias() { 43 | return this.privateAlias; 44 | } 45 | 46 | public String keyPassword() { 47 | return this.keyPassword; 48 | } 49 | 50 | public String storePassword() { 51 | return this.storePassword; 52 | } 53 | 54 | public String privateKeyPath() { 55 | return this.privateKeyPath; 56 | } 57 | 58 | public String licensePath() { 59 | return this.licensePath; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /hugegraph-rpc/src/test/java/org/apache/hugegraph/unit/BaseUnitTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.unit; 19 | 20 | import java.net.URL; 21 | 22 | import org.junit.BeforeClass; 23 | 24 | import org.apache.hugegraph.config.HugeConfig; 25 | import org.apache.hugegraph.config.OptionSpace; 26 | import org.apache.hugegraph.rpc.RpcServer; 27 | 28 | public class BaseUnitTest { 29 | 30 | @BeforeClass 31 | public static void initEnv() { 32 | OptionSpace.register("rpc", "org.apache.hugegraph.config.RpcOptions"); 33 | } 34 | 35 | protected static HugeConfig config(boolean server) { 36 | return config(server ? "server" : "client"); 37 | } 38 | 39 | protected static HugeConfig config(String type) { 40 | String name = String.format("rpc-%s.properties", type); 41 | URL conf = BaseUnitTest.class.getClassLoader().getResource(name); 42 | return new HugeConfig(conf.getPath()); 43 | } 44 | 45 | protected static void startServer(RpcServer rpcServer) { 46 | rpcServer.config().configs().values().forEach(c -> { 47 | c.setRepeatedExportLimit(100); 48 | }); 49 | 50 | rpcServer.exportAll(); 51 | } 52 | 53 | protected static void stopServer(RpcServer rpcServer) { 54 | rpcServer.destroy(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /hugegraph-common/src/test/java/org/apache/hugegraph/unit/perf/testclass/TestPerfClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.unit.perf.testclass; 19 | 20 | import org.apache.hugegraph.perf.PerfUtil.Watched; 21 | 22 | public class TestPerfClass { 23 | 24 | private Foo foo = new Foo(); 25 | 26 | @Watched 27 | public void test(int times) { 28 | for (int i = 0; i < times; i++) { 29 | this.testNew(); 30 | this.testNewAndCall(); 31 | this.testCall(); 32 | this.testCallFooThenSum(); 33 | } 34 | } 35 | 36 | @Watched 37 | public void testNew() { 38 | new Foo(); 39 | } 40 | 41 | @Watched 42 | public void testNewAndCall() { 43 | new Foo().sum(1, 2); 44 | } 45 | 46 | @Watched 47 | public void testCall() { 48 | this.foo.sum(1, 2); 49 | } 50 | 51 | @Watched 52 | public void testCallFooThenSum() { 53 | this.foo.foo(); 54 | } 55 | 56 | public static class Foo { 57 | 58 | @Watched 59 | public void foo() { 60 | this.sum(1, 2); 61 | } 62 | 63 | @Watched 64 | public int sum(int a, int b) { 65 | int sum = a; 66 | for (int i = 0; i < 100; i++) { 67 | sum += i; 68 | } 69 | return sum + b; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/util/TimeUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.util; 19 | 20 | import java.time.Duration; 21 | import java.util.Date; 22 | 23 | public final class TimeUtil { 24 | 25 | @SuppressWarnings("deprecation") 26 | public static long BASE_TIME = new Date(2017 - 1900, 10, 28).getTime(); 27 | 28 | public static long timeGen() { 29 | return System.currentTimeMillis() - BASE_TIME; 30 | } 31 | 32 | public static long timeGen(Date date) { 33 | return date.getTime() - BASE_TIME; 34 | } 35 | 36 | public static long timeGen(long time) { 37 | return time - BASE_TIME; 38 | } 39 | 40 | public static long tillNextMillis(long lastTimestamp) { 41 | long timestamp = timeGen(); 42 | while (timestamp <= lastTimestamp) { 43 | timestamp = timeGen(); 44 | } 45 | return timestamp; 46 | } 47 | 48 | public static String readableTime(long time) { 49 | if (time > 60 * 1000) { 50 | // Remove the milliseconds part 51 | time = time / 1000 * 1000; 52 | } 53 | Duration duration = Duration.ofMillis(time); 54 | return duration.toString() 55 | .substring(2) 56 | .replaceAll("(\\d[HMS])(?!$)", "$1 ") 57 | .toLowerCase(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /hugegraph-common/src/test/java/org/apache/hugegraph/unit/perf/testclass/TestPerfLightClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.unit.perf.testclass; 19 | 20 | import org.apache.hugegraph.perf.PerfUtil.Watched; 21 | 22 | public class TestPerfLightClass { 23 | 24 | private final Foo foo = new Foo(); 25 | 26 | @Watched 27 | public void test(int times) { 28 | for (int i = 0; i < times; i++) { 29 | this.testNew(); 30 | this.testNewAndCall(); 31 | this.testCall(); 32 | this.testCallFooThenSum(); 33 | } 34 | } 35 | 36 | @Watched 37 | public void testNew() { 38 | new Foo(); 39 | } 40 | 41 | @Watched 42 | public void testNewAndCall() { 43 | new Foo().sum(1, 2); 44 | } 45 | 46 | @Watched 47 | public void testCall() { 48 | this.foo.sum(1, 2); 49 | } 50 | 51 | @Watched 52 | public void testCallFooThenSum() { 53 | this.foo.foo(); 54 | } 55 | 56 | public static class Foo { 57 | 58 | @Watched 59 | public void foo() { 60 | this.sum(1, 2); 61 | } 62 | 63 | @Watched 64 | public int sum(int a, int b) { 65 | int sum = a; 66 | for (int i = 0; i < 100; i++) { 67 | sum += i; 68 | } 69 | return sum + b; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /hugegraph-common/src/test/java/org/apache/hugegraph/unit/rest/AbstractRestClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.unit.rest; 19 | 20 | import org.apache.hugegraph.rest.AbstractRestClient; 21 | import org.junit.Assert; 22 | import org.junit.Test; 23 | 24 | public class AbstractRestClientTest { 25 | 26 | @Test 27 | public void testEncodeWithSpaces() { 28 | String raw = "hello world"; 29 | String expected = "hello%2Bworld"; 30 | String encoded = AbstractRestClient.encode(raw); 31 | Assert.assertEquals(expected, encoded); 32 | } 33 | 34 | @Test 35 | public void testEncodeWithSpecialCharacters() { 36 | String raw = "hello@world!"; 37 | String expected = "hello%40world%21"; 38 | String encoded = AbstractRestClient.encode(raw); 39 | Assert.assertEquals(expected, encoded); 40 | } 41 | 42 | @Test 43 | public void testEncodeWithChineseCharacters() { 44 | String raw = "你好"; 45 | String expected = "%E4%BD%A0%E5%A5%BD"; 46 | String encoded = AbstractRestClient.encode(raw); 47 | Assert.assertEquals(expected, encoded); 48 | } 49 | 50 | @Test 51 | public void testEncodeWithNullInput() { 52 | String raw = null; 53 | Assert.assertThrows(NullPointerException.class, () -> { 54 | AbstractRestClient.encode(raw); 55 | }); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /hugegraph-rpc/src/test/java/org/apache/hugegraph/unit/ExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.unit; 19 | 20 | import org.junit.Test; 21 | 22 | import org.apache.hugegraph.rpc.RpcException; 23 | import org.apache.hugegraph.testutil.Assert; 24 | 25 | public class ExceptionTest { 26 | 27 | @Test 28 | public void testExceptionWithMessage() { 29 | RpcException e = new RpcException("test"); 30 | Assert.assertEquals("test", e.getMessage()); 31 | Assert.assertNull(e.getCause()); 32 | } 33 | 34 | @Test 35 | public void testExceptionWithMessageAndCause() { 36 | Exception cause = new Exception(); 37 | RpcException e = new RpcException("test", cause); 38 | Assert.assertEquals("test", e.getMessage()); 39 | Assert.assertEquals(cause, e.getCause()); 40 | } 41 | 42 | @Test 43 | public void testExceptionWithMessageAndArgs() { 44 | RpcException e = new RpcException("test %s", 168); 45 | Assert.assertEquals("test 168", e.getMessage()); 46 | Assert.assertNull(e.getCause()); 47 | } 48 | 49 | @Test 50 | public void testExceptionWithMessageAndArgsAndCause() { 51 | Exception cause = new Exception(); 52 | RpcException e = new RpcException("test %s", cause, 168); 53 | Assert.assertEquals("test 168", e.getMessage()); 54 | Assert.assertEquals(cause, e.getCause()); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/rest/RestClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.rest; 19 | 20 | import java.util.Map; 21 | 22 | public interface RestClient { 23 | /** 24 | * Post method 25 | */ 26 | RestResult post(String path, Object object); 27 | 28 | RestResult post(String path, Object object, RestHeaders headers); 29 | 30 | RestResult post(String path, Object object, Map params); 31 | 32 | RestResult post(String path, Object object, RestHeaders headers, Map params); 33 | 34 | /** 35 | * Put method 36 | */ 37 | RestResult put(String path, String id, Object object); 38 | 39 | RestResult put(String path, String id, Object object, RestHeaders headers); 40 | 41 | RestResult put(String path, String id, Object object, Map params); 42 | 43 | RestResult put(String path, String id, Object object, RestHeaders headers, 44 | Map params); 45 | 46 | /** 47 | * Get method 48 | */ 49 | RestResult get(String path); 50 | 51 | RestResult get(String path, Map params); 52 | 53 | RestResult get(String path, String id); 54 | 55 | /** 56 | * Delete method 57 | */ 58 | RestResult delete(String path, Map params); 59 | 60 | RestResult delete(String path, String id); 61 | 62 | void close(); 63 | } 64 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/util/InsertionOrderUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.util; 19 | 20 | import java.util.ArrayList; 21 | import java.util.LinkedHashMap; 22 | import java.util.LinkedHashSet; 23 | import java.util.List; 24 | import java.util.Map; 25 | import java.util.Set; 26 | 27 | public final class InsertionOrderUtil { 28 | 29 | public static Map newMap() { 30 | return new LinkedHashMap<>(); 31 | } 32 | 33 | public static Map newMap(int initialCapacity) { 34 | return new LinkedHashMap<>(initialCapacity); 35 | } 36 | 37 | public static Map newMap(Map origin) { 38 | return new LinkedHashMap<>(origin); 39 | } 40 | 41 | public static Set newSet() { 42 | return new LinkedHashSet<>(); 43 | } 44 | 45 | public static Set newSet(int initialCapacity) { 46 | return new LinkedHashSet<>(initialCapacity); 47 | } 48 | 49 | public static Set newSet(Set origin) { 50 | return new LinkedHashSet<>(origin); 51 | } 52 | 53 | public static List newList() { 54 | return new ArrayList<>(); 55 | } 56 | 57 | public static List newList(int initialCapacity) { 58 | return new ArrayList<>(initialCapacity); 59 | } 60 | 61 | public static List newList(List origin) { 62 | return new ArrayList<>(origin); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /hugegraph-common/src/test/java/org/apache/hugegraph/unit/license/LicenseInstallParamTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.unit.license; 19 | 20 | import java.io.IOException; 21 | 22 | import org.junit.Test; 23 | 24 | import org.apache.hugegraph.license.LicenseInstallParam; 25 | import org.apache.hugegraph.testutil.Assert; 26 | import com.fasterxml.jackson.databind.ObjectMapper; 27 | 28 | public class LicenseInstallParamTest { 29 | 30 | @Test 31 | public void testDeserializeLicenseVerifyParam() throws IOException { 32 | String json = "{" 33 | + "\"subject\":\"hugegraph-evaluation\"," 34 | + "\"public_alias\":\"publiccert\"," 35 | + "\"store_ticket\":\"a123456\"," 36 | + "\"publickey_path\":\"./publicCerts.store\"," 37 | + "\"license_path\":\"./hugegraph-evaluation.license\"" 38 | + "}"; 39 | ObjectMapper mapper = new ObjectMapper(); 40 | LicenseInstallParam param = mapper.readValue(json, 41 | LicenseInstallParam.class); 42 | Assert.assertEquals("hugegraph-evaluation", param.subject()); 43 | Assert.assertEquals("publiccert", param.publicAlias()); 44 | Assert.assertEquals("a123456", param.storePassword()); 45 | Assert.assertEquals("./publicCerts.store", param.publicKeyPath()); 46 | Assert.assertEquals("./hugegraph-evaluation.license", 47 | param.licensePath()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/config/OptionHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.config; 19 | 20 | import java.lang.reflect.Field; 21 | import java.util.Collections; 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | 25 | import org.apache.hugegraph.util.Log; 26 | import org.slf4j.Logger; 27 | 28 | public class OptionHolder { 29 | 30 | private static final Logger LOG = Log.logger(HugeConfig.class); 31 | 32 | protected Map> options; 33 | 34 | public OptionHolder() { 35 | this.options = new HashMap<>(); 36 | } 37 | 38 | protected void registerOptions() { 39 | for (Field field : this.getClass().getFields()) { 40 | if (!TypedOption.class.isAssignableFrom(field.getType())) { 41 | // Skip if not option 42 | continue; 43 | } 44 | try { 45 | TypedOption option = (TypedOption) field.get(this); 46 | // Fields of subclass first, don't overwrite by superclass 47 | this.options.putIfAbsent(option.name(), option); 48 | } catch (Exception e) { 49 | LOG.error("Failed to register option: {}", field, e); 50 | throw new ConfigException( 51 | "Failed to register option: %s", field); 52 | } 53 | } 54 | } 55 | 56 | public Map> options() { 57 | return Collections.unmodifiableMap(this.options); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/iterator/LimitIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.iterator; 19 | 20 | import java.util.Iterator; 21 | import java.util.function.Function; 22 | 23 | public class LimitIterator extends WrappedIterator { 24 | 25 | private final Iterator originIterator; 26 | private final Function filterCallback; 27 | 28 | public LimitIterator(Iterator origin, Function filter) { 29 | this.originIterator = origin; 30 | this.filterCallback = filter; 31 | } 32 | 33 | @Override 34 | protected Iterator originIterator() { 35 | return this.originIterator; 36 | } 37 | 38 | @Override 39 | protected final boolean fetch() { 40 | while (this.originIterator.hasNext()) { 41 | T next = this.originIterator.next(); 42 | if (next == null) { 43 | continue; 44 | } 45 | // Do filter 46 | boolean reachLimit = this.filterCallback.apply(next); 47 | if (reachLimit) { 48 | this.closeOriginIterator(); 49 | return false; 50 | } 51 | assert this.current == none(); 52 | this.current = next; 53 | return true; 54 | } 55 | return false; 56 | } 57 | 58 | protected final void closeOriginIterator() { 59 | if (this.originIterator == null) { 60 | return; 61 | } 62 | close(this.originIterator); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/date/SafeDateFormat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.date; 19 | 20 | import java.util.Date; 21 | import java.util.TimeZone; 22 | 23 | import org.joda.time.DateTimeZone; 24 | import org.joda.time.format.DateTimeFormat; 25 | import org.joda.time.format.DateTimeFormatter; 26 | 27 | /** 28 | * The SafeDateFormat actually is a proxy for joda DateTimeFormatter 29 | */ 30 | public class SafeDateFormat { 31 | 32 | private static final int ONE_HOUR_MS = 3600 * 1000; 33 | 34 | private final String pattern; 35 | private DateTimeFormatter formatter; 36 | 37 | public SafeDateFormat(String pattern) { 38 | this.pattern = pattern; 39 | this.formatter = DateTimeFormat.forPattern(pattern); 40 | } 41 | 42 | public synchronized void setTimeZone(String zoneId) { 43 | int hoursOffset = TimeZone.getTimeZone(zoneId).getRawOffset() / 44 | ONE_HOUR_MS; 45 | DateTimeZone zone = DateTimeZone.forOffsetHours(hoursOffset); 46 | this.formatter = this.formatter.withZone(zone); 47 | } 48 | 49 | public TimeZone getTimeZone() { 50 | return this.formatter.getZone().toTimeZone(); 51 | } 52 | 53 | public Date parse(String source) { 54 | return this.formatter.parseDateTime(source).toDate(); 55 | } 56 | 57 | public String format(Date date) { 58 | return this.formatter.print(date.getTime()); 59 | } 60 | 61 | public Object toPattern() { 62 | return this.pattern; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /hugegraph-common/src/test/java/org/apache/hugegraph/unit/concurrent/AtomicLockTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.unit.concurrent; 19 | 20 | import org.junit.Test; 21 | 22 | import org.apache.hugegraph.concurrent.AtomicLock; 23 | import org.apache.hugegraph.testutil.Assert; 24 | import org.apache.hugegraph.unit.BaseUnitTest; 25 | 26 | public class AtomicLockTest extends BaseUnitTest { 27 | 28 | @Test 29 | public void testLockUnlock() { 30 | AtomicLock lock = new AtomicLock("lock"); 31 | Assert.assertEquals("lock", lock.name()); 32 | 33 | Assert.assertTrue(lock.lock(0)); 34 | try { 35 | Assert.assertFalse(lock.lock(1)); 36 | // lock in other threads 37 | runWithThreads(2, () -> { 38 | Assert.assertFalse(lock.tryLock()); 39 | }); 40 | lock.unlock(); 41 | } finally { 42 | lock.unlock(); 43 | // unlock multi times is OK 44 | lock.unlock(); 45 | lock.unlock(); 46 | } 47 | 48 | Assert.assertThrows(RuntimeException.class, () -> { 49 | lock.lock(-1); 50 | }, e -> { 51 | Assert.assertContains("Locking retry times should be in [0, 10], " + 52 | "but got -1", e.getMessage()); 53 | }); 54 | 55 | Assert.assertThrows(RuntimeException.class, () -> { 56 | lock.lock(11); 57 | }, e -> { 58 | Assert.assertContains("Locking retry times should be in [0, 10], " + 59 | "but got 11", e.getMessage()); 60 | }); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/event/Event.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.event; 19 | 20 | import java.util.Arrays; 21 | import java.util.Collections; 22 | 23 | import org.apache.hugegraph.util.E; 24 | 25 | public class Event extends java.util.EventObject { 26 | 27 | private static final long serialVersionUID = 1625973849208342813L; 28 | 29 | private String name; 30 | private Object[] args; 31 | 32 | public Event(Object source, String event) { 33 | this(source, event, Collections.emptyList().toArray()); 34 | } 35 | 36 | public Event(Object source, String event, Object... args) { 37 | super(source); 38 | this.name = event; 39 | this.args = args; 40 | } 41 | 42 | public String name() { 43 | return this.name; 44 | } 45 | 46 | public Object[] args() { 47 | return this.args; 48 | } 49 | 50 | public void checkArgs(Class... classes) throws IllegalArgumentException { 51 | E.checkArgument(this.args.length == classes.length, 52 | "The args count of event '%s' should be %s(actual %s)", 53 | this.name, classes.length, this.args.length); 54 | int i = 0; 55 | for (Class c : classes) { 56 | Object arg = this.args[i++]; 57 | if (arg == null) { 58 | continue; 59 | } 60 | E.checkArgument(c.isAssignableFrom(arg.getClass()), 61 | "The arg '%s'(%s) can't match %s", 62 | arg, arg.getClass(), c); 63 | } 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return String.format("Event{name='%s', args=%s}", 69 | this.name, Arrays.asList(this.args)); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/concurrent/LockManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.concurrent; 19 | 20 | import java.util.Map; 21 | import java.util.concurrent.ConcurrentHashMap; 22 | 23 | public class LockManager { 24 | 25 | private static final LockManager INSTANCE = new LockManager(); 26 | 27 | public static LockManager instance() { 28 | return INSTANCE; 29 | } 30 | 31 | private Map lockGroupMap; 32 | 33 | private LockManager() { 34 | this.lockGroupMap = new ConcurrentHashMap<>(); 35 | } 36 | 37 | public boolean exists(String group) { 38 | return this.lockGroupMap.containsKey(group); 39 | } 40 | 41 | public LockGroup create(String group) { 42 | if (exists(group)) { 43 | throw new RuntimeException(String.format( 44 | "LockGroup '%s' already exists", group)); 45 | } 46 | LockGroup lockGroup = new LockGroup(group); 47 | LockGroup previous = this.lockGroupMap.putIfAbsent(group, lockGroup); 48 | if (previous != null) { 49 | return previous; 50 | } 51 | return lockGroup; 52 | } 53 | 54 | public LockGroup get(String group) { 55 | LockGroup lockGroup = this.lockGroupMap.get(group); 56 | if (lockGroup == null) { 57 | throw new RuntimeException(String.format( 58 | "LockGroup '%s' does not exists", group)); 59 | } 60 | return lockGroup; 61 | } 62 | 63 | public void destroy(String group) { 64 | if (this.exists(group)) { 65 | this.lockGroupMap.remove(group); 66 | } else { 67 | throw new RuntimeException(String.format( 68 | "LockGroup '%s' does not exists", group)); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /hugegraph-common/src/test/java/org/apache/hugegraph/unit/BaseUnitTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.unit; 19 | 20 | import java.io.File; 21 | import java.io.IOException; 22 | import java.net.URL; 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | import java.util.concurrent.ExecutorService; 26 | import java.util.concurrent.Executors; 27 | import java.util.concurrent.Future; 28 | 29 | import org.apache.commons.io.FileUtils; 30 | import org.apache.hugegraph.util.ExceptionUtil; 31 | import org.apache.hugegraph.util.TimeUtil; 32 | import org.junit.AfterClass; 33 | import org.junit.BeforeClass; 34 | 35 | public class BaseUnitTest { 36 | 37 | @BeforeClass 38 | public static void init() { 39 | // pass 40 | } 41 | 42 | @AfterClass 43 | public static void clear() throws Exception { 44 | // pass 45 | } 46 | 47 | protected static void runWithThreads(int threads, Runnable task) { 48 | ExecutorService executor = Executors.newFixedThreadPool(threads); 49 | List> futures = new ArrayList<>(); 50 | for (int i = 0; i < threads; i++) { 51 | futures.add(executor.submit(task)); 52 | } 53 | for (Future future : futures) { 54 | ExceptionUtil.futureGet(future); 55 | } 56 | } 57 | 58 | protected static void waitTillNext(long seconds) { 59 | TimeUtil.tillNextMillis(TimeUtil.timeGen() + seconds * 1000); 60 | } 61 | 62 | public static void downloadFileByUrl(String url, String destPath) { 63 | int connectTimeout = 5000; 64 | int readTimeout = 5000; 65 | try { 66 | FileUtils.copyURLToFile(new URL(url), new File(destPath), connectTimeout, readTimeout); 67 | } catch (IOException e) { 68 | throw new RuntimeException(e); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/concurrent/PausableScheduledThreadPool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.concurrent; 19 | 20 | import java.util.List; 21 | import java.util.concurrent.ScheduledThreadPoolExecutor; 22 | import java.util.concurrent.ThreadFactory; 23 | 24 | import org.apache.hugegraph.util.Log; 25 | import org.slf4j.Logger; 26 | 27 | public class PausableScheduledThreadPool extends ScheduledThreadPoolExecutor { 28 | 29 | private static final Logger LOG = Log.logger(PausableScheduledThreadPool.class); 30 | 31 | private volatile boolean paused = false; 32 | 33 | public PausableScheduledThreadPool(int corePoolSize, 34 | ThreadFactory factory) { 35 | super(corePoolSize, factory); 36 | } 37 | 38 | public synchronized void pauseSchedule() { 39 | this.paused = true; 40 | LOG.info("PausableScheduledThreadPool was paused"); 41 | } 42 | 43 | public synchronized void resumeSchedule() { 44 | this.paused = false; 45 | this.notifyAll(); 46 | LOG.info("PausableScheduledThreadPool was resumed"); 47 | } 48 | 49 | @Override 50 | protected void beforeExecute(Thread t, Runnable r) { 51 | synchronized (this) { 52 | while (this.paused) { 53 | try { 54 | this.wait(); 55 | } catch (InterruptedException e) { 56 | LOG.warn("PausableScheduledThreadPool was interrupted"); 57 | } 58 | } 59 | } 60 | super.beforeExecute(t, r); 61 | } 62 | 63 | @Override 64 | public void shutdown() { 65 | if (this.paused) { 66 | this.resumeSchedule(); 67 | } 68 | super.shutdown(); 69 | } 70 | 71 | @Override 72 | public List shutdownNow() { 73 | if (this.paused) { 74 | this.resumeSchedule(); 75 | } 76 | return super.shutdownNow(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /hugegraph-common/src/test/java/org/apache/hugegraph/unit/license/LicenseExtraParamTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.unit.license; 19 | 20 | import java.io.IOException; 21 | 22 | import org.apache.hugegraph.license.LicenseExtraParam; 23 | import org.junit.Test; 24 | 25 | import org.apache.hugegraph.testutil.Assert; 26 | import com.fasterxml.jackson.databind.ObjectMapper; 27 | 28 | public class LicenseExtraParamTest { 29 | 30 | @Test 31 | public void testDeserializeExtraParam() throws IOException { 32 | String json = "{" 33 | + "\"id\":\"server-1\"," 34 | + "\"version\":\"0.10.2\"," 35 | + "\"graphs\":3," 36 | + "\"ip\":\"127.0.0.1\"," 37 | + "\"mac\":\"00-01-6C-06-A6-29\"," 38 | + "\"cpus\":32," 39 | + "\"ram\":65536," 40 | + "\"threads\":96," 41 | + "\"memory\":32768," 42 | + "\"nodes\":3," 43 | + "\"data_size\":1024," 44 | + "\"vertices\":1000," 45 | + "\"edges\":2000" 46 | + "}"; 47 | ObjectMapper mapper = new ObjectMapper(); 48 | LicenseExtraParam param = mapper.readValue(json, LicenseExtraParam.class); 49 | Assert.assertEquals("server-1", param.id()); 50 | Assert.assertEquals("0.10.2", param.version()); 51 | Assert.assertEquals(3, param.graphs()); 52 | Assert.assertEquals("127.0.0.1", param.ip()); 53 | Assert.assertEquals("00-01-6C-06-A6-29", param.mac()); 54 | Assert.assertEquals(32, param.cpus()); 55 | Assert.assertEquals(65536, param.ram()); 56 | Assert.assertEquals(96, param.threads()); 57 | Assert.assertEquals(32768, param.memory()); 58 | Assert.assertEquals(3, param.nodes()); 59 | Assert.assertEquals(1024, param.dataSize()); 60 | Assert.assertEquals(1000, param.vertices()); 61 | Assert.assertEquals(2000, param.edges()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/util/E.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.util; 19 | 20 | import java.util.Collection; 21 | 22 | import javax.annotation.Nullable; 23 | 24 | import com.google.common.base.Preconditions; 25 | 26 | public final class E { 27 | 28 | public static void checkNotNull(Object object, String elem) { 29 | Preconditions.checkNotNull(object, "The '%s' can't be null", elem); 30 | } 31 | 32 | public static void checkNotNull(Object object, String elem, String owner) { 33 | Preconditions.checkNotNull(object, 34 | "The '%s' of '%s' can't be null", 35 | elem, owner); 36 | } 37 | 38 | public static void checkNotEmpty(Collection collection, String elem) { 39 | Preconditions.checkArgument(!collection.isEmpty(), 40 | "The '%s' can't be empty", elem); 41 | } 42 | 43 | public static void checkNotEmpty(Collection collection, String elem, String owner) { 44 | Preconditions.checkArgument(!collection.isEmpty(), 45 | "The '%s' of '%s' can't be empty", 46 | elem, owner); 47 | } 48 | 49 | public static void checkArgument(boolean expression, 50 | @Nullable String message, 51 | @Nullable Object... args) { 52 | Preconditions.checkArgument(expression, message, args); 53 | } 54 | 55 | public static void checkArgumentNotNull(Object object, 56 | @Nullable String message, 57 | @Nullable Object... args) { 58 | Preconditions.checkArgument(object != null, message, args); 59 | } 60 | 61 | public static void checkState(boolean expression, 62 | @Nullable String message, 63 | @Nullable Object... args) { 64 | Preconditions.checkState(expression, message, args); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/iterator/ListIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.iterator; 19 | 20 | import java.util.Collection; 21 | import java.util.Collections; 22 | import java.util.Iterator; 23 | import java.util.List; 24 | 25 | import org.apache.hugegraph.util.InsertionOrderUtil; 26 | 27 | public class ListIterator extends WrappedIterator { 28 | 29 | private final Iterator originIterator; 30 | private final Iterator resultsIterator; 31 | private final Collection results; 32 | 33 | public ListIterator(long capacity, Iterator origin) { 34 | List results = InsertionOrderUtil.newList(); 35 | while (origin.hasNext()) { 36 | if (capacity >= 0L && results.size() >= capacity) { 37 | throw new IllegalArgumentException( 38 | "The iterator exceeded capacity " + capacity); 39 | } 40 | results.add(origin.next()); 41 | } 42 | this.originIterator = origin; 43 | this.results = Collections.unmodifiableList(results); 44 | this.resultsIterator = this.results.iterator(); 45 | } 46 | 47 | public ListIterator(Collection origin) { 48 | this.originIterator = origin.iterator(); 49 | this.results = origin instanceof List ? 50 | Collections.unmodifiableList((List) origin) : 51 | Collections.unmodifiableCollection(origin); 52 | this.resultsIterator = this.results.iterator(); 53 | } 54 | 55 | @Override 56 | public void remove() { 57 | this.resultsIterator.remove(); 58 | } 59 | 60 | public Collection list() { 61 | return this.results; 62 | } 63 | 64 | @Override 65 | protected boolean fetch() { 66 | assert this.current == none(); 67 | if (!this.resultsIterator.hasNext()) { 68 | return false; 69 | } 70 | this.current = this.resultsIterator.next(); 71 | return true; 72 | } 73 | 74 | @Override 75 | protected Iterator originIterator() { 76 | return this.originIterator; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/config/ConfigListConvOption.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.config; 19 | 20 | import java.util.ArrayList; 21 | import java.util.Arrays; 22 | import java.util.List; 23 | import java.util.function.Function; 24 | 25 | import org.apache.hugegraph.util.E; 26 | import com.google.common.base.Predicate; 27 | 28 | public class ConfigListConvOption extends TypedOption, List> { 29 | 30 | private final Class elemClass; 31 | private final Function converter; 32 | 33 | @SuppressWarnings("unchecked") 34 | public ConfigListConvOption(String name, String desc, 35 | Predicate> pred, Function convert, 36 | T... values) { 37 | this(name, false, desc, pred, convert, null, Arrays.asList(values)); 38 | } 39 | 40 | @SuppressWarnings("unchecked") 41 | public ConfigListConvOption(String name, boolean required, String desc, 42 | Predicate> pred, Function convert, 43 | Class clazz, List values) { 44 | super(name, required, desc, pred, 45 | (Class>) values.getClass(), values); 46 | E.checkNotNull(convert, "convert"); 47 | if (clazz == null && values.size() > 0) { 48 | clazz = (Class) values.get(0).getClass(); 49 | } 50 | E.checkArgumentNotNull(clazz, "Element class can't be null"); 51 | this.elemClass = clazz; 52 | this.converter = convert; 53 | } 54 | 55 | @Override 56 | protected boolean forList() { 57 | return true; 58 | } 59 | 60 | @Override 61 | protected List parse(String value) { 62 | return ConfigListOption.convert(value, part -> { 63 | return this.parse(part, this.elemClass); 64 | }); 65 | } 66 | 67 | @Override 68 | public List convert(List values) { 69 | List results = new ArrayList<>(values.size()); 70 | for (T value : values) { 71 | results.add(this.converter.apply(value)); 72 | } 73 | return results; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/concurrent/AtomicLock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.concurrent; 19 | 20 | import java.util.concurrent.atomic.AtomicReference; 21 | 22 | import org.apache.hugegraph.util.Log; 23 | import org.slf4j.Logger; 24 | 25 | public class AtomicLock { 26 | 27 | private static final Logger LOG = Log.logger(LockManager.class); 28 | 29 | private String name; 30 | private AtomicReference sign; 31 | 32 | public AtomicLock(String name) { 33 | this.name = name; 34 | this.sign = new AtomicReference<>(); 35 | } 36 | 37 | public boolean tryLock() { 38 | Thread current = Thread.currentThread(); 39 | return this.sign.compareAndSet(null, current); 40 | } 41 | 42 | public void unlock() { 43 | if (this.sign.get() == null) { 44 | return; 45 | } 46 | Thread current = Thread.currentThread(); 47 | if (!this.sign.compareAndSet(current, null)) { 48 | throw new RuntimeException(String.format( 49 | "Thread '%s' trying to unlock '%s' " + 50 | "which is held by other threads now.", 51 | current.getName(), this.name)); 52 | } 53 | } 54 | 55 | public boolean lock(int retries) { 56 | // The interval between retries is exponential growth, most wait 57 | // interval is 2^(retries-1)s. If retries=0, don't retry. 58 | if (retries < 0 || retries > 10) { 59 | throw new IllegalArgumentException(String.format( 60 | "Locking retry times should be in [0, 10], but got %d", 61 | retries)); 62 | } 63 | 64 | boolean isLocked = false; 65 | try { 66 | for (int i = 0; !(isLocked = this.tryLock()) && i < retries; i++) { 67 | Thread.sleep(1000 * (1L << i)); 68 | } 69 | } catch (InterruptedException ignored) { 70 | LOG.info("Thread sleep is interrupted."); 71 | } 72 | return isLocked; 73 | } 74 | 75 | public String name() { 76 | return this.name; 77 | } 78 | 79 | public void name(String name) { 80 | this.name = name; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /hugegraph-rpc/src/main/java/org/apache/hugegraph/rpc/RpcClientProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.rpc; 19 | 20 | import java.util.Arrays; 21 | import java.util.LinkedHashSet; 22 | import java.util.Set; 23 | 24 | import com.alipay.sofa.rpc.common.utils.StringUtils; 25 | import org.apache.hugegraph.config.RpcOptions; 26 | import org.apache.hugegraph.config.HugeConfig; 27 | import org.apache.hugegraph.util.E; 28 | 29 | public class RpcClientProvider { 30 | 31 | private final RpcConsumerConfig consumerConfig; 32 | 33 | public RpcClientProvider(HugeConfig config) { 34 | // TODO: fetch from registry server 35 | String rpcUrl = config.get(RpcOptions.RPC_REMOTE_URL); 36 | String selfUrl = config.get(RpcOptions.RPC_SERVER_HOST) + ":" + 37 | config.get(RpcOptions.RPC_SERVER_PORT); 38 | rpcUrl = excludeSelfUrl(rpcUrl, selfUrl); 39 | this.consumerConfig = StringUtils.isNotBlank(rpcUrl) ? 40 | new RpcConsumerConfig(config, rpcUrl) : null; 41 | } 42 | 43 | public boolean enabled() { 44 | return this.consumerConfig != null; 45 | } 46 | 47 | public RpcConsumerConfig config() { 48 | E.checkArgument(this.consumerConfig != null, 49 | "RpcClient is not enabled, please config option '%s' " + 50 | "and ensure to add an address other than self service", 51 | RpcOptions.RPC_REMOTE_URL.name()); 52 | return this.consumerConfig; 53 | } 54 | 55 | public void unreferAll() { 56 | if (this.consumerConfig != null) { 57 | this.consumerConfig.removeAllServiceProxy(); 58 | } 59 | } 60 | 61 | public void destroy() { 62 | if (this.consumerConfig != null) { 63 | this.consumerConfig.destroy(); 64 | } 65 | } 66 | 67 | protected static String excludeSelfUrl(String rpcUrl, String selfUrl) { 68 | String[] urls = StringUtils.splitWithCommaOrSemicolon(rpcUrl); 69 | // Keep urls order via LinkedHashSet 70 | Set urlSet = new LinkedHashSet<>(Arrays.asList(urls)); 71 | urlSet.remove(selfUrl); 72 | return String.join(",", urlSet); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/util/DateUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.util; 19 | 20 | import java.util.Date; 21 | import java.util.Map; 22 | import java.util.concurrent.ConcurrentHashMap; 23 | 24 | import org.apache.hugegraph.date.SafeDateFormat; 25 | import com.google.common.collect.ImmutableMap; 26 | 27 | public final class DateUtil { 28 | 29 | public static final Date DATE_ZERO = new Date(0L); 30 | 31 | private static final Map VALID_DFS = ImmutableMap.of( 32 | "^\\d{4}-\\d{1,2}-\\d{1,2}", 33 | "yyyy-MM-dd", 34 | "^\\d{4}-\\d{1,2}-\\d{1,2}\\s\\d{2}:\\d{2}:\\d{2}", 35 | "yyyy-MM-dd HH:mm:ss", 36 | "^\\d{4}-\\d{1,2}-\\d{1,2}\\s\\d{2}:\\d{2}:\\d{2}\\.\\d{1,3}", 37 | "yyyy-MM-dd HH:mm:ss.SSS" 38 | ); 39 | 40 | private static final Map DATE_FORMATS = new ConcurrentHashMap<>(); 41 | 42 | public static Date parse(String value) { 43 | for (Map.Entry entry : VALID_DFS.entrySet()) { 44 | if (value.matches(entry.getKey())) { 45 | return parse(value, entry.getValue()); 46 | } 47 | } 48 | throw new IllegalArgumentException(String.format( 49 | "Expected date format is: %s, but got '%s'", VALID_DFS.values(), value)); 50 | } 51 | 52 | public static Date parse(String value, String df) { 53 | SafeDateFormat dateFormat = getDateFormat(df); 54 | return dateFormat.parse(value); 55 | } 56 | 57 | public static Date now() { 58 | return new Date(); 59 | } 60 | 61 | private static SafeDateFormat getDateFormat(String df) { 62 | SafeDateFormat dateFormat = DATE_FORMATS.get(df); 63 | if (dateFormat == null) { 64 | dateFormat = new SafeDateFormat(df); 65 | SafeDateFormat previous = DATE_FORMATS.putIfAbsent(df, dateFormat); 66 | if (previous != null) { 67 | dateFormat = previous; 68 | } 69 | } 70 | return dateFormat; 71 | } 72 | 73 | public static Object toPattern(String df) { 74 | SafeDateFormat dateFormat = getDateFormat(df); 75 | return dateFormat.toPattern(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/config/ConfigListOption.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.config; 19 | 20 | import java.util.ArrayList; 21 | import java.util.Arrays; 22 | import java.util.List; 23 | import java.util.function.Function; 24 | 25 | import org.apache.hugegraph.util.E; 26 | import com.google.common.base.Predicate; 27 | 28 | public class ConfigListOption extends ConfigOption> { 29 | 30 | private final Class elemClass; 31 | 32 | @SuppressWarnings("unchecked") 33 | public ConfigListOption(String name, String desc, 34 | Predicate> pred, T... values) { 35 | this(name, false, desc, pred, null, Arrays.asList(values)); 36 | } 37 | 38 | @SuppressWarnings("unchecked") 39 | public ConfigListOption(String name, boolean required, String desc, 40 | Predicate> pred, Class clazz, 41 | List values) { 42 | super(name, required, desc, pred, 43 | (Class>) values.getClass(), values); 44 | if (clazz == null && values.size() > 0) { 45 | clazz = (Class) values.get(0).getClass(); 46 | } 47 | E.checkArgumentNotNull(clazz, "Element class can't be null"); 48 | this.elemClass = clazz; 49 | } 50 | 51 | @Override 52 | protected boolean forList() { 53 | return true; 54 | } 55 | 56 | @Override 57 | protected List parse(String value) { 58 | return convert(value, part -> this.parse(part, this.elemClass)); 59 | } 60 | 61 | @SuppressWarnings("unchecked") 62 | public static List convert(Object value, Function conv) { 63 | if (value instanceof List) { 64 | return (List) value; 65 | } 66 | // If target data type is List, parse it as a list 67 | String str = (String) value; 68 | if (str.startsWith("[") && str.endsWith("]")) { 69 | str = str.substring(1, str.length() - 1); 70 | } 71 | 72 | String[] parts = str.split(","); 73 | List results = new ArrayList<>(parts.length); 74 | for (String part : parts) { 75 | results.add((T) conv.apply(part.trim())); 76 | } 77 | return results; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/rest/RestHeaders.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.rest; 19 | 20 | import java.util.Date; 21 | import java.util.Iterator; 22 | 23 | import kotlin.Pair; 24 | 25 | public class RestHeaders { 26 | 27 | public static final String CONTENT_TYPE = "Content-Type"; 28 | 29 | public static final String CONTENT_ENCODING = "Content-Encoding"; 30 | 31 | public static final String AUTHORIZATION = "Authorization"; 32 | 33 | public static final String APPLICATION_JSON = "application/json"; 34 | 35 | public static final String BEARER_PREFIX = "Bearer "; 36 | 37 | private final okhttp3.Headers.Builder headersBuilder; 38 | 39 | public RestHeaders() { 40 | this.headersBuilder = new okhttp3.Headers.Builder(); 41 | } 42 | 43 | public static RestHeaders convertToRestHeaders(okhttp3.Headers headers) { 44 | RestHeaders restHeaders = new RestHeaders(); 45 | 46 | if (headers != null) { 47 | Iterator> iter = headers.iterator(); 48 | while (iter.hasNext()) { 49 | Pair pair = iter.next(); 50 | restHeaders.add(pair.getFirst(), pair.getSecond()); 51 | } 52 | } 53 | return restHeaders; 54 | } 55 | 56 | public String get(String key) { 57 | return this.headersBuilder.get(key); 58 | } 59 | 60 | public Date getDate(String key) { 61 | return this.headersBuilder.build().getDate(key); 62 | } 63 | 64 | public RestHeaders add(String key, String value) { 65 | this.headersBuilder.add(key, value); 66 | return this; 67 | } 68 | 69 | public RestHeaders add(String key, Date value) { 70 | this.headersBuilder.add(key, value); 71 | return this; 72 | } 73 | 74 | @Override 75 | public int hashCode() { 76 | return this.toOkHttpHeader().hashCode(); 77 | } 78 | 79 | @Override 80 | public boolean equals(Object obj) { 81 | if (obj instanceof RestHeaders) { 82 | return this.toOkHttpHeader().equals(((RestHeaders) obj).toOkHttpHeader()); 83 | } 84 | return false; 85 | } 86 | 87 | public okhttp3.Headers toOkHttpHeader() { 88 | return this.headersBuilder.build(); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/license/LicenseExtraParam.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.license; 19 | 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | 22 | public class LicenseExtraParam { 23 | 24 | public static final int NO_LIMIT = -1; 25 | 26 | @JsonProperty("id") 27 | private String id; 28 | 29 | @JsonProperty("version") 30 | private String version; 31 | 32 | @JsonProperty("graphs") 33 | private int graphs; 34 | 35 | @JsonProperty("ip") 36 | private String ip; 37 | 38 | @JsonProperty("mac") 39 | private String mac; 40 | 41 | @JsonProperty("cpus") 42 | private int cpus; 43 | 44 | // The unit is MB 45 | @JsonProperty("ram") 46 | private int ram; 47 | 48 | @JsonProperty("threads") 49 | private int threads; 50 | 51 | // The unit is MB 52 | @JsonProperty("memory") 53 | private int memory; 54 | 55 | @JsonProperty("nodes") 56 | private int nodes; 57 | 58 | // The unit is MB 59 | @JsonProperty("data_size") 60 | private long dataSize; 61 | 62 | @JsonProperty("vertices") 63 | private long vertices; 64 | 65 | @JsonProperty("edges") 66 | private long edges; 67 | 68 | public String id() { 69 | return this.id; 70 | } 71 | 72 | public String version() { 73 | return this.version; 74 | } 75 | 76 | public int graphs() { 77 | return this.graphs; 78 | } 79 | 80 | public String ip() { 81 | return this.ip; 82 | } 83 | 84 | public String mac() { 85 | return this.mac; 86 | } 87 | 88 | public int cpus() { 89 | return this.cpus; 90 | } 91 | 92 | public int ram() { 93 | return this.ram; 94 | } 95 | 96 | public int threads() { 97 | return this.threads; 98 | } 99 | 100 | public int memory() { 101 | return this.memory; 102 | } 103 | 104 | public int nodes() { 105 | return this.nodes; 106 | } 107 | 108 | public long dataSize() { 109 | return this.dataSize; 110 | } 111 | 112 | public long vertices() { 113 | return this.vertices; 114 | } 115 | 116 | public long edges() { 117 | return this.edges; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/iterator/FlatMapperIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.iterator; 19 | 20 | import java.util.Iterator; 21 | import java.util.function.Function; 22 | 23 | import org.apache.hugegraph.util.E; 24 | 25 | public class FlatMapperIterator extends WrappedIterator { 26 | 27 | private final Iterator originIterator; 28 | private final Function> mapperCallback; 29 | 30 | protected Iterator batchIterator; 31 | 32 | public FlatMapperIterator(Iterator origin, 33 | Function> mapper) { 34 | this.originIterator = origin; 35 | this.mapperCallback = mapper; 36 | this.batchIterator = null; 37 | } 38 | 39 | @Override 40 | public void close() throws Exception { 41 | this.resetBatchIterator(); 42 | super.close(); 43 | } 44 | 45 | @Override 46 | protected Iterator originIterator() { 47 | return this.originIterator; 48 | } 49 | 50 | @Override 51 | protected final boolean fetch() { 52 | if (this.batchIterator != null && this.fetchFromBatch()) { 53 | return true; 54 | } 55 | 56 | while (this.originIterator.hasNext()) { 57 | T next = this.originIterator.next(); 58 | assert this.batchIterator == null; 59 | // Do fetch 60 | this.batchIterator = this.mapperCallback.apply(next); 61 | if (this.batchIterator != null && this.fetchFromBatch()) { 62 | return true; 63 | } 64 | } 65 | return false; 66 | } 67 | 68 | protected boolean fetchFromBatch() { 69 | E.checkNotNull(this.batchIterator, "mapper results"); 70 | while (this.batchIterator.hasNext()) { 71 | R result = this.batchIterator.next(); 72 | if (result != null) { 73 | assert this.current == none(); 74 | this.current = result; 75 | return true; 76 | } 77 | } 78 | this.resetBatchIterator(); 79 | return false; 80 | } 81 | 82 | protected final void resetBatchIterator() { 83 | if (this.batchIterator == null) { 84 | return; 85 | } 86 | close(this.batchIterator); 87 | this.batchIterator = null; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/config/OptionChecker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.config; 19 | 20 | import java.lang.reflect.Array; 21 | import java.util.Arrays; 22 | import java.util.HashSet; 23 | import java.util.List; 24 | 25 | import org.apache.commons.lang3.StringUtils; 26 | 27 | import com.google.common.base.Predicate; 28 | 29 | public final class OptionChecker { 30 | 31 | public static Predicate disallowEmpty() { 32 | return o -> { 33 | if (o == null) { 34 | return false; 35 | } 36 | if (o instanceof String) { 37 | return StringUtils.isNotBlank((String) o); 38 | } 39 | if (o.getClass().isArray() && (Array.getLength(o) == 0)) { 40 | return false; 41 | } 42 | return !(o instanceof Iterable) || ((Iterable) o).iterator().hasNext(); 43 | }; 44 | } 45 | 46 | @SuppressWarnings("unchecked") 47 | public static Predicate allowValues(O... values) { 48 | return o -> o != null && Arrays.asList(values).contains(o); 49 | } 50 | 51 | @SuppressWarnings("unchecked") 52 | public static Predicate> inValues(O... values) { 53 | return o -> o != null && new HashSet<>(Arrays.asList(values)).containsAll(o); 54 | } 55 | 56 | public static Predicate positiveInt() { 57 | return number -> number != null && number.longValue() > 0; 58 | } 59 | 60 | public static Predicate nonNegativeInt() { 61 | return number -> number != null && number.longValue() >= 0; 62 | } 63 | 64 | public static Predicate rangeInt(N min, N max) { 65 | return number -> { 66 | if (number == null) { 67 | return false; 68 | } 69 | long value = number.longValue(); 70 | return value >= min.longValue() && value <= max.longValue(); 71 | }; 72 | } 73 | 74 | public static Predicate rangeDouble(N min, N max) { 75 | return number -> { 76 | if (number == null) { 77 | return false; 78 | } 79 | double value = number.doubleValue(); 80 | return value >= min.doubleValue() && value <= max.doubleValue(); 81 | }; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /hugegraph-common/src/test/java/org/apache/hugegraph/unit/perf/testclass/TestClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.unit.perf.testclass; 19 | 20 | import org.apache.hugegraph.perf.PerfUtil; 21 | import org.apache.hugegraph.perf.PerfUtil.Watched; 22 | 23 | public class TestClass { 24 | 25 | @Watched 26 | public void test() { 27 | new Foo().bar(); 28 | } 29 | 30 | public static class Foo { 31 | 32 | @Watched(prefix="foo") 33 | public void foo() { 34 | this.bar(); 35 | } 36 | 37 | @Watched(prefix="foo") 38 | public void bar() {} 39 | } 40 | 41 | public static class Bar { 42 | 43 | @Watched("bar_foo") 44 | public void foo() { 45 | this.bar(); 46 | } 47 | 48 | @Watched("bar_bar") 49 | public void bar() {} 50 | } 51 | 52 | public static class ManuallyProfile { 53 | 54 | public void foo() { 55 | PerfUtil.instance().start("manu-foo"); 56 | this.bar(); 57 | this.bar2(); 58 | PerfUtil.instance().end("manu-foo"); 59 | } 60 | 61 | public void bar() { 62 | PerfUtil.instance().start("manu-bar"); 63 | try { 64 | Thread.sleep(0); 65 | } catch (InterruptedException ignored) { 66 | // pass 67 | } 68 | PerfUtil.instance().end("manu-bar"); 69 | } 70 | 71 | public void foo2() { 72 | PerfUtil.instance().start2("manu-foo2"); 73 | this.bar(); 74 | this.bar2(); 75 | PerfUtil.instance().end("manu-foo2"); 76 | } 77 | 78 | public void bar2() { 79 | PerfUtil.instance().start2("manu-bar2"); 80 | try { 81 | Thread.sleep(0); 82 | } catch (InterruptedException ignored) { 83 | // pass 84 | } 85 | PerfUtil.instance().end("manu-bar2"); 86 | } 87 | } 88 | 89 | public static class Base { 90 | 91 | @Watched 92 | public void func() {} 93 | } 94 | 95 | public static class Sub extends Base { 96 | 97 | @Watched 98 | public void func1() {} 99 | 100 | public void func2() {} 101 | 102 | @Watched 103 | public void func3() {} 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /hugegraph-rpc/src/main/java/org/apache/hugegraph/rpc/RpcProviderConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.rpc; 19 | 20 | import java.util.Map; 21 | 22 | import com.alipay.sofa.rpc.config.ProviderConfig; 23 | import org.apache.hugegraph.util.E; 24 | import com.google.common.collect.Maps; 25 | 26 | public class RpcProviderConfig implements RpcServiceConfig4Server { 27 | 28 | private final Map> configs = Maps.newHashMap(); 29 | 30 | @Override 31 | public String addService(Class clazz, S serviceImpl) { 32 | return this.addService(null, clazz.getName(), serviceImpl); 33 | } 34 | 35 | @Override 36 | public String addService(String graph, 37 | Class clazz, 38 | S serviceImpl) { 39 | return this.addService(graph, clazz.getName(), serviceImpl); 40 | } 41 | 42 | private String addService(String graph, 43 | String interfaceId, 44 | S serviceImpl) { 45 | ProviderConfig providerConfig = new ProviderConfig<>(); 46 | String serviceId; 47 | if (graph != null) { 48 | serviceId = interfaceId + ":" + graph; 49 | providerConfig.setId(serviceId).setUniqueId(graph); 50 | } else { 51 | serviceId = interfaceId; 52 | } 53 | 54 | providerConfig.setInterfaceId(interfaceId) 55 | .setRef(serviceImpl); 56 | 57 | E.checkArgument(!this.configs.containsKey(serviceId), 58 | "Not allowed to add service already exist: '%s'", 59 | serviceId); 60 | this.configs.put(serviceId, providerConfig); 61 | return serviceId; 62 | } 63 | 64 | @Override 65 | public void removeService(String serviceId) { 66 | ProviderConfig config = this.configs.remove(serviceId); 67 | E.checkArgument(config != null, 68 | "The service '%s' doesn't exist", serviceId); 69 | config.unExport(); 70 | } 71 | 72 | @Override 73 | public void removeAllService() { 74 | for (ProviderConfig config : this.configs.values()) { 75 | config.unExport(); 76 | } 77 | this.configs.clear(); 78 | } 79 | 80 | public Map> configs() { 81 | return this.configs; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/concurrent/LockGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.concurrent; 19 | 20 | import java.util.Map; 21 | import java.util.concurrent.ConcurrentHashMap; 22 | import java.util.concurrent.locks.Lock; 23 | import java.util.concurrent.locks.ReadWriteLock; 24 | import java.util.concurrent.locks.ReentrantLock; 25 | import java.util.concurrent.locks.ReentrantReadWriteLock; 26 | 27 | public class LockGroup { 28 | 29 | private final String name; 30 | private final Map locksMap; 31 | 32 | public LockGroup(String lockGroup) { 33 | this.name = lockGroup; 34 | this.locksMap = new ConcurrentHashMap<>(); 35 | } 36 | 37 | public Lock lock(String lockName) { 38 | if (!this.locksMap.containsKey(lockName)) { 39 | this.locksMap.putIfAbsent(lockName, new ReentrantLock()); 40 | } 41 | return (Lock) this.locksMap.get(lockName); 42 | } 43 | 44 | public AtomicLock atomicLock(String lockName) { 45 | if (!this.locksMap.containsKey(lockName)) { 46 | this.locksMap.putIfAbsent(lockName, new AtomicLock(lockName)); 47 | } 48 | return (AtomicLock) this.locksMap.get(lockName); 49 | } 50 | 51 | public ReadWriteLock readWriteLock(String lockName) { 52 | if (!this.locksMap.containsKey(lockName)) { 53 | this.locksMap.putIfAbsent(lockName, new ReentrantReadWriteLock()); 54 | } 55 | return (ReadWriteLock) this.locksMap.get(lockName); 56 | } 57 | 58 | public KeyLock keyLock(String lockName) { 59 | if (!this.locksMap.containsKey(lockName)) { 60 | this.locksMap.putIfAbsent(lockName, new KeyLock()); 61 | } 62 | return (KeyLock) this.locksMap.get(lockName); 63 | } 64 | 65 | public KeyLock keyLock(String lockName, int size) { 66 | if (!this.locksMap.containsKey(lockName)) { 67 | this.locksMap.putIfAbsent(lockName, new KeyLock(size)); 68 | } 69 | return (KeyLock) this.locksMap.get(lockName); 70 | } 71 | 72 | public > RowLock rowLock(String lockName) { 73 | if (!this.locksMap.containsKey(lockName)) { 74 | this.locksMap.putIfAbsent(lockName, new RowLock<>()); 75 | } 76 | Object value = this.locksMap.get(lockName); 77 | @SuppressWarnings("unchecked") 78 | RowLock lock = (RowLock) value; 79 | return lock; 80 | } 81 | 82 | public String name() { 83 | return this.name; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/iterator/ExtendableIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.iterator; 19 | 20 | import java.util.Deque; 21 | import java.util.Iterator; 22 | import java.util.concurrent.ConcurrentLinkedDeque; 23 | 24 | import org.apache.hugegraph.util.E; 25 | 26 | public class ExtendableIterator extends WrappedIterator { 27 | 28 | private final Deque> itors; 29 | 30 | private Iterator currentIterator; 31 | 32 | public ExtendableIterator() { 33 | this.itors = new ConcurrentLinkedDeque<>(); 34 | this.currentIterator = null; 35 | } 36 | 37 | public ExtendableIterator(Iterator iter) { 38 | this(); 39 | this.extend(iter); 40 | } 41 | 42 | public ExtendableIterator(Iterator itor1, Iterator itor2) { 43 | this(); 44 | this.extend(itor1); 45 | this.extend(itor2); 46 | } 47 | 48 | public ExtendableIterator extend(Iterator iter) { 49 | E.checkState(this.currentIterator == null, 50 | "Can't extend iterator after iterating"); 51 | if (iter != null) { 52 | this.itors.addLast(iter); 53 | } 54 | return this; 55 | } 56 | 57 | @Override 58 | public void close() throws Exception { 59 | for (Iterator iter : this.itors) { 60 | if (iter instanceof AutoCloseable) { 61 | ((AutoCloseable) iter).close(); 62 | } 63 | } 64 | } 65 | 66 | @Override 67 | protected Iterator originIterator() { 68 | return this.currentIterator; 69 | } 70 | 71 | @Override 72 | protected boolean fetch() { 73 | assert this.current == none(); 74 | if (this.itors.isEmpty()) { 75 | return false; 76 | } 77 | 78 | if (this.currentIterator != null && this.currentIterator.hasNext()) { 79 | this.current = this.currentIterator.next(); 80 | return true; 81 | } 82 | 83 | Iterator first; 84 | while ((first = this.itors.peekFirst()) != null && !first.hasNext()) { 85 | if (first == this.itors.peekLast() && this.itors.size() == 1) { 86 | this.currentIterator = first; 87 | // The last one 88 | return false; 89 | } 90 | close(this.itors.removeFirst()); 91 | } 92 | 93 | assert first != null && first.hasNext(); 94 | this.currentIterator = first; 95 | this.current = this.currentIterator.next(); 96 | return true; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/iterator/WrappedIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.iterator; 19 | 20 | import java.util.Iterator; 21 | import java.util.NoSuchElementException; 22 | 23 | public abstract class WrappedIterator implements CIter { 24 | 25 | private static final Object NONE = new Object(); 26 | 27 | protected R current; 28 | 29 | public WrappedIterator() { 30 | this.current = none(); 31 | } 32 | 33 | @Override 34 | public boolean hasNext() { 35 | if (this.current != none()) { 36 | return true; 37 | } 38 | return this.fetch(); 39 | } 40 | 41 | @Override 42 | public R next() { 43 | if (this.current == none()) { 44 | this.fetch(); 45 | if (this.current == none()) { 46 | throw new NoSuchElementException(); 47 | } 48 | } 49 | R current = this.current; 50 | this.current = none(); 51 | return current; 52 | } 53 | 54 | @Override 55 | public void remove() { 56 | Iterator iterator = this.originIterator(); 57 | if (iterator == null) { 58 | throw new NoSuchElementException( 59 | "The origin iterator can't be null for removing"); 60 | } 61 | iterator.remove(); 62 | } 63 | 64 | @Override 65 | public void close() throws Exception { 66 | Iterator iterator = this.originIterator(); 67 | if (iterator instanceof AutoCloseable) { 68 | ((AutoCloseable) iterator).close(); 69 | } 70 | } 71 | 72 | @Override 73 | public Object metadata(String meta, Object... args) { 74 | Iterator iterator = this.originIterator(); 75 | if (iterator instanceof Metadatable) { 76 | return ((Metadatable) iterator).metadata(meta, args); 77 | } 78 | throw new IllegalStateException("Original iterator is not Metadatable"); 79 | } 80 | 81 | @SuppressWarnings("unchecked") 82 | protected static final R none() { 83 | return (R) NONE; 84 | } 85 | 86 | public static void close(Iterator iterator) { 87 | if (iterator instanceof AutoCloseable) { 88 | try { 89 | ((AutoCloseable) iterator).close(); 90 | } catch (Exception e) { 91 | throw new IllegalStateException("Failed to close iterator"); 92 | } 93 | } 94 | } 95 | 96 | protected abstract Iterator originIterator(); 97 | 98 | protected abstract boolean fetch(); 99 | } 100 | -------------------------------------------------------------------------------- /hugegraph-common/src/test/java/org/apache/hugegraph/unit/concurrent/PausableScheduledThreadPoolTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.unit.concurrent; 19 | 20 | import java.util.concurrent.TimeUnit; 21 | import java.util.concurrent.atomic.AtomicInteger; 22 | 23 | import org.apache.hugegraph.util.ExecutorUtil; 24 | import org.junit.Assert; 25 | import org.junit.Test; 26 | 27 | import org.apache.hugegraph.concurrent.PausableScheduledThreadPool; 28 | 29 | public class PausableScheduledThreadPoolTest { 30 | 31 | @Test 32 | public void testScheduleWithFixedDelay() throws InterruptedException { 33 | PausableScheduledThreadPool executor = 34 | ExecutorUtil.newPausableScheduledThreadPool("test"); 35 | long period = 500L; 36 | AtomicInteger counter = new AtomicInteger(0); 37 | executor.scheduleWithFixedDelay(() -> { 38 | System.out.println("counter: " + counter.incrementAndGet()); 39 | }, period, period, TimeUnit.MILLISECONDS); 40 | 41 | Thread.sleep((long) (2.1 * period)); 42 | Assert.assertEquals(2, counter.get()); 43 | 44 | // pause 45 | executor.pauseSchedule(); 46 | Thread.sleep(period); 47 | Assert.assertEquals(2, counter.get()); 48 | 49 | // resume 50 | executor.resumeSchedule(); 51 | Thread.sleep((long) (0.5 * period)); 52 | Assert.assertEquals(3, counter.get()); 53 | 54 | Thread.sleep((long) (0.6 * period)); 55 | Assert.assertEquals(4, counter.get()); 56 | 57 | // pause again 58 | executor.pauseSchedule(); 59 | 60 | executor.shutdown(); 61 | executor.awaitTermination(3L, TimeUnit.SECONDS); 62 | } 63 | 64 | @Test 65 | public void testScheduleWithFixedRate() throws InterruptedException { 66 | PausableScheduledThreadPool executor = 67 | ExecutorUtil.newPausableScheduledThreadPool(2, "test"); 68 | long period = 500L; 69 | AtomicInteger counter = new AtomicInteger(0); 70 | executor.scheduleAtFixedRate(() -> { 71 | System.out.println("counter: " + counter.incrementAndGet()); 72 | }, period, period, TimeUnit.MILLISECONDS); 73 | 74 | Thread.sleep((long) (2.1 * period)); 75 | Assert.assertEquals(2, counter.get()); 76 | 77 | // pause 78 | executor.pauseSchedule(); 79 | Thread.sleep(period); 80 | Assert.assertEquals(2, counter.get()); 81 | 82 | // resume 83 | executor.resumeSchedule(); 84 | Thread.sleep((long) (1.1 * period)); 85 | Assert.assertEquals(4, counter.get()); 86 | 87 | // pause again 88 | executor.pauseSchedule(); 89 | 90 | executor.shutdownNow(); 91 | executor.awaitTermination(3L, TimeUnit.SECONDS); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/util/JsonUtilCommon.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.util; 19 | 20 | import java.io.IOException; 21 | 22 | import org.apache.hugegraph.rest.SerializeException; 23 | 24 | import com.fasterxml.jackson.core.JsonProcessingException; 25 | import com.fasterxml.jackson.databind.JsonNode; 26 | import com.fasterxml.jackson.databind.Module; 27 | import com.fasterxml.jackson.databind.ObjectMapper; 28 | 29 | /** 30 | * Utility class for JSON operations. 31 | */ 32 | public final class JsonUtilCommon { 33 | 34 | /** 35 | * ObjectMapper instance used for JSON operations. 36 | */ 37 | private static final ObjectMapper MAPPER = new ObjectMapper(); 38 | 39 | /** 40 | * Registers a module with the ObjectMapper. 41 | * 42 | * @param module the module to register 43 | */ 44 | public static void registerModule(Module module) { 45 | MAPPER.registerModule(module); 46 | } 47 | 48 | /** 49 | * Converts an object to a JSON string. 50 | * 51 | * @param object the object to convert 52 | * @return the JSON string representation of the object 53 | * @throws SerializeException if the object cannot be serialized 54 | */ 55 | public static String toJson(Object object) { 56 | try { 57 | return MAPPER.writeValueAsString(object); 58 | } catch (JsonProcessingException e) { 59 | throw new SerializeException("Failed to serialize object '%s'", e, object); 60 | } 61 | } 62 | 63 | /** 64 | * Converts a JSON string to an object of the specified class. 65 | * 66 | * @param json the JSON string 67 | * @param clazz the class of the object 68 | * @return the object represented by the JSON string 69 | * @throws SerializeException if the JSON string cannot be deserialized 70 | */ 71 | public static T fromJson(String json, Class clazz) { 72 | try { 73 | return MAPPER.readValue(json, clazz); 74 | } catch (IOException e) { 75 | throw new SerializeException("Failed to deserialize json '%s'", e, json); 76 | } 77 | } 78 | 79 | /** 80 | * Converts a JsonNode to an object of the specified class. 81 | * 82 | * @param node the JsonNode 83 | * @param clazz the class of the object 84 | * @return the object represented by the JsonNode 85 | * @throws SerializeException if the JsonNode cannot be deserialized 86 | */ 87 | public static T convertValue(JsonNode node, Class clazz) { 88 | try { 89 | return MAPPER.convertValue(node, clazz); 90 | } catch (IllegalArgumentException e) { 91 | throw new SerializeException("Failed to deserialize json node '%s'", e, node); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /hugegraph-common/src/test/java/org/apache/hugegraph/unit/license/LicenseParamsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.unit.license; 19 | 20 | import java.io.IOException; 21 | 22 | import org.apache.hugegraph.license.LicenseExtraParam; 23 | import org.apache.hugegraph.license.LicenseParams; 24 | import org.junit.Test; 25 | 26 | import org.apache.hugegraph.testutil.Assert; 27 | import com.fasterxml.jackson.databind.ObjectMapper; 28 | 29 | public class LicenseParamsTest { 30 | 31 | @Test 32 | public void testLicenseParams() throws IOException { 33 | String json = "{" 34 | + "\"subject\":\"hugegraph-evaluation\"," 35 | + "\"issued_time\":\"2019-08-10 00:00:00\"," 36 | + "\"not_before\":\"2019-08-10 00:00:00\"," 37 | + "\"not_after\":\"2020-08-10 00:00:00\"," 38 | + "\"consumer_type\":\"user\"," 39 | + "\"consumer_amount\":1," 40 | + "\"description\":\"hugegraph license\"," 41 | + "\"extra_params\":[" 42 | + "{" 43 | + "\"id\":\"server-1\"," 44 | + "\"version\":\"0.9.2\"," 45 | + "\"graphs\":3," 46 | + "\"ip\":\"127.0.0.1\"," 47 | + "\"mac\":\"00-01-6C-06-A6-29\"," 48 | + "\"cpus\":32," 49 | + "\"ram\":65536," 50 | + "\"threads\":96," 51 | + "\"memory\":32768," 52 | + "\"nodes\":3," 53 | + "\"data_size\":1024," 54 | + "\"vertices\":1000," 55 | + "\"edges\":2000" 56 | + "}," 57 | + "{" 58 | + "\"id\":\"server-2\"," 59 | + "\"version\":\"0.10.2\"," 60 | + "\"graphs\":3," 61 | + "\"ip\":\"127.0.0.1\"," 62 | + "\"mac\":\"00-02-6C-06-A6-29\"," 63 | + "\"cpus\":64," 64 | + "\"ram\":65536," 65 | + "\"threads\":96," 66 | + "\"memory\":65536," 67 | + "\"nodes\":30," 68 | + "\"data_size\":10240," 69 | + "\"vertices\":10000," 70 | + "\"edges\":20000" 71 | + "}" 72 | + "]" 73 | + "}"; 74 | ObjectMapper mapper = new ObjectMapper(); 75 | LicenseParams param = mapper.readValue(json, LicenseParams.class); 76 | 77 | LicenseExtraParam extraParam = param.matchParam("server-not-exist"); 78 | Assert.assertNull(extraParam); 79 | 80 | extraParam = param.matchParam("server-1"); 81 | Assert.assertEquals("00-01-6C-06-A6-29", extraParam.mac()); 82 | 83 | extraParam = param.matchParam("server-2"); 84 | Assert.assertEquals("00-02-6C-06-A6-29", extraParam.mac()); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /hugegraph-common/src/test/java/org/apache/hugegraph/unit/license/MachineInfoTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.unit.license; 19 | 20 | import java.net.InetAddress; 21 | import java.net.UnknownHostException; 22 | import java.util.List; 23 | import java.util.regex.Pattern; 24 | 25 | import org.junit.Test; 26 | 27 | import org.apache.hugegraph.license.MachineInfo; 28 | import org.apache.hugegraph.testutil.Assert; 29 | 30 | public class MachineInfoTest { 31 | 32 | private static final Pattern IPV4_PATTERN = Pattern.compile( 33 | "^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}" + 34 | "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$" 35 | ); 36 | private static final Pattern IPV6_PATTERN = Pattern.compile( 37 | "^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$" 38 | ); 39 | 40 | private static final Pattern MAC_PATTERN = Pattern.compile( 41 | "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$" 42 | ); 43 | 44 | private static final MachineInfo machineInfo = new MachineInfo(); 45 | 46 | @Test 47 | public void testGetIpAddressList() { 48 | List ipAddressList = machineInfo.getIpAddress(); 49 | for (String ip : ipAddressList) { 50 | Assert.assertTrue(IPV4_PATTERN.matcher(ip).matches() || 51 | IPV6_PATTERN.matcher(ip).matches()); 52 | } 53 | Assert.assertEquals(ipAddressList, machineInfo.getIpAddress()); 54 | } 55 | 56 | @Test 57 | public void testGetMacAddressList() { 58 | List macAddressList = machineInfo.getMacAddress(); 59 | for (String mac : macAddressList) { 60 | Assert.assertTrue(MAC_PATTERN.matcher(mac).matches()); 61 | } 62 | Assert.assertEquals(macAddressList, machineInfo.getMacAddress()); 63 | } 64 | 65 | @Test 66 | public void testGetLocalAllInetAddress() { 67 | List addressList = machineInfo.getLocalAllInetAddress(); 68 | for (InetAddress address : addressList) { 69 | String ip = address.getHostAddress(); 70 | Assert.assertTrue(IPV4_PATTERN.matcher(ip).matches() || 71 | IPV6_PATTERN.matcher(ip).matches()); 72 | } 73 | } 74 | 75 | @Test 76 | public void testGetMacByInetAddress() throws UnknownHostException { 77 | List addressList = machineInfo.getLocalAllInetAddress(); 78 | for (InetAddress address : addressList) { 79 | String mac = machineInfo.getMacByInetAddress(address); 80 | Assert.assertTrue(MAC_PATTERN.matcher(mac).matches()); 81 | } 82 | InetAddress address = InetAddress.getByAddress(new byte[]{0, 0, 0, 0}); 83 | Assert.assertThrows(RuntimeException.class, () -> { 84 | machineInfo.getMacByInetAddress(address); 85 | }); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /hugegraph-common/src/main/java/org/apache/hugegraph/license/LicenseCommonParam.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with this 4 | * work for additional information regarding copyright ownership. The ASF 5 | * licenses this file to You under the Apache License, Version 2.0 (the 6 | * "License"); you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | */ 17 | 18 | package org.apache.hugegraph.license; 19 | 20 | import java.util.Date; 21 | import java.util.List; 22 | 23 | import org.apache.commons.lang3.time.DateUtils; 24 | 25 | import com.fasterxml.jackson.annotation.JsonFormat; 26 | import com.fasterxml.jackson.annotation.JsonProperty; 27 | 28 | public class LicenseCommonParam { 29 | 30 | @JsonProperty("subject") 31 | private String subject; 32 | 33 | @JsonProperty("issued_time") 34 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 35 | private Date issuedTime = new Date(); 36 | 37 | @JsonProperty("not_before") 38 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 39 | private Date notBefore = this.issuedTime; 40 | 41 | @JsonProperty("not_after") 42 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 43 | private Date notAfter = DateUtils.addDays(this.notBefore, 30); 44 | 45 | @JsonProperty("consumer_type") 46 | private String consumerType = "user"; 47 | 48 | @JsonProperty("consumer_amount") 49 | private Integer consumerAmount = 1; 50 | 51 | @JsonProperty("description") 52 | private String description = ""; 53 | 54 | @JsonProperty("extra_params") 55 | private List extraParams; 56 | 57 | public LicenseCommonParam() { 58 | // pass 59 | } 60 | 61 | public LicenseCommonParam(String subject, String description, 62 | Date issued, Date notBefore, Date notAfter, 63 | String consumerType, int consumerAmount, 64 | List extraParams) { 65 | this.subject = subject; 66 | this.description = description; 67 | this.issuedTime = issued; 68 | this.notBefore = notBefore; 69 | this.notAfter = notAfter; 70 | this.consumerType = consumerType; 71 | this.consumerAmount = consumerAmount; 72 | this.extraParams = extraParams; 73 | } 74 | 75 | public String subject() { 76 | return this.subject; 77 | } 78 | 79 | public Date issuedTime() { 80 | return this.issuedTime; 81 | } 82 | 83 | public Date notBefore() { 84 | return this.notBefore; 85 | } 86 | 87 | public Date notAfter() { 88 | return this.notAfter; 89 | } 90 | 91 | public String consumerType() { 92 | return this.consumerType; 93 | } 94 | 95 | public Integer consumerAmount() { 96 | return this.consumerAmount; 97 | } 98 | 99 | public String description() { 100 | return this.description; 101 | } 102 | 103 | public List extraParams() { 104 | return this.extraParams; 105 | } 106 | } 107 | --------------------------------------------------------------------------------