├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── OSSMETADATA ├── README.md ├── build.gradle ├── gradle ├── buildViaTravis.sh └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── pom.xml ├── settings.gradle └── src └── main ├── java └── how │ └── hollow │ ├── consumer │ ├── Consumer.java │ ├── api │ │ ├── APIGenerator.java │ │ └── generated │ │ │ ├── Actor.java │ │ │ ├── Movie.java │ │ │ ├── MovieAPI.java │ │ │ ├── accessor │ │ │ ├── ActorDataAccessor.java │ │ │ └── MovieDataAccessor.java │ │ │ ├── collections │ │ │ └── SetOfActor.java │ │ │ ├── core │ │ │ ├── ActorDelegate.java │ │ │ ├── ActorDelegateCachedImpl.java │ │ │ ├── ActorDelegateLookupImpl.java │ │ │ ├── ActorHollowFactory.java │ │ │ ├── ActorTypeAPI.java │ │ │ ├── MovieAPIFactory.java │ │ │ ├── MovieDelegate.java │ │ │ ├── MovieDelegateCachedImpl.java │ │ │ ├── MovieDelegateLookupImpl.java │ │ │ ├── MovieHollowFactory.java │ │ │ ├── MovieTypeAPI.java │ │ │ ├── SetOfActorHollowFactory.java │ │ │ └── SetOfActorTypeAPI.java │ │ │ └── index │ │ │ ├── ActorPrimaryKeyIndex.java │ │ │ ├── ActorUniqueKeyIndex.java │ │ │ ├── MovieAPIHashIndex.java │ │ │ ├── MoviePrimaryKeyIndex.java │ │ │ └── MovieUniqueKeyIndex.java │ └── infrastructure │ │ ├── DynamoDBAnnouncementWatcher.java │ │ ├── S3AnnouncementWatcher.java │ │ └── S3BlobRetriever.java │ └── producer │ ├── Producer.java │ ├── SourceDataRetriever.java │ ├── datamodel │ ├── Actor.java │ └── Movie.java │ └── infrastructure │ ├── DynamoDBAnnouncer.java │ ├── S3Announcer.java │ └── S3Publisher.java └── resources └── readme /.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | /target/ 4 | /.idea/ 5 | .classpath 6 | .gradle 7 | .project 8 | .settings 9 | *.iml 10 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Netflix/hollow-reference-implementation/a2974a8fef35d806d1b735b185ebc5bfba2cc1d1/CHANGELOG.md -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /OSSMETADATA: -------------------------------------------------------------------------------- 1 | osslifecycle=active 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hollow Reference Implementation 2 | 3 | [![Join the chat at https://gitter.im/Netflix/hollow](https://badges.gitter.im/Netflix/hollow.svg)](https://gitter.im/Netflix/hollow?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 4 | 5 | This project is a reference implementation for NetflixOSS [Hollow](https://github.com/Netflix/hollow). 6 | 7 | Clone this project, import it into your IDE, then follow along with the [quick start guide](http://hollow.how/quick-start) — you'll have a demo up and running in minutes, and a fully production-scalable implementation of Hollow at your fingertips in about an hour. From there, you can plug in your data model and it's off to the races. 8 | 9 | ## Get Support 10 | 11 | Hollow is maintained by the Platform Data Technologies team at Netflix. Support can be obtained directly from us or from fellow users through [Gitter](https://gitter.im/Netflix/hollow) or by posting a question tagged with _hollow_ on Stack Overflow. 12 | 13 | ## LICENSE 14 | 15 | Copyright (c) 2016 Netflix, Inc. 16 | 17 | Licensed under the Apache License, Version 2.0 (the "License"); 18 | you may not use this file except in compliance with the License. 19 | You may obtain a copy of the License at 20 | 21 | 22 | 23 | Unless required by applicable law or agreed to in writing, software 24 | distributed under the License is distributed on an "AS IS" BASIS, 25 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 26 | See the License for the specific language governing permissions and 27 | limitations under the License. 28 | 29 | # Build & Generation tasks 30 | 31 | you can build this project and generate consumer code with `gradle` or with `maven` build systems. 32 | 33 | ## Gradle 34 | 35 | ```bash 36 | # generate consumer java code 37 | ./gradlew generateHollowConsumerApi 38 | 39 | # build 40 | ./gradlew clean build 41 | ``` 42 | 43 | ## Maven 44 | 45 | ```bash 46 | # generate consumer java code 47 | mvn hollow:generate-as-project-sources 48 | 49 | # build 50 | mvn clean package 51 | ``` -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | } 5 | dependencies { 6 | classpath "com.netflix.nebula:nebula-hollow-plugin:3.+" 7 | } 8 | } 9 | 10 | plugins { 11 | id "nebula.netflixoss" version "11.1.1" 12 | } 13 | 14 | apply plugin: 'java' 15 | apply plugin: 'nebula.hollow' 16 | compileJava { 17 | sourceCompatibility = 11 18 | targetCompatibility = 11 19 | } 20 | 21 | repositories { 22 | mavenCentral() 23 | } 24 | 25 | def hollowVersion = "7.1.7" 26 | def awsVersion = "1.12.353" 27 | 28 | dependencies { 29 | implementation "com.netflix.hollow:hollow:${hollowVersion}" 30 | implementation "com.netflix.hollow:hollow-diff-ui:${hollowVersion}" 31 | implementation "com.netflix.hollow:hollow-explorer-ui:${hollowVersion}" 32 | implementation "org.eclipse.jetty:jetty-server:9.4.2.v20170220" 33 | 34 | implementation "com.amazonaws:aws-java-sdk-s3:${awsVersion}" 35 | implementation "com.amazonaws:aws-java-sdk-dynamodb:${awsVersion}" 36 | 37 | implementation 'commons-io:commons-io:2.11.0' 38 | } 39 | 40 | task( producer, dependsOn: jar, type: JavaExec ) { 41 | main = 'how.hollow.producer.Producer' 42 | classpath = sourceSets.main.runtimeClasspath 43 | } 44 | 45 | task( consumer, dependsOn: jar, type: JavaExec ) { 46 | main = 'how.hollow.consumer.Consumer' 47 | classpath = sourceSets.main.runtimeClasspath 48 | } 49 | 50 | hollow { 51 | packagesToScan = ['how.hollow.producer.datamodel'] 52 | apiClassName = 'MovieAPI' 53 | apiPackageName = 'how.hollow.consumer.api.generated' 54 | getterPrefix = '' 55 | classPostfix = '' 56 | usePackageGrouping = true 57 | parameterizeAllClassNames = false 58 | useAggressiveSubstitutions = false 59 | useErgonomicShortcuts = true 60 | reservePrimaryKeyIndexForTypeWithPrimaryKey = true 61 | useHollowPrimitiveTypes = true 62 | restrictApiToFieldType = true 63 | useVerboseToString = true 64 | } 65 | -------------------------------------------------------------------------------- /gradle/buildViaTravis.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This script will build the project. 3 | 4 | SWITCHES="--info --stacktrace" 5 | 6 | GRADLE_VERSION=$(./gradlew -version | grep Gradle | cut -d ' ' -f 2) 7 | 8 | if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then 9 | echo -e "Build Pull Request #$TRAVIS_PULL_REQUEST => Branch [$TRAVIS_BRANCH]" 10 | ./gradlew build $SWITCHES 11 | elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" == "" ]; then 12 | echo -e 'Build Branch with Snapshot => Branch ['$TRAVIS_BRANCH']' 13 | ./gradlew -Prelease.travisci=true snapshot $SWITCHES 14 | elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" != "" ]; then 15 | echo -e 'Build Branch for Release => Branch ['$TRAVIS_BRANCH'] Tag ['$TRAVIS_TAG']' 16 | case "$TRAVIS_TAG" in 17 | *-rc\.*) 18 | ./gradlew -Prelease.travisci=true -Prelease.useLastTag=true candidate $SWITCHES 19 | ;; 20 | *) 21 | ./gradlew -Prelease.travisci=true -Prelease.useLastTag=true final $SWITCHES 22 | ;; 23 | esac 24 | else 25 | echo -e 'WARN: Should not be here => Branch ['$TRAVIS_BRANCH'] Tag ['$TRAVIS_TAG'] Pull Request ['$TRAVIS_PULL_REQUEST']' 26 | ./gradlew build $SWITCHES 27 | fi 28 | 29 | EXIT=$? 30 | 31 | rm -f "$HOME/.gradle/caches/modules-2/modules-2.lock" 32 | rm -rf "$HOME/.gradle/caches/$GRADLE_VERSION/plugin-resolution" 33 | 34 | exit $EXIT 35 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Netflix/hollow-reference-implementation/a2974a8fef35d806d1b735b185ebc5bfba2cc1d1/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Oct 13 15:06:19 PDT 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 165 | if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then 166 | cd "$(dirname "$0")" 167 | fi 168 | 169 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 170 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.netflix.hollow 6 | hollow-reference-implementation 7 | 1.0-SNAPSHOT 8 | jar 9 | 10 | Netflix Hollow Reference Implementation 11 | http://hollow.how/quick-start 12 | 13 | 14 | 7.1.7 15 | 1.12.353 16 | 17 | 18 | 19 | 20 | com.netflix.hollow 21 | hollow 22 | ${hollow.version} 23 | compile 24 | 25 | 26 | 27 | com.netflix.hollow 28 | hollow-diff-ui 29 | ${hollow.version} 30 | compile 31 | 32 | 33 | 34 | com.netflix.hollow 35 | hollow-explorer-ui 36 | ${hollow.version} 37 | compile 38 | 39 | 40 | 41 | com.amazonaws 42 | aws-java-sdk-s3 43 | ${aws.version} 44 | compile 45 | 46 | 47 | 48 | com.amazonaws 49 | aws-java-sdk-dynamodb 50 | ${aws.version} 51 | compile 52 | 53 | 54 | 55 | commons-io 56 | commons-io 57 | 2.11.0 58 | compile 59 | 60 | 61 | 62 | org.junit.jupiter 63 | junit-jupiter-engine 64 | 5.9.0 65 | test 66 | 67 | 68 | 69 | org.eclipse.jetty 70 | jetty-server 71 | 9.4.10.v20180503 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | org.apache.maven.plugins 80 | maven-compiler-plugin 81 | 2.3.2 82 | 83 | 11 84 | 11 85 | UTF-8 86 | 87 | 88 | 89 | 90 | com.github.igorperikov 91 | hollow-maven-plugin 92 | 1.0.0 93 | 94 | MovieAPI 95 | how.hollow.consumer.api.generated 96 | how.hollow.producer.datamodel 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | generate-as-project-sources 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'hollow-reference-implementation' 2 | 3 | -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/Consumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2016 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * 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, 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 | package how.hollow.consumer; 19 | 20 | import com.netflix.hollow.api.consumer.HollowConsumer; 21 | import com.netflix.hollow.api.consumer.fs.HollowFilesystemAnnouncementWatcher; 22 | import com.netflix.hollow.api.consumer.fs.HollowFilesystemBlobRetriever; 23 | import com.netflix.hollow.api.consumer.index.HashIndex; 24 | import com.netflix.hollow.api.consumer.index.UniqueKeyIndex; 25 | import com.netflix.hollow.explorer.ui.jetty.HollowExplorerUIServer; 26 | import com.netflix.hollow.history.ui.jetty.HollowHistoryUIServer; 27 | import how.hollow.consumer.api.generated.Actor; 28 | import how.hollow.consumer.api.generated.Movie; 29 | import how.hollow.consumer.api.generated.MovieAPI; 30 | import how.hollow.producer.Producer; 31 | 32 | import java.io.File; 33 | 34 | public class Consumer { 35 | 36 | public static void main(String args[]) throws Exception { 37 | File publishDir = new File(Producer.SCRATCH_DIR, "publish-dir"); 38 | 39 | System.out.println("I AM THE CONSUMER. I WILL READ FROM " + publishDir.getAbsolutePath()); 40 | 41 | HollowConsumer.BlobRetriever blobRetriever = new HollowFilesystemBlobRetriever(publishDir.toPath()); 42 | HollowConsumer.AnnouncementWatcher announcementWatcher = new HollowFilesystemAnnouncementWatcher(publishDir.toPath()); 43 | 44 | HollowConsumer consumer = HollowConsumer.withBlobRetriever(blobRetriever) 45 | .withAnnouncementWatcher(announcementWatcher) 46 | .withGeneratedAPIClass(MovieAPI.class) 47 | .build(); 48 | 49 | consumer.triggerRefresh(); 50 | 51 | hereIsHowToUseTheDataProgrammatically(consumer); 52 | 53 | /// start a history server on port 7777 54 | HollowHistoryUIServer historyServer = new HollowHistoryUIServer(consumer, 7777); 55 | historyServer.start(); 56 | 57 | /// start an explorer server on port 7778 58 | HollowExplorerUIServer explorerServer = new HollowExplorerUIServer(consumer, 7778); 59 | explorerServer.start(); 60 | 61 | historyServer.join(); 62 | } 63 | 64 | private static void hereIsHowToUseTheDataProgrammatically(HollowConsumer consumer) { 65 | /// create an index for Movie based on its primary key (Id) 66 | UniqueKeyIndex idx = Movie.uniqueIndex(consumer); 67 | 68 | /// create an index for movies by the names of cast members 69 | HashIndex moviesByActorName = HashIndex.from(consumer, Movie.class) 70 | .usingPath("actors.element.actorName.value", String.class); 71 | 72 | /// find the movie for a some known ID 73 | Movie foundMovie = idx.findMatch(1000004); 74 | 75 | /// for each actor in that movie 76 | for(Actor actor : foundMovie.getActors()) { 77 | /// get all of movies of which they are cast members 78 | moviesByActorName.findMatches(actor.getActorName()).forEach(movie -> { 79 | /// and just print the result 80 | System.out.println(actor.getActorName() + " starred in " + movie.getTitle()); 81 | }); 82 | } 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/api/APIGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2016 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * 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, 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 | package how.hollow.consumer.api; 19 | 20 | import com.netflix.hollow.api.codegen.HollowAPIGenerator; 21 | import com.netflix.hollow.core.write.HollowWriteStateEngine; 22 | import com.netflix.hollow.core.write.objectmapper.HollowObjectMapper; 23 | 24 | import java.io.File; 25 | import java.io.IOException; 26 | 27 | /** 28 | *
    29 | *
  • or use the gradle generation task with `./gradlew generateHollowConsumerApi`
  • 30 | *
  • or use the maven generation task with `mvn hollow:generate-as-project-sources`
  • 31 | *
32 | * (maven generation is broken atm due the old version of hollow in its dependencies, 33 | * please vote for this PR) 34 | */ 35 | public class APIGenerator { 36 | 37 | private static final String GENERATED_API_NAME = "MovieAPI"; 38 | 39 | private static final String DATA_MODEL_PACKAGE = "how.hollow.producer.datamodel"; 40 | private static final String GENERATED_API_PACKAGE = "how.hollow.consumer.api.generated"; 41 | 42 | private static final String DATA_MODEL_SOURCE_FOLDER = "src/main/java/" + DATA_MODEL_PACKAGE.replace('.', '/'); 43 | private static final String GENERATED_API_CODE_FOLDER = "src/main/java/" + GENERATED_API_PACKAGE.replace('.', '/'); 44 | 45 | /** 46 | * Run this main method to (re)generate the API based on the POJOs defining the data model. 47 | * If the first arg is populated, it will specify the root project folder. If not, we will attempt to discover the root project folder. 48 | */ 49 | public static void main(String[] args) throws ClassNotFoundException, IOException { 50 | File projectRootFolder; 51 | 52 | if(args.length > 0) 53 | projectRootFolder = new File(args[0]); 54 | else 55 | projectRootFolder = findRootProjectFolder(); 56 | 57 | 58 | APIGenerator generator = new APIGenerator(projectRootFolder); 59 | 60 | generator.generateFiles(); 61 | } 62 | 63 | 64 | private final File projectRootFolder; 65 | 66 | public APIGenerator(File projectRootFolder) { 67 | this.projectRootFolder = projectRootFolder; 68 | } 69 | 70 | /** 71 | * Generate the API. 72 | */ 73 | public void generateFiles() throws IOException, ClassNotFoundException { 74 | /// we'll use the following write state engine and object mapper to build schemas 75 | HollowWriteStateEngine stateEngine = new HollowWriteStateEngine(); 76 | HollowObjectMapper mapper = new HollowObjectMapper(stateEngine); 77 | 78 | /// iterate over all java POJO files describing the data model. 79 | for(String filename : findProjectFolder(DATA_MODEL_SOURCE_FOLDER).list()) { 80 | if(filename.endsWith(".java") && !filename.equals("SourceDataRetriever.java")) { 81 | String discoveredType = filename.substring(0, filename.indexOf(".java")); 82 | /// initialize the schema for that data model type. 83 | mapper.initializeTypeState(Class.forName(DATA_MODEL_PACKAGE + "." + discoveredType)); 84 | } 85 | } 86 | 87 | File apiCodeFolder = findProjectFolder(GENERATED_API_CODE_FOLDER); 88 | 89 | apiCodeFolder.mkdirs(); 90 | 91 | for(File f : apiCodeFolder.listFiles()) 92 | f.delete(); 93 | 94 | HollowAPIGenerator codeGenerator = new HollowAPIGenerator.Builder() 95 | .withAPIClassname(GENERATED_API_NAME) 96 | .withPackageName(GENERATED_API_PACKAGE) 97 | .withDataModel(stateEngine) 98 | .withDestination(apiCodeFolder.toPath()) 99 | .withParameterizeAllClassNames(false) 100 | .withAggressiveSubstitutions(false) 101 | .withBooleanFieldErgonomics(true) 102 | .reservePrimaryKeyIndexForTypeWithPrimaryKey(true) 103 | .withHollowPrimitiveTypes(true) 104 | .withVerboseToString(true) 105 | .withRestrictApiToFieldType() 106 | .withPackageGrouping() 107 | .withErgonomicShortcuts() 108 | .withClassPostfix("") 109 | .build(); 110 | 111 | codeGenerator.generateSourceFiles(); 112 | } 113 | 114 | /** 115 | * Find the relative project folder 116 | */ 117 | private File findProjectFolder(String projectFolder) { 118 | File f = projectRootFolder; 119 | 120 | for(String s : projectFolder.split("//")) { 121 | f = new File(f, s); 122 | } 123 | 124 | return f; 125 | } 126 | 127 | /** 128 | * Attempts to find the root project folder. 129 | * Assumption: A file 'readme', which is in the classpath, is nested somewhere underneath the root project folder. 130 | */ 131 | private static File findRootProjectFolder() { 132 | File f = new File(APIGenerator.class.getResource("/readme").getFile()); 133 | f = f.getParentFile(); 134 | 135 | while(!containsBuildGradle(f)) { 136 | f = f.getParentFile(); 137 | } 138 | return f; 139 | } 140 | 141 | /** 142 | * Assumption: The root project folder contains a file called 'build.gradle' 143 | */ 144 | private static boolean containsBuildGradle(File f) { 145 | return f.listFiles((dir, name) -> name.equals("build.gradle")).length > 0; 146 | } 147 | 148 | } 149 | -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/api/generated/Actor.java: -------------------------------------------------------------------------------- 1 | package how.hollow.consumer.api.generated; 2 | 3 | import com.netflix.hollow.core.type.*; 4 | import how.hollow.consumer.api.generated.MovieAPI; 5 | import how.hollow.consumer.api.generated.core.*; 6 | import how.hollow.consumer.api.generated.collections.*; 7 | 8 | import com.netflix.hollow.api.consumer.HollowConsumer; 9 | import com.netflix.hollow.api.consumer.index.UniqueKeyIndex; 10 | import com.netflix.hollow.api.objects.HollowObject; 11 | import com.netflix.hollow.core.schema.HollowObjectSchema; 12 | import com.netflix.hollow.tools.stringifier.HollowRecordStringifier; 13 | 14 | @SuppressWarnings("all") 15 | public class Actor extends HollowObject { 16 | 17 | public Actor(ActorDelegate delegate, int ordinal) { 18 | super(delegate, ordinal); 19 | } 20 | 21 | public int getActorId() { 22 | return delegate().getActorId(ordinal); 23 | } 24 | 25 | 26 | 27 | public String getActorName() { 28 | return delegate().getActorName(ordinal); 29 | } 30 | 31 | public boolean isActorNameEqual(String testValue) { 32 | return delegate().isActorNameEqual(ordinal, testValue); 33 | } 34 | 35 | public HString getActorNameHollowReference() { 36 | int refOrdinal = delegate().getActorNameOrdinal(ordinal); 37 | if(refOrdinal == -1) 38 | return null; 39 | return api().getHString(refOrdinal); 40 | } 41 | 42 | public MovieAPI api() { 43 | return typeApi().getAPI(); 44 | } 45 | 46 | public ActorTypeAPI typeApi() { 47 | return delegate().getTypeAPI(); 48 | } 49 | 50 | protected ActorDelegate delegate() { 51 | return (ActorDelegate)delegate; 52 | } 53 | 54 | public String toString() { 55 | return new HollowRecordStringifier().stringify(this); 56 | } 57 | 58 | /** 59 | * Creates a unique key index for {@code Actor} that has a primary key. 60 | * The primary key is represented by the type {@code int}. 61 | *

62 | * By default the unique key index will not track updates to the {@code consumer} and thus 63 | * any changes will not be reflected in matched results. To track updates the index must be 64 | * {@link HollowConsumer#addRefreshListener(HollowConsumer.RefreshListener) registered} 65 | * with the {@code consumer} 66 | * 67 | * @param consumer the consumer 68 | * @return the unique key index 69 | */ 70 | public static UniqueKeyIndex uniqueIndex(HollowConsumer consumer) { 71 | return UniqueKeyIndex.from(consumer, Actor.class) 72 | .bindToPrimaryKey() 73 | .usingPath("actorId", int.class); 74 | } 75 | 76 | } -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/api/generated/Movie.java: -------------------------------------------------------------------------------- 1 | package how.hollow.consumer.api.generated; 2 | 3 | import com.netflix.hollow.core.type.*; 4 | import how.hollow.consumer.api.generated.MovieAPI; 5 | import how.hollow.consumer.api.generated.core.*; 6 | import how.hollow.consumer.api.generated.collections.*; 7 | 8 | import com.netflix.hollow.api.consumer.HollowConsumer; 9 | import com.netflix.hollow.api.consumer.index.UniqueKeyIndex; 10 | import com.netflix.hollow.api.objects.HollowObject; 11 | import com.netflix.hollow.core.schema.HollowObjectSchema; 12 | import com.netflix.hollow.tools.stringifier.HollowRecordStringifier; 13 | 14 | @SuppressWarnings("all") 15 | public class Movie extends HollowObject { 16 | 17 | public Movie(MovieDelegate delegate, int ordinal) { 18 | super(delegate, ordinal); 19 | } 20 | 21 | public int getId() { 22 | return delegate().getId(ordinal); 23 | } 24 | 25 | 26 | 27 | public String getTitle() { 28 | return delegate().getTitle(ordinal); 29 | } 30 | 31 | public boolean isTitleEqual(String testValue) { 32 | return delegate().isTitleEqual(ordinal, testValue); 33 | } 34 | 35 | public HString getTitleHollowReference() { 36 | int refOrdinal = delegate().getTitleOrdinal(ordinal); 37 | if(refOrdinal == -1) 38 | return null; 39 | return api().getHString(refOrdinal); 40 | } 41 | 42 | public SetOfActor getActors() { 43 | int refOrdinal = delegate().getActorsOrdinal(ordinal); 44 | if(refOrdinal == -1) 45 | return null; 46 | return api().getSetOfActor(refOrdinal); 47 | } 48 | 49 | public MovieAPI api() { 50 | return typeApi().getAPI(); 51 | } 52 | 53 | public MovieTypeAPI typeApi() { 54 | return delegate().getTypeAPI(); 55 | } 56 | 57 | protected MovieDelegate delegate() { 58 | return (MovieDelegate)delegate; 59 | } 60 | 61 | public String toString() { 62 | return new HollowRecordStringifier().stringify(this); 63 | } 64 | 65 | /** 66 | * Creates a unique key index for {@code Movie} that has a primary key. 67 | * The primary key is represented by the type {@code int}. 68 | *

69 | * By default the unique key index will not track updates to the {@code consumer} and thus 70 | * any changes will not be reflected in matched results. To track updates the index must be 71 | * {@link HollowConsumer#addRefreshListener(HollowConsumer.RefreshListener) registered} 72 | * with the {@code consumer} 73 | * 74 | * @param consumer the consumer 75 | * @return the unique key index 76 | */ 77 | public static UniqueKeyIndex uniqueIndex(HollowConsumer consumer) { 78 | return UniqueKeyIndex.from(consumer, Movie.class) 79 | .bindToPrimaryKey() 80 | .usingPath("id", int.class); 81 | } 82 | 83 | } -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/api/generated/MovieAPI.java: -------------------------------------------------------------------------------- 1 | package how.hollow.consumer.api.generated; 2 | 3 | import com.netflix.hollow.core.type.*; 4 | import how.hollow.consumer.api.generated.core.*; 5 | import how.hollow.consumer.api.generated.collections.*; 6 | 7 | import java.util.Objects; 8 | import java.util.Collection; 9 | import java.util.Collections; 10 | import java.util.Set; 11 | import java.util.Map; 12 | import com.netflix.hollow.api.consumer.HollowConsumerAPI; 13 | import com.netflix.hollow.api.custom.HollowAPI; 14 | import com.netflix.hollow.core.read.dataaccess.HollowDataAccess; 15 | import com.netflix.hollow.core.read.dataaccess.HollowTypeDataAccess; 16 | import com.netflix.hollow.core.read.dataaccess.HollowObjectTypeDataAccess; 17 | import com.netflix.hollow.core.read.dataaccess.HollowListTypeDataAccess; 18 | import com.netflix.hollow.core.read.dataaccess.HollowSetTypeDataAccess; 19 | import com.netflix.hollow.core.read.dataaccess.HollowMapTypeDataAccess; 20 | import com.netflix.hollow.core.read.dataaccess.missing.HollowObjectMissingDataAccess; 21 | import com.netflix.hollow.core.read.dataaccess.missing.HollowListMissingDataAccess; 22 | import com.netflix.hollow.core.read.dataaccess.missing.HollowSetMissingDataAccess; 23 | import com.netflix.hollow.core.read.dataaccess.missing.HollowMapMissingDataAccess; 24 | import com.netflix.hollow.api.objects.provider.HollowFactory; 25 | import com.netflix.hollow.api.objects.provider.HollowObjectProvider; 26 | import com.netflix.hollow.api.objects.provider.HollowObjectCacheProvider; 27 | import com.netflix.hollow.api.objects.provider.HollowObjectFactoryProvider; 28 | import com.netflix.hollow.api.sampling.HollowObjectCreationSampler; 29 | import com.netflix.hollow.api.sampling.HollowSamplingDirector; 30 | import com.netflix.hollow.api.sampling.SampleResult; 31 | import com.netflix.hollow.core.util.AllHollowRecordCollection; 32 | 33 | @SuppressWarnings("all") 34 | public class MovieAPI extends HollowAPI implements HollowConsumerAPI.StringRetriever { 35 | 36 | private final HollowObjectCreationSampler objectCreationSampler; 37 | 38 | private final StringTypeAPI stringTypeAPI; 39 | private final ActorTypeAPI actorTypeAPI; 40 | private final SetOfActorTypeAPI setOfActorTypeAPI; 41 | private final MovieTypeAPI movieTypeAPI; 42 | 43 | private final HollowObjectProvider stringProvider; 44 | private final HollowObjectProvider actorProvider; 45 | private final HollowObjectProvider setOfActorProvider; 46 | private final HollowObjectProvider movieProvider; 47 | 48 | public MovieAPI(HollowDataAccess dataAccess) { 49 | this(dataAccess, Collections.emptySet()); 50 | } 51 | 52 | public MovieAPI(HollowDataAccess dataAccess, Set cachedTypes) { 53 | this(dataAccess, cachedTypes, Collections.>emptyMap()); 54 | } 55 | 56 | public MovieAPI(HollowDataAccess dataAccess, Set cachedTypes, Map> factoryOverrides) { 57 | this(dataAccess, cachedTypes, factoryOverrides, null); 58 | } 59 | 60 | public MovieAPI(HollowDataAccess dataAccess, Set cachedTypes, Map> factoryOverrides, MovieAPI previousCycleAPI) { 61 | super(dataAccess); 62 | HollowTypeDataAccess typeDataAccess; 63 | HollowFactory factory; 64 | 65 | objectCreationSampler = new HollowObjectCreationSampler("String","Actor","SetOfActor","Movie"); 66 | 67 | typeDataAccess = dataAccess.getTypeDataAccess("String"); 68 | if(typeDataAccess != null) { 69 | stringTypeAPI = new StringTypeAPI(this, (HollowObjectTypeDataAccess)typeDataAccess); 70 | } else { 71 | stringTypeAPI = new StringTypeAPI(this, new HollowObjectMissingDataAccess(dataAccess, "String")); 72 | } 73 | addTypeAPI(stringTypeAPI); 74 | factory = factoryOverrides.get("String"); 75 | if(factory == null) 76 | factory = new StringHollowFactory(); 77 | if(cachedTypes.contains("String")) { 78 | HollowObjectCacheProvider previousCacheProvider = null; 79 | if(previousCycleAPI != null && (previousCycleAPI.stringProvider instanceof HollowObjectCacheProvider)) 80 | previousCacheProvider = (HollowObjectCacheProvider) previousCycleAPI.stringProvider; 81 | stringProvider = new HollowObjectCacheProvider(typeDataAccess, stringTypeAPI, factory, previousCacheProvider); 82 | } else { 83 | stringProvider = new HollowObjectFactoryProvider(typeDataAccess, stringTypeAPI, factory); 84 | } 85 | 86 | typeDataAccess = dataAccess.getTypeDataAccess("Actor"); 87 | if(typeDataAccess != null) { 88 | actorTypeAPI = new ActorTypeAPI(this, (HollowObjectTypeDataAccess)typeDataAccess); 89 | } else { 90 | actorTypeAPI = new ActorTypeAPI(this, new HollowObjectMissingDataAccess(dataAccess, "Actor")); 91 | } 92 | addTypeAPI(actorTypeAPI); 93 | factory = factoryOverrides.get("Actor"); 94 | if(factory == null) 95 | factory = new ActorHollowFactory(); 96 | if(cachedTypes.contains("Actor")) { 97 | HollowObjectCacheProvider previousCacheProvider = null; 98 | if(previousCycleAPI != null && (previousCycleAPI.actorProvider instanceof HollowObjectCacheProvider)) 99 | previousCacheProvider = (HollowObjectCacheProvider) previousCycleAPI.actorProvider; 100 | actorProvider = new HollowObjectCacheProvider(typeDataAccess, actorTypeAPI, factory, previousCacheProvider); 101 | } else { 102 | actorProvider = new HollowObjectFactoryProvider(typeDataAccess, actorTypeAPI, factory); 103 | } 104 | 105 | typeDataAccess = dataAccess.getTypeDataAccess("SetOfActor"); 106 | if(typeDataAccess != null) { 107 | setOfActorTypeAPI = new SetOfActorTypeAPI(this, (HollowSetTypeDataAccess)typeDataAccess); 108 | } else { 109 | setOfActorTypeAPI = new SetOfActorTypeAPI(this, new HollowSetMissingDataAccess(dataAccess, "SetOfActor")); 110 | } 111 | addTypeAPI(setOfActorTypeAPI); 112 | factory = factoryOverrides.get("SetOfActor"); 113 | if(factory == null) 114 | factory = new SetOfActorHollowFactory(); 115 | if(cachedTypes.contains("SetOfActor")) { 116 | HollowObjectCacheProvider previousCacheProvider = null; 117 | if(previousCycleAPI != null && (previousCycleAPI.setOfActorProvider instanceof HollowObjectCacheProvider)) 118 | previousCacheProvider = (HollowObjectCacheProvider) previousCycleAPI.setOfActorProvider; 119 | setOfActorProvider = new HollowObjectCacheProvider(typeDataAccess, setOfActorTypeAPI, factory, previousCacheProvider); 120 | } else { 121 | setOfActorProvider = new HollowObjectFactoryProvider(typeDataAccess, setOfActorTypeAPI, factory); 122 | } 123 | 124 | typeDataAccess = dataAccess.getTypeDataAccess("Movie"); 125 | if(typeDataAccess != null) { 126 | movieTypeAPI = new MovieTypeAPI(this, (HollowObjectTypeDataAccess)typeDataAccess); 127 | } else { 128 | movieTypeAPI = new MovieTypeAPI(this, new HollowObjectMissingDataAccess(dataAccess, "Movie")); 129 | } 130 | addTypeAPI(movieTypeAPI); 131 | factory = factoryOverrides.get("Movie"); 132 | if(factory == null) 133 | factory = new MovieHollowFactory(); 134 | if(cachedTypes.contains("Movie")) { 135 | HollowObjectCacheProvider previousCacheProvider = null; 136 | if(previousCycleAPI != null && (previousCycleAPI.movieProvider instanceof HollowObjectCacheProvider)) 137 | previousCacheProvider = (HollowObjectCacheProvider) previousCycleAPI.movieProvider; 138 | movieProvider = new HollowObjectCacheProvider(typeDataAccess, movieTypeAPI, factory, previousCacheProvider); 139 | } else { 140 | movieProvider = new HollowObjectFactoryProvider(typeDataAccess, movieTypeAPI, factory); 141 | } 142 | 143 | } 144 | 145 | public void detachCaches() { 146 | if(stringProvider instanceof HollowObjectCacheProvider) 147 | ((HollowObjectCacheProvider)stringProvider).detach(); 148 | if(actorProvider instanceof HollowObjectCacheProvider) 149 | ((HollowObjectCacheProvider)actorProvider).detach(); 150 | if(setOfActorProvider instanceof HollowObjectCacheProvider) 151 | ((HollowObjectCacheProvider)setOfActorProvider).detach(); 152 | if(movieProvider instanceof HollowObjectCacheProvider) 153 | ((HollowObjectCacheProvider)movieProvider).detach(); 154 | } 155 | 156 | public StringTypeAPI getStringTypeAPI() { 157 | return stringTypeAPI; 158 | } 159 | public ActorTypeAPI getActorTypeAPI() { 160 | return actorTypeAPI; 161 | } 162 | public SetOfActorTypeAPI getSetOfActorTypeAPI() { 163 | return setOfActorTypeAPI; 164 | } 165 | public MovieTypeAPI getMovieTypeAPI() { 166 | return movieTypeAPI; 167 | } 168 | public Collection getAllHString() { 169 | HollowTypeDataAccess tda = Objects.requireNonNull(getDataAccess().getTypeDataAccess("String"), "type not loaded or does not exist in dataset; type=String"); 170 | return new AllHollowRecordCollection(tda.getTypeState()) { 171 | protected HString getForOrdinal(int ordinal) { 172 | return getHString(ordinal); 173 | } 174 | }; 175 | } 176 | public HString getHString(int ordinal) { 177 | objectCreationSampler.recordCreation(0); 178 | return (HString)stringProvider.getHollowObject(ordinal); 179 | } 180 | public Collection getAllActor() { 181 | HollowTypeDataAccess tda = Objects.requireNonNull(getDataAccess().getTypeDataAccess("Actor"), "type not loaded or does not exist in dataset; type=Actor"); 182 | return new AllHollowRecordCollection(tda.getTypeState()) { 183 | protected Actor getForOrdinal(int ordinal) { 184 | return getActor(ordinal); 185 | } 186 | }; 187 | } 188 | public Actor getActor(int ordinal) { 189 | objectCreationSampler.recordCreation(1); 190 | return (Actor)actorProvider.getHollowObject(ordinal); 191 | } 192 | public Collection getAllSetOfActor() { 193 | HollowTypeDataAccess tda = Objects.requireNonNull(getDataAccess().getTypeDataAccess("SetOfActor"), "type not loaded or does not exist in dataset; type=SetOfActor"); 194 | return new AllHollowRecordCollection(tda.getTypeState()) { 195 | protected SetOfActor getForOrdinal(int ordinal) { 196 | return getSetOfActor(ordinal); 197 | } 198 | }; 199 | } 200 | public SetOfActor getSetOfActor(int ordinal) { 201 | objectCreationSampler.recordCreation(2); 202 | return (SetOfActor)setOfActorProvider.getHollowObject(ordinal); 203 | } 204 | public Collection getAllMovie() { 205 | HollowTypeDataAccess tda = Objects.requireNonNull(getDataAccess().getTypeDataAccess("Movie"), "type not loaded or does not exist in dataset; type=Movie"); 206 | return new AllHollowRecordCollection(tda.getTypeState()) { 207 | protected Movie getForOrdinal(int ordinal) { 208 | return getMovie(ordinal); 209 | } 210 | }; 211 | } 212 | public Movie getMovie(int ordinal) { 213 | objectCreationSampler.recordCreation(3); 214 | return (Movie)movieProvider.getHollowObject(ordinal); 215 | } 216 | public void setSamplingDirector(HollowSamplingDirector director) { 217 | super.setSamplingDirector(director); 218 | objectCreationSampler.setSamplingDirector(director); 219 | } 220 | 221 | public Collection getObjectCreationSamplingResults() { 222 | return objectCreationSampler.getSampleResults(); 223 | } 224 | 225 | } 226 | -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/api/generated/accessor/ActorDataAccessor.java: -------------------------------------------------------------------------------- 1 | package how.hollow.consumer.api.generated.accessor; 2 | 3 | import com.netflix.hollow.core.type.*; 4 | import how.hollow.consumer.api.generated.MovieAPI; 5 | import how.hollow.consumer.api.generated.Actor; 6 | import how.hollow.consumer.api.generated.core.*; 7 | import how.hollow.consumer.api.generated.collections.*; 8 | 9 | import com.netflix.hollow.api.consumer.HollowConsumer; 10 | import com.netflix.hollow.api.consumer.data.AbstractHollowDataAccessor; 11 | import com.netflix.hollow.core.index.key.PrimaryKey; 12 | import com.netflix.hollow.core.read.engine.HollowReadStateEngine; 13 | 14 | @SuppressWarnings("all") 15 | public class ActorDataAccessor extends AbstractHollowDataAccessor { 16 | 17 | public static final String TYPE = "Actor"; 18 | private MovieAPI api; 19 | 20 | public ActorDataAccessor(HollowConsumer consumer) { 21 | super(consumer, TYPE); 22 | this.api = (MovieAPI)consumer.getAPI(); 23 | } 24 | 25 | public ActorDataAccessor(HollowReadStateEngine rStateEngine, MovieAPI api) { 26 | super(rStateEngine, TYPE); 27 | this.api = api; 28 | } 29 | 30 | public ActorDataAccessor(HollowReadStateEngine rStateEngine, MovieAPI api, String ... fieldPaths) { 31 | super(rStateEngine, TYPE, fieldPaths); 32 | this.api = api; 33 | } 34 | 35 | public ActorDataAccessor(HollowReadStateEngine rStateEngine, MovieAPI api, PrimaryKey primaryKey) { 36 | super(rStateEngine, TYPE, primaryKey); 37 | this.api = api; 38 | } 39 | 40 | @Override public Actor getRecord(int ordinal){ 41 | return api.getActor(ordinal); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/api/generated/accessor/MovieDataAccessor.java: -------------------------------------------------------------------------------- 1 | package how.hollow.consumer.api.generated.accessor; 2 | 3 | import com.netflix.hollow.core.type.*; 4 | import how.hollow.consumer.api.generated.MovieAPI; 5 | import how.hollow.consumer.api.generated.Movie; 6 | import how.hollow.consumer.api.generated.core.*; 7 | import how.hollow.consumer.api.generated.collections.*; 8 | 9 | import com.netflix.hollow.api.consumer.HollowConsumer; 10 | import com.netflix.hollow.api.consumer.data.AbstractHollowDataAccessor; 11 | import com.netflix.hollow.core.index.key.PrimaryKey; 12 | import com.netflix.hollow.core.read.engine.HollowReadStateEngine; 13 | 14 | @SuppressWarnings("all") 15 | public class MovieDataAccessor extends AbstractHollowDataAccessor { 16 | 17 | public static final String TYPE = "Movie"; 18 | private MovieAPI api; 19 | 20 | public MovieDataAccessor(HollowConsumer consumer) { 21 | super(consumer, TYPE); 22 | this.api = (MovieAPI)consumer.getAPI(); 23 | } 24 | 25 | public MovieDataAccessor(HollowReadStateEngine rStateEngine, MovieAPI api) { 26 | super(rStateEngine, TYPE); 27 | this.api = api; 28 | } 29 | 30 | public MovieDataAccessor(HollowReadStateEngine rStateEngine, MovieAPI api, String ... fieldPaths) { 31 | super(rStateEngine, TYPE, fieldPaths); 32 | this.api = api; 33 | } 34 | 35 | public MovieDataAccessor(HollowReadStateEngine rStateEngine, MovieAPI api, PrimaryKey primaryKey) { 36 | super(rStateEngine, TYPE, primaryKey); 37 | this.api = api; 38 | } 39 | 40 | @Override public Movie getRecord(int ordinal){ 41 | return api.getMovie(ordinal); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/api/generated/collections/SetOfActor.java: -------------------------------------------------------------------------------- 1 | package how.hollow.consumer.api.generated.collections; 2 | 3 | import com.netflix.hollow.core.type.*; 4 | import how.hollow.consumer.api.generated.MovieAPI; 5 | import how.hollow.consumer.api.generated.Actor; 6 | import how.hollow.consumer.api.generated.core.*; 7 | import how.hollow.consumer.api.generated.collections.*; 8 | 9 | import com.netflix.hollow.api.objects.HollowSet; 10 | import com.netflix.hollow.core.schema.HollowSetSchema; 11 | import com.netflix.hollow.api.objects.delegate.HollowSetDelegate; 12 | import com.netflix.hollow.api.objects.generic.GenericHollowRecordHelper; 13 | 14 | @SuppressWarnings("all") 15 | public class SetOfActor extends HollowSet { 16 | 17 | public SetOfActor(HollowSetDelegate delegate, int ordinal) { 18 | super(delegate, ordinal); 19 | } 20 | 21 | @Override 22 | public Actor instantiateElement(int ordinal) { 23 | return (Actor) api().getActor(ordinal); 24 | } 25 | 26 | @Override 27 | public boolean equalsElement(int elementOrdinal, Object testObject) { 28 | return GenericHollowRecordHelper.equalObject(getSchema().getElementType(), elementOrdinal, testObject); 29 | } 30 | 31 | public MovieAPI api() { 32 | return typeApi().getAPI(); 33 | } 34 | 35 | public SetOfActorTypeAPI typeApi() { 36 | return (SetOfActorTypeAPI) delegate.getTypeAPI(); 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/api/generated/core/ActorDelegate.java: -------------------------------------------------------------------------------- 1 | package how.hollow.consumer.api.generated.core; 2 | 3 | import com.netflix.hollow.core.type.*; 4 | import how.hollow.consumer.api.generated.core.*; 5 | import how.hollow.consumer.api.generated.collections.*; 6 | 7 | import com.netflix.hollow.api.objects.delegate.HollowObjectDelegate; 8 | 9 | 10 | @SuppressWarnings("all") 11 | public interface ActorDelegate extends HollowObjectDelegate { 12 | 13 | public int getActorId(int ordinal); 14 | 15 | public Integer getActorIdBoxed(int ordinal); 16 | 17 | public String getActorName(int ordinal); 18 | 19 | public boolean isActorNameEqual(int ordinal, String testValue); 20 | 21 | public int getActorNameOrdinal(int ordinal); 22 | 23 | public ActorTypeAPI getTypeAPI(); 24 | 25 | } -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/api/generated/core/ActorDelegateCachedImpl.java: -------------------------------------------------------------------------------- 1 | package how.hollow.consumer.api.generated.core; 2 | 3 | import com.netflix.hollow.core.type.*; 4 | import how.hollow.consumer.api.generated.core.*; 5 | import how.hollow.consumer.api.generated.collections.*; 6 | 7 | import com.netflix.hollow.api.objects.delegate.HollowObjectAbstractDelegate; 8 | import com.netflix.hollow.core.read.dataaccess.HollowObjectTypeDataAccess; 9 | import com.netflix.hollow.core.schema.HollowObjectSchema; 10 | import com.netflix.hollow.api.custom.HollowTypeAPI; 11 | import com.netflix.hollow.api.objects.delegate.HollowCachedDelegate; 12 | 13 | @SuppressWarnings("all") 14 | public class ActorDelegateCachedImpl extends HollowObjectAbstractDelegate implements HollowCachedDelegate, ActorDelegate { 15 | 16 | private final Integer actorId; 17 | private final String actorName; 18 | private final int actorNameOrdinal; 19 | private ActorTypeAPI typeAPI; 20 | 21 | public ActorDelegateCachedImpl(ActorTypeAPI typeAPI, int ordinal) { 22 | this.actorId = typeAPI.getActorIdBoxed(ordinal); 23 | this.actorNameOrdinal = typeAPI.getActorNameOrdinal(ordinal); 24 | int actorNameTempOrdinal = actorNameOrdinal; 25 | this.actorName = actorNameTempOrdinal == -1 ? null : typeAPI.getAPI().getStringTypeAPI().getValue(actorNameTempOrdinal); 26 | this.typeAPI = typeAPI; 27 | } 28 | 29 | public int getActorId(int ordinal) { 30 | if(actorId == null) 31 | return Integer.MIN_VALUE; 32 | return actorId.intValue(); 33 | } 34 | 35 | public Integer getActorIdBoxed(int ordinal) { 36 | return actorId; 37 | } 38 | 39 | public String getActorName(int ordinal) { 40 | return actorName; 41 | } 42 | 43 | public boolean isActorNameEqual(int ordinal, String testValue) { 44 | if(testValue == null) 45 | return actorName == null; 46 | return testValue.equals(actorName); 47 | } 48 | 49 | public int getActorNameOrdinal(int ordinal) { 50 | return actorNameOrdinal; 51 | } 52 | 53 | @Override 54 | public HollowObjectSchema getSchema() { 55 | return typeAPI.getTypeDataAccess().getSchema(); 56 | } 57 | 58 | @Override 59 | public HollowObjectTypeDataAccess getTypeDataAccess() { 60 | return typeAPI.getTypeDataAccess(); 61 | } 62 | 63 | public ActorTypeAPI getTypeAPI() { 64 | return typeAPI; 65 | } 66 | 67 | public void updateTypeAPI(HollowTypeAPI typeAPI) { 68 | this.typeAPI = (ActorTypeAPI) typeAPI; 69 | } 70 | 71 | } -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/api/generated/core/ActorDelegateLookupImpl.java: -------------------------------------------------------------------------------- 1 | package how.hollow.consumer.api.generated.core; 2 | 3 | import com.netflix.hollow.core.type.*; 4 | import how.hollow.consumer.api.generated.core.*; 5 | import how.hollow.consumer.api.generated.collections.*; 6 | 7 | import com.netflix.hollow.api.objects.delegate.HollowObjectAbstractDelegate; 8 | import com.netflix.hollow.core.read.dataaccess.HollowObjectTypeDataAccess; 9 | import com.netflix.hollow.core.schema.HollowObjectSchema; 10 | 11 | @SuppressWarnings("all") 12 | public class ActorDelegateLookupImpl extends HollowObjectAbstractDelegate implements ActorDelegate { 13 | 14 | private final ActorTypeAPI typeAPI; 15 | 16 | public ActorDelegateLookupImpl(ActorTypeAPI typeAPI) { 17 | this.typeAPI = typeAPI; 18 | } 19 | 20 | public int getActorId(int ordinal) { 21 | return typeAPI.getActorId(ordinal); 22 | } 23 | 24 | public Integer getActorIdBoxed(int ordinal) { 25 | return typeAPI.getActorIdBoxed(ordinal); 26 | } 27 | 28 | public String getActorName(int ordinal) { 29 | ordinal = typeAPI.getActorNameOrdinal(ordinal); 30 | return ordinal == -1 ? null : typeAPI.getAPI().getStringTypeAPI().getValue(ordinal); 31 | } 32 | 33 | public boolean isActorNameEqual(int ordinal, String testValue) { 34 | ordinal = typeAPI.getActorNameOrdinal(ordinal); 35 | return ordinal == -1 ? testValue == null : typeAPI.getAPI().getStringTypeAPI().isValueEqual(ordinal, testValue); 36 | } 37 | 38 | public int getActorNameOrdinal(int ordinal) { 39 | return typeAPI.getActorNameOrdinal(ordinal); 40 | } 41 | 42 | public ActorTypeAPI getTypeAPI() { 43 | return typeAPI; 44 | } 45 | 46 | @Override 47 | public HollowObjectSchema getSchema() { 48 | return typeAPI.getTypeDataAccess().getSchema(); 49 | } 50 | 51 | @Override 52 | public HollowObjectTypeDataAccess getTypeDataAccess() { 53 | return typeAPI.getTypeDataAccess(); 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/api/generated/core/ActorHollowFactory.java: -------------------------------------------------------------------------------- 1 | package how.hollow.consumer.api.generated.core; 2 | 3 | import com.netflix.hollow.core.type.*; 4 | import how.hollow.consumer.api.generated.Actor; 5 | import how.hollow.consumer.api.generated.core.*; 6 | import how.hollow.consumer.api.generated.collections.*; 7 | 8 | import com.netflix.hollow.api.objects.provider.HollowFactory; 9 | import com.netflix.hollow.core.read.dataaccess.HollowTypeDataAccess; 10 | import com.netflix.hollow.api.custom.HollowTypeAPI; 11 | 12 | @SuppressWarnings("all") 13 | public class ActorHollowFactory extends HollowFactory { 14 | 15 | @Override 16 | public T newHollowObject(HollowTypeDataAccess dataAccess, HollowTypeAPI typeAPI, int ordinal) { 17 | return (T)new Actor(((ActorTypeAPI)typeAPI).getDelegateLookupImpl(), ordinal); 18 | } 19 | 20 | @Override 21 | public T newCachedHollowObject(HollowTypeDataAccess dataAccess, HollowTypeAPI typeAPI, int ordinal) { 22 | return (T)new Actor(new ActorDelegateCachedImpl((ActorTypeAPI)typeAPI, ordinal), ordinal); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/api/generated/core/ActorTypeAPI.java: -------------------------------------------------------------------------------- 1 | package how.hollow.consumer.api.generated.core; 2 | 3 | import com.netflix.hollow.core.type.*; 4 | import how.hollow.consumer.api.generated.MovieAPI; 5 | import how.hollow.consumer.api.generated.core.*; 6 | import how.hollow.consumer.api.generated.collections.*; 7 | 8 | import com.netflix.hollow.api.custom.HollowObjectTypeAPI; 9 | import com.netflix.hollow.core.read.dataaccess.HollowObjectTypeDataAccess; 10 | 11 | @SuppressWarnings("all") 12 | public class ActorTypeAPI extends HollowObjectTypeAPI { 13 | 14 | private final ActorDelegateLookupImpl delegateLookupImpl; 15 | 16 | public ActorTypeAPI(MovieAPI api, HollowObjectTypeDataAccess typeDataAccess) { 17 | super(api, typeDataAccess, new String[] { 18 | "actorId", 19 | "actorName" 20 | }); 21 | this.delegateLookupImpl = new ActorDelegateLookupImpl(this); 22 | } 23 | 24 | public int getActorId(int ordinal) { 25 | if(fieldIndex[0] == -1) 26 | return missingDataHandler().handleInt("Actor", ordinal, "actorId"); 27 | return getTypeDataAccess().readInt(ordinal, fieldIndex[0]); 28 | } 29 | 30 | public Integer getActorIdBoxed(int ordinal) { 31 | int i; 32 | if(fieldIndex[0] == -1) { 33 | i = missingDataHandler().handleInt("Actor", ordinal, "actorId"); 34 | } else { 35 | boxedFieldAccessSampler.recordFieldAccess(fieldIndex[0]); 36 | i = getTypeDataAccess().readInt(ordinal, fieldIndex[0]); 37 | } 38 | if(i == Integer.MIN_VALUE) 39 | return null; 40 | return Integer.valueOf(i); 41 | } 42 | 43 | 44 | 45 | public int getActorNameOrdinal(int ordinal) { 46 | if(fieldIndex[1] == -1) 47 | return missingDataHandler().handleReferencedOrdinal("Actor", ordinal, "actorName"); 48 | return getTypeDataAccess().readOrdinal(ordinal, fieldIndex[1]); 49 | } 50 | 51 | public StringTypeAPI getActorNameTypeAPI() { 52 | return getAPI().getStringTypeAPI(); 53 | } 54 | 55 | public ActorDelegateLookupImpl getDelegateLookupImpl() { 56 | return delegateLookupImpl; 57 | } 58 | 59 | @Override 60 | public MovieAPI getAPI() { 61 | return (MovieAPI) api; 62 | } 63 | 64 | } -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/api/generated/core/MovieAPIFactory.java: -------------------------------------------------------------------------------- 1 | package how.hollow.consumer.api.generated.core; 2 | 3 | import com.netflix.hollow.core.type.*; 4 | import how.hollow.consumer.api.generated.MovieAPI; 5 | import how.hollow.consumer.api.generated.core.*; 6 | import how.hollow.consumer.api.generated.collections.*; 7 | 8 | import com.netflix.hollow.api.client.HollowAPIFactory; 9 | import com.netflix.hollow.api.custom.HollowAPI; 10 | import com.netflix.hollow.api.objects.provider.HollowFactory; 11 | import com.netflix.hollow.core.read.dataaccess.HollowDataAccess; 12 | import java.util.Collections; 13 | import java.util.Set; 14 | 15 | @SuppressWarnings("all") 16 | public class MovieAPIFactory implements HollowAPIFactory { 17 | 18 | private final Set cachedTypes; 19 | 20 | public MovieAPIFactory() { 21 | this(Collections.emptySet()); 22 | } 23 | 24 | public MovieAPIFactory(Set cachedTypes) { 25 | this.cachedTypes = cachedTypes; 26 | } 27 | 28 | @Override 29 | public HollowAPI createAPI(HollowDataAccess dataAccess) { 30 | return new MovieAPI(dataAccess, cachedTypes); 31 | } 32 | 33 | @Override 34 | public HollowAPI createAPI(HollowDataAccess dataAccess, HollowAPI previousCycleAPI) { 35 | if (!(previousCycleAPI instanceof MovieAPI)) { 36 | throw new ClassCastException(previousCycleAPI.getClass() + " not instance of MovieAPI"); } 37 | return new MovieAPI(dataAccess, cachedTypes, Collections.>emptyMap(), (MovieAPI) previousCycleAPI); 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/api/generated/core/MovieDelegate.java: -------------------------------------------------------------------------------- 1 | package how.hollow.consumer.api.generated.core; 2 | 3 | import com.netflix.hollow.core.type.*; 4 | import how.hollow.consumer.api.generated.core.*; 5 | import how.hollow.consumer.api.generated.collections.*; 6 | 7 | import com.netflix.hollow.api.objects.delegate.HollowObjectDelegate; 8 | 9 | 10 | @SuppressWarnings("all") 11 | public interface MovieDelegate extends HollowObjectDelegate { 12 | 13 | public int getId(int ordinal); 14 | 15 | public Integer getIdBoxed(int ordinal); 16 | 17 | public String getTitle(int ordinal); 18 | 19 | public boolean isTitleEqual(int ordinal, String testValue); 20 | 21 | public int getTitleOrdinal(int ordinal); 22 | 23 | public int getActorsOrdinal(int ordinal); 24 | 25 | public MovieTypeAPI getTypeAPI(); 26 | 27 | } -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/api/generated/core/MovieDelegateCachedImpl.java: -------------------------------------------------------------------------------- 1 | package how.hollow.consumer.api.generated.core; 2 | 3 | import com.netflix.hollow.core.type.*; 4 | import how.hollow.consumer.api.generated.core.*; 5 | import how.hollow.consumer.api.generated.collections.*; 6 | 7 | import com.netflix.hollow.api.objects.delegate.HollowObjectAbstractDelegate; 8 | import com.netflix.hollow.core.read.dataaccess.HollowObjectTypeDataAccess; 9 | import com.netflix.hollow.core.schema.HollowObjectSchema; 10 | import com.netflix.hollow.api.custom.HollowTypeAPI; 11 | import com.netflix.hollow.api.objects.delegate.HollowCachedDelegate; 12 | 13 | @SuppressWarnings("all") 14 | public class MovieDelegateCachedImpl extends HollowObjectAbstractDelegate implements HollowCachedDelegate, MovieDelegate { 15 | 16 | private final Integer id; 17 | private final String title; 18 | private final int titleOrdinal; 19 | private final int actorsOrdinal; 20 | private MovieTypeAPI typeAPI; 21 | 22 | public MovieDelegateCachedImpl(MovieTypeAPI typeAPI, int ordinal) { 23 | this.id = typeAPI.getIdBoxed(ordinal); 24 | this.titleOrdinal = typeAPI.getTitleOrdinal(ordinal); 25 | int titleTempOrdinal = titleOrdinal; 26 | this.title = titleTempOrdinal == -1 ? null : typeAPI.getAPI().getStringTypeAPI().getValue(titleTempOrdinal); 27 | this.actorsOrdinal = typeAPI.getActorsOrdinal(ordinal); 28 | this.typeAPI = typeAPI; 29 | } 30 | 31 | public int getId(int ordinal) { 32 | if(id == null) 33 | return Integer.MIN_VALUE; 34 | return id.intValue(); 35 | } 36 | 37 | public Integer getIdBoxed(int ordinal) { 38 | return id; 39 | } 40 | 41 | public String getTitle(int ordinal) { 42 | return title; 43 | } 44 | 45 | public boolean isTitleEqual(int ordinal, String testValue) { 46 | if(testValue == null) 47 | return title == null; 48 | return testValue.equals(title); 49 | } 50 | 51 | public int getTitleOrdinal(int ordinal) { 52 | return titleOrdinal; 53 | } 54 | 55 | public int getActorsOrdinal(int ordinal) { 56 | return actorsOrdinal; 57 | } 58 | 59 | @Override 60 | public HollowObjectSchema getSchema() { 61 | return typeAPI.getTypeDataAccess().getSchema(); 62 | } 63 | 64 | @Override 65 | public HollowObjectTypeDataAccess getTypeDataAccess() { 66 | return typeAPI.getTypeDataAccess(); 67 | } 68 | 69 | public MovieTypeAPI getTypeAPI() { 70 | return typeAPI; 71 | } 72 | 73 | public void updateTypeAPI(HollowTypeAPI typeAPI) { 74 | this.typeAPI = (MovieTypeAPI) typeAPI; 75 | } 76 | 77 | } -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/api/generated/core/MovieDelegateLookupImpl.java: -------------------------------------------------------------------------------- 1 | package how.hollow.consumer.api.generated.core; 2 | 3 | import com.netflix.hollow.core.type.*; 4 | import how.hollow.consumer.api.generated.core.*; 5 | import how.hollow.consumer.api.generated.collections.*; 6 | 7 | import com.netflix.hollow.api.objects.delegate.HollowObjectAbstractDelegate; 8 | import com.netflix.hollow.core.read.dataaccess.HollowObjectTypeDataAccess; 9 | import com.netflix.hollow.core.schema.HollowObjectSchema; 10 | 11 | @SuppressWarnings("all") 12 | public class MovieDelegateLookupImpl extends HollowObjectAbstractDelegate implements MovieDelegate { 13 | 14 | private final MovieTypeAPI typeAPI; 15 | 16 | public MovieDelegateLookupImpl(MovieTypeAPI typeAPI) { 17 | this.typeAPI = typeAPI; 18 | } 19 | 20 | public int getId(int ordinal) { 21 | return typeAPI.getId(ordinal); 22 | } 23 | 24 | public Integer getIdBoxed(int ordinal) { 25 | return typeAPI.getIdBoxed(ordinal); 26 | } 27 | 28 | public String getTitle(int ordinal) { 29 | ordinal = typeAPI.getTitleOrdinal(ordinal); 30 | return ordinal == -1 ? null : typeAPI.getAPI().getStringTypeAPI().getValue(ordinal); 31 | } 32 | 33 | public boolean isTitleEqual(int ordinal, String testValue) { 34 | ordinal = typeAPI.getTitleOrdinal(ordinal); 35 | return ordinal == -1 ? testValue == null : typeAPI.getAPI().getStringTypeAPI().isValueEqual(ordinal, testValue); 36 | } 37 | 38 | public int getTitleOrdinal(int ordinal) { 39 | return typeAPI.getTitleOrdinal(ordinal); 40 | } 41 | 42 | public int getActorsOrdinal(int ordinal) { 43 | return typeAPI.getActorsOrdinal(ordinal); 44 | } 45 | 46 | public MovieTypeAPI getTypeAPI() { 47 | return typeAPI; 48 | } 49 | 50 | @Override 51 | public HollowObjectSchema getSchema() { 52 | return typeAPI.getTypeDataAccess().getSchema(); 53 | } 54 | 55 | @Override 56 | public HollowObjectTypeDataAccess getTypeDataAccess() { 57 | return typeAPI.getTypeDataAccess(); 58 | } 59 | 60 | } -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/api/generated/core/MovieHollowFactory.java: -------------------------------------------------------------------------------- 1 | package how.hollow.consumer.api.generated.core; 2 | 3 | import com.netflix.hollow.core.type.*; 4 | import how.hollow.consumer.api.generated.Movie; 5 | import how.hollow.consumer.api.generated.core.*; 6 | import how.hollow.consumer.api.generated.collections.*; 7 | 8 | import com.netflix.hollow.api.objects.provider.HollowFactory; 9 | import com.netflix.hollow.core.read.dataaccess.HollowTypeDataAccess; 10 | import com.netflix.hollow.api.custom.HollowTypeAPI; 11 | 12 | @SuppressWarnings("all") 13 | public class MovieHollowFactory extends HollowFactory { 14 | 15 | @Override 16 | public T newHollowObject(HollowTypeDataAccess dataAccess, HollowTypeAPI typeAPI, int ordinal) { 17 | return (T)new Movie(((MovieTypeAPI)typeAPI).getDelegateLookupImpl(), ordinal); 18 | } 19 | 20 | @Override 21 | public T newCachedHollowObject(HollowTypeDataAccess dataAccess, HollowTypeAPI typeAPI, int ordinal) { 22 | return (T)new Movie(new MovieDelegateCachedImpl((MovieTypeAPI)typeAPI, ordinal), ordinal); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/api/generated/core/MovieTypeAPI.java: -------------------------------------------------------------------------------- 1 | package how.hollow.consumer.api.generated.core; 2 | 3 | import com.netflix.hollow.core.type.*; 4 | import how.hollow.consumer.api.generated.MovieAPI; 5 | import how.hollow.consumer.api.generated.core.*; 6 | import how.hollow.consumer.api.generated.collections.*; 7 | 8 | import com.netflix.hollow.api.custom.HollowObjectTypeAPI; 9 | import com.netflix.hollow.core.read.dataaccess.HollowObjectTypeDataAccess; 10 | 11 | @SuppressWarnings("all") 12 | public class MovieTypeAPI extends HollowObjectTypeAPI { 13 | 14 | private final MovieDelegateLookupImpl delegateLookupImpl; 15 | 16 | public MovieTypeAPI(MovieAPI api, HollowObjectTypeDataAccess typeDataAccess) { 17 | super(api, typeDataAccess, new String[] { 18 | "id", 19 | "title", 20 | "actors" 21 | }); 22 | this.delegateLookupImpl = new MovieDelegateLookupImpl(this); 23 | } 24 | 25 | public int getId(int ordinal) { 26 | if(fieldIndex[0] == -1) 27 | return missingDataHandler().handleInt("Movie", ordinal, "id"); 28 | return getTypeDataAccess().readInt(ordinal, fieldIndex[0]); 29 | } 30 | 31 | public Integer getIdBoxed(int ordinal) { 32 | int i; 33 | if(fieldIndex[0] == -1) { 34 | i = missingDataHandler().handleInt("Movie", ordinal, "id"); 35 | } else { 36 | boxedFieldAccessSampler.recordFieldAccess(fieldIndex[0]); 37 | i = getTypeDataAccess().readInt(ordinal, fieldIndex[0]); 38 | } 39 | if(i == Integer.MIN_VALUE) 40 | return null; 41 | return Integer.valueOf(i); 42 | } 43 | 44 | 45 | 46 | public int getTitleOrdinal(int ordinal) { 47 | if(fieldIndex[1] == -1) 48 | return missingDataHandler().handleReferencedOrdinal("Movie", ordinal, "title"); 49 | return getTypeDataAccess().readOrdinal(ordinal, fieldIndex[1]); 50 | } 51 | 52 | public StringTypeAPI getTitleTypeAPI() { 53 | return getAPI().getStringTypeAPI(); 54 | } 55 | 56 | public int getActorsOrdinal(int ordinal) { 57 | if(fieldIndex[2] == -1) 58 | return missingDataHandler().handleReferencedOrdinal("Movie", ordinal, "actors"); 59 | return getTypeDataAccess().readOrdinal(ordinal, fieldIndex[2]); 60 | } 61 | 62 | public SetOfActorTypeAPI getActorsTypeAPI() { 63 | return getAPI().getSetOfActorTypeAPI(); 64 | } 65 | 66 | public MovieDelegateLookupImpl getDelegateLookupImpl() { 67 | return delegateLookupImpl; 68 | } 69 | 70 | @Override 71 | public MovieAPI getAPI() { 72 | return (MovieAPI) api; 73 | } 74 | 75 | } -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/api/generated/core/SetOfActorHollowFactory.java: -------------------------------------------------------------------------------- 1 | package how.hollow.consumer.api.generated.core; 2 | 3 | import com.netflix.hollow.core.type.*; 4 | import how.hollow.consumer.api.generated.Actor; 5 | import how.hollow.consumer.api.generated.core.*; 6 | import how.hollow.consumer.api.generated.collections.*; 7 | 8 | import com.netflix.hollow.api.objects.provider.HollowFactory; 9 | import com.netflix.hollow.core.read.dataaccess.HollowTypeDataAccess; 10 | import com.netflix.hollow.api.custom.HollowTypeAPI; 11 | import com.netflix.hollow.api.objects.delegate.HollowSetCachedDelegate; 12 | 13 | @SuppressWarnings("all") 14 | public class SetOfActorHollowFactory extends HollowFactory { 15 | 16 | @Override 17 | public T newHollowObject(HollowTypeDataAccess dataAccess, HollowTypeAPI typeAPI, int ordinal) { 18 | return (T)new SetOfActor(((SetOfActorTypeAPI)typeAPI).getDelegateLookupImpl(), ordinal); 19 | } 20 | 21 | @Override 22 | public T newCachedHollowObject(HollowTypeDataAccess dataAccess, HollowTypeAPI typeAPI, int ordinal) { 23 | return (T)new SetOfActor(new HollowSetCachedDelegate((SetOfActorTypeAPI)typeAPI, ordinal), ordinal); 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/api/generated/core/SetOfActorTypeAPI.java: -------------------------------------------------------------------------------- 1 | package how.hollow.consumer.api.generated.core; 2 | 3 | import com.netflix.hollow.core.type.*; 4 | import how.hollow.consumer.api.generated.MovieAPI; 5 | import how.hollow.consumer.api.generated.core.*; 6 | import how.hollow.consumer.api.generated.collections.*; 7 | 8 | import com.netflix.hollow.api.custom.HollowSetTypeAPI; 9 | 10 | import com.netflix.hollow.core.read.dataaccess.HollowSetTypeDataAccess; 11 | import com.netflix.hollow.api.objects.delegate.HollowSetLookupDelegate; 12 | 13 | @SuppressWarnings("all") 14 | public class SetOfActorTypeAPI extends HollowSetTypeAPI { 15 | 16 | private final HollowSetLookupDelegate delegateLookupImpl; 17 | 18 | public SetOfActorTypeAPI(MovieAPI api, HollowSetTypeDataAccess dataAccess) { 19 | super(api, dataAccess); 20 | this.delegateLookupImpl = new HollowSetLookupDelegate(this); 21 | } 22 | 23 | public ActorTypeAPI getElementAPI() { 24 | return getAPI().getActorTypeAPI(); 25 | } 26 | 27 | public MovieAPI getAPI() { 28 | return (MovieAPI)api; 29 | } 30 | 31 | public HollowSetLookupDelegate getDelegateLookupImpl() { 32 | return delegateLookupImpl; 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/api/generated/index/ActorPrimaryKeyIndex.java: -------------------------------------------------------------------------------- 1 | package how.hollow.consumer.api.generated.index; 2 | 3 | import com.netflix.hollow.core.type.*; 4 | import how.hollow.consumer.api.generated.MovieAPI; 5 | import how.hollow.consumer.api.generated.Actor; 6 | import how.hollow.consumer.api.generated.core.*; 7 | import how.hollow.consumer.api.generated.collections.*; 8 | 9 | import com.netflix.hollow.api.consumer.HollowConsumer; 10 | import com.netflix.hollow.api.consumer.index.AbstractHollowUniqueKeyIndex; 11 | import com.netflix.hollow.api.consumer.index.HollowUniqueKeyIndex; 12 | import com.netflix.hollow.core.schema.HollowObjectSchema; 13 | 14 | /** 15 | * @deprecated see {@link com.netflix.hollow.api.consumer.index.UniqueKeyIndex} which can be created as follows: 16 | *

{@code
17 |  *     UniqueKeyIndex uki = Actor.uniqueIndex(consumer);
18 |  *     int k = ...;
19 |  *     Actor m = uki.findMatch(k);
20 |  * }
21 | * @see Actor#uniqueIndex 22 | */ 23 | @Deprecated 24 | @SuppressWarnings("all") 25 | public class ActorPrimaryKeyIndex extends AbstractHollowUniqueKeyIndex { 26 | 27 | public ActorPrimaryKeyIndex(HollowConsumer consumer) { 28 | this(consumer, false); 29 | } 30 | 31 | public ActorPrimaryKeyIndex(HollowConsumer consumer, boolean isListenToDataRefresh) { 32 | this(consumer, isListenToDataRefresh, ((HollowObjectSchema)consumer.getStateEngine().getNonNullSchema("Actor")).getPrimaryKey().getFieldPaths()); 33 | } 34 | 35 | private ActorPrimaryKeyIndex(HollowConsumer consumer, String... fieldPaths) { 36 | this(consumer, false, fieldPaths); 37 | } 38 | 39 | private ActorPrimaryKeyIndex(HollowConsumer consumer, boolean isListenToDataRefresh, String... fieldPaths) { 40 | super(consumer, "Actor", isListenToDataRefresh, fieldPaths); 41 | } 42 | 43 | public Actor findMatch(int actorId) { 44 | int ordinal = idx.getMatchingOrdinal(actorId); 45 | if(ordinal == -1) 46 | return null; 47 | return api.getActor(ordinal); 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/api/generated/index/ActorUniqueKeyIndex.java: -------------------------------------------------------------------------------- 1 | package how.hollow.consumer.api.generated.index; 2 | 3 | import com.netflix.hollow.core.type.*; 4 | import how.hollow.consumer.api.generated.MovieAPI; 5 | import how.hollow.consumer.api.generated.Actor; 6 | import how.hollow.consumer.api.generated.core.*; 7 | import how.hollow.consumer.api.generated.collections.*; 8 | 9 | import com.netflix.hollow.api.consumer.HollowConsumer; 10 | import com.netflix.hollow.api.consumer.index.AbstractHollowUniqueKeyIndex; 11 | import com.netflix.hollow.api.consumer.index.HollowUniqueKeyIndex; 12 | 13 | /** 14 | * @deprecated see {@link com.netflix.hollow.api.consumer.index.UniqueKeyIndex} which can be built as follows: 15 | *
{@code
16 |  *     UniqueKeyIndex uki = UniqueKeyIndex.from(consumer, Actor.class)
17 |  *         .usingBean(k);
18 |  *     Actor m = uki.findMatch(k);
19 |  * }
20 | * where {@code K} is a class declaring key field paths members, annotated with 21 | * {@link com.netflix.hollow.api.consumer.index.FieldPath}, and {@code k} is an instance of 22 | * {@code K} that is the key to find the unique {@code Actor} object. 23 | */ 24 | @Deprecated 25 | @SuppressWarnings("all") 26 | public class ActorUniqueKeyIndex extends AbstractHollowUniqueKeyIndex implements HollowUniqueKeyIndex { 27 | 28 | public ActorUniqueKeyIndex(HollowConsumer consumer, String... fieldPaths) { 29 | this(consumer, false, fieldPaths); 30 | } 31 | 32 | public ActorUniqueKeyIndex(HollowConsumer consumer, boolean isListenToDataRefresh, String... fieldPaths) { 33 | super(consumer, "Actor", isListenToDataRefresh, fieldPaths); 34 | } 35 | 36 | @Override 37 | public Actor findMatch(Object... keys) { 38 | int ordinal = idx.getMatchingOrdinal(keys); 39 | if(ordinal == -1) 40 | return null; 41 | return api.getActor(ordinal); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/api/generated/index/MovieAPIHashIndex.java: -------------------------------------------------------------------------------- 1 | package how.hollow.consumer.api.generated.index; 2 | 3 | import com.netflix.hollow.core.type.*; 4 | import how.hollow.consumer.api.generated.MovieAPI; 5 | import how.hollow.consumer.api.generated.Movie; 6 | import how.hollow.consumer.api.generated.Actor; 7 | import how.hollow.consumer.api.generated.core.*; 8 | import how.hollow.consumer.api.generated.collections.*; 9 | 10 | import com.netflix.hollow.api.consumer.HollowConsumer; 11 | import com.netflix.hollow.core.index.HollowHashIndexResult; 12 | import java.util.Collections; 13 | import java.lang.Iterable; 14 | import com.netflix.hollow.api.consumer.index.AbstractHollowHashIndex; 15 | import com.netflix.hollow.api.consumer.data.AbstractHollowOrdinalIterable; 16 | 17 | 18 | /** 19 | * @deprecated see {@link com.netflix.hollow.api.consumer.index.HashIndex} which can be built as follows: 20 | *
{@code
21 |  *     HashIndex uki = HashIndex.from(consumer, HString.class)
22 |  *         .usingBean(k);
23 |  *     Stream results = uki.findMatches(k);
24 |  * }
25 | * where {@code K} is a class declaring key field paths members, annotated with 26 | * {@link com.netflix.hollow.api.consumer.index.FieldPath}, and {@code k} is an instance of 27 | * {@code K} that is the query to find the matching {@code HString} objects. 28 | */ 29 | @Deprecated 30 | @SuppressWarnings("all") 31 | public class MovieAPIHashIndex extends AbstractHollowHashIndex { 32 | 33 | public MovieAPIHashIndex(HollowConsumer consumer, String queryType, String selectFieldPath, String... matchFieldPaths) { 34 | super(consumer, false, queryType, selectFieldPath, matchFieldPaths); 35 | } 36 | 37 | public MovieAPIHashIndex(HollowConsumer consumer, boolean isListenToDataRefresh, String queryType, String selectFieldPath, String... matchFieldPaths) { 38 | super(consumer, isListenToDataRefresh, queryType, selectFieldPath, matchFieldPaths); 39 | } 40 | 41 | public Iterable findStringMatches(Object... keys) { 42 | HollowHashIndexResult matches = idx.findMatches(keys); 43 | if(matches == null) return Collections.emptySet(); 44 | 45 | return new AbstractHollowOrdinalIterable(matches.iterator()) { 46 | public HString getData(int ordinal) { 47 | return api.getHString(ordinal); 48 | } 49 | }; 50 | } 51 | 52 | public Iterable findActorMatches(Object... keys) { 53 | HollowHashIndexResult matches = idx.findMatches(keys); 54 | if(matches == null) return Collections.emptySet(); 55 | 56 | return new AbstractHollowOrdinalIterable(matches.iterator()) { 57 | public Actor getData(int ordinal) { 58 | return api.getActor(ordinal); 59 | } 60 | }; 61 | } 62 | 63 | public Iterable findSetOfActorMatches(Object... keys) { 64 | HollowHashIndexResult matches = idx.findMatches(keys); 65 | if(matches == null) return Collections.emptySet(); 66 | 67 | return new AbstractHollowOrdinalIterable(matches.iterator()) { 68 | public SetOfActor getData(int ordinal) { 69 | return api.getSetOfActor(ordinal); 70 | } 71 | }; 72 | } 73 | 74 | public Iterable findMovieMatches(Object... keys) { 75 | HollowHashIndexResult matches = idx.findMatches(keys); 76 | if(matches == null) return Collections.emptySet(); 77 | 78 | return new AbstractHollowOrdinalIterable(matches.iterator()) { 79 | public Movie getData(int ordinal) { 80 | return api.getMovie(ordinal); 81 | } 82 | }; 83 | } 84 | 85 | } -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/api/generated/index/MoviePrimaryKeyIndex.java: -------------------------------------------------------------------------------- 1 | package how.hollow.consumer.api.generated.index; 2 | 3 | import com.netflix.hollow.core.type.*; 4 | import how.hollow.consumer.api.generated.MovieAPI; 5 | import how.hollow.consumer.api.generated.Movie; 6 | import how.hollow.consumer.api.generated.core.*; 7 | import how.hollow.consumer.api.generated.collections.*; 8 | 9 | import com.netflix.hollow.api.consumer.HollowConsumer; 10 | import com.netflix.hollow.api.consumer.index.AbstractHollowUniqueKeyIndex; 11 | import com.netflix.hollow.api.consumer.index.HollowUniqueKeyIndex; 12 | import com.netflix.hollow.core.schema.HollowObjectSchema; 13 | 14 | /** 15 | * @deprecated see {@link com.netflix.hollow.api.consumer.index.UniqueKeyIndex} which can be created as follows: 16 | *
{@code
17 |  *     UniqueKeyIndex uki = Movie.uniqueIndex(consumer);
18 |  *     int k = ...;
19 |  *     Movie m = uki.findMatch(k);
20 |  * }
21 | * @see Movie#uniqueIndex 22 | */ 23 | @Deprecated 24 | @SuppressWarnings("all") 25 | public class MoviePrimaryKeyIndex extends AbstractHollowUniqueKeyIndex { 26 | 27 | public MoviePrimaryKeyIndex(HollowConsumer consumer) { 28 | this(consumer, false); 29 | } 30 | 31 | public MoviePrimaryKeyIndex(HollowConsumer consumer, boolean isListenToDataRefresh) { 32 | this(consumer, isListenToDataRefresh, ((HollowObjectSchema)consumer.getStateEngine().getNonNullSchema("Movie")).getPrimaryKey().getFieldPaths()); 33 | } 34 | 35 | private MoviePrimaryKeyIndex(HollowConsumer consumer, String... fieldPaths) { 36 | this(consumer, false, fieldPaths); 37 | } 38 | 39 | private MoviePrimaryKeyIndex(HollowConsumer consumer, boolean isListenToDataRefresh, String... fieldPaths) { 40 | super(consumer, "Movie", isListenToDataRefresh, fieldPaths); 41 | } 42 | 43 | public Movie findMatch(int id) { 44 | int ordinal = idx.getMatchingOrdinal(id); 45 | if(ordinal == -1) 46 | return null; 47 | return api.getMovie(ordinal); 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/api/generated/index/MovieUniqueKeyIndex.java: -------------------------------------------------------------------------------- 1 | package how.hollow.consumer.api.generated.index; 2 | 3 | import com.netflix.hollow.core.type.*; 4 | import how.hollow.consumer.api.generated.MovieAPI; 5 | import how.hollow.consumer.api.generated.Movie; 6 | import how.hollow.consumer.api.generated.core.*; 7 | import how.hollow.consumer.api.generated.collections.*; 8 | 9 | import com.netflix.hollow.api.consumer.HollowConsumer; 10 | import com.netflix.hollow.api.consumer.index.AbstractHollowUniqueKeyIndex; 11 | import com.netflix.hollow.api.consumer.index.HollowUniqueKeyIndex; 12 | 13 | /** 14 | * @deprecated see {@link com.netflix.hollow.api.consumer.index.UniqueKeyIndex} which can be built as follows: 15 | *
{@code
16 |  *     UniqueKeyIndex uki = UniqueKeyIndex.from(consumer, Movie.class)
17 |  *         .usingBean(k);
18 |  *     Movie m = uki.findMatch(k);
19 |  * }
20 | * where {@code K} is a class declaring key field paths members, annotated with 21 | * {@link com.netflix.hollow.api.consumer.index.FieldPath}, and {@code k} is an instance of 22 | * {@code K} that is the key to find the unique {@code Movie} object. 23 | */ 24 | @Deprecated 25 | @SuppressWarnings("all") 26 | public class MovieUniqueKeyIndex extends AbstractHollowUniqueKeyIndex implements HollowUniqueKeyIndex { 27 | 28 | public MovieUniqueKeyIndex(HollowConsumer consumer, String... fieldPaths) { 29 | this(consumer, false, fieldPaths); 30 | } 31 | 32 | public MovieUniqueKeyIndex(HollowConsumer consumer, boolean isListenToDataRefresh, String... fieldPaths) { 33 | super(consumer, "Movie", isListenToDataRefresh, fieldPaths); 34 | } 35 | 36 | @Override 37 | public Movie findMatch(Object... keys) { 38 | int ordinal = idx.getMatchingOrdinal(keys); 39 | if(ordinal == -1) 40 | return null; 41 | return api.getMovie(ordinal); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/infrastructure/DynamoDBAnnouncementWatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2016 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * 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, 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 | package how.hollow.consumer.infrastructure; 19 | 20 | import com.amazonaws.auth.AWSCredentials; 21 | import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; 22 | import com.amazonaws.services.dynamodbv2.document.DynamoDB; 23 | import com.amazonaws.services.dynamodbv2.document.Item; 24 | import com.amazonaws.services.dynamodbv2.document.Table; 25 | import com.netflix.hollow.api.consumer.HollowConsumer; 26 | import com.netflix.hollow.api.consumer.HollowConsumer.AnnouncementWatcher; 27 | import java.util.ArrayList; 28 | import java.util.Collections; 29 | import java.util.List; 30 | 31 | public class DynamoDBAnnouncementWatcher implements AnnouncementWatcher { 32 | 33 | private final DynamoDB dynamoDB; 34 | private final String tableName; 35 | private final String blobNamespace; 36 | 37 | private final List subscribedConsumers; 38 | 39 | private long latestVersion; 40 | 41 | public DynamoDBAnnouncementWatcher(AWSCredentials credentials, String tableName, String blobNamespace) { 42 | this.dynamoDB = new DynamoDB(new AmazonDynamoDBClient(credentials)); 43 | this.tableName = tableName; 44 | this.blobNamespace = blobNamespace; 45 | this.subscribedConsumers = Collections.synchronizedList(new ArrayList()); 46 | 47 | this.latestVersion = readLatestVersion(); 48 | 49 | setupPollingThread(); 50 | } 51 | 52 | public void setupPollingThread() { 53 | Thread t = new Thread(new Runnable() { 54 | public void run() { 55 | while (true) { 56 | try { 57 | long currentVersion = readLatestVersion(); 58 | if (latestVersion != currentVersion) { 59 | latestVersion = currentVersion; 60 | for(HollowConsumer consumer : subscribedConsumers) 61 | consumer.triggerAsyncRefresh(); 62 | } 63 | 64 | Thread.sleep(1000); 65 | } catch (Throwable th) { 66 | th.printStackTrace(); 67 | } 68 | } 69 | } 70 | }); 71 | 72 | t.setName("hollow-dynamodb-announcementwatcher-poller"); 73 | t.setDaemon(true); 74 | t.start(); 75 | } 76 | 77 | @Override 78 | public long getLatestVersion() { 79 | return latestVersion; 80 | } 81 | 82 | @Override 83 | public void subscribeToUpdates(HollowConsumer consumer) { 84 | subscribedConsumers.add(consumer); 85 | } 86 | 87 | public long readLatestVersion() { 88 | Table table = dynamoDB.getTable(tableName); 89 | 90 | Item item = table.getItem("namespace", blobNamespace, 91 | "version, pin_version", null); 92 | 93 | if (item.isPresent("pin_version") && !item.isNull("pin_version")) 94 | return item.getLong("pin_version"); 95 | 96 | return item.getLong("version"); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/infrastructure/S3AnnouncementWatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2016 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * 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, 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 | package how.hollow.consumer.infrastructure; 19 | 20 | import com.amazonaws.auth.AWSCredentials; 21 | import com.amazonaws.services.s3.AmazonS3; 22 | import com.amazonaws.services.s3.AmazonS3Client; 23 | import com.netflix.hollow.api.consumer.HollowConsumer; 24 | import com.netflix.hollow.api.consumer.HollowConsumer.AnnouncementWatcher; 25 | import how.hollow.producer.infrastructure.S3Announcer; 26 | import java.util.ArrayList; 27 | import java.util.Collections; 28 | import java.util.List; 29 | 30 | public class S3AnnouncementWatcher implements AnnouncementWatcher { 31 | 32 | private final AmazonS3 s3; 33 | private final String bucketName; 34 | private final String blobNamespace; 35 | 36 | private final List subscribedConsumers; 37 | 38 | private long latestVersion; 39 | 40 | 41 | public S3AnnouncementWatcher(AWSCredentials credentials, String bucketName, String blobNamespace) { 42 | this.s3 = new AmazonS3Client(credentials); 43 | this.bucketName = bucketName; 44 | this.blobNamespace = blobNamespace; 45 | this.subscribedConsumers = Collections.synchronizedList(new ArrayList()); 46 | 47 | this.latestVersion = readLatestVersion(); 48 | 49 | setupPollingThread(); 50 | } 51 | 52 | public void setupPollingThread() { 53 | Thread t = new Thread(new Runnable() { 54 | public void run() { 55 | while(true) { 56 | try { 57 | long currentVersion = readLatestVersion(); 58 | if(latestVersion != currentVersion) { 59 | latestVersion = currentVersion; 60 | for(HollowConsumer consumer : subscribedConsumers) 61 | consumer.triggerAsyncRefresh(); 62 | } 63 | 64 | Thread.sleep(1000); 65 | } catch(Throwable th) { 66 | th.printStackTrace(); 67 | } 68 | } 69 | } 70 | }); 71 | 72 | t.setName("hollow-s3-announcementwatcher-poller"); 73 | t.setDaemon(true); 74 | t.start(); 75 | } 76 | 77 | @Override 78 | public long getLatestVersion() { 79 | return latestVersion; 80 | } 81 | 82 | @Override 83 | public void subscribeToUpdates(HollowConsumer consumer) { 84 | subscribedConsumers.add(consumer); 85 | } 86 | 87 | 88 | private long readLatestVersion() { 89 | return Long.parseLong(s3.getObjectAsString(bucketName, blobNamespace + "/" + S3Announcer.ANNOUNCEMENT_OBJECTNAME)); 90 | } 91 | 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/how/hollow/consumer/infrastructure/S3BlobRetriever.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2016 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * 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, 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 | package how.hollow.consumer.infrastructure; 19 | 20 | import com.amazonaws.SdkBaseException; 21 | import com.amazonaws.auth.AWSCredentials; 22 | import com.amazonaws.services.s3.AmazonS3; 23 | import com.amazonaws.services.s3.AmazonS3Client; 24 | import com.amazonaws.services.s3.model.AmazonS3Exception; 25 | import com.amazonaws.services.s3.model.ObjectMetadata; 26 | import com.amazonaws.services.s3.transfer.Download; 27 | import com.amazonaws.services.s3.transfer.TransferManager; 28 | import com.netflix.hollow.api.consumer.HollowConsumer.Blob; 29 | import com.netflix.hollow.api.consumer.HollowConsumer.BlobRetriever; 30 | import com.netflix.hollow.core.memory.encoding.VarInt; 31 | import how.hollow.producer.infrastructure.S3Publisher; 32 | import java.io.BufferedInputStream; 33 | import java.io.File; 34 | import java.io.FileInputStream; 35 | import java.io.IOException; 36 | import java.io.InputStream; 37 | 38 | public class S3BlobRetriever implements BlobRetriever { 39 | 40 | private final AmazonS3 s3; 41 | private final TransferManager s3TransferManager; 42 | private final String bucketName; 43 | private final String blobNamespace; 44 | 45 | public S3BlobRetriever(AWSCredentials credentials, String bucketName, String blobNamespace) { 46 | this.s3 = new AmazonS3Client(credentials); 47 | this.s3TransferManager = new TransferManager(s3); 48 | this.bucketName = bucketName; 49 | this.blobNamespace = blobNamespace; 50 | } 51 | 52 | @Override 53 | public Blob retrieveSnapshotBlob(long desiredVersion) { 54 | try { 55 | return knownSnapshotBlob(desiredVersion); 56 | } catch (AmazonS3Exception transitionNotFound) { } 57 | 58 | /// There was no exact match for a snapshot leading to the desired state. 59 | /// We'll use the snapshot index to find the nearest one before the desired state. 60 | try { 61 | File f = downloadFile(S3Publisher.getSnapshotIndexObjectName(blobNamespace)); 62 | long snapshotIdxLength = f.length(); 63 | long pos = 0; 64 | long currentSnapshotStateId = 0; 65 | 66 | try(InputStream is = new BufferedInputStream(new FileInputStream(f))) { 67 | while(pos < snapshotIdxLength) { 68 | long nextGap = VarInt.readVLong(is); 69 | 70 | if(currentSnapshotStateId + nextGap > desiredVersion) { 71 | if(currentSnapshotStateId == 0) 72 | return null; 73 | 74 | return knownSnapshotBlob(currentSnapshotStateId); 75 | } 76 | 77 | currentSnapshotStateId += nextGap; 78 | pos += VarInt.sizeOfVLong(nextGap); 79 | } 80 | 81 | if(currentSnapshotStateId != 0) 82 | return knownSnapshotBlob(currentSnapshotStateId); 83 | } 84 | } catch(IOException e) { 85 | throw new RuntimeException(e); 86 | } 87 | 88 | return null; 89 | } 90 | 91 | @Override 92 | public Blob retrieveDeltaBlob(long currentVersion) { 93 | try { 94 | return knownDeltaBlob("delta", currentVersion); 95 | } catch (AmazonS3Exception transitionNotFound) { 96 | return null; 97 | } 98 | } 99 | 100 | @Override 101 | public Blob retrieveReverseDeltaBlob(long currentVersion) { 102 | try { 103 | return knownDeltaBlob("reversedelta", currentVersion); 104 | } catch (AmazonS3Exception transitionNotFound) { 105 | return null; 106 | } 107 | } 108 | 109 | private Blob knownSnapshotBlob(long desiredVersion) { 110 | String objectName = S3Publisher.getS3ObjectName(blobNamespace, "snapshot", desiredVersion); 111 | ObjectMetadata objectMetadata = s3.getObjectMetadata(bucketName, objectName); 112 | long toState = Long.parseLong(objectMetadata.getUserMetaDataOf("to_state")); 113 | 114 | return new S3Blob(objectName, toState); 115 | } 116 | 117 | private Blob knownDeltaBlob(String fileType, long fromVersion) { 118 | String objectName = S3Publisher.getS3ObjectName(blobNamespace, fileType, fromVersion); 119 | ObjectMetadata objectMetadata = s3.getObjectMetadata(bucketName, objectName); 120 | long fromState = Long.parseLong(objectMetadata.getUserMetaDataOf("from_state")); 121 | long toState = Long.parseLong(objectMetadata.getUserMetaDataOf("to_state")); 122 | 123 | return new S3Blob(objectName, fromState, toState); 124 | } 125 | 126 | private class S3Blob extends Blob { 127 | 128 | private final String objectName; 129 | 130 | public S3Blob(String objectName, long toVersion) { 131 | super(toVersion); 132 | this.objectName = objectName; 133 | } 134 | 135 | public S3Blob(String objectName, long fromVersion, long toVersion) { 136 | super(fromVersion, toVersion); 137 | this.objectName = objectName; 138 | } 139 | 140 | @Override 141 | public InputStream getInputStream() throws IOException { 142 | 143 | final File tempFile = downloadFile(objectName); 144 | 145 | return new BufferedInputStream(new FileInputStream(tempFile)) { 146 | @Override 147 | public void close() throws IOException { 148 | super.close(); 149 | tempFile.delete(); 150 | } 151 | }; 152 | 153 | } 154 | 155 | } 156 | 157 | private File downloadFile(String objectName) throws IOException { 158 | File tempFile = new File(System.getProperty("java.io.tmpdir"), objectName.replace('/', '-')); 159 | 160 | Download download = s3TransferManager.download(bucketName, objectName, tempFile); 161 | 162 | try { 163 | download.waitForCompletion(); 164 | } catch(SdkBaseException | InterruptedException e) { 165 | throw new RuntimeException(e); 166 | } 167 | 168 | return tempFile; 169 | } 170 | 171 | } 172 | -------------------------------------------------------------------------------- /src/main/java/how/hollow/producer/Producer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2016 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * 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, 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 | package how.hollow.producer; 19 | 20 | import com.netflix.hollow.api.consumer.HollowConsumer.AnnouncementWatcher; 21 | import com.netflix.hollow.api.consumer.HollowConsumer.BlobRetriever; 22 | import com.netflix.hollow.api.consumer.fs.HollowFilesystemAnnouncementWatcher; 23 | import com.netflix.hollow.api.consumer.fs.HollowFilesystemBlobRetriever; 24 | import com.netflix.hollow.api.producer.HollowProducer; 25 | import com.netflix.hollow.api.producer.HollowProducer.Announcer; 26 | import com.netflix.hollow.api.producer.HollowProducer.Publisher; 27 | import com.netflix.hollow.api.producer.fs.HollowFilesystemAnnouncer; 28 | import com.netflix.hollow.api.producer.fs.HollowFilesystemPublisher; 29 | import how.hollow.producer.datamodel.Movie; 30 | 31 | import java.io.File; 32 | 33 | 34 | public class Producer { 35 | 36 | public static final String SCRATCH_DIR = System.getProperty("java.io.tmpdir"); 37 | private static final long MIN_TIME_BETWEEN_CYCLES = 10000; 38 | 39 | public static void main(String[] args) { 40 | File publishDir = new File(SCRATCH_DIR, "publish-dir"); 41 | publishDir.mkdir(); 42 | 43 | System.out.println("I AM THE PRODUCER. I WILL PUBLISH TO " + publishDir.getAbsolutePath()); 44 | 45 | Publisher publisher = new HollowFilesystemPublisher(publishDir.toPath()); 46 | Announcer announcer = new HollowFilesystemAnnouncer(publishDir.toPath()); 47 | 48 | BlobRetriever blobRetriever = new HollowFilesystemBlobRetriever(publishDir.toPath()); 49 | AnnouncementWatcher announcementWatcher = new HollowFilesystemAnnouncementWatcher(publishDir.toPath()); 50 | 51 | HollowProducer producer = HollowProducer.withPublisher(publisher) 52 | .withAnnouncer(announcer) 53 | .build(); 54 | 55 | producer.initializeDataModel(Movie.class); 56 | 57 | restoreIfAvailable(producer, blobRetriever, announcementWatcher); 58 | 59 | cycleForever(producer); 60 | 61 | } 62 | 63 | public static void restoreIfAvailable(HollowProducer producer, 64 | BlobRetriever retriever, 65 | AnnouncementWatcher unpinnableAnnouncementWatcher) { 66 | 67 | System.out.println("ATTEMPTING TO RESTORE PRIOR STATE..."); 68 | long latestVersion = unpinnableAnnouncementWatcher.getLatestVersion(); 69 | if(latestVersion != AnnouncementWatcher.NO_ANNOUNCEMENT_AVAILABLE) { 70 | producer.restore(latestVersion, retriever); 71 | System.out.println("RESTORED " + latestVersion); 72 | } else { 73 | System.out.println("RESTORE NOT AVAILABLE"); 74 | } 75 | } 76 | 77 | 78 | public static void cycleForever(HollowProducer producer) { 79 | final SourceDataRetriever sourceDataRetriever = new SourceDataRetriever(); 80 | 81 | long lastCycleTime = Long.MIN_VALUE; 82 | while(true) { 83 | waitForMinCycleTime(lastCycleTime); 84 | lastCycleTime = System.currentTimeMillis(); 85 | producer.runCycle(writeState -> { 86 | for(Movie movie : sourceDataRetriever.retrieveAllMovies()) { 87 | writeState.add(movie); /// <-- this is thread-safe, and can be done in parallel 88 | } 89 | }); 90 | } 91 | } 92 | 93 | private static void waitForMinCycleTime(long lastCycleTime) { 94 | long targetNextCycleTime = lastCycleTime + MIN_TIME_BETWEEN_CYCLES; 95 | 96 | while(System.currentTimeMillis() < targetNextCycleTime) { 97 | try { 98 | Thread.sleep(targetNextCycleTime - System.currentTimeMillis()); 99 | } catch(InterruptedException ignore) { } 100 | } 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/how/hollow/producer/SourceDataRetriever.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2016 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * 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, 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 | package how.hollow.producer; 19 | 20 | import how.hollow.producer.datamodel.Actor; 21 | import how.hollow.producer.datamodel.Movie; 22 | 23 | import java.util.*; 24 | 25 | public class SourceDataRetriever { 26 | 27 | private final List allMovies; 28 | private final List allActors; 29 | private final Random rand; 30 | 31 | private int nextMovieId; 32 | private int nextActorId; 33 | 34 | public SourceDataRetriever() { 35 | this.allMovies = new ArrayList(); 36 | this.allActors = new ArrayList(); 37 | this.rand = new Random(); 38 | bootstrapData(); 39 | } 40 | 41 | /** 42 | * Retrieve all movies from the source of truth. 43 | */ 44 | public List retrieveAllMovies() { 45 | // change a few movie titles 46 | int numMovieNamesToChange = rand.nextInt(5); 47 | 48 | for(int i=0;i iterator = movie.actors.iterator(); 69 | iterator.next(); 70 | iterator.remove(); 71 | } 72 | 73 | for(int j=0;j bootstrapData() { 91 | nextActorId = 1000000; 92 | nextMovieId = 1000000; 93 | 94 | for(int i=1;i<1000;i++) 95 | allActors.add(generateNewRandomActor()); 96 | 97 | 98 | for(int i=0;i<10000;i++) 99 | allMovies.add(generateNewRandomMovie()); 100 | 101 | return allMovies; 102 | } 103 | 104 | private Actor generateNewRandomActor() { 105 | return new Actor(++nextActorId, generateRandomString()); 106 | } 107 | 108 | private Movie generateNewRandomMovie() { 109 | int numActors = rand.nextInt(25) + 1; 110 | Set actors = new HashSet(); 111 | 112 | for(int j=0;j actors; 32 | 33 | public Movie() { } 34 | 35 | public Movie(int id, String title, Set actors) { 36 | this.id = id; 37 | this.title = title; 38 | this.actors = actors; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/how/hollow/producer/infrastructure/DynamoDBAnnouncer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2016 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * 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, 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 | package how.hollow.producer.infrastructure; 19 | 20 | import com.amazonaws.auth.AWSCredentials; 21 | import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; 22 | import com.amazonaws.services.dynamodbv2.document.DynamoDB; 23 | import com.amazonaws.services.dynamodbv2.document.Table; 24 | import com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec; 25 | import com.amazonaws.services.dynamodbv2.document.utils.NameMap; 26 | import com.amazonaws.services.dynamodbv2.document.utils.ValueMap; 27 | import com.netflix.hollow.api.producer.HollowProducer.Announcer; 28 | 29 | public class DynamoDBAnnouncer implements Announcer { 30 | 31 | private final DynamoDB dynamoDB; 32 | private final String tableName; 33 | private final String blobNamespace; 34 | 35 | public DynamoDBAnnouncer(AWSCredentials credentials, String tableName, String blobNamespace) { 36 | this.dynamoDB = new DynamoDB(new AmazonDynamoDBClient(credentials)); 37 | this.tableName = tableName; 38 | this.blobNamespace = blobNamespace; 39 | } 40 | 41 | @Override 42 | public void announce(long stateVersion) { 43 | Table table = dynamoDB.getTable(tableName); 44 | 45 | UpdateItemSpec updateItemSpec = new UpdateItemSpec() 46 | .withPrimaryKey("namespace", blobNamespace) 47 | .withUpdateExpression("set #version = :ver") 48 | .withNameMap(new NameMap().with("#version", "version")) 49 | .withValueMap(new ValueMap().withNumber(":ver", stateVersion)); 50 | 51 | table.updateItem(updateItemSpec); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/how/hollow/producer/infrastructure/S3Announcer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2016 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * 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, 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 | package how.hollow.producer.infrastructure; 19 | 20 | import com.amazonaws.auth.AWSCredentials; 21 | import com.amazonaws.services.s3.AmazonS3; 22 | import com.amazonaws.services.s3.AmazonS3Client; 23 | import com.netflix.hollow.api.producer.HollowProducer.Announcer; 24 | 25 | public class S3Announcer implements Announcer { 26 | 27 | public static final String ANNOUNCEMENT_OBJECTNAME = "announced.version"; 28 | 29 | private final AmazonS3 s3; 30 | private final String bucketName; 31 | private final String blobNamespace; 32 | 33 | public S3Announcer(AWSCredentials credentials, String bucketName, String blobNamespace) { 34 | this.s3 = new AmazonS3Client(credentials); 35 | this.bucketName = bucketName; 36 | this.blobNamespace = blobNamespace; 37 | } 38 | 39 | @Override 40 | public void announce(long stateVersion) { 41 | s3.putObject(bucketName, blobNamespace + "/" + ANNOUNCEMENT_OBJECTNAME, String.valueOf(stateVersion)); 42 | } 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/how/hollow/producer/infrastructure/S3Publisher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2016 Netflix, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * 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, 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 | package how.hollow.producer.infrastructure; 19 | 20 | import com.amazonaws.auth.AWSCredentials; 21 | import com.amazonaws.services.s3.AmazonS3; 22 | import com.amazonaws.services.s3.AmazonS3Client; 23 | import com.amazonaws.services.s3.model.ObjectListing; 24 | import com.amazonaws.services.s3.model.ObjectMetadata; 25 | import com.amazonaws.services.s3.model.S3ObjectSummary; 26 | import com.amazonaws.services.s3.transfer.TransferManager; 27 | import com.amazonaws.services.s3.transfer.Upload; 28 | import com.netflix.hollow.api.producer.HollowProducer.Blob; 29 | import com.netflix.hollow.api.producer.HollowProducer.Publisher; 30 | import com.netflix.hollow.core.memory.encoding.HashCodes; 31 | import com.netflix.hollow.core.memory.encoding.VarInt; 32 | import java.io.BufferedInputStream; 33 | import java.io.ByteArrayInputStream; 34 | import java.io.ByteArrayOutputStream; 35 | import java.io.File; 36 | import java.io.FileInputStream; 37 | import java.io.IOException; 38 | import java.io.InputStream; 39 | import java.util.ArrayList; 40 | import java.util.Collections; 41 | import java.util.List; 42 | 43 | public class S3Publisher implements Publisher { 44 | 45 | private final AmazonS3 s3; 46 | private final TransferManager s3TransferManager; 47 | private final String bucketName; 48 | private final String blobNamespace; 49 | 50 | private final List snapshotIndex; 51 | 52 | public S3Publisher(AWSCredentials credentials, String bucketName, String blobNamespace) { 53 | this.s3 = new AmazonS3Client(credentials); 54 | this.s3TransferManager = new TransferManager(s3); 55 | this.bucketName = bucketName; 56 | this.blobNamespace = blobNamespace; 57 | this.snapshotIndex = initializeSnapshotIndex(); 58 | } 59 | 60 | @Override 61 | public void publish(Blob blob) { 62 | switch(blob.getType()) { 63 | case SNAPSHOT: 64 | publishSnapshot(blob); 65 | break; 66 | case DELTA: 67 | publishDelta(blob); 68 | break; 69 | case REVERSE_DELTA: 70 | publishReverseDelta(blob); 71 | break; 72 | } 73 | } 74 | 75 | public void publishSnapshot(Blob blob) { 76 | String objectName = getS3ObjectName(blobNamespace, "snapshot", blob.getToVersion()); 77 | 78 | ObjectMetadata metadata = new ObjectMetadata(); 79 | metadata.addUserMetadata("to_state", String.valueOf(blob.getToVersion())); 80 | metadata.setHeader("Content-Length", blob.getFile().length()); 81 | 82 | uploadFile(blob.getFile(), objectName, metadata); 83 | 84 | /// now we update the snapshot index 85 | updateSnapshotIndex(blob.getToVersion()); 86 | } 87 | 88 | public void publishDelta(Blob blob) { 89 | String objectName = getS3ObjectName(blobNamespace, "delta", blob.getFromVersion()); 90 | 91 | ObjectMetadata metadata = new ObjectMetadata(); 92 | metadata.addUserMetadata("from_state", String.valueOf(blob.getFromVersion())); 93 | metadata.addUserMetadata("to_state", String.valueOf(blob.getToVersion())); 94 | metadata.setHeader("Content-Length", blob.getFile().length()); 95 | 96 | uploadFile(blob.getFile(), objectName, metadata); 97 | } 98 | 99 | public void publishReverseDelta(Blob blob) { 100 | String objectName = getS3ObjectName(blobNamespace, "reversedelta", blob.getFromVersion()); 101 | 102 | ObjectMetadata metadata = new ObjectMetadata(); 103 | metadata.addUserMetadata("from_state", String.valueOf(blob.getFromVersion())); 104 | metadata.addUserMetadata("to_state", String.valueOf(blob.getToVersion())); 105 | metadata.setHeader("Content-Length", blob.getFile().length()); 106 | 107 | uploadFile(blob.getFile(), objectName, metadata); 108 | } 109 | 110 | public static String getS3ObjectName(String blobNamespace, String fileType, long lookupVersion) { 111 | StringBuilder builder = new StringBuilder(getS3ObjectPrefix(blobNamespace, fileType)); 112 | builder.append(Integer.toHexString(HashCodes.hashLong(lookupVersion))); 113 | builder.append("-"); 114 | builder.append(lookupVersion); 115 | return builder.toString(); 116 | } 117 | 118 | private static String getS3ObjectPrefix(String blobNamespace, String fileType) { 119 | StringBuilder builder = new StringBuilder(blobNamespace); 120 | builder.append("/").append(fileType).append("/"); 121 | return builder.toString(); 122 | } 123 | 124 | private void uploadFile(File file, String s3ObjectName, ObjectMetadata metadata) { 125 | try (InputStream is = new BufferedInputStream(new FileInputStream(file))) { 126 | Upload upload = s3TransferManager.upload(bucketName, s3ObjectName, is, metadata); 127 | 128 | upload.waitForCompletion(); 129 | } catch (Exception e) { 130 | throw new RuntimeException(e); 131 | } 132 | } 133 | 134 | /////////////////////// BEGIN SNAPSHOT INDEX CODE /////////////////////// 135 | /* 136 | * We need an index over the available state versions for which snapshot blobs are available. 137 | * The S3Publisher stores that index as an object with a known key in S3. 138 | * The remainder of this class deals with maintaining that index. 139 | */ 140 | 141 | public static String getSnapshotIndexObjectName(String blobNamespace) { 142 | return blobNamespace + "/snapshot.index"; 143 | } 144 | 145 | /** 146 | * Write a list of all of the state versions to S3. 147 | * @param newVersion 148 | */ 149 | private synchronized void updateSnapshotIndex(Long newVersion) { 150 | /// insert the new version into the list 151 | int idx = Collections.binarySearch(snapshotIndex, newVersion); 152 | int insertionPoint = Math.abs(idx) - 1; 153 | snapshotIndex.add(insertionPoint, newVersion); 154 | 155 | /// build a binary representation of the list -- gap encoded variable-length integers 156 | byte[] idxBytes = buidGapEncodedVarIntSnapshotIndex(); 157 | 158 | /// indicate the Content-Length 159 | ObjectMetadata metadata = new ObjectMetadata(); 160 | metadata.setHeader("Content-Length", (long)idxBytes.length); 161 | 162 | /// upload the new file content. 163 | try(InputStream is = new ByteArrayInputStream(idxBytes)) { 164 | Upload upload = s3TransferManager.upload(bucketName, getSnapshotIndexObjectName(blobNamespace), is, metadata); 165 | 166 | upload.waitForCompletion(); 167 | } catch(Exception e) { 168 | throw new RuntimeException(e); 169 | } 170 | } 171 | 172 | /** 173 | * Encode the sorted list of all state versions as gap-encoded variable length integers. 174 | * @return 175 | */ 176 | private byte[] buidGapEncodedVarIntSnapshotIndex() { 177 | int idx; 178 | byte[] idxBytes; 179 | idx = 0; 180 | long currentSnapshotId = snapshotIndex.get(idx++); 181 | long currentSnapshotIdGap = currentSnapshotId; 182 | try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { 183 | while(idx < snapshotIndex.size()) { 184 | VarInt.writeVLong(os, currentSnapshotIdGap); 185 | 186 | long nextSnapshotId = snapshotIndex.get(idx++); 187 | currentSnapshotIdGap = nextSnapshotId - currentSnapshotId; 188 | currentSnapshotId = nextSnapshotId; 189 | } 190 | 191 | VarInt.writeVLong(os, currentSnapshotIdGap); 192 | 193 | idxBytes = os.toByteArray(); 194 | } catch(IOException shouldNotHappen) { 195 | throw new RuntimeException(shouldNotHappen); 196 | } 197 | 198 | return idxBytes; 199 | } 200 | 201 | /** 202 | * Find all of the existing snapshots. 203 | */ 204 | private List initializeSnapshotIndex() { 205 | List snapshotIdx = new ArrayList(); 206 | 207 | ObjectListing listObjects = s3.listObjects(bucketName, getS3ObjectPrefix(blobNamespace, "snapshot")); 208 | 209 | for (S3ObjectSummary summary : listObjects.getObjectSummaries()) 210 | addSnapshotStateId(summary, snapshotIdx); 211 | 212 | while (listObjects.isTruncated()) { 213 | listObjects = s3.listNextBatchOfObjects(listObjects); 214 | 215 | for (S3ObjectSummary summary : listObjects.getObjectSummaries()) 216 | addSnapshotStateId(summary, snapshotIdx); 217 | } 218 | 219 | Collections.sort(snapshotIdx); 220 | 221 | return snapshotIdx; 222 | } 223 | 224 | private void addSnapshotStateId(S3ObjectSummary obj, List snapshotIdx) { 225 | String key = obj.getKey(); 226 | try { 227 | snapshotIdx.add(Long.parseLong(key.substring(key.lastIndexOf("-") + 1))); 228 | } catch(NumberFormatException ignore) { } 229 | } 230 | 231 | } 232 | -------------------------------------------------------------------------------- /src/main/resources/readme: -------------------------------------------------------------------------------- 1 | Project documentation available at http://hollow.how/quick-start --------------------------------------------------------------------------------