├── .gitignore ├── LICENSE ├── README.md ├── _config.yml ├── chapters ├── .gitignore ├── LICENSE ├── README.md ├── chapter-bigdata-spark │ ├── ignite-spark-scala │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── scala │ │ │ └── com │ │ │ └── blu │ │ │ └── imdg │ │ │ └── SparkIgniteTest.scala │ ├── spark-shell-srcipts │ │ ├── PutRdd.spark │ │ └── ReadRdd.spark │ └── wordcount │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── blu │ │ └── imdg │ │ └── JavaWordCount.java ├── chapter-bigdata │ ├── pom.xml │ └── src │ │ └── main │ │ ├── config │ │ ├── hive │ │ │ ├── HiveQL.sql │ │ │ ├── copy-hadoop-directory.sh │ │ │ ├── create-metastore.sh │ │ │ ├── hive-ig.sh │ │ │ └── hive-site.xml │ │ ├── ignite-inmemory │ │ │ ├── default-config.xml │ │ │ └── hadoop.sh │ │ └── pig │ │ │ └── piglatin.pig │ │ ├── input │ │ ├── movies_data.csv │ │ ├── movies_with_duplicates.csv │ │ └── t8.shakespeare.txt │ │ ├── java │ │ └── com │ │ │ └── blu │ │ │ └── imdg │ │ │ └── igfs │ │ │ ├── IngestFileInIGFS.java │ │ │ └── MapReduceResultReader.java │ │ ├── resources │ │ ├── default-config.xml │ │ ├── log4j.xml │ │ └── t8.shakespeare.txt │ │ └── statistics │ │ └── inmemory.xlsx ├── chapter-caching │ ├── hibernate │ │ ├── pom.xml │ │ ├── scripts │ │ │ ├── emp-dept.ddl │ │ │ ├── emp-dept.dml │ │ │ ├── exc-rate.ddl │ │ │ └── exc-rate.dml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── blu │ │ │ │ └── imdg │ │ │ │ ├── EmpDaoImpl.java │ │ │ │ ├── Run.java │ │ │ │ ├── RunWebService.java │ │ │ │ ├── dao │ │ │ │ └── EmpDao.java │ │ │ │ ├── dto │ │ │ │ ├── Employee.java │ │ │ │ └── ExchangeRate.java │ │ │ │ └── ws │ │ │ │ └── WebService.java │ │ │ └── resources │ │ │ ├── jdbc.properties │ │ │ └── spring-core.xml │ ├── mybatis │ │ ├── pom.xml │ │ ├── scripts │ │ │ ├── emp-dept.ddl │ │ │ └── emp-dept.dml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── blu │ │ │ │ └── imdg │ │ │ │ ├── RunWebService.java │ │ │ │ ├── WebServices.java │ │ │ │ ├── dao │ │ │ │ └── UserServices.java │ │ │ │ ├── dto │ │ │ │ └── Employee.java │ │ │ │ └── mapper │ │ │ │ └── UserMapper.java │ │ │ └── resources │ │ │ ├── com │ │ │ └── blu │ │ │ │ └── imdg │ │ │ │ └── mapper │ │ │ │ └── UserMapper.xml │ │ │ ├── jdbc.properties │ │ │ └── spring-core.xml │ ├── offheap │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── blu │ │ │ │ └── imdg │ │ │ │ └── PutElementstoOffHeap.java │ │ │ └── resources │ │ │ ├── spring-offheap-tiered.xml │ │ │ ├── spring-offheap-values.xml │ │ │ └── spring-onheap-tiered.xml │ └── web-session-clustering │ │ ├── README │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── blu │ │ │ └── imdg │ │ │ └── wsession │ │ │ ├── bean │ │ │ └── Person.java │ │ │ └── controller │ │ │ └── WebSessionController.java │ │ ├── resources │ │ └── META-INF │ │ │ └── spring-ignite-cache.xml │ │ └── webapp │ │ └── WEB-INF │ │ ├── spring-servlet.xml │ │ ├── views │ │ └── welcome.jsp │ │ └── web.xml ├── chapter-cep │ ├── camel │ │ ├── README.md │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── blu │ │ │ │ └── imdg │ │ │ │ ├── ExampleNodeStartup.java │ │ │ │ ├── ExamplesUtils.java │ │ │ │ ├── camel │ │ │ │ ├── CamelStreamerDirectIngestion.java │ │ │ │ ├── CamelStreamerMediation.java │ │ │ │ └── CamelStreamerMediationIngestion.java │ │ │ │ ├── dto │ │ │ │ ├── Alert.java │ │ │ │ ├── Level.java │ │ │ │ ├── MnpRouting.java │ │ │ │ └── ServiceStatus.java │ │ │ │ ├── processor │ │ │ │ └── RouteProcessor.java │ │ │ │ ├── query │ │ │ │ ├── AlertMonitoring.java │ │ │ │ └── QueryStatus.java │ │ │ │ └── streamer │ │ │ │ ├── HealthCheckStreamVisitor.java │ │ │ │ └── HealthCheckStreamer.java │ │ │ └── resources │ │ │ ├── camel.properties │ │ │ ├── default-config.xml │ │ │ ├── example-default.xml │ │ │ ├── example-ignite.xml │ │ │ ├── ignite-log4j2.xml │ │ │ └── input.json │ ├── flume │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── blu │ │ │ │ └── imdg │ │ │ │ └── flume │ │ │ │ ├── Transformer │ │ │ │ └── FlumeEventTransformer.java │ │ │ │ ├── config │ │ │ │ ├── agent.sh │ │ │ │ ├── demo.properties │ │ │ │ └── example-ignite.xml │ │ │ │ └── rpc │ │ │ │ ├── RpcEventGenerator.java │ │ │ │ └── RunClient.java │ │ │ └── resources │ │ │ └── generator.properties │ └── storm │ │ ├── README.md │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── blu │ │ │ └── imdg │ │ │ └── storm │ │ │ ├── bolts │ │ │ ├── SpeedLimitBolt.java │ │ │ ├── SplitSentence.java │ │ │ └── WordCount.java │ │ │ ├── spouts │ │ │ ├── FileSourceSpout.java │ │ │ └── RandomSentenceSpout.java │ │ │ └── topology │ │ │ ├── SpeedViolationTopology.java │ │ │ └── WordCountTopology.java │ │ └── resources │ │ ├── example-ignite.xml │ │ ├── ignite-storm.properties │ │ └── source.csv ├── chapter-dist-computing │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── blu │ │ │ └── imdg │ │ │ ├── StartCacheNode.java │ │ │ ├── common │ │ │ ├── CommonConstants.java │ │ │ ├── HttpAuditClient.java │ │ │ ├── HttpAuditEmulator.java │ │ │ ├── JSEvaluate.java │ │ │ ├── TestDataGenerator.java │ │ │ ├── XPathExecutor.java │ │ │ ├── XsdValidator.java │ │ │ └── bankData │ │ │ │ ├── BankDataGenerator.java │ │ │ │ └── model │ │ │ │ ├── AccountCacheData.java │ │ │ │ ├── AccountCacheKey.java │ │ │ │ ├── AccountData.java │ │ │ │ ├── AccountKey.java │ │ │ │ ├── CashBackDictionaryData.java │ │ │ │ ├── TransactionData.java │ │ │ │ └── TransactionKey.java │ │ │ ├── example1 │ │ │ ├── SimpleComputation.java │ │ │ └── SimpleComputationClosure.java │ │ │ ├── example10 │ │ │ ├── AsyncBankService.java │ │ │ ├── AsyncBankServiceImpl.java │ │ │ ├── TestAsyncMicroServiceMain.java │ │ │ ├── ZeroMQBroker.java │ │ │ └── dto │ │ │ │ ├── ValidateRequest.java │ │ │ │ └── ValidateResponse.java │ │ │ ├── example2 │ │ │ └── AsyncComputation.java │ │ │ ├── example3 │ │ │ ├── ForkJoinComputation.java │ │ │ ├── ForkJoinJobAdapter.java │ │ │ └── ValidateMessage.java │ │ │ ├── example4 │ │ │ ├── ForkJoinComputationExt.java │ │ │ └── ForkJoinJobAdapterExt.java │ │ │ ├── example5 │ │ │ ├── ForkJoinWithSessionJobAdapter.java │ │ │ └── ForkJointWithSessionComputation.java │ │ │ ├── example6 │ │ │ ├── ForkJoinWithCheckpointComputation.java │ │ │ └── ForkJoinWithCheckpointJobAdapter.java │ │ │ ├── example7 │ │ │ ├── DeployClusterSingleton.java │ │ │ ├── DeployNodeSingleton.java │ │ │ ├── RunXsdValidationService.java │ │ │ ├── ServiceManagements.java │ │ │ ├── TestXsdValidatingService.java │ │ │ ├── XsdValidatingService.java │ │ │ └── XsdValidatingServiceImpl.java │ │ │ ├── example8 │ │ │ └── TestAccountSavingsMain.java │ │ │ └── example9 │ │ │ ├── BankService.java │ │ │ ├── BankServiceImpl.java │ │ │ ├── DeployService.java │ │ │ ├── LogService.java │ │ │ ├── LogServiceImpl.java │ │ │ ├── ServiceHttpClient.java │ │ │ ├── TestMicroServiceMain.java │ │ │ └── exception │ │ │ ├── AccountNotFoundException.java │ │ │ └── LogServiceException.java │ │ └── resources │ │ └── META-INF │ │ └── org │ │ └── book │ │ └── examples │ │ ├── base-config.xml │ │ ├── cache-node-config.xml │ │ ├── data │ │ ├── sample1.xml │ │ ├── sample2.xml │ │ ├── sample3.xml │ │ ├── validate-schema.xsd │ │ └── validate-script.js │ │ └── simple-client-config.xml ├── chapter-installation │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── blu │ │ │ ├── dto │ │ │ └── Person.java │ │ │ └── imdg │ │ │ ├── HelloIgnite.java │ │ │ ├── HelloIgniteAsyn.java │ │ │ └── HelloIgniteSpring.java │ │ └── resources │ │ └── default-config.xml ├── chapter-persistence │ ├── README.md │ ├── expiry │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── blu │ │ │ │ └── imdg │ │ │ │ └── IgniteExpiryExample.java │ │ │ └── resources │ │ │ └── default-config.xml │ ├── persistence-store │ │ ├── README.md │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── blu │ │ │ │ └── imdg │ │ │ │ ├── CacheStoreSample.java │ │ │ │ ├── jdbc │ │ │ │ ├── PostgresDBStore.java │ │ │ │ └── model │ │ │ │ │ └── Post.java │ │ │ │ └── nosql │ │ │ │ ├── MongoDBStore.java │ │ │ │ ├── PostRepository.java │ │ │ │ └── model │ │ │ │ └── MongoPost.java │ │ │ └── resources │ │ │ ├── create-db-scheme.ddl │ │ │ ├── jdbc.properties │ │ │ ├── logback.xml │ │ │ ├── mongo-context.xml │ │ │ └── postgres-context.xml │ ├── pom.xml │ ├── spring-data │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── blu │ │ │ └── imdg │ │ │ ├── App.java │ │ │ ├── model │ │ │ ├── Breed.java │ │ │ └── Dog.java │ │ │ └── repositories │ │ │ ├── BreedRepository.java │ │ │ ├── DogRepository.java │ │ │ └── SpringAppConfig.java │ ├── sqlqueries │ │ ├── README.md │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── blu │ │ │ │ └── imdg │ │ │ │ ├── SqlQueryEmployees.java │ │ │ │ └── model │ │ │ │ ├── Department.java │ │ │ │ ├── Employee.java │ │ │ │ └── EmployeeKey.java │ │ │ └── resources │ │ │ ├── create-table.ddl │ │ │ ├── example-ignite.xml │ │ │ ├── insert-data.dml │ │ │ └── logback.xml │ ├── textquery │ │ ├── README.md │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── blu │ │ │ │ └── imdg │ │ │ │ ├── TextQueryExample.java │ │ │ │ └── model │ │ │ │ └── Company.java │ │ │ └── resources │ │ │ ├── USA_NY_email_addresses.csv │ │ │ ├── example-ignite.xml │ │ │ └── logback.xml │ └── transactions │ │ ├── README.md │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── blu │ │ │ └── imdg │ │ │ └── SimpleTransactions.java │ │ └── resources │ │ ├── example-ignite.xml │ │ └── logback.xml ├── chapters.ipr └── pom.xml └── highperfomance-mini.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### JetBrains template 3 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 4 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 5 | 6 | # User-specific stuff: 7 | .idea/** 8 | **.iml 9 | **.ipr 10 | # Sensitive or high-churn files: 11 | .idea/dataSources.ids 12 | .idea/dataSources.xml 13 | .idea/dataSources.local.xml 14 | .idea/sqlDataSources.xml 15 | .idea/dynamic.xml 16 | .idea/uiDesigner.xml 17 | 18 | # Gradle: 19 | .idea/gradle.xml 20 | .idea/libraries 21 | 22 | # Mongo Explorer plugin: 23 | .idea/mongoSettings.xml 24 | 25 | ## File-based project format: 26 | *.iws 27 | 28 | ## Plugin-specific files: 29 | 30 | # IntelliJ 31 | /out/ 32 | 33 | # mpeltonen/sbt-idea plugin 34 | .idea_modules/ 35 | 36 | # JIRA plugin 37 | atlassian-ide-plugin.xml 38 | 39 | # Crashlytics plugin (for Android Studio and IntelliJ) 40 | com_crashlytics_export_strings.xml 41 | crashlytics.properties 42 | crashlytics-build.properties 43 | fabric.properties 44 | ### Maven template 45 | target/ 46 | pom.xml.tag 47 | pom.xml.releaseBackup 48 | pom.xml.versionsBackup 49 | pom.xml.next 50 | release.properties 51 | dependency-reduced-pom.xml 52 | buildNumber.properties 53 | .mvn/timing.properties 54 | ### Java template 55 | *.class 56 | 57 | # Mobile Tools for Java (J2ME) 58 | .mtj.tmp/ 59 | 60 | # Package Files # 61 | *.jar 62 | *.war 63 | *.ear 64 | 65 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 66 | hs_err_pid* 67 | .idea/ 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # High performance in-memory data grid with Apache Ignite 2 | 3 | All code samples, scripts and more in-depth examples for the book **High performance in-memory computing with Apache Ignite**. 4 | 5 | [![alt text](/highperfomance-mini.jpg "book cover")](http://leanpub.com/ignite) 6 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-architect -------------------------------------------------------------------------------- /chapters/.gitignore: -------------------------------------------------------------------------------- 1 | **.iml 2 | **/target 3 | /chapter-cep-flume/target/ 4 | /chapter-cep-flume/chapter-cep-flume.iws 5 | /chapter-cep-storm/.idea/ 6 | /chapter-dist-computing/target/ 7 | /chapters.ipr 8 | /chapters.iml 9 | /chapters.iws 10 | /chapter-cep/camel/target/ 11 | /chapters.ids 12 | /chapter-persistence/expiry/expiry.iml 13 | /chapter-bigdata-spark/wordcount/ignite-spark.iml 14 | /chapter-bigdata-spark/wordcount/wordcount.ipr 15 | /chapter-bigdata-spark/wordcount/wordcount.iws 16 | -------------------------------------------------------------------------------- /chapters/README.md: -------------------------------------------------------------------------------- 1 | ## Prerequisites 2 | | N | Name | Value | 3 | |---|---------|--------------------------------------------------------------------------------------| 4 | | 1 | JDK | Oracle JDK 8 and above | 5 | | 2 | OS | Linux, MacOS (10.6 and above), Windows XP and above, Windows Server (2008 and above) | 6 | |3 | Ignite version| 1.6 or above | 7 | 8 | > To compile, run the following command: 9 | 10 | > mvn clean install 11 | -------------------------------------------------------------------------------- /chapters/chapter-bigdata-spark/ignite-spark-scala/src/main/scala/com/blu/imdg/SparkIgniteTest.scala: -------------------------------------------------------------------------------- 1 | package com.blu.imdg 2 | 3 | import org.apache.ignite.configuration._ 4 | import org.apache.ignite.spark.{IgniteContext, IgniteRDD} 5 | import org.apache.spark.{SparkConf, SparkContext} 6 | 7 | object RDDProducer extends App { 8 | val conf = new SparkConf().setAppName("SparkIgniteProducer") 9 | val sc = new SparkContext(conf) 10 | val ic = new IgniteContext[Int, Int](sc, () => new IgniteConfiguration()) 11 | val sharedRDD: IgniteRDD[Int, Int] = ic.fromCache("IgniteRDD") 12 | sharedRDD.savePairs(sc.parallelize(1 to 1000, 10).map(i => (i, i))) 13 | } 14 | 15 | object RDDConsumer extends App { 16 | val conf = new SparkConf().setAppName("SparkIgniteConsume") 17 | val sc = new SparkContext(conf) 18 | val ic = new IgniteContext[Int, Int](sc, () => new IgniteConfiguration()) 19 | val sharedRDD = ic.fromCache("IgniteRDD") 20 | val lessThanTwenty = sharedRDD.filter(_._2 < 20) 21 | println("The count is:::::::::::: "+lessThanTwenty.count()) 22 | } -------------------------------------------------------------------------------- /chapters/chapter-bigdata-spark/spark-shell-srcipts/PutRdd.spark: -------------------------------------------------------------------------------- 1 | import org.apache.ignite.spark._ 2 | import org.apache.ignite.configuration._ 3 | val ic = new IgniteContext[Int, String](sc, () => new IgniteConfiguration()) 4 | val igniteRdd = ic.fromCache("SparkIgniteRDD") 5 | val RDDa = sc.parallelize(List("packt", "leanpub", "oreally", "wiston", "neahua"), 2) 6 | val RDDb = RDDa.map(x => (x.length, x)) 7 | igniteRdd.savePairs(RDDb) -------------------------------------------------------------------------------- /chapters/chapter-bigdata-spark/spark-shell-srcipts/ReadRdd.spark: -------------------------------------------------------------------------------- 1 | import org.apache.ignite.spark._ 2 | import org.apache.ignite.configuration._ 3 | 4 | val ic = new IgniteContext[Int, String](sc, () => new IgniteConfiguration()) 5 | val igniteRdd = ic.fromCache("SparkIgniteRDD") 6 | val res = igniteRdd.foldByKey("")(_ + _).collect -------------------------------------------------------------------------------- /chapters/chapter-bigdata-spark/wordcount/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | com.blu.imdg 7 | chapters 8 | 1.0-SNAPSHOT 9 | ../../parent 10 | 11 | com.blu.imdg 12 | wordcount 13 | 1.0-SNAPSHOT 14 | jar 15 | 16 | wordcount 17 | http://maven.apache.org 18 | 19 | 20 | UTF-8 21 | 22 | 23 | 24 | 25 | junit 26 | junit 27 | 3.8.1 28 | test 29 | 30 | 31 | org.apache.spark 32 | spark-core_2.10 33 | 1.6.0 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /chapters/chapter-bigdata-spark/wordcount/src/main/java/com/blu/imdg/JavaWordCount.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg; 2 | 3 | /** 4 | * Created by shamim on 29/02/16. 5 | */ 6 | import scala.Tuple2; 7 | import org.apache.spark.SparkConf; 8 | import org.apache.spark.api.java.JavaPairRDD; 9 | import org.apache.spark.api.java.JavaRDD; 10 | import org.apache.spark.api.java.JavaSparkContext; 11 | import org.apache.spark.api.java.function.FlatMapFunction; 12 | import org.apache.spark.api.java.function.Function2; 13 | import org.apache.spark.api.java.function.PairFunction; 14 | 15 | import java.util.Arrays; 16 | import java.util.List; 17 | import java.util.regex.Pattern; 18 | 19 | /** 20 | * Run in Spark Shell : ./spark-submit --class com.blu.imdg.JavaWordCount --master spark://192.168.1.37:7077 ~/Development/workshop/github/ignite-book-code-samples/chapters/chapter-bigdata-spark/wordcount/target/wordcount-1.0-SNAPSHOT.jar ~/Downloads/CHANGES.txt ~/Downloads/ 21 | * */ 22 | public final class JavaWordCount { 23 | private static final Pattern SPACE = Pattern.compile(" "); 24 | 25 | public static void main(String[] args) throws Exception { 26 | 27 | if (args.length < 1) { 28 | System.err.println("Usage: JavaWordCount "); 29 | System.exit(1); 30 | } 31 | 32 | SparkConf sparkConf = new SparkConf().setAppName("JavaWordCount"); 33 | JavaSparkContext ctx = new JavaSparkContext(sparkConf); 34 | JavaRDD lines = ctx.textFile(args[0], 1); 35 | 36 | JavaRDD words = lines.flatMap(new FlatMapFunction() { 37 | //@Override 38 | public Iterable call(String s) { 39 | return Arrays.asList(SPACE.split(s)); 40 | } 41 | }); 42 | 43 | JavaPairRDD ones = words.mapToPair(new PairFunction() { 44 | //@Override 45 | public Tuple2 call(String s) { 46 | return new Tuple2(s, 1); 47 | } 48 | }); 49 | 50 | JavaPairRDD counts = ones.reduceByKey(new Function2() { 51 | //@Override 52 | public Integer call(Integer i1, Integer i2) { 53 | return i1 + i2; 54 | } 55 | }); 56 | 57 | List> output = counts.collect(); 58 | for (Tuple2 tuple : output) { 59 | System.out.println(tuple._1() + ": " + tuple._2()); 60 | } 61 | ctx.stop(); 62 | } 63 | } -------------------------------------------------------------------------------- /chapters/chapter-bigdata/src/main/config/hive/HiveQL.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE input (line STRING); 2 | LOAD DATA LOCAL INPATH '/FILE_PATH/t8.shakespeare.txt' OVERWRITE INTO TABLE input; 3 | SELECT word, COUNT(*) FROM input LATERAL VIEW explode(split(line, ' ')) lTable as word GROUP BY word; 4 | 5 | CREATE TABLE IF NOT EXISTS movies 6 | (id STRING, 7 | title STRING, 8 | releasedate STRING, 9 | rating INT, 10 | Publisher STRING) 11 | ROW FORMAT DELIMITED 12 | FIELDS TERMINATED BY ',' 13 | STORED AS TEXTFILE; 14 | 15 | LOAD DATA local INPATH '/FILE_PATH/movies_data.csv' OVERWRITE INTO TABLE movies; 16 | 17 | Select releasedate, count(releasedate) from movies m group by m.releasedate; 18 | Select releasedate, count(releasedate) from movies m where rating >3 group by m.releasedate; 19 | 20 | #load data from IGFS 21 | CREATE TABLE igfsinput (line STRING); 22 | 23 | LOAD DATA INPATH '/myDir/myFile' OVERWRITE INTO TABLE igfsinput; 24 | 25 | SELECT word, COUNT(*) FROM igfsinput LATERAL VIEW explode(split(line, ' ')) lTable as word GROUP BY word; -------------------------------------------------------------------------------- /chapters/chapter-bigdata/src/main/config/hive/copy-hadoop-directory.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd $HADOOP_HOME/etc 3 | mkdir hadoop-hive 4 | cp ./hadoop/*.* ./hadoop-hive -------------------------------------------------------------------------------- /chapters/chapter-bigdata/src/main/config/hive/create-metastore.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | schematool -initSchema -dbType derby -------------------------------------------------------------------------------- /chapters/chapter-bigdata/src/main/config/hive/hive-ig.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Specify Hive home directory: 3 | export HIVE_HOME= 4 | 5 | # If you did not set hadoop executable in PATH, specify Hadoop home explicitly: 6 | export HADOOP_HOME= 7 | 8 | # Specify configuration files location: 9 | export HIVE_CONF_DIR=$HADOOP_HOME/etc/hadoop-hive 10 | 11 | # Avoid problem with different 'jline' library in Hadoop: 12 | export HADOOP_USER_CLASSPATH_FIRST=true 13 | 14 | ${HIVE_HOME}/bin/hive "${@}" -------------------------------------------------------------------------------- /chapters/chapter-bigdata/src/main/config/hive/hive-site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | hive.rpc.query.plan 9 | true 10 | 11 | -------------------------------------------------------------------------------- /chapters/chapter-bigdata/src/main/config/ignite-inmemory/default-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 127.0.0.1:47500..47509 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /chapters/chapter-bigdata/src/main/config/ignite-inmemory/hadoop.sh: -------------------------------------------------------------------------------- 1 | #Setup password less or passphrase less ssh 2 | $ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa 3 | $ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys 4 | $ chmod 0600 ~/.ssh/authorized_keys 5 | 6 | #Format the HDFS file system 7 | $bin/hdfs namenode -format 8 | 9 | #Start namenode/datanode daemon 10 | $ sbin/start-dfs.sh 11 | 12 | #Create new directories into HDFS 13 | $bin/hdfs dfs -mkdir /user 14 | $bin/hdfs dfs -mkdir /input 15 | 16 | #Insert some files in directory /input 17 | $bin/hdfs dfs -put $HADOOP_HOME/etc/hadoop /input 18 | 19 | #Run the map reduce worcount example 20 | $bin/hadoop jar $HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar wordcount /input/hadoop output 21 | 22 | #View the output from the HDFS 23 | $bin/hdfs dfs -cat output/* 24 | 25 | #Add shakespeare.txt into HDFS directory wc-input 26 | $bin/hdfs dfs -put /YOUR_PATH_TO_THE_FILE /t8.shakespeare.txt /wc-input 27 | 28 | # run Hadoop wordcount example for Shakespeare work of art 29 | time hadoop jar $HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar wordcount /wc-input/ output6 30 | -------------------------------------------------------------------------------- /chapters/chapter-bigdata/src/main/config/pig/piglatin.pig: -------------------------------------------------------------------------------- 1 | #Word count example 2 | A = load '/wc-input/t8.shakespeare.txt'; 3 | B = foreach A generate flatten(TOKENIZE((chararray)$0)) as word; 4 | C = group B by word; 5 | D = foreach C generate COUNT(B), group; 6 | E = Limit D 10; 7 | Dump E; 8 | # movie 9 | movies = LOAD '/input/hadoop/movies_data.csv' USING PigStorage(',') as (id:int,name:chararray,year:int,rating:double,duration:int); 10 | movies_rating_greater_than_four = FILTER movies BY (float)rating > 4.0; 11 | DUMP movies_rating_greater_than_four; 12 | movie_mummy = FILTER movies by (name matches '.*Mummy.*'); 13 | grouped_by_year = group movies by year; 14 | count_by_year = FOREACH grouped_by_year GENERATE group, COUNT(movies); 15 | group_all = GROUP count_by_year ALL; 16 | sum_all = FOREACH group_all GENERATE SUM(count_by_year.$1); 17 | DUMP sum_all; -------------------------------------------------------------------------------- /chapters/chapter-bigdata/src/main/input/movies_with_duplicates.csv: -------------------------------------------------------------------------------- 1 | 1,The Nightmare Before Christmas,1993,3.9,4568 2 | 1,The Nightmare Before Christmas,1993,3.9,4568 3 | 1,The Nightmare Before Christmas,1993,3.9,4568 4 | 2,The Mummy,1932,3.5,4388 5 | 3,Orphans of the Storm,1921,3.2,9062 6 | 4,The Object of Beauty,1991,2.8,6150 7 | 5,Night Tide,1963,2.8,5126 8 | 5,Night Tide,1963,2.8,5126 9 | 5,Night Tide,1963,2.8,5126 10 | 6,One Magic Christmas,1985,3.8,5333 11 | 7,Muriel's Wedding,1994,3.5,6323 12 | 8,Mother's Boys,1994,3.4,5733 13 | 9,Nosferatu: Original Version,1929,3.5,5651 14 | 10,Nick of Time,1995,3.4,5333 15 | 9,Nosferatu: Original Version,1929,3.5,5651 16 | -------------------------------------------------------------------------------- /chapters/chapter-bigdata/src/main/java/com/blu/imdg/igfs/IngestFileInIGFS.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.igfs; 2 | 3 | import com.google.common.io.ByteStreams; 4 | import org.apache.ignite.Ignite; 5 | import org.apache.ignite.IgniteFileSystem; 6 | import org.apache.ignite.Ignition; 7 | import org.apache.ignite.igfs.IgfsPath; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import java.io.IOException; 12 | import java.io.InputStream; 13 | import java.io.OutputStream; 14 | import java.util.Collection; 15 | import java.util.Iterator; 16 | 17 | 18 | /** 19 | * Created by shamim on 06/09/16. 20 | */ 21 | public class IngestFileInIGFS { 22 | private final static Logger LOGGER = LoggerFactory.getLogger(IngestFileInIGFS.class); 23 | private final static String IGFS_FS_NAME= "igfs"; 24 | 25 | public static void main(String... args) { 26 | if(args.length < 2){ 27 | LOGGER.error("Usages [java -jar chapter-hadoop-spark-1.0-SNAPSHOT.jar DIRECTORY_NAME FILE NAME, for example java -jar chapter-hadoop-spark-1.0-SNAPSHOT.jar myDir myFile]"); 28 | System.exit(0); 29 | } 30 | 31 | Ignite ignite = Ignition.start("default-config.xml"); 32 | Ignition.setClientMode(true); 33 | 34 | Collection fs = ignite.fileSystems(); 35 | 36 | for(Iterator ite = fs.iterator();ite.hasNext();){ 37 | IgniteFileSystem igniteFileSystem = (IgniteFileSystem) ite.next(); 38 | 39 | LOGGER.info("IGFS File System name:" + igniteFileSystem.name()); 40 | } 41 | 42 | IgniteFileSystem igfs = ignite.fileSystem(IGFS_FS_NAME); 43 | // Create directory. 44 | IgfsPath dir = new IgfsPath("/" + args[0]); 45 | igfs.mkdirs(dir); 46 | 47 | // Create file and write some data to it. 48 | IgfsPath file = new IgfsPath(dir, args[1]); 49 | // Read the File Shakespeare 50 | InputStream inputStream = IngestFileInIGFS.class.getClassLoader().getResourceAsStream("t8.shakespeare.txt"); 51 | 52 | byte[] filesToByte; 53 | try { 54 | filesToByte = ByteStreams.toByteArray(inputStream); 55 | OutputStream out = igfs.create(file, true); 56 | 57 | out.write(filesToByte); 58 | out.close(); 59 | 60 | } catch (IOException e) { 61 | LOGGER.error(e.getMessage()); 62 | } finally { 63 | try { 64 | inputStream.close(); 65 | } catch (IOException e) { 66 | LOGGER.error(e.getMessage()); 67 | } 68 | } 69 | 70 | LOGGER.info("Created file path:" + file.toString()); 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /chapters/chapter-bigdata/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /chapters/chapter-bigdata/src/main/statistics/inmemory.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/srecon/ignite-book-code-samples/34eb1453a2a39b96e3bcbdafb5fa89f96018e775/chapters/chapter-bigdata/src/main/statistics/inmemory.xlsx -------------------------------------------------------------------------------- /chapters/chapter-caching/hibernate/scripts/emp-dept.ddl: -------------------------------------------------------------------------------- 1 | create table dept( 2 | deptno integer, 3 | dname text, 4 | loc text, 5 | constraint pk_dept primary key (deptno) 6 | ); 7 | 8 | create table emp( 9 | empno integer, 10 | ename text, 11 | job text, 12 | mgr integer, 13 | hiredate date, 14 | sal integer, 15 | comm integer, 16 | deptno integer, 17 | constraint pk_emp primary key (empno), 18 | constraint fk_deptno foreign key (deptno) references dept (deptno) 19 | ); 20 | 21 | CREATE UNIQUE INDEX ename_idx ON emp (ename); -------------------------------------------------------------------------------- /chapters/chapter-caching/hibernate/scripts/emp-dept.dml: -------------------------------------------------------------------------------- 1 | insert into dept 2 | values(10, 'ACCOUNTING', 'NEW YORK'); 3 | insert into dept 4 | values(20, 'RESEARCH', 'DALLAS'); 5 | insert into dept 6 | values(30, 'SALES', 'CHICAGO'); 7 | insert into dept 8 | values(40, 'OPERATIONS', 'BOSTON'); 9 | 10 | insert into emp 11 | values( 12 | 7839, 'KING', 'PRESIDENT', null, 13 | to_date('17-11-1981','dd-mm-yyyy'), 14 | 5000, null, 10 15 | ); 16 | insert into emp 17 | values( 18 | 7698, 'BLAKE', 'MANAGER', 7839, 19 | to_date('1-5-1981','dd-mm-yyyy'), 20 | 2850, null, 30 21 | ); 22 | insert into emp 23 | values( 24 | 7782, 'CLARK', 'MANAGER', 7839, 25 | to_date('9-6-1981','dd-mm-yyyy'), 26 | 2450, null, 10 27 | ); 28 | insert into emp 29 | values( 30 | 7566, 'JONES', 'MANAGER', 7839, 31 | to_date('2-4-1981','dd-mm-yyyy'), 32 | 2975, null, 20 33 | ); 34 | insert into emp 35 | values( 36 | 7788, 'SCOTT', 'ANALYST', 7566, 37 | to_date('13-07-87','dd-mm-rr') - 85, 38 | 3000, null, 20 39 | ); 40 | insert into emp 41 | values( 42 | 7902, 'FORD', 'ANALYST', 7566, 43 | to_date('3-12-1981','dd-mm-yyyy'), 44 | 3000, null, 20 45 | ); 46 | insert into emp 47 | values( 48 | 7369, 'SMITH', 'CLERK', 7902, 49 | to_date('17-12-1980','dd-mm-yyyy'), 50 | 800, null, 20 51 | ); 52 | insert into emp 53 | values( 54 | 7499, 'ALLEN', 'SALESMAN', 7698, 55 | to_date('20-2-1981','dd-mm-yyyy'), 56 | 1600, 300, 30 57 | ); 58 | insert into emp 59 | values( 60 | 7521, 'WARD', 'SALESMAN', 7698, 61 | to_date('22-2-1981','dd-mm-yyyy'), 62 | 1250, 500, 30 63 | ); 64 | insert into emp 65 | values( 66 | 7654, 'MARTIN', 'SALESMAN', 7698, 67 | to_date('28-9-1981','dd-mm-yyyy'), 68 | 1250, 1400, 30 69 | ); 70 | insert into emp 71 | values( 72 | 7844, 'TURNER', 'SALESMAN', 7698, 73 | to_date('8-9-1981','dd-mm-yyyy'), 74 | 1500, 0, 30 75 | ); 76 | insert into emp 77 | values( 78 | 7876, 'ADAMS', 'CLERK', 7788, 79 | to_date('13-07-87', 'dd-mm-rr') - 51, 80 | 1100, null, 20 81 | ); 82 | insert into emp 83 | values( 84 | 7900, 'JAMES', 'CLERK', 7698, 85 | to_date('3-12-1981','dd-mm-yyyy'), 86 | 950, null, 30 87 | ); 88 | insert into emp 89 | values( 90 | 7934, 'MILLER', 'CLERK', 7782, 91 | to_date('23-1-1982','dd-mm-yyyy'), 92 | 1300, null, 10 93 | ); 94 | 95 | 96 | commit; -------------------------------------------------------------------------------- /chapters/chapter-caching/hibernate/scripts/exc-rate.ddl: -------------------------------------------------------------------------------- 1 | create table exchangerate( 2 | ratedate date, 3 | usdollar decimal, 4 | euro decimal, 5 | gbp decimal, 6 | region text, 7 | primary key (ratedate, region) 8 | ); -------------------------------------------------------------------------------- /chapters/chapter-caching/hibernate/scripts/exc-rate.dml: -------------------------------------------------------------------------------- 1 | INSERT INTO public.exchangerate (ratedate,usdollar,euro,gbp,region) VALUES ( 2 | TO_DATE('2015-05-01','YYYY-MM-DD'),69.7,75.9,103.01,'Vladimir'); 3 | INSERT INTO public.exchangerate (ratedate,usdollar,euro,gbp,region) VALUES ( 4 | TO_DATE('2015-05-02','YYYY-MM-DD'),71.7,77.1,102.03,'Tver'); 5 | INSERT INTO public.exchangerate (ratedate,usdollar,euro,gbp,region) VALUES ( 6 | TO_DATE('2015-05-02','YYYY-MM-DD'),71.7,77.1,102.03,'Moscow'); 7 | INSERT INTO public.exchangerate (ratedate,usdollar,euro,gbp,region) VALUES ( 8 | TO_DATE('2015-05-02','YYYY-MM-DD'),71.7,77.1,102.03,'Vladimir'); 9 | INSERT INTO public.exchangerate (ratedate,usdollar,euro,gbp,region) VALUES ( 10 | TO_DATE('2015-05-03','YYYY-MM-DD'),71.9,77.4,101.03,'Tver'); 11 | INSERT INTO public.exchangerate (ratedate,usdollar,euro,gbp,region) VALUES ( 12 | TO_DATE('2015-05-03','YYYY-MM-DD'),70.3,76.1,103.07,'Moscow'); 13 | INSERT INTO public.exchangerate (ratedate,usdollar,euro,gbp,region) VALUES ( 14 | TO_DATE('2015-05-03','YYYY-MM-DD'),71.1,77.4,101.01,'Vladimir'); 15 | commit; -------------------------------------------------------------------------------- /chapters/chapter-caching/hibernate/src/main/java/com/blu/imdg/Run.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg; 2 | 3 | import com.blu.imdg.dao.EmpDao; 4 | import com.blu.imdg.dto.Employee; 5 | import com.blu.imdg.dto.ExchangeRate; 6 | import org.springframework.context.ApplicationContext; 7 | import org.springframework.context.support.ClassPathXmlApplicationContext; 8 | 9 | import java.util.Date; 10 | import java.util.List; 11 | 12 | /** 13 | * Created by shamim on 24/06/16. 14 | */ 15 | public class Run { 16 | public static void main(String[] args) { 17 | System.out.println("Hello Hibernate after a long time!!"); 18 | ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-core.xml"); 19 | EmpDao empDao = (EmpDao) ctx.getBean("empDAO"); 20 | //List employee = empDao.getAllEmployees(); 21 | //String res = empDao.getExchangeRateByRegion("Moscow"); 22 | ExchangeRate e = new ExchangeRate(); 23 | e.setRegion("Moscow"); 24 | e.setRateDate(new Date(System.currentTimeMillis())); 25 | e.setUsdollar(71.17); 26 | empDao.updateExchange(e); 27 | System.out.println("return size:"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /chapters/chapter-caching/hibernate/src/main/java/com/blu/imdg/RunWebService.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg; 2 | 3 | import com.blu.imdg.ws.WebService; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.support.ClassPathXmlApplicationContext; 6 | 7 | import javax.xml.ws.Endpoint; 8 | 9 | /** 10 | * Created by shamim on 24/06/16. 11 | */ 12 | public class RunWebService { 13 | public static void main(String[] args) { 14 | ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-core.xml"); 15 | WebService service = (WebService) ctx.getBean("serviceBean"); 16 | 17 | Endpoint.publish("http://localhost:7001/invokeRules", service); 18 | System.out.println("Server start in Port .. 7001"); 19 | } 20 | } -------------------------------------------------------------------------------- /chapters/chapter-caching/hibernate/src/main/java/com/blu/imdg/dao/EmpDao.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.dao; 2 | 3 | import com.blu.imdg.dto.Employee; 4 | import com.blu.imdg.dto.ExchangeRate; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by shamim on 24/06/16. 10 | */ 11 | public interface EmpDao { 12 | List getAllEmployees (); 13 | void create(Integer empno, String ename, String job, Integer mgr ); 14 | List getEmpByName(String ename); 15 | String getExchangeRateByRegion(String region); 16 | void updateExchange(ExchangeRate e); 17 | } 18 | -------------------------------------------------------------------------------- /chapters/chapter-caching/hibernate/src/main/java/com/blu/imdg/dto/Employee.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.dto; 2 | 3 | 4 | import org.hibernate.annotations.CacheConcurrencyStrategy; 5 | 6 | import javax.persistence.*; 7 | import java.io.Serializable; 8 | import java.util.Date; 9 | import org.hibernate.annotations.Cache; 10 | import org.hibernate.annotations.CacheConcurrencyStrategy; 11 | /** 12 | * Created by shamim on 23/06/16. 13 | */ 14 | @Entity 15 | @Cacheable 16 | @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) 17 | @Table( name = "emp" ) 18 | public class Employee implements Serializable{ 19 | @Id 20 | //@GeneratedValue(strategy = GenerationType.IDENTITY) 21 | @Column(name = "empno") 22 | private Integer empno; 23 | @Column(name = "ename") 24 | private String ename; 25 | @Column(name = "job") 26 | private String job; 27 | @Column(name = "mgr") 28 | private Integer mgr; 29 | @Column(name = "hiredate") 30 | private Date date; 31 | @Column(name = "sal") 32 | private Integer sal; 33 | @Column(name = "deptno") 34 | private Integer deptno; 35 | @Column(name = "comm") 36 | private Integer comm; 37 | 38 | public Employee() { 39 | } 40 | 41 | public Integer getEmpno() { 42 | return empno; 43 | } 44 | 45 | public void setEmpno(Integer empno) { 46 | this.empno = empno; 47 | } 48 | 49 | public String getEname() { 50 | return ename; 51 | } 52 | 53 | public void setEname(String ename) { 54 | this.ename = ename; 55 | } 56 | 57 | public String getJob() { 58 | return job; 59 | } 60 | 61 | public void setJob(String job) { 62 | this.job = job; 63 | } 64 | 65 | public Integer getMgr() { 66 | return mgr; 67 | } 68 | 69 | public void setMgr(Integer mgr) { 70 | this.mgr = mgr; 71 | } 72 | 73 | public Date getDate() { 74 | return date; 75 | } 76 | 77 | public void setDate(Date date) { 78 | this.date = date; 79 | } 80 | 81 | public Integer getSal() { 82 | return sal; 83 | } 84 | 85 | public void setSal(Integer sal) { 86 | this.sal = sal; 87 | } 88 | 89 | public Integer getDeptno() { 90 | return deptno; 91 | } 92 | 93 | public void setDeptno(Integer deptno) { 94 | this.deptno = deptno; 95 | } 96 | 97 | public Integer getComm() { 98 | return comm; 99 | } 100 | 101 | public void setComm(Integer comm) { 102 | this.comm = comm; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /chapters/chapter-caching/hibernate/src/main/java/com/blu/imdg/dto/ExchangeRate.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.dto; 2 | 3 | import org.hibernate.annotations.Cache; 4 | import org.hibernate.annotations.CacheConcurrencyStrategy; 5 | 6 | import javax.persistence.*; 7 | import java.util.Date; 8 | 9 | /** 10 | * User: bsha 11 | * Date: 03.07.2016 12 | * Time: 10:29 13 | */ 14 | @Entity 15 | @Table( name = "emp" ) 16 | public class ExchangeRate { 17 | @Id 18 | @Column(name = "region") 19 | private String region; 20 | @Column(name = "ratedate") 21 | private Date rateDate; 22 | @Column(name = "usdollar") 23 | private double usdollar; 24 | @Column(name = "euro") 25 | private double euro; 26 | @Column(name = "gbp") 27 | private double gbp; 28 | 29 | public ExchangeRate() { 30 | } 31 | 32 | public String getRegion() { 33 | return region; 34 | } 35 | 36 | public void setRegion(String region) { 37 | this.region = region; 38 | } 39 | 40 | public Date getRateDate() { 41 | return rateDate; 42 | } 43 | 44 | public void setRateDate(Date rateDate) { 45 | this.rateDate = rateDate; 46 | } 47 | 48 | public double getUsdollar() { 49 | return usdollar; 50 | } 51 | 52 | public void setUsdollar(double usdollar) { 53 | this.usdollar = usdollar; 54 | } 55 | 56 | public double getEuro() { 57 | return euro; 58 | } 59 | 60 | public void setEuro(double euro) { 61 | this.euro = euro; 62 | } 63 | 64 | public double getGbp() { 65 | return gbp; 66 | } 67 | 68 | public void setGbp(double gbp) { 69 | this.gbp = gbp; 70 | } 71 | 72 | @Override 73 | public boolean equals(Object o) { 74 | if (this == o) return true; 75 | if (o == null || getClass() != o.getClass()) return false; 76 | 77 | ExchangeRate that = (ExchangeRate) o; 78 | 79 | if (!rateDate.equals(that.rateDate)) return false; 80 | if (!region.equals(that.region)) return false; 81 | 82 | return true; 83 | } 84 | 85 | @Override 86 | public int hashCode() { 87 | int result = region.hashCode(); 88 | result = 31 * result + rateDate.hashCode(); 89 | return result; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /chapters/chapter-caching/hibernate/src/main/java/com/blu/imdg/ws/WebService.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.ws; 2 | 3 | import com.blu.imdg.dao.EmpDao; 4 | import com.blu.imdg.dto.Employee; 5 | import com.blu.imdg.dto.ExchangeRate; 6 | 7 | import javax.jws.WebMethod; 8 | import java.util.Date; 9 | import java.util.List; 10 | 11 | /** 12 | * Created by shamim on 24/06/16. 13 | */ 14 | @javax.jws.WebService(name = "BusinessRulesServices", 15 | serviceName="BusinessRulesServices", 16 | targetNamespace = "http://com.blu.rules/services") 17 | public class WebService { 18 | private EmpDao empDao; 19 | 20 | @WebMethod(exclude = true) 21 | public void setEmpDao(EmpDao empDao) { 22 | this.empDao = empDao; 23 | } 24 | @WebMethod(operationName = "getAllEmploees") 25 | public List getAllEmployees() { 26 | return empDao.getAllEmployees(); 27 | } 28 | @WebMethod(operationName = "addEmployee") 29 | public void addEmployee(Integer empno, String ename, String job, Integer mgr ) { 30 | empDao.create(empno, ename, job, mgr); 31 | } 32 | @WebMethod(operationName = "getEmpByName") 33 | public List getEmpByName(String ename) { 34 | return empDao.getEmpByName(ename); 35 | } 36 | @WebMethod(operationName = "getExchangeRateByRegion") 37 | public String getExchangeRateByRegion(String str){ 38 | return empDao.getExchangeRateByRegion(str); 39 | } 40 | @WebMethod(operationName = "updateExchangeRate") 41 | public void updateExchangeRate(String region, Date rateDate, double usdollar, double euro, double gbp){ 42 | ExchangeRate e = new ExchangeRate(); 43 | e.setRegion(region); 44 | e.setUsdollar(usdollar); 45 | e.setEuro(euro); 46 | e.setGbp(gbp); 47 | e.setRateDate(rateDate); 48 | 49 | empDao.updateExchange(e); 50 | } 51 | } 52 | 53 | -------------------------------------------------------------------------------- /chapters/chapter-caching/hibernate/src/main/resources/jdbc.properties: -------------------------------------------------------------------------------- 1 | jdbc.driver=org.postgresql.Driver 2 | jdbc.url=jdbc:postgresql://192.168.9.78:5432/trudvsem_db 3 | jdbc.username=postgres 4 | jdbc.password=unix11 5 | -------------------------------------------------------------------------------- /chapters/chapter-caching/mybatis/scripts/emp-dept.ddl: -------------------------------------------------------------------------------- 1 | create table dept( 2 | deptno integer, 3 | dname text, 4 | loc text, 5 | constraint pk_dept primary key (deptno) 6 | ); 7 | 8 | create table emp( 9 | empno integer, 10 | ename text, 11 | job text, 12 | mgr integer, 13 | hiredate date, 14 | sal integer, 15 | comm integer, 16 | deptno integer, 17 | constraint pk_emp primary key (empno), 18 | constraint fk_deptno foreign key (deptno) references dept (deptno) 19 | ); 20 | 21 | CREATE UNIQUE INDEX ename_idx ON emp (ename); -------------------------------------------------------------------------------- /chapters/chapter-caching/mybatis/scripts/emp-dept.dml: -------------------------------------------------------------------------------- 1 | insert into dept 2 | values(10, 'ACCOUNTING', 'NEW YORK'); 3 | insert into dept 4 | values(20, 'RESEARCH', 'DALLAS'); 5 | insert into dept 6 | values(30, 'SALES', 'CHICAGO'); 7 | insert into dept 8 | values(40, 'OPERATIONS', 'BOSTON'); 9 | 10 | insert into emp 11 | values( 12 | 7839, 'KING', 'PRESIDENT', null, 13 | to_date('17-11-1981','dd-mm-yyyy'), 14 | 5000, null, 10 15 | ); 16 | insert into emp 17 | values( 18 | 7698, 'BLAKE', 'MANAGER', 7839, 19 | to_date('1-5-1981','dd-mm-yyyy'), 20 | 2850, null, 30 21 | ); 22 | insert into emp 23 | values( 24 | 7782, 'CLARK', 'MANAGER', 7839, 25 | to_date('9-6-1981','dd-mm-yyyy'), 26 | 2450, null, 10 27 | ); 28 | insert into emp 29 | values( 30 | 7566, 'JONES', 'MANAGER', 7839, 31 | to_date('2-4-1981','dd-mm-yyyy'), 32 | 2975, null, 20 33 | ); 34 | insert into emp 35 | values( 36 | 7788, 'SCOTT', 'ANALYST', 7566, 37 | to_date('13-07-87','dd-mm-rr') - 85, 38 | 3000, null, 20 39 | ); 40 | insert into emp 41 | values( 42 | 7902, 'FORD', 'ANALYST', 7566, 43 | to_date('3-12-1981','dd-mm-yyyy'), 44 | 3000, null, 20 45 | ); 46 | insert into emp 47 | values( 48 | 7369, 'SMITH', 'CLERK', 7902, 49 | to_date('17-12-1980','dd-mm-yyyy'), 50 | 800, null, 20 51 | ); 52 | insert into emp 53 | values( 54 | 7499, 'ALLEN', 'SALESMAN', 7698, 55 | to_date('20-2-1981','dd-mm-yyyy'), 56 | 1600, 300, 30 57 | ); 58 | insert into emp 59 | values( 60 | 7521, 'WARD', 'SALESMAN', 7698, 61 | to_date('22-2-1981','dd-mm-yyyy'), 62 | 1250, 500, 30 63 | ); 64 | insert into emp 65 | values( 66 | 7654, 'MARTIN', 'SALESMAN', 7698, 67 | to_date('28-9-1981','dd-mm-yyyy'), 68 | 1250, 1400, 30 69 | ); 70 | insert into emp 71 | values( 72 | 7844, 'TURNER', 'SALESMAN', 7698, 73 | to_date('8-9-1981','dd-mm-yyyy'), 74 | 1500, 0, 30 75 | ); 76 | insert into emp 77 | values( 78 | 7876, 'ADAMS', 'CLERK', 7788, 79 | to_date('13-07-87', 'dd-mm-rr') - 51, 80 | 1100, null, 20 81 | ); 82 | insert into emp 83 | values( 84 | 7900, 'JAMES', 'CLERK', 7698, 85 | to_date('3-12-1981','dd-mm-yyyy'), 86 | 950, null, 30 87 | ); 88 | insert into emp 89 | values( 90 | 7934, 'MILLER', 'CLERK', 7782, 91 | to_date('23-1-1982','dd-mm-yyyy'), 92 | 1300, null, 10 93 | ); 94 | 95 | 96 | commit; -------------------------------------------------------------------------------- /chapters/chapter-caching/mybatis/src/main/java/com/blu/imdg/RunWebService.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.support.ClassPathXmlApplicationContext; 5 | 6 | import javax.xml.ws.Endpoint; 7 | 8 | /** 9 | * Created by shamim on 14/02/16. 10 | */ 11 | public class RunWebService { 12 | public static void main(String[] args) { 13 | ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-core.xml"); 14 | WebServices services = (WebServices) ctx.getBean("servicesBean"); 15 | 16 | Endpoint.publish("http://localhost:7001/invokeRules", services); 17 | System.out.println("Server start in Port .. 7001"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /chapters/chapter-caching/mybatis/src/main/java/com/blu/imdg/WebServices.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg; 2 | 3 | import com.blu.imdg.dao.UserServices; 4 | import com.blu.imdg.dto.Employee; 5 | 6 | import javax.jws.WebMethod; 7 | import javax.jws.WebService; 8 | 9 | /** 10 | * Created by shamim on 14/02/16. 11 | */ 12 | @WebService(name = "BusinessRulesServices", 13 | serviceName="BusinessRulesServices", 14 | targetNamespace = "http://com.blu.rules/services") 15 | public class WebServices { 16 | private UserServices userServices; 17 | 18 | @WebMethod(exclude = true) 19 | public void setDao(UserServices userServices){ 20 | this.userServices = userServices; 21 | } 22 | 23 | @WebMethod(operationName = "getEmploee") 24 | public Employee getEmploee (String ename) {return userServices.getEmploee(ename);} 25 | 26 | } 27 | -------------------------------------------------------------------------------- /chapters/chapter-caching/mybatis/src/main/java/com/blu/imdg/dao/UserServices.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.dao; 2 | 3 | import com.blu.imdg.dto.Employee; 4 | import com.blu.imdg.mapper.UserMapper; 5 | import org.springframework.cache.annotation.Cacheable; 6 | 7 | /** 8 | * Created by shamim on 16/02/16. 9 | */ 10 | public class UserServices { 11 | private UserMapper userMapper; 12 | 13 | public void setUserMapper(UserMapper userMapper) { 14 | this.userMapper = userMapper; 15 | } 16 | 17 | public Employee getEmploee (String ename){return userMapper.getEmploee(ename);} 18 | } 19 | -------------------------------------------------------------------------------- /chapters/chapter-caching/mybatis/src/main/java/com/blu/imdg/dto/Employee.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.dto; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | /** 7 | * Created by shamim on 23/06/16. 8 | */ 9 | public class Employee implements Serializable{ 10 | private Integer empno; 11 | private String ename; 12 | private String job; 13 | private Integer mgr; 14 | private Date date; 15 | private Integer sal; 16 | private Integer deptno; 17 | 18 | public Integer getEmpno() { 19 | return empno; 20 | } 21 | 22 | public void setEmpno(Integer empno) { 23 | this.empno = empno; 24 | } 25 | 26 | public String getEname() { 27 | return ename; 28 | } 29 | 30 | public void setEname(String ename) { 31 | this.ename = ename; 32 | } 33 | 34 | public String getJob() { 35 | return job; 36 | } 37 | 38 | public void setJob(String job) { 39 | this.job = job; 40 | } 41 | 42 | public Integer getMgr() { 43 | return mgr; 44 | } 45 | 46 | public void setMgr(Integer mgr) { 47 | this.mgr = mgr; 48 | } 49 | 50 | public Date getDate() { 51 | return date; 52 | } 53 | 54 | public void setDate(Date date) { 55 | this.date = date; 56 | } 57 | 58 | public Integer getSal() { 59 | return sal; 60 | } 61 | 62 | public void setSal(Integer sal) { 63 | this.sal = sal; 64 | } 65 | 66 | public Integer getDeptno() { 67 | return deptno; 68 | } 69 | 70 | public void setDeptno(Integer deptno) { 71 | this.deptno = deptno; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /chapters/chapter-caching/mybatis/src/main/java/com/blu/imdg/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.mapper; 2 | 3 | import com.blu.imdg.dto.Employee; 4 | 5 | /** 6 | * Created by shamim on 15/02/16. 7 | */ 8 | public interface UserMapper { 9 | 10 | Employee getEmploee (String ename); 11 | } 12 | -------------------------------------------------------------------------------- /chapters/chapter-caching/mybatis/src/main/resources/com/blu/imdg/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | 13 | 14 | -------------------------------------------------------------------------------- /chapters/chapter-caching/mybatis/src/main/resources/jdbc.properties: -------------------------------------------------------------------------------- 1 | jdbc.driver=org.postgresql.Driver 2 | jdbc.url=jdbc:postgresql://192.168.9.78:5432/trudvsem_db 3 | jdbc.username=postgres 4 | jdbc.password=unix11 5 | -------------------------------------------------------------------------------- /chapters/chapter-caching/offheap/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.blu.imdg 8 | chapters 9 | 1.0-SNAPSHOT 10 | ../../parent 11 | 12 | com.blu.imdg 13 | offheap 14 | 1.0-SNAPSHOT 15 | offheap 16 | http://maven.apache.org 17 | 18 | UTF-8 19 | 20 | 21 | 22 | org.apache.ignite 23 | ignite-core 24 | 25 | 26 | org.apache.ignite 27 | ignite-spring 28 | 29 | 30 | 31 | 32 | 33 | org.apache.maven.plugins 34 | maven-jar-plugin 35 | 36 | 37 | 38 | com.blu.imdg.PutElementstoOffHeap 39 | 40 | 41 | 42 | 43 | 44 | com.jolira 45 | onejar-maven-plugin 46 | 1.4.4 47 | 48 | 49 | 50 | one-jar 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | onejar-maven-plugin.googlecode.com 61 | http://onejar-maven-plugin.googlecode.com/svn/mavenrepo 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /chapters/chapter-caching/offheap/src/main/java/com/blu/imdg/PutElementstoOffHeap.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg; 2 | 3 | import org.apache.ignite.Ignite; 4 | import org.apache.ignite.IgniteCache; 5 | import org.apache.ignite.Ignition; 6 | import org.apache.ignite.configuration.IgniteConfiguration; 7 | import org.springframework.context.ApplicationContext; 8 | import org.springframework.context.support.ClassPathXmlApplicationContext; 9 | 10 | /** 11 | * User: bsha 12 | * Date: 03.07.2016 13 | * Time: 17:58 14 | */ 15 | public class PutElementstoOffHeap { 16 | public static void main(String[] args) throws Exception{ 17 | if(args.length <= 0){ 18 | System.out.println("Usages! java -jar .\\target\\chapter-three-offheap-1.0-SNAPSHOT.one-jar.jar spring-offheap-tiered.xml"); 19 | System.exit(0); 20 | } 21 | String springCoreFile = args[0]; 22 | // Start Ignite cluster 23 | Ignite ignite = Ignition.start(springCoreFile); 24 | // get or create cache 25 | IgniteCache cache = ignite.getOrCreateCache("offheap-cache"); 26 | for(int i = 1; i <= 1000; i++){ 27 | cache.put(i, Integer.toString(i)); 28 | } 29 | for(int i =1; i<=1000;i++){ 30 | System.out.println("Cache get:"+ cache.get(i)); 31 | } 32 | System.out.println("Wait 10 seconds for statistics"); 33 | Thread.sleep(10000); 34 | // statistics 35 | System.out.println("Cache Hits:"+ cache.metrics(ignite.cluster()).getCacheHits()); 36 | 37 | System.out.println("Enter crtl-x to quite the application!!!"); 38 | Thread.sleep(Integer.MAX_VALUE); // sleep for 20 seconds 39 | 40 | ignite.close(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /chapters/chapter-caching/web-session-clustering/README: -------------------------------------------------------------------------------- 1 | mvn -Djetty.port=8080 jetty:run 2 | 3 | http://localhost:8080/test-session/putperson?name=shamim&age=38 4 | http://localhost:8081/test-session/getperson?name=shamim 5 | -------------------------------------------------------------------------------- /chapters/chapter-caching/web-session-clustering/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 4.0.0 6 | 7 | com.blu.imdg 8 | chapters 9 | 1.0-SNAPSHOT 10 | ../../parent 11 | 12 | com.blu.imdg 13 | web-session-clustering 14 | war 15 | 1.0.0 16 | web-session-clustering 17 | 18 | 19 | 4.1.0.RELEASE 20 | 1.6.0 21 | UTF-8 22 | 23 | 24 | 25 | 26 | org.springframework 27 | spring-webmvc 28 | ${springframework.version} 29 | 30 | 31 | javax.servlet 32 | javax.servlet-api 33 | 3.1.0 34 | 35 | 36 | javax.servlet.jsp 37 | javax.servlet.jsp-api 38 | 2.3.1 39 | 40 | 41 | javax.servlet 42 | jstl 43 | 1.2 44 | 45 | 46 | 47 | org.apache.ignite 48 | ignite-core 49 | 50 | 51 | org.apache.ignite 52 | ignite-web 53 | ${ignite.version} 54 | 55 | 56 | org.apache.ignite 57 | ignite-log4j 58 | 59 | 60 | org.apache.ignite 61 | ignite-spring 62 | 63 | 64 | 65 | WebSessionClustering 66 | 67 | 68 | org.eclipse.jetty 69 | jetty-maven-plugin 70 | 9.2.11.v20150529 71 | 72 | 10 73 | 74 | /test-session 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /chapters/chapter-caching/web-session-clustering/src/main/java/com/blu/imdg/wsession/bean/Person.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.wsession.bean; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by shamim on 07/07/16. 7 | */ 8 | public class Person implements Serializable{ 9 | private String firstName; 10 | private int age; 11 | 12 | public Person(String firstName) { 13 | this.firstName = firstName; 14 | } 15 | 16 | public Person() { 17 | } 18 | 19 | public String getFirstName() { 20 | return firstName; 21 | } 22 | 23 | public void setFirstName(String firstName) { 24 | this.firstName = firstName; 25 | } 26 | 27 | public int getAge() { 28 | return age; 29 | } 30 | 31 | public void setAge(int age) { 32 | this.age = age; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapters/chapter-caching/web-session-clustering/src/main/java/com/blu/imdg/wsession/controller/WebSessionController.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.wsession.controller; 2 | 3 | import com.blu.imdg.wsession.bean.Person; 4 | import org.springframework.context.annotation.Scope; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.ui.ModelMap; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestMethod; 9 | import org.springframework.web.bind.annotation.SessionAttributes; 10 | 11 | import javax.servlet.http.HttpServletRequest; 12 | 13 | @Controller 14 | @RequestMapping("/") 15 | public class WebSessionController { 16 | 17 | @RequestMapping(value="/putperson", method = RequestMethod.GET) 18 | public String putSession(ModelMap model, HttpServletRequest request) { 19 | model.addAttribute("person", "Add Person to user session"); 20 | String fName = request.getParameter("name"); 21 | int age = Integer.valueOf(request.getParameter("age")); 22 | Person person = new Person(); 23 | person.setFirstName(fName); 24 | person.setAge(age); 25 | // set user session data 26 | request.getSession().setAttribute(fName, person); 27 | // return to the welcome.jsp view 28 | return "welcome"; 29 | } 30 | 31 | @RequestMapping(value="/getperson", method = RequestMethod.GET) 32 | public String getSession(ModelMap model, HttpServletRequest request) { 33 | String fName = request.getParameter("name"); 34 | // get session data 35 | model.addAttribute("person", request.getSession().getAttribute(fName) != null ? "Age: " + ((Person) request.getSession().getAttribute(fName)).getAge() : " Unknown"); 36 | // view welcome.jsp 37 | return "welcome"; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /chapters/chapter-caching/web-session-clustering/src/main/webapp/WEB-INF/spring-servlet.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | /WEB-INF/views/ 19 | 20 | 21 | .jsp 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /chapters/chapter-caching/web-session-clustering/src/main/webapp/WEB-INF/views/welcome.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | 4 | 5 | 6 | 7 | Web session clustering example 8 | 9 | 10 | Data : ${person} 11 | 12 | -------------------------------------------------------------------------------- /chapters/chapter-caching/web-session-clustering/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | Ignite web session clustering example 8 | 9 | org.apache.ignite.startup.servlet.ServletContextListenerStartup 10 | 11 | 12 | 13 | dispatcher 14 | 15 | org.springframework.web.servlet.DispatcherServlet 16 | 17 | 18 | contextConfigLocation 19 | 20 | /WEB-INF/spring-servlet.xml 21 | 22 | 1 23 | 24 | 25 | 26 | dispatcher 27 | / 28 | 29 | 30 | 31 | 32 | IgniteWebSessionsFilter 33 | org.apache.ignite.cache.websession.WebSessionFilter 34 | 35 | 36 | IgniteWebSessionsFilter 37 | /* 38 | 39 | 40 | 41 | IgniteConfigurationFilePath 42 | spring-ignite-cache.xml 43 | 44 | 45 | 46 | IgniteWebSessionsCacheName 47 | session-cache 48 | 49 | 50 | IgniteWebSessionsGridName 51 | session-grid 52 | 53 | -------------------------------------------------------------------------------- /chapters/chapter-cep/camel/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chapters/chapter-cep/camel/src/main/java/com/blu/imdg/ExampleNodeStartup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.blu.imdg; 19 | 20 | import org.apache.ignite.IgniteException; 21 | import org.apache.ignite.Ignition; 22 | 23 | /** 24 | * Starts up an empty node with example compute configuration. 25 | */ 26 | public class ExampleNodeStartup { 27 | /** 28 | * Start up an empty node with example compute configuration. 29 | * 30 | * @param args Command line arguments, none required. 31 | * @throws IgniteException If failed. 32 | */ 33 | public static void main(String[] args) throws IgniteException { 34 | // use same ignite configuration 35 | Ignition.start("example-ignite.xml"); 36 | } 37 | } -------------------------------------------------------------------------------- /chapters/chapter-cep/camel/src/main/java/com/blu/imdg/dto/Alert.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.dto; 2 | 3 | import org.apache.ignite.cache.query.annotations.QuerySqlField; 4 | 5 | /** 6 | * Created by shamim on 05/08/16. 7 | */ 8 | public class Alert { 9 | @QuerySqlField(index = true) 10 | private String serviceName; 11 | @QuerySqlField(index = true) 12 | private Level alertLevel; 13 | 14 | public Alert(String serviceName, Level alertLevel) { 15 | this.serviceName = serviceName; 16 | this.alertLevel = alertLevel; 17 | } 18 | 19 | public Level getAlertLevel() { 20 | return alertLevel; 21 | } 22 | 23 | public void setAlertLevel(Level alertLevel) { 24 | this.alertLevel = alertLevel; 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return "Alert{" + 30 | "serviceName='" + serviceName + '\'' + 31 | ", alertLevel='" + alertLevel + '\'' + 32 | '}'; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapters/chapter-cep/camel/src/main/java/com/blu/imdg/dto/Level.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.dto; 2 | 3 | /** 4 | * Created by shamim on 05/08/16. 5 | */ 6 | public enum Level { 7 | GREEN, 8 | YELLOW, 9 | RED 10 | } 11 | -------------------------------------------------------------------------------- /chapters/chapter-cep/camel/src/main/java/com/blu/imdg/dto/MnpRouting.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.dto; 2 | 3 | import org.apache.ignite.cache.query.annotations.QuerySqlField; 4 | 5 | /** 6 | * User: bsha 7 | * Date: 07.08.2016 8 | * Time: 15:29 9 | */ 10 | public class MnpRouting { 11 | @QuerySqlField(index = true) 12 | private String telephone; 13 | @QuerySqlField(index = true) 14 | private long credit; 15 | @QuerySqlField(index = true) 16 | private String routeTo; 17 | 18 | public String getTelephone() { 19 | return telephone; 20 | } 21 | 22 | public void setTelephone(String telephone) { 23 | this.telephone = telephone; 24 | } 25 | 26 | public long getCredit() { 27 | return credit; 28 | } 29 | 30 | public void setCredit(long credit) { 31 | this.credit = credit; 32 | } 33 | 34 | public String getRouteTo() { 35 | return routeTo; 36 | } 37 | 38 | public void setRouteTo(String routeTo) { 39 | this.routeTo = routeTo; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return "Routing {" + 45 | "telephone='" + telephone + '\'' + 46 | ", credit=" + credit + 47 | ", routeTo='" + routeTo + '\'' + 48 | '}'; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /chapters/chapter-cep/camel/src/main/java/com/blu/imdg/dto/ServiceStatus.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.dto; 2 | 3 | import org.apache.ignite.cache.query.annotations.QuerySqlField; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * Created by shamim on 04/08/16. 9 | */ 10 | public class ServiceStatus implements Serializable{ 11 | @QuerySqlField(index = true) 12 | private String serviceName; 13 | @QuerySqlField(index = true) 14 | private int statusCode; 15 | @QuerySqlField(index = true) 16 | private long responseTime; 17 | @QuerySqlField(index = true) 18 | private long unavailableCnt; 19 | @QuerySqlField(index = true) 20 | private long healthCheckCnt; 21 | 22 | public ServiceStatus(String name, int statusCode){ 23 | this.serviceName = name; 24 | this.statusCode =statusCode; 25 | } 26 | 27 | public String getServiceName() { 28 | return serviceName; 29 | } 30 | 31 | public void setServiceName(String serviceName) { 32 | this.serviceName = serviceName; 33 | } 34 | 35 | public int getStatusCode() { 36 | return statusCode; 37 | } 38 | 39 | public void setStatusCode(int statusCode) { 40 | this.statusCode = statusCode; 41 | } 42 | 43 | public long getResponseTime() { 44 | return responseTime; 45 | } 46 | 47 | public void setResponseTime(long responseTime) { 48 | this.responseTime = responseTime; 49 | } 50 | 51 | public long getUnavailableCnt() { 52 | return unavailableCnt; 53 | } 54 | 55 | public void setUnavailableCnt(long unavailableCnt) { 56 | this.unavailableCnt = unavailableCnt; 57 | } 58 | 59 | public long getHealthCheckCnt() { 60 | return healthCheckCnt; 61 | } 62 | 63 | public void setHealthCheckCnt(long healthCheckCnt) { 64 | this.healthCheckCnt = healthCheckCnt; 65 | } 66 | 67 | 68 | @Override 69 | public String toString() { 70 | return "ServiceStatus{" + 71 | "serviceName='" + serviceName + '\'' + 72 | ", statusCode=" + statusCode + 73 | ", responseTime=" + responseTime + 74 | ", unavailableCnt=" + unavailableCnt + 75 | ", healthCheckCnt=" + healthCheckCnt + 76 | '}'; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /chapters/chapter-cep/camel/src/main/java/com/blu/imdg/processor/RouteProcessor.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.processor; 2 | 3 | import com.blu.imdg.dto.MnpRouting; 4 | import org.apache.camel.Exchange; 5 | import org.apache.camel.Processor; 6 | 7 | /** 8 | * User: bsha 9 | * Date: 07.08.2016 10 | * Time: 19:31 11 | */ 12 | public class RouteProcessor implements Processor { 13 | private static final long CREDIT_LIMIT = 100l; 14 | @Override 15 | public void process(Exchange exchange) throws Exception { 16 | System.out.println("Process the bean MnpRouting!"); 17 | MnpRouting mnpRouting = (MnpRouting) exchange.getIn().getBody(); 18 | if(mnpRouting != null){ 19 | // validate phone numbers of format "1234567890" 20 | if (!mnpRouting.getTelephone().matches("\\d{11}") || mnpRouting.getCredit() < CREDIT_LIMIT){ 21 | exchange.getOut().setBody("Message doesn't pass validation"); 22 | exchange.getOut().setHeader("key", mnpRouting.getTelephone()); 23 | } else{ 24 | exchange.getOut().setBody(mnpRouting.toString()); 25 | exchange.getOut().setHeader("key", mnpRouting.getTelephone()); 26 | 27 | } 28 | 29 | } 30 | //System.out.println(mnpRouting); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /chapters/chapter-cep/camel/src/main/java/com/blu/imdg/query/AlertMonitoring.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.query; 2 | 3 | import com.blu.imdg.ExamplesUtils; 4 | import com.blu.imdg.dto.Alert; 5 | import org.apache.ignite.Ignite; 6 | import org.apache.ignite.IgniteCache; 7 | import org.apache.ignite.Ignition; 8 | import org.apache.ignite.cache.query.SqlFieldsQuery; 9 | import org.apache.ignite.configuration.CacheConfiguration; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * Created by shamim on 05/08/16. 15 | */ 16 | public class AlertMonitoring { 17 | 18 | private static final String QUERY_RED = "select alertLevel, count(alertLevel) from Alert group by alertLevel"; 19 | public static void main(String[] args) throws Exception { 20 | // Mark this cluster member as client. 21 | Ignition.setClientMode(true); 22 | 23 | try (Ignite ignite = Ignition.start("example-ignite.xml")) { 24 | if (!ExamplesUtils.hasServerNodes(ignite)) 25 | return; 26 | 27 | CacheConfiguration alert_Cfg = new CacheConfiguration<>("alerts"); 28 | IgniteCache instCache = ignite.getOrCreateCache(alert_Cfg); 29 | 30 | SqlFieldsQuery top3qry = new SqlFieldsQuery(QUERY_RED); 31 | while(true){ 32 | // Execute queries. 33 | List> top3 = instCache.query(top3qry).getAll(); 34 | 35 | System.out.println("Service Health Monitoring"); 36 | 37 | ExamplesUtils.printQueryResults(top3); 38 | 39 | Thread.sleep(1000); 40 | } 41 | 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /chapters/chapter-cep/camel/src/main/java/com/blu/imdg/query/QueryStatus.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.query; 2 | 3 | import com.blu.imdg.ExamplesUtils; 4 | import com.blu.imdg.dto.ServiceStatus; 5 | import org.apache.ignite.Ignite; 6 | import org.apache.ignite.IgniteCache; 7 | import org.apache.ignite.Ignition; 8 | import org.apache.ignite.cache.query.SqlFieldsQuery; 9 | import org.apache.ignite.configuration.CacheConfiguration; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * Created by shamim on 04/08/16. 15 | */ 16 | public class QueryStatus { 17 | private static final String QUERY_404="SELECT serviceName, statusCode from ServiceStatus where statusCode = 404"; 18 | private static final String QUERY_CNT= "select count(*) from ServiceStatus where statusCode = 404"; 19 | public static void main(String[] args) throws Exception { 20 | // Mark this cluster member as client. 21 | Ignition.setClientMode(true); 22 | 23 | try (Ignite ignite = Ignition.start("example-ignite.xml")) { 24 | if (!ExamplesUtils.hasServerNodes(ignite)) 25 | return; 26 | // query code goes here. 27 | CacheConfiguration healthchecksCfg = new CacheConfiguration<>("healthchecks"); 28 | IgniteCache instCache = ignite.getOrCreateCache(healthchecksCfg); 29 | SqlFieldsQuery query = new SqlFieldsQuery(QUERY_404); 30 | 31 | while(true){ 32 | // Execute queries. 33 | List> res = instCache.query(query).getAll(); 34 | 35 | System.out.println("Service Health check status"); 36 | 37 | ExamplesUtils.printQueryResults(res); 38 | 39 | Thread.sleep(1000); 40 | } 41 | 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /chapters/chapter-cep/camel/src/main/java/com/blu/imdg/streamer/HealthCheckStreamer.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.streamer; 2 | 3 | import com.blu.imdg.ExamplesUtils; 4 | import com.blu.imdg.dto.ServiceStatus; 5 | import org.apache.ignite.Ignite; 6 | import org.apache.ignite.IgniteCache; 7 | import org.apache.ignite.IgniteDataStreamer; 8 | import org.apache.ignite.Ignition; 9 | import org.apache.ignite.configuration.CacheConfiguration; 10 | 11 | import javax.cache.configuration.FactoryBuilder; 12 | import javax.cache.expiry.CreatedExpiryPolicy; 13 | import javax.cache.expiry.Duration; 14 | import java.util.Date; 15 | import java.util.Random; 16 | 17 | import static java.util.concurrent.TimeUnit.SECONDS; 18 | 19 | /** 20 | * Created by shamim on 04/08/16. 21 | */ 22 | public class HealthCheckStreamer { 23 | private static final Random RAND = new Random(); 24 | private static final String[] SERVICE_NAME = new String[] {"GETINN", "GETWEATHER", "GETEXCHANGERATE", "CONVERTCURRENCY", "GETPUBLICSERVICELIST", "SEARCHBRANCHES", "GETNEWSBYTOPICS"}; 25 | private static final int[] STATUS_CODE = new int[] {200, 404, 504}; 26 | 27 | public static void main(String[] args) throws Exception{ 28 | System.out.println("Streamer for service health check!!"); 29 | // Mark this cluster member as client. 30 | Ignition.setClientMode(true); 31 | try(Ignite ignite = Ignition.start("example-ignite.xml")){ 32 | if(!ExamplesUtils.hasServerNodes(ignite)) 33 | return; 34 | // healthcheck cache configuration 35 | CacheConfiguration healthcheck_cfg = new CacheConfiguration<>("healthchecks"); 36 | // set window to 5 second 37 | // Note: data will evicts after 5 seconds 38 | //healthcheck_cfg.setExpiryPolicyFactory(FactoryBuilder.factoryOf(new CreatedExpiryPolicy(new Duration(SECONDS, 15)))); 39 | // set index 40 | healthcheck_cfg.setIndexedTypes(String.class, ServiceStatus.class); 41 | 42 | IgniteCache healthCheckCache = ignite.getOrCreateCache(healthcheck_cfg); 43 | 44 | try(IgniteDataStreamer healthCheckStreamer = ignite.dataStreamer(healthCheckCache.getName())){ 45 | healthCheckStreamer.allowOverwrite(true); 46 | 47 | while(true ){ 48 | int idx_service_name = RAND.nextInt(SERVICE_NAME.length); 49 | int idx_code = RAND.nextInt(STATUS_CODE.length); 50 | ServiceStatus serviceStatus = new ServiceStatus(SERVICE_NAME[idx_service_name], STATUS_CODE[idx_code]); 51 | 52 | healthCheckStreamer.addData(SERVICE_NAME[idx_service_name], serviceStatus); 53 | } 54 | 55 | } 56 | 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /chapters/chapter-cep/camel/src/main/resources/camel.properties: -------------------------------------------------------------------------------- 1 | input.file.location=f:\\workshop\\assembla\\ignite-book\\chapters\\chapter-cep\\input?delete=true -------------------------------------------------------------------------------- /chapters/chapter-cep/camel/src/main/resources/default-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 25 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /chapters/chapter-cep/camel/src/main/resources/example-ignite.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 23 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /chapters/chapter-cep/camel/src/main/resources/input.json: -------------------------------------------------------------------------------- 1 | {"telephone" : "89096860917", "credit" : "129", "routeTo" : "MTS"} -------------------------------------------------------------------------------- /chapters/chapter-cep/flume/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.blu.imdg 8 | chapters 9 | 1.0-SNAPSHOT 10 | ../../parent 11 | 12 | com.blu.imdg 13 | flume 14 | 1.0-SNAPSHOT 15 | flume 16 | http://maven.apache.org 17 | 18 | UTF-8 19 | 20 | 21 | 22 | org.apache.ignite 23 | ignite-core 24 | 25 | 26 | org.apache.ignite 27 | ignite-spring 28 | 29 | 30 | org.apache.ignite 31 | ignite-log4j 32 | 33 | 34 | 35 | org.apache.ignite 36 | ignite-flume 37 | 38 | 39 | 40 | 41 | 42 | org.apache.maven.plugins 43 | maven-compiler-plugin 44 | 45 | 1.7 46 | 1.7 47 | 48 | 49 | 50 | com.jolira 51 | onejar-maven-plugin 52 | 1.4.4 53 | 54 | 55 | run-avro-clinet 56 | 57 | com.blu.imdg.flume.rpc.RunClient 58 | true 59 | onejar 60 | flume-avro-client.jar 61 | 62 | 63 | one-jar 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /chapters/chapter-cep/flume/src/main/java/com/blu/imdg/flume/Transformer/FlumeEventTransformer.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.flume.Transformer; 2 | 3 | import org.apache.flume.Event; 4 | import org.apache.ignite.stream.flume.EventTransformer; 5 | import org.jetbrains.annotations.Nullable; 6 | 7 | import java.util.HashMap; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | /** 12 | * User: bsha 13 | * Date: 10.08.2016 14 | * Time: 23:24 15 | */ 16 | public class FlumeEventTransformer implements EventTransformer { 17 | @Nullable 18 | @Override 19 | public Map transform(List list) { 20 | final Map map = new HashMap<>(list.size()); 21 | for(Event event : list){ 22 | map.putAll(transform(event)); 23 | } 24 | return map; 25 | } 26 | /** 27 | * Format event - String:String 28 | * example - transactionId:amount [56102:232], where transactionId is the key and amount is the value 29 | * */ 30 | private Map transform(Event event){ 31 | final Map map = new HashMap<>(); 32 | String eventBody = new String(event.getBody()); 33 | if(!eventBody.isEmpty()){ 34 | // parse the string by : 35 | String[] tokens = eventBody.split(":"); 36 | map.put(tokens[0].trim(), Integer.valueOf(tokens[1].trim())); 37 | } 38 | 39 | return map; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /chapters/chapter-cep/flume/src/main/java/com/blu/imdg/flume/config/agent.sh: -------------------------------------------------------------------------------- 1 | ./flume-ng agent --conf conf --conf-file /home/user/apache-flume-1.6.0-bin/conf/single-node-demo.properties --name a1 -Dflume.root.logger=INFO,console 2 | #Hadoop and hive in classpath 3 | # add asm-all-4.2 lib 4 | #netcat 5 | nc host port 6 | 7 | #for ignite example 8 | ./flume-ng agent --conf conf --conf-file /home/user/apache-flume-1.6.0-bin/conf/single-node-demo.properties --name a1 -------------------------------------------------------------------------------- /chapters/chapter-cep/flume/src/main/java/com/blu/imdg/flume/config/demo.properties: -------------------------------------------------------------------------------- 1 | # Name the components on this agent 2 | a1.sources = r1 3 | a1.sinks = k1 4 | a1.channels = c1 5 | 6 | # Describe/configure the source 7 | #a1.sources.r1.type = netcat 8 | a1.sources.r1.type = avro 9 | a1.sources.r1.bind = localhost 10 | a1.sources.r1.port = 44444 11 | 12 | # Describe the sink, Sink logger is not need for ignite 13 | #a1.sinks.k1.type = logger 14 | 15 | # Use a channel which buffers events in memory 16 | a1.channels.c1.type = memory 17 | a1.channels.c1.capacity = 1000 18 | a1.channels.c1.transactionCapacity = 100 19 | 20 | # Bind the source and sink to the channel 21 | a1.sources.r1.channels = c1 22 | a1.sinks.k1.channel = c1 23 | 24 | # ignite sink 25 | a1.sinks.k1.type = org.apache.ignite.stream.flume.IgniteSink 26 | a1.sinks.k1.igniteCfg = /home/user/apache-flume-1.6.0-bin/conf/example-ignite.xml 27 | a1.sinks.k1.cacheName = testCache 28 | a1.sinks.k1.eventTransformer = com.blu.imdg.flume.Transformer.FlumeEventTransformer 29 | a1.sinks.k1.batchSize = 100 -------------------------------------------------------------------------------- /chapters/chapter-cep/flume/src/main/java/com/blu/imdg/flume/rpc/RpcEventGenerator.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.flume.rpc; 2 | 3 | import org.apache.flume.Event; 4 | import org.apache.flume.EventDeliveryException; 5 | import org.apache.flume.api.RpcClient; 6 | import org.apache.flume.api.RpcClientFactory; 7 | import org.apache.flume.event.EventBuilder; 8 | 9 | /** 10 | * Created by shamim on 11/08/16. 11 | */ 12 | public class RpcEventGenerator { 13 | private org.apache.flume.api.RpcClient rpcClient; 14 | private String hostName; 15 | private int port; 16 | 17 | public RpcEventGenerator(String hostName, int port) { 18 | this.hostName = hostName; 19 | this.port = port; 20 | this.rpcClient = RpcClientFactory.getDefaultInstance(hostName, port); 21 | } 22 | 23 | public void sendData(String data){ 24 | Event event = EventBuilder.withBody(data.getBytes()); 25 | 26 | try { 27 | rpcClient.append(event); 28 | } catch (EventDeliveryException e) { 29 | e.printStackTrace(); 30 | rpcClient.close(); 31 | rpcClient = RpcClientFactory.getDefaultInstance(this.hostName, this.port); 32 | } 33 | 34 | } 35 | public void cleanUp(){ 36 | if(rpcClient.isActive()){ 37 | rpcClient.close(); 38 | } 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /chapters/chapter-cep/flume/src/main/java/com/blu/imdg/flume/rpc/RunClient.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.flume.rpc; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.util.Properties; 6 | 7 | /** 8 | * Created by shamim on 11/08/16. 9 | */ 10 | public class RunClient { 11 | private static final String HOST_NAME="flume.agent.host"; 12 | private static final String PORT="flume.agent.port"; 13 | 14 | public static void main(String[] args) { 15 | System.out.println("RPC client to send data"); 16 | // read properties from file 17 | if(getProperties() == null || getProperties().isEmpty()){ 18 | System.out.println("Property file is not found or empty"); 19 | return; 20 | } 21 | 22 | RpcEventGenerator eventGenerator = new RpcEventGenerator(getProperties().getProperty(HOST_NAME), Integer.valueOf(getProperties().getProperty(PORT))); 23 | // generate some sequence of transactions 24 | 25 | for(int i = 1; i < 100 ; i++){ 26 | eventGenerator.sendData("transaction"+i+":"+i); 27 | } 28 | eventGenerator.cleanUp(); 29 | } 30 | private static Properties getProperties(){ 31 | Properties properties = new Properties(); 32 | InputStream ins = RunClient.class.getClassLoader().getResourceAsStream("generator.properties"); 33 | 34 | try { 35 | properties.load(ins); 36 | } catch (IOException e) { 37 | e.printStackTrace(); 38 | properties = null; 39 | } 40 | return properties; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /chapters/chapter-cep/flume/src/main/resources/generator.properties: -------------------------------------------------------------------------------- 1 | flume.agent.host=192.168.15.150 2 | flume.agent.port=44444 -------------------------------------------------------------------------------- /chapters/chapter-cep/storm/README.md: -------------------------------------------------------------------------------- 1 | to run the topology, execute 2 | 3 | mvn compile exec:java -Dstorm.topology=com.blu.imdg.storm.topology.SpeedViolationTopology -------------------------------------------------------------------------------- /chapters/chapter-cep/storm/src/main/java/com/blu/imdg/storm/bolts/SpeedLimitBolt.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.storm.bolts; 2 | 3 | import backtype.storm.topology.BasicOutputCollector; 4 | import backtype.storm.topology.OutputFieldsDeclarer; 5 | import backtype.storm.topology.base.BaseBasicBolt; 6 | import backtype.storm.tuple.Fields; 7 | import backtype.storm.tuple.Tuple; 8 | import backtype.storm.tuple.Values; 9 | import clojure.lang.IFn; 10 | import org.apache.logging.log4j.LogManager; 11 | import org.apache.logging.log4j.Logger; 12 | 13 | import java.util.TreeMap; 14 | 15 | /** 16 | * Created by shamim on 28/08/16. 17 | */ 18 | public class SpeedLimitBolt extends BaseBasicBolt { 19 | // Static field for ignite 20 | private static final String IGNITE_FIELD = "ignite"; 21 | private static final int SPEED_THRESHOLD = 120; 22 | //Create logger for this class 23 | private static final Logger LOGGER = LogManager.getLogger(SpeedLimitBolt.class); 24 | @Override 25 | public void execute(Tuple tuple, BasicOutputCollector basicOutputCollector) { 26 | String line = (String)tuple.getValue(0); 27 | if(!line.isEmpty()){ 28 | String[] elements = line.split(","); 29 | // we are interested in speed and the car registration number 30 | int speed = Integer.valueOf((elements[1]).trim()); 31 | String car = elements[0]; 32 | if(speed > SPEED_THRESHOLD){ 33 | TreeMap carValue = new TreeMap(); 34 | carValue.put(car, speed); 35 | basicOutputCollector.emit(new Values(carValue)); 36 | LOGGER.info("Speed violation found:"+ car + " speed:" + speed); 37 | } 38 | } 39 | } 40 | 41 | @Override 42 | public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) { 43 | outputFieldsDeclarer.declare(new Fields(IGNITE_FIELD)); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /chapters/chapter-cep/storm/src/main/java/com/blu/imdg/storm/bolts/SplitSentence.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.storm.bolts; 2 | 3 | import backtype.storm.topology.BasicOutputCollector; 4 | import backtype.storm.topology.OutputFieldsDeclarer; 5 | import backtype.storm.topology.base.BaseBasicBolt; 6 | import backtype.storm.tuple.Fields; 7 | import backtype.storm.tuple.Tuple; 8 | import backtype.storm.tuple.Values; 9 | 10 | import java.text.BreakIterator; 11 | 12 | /** 13 | * Created by shamim on 24/08/16. 14 | */ 15 | public class SplitSentence extends BaseBasicBolt { 16 | //Execute is called to process tuples 17 | @Override 18 | public void execute(Tuple tuple, BasicOutputCollector collector) { 19 | //Get the sentence content from the tuple 20 | String sentence = tuple.getString(0); 21 | //An iterator to get each word 22 | BreakIterator boundary=BreakIterator.getWordInstance(); 23 | //Give the iterator the sentence 24 | boundary.setText(sentence); 25 | //Find the beginning first word 26 | int start=boundary.first(); 27 | //Iterate over each word and emit it to the output stream 28 | for (int end = boundary.next(); end != BreakIterator.DONE; start=end, end=boundary.next()) { 29 | //get the word 30 | String word=sentence.substring(start,end); 31 | //If a word is whitespace characters, replace it with empty 32 | word=word.replaceAll("\\s+",""); 33 | //if it's an actual word, emit it 34 | if (!word.equals("")) { 35 | collector.emit(new Values(word)); 36 | } 37 | } 38 | } 39 | 40 | //Declare that emitted tuples will contain a word field 41 | @Override 42 | public void declareOutputFields(OutputFieldsDeclarer declarer) { 43 | declarer.declare(new Fields("word")); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /chapters/chapter-cep/storm/src/main/java/com/blu/imdg/storm/bolts/WordCount.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.storm.bolts; 2 | 3 | import backtype.storm.topology.BasicOutputCollector; 4 | import backtype.storm.topology.OutputFieldsDeclarer; 5 | import backtype.storm.topology.base.BaseBasicBolt; 6 | import backtype.storm.tuple.Fields; 7 | import backtype.storm.tuple.Tuple; 8 | import backtype.storm.tuple.Values; 9 | import org.apache.logging.log4j.LogManager; 10 | import org.apache.logging.log4j.Logger; 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | import java.util.TreeMap; 15 | 16 | /** 17 | * Created by shamim on 24/08/16. 18 | */ 19 | public class WordCount extends BaseBasicBolt { 20 | // Static field for ignite 21 | private static final String IGNITE_FIELD = "ignite"; 22 | //Create logger for this class 23 | private static final Logger logger = LogManager.getLogger(WordCount.class); 24 | 25 | //For holding words and counts 26 | Map counts = new HashMap(); 27 | 28 | //execute is called to process tuples 29 | @Override 30 | public void execute(Tuple tuple, BasicOutputCollector collector) { 31 | //Get the word contents from the tuple 32 | String word = tuple.getString(0); 33 | //Have we counted any already? 34 | Integer count = counts.get(word); 35 | if (count == null) 36 | count = 0; 37 | //Increment the count and store it 38 | count++; 39 | counts.put(word, count); 40 | //Emit the word and the current count 41 | //collector.emit(new Values(IGNITE_FIELD, count)); 42 | TreeMap words = new TreeMap<>(); 43 | words.put(word,count); 44 | 45 | collector.emit(new Values(words)); 46 | //Log information 47 | logger.info("Emitting a count of " + count + " for word " + word); 48 | } 49 | 50 | //Declare that we will emit a tuple containing two fields; word and count 51 | @Override 52 | public void declareOutputFields(OutputFieldsDeclarer declarer) { 53 | declarer.declare(new Fields(IGNITE_FIELD)); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /chapters/chapter-cep/storm/src/main/java/com/blu/imdg/storm/spouts/FileSourceSpout.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.storm.spouts; 2 | 3 | import backtype.storm.spout.SpoutOutputCollector; 4 | import backtype.storm.task.TopologyContext; 5 | import backtype.storm.topology.OutputFieldsDeclarer; 6 | import backtype.storm.topology.base.BaseRichSpout; 7 | import backtype.storm.tuple.Fields; 8 | 9 | import backtype.storm.tuple.Values; 10 | import org.apache.logging.log4j.LogManager; 11 | import org.apache.logging.log4j.Logger; 12 | 13 | 14 | import java.io.*; 15 | import java.net.URISyntaxException; 16 | import java.nio.file.Files; 17 | import java.nio.file.Path; 18 | import java.nio.file.Paths; 19 | import java.util.Map; 20 | import java.util.stream.Stream; 21 | 22 | 23 | /** 24 | * Created by shamim on 28/08/16. 25 | */ 26 | public class FileSourceSpout extends BaseRichSpout { 27 | private static final Logger LOGGER = LogManager.getLogger(FileSourceSpout.class); 28 | private SpoutOutputCollector outputCollector; 29 | @Override 30 | public void open(Map map, TopologyContext topologyContext, SpoutOutputCollector spoutOutputCollector) { 31 | this.outputCollector = spoutOutputCollector; 32 | } 33 | 34 | /** 35 | * Read file from classpath to generate source. 36 | * */ 37 | @Override 38 | public void nextTuple() { 39 | 40 | try { 41 | Path filePath = Paths.get(this.getClass().getClassLoader().getResource("source.csv").toURI()); 42 | try(Stream lines = Files.lines(filePath)){ 43 | lines.forEach(line ->{ 44 | outputCollector.emit(new Values(line)); 45 | }); 46 | 47 | } catch(IOException e){ 48 | LOGGER.error(e.getMessage()); 49 | } 50 | 51 | } catch (URISyntaxException e) { 52 | LOGGER.error(e.getMessage()); 53 | } 54 | 55 | } 56 | 57 | @Override 58 | public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) { 59 | outputFieldsDeclarer.declare(new Fields("trafficLog")); 60 | 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /chapters/chapter-cep/storm/src/main/java/com/blu/imdg/storm/spouts/RandomSentenceSpout.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.storm.spouts; 2 | 3 | import backtype.storm.spout.SpoutOutputCollector; 4 | import backtype.storm.task.TopologyContext; 5 | import backtype.storm.topology.OutputFieldsDeclarer; 6 | import backtype.storm.topology.base.BaseRichSpout; 7 | import backtype.storm.tuple.Fields; 8 | import backtype.storm.tuple.Values; 9 | import backtype.storm.utils.Utils; 10 | 11 | import java.util.Map; 12 | import java.util.Random; 13 | 14 | /** 15 | * Created by shamim on 24/08/16. 16 | */ 17 | public class RandomSentenceSpout extends BaseRichSpout { 18 | 19 | //Collector used to emit output 20 | SpoutOutputCollector _collector; 21 | //Used to generate a random number 22 | Random _rand; 23 | 24 | //Open is called when an instance of the class is created 25 | @Override 26 | public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) { 27 | //Set the instance collector to the one passed in 28 | _collector = collector; 29 | //For randomness 30 | _rand = new Random(); 31 | } 32 | 33 | //Emit data to the stream 34 | @Override 35 | public void nextTuple() { 36 | //Sleep for a bit 37 | Utils.sleep(100); 38 | //The sentences that will be randomly emitted 39 | String[] sentences = new String[]{"the cow jumped over the moon", "an apple a day keeps the doctor away", 40 | "four score and seven years ago", "snow white and the seven dwarfs", "i am at two with nature"}; 41 | //Randomly pick a sentence 42 | String sentence = sentences[_rand.nextInt(sentences.length)]; 43 | //Emit the sentence 44 | _collector.emit(new Values(sentence)); 45 | } 46 | 47 | //Ack is not implemented since this is a basic example 48 | @Override 49 | public void ack(Object id) { 50 | } 51 | 52 | //Fail is not implemented since this is a basic example 53 | @Override 54 | public void fail(Object id) { 55 | } 56 | 57 | //Declare the output fields. In this case, an sentence 58 | @Override 59 | public void declareOutputFields(OutputFieldsDeclarer declarer) { 60 | declarer.declare(new Fields("sentence")); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /chapters/chapter-cep/storm/src/main/java/com/blu/imdg/storm/topology/SpeedViolationTopology.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.storm.topology; 2 | 3 | import backtype.storm.Config; 4 | import backtype.storm.LocalCluster; 5 | import backtype.storm.StormSubmitter; 6 | import backtype.storm.topology.TopologyBuilder; 7 | import backtype.storm.tuple.Fields; 8 | import com.blu.imdg.storm.bolts.SpeedLimitBolt; 9 | import com.blu.imdg.storm.bolts.SplitSentence; 10 | import com.blu.imdg.storm.bolts.WordCount; 11 | import com.blu.imdg.storm.spouts.FileSourceSpout; 12 | import com.blu.imdg.storm.spouts.RandomSentenceSpout; 13 | import org.apache.ignite.stream.storm.StormStreamer; 14 | 15 | import java.io.IOException; 16 | import java.io.InputStream; 17 | import java.util.Properties; 18 | 19 | /** 20 | * Created by shamim on 28/08/16. 21 | */ 22 | public class SpeedViolationTopology { 23 | 24 | private static final int STORM_EXECUTORS = 2; 25 | 26 | public static void main(String[] args) throws Exception { 27 | if (getProperties() == null || getProperties().isEmpty()) { 28 | System.out.println("Property file is not found or empty"); 29 | return; 30 | } 31 | // Ignite Stream Ibolt 32 | final StormStreamer stormStreamer = new StormStreamer<>(); 33 | 34 | stormStreamer.setAutoFlushFrequency(10L); 35 | stormStreamer.setAllowOverwrite(true); 36 | stormStreamer.setCacheName(getProperties().getProperty("cache.name")); 37 | 38 | stormStreamer.setIgniteTupleField(getProperties().getProperty("tuple.name")); 39 | stormStreamer.setIgniteConfigFile(getProperties().getProperty("ignite.spring.xml")); 40 | 41 | 42 | TopologyBuilder builder = new TopologyBuilder(); 43 | 44 | builder.setSpout("spout", new FileSourceSpout(), 1); 45 | builder.setBolt("limit", new SpeedLimitBolt(), 1).fieldsGrouping("spout", new Fields("trafficLog")); 46 | // set ignite bolt 47 | builder.setBolt("ignite-bolt", stormStreamer, STORM_EXECUTORS).shuffleGrouping("limit"); 48 | 49 | Config conf = new Config(); 50 | conf.setDebug(false); 51 | 52 | conf.setMaxTaskParallelism(1); 53 | LocalCluster cluster = new LocalCluster(); 54 | cluster.submitTopology("speed-violation", conf, builder.createTopology()); 55 | Thread.sleep(10000); 56 | cluster.shutdown(); 57 | 58 | } 59 | 60 | private static Properties getProperties() { 61 | Properties properties = new Properties(); 62 | InputStream ins = SpeedViolationTopology.class.getClassLoader().getResourceAsStream("ignite-storm.properties"); 63 | 64 | try { 65 | properties.load(ins); 66 | } catch (IOException e) { 67 | e.printStackTrace(); 68 | properties = null; 69 | } 70 | return properties; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /chapters/chapter-cep/storm/src/main/resources/ignite-storm.properties: -------------------------------------------------------------------------------- 1 | cache.name=testCache 2 | tuple.name=ignite 3 | ignite.spring.xml=example-ignite.xml -------------------------------------------------------------------------------- /chapters/chapter-cep/storm/src/main/resources/source.csv: -------------------------------------------------------------------------------- 1 | AB 123, 160, North city 2 | BC 123, 170, South city 3 | CD 234, 40, South city 4 | DE 123, 40, East city 5 | EF 123, 190, South city 6 | GH 123, 150, West city 7 | XY 123, 110, North city 8 | GF 123, 100, South city 9 | PO 234, 140, South city 10 | XX 123, 110, East city 11 | YY 123, 120, South city 12 | ZQ 123, 100, West city -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/StartCacheNode.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg; 2 | 3 | import org.apache.ignite.Ignite; 4 | import org.apache.ignite.Ignition; 5 | 6 | import java.io.IOException; 7 | 8 | /** 9 | * Created by mikl on 19.08.16. 10 | */ 11 | //mvn exec:java -Dexec.mainClass=com.blu.imdg.StartCacheNode 12 | public class StartCacheNode { 13 | public static void main(String[] args) { 14 | try (Ignite ignite = Ignition.start("org/book/examples/cache-node-config.xml")) { 15 | System.out.println("Presse ENTER to exit!"); 16 | System.in.read(); 17 | } catch (IOException e) { 18 | e.printStackTrace(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/common/CommonConstants.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.common; 2 | 3 | /** 4 | * Created by mikl on 23.08.16. 5 | */ 6 | public class CommonConstants { 7 | public static final String CLIENT_CONFIG = "org/book/examples/simple-client-config.xml"; 8 | } 9 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/common/HttpAuditClient.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.common; 2 | 3 | import org.apache.http.client.HttpClient; 4 | import org.apache.http.client.methods.CloseableHttpResponse; 5 | import org.apache.http.client.methods.HttpGet; 6 | import org.apache.http.client.utils.URIBuilder; 7 | import org.apache.http.impl.client.HttpClients; 8 | import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; 9 | 10 | import java.io.IOException; 11 | import java.net.URI; 12 | import java.net.URISyntaxException; 13 | import java.util.concurrent.ConcurrentMap; 14 | import java.util.function.Function; 15 | 16 | /** 17 | * Created by mikl on 23.08.16. 18 | */ 19 | public class HttpAuditClient { 20 | 21 | public static Boolean sendResult(HttpClient client, Boolean result, String messageId) throws URISyntaxException, IOException { 22 | URI uri = new URIBuilder().setScheme("http").setHost("localhost").setPort(9998).setPath("/audit/log") 23 | .setParameter("msgId", messageId) 24 | .setParameter("validationResult", result.toString()) 25 | .build(); 26 | HttpGet httpget = new HttpGet(uri); 27 | try (CloseableHttpResponse resp = (CloseableHttpResponse) client.execute(httpget)) { 28 | System.out.println("msg=" + messageId + " result=" + result); 29 | return result; 30 | } 31 | } 32 | 33 | public static HttpClient createHttpClient(ConcurrentMap nodeLocalMap) { 34 | return (HttpClient) nodeLocalMap.computeIfAbsent("httpClient", new Function() { 35 | @Override 36 | public HttpClient apply(Object o) { 37 | return createHttpClient(); 38 | } 39 | }); 40 | } 41 | 42 | public static HttpClient createHttpClient() { 43 | PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); 44 | return HttpClients.custom() 45 | .setConnectionManager(cm) 46 | .build(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/common/HttpAuditEmulator.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.common; 2 | 3 | import com.sun.net.httpserver.HttpServer; 4 | import org.glassfish.jersey.jdkhttp.JdkHttpServerFactory; 5 | import org.glassfish.jersey.server.ResourceConfig; 6 | 7 | import javax.ws.rs.GET; 8 | import javax.ws.rs.Path; 9 | import javax.ws.rs.Produces; 10 | import javax.ws.rs.QueryParam; 11 | import javax.ws.rs.core.MediaType; 12 | import javax.ws.rs.core.UriBuilder; 13 | import java.net.URI; 14 | 15 | /** 16 | * Created by mikl on 11.07.16. 17 | * mvn exec:java -Dexec.mainClass=com.blu.imdg.common.HttpAuditEmulator 18 | */ 19 | @Path("/audit") 20 | public class HttpAuditEmulator { 21 | 22 | 23 | @GET 24 | @Path("/log") 25 | @Produces(MediaType.TEXT_PLAIN) 26 | public String acceptResponse( 27 | @QueryParam("msgId") String msgId, 28 | @QueryParam("validationResult") boolean result 29 | ) { 30 | System.out.println("log message validation result msgId=" + msgId + " result=" + result); 31 | return "1"; 32 | } 33 | 34 | public static void main(String[] args) { 35 | URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build(); 36 | ResourceConfig config = new ResourceConfig(HttpAuditEmulator.class); 37 | HttpServer server = JdkHttpServerFactory.createHttpServer(baseUri, config); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/common/JSEvaluate.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.common; 2 | 3 | 4 | import javax.script.Bindings; 5 | import javax.script.ScriptEngine; 6 | import javax.script.ScriptEngineManager; 7 | 8 | /** 9 | * Created by mzheludkov on 04.07.16. 10 | */ 11 | public class JSEvaluate { 12 | 13 | public static boolean evaluateJs(String xml, String js) { 14 | ScriptEngineManager factory = new ScriptEngineManager(); 15 | ScriptEngine engine = factory.getEngineByName("nashorn"); 16 | Bindings bindings = engine.createBindings(); 17 | try { 18 | bindings.put("xpath", new XPathExecutor(xml)); 19 | return (boolean) engine.eval(js, bindings); 20 | } catch (final Exception err) { 21 | throw new RuntimeException(err); 22 | } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/common/TestDataGenerator.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.common; 2 | 3 | import org.apache.commons.io.IOUtils; 4 | import com.blu.imdg.example3.ValidateMessage; 5 | 6 | import java.io.IOException; 7 | 8 | /** 9 | * Created by mikl on 22.08.16. 10 | */ 11 | public class TestDataGenerator { 12 | private static final String SAMPLE1 = "/META-INF/org/book/examples/data/sample1.xml"; 13 | private static final String SAMPLE2 = "/META-INF/org/book/examples/data/sample2.xml"; 14 | private static final String SAMPLE3 = "/META-INF/org/book/examples/data/sample3.xml"; 15 | private static final String VALIDATE_SCHEMA = "/META-INF/org/book/examples/data/validate-schema.xsd"; 16 | private static final String VALIDATE_SCRIPT = "/META-INF/org/book/examples/data/validate-script.js"; 17 | 18 | private static String getStringResource(String resource) throws IOException { 19 | return IOUtils.toString(TestDataGenerator.class.getResourceAsStream(resource)); 20 | } 21 | 22 | private static byte[] getByteResource(String resource) throws IOException { 23 | return IOUtils.toByteArray(TestDataGenerator.class.getResourceAsStream(resource)); 24 | } 25 | 26 | 27 | public static String getValidateScript() throws IOException { 28 | return getStringResource(VALIDATE_SCRIPT); 29 | } 30 | 31 | public static byte[] getValidateSchema() throws IOException { 32 | return getByteResource(VALIDATE_SCHEMA); 33 | } 34 | 35 | public static String getSample1() throws IOException { 36 | return getStringResource(SAMPLE1); 37 | } 38 | 39 | public static String getSample2() throws IOException { 40 | return getStringResource(SAMPLE2); 41 | } 42 | 43 | public static ValidateMessage[] getValidateMessages() throws IOException { 44 | byte[] vaidateSchema = getValidateSchema(); 45 | String validateScript = getValidateScript(); 46 | 47 | return new ValidateMessage[]{ 48 | new ValidateMessage("1", getStringResource(SAMPLE1), vaidateSchema, validateScript), 49 | new ValidateMessage("2", getStringResource(SAMPLE2), vaidateSchema, validateScript), 50 | new ValidateMessage("3", getStringResource(SAMPLE3), vaidateSchema, validateScript) 51 | }; 52 | } 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/common/XPathExecutor.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.common; 2 | 3 | import org.w3c.dom.Document; 4 | import org.xml.sax.InputSource; 5 | 6 | import java.io.StringReader; 7 | import java.util.function.Function; 8 | import javax.xml.parsers.DocumentBuilder; 9 | import javax.xml.parsers.DocumentBuilderFactory; 10 | import javax.xml.xpath.XPath; 11 | import javax.xml.xpath.XPathExpressionException; 12 | import javax.xml.xpath.XPathFactory; 13 | 14 | /** 15 | * Created by mzheludkov on 04.07.16. 16 | */ 17 | public class XPathExecutor implements Function { 18 | private Document document; 19 | 20 | public XPathExecutor(String xml) { 21 | try { 22 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 23 | DocumentBuilder db = dbf.newDocumentBuilder(); 24 | document = db.parse(new InputSource(new StringReader(xml))); 25 | } catch (Exception err) { 26 | throw new RuntimeException(err); 27 | } 28 | } 29 | 30 | public Object apply(String xpathStr) { 31 | try { 32 | final XPath xpath = XPathFactory.newInstance().newXPath(); 33 | return xpath.evaluate(xpathStr, document); 34 | } catch (XPathExpressionException e) { 35 | throw new RuntimeException(e); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/common/XsdValidator.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.common; 2 | 3 | import javax.xml.XMLConstants; 4 | import javax.xml.transform.Source; 5 | import javax.xml.transform.stream.StreamSource; 6 | import javax.xml.validation.Schema; 7 | import javax.xml.validation.SchemaFactory; 8 | import javax.xml.validation.Validator; 9 | import java.io.ByteArrayInputStream; 10 | 11 | /** 12 | * Created by mzheludkov on 04.07.16. 13 | */ 14 | public class XsdValidator { 15 | public static boolean validate(String xml, byte[] xsd) { 16 | try { 17 | SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 18 | Source schemaFile = new StreamSource(new ByteArrayInputStream(xsd)); 19 | Schema schema = factory.newSchema(schemaFile); 20 | 21 | Validator validator = schema.newValidator(); 22 | validator.validate(new StreamSource(new ByteArrayInputStream(xml.getBytes()))); 23 | return true; 24 | } catch (Exception err) { 25 | err.printStackTrace(); 26 | return false; 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/common/bankData/model/AccountCacheData.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.common.bankData.model; 2 | 3 | /** 4 | * Created by mikl on 24.10.16. 5 | */ 6 | public interface AccountCacheData { 7 | } 8 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/common/bankData/model/AccountCacheKey.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.common.bankData.model; 2 | 3 | /** 4 | * Created by mikl on 24.10.16. 5 | */ 6 | public interface AccountCacheKey { 7 | } 8 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/common/bankData/model/AccountData.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.common.bankData.model; 2 | 3 | import java.math.BigDecimal; 4 | import java.time.LocalDate; 5 | import java.util.Date; 6 | 7 | /** 8 | * Created by mikl on 21.10.16. 9 | */ 10 | public class AccountData implements AccountCacheData { 11 | private String account; 12 | private String personId; 13 | private String accountType; 14 | private Date openedAt; 15 | 16 | private BigDecimal dailyLimit; 17 | private BigDecimal todayOperationSum; 18 | private LocalDate today; 19 | 20 | public AccountData(String account, String personId, String accountType, Date openedAt, BigDecimal dailyLimit) { 21 | this.account = account; 22 | this.personId = personId; 23 | this.accountType = accountType; 24 | this.openedAt = openedAt; 25 | this.dailyLimit = dailyLimit; 26 | this.todayOperationSum = new BigDecimal(0); 27 | this.today = LocalDate.now(); 28 | } 29 | 30 | public String getAccount() { 31 | return account; 32 | } 33 | 34 | public void setAccount(String account) { 35 | this.account = account; 36 | } 37 | 38 | public String getPersonId() { 39 | return personId; 40 | } 41 | 42 | public void setPersonId(String personId) { 43 | this.personId = personId; 44 | } 45 | 46 | public String getAccountType() { 47 | return accountType; 48 | } 49 | 50 | public void setAccountType(String accountType) { 51 | this.accountType = accountType; 52 | } 53 | 54 | public Date getOpenedAt() { 55 | return openedAt; 56 | } 57 | 58 | public void setOpenedAt(Date openedAt) { 59 | this.openedAt = openedAt; 60 | } 61 | 62 | public BigDecimal getTodayOperationSum() { 63 | return todayOperationSum; 64 | } 65 | 66 | public void setTodayOperationSum(BigDecimal todayOperationSum) { 67 | this.todayOperationSum = todayOperationSum; 68 | } 69 | 70 | public LocalDate getToday() { 71 | return today; 72 | } 73 | 74 | public void setToday(LocalDate today) { 75 | this.today = today; 76 | } 77 | 78 | public BigDecimal getDailyLimit() { 79 | return dailyLimit; 80 | } 81 | 82 | @Override 83 | public String toString() { 84 | return "AccountData{" + 85 | "account='" + account + '\'' + 86 | ", personId='" + personId + '\'' + 87 | ", accountType='" + accountType + '\'' + 88 | ", openedAt=" + openedAt + 89 | ", dailyLimit=" + dailyLimit + 90 | ", todayOperationSum=" + todayOperationSum + 91 | ", today=" + today + 92 | '}'; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/common/bankData/model/AccountKey.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.common.bankData.model; 2 | 3 | import org.apache.ignite.cache.affinity.AffinityKeyMapped; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * Created by mikl on 21.10.16. 9 | */ 10 | public class AccountKey implements AccountCacheKey,Serializable { 11 | @AffinityKeyMapped 12 | private String account; 13 | 14 | public AccountKey(String account) { 15 | this.account = account; 16 | } 17 | 18 | public String getAccount() { 19 | return account; 20 | } 21 | 22 | @Override 23 | public boolean equals(Object o) { 24 | if (this == o) return true; 25 | if (o == null || getClass() != o.getClass()) return false; 26 | 27 | AccountKey that = (AccountKey) o; 28 | 29 | return account != null ? account.equals(that.account) : that.account == null; 30 | 31 | } 32 | 33 | @Override 34 | public int hashCode() { 35 | return account != null ? account.hashCode() : 0; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/common/bankData/model/CashBackDictionaryData.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.common.bankData.model; 2 | 3 | import java.math.BigDecimal; 4 | 5 | /** 6 | * Created by mikl on 21.10.16. 7 | */ 8 | public class CashBackDictionaryData implements AccountCacheData { 9 | private BigDecimal cashBackPercent; 10 | private String savingsDescription; 11 | 12 | public CashBackDictionaryData() { 13 | } 14 | 15 | public CashBackDictionaryData(BigDecimal cashBackPercent, String savingsDescription) { 16 | this.cashBackPercent = cashBackPercent; 17 | this.savingsDescription = savingsDescription; 18 | } 19 | 20 | public BigDecimal getCashBackPercent() { 21 | return cashBackPercent; 22 | } 23 | 24 | public void setCashBackPercent(BigDecimal cashBackPercent) { 25 | this.cashBackPercent = cashBackPercent; 26 | } 27 | 28 | public String getSavingsDescription() { 29 | return savingsDescription; 30 | } 31 | 32 | public void setSavingsDescription(String savingsDescription) { 33 | this.savingsDescription = savingsDescription; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/common/bankData/model/TransactionData.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.common.bankData.model; 2 | 3 | import org.apache.ignite.cache.query.annotations.QuerySqlField; 4 | 5 | import java.math.BigDecimal; 6 | 7 | /** 8 | * Created by mikl on 21.10.16. 9 | */ 10 | public class TransactionData implements AccountCacheData { 11 | 12 | 13 | private String fromAccount; 14 | private String toAccount; 15 | private BigDecimal sum; 16 | private String transactionType; 17 | 18 | public TransactionData() { 19 | } 20 | 21 | public TransactionData(String fromAccount, String toAccount, BigDecimal sum, String transactionType) { 22 | this.fromAccount = fromAccount; 23 | this.toAccount = toAccount; 24 | this.sum = sum; 25 | this.transactionType = transactionType; 26 | } 27 | 28 | public String getFromAccount() { 29 | return fromAccount; 30 | } 31 | 32 | public void setFromAccount(String fromAccount) { 33 | this.fromAccount = fromAccount; 34 | } 35 | 36 | public String getToAccount() { 37 | return toAccount; 38 | } 39 | 40 | public void setToAccount(String toAccount) { 41 | this.toAccount = toAccount; 42 | } 43 | 44 | public BigDecimal getSum() { 45 | return sum; 46 | } 47 | 48 | public void setSum(BigDecimal sum) { 49 | this.sum = sum; 50 | } 51 | 52 | public String getTransactionType() { 53 | return transactionType; 54 | } 55 | 56 | public void setTransactionType(String transactionType) { 57 | this.transactionType = transactionType; 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return "TransactionData{" + 63 | ", fromAccount='" + fromAccount + '\'' + 64 | ", toAccount='" + toAccount + '\'' + 65 | ", sum=" + sum + 66 | ", transactionType='" + transactionType + '\'' + 67 | '}'; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/common/bankData/model/TransactionKey.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.common.bankData.model; 2 | 3 | import org.apache.ignite.cache.affinity.AffinityKeyMapped; 4 | import org.apache.ignite.cache.query.annotations.QuerySqlField; 5 | 6 | import java.io.Serializable; 7 | import java.util.Date; 8 | 9 | /** 10 | * Created by mikl on 21.10.16. 11 | */ 12 | public class TransactionKey implements AccountCacheKey, Serializable { 13 | 14 | @QuerySqlField(index = true) 15 | @AffinityKeyMapped 16 | private String account; 17 | 18 | private Date transactionDate; 19 | 20 | private String transactionId; 21 | 22 | public TransactionKey() { 23 | } 24 | 25 | public TransactionKey(String account, Date transactionDate, String transactionId) { 26 | this.account = account; 27 | this.transactionDate = transactionDate; 28 | this.transactionId = transactionId; 29 | } 30 | 31 | public String getAccount() { 32 | return account; 33 | } 34 | 35 | public void setAccount(String account) { 36 | this.account = account; 37 | } 38 | 39 | public Date getTransactionDate() { 40 | return transactionDate; 41 | } 42 | 43 | public void setTransactionDate(Date transactionDate) { 44 | this.transactionDate = transactionDate; 45 | } 46 | 47 | public String getTransactionId() { 48 | return transactionId; 49 | } 50 | 51 | public void setTransactionId(String transactionId) { 52 | this.transactionId = transactionId; 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return "TransactionKey{" + 58 | "account='" + account + '\'' + 59 | ", transactionDate=" + transactionDate + 60 | ", transactionId='" + transactionId + '\'' + 61 | '}'; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example1/SimpleComputation.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example1; 2 | 3 | import org.apache.ignite.Ignite; 4 | import org.apache.ignite.IgniteCompute; 5 | import org.apache.ignite.Ignition; 6 | import com.blu.imdg.common.JSEvaluate; 7 | import com.blu.imdg.common.TestDataGenerator; 8 | import com.blu.imdg.common.XsdValidator; 9 | 10 | import java.io.IOException; 11 | 12 | import static com.blu.imdg.common.CommonConstants.CLIENT_CONFIG; 13 | 14 | /** 15 | * Created by mikl on 19.08.16. 16 | */ 17 | //mvn exec:java -Dexec.mainClass=com.blu.imdg.example1.SimpleComputation 18 | public class SimpleComputation { 19 | 20 | public static void main(String[] args) throws IOException { 21 | String sample1 = TestDataGenerator.getSample1(); 22 | byte[] vaidateSchema = TestDataGenerator.getValidateSchema(); 23 | String validateScript = TestDataGenerator.getValidateScript(); 24 | 25 | try (Ignite ignite = Ignition.start(CLIENT_CONFIG)) { 26 | IgniteCompute compute = ignite.compute(); 27 | 28 | Boolean result = compute.call(() -> { 29 | boolean validateXsdResult = XsdValidator.validate(sample1, vaidateSchema); 30 | boolean validateByJs = JSEvaluate.evaluateJs(sample1, validateScript); 31 | 32 | System.out.println("validateXsdResult=" + validateXsdResult); 33 | System.out.println("validateByJs=" + validateByJs); 34 | 35 | return validateXsdResult && validateByJs; 36 | }); 37 | 38 | System.out.println("result=" + result); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example1/SimpleComputationClosure.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example1; 2 | 3 | import com.blu.imdg.common.JSEvaluate; 4 | import com.blu.imdg.common.TestDataGenerator; 5 | import com.blu.imdg.common.XsdValidator; 6 | import org.apache.ignite.Ignite; 7 | import org.apache.ignite.IgniteCompute; 8 | import org.apache.ignite.Ignition; 9 | import org.apache.ignite.lang.IgniteClosure; 10 | 11 | import java.io.IOException; 12 | import java.util.Arrays; 13 | import java.util.Collection; 14 | 15 | import static com.blu.imdg.common.CommonConstants.CLIENT_CONFIG; 16 | 17 | /** 18 | * Created by shamim on 26/11/16. 19 | * mvn exec:java -Dexec.mainClass=com.blu.imdg.example1.SimpleComputationClosure 20 | */ 21 | public class SimpleComputationClosure { 22 | public static void main(String[] args) throws IOException { 23 | try (Ignite ignite = Ignition.start(CLIENT_CONFIG)) { 24 | IgniteCompute compute = ignite.compute(); 25 | 26 | // Execute closure on all cluster nodes. 27 | Collection res = compute.apply( 28 | new IgniteClosure() { 29 | @Override 30 | public Integer apply(String word) { 31 | // Return number of letters in the word. 32 | return word.length(); 33 | } 34 | }, 35 | Arrays.asList("Count characters using closure".split(" ")) 36 | ); 37 | 38 | int sum = 0; 39 | 40 | // Add up individual word lengths received from remote nodes 41 | for (int len : res) 42 | sum += len; 43 | System.out.println("Length of the sentence: "+ sum); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example10/AsyncBankService.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example10; 2 | 3 | /** 4 | * Created by mikl on 26.10.16. 5 | */ 6 | public interface AsyncBankService { 7 | String NAME = "BANK_SERVICE"; 8 | } 9 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example10/ZeroMQBroker.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example10; 2 | 3 | import org.zeromq.ZMQ; 4 | import org.zeromq.ZMQ.Context; 5 | import org.zeromq.ZMQ.Socket; 6 | /** 7 | * Created by mikl on 07.01.17. 8 | */ 9 | //mvn exec:java -Dexec.mainClass=com.blu.imdg.example10.ZeroMQBroker 10 | public class ZeroMQBroker { 11 | public static void main (String[] args) { 12 | // Prepare our context and sockets 13 | Context context = ZMQ.context(1); 14 | 15 | // Socket facing clients 16 | Socket frontend = context.socket(ZMQ.ROUTER); 17 | frontend.bind("tcp://*:5559"); 18 | 19 | // Socket facing services 20 | Socket backend = context.socket(ZMQ.DEALER); 21 | backend.bind("tcp://*:5560"); 22 | 23 | // Start the proxy 24 | ZMQ.proxy (frontend, backend, null); 25 | 26 | // We never get here but clean up anyhow 27 | frontend.close(); 28 | backend.close(); 29 | context.term(); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example10/dto/ValidateRequest.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example10.dto; 2 | 3 | import java.math.BigDecimal; 4 | 5 | /** 6 | * Created by mikl on 07.01.17. 7 | */ 8 | public class ValidateRequest { 9 | String account; 10 | BigDecimal sum; 11 | 12 | public ValidateRequest() { 13 | } 14 | 15 | public ValidateRequest(String account, BigDecimal sum) { 16 | this.account = account; 17 | this.sum = sum; 18 | } 19 | 20 | public String getAccount() { 21 | return account; 22 | } 23 | 24 | public void setAccount(String account) { 25 | this.account = account; 26 | } 27 | 28 | public BigDecimal getSum() { 29 | return sum; 30 | } 31 | 32 | public void setSum(BigDecimal sum) { 33 | this.sum = sum; 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return "ValidateRequest{" + 39 | "account='" + account + '\'' + 40 | ", sum=" + sum + 41 | '}'; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example10/dto/ValidateResponse.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example10.dto; 2 | 3 | /** 4 | * Created by mikl on 08.01.17. 5 | */ 6 | public class ValidateResponse { 7 | public static ValidateResponse OK =new ValidateResponse(true); 8 | public static ValidateResponse DENIED =new ValidateResponse(false); 9 | 10 | 11 | private Boolean result; 12 | private String error; 13 | 14 | public ValidateResponse() { 15 | } 16 | 17 | public ValidateResponse(Boolean result, String error) { 18 | this.result = result; 19 | this.error = error; 20 | } 21 | 22 | public ValidateResponse(Boolean result) { 23 | this.result = result; 24 | } 25 | 26 | public ValidateResponse(String error) { 27 | this.error = error; 28 | } 29 | 30 | public static ValidateResponse error(String errorText) { 31 | return new ValidateResponse(errorText); 32 | } 33 | 34 | public Boolean getResult() { 35 | return result; 36 | } 37 | 38 | public void setResult(Boolean result) { 39 | this.result = result; 40 | } 41 | 42 | public String getError() { 43 | return error; 44 | } 45 | 46 | public void setError(String error) { 47 | this.error = error; 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | return "ValidateResponse{" + 53 | "result=" + result + 54 | ", error='" + error + '\'' + 55 | '}'; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example2/AsyncComputation.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example2; 2 | 3 | import com.blu.imdg.common.CommonConstants; 4 | import com.blu.imdg.common.JSEvaluate; 5 | import com.blu.imdg.common.XsdValidator; 6 | import org.apache.ignite.Ignite; 7 | import org.apache.ignite.IgniteCompute; 8 | import org.apache.ignite.Ignition; 9 | import com.blu.imdg.common.TestDataGenerator; 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * Created by mzheludkov on 30.06.16. 15 | */ 16 | //mvn exec:java -Dexec.mainClass=com.blu.imdg.example2.AsyncComputation 17 | public class AsyncComputation { 18 | 19 | public static void main(String[] args) throws IOException { 20 | String sample1 = TestDataGenerator.getSample1(); 21 | byte[] vaidateSchema = TestDataGenerator.getValidateSchema(); 22 | String validateScript = TestDataGenerator.getValidateScript(); 23 | 24 | try (Ignite ignite = Ignition.start(CommonConstants.CLIENT_CONFIG)) { 25 | IgniteCompute compute = ignite.compute().withAsync(); 26 | 27 | compute.call(() -> { 28 | boolean validateXsdResult = XsdValidator.validate(sample1, vaidateSchema); 29 | boolean validateByJs = JSEvaluate.evaluateJs(sample1, validateScript); 30 | 31 | System.out.println("validateXsdResult=" + validateXsdResult); 32 | System.out.println("validateByJs=" + validateByJs); 33 | 34 | return validateXsdResult && validateByJs; 35 | }); 36 | 37 | compute.future().listen((result) -> { 38 | boolean res = (boolean) result.get(); 39 | System.out.println("result=" + res); 40 | }); 41 | 42 | 43 | //System.out.println("Presse ENTER to exit!"); 44 | //System.in.read(); 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example3/ForkJoinJobAdapter.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example3; 2 | 3 | import org.apache.ignite.IgniteException; 4 | import org.apache.ignite.compute.ComputeJobAdapter; 5 | import com.blu.imdg.common.JSEvaluate; 6 | import com.blu.imdg.common.XsdValidator; 7 | 8 | /** 9 | * Created by mikl on 23.08.16. 10 | */ 11 | public class ForkJoinJobAdapter extends ComputeJobAdapter { 12 | 13 | private ValidateMessage msg; 14 | 15 | public ForkJoinJobAdapter(ValidateMessage msg) { 16 | this.msg = msg; 17 | } 18 | 19 | @Override 20 | public Boolean execute() throws IgniteException { 21 | boolean validateXsdResult = XsdValidator.validate(msg.getMsg(), msg.getXsd()); 22 | boolean validateByJs = JSEvaluate.evaluateJs(msg.getMsg(), msg.getJs()); 23 | 24 | System.out.println("msg=" + msg.getId()); 25 | System.out.println("validateXsdResult=" + validateXsdResult); 26 | System.out.println("validateByJs=" + validateByJs); 27 | 28 | return validateXsdResult && validateByJs; 29 | } 30 | } -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example3/ValidateMessage.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example3; 2 | 3 | /** 4 | * Created by mikl on 12.07.16. 5 | */ 6 | public class ValidateMessage { 7 | 8 | private String id; 9 | private String msg; 10 | private byte[] xsd ; 11 | private String js; 12 | 13 | public ValidateMessage(String id, String msg, byte[] xsd, String js) { 14 | this.id = id; 15 | this.msg = msg; 16 | this.xsd = xsd; 17 | this.js = js; 18 | } 19 | 20 | public String getMsg() { 21 | return msg; 22 | } 23 | 24 | public byte[] getXsd() { 25 | return xsd; 26 | } 27 | 28 | public String getJs() { 29 | return js; 30 | } 31 | 32 | public String getId() { 33 | return id; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example4/ForkJoinComputationExt.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example4; 2 | 3 | import org.apache.ignite.Ignite; 4 | import org.apache.ignite.IgniteCompute; 5 | import org.apache.ignite.IgniteException; 6 | import org.apache.ignite.Ignition; 7 | import org.apache.ignite.compute.ComputeJob; 8 | import org.apache.ignite.compute.ComputeJobResult; 9 | import org.apache.ignite.compute.ComputeTaskSplitAdapter; 10 | import com.blu.imdg.common.TestDataGenerator; 11 | import com.blu.imdg.example3.ValidateMessage; 12 | import org.jetbrains.annotations.Nullable; 13 | 14 | import java.io.IOException; 15 | import java.util.Arrays; 16 | import java.util.Collection; 17 | import java.util.List; 18 | import java.util.stream.Collectors; 19 | 20 | import static com.blu.imdg.common.CommonConstants.CLIENT_CONFIG; 21 | 22 | /** 23 | * Created by mikl on 14.07.16. 24 | * Run http simulator: mvn exec:java -Dexec.mainClass=com.blu.imdg.common.HttpAuditEmulator 25 | * Run Ignite node: mvn clean package exec:java -Dexec.mainClass=com.blu.imdg.StartCacheNode 26 | * Run the applicaion: mvn exec:java -Dexec.mainClass=com.blu.imdg.example4.ForkJoinComputationExt 27 | * 28 | */ 29 | public class ForkJoinComputationExt extends ComputeTaskSplitAdapter { 30 | 31 | 32 | 33 | @Override 34 | protected Collection split(int i, ValidateMessage[] messages) throws IgniteException { 35 | return Arrays.stream(messages).map(ForkJoinJobAdapterExt::new).collect(Collectors.toList()); 36 | } 37 | 38 | @Nullable 39 | @Override 40 | public Boolean reduce(List list) throws IgniteException { 41 | return list.stream().reduce(true, (acc, value) -> acc && (Boolean) value.getData(), (a, b) -> a && b); 42 | } 43 | 44 | public static void main(String[] args) throws IOException { 45 | 46 | try (Ignite ignite = Ignition.start(CLIENT_CONFIG)) { 47 | IgniteCompute compute = ignite.compute(); 48 | 49 | ValidateMessage[] validateMessages = TestDataGenerator.getValidateMessages(); 50 | Boolean result = compute.execute(new ForkJoinComputationExt(), validateMessages); 51 | System.out.println("result=" + result); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example4/ForkJoinJobAdapterExt.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example4; 2 | 3 | import com.blu.imdg.common.HttpAuditClient; 4 | import org.apache.http.client.HttpClient; 5 | import org.apache.ignite.Ignite; 6 | import org.apache.ignite.IgniteException; 7 | import org.apache.ignite.compute.ComputeJobAdapter; 8 | import org.apache.ignite.resources.IgniteInstanceResource; 9 | import com.blu.imdg.common.JSEvaluate; 10 | import com.blu.imdg.common.XsdValidator; 11 | import com.blu.imdg.example3.ValidateMessage; 12 | 13 | 14 | import java.util.concurrent.ConcurrentMap; 15 | 16 | /** 17 | * Created by mikl on 12.07.16. 18 | */ 19 | public class ForkJoinJobAdapterExt extends ComputeJobAdapter { 20 | 21 | @IgniteInstanceResource 22 | private Ignite ignite; 23 | 24 | private ValidateMessage msg; 25 | 26 | public ForkJoinJobAdapterExt(ValidateMessage msg) { 27 | this.msg = msg; 28 | } 29 | 30 | @Override 31 | public Boolean execute() throws IgniteException { 32 | try { 33 | boolean validateXsdResult = XsdValidator.validate(msg.getMsg(), msg.getXsd()); 34 | boolean validateByJs = JSEvaluate.evaluateJs(msg.getMsg(), msg.getJs()); 35 | 36 | Boolean result = validateXsdResult && validateByJs; 37 | 38 | ConcurrentMap nodeLocalMap = ignite.cluster().nodeLocalMap(); 39 | 40 | HttpClient client = HttpAuditClient.createHttpClient(nodeLocalMap); 41 | 42 | return HttpAuditClient.sendResult(client, result, msg.getId()); 43 | 44 | } catch (Exception err) { 45 | throw new IgniteException(err); 46 | } 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example5/ForkJointWithSessionComputation.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example5; 2 | 3 | import org.apache.ignite.Ignite; 4 | import org.apache.ignite.IgniteCompute; 5 | import org.apache.ignite.IgniteException; 6 | import org.apache.ignite.Ignition; 7 | import org.apache.ignite.compute.ComputeJob; 8 | import org.apache.ignite.compute.ComputeJobResult; 9 | import org.apache.ignite.compute.ComputeTaskSessionFullSupport; 10 | import org.apache.ignite.compute.ComputeTaskSplitAdapter; 11 | import com.blu.imdg.common.TestDataGenerator; 12 | import com.blu.imdg.example3.ValidateMessage; 13 | import org.jetbrains.annotations.Nullable; 14 | 15 | import java.io.IOException; 16 | import java.util.Arrays; 17 | import java.util.Collection; 18 | import java.util.List; 19 | import java.util.stream.Collectors; 20 | 21 | import static com.blu.imdg.common.CommonConstants.CLIENT_CONFIG; 22 | 23 | /** 24 | * Created by mikl on 14.07.16. 25 | */ 26 | @ComputeTaskSessionFullSupport 27 | public class ForkJointWithSessionComputation extends ComputeTaskSplitAdapter { 28 | 29 | 30 | 31 | @Override 32 | protected Collection split(int i, ValidateMessage[] messages) throws IgniteException { 33 | return Arrays.stream(messages).map(ForkJoinWithSessionJobAdapter::new).collect(Collectors.toList()); 34 | } 35 | 36 | 37 | @Nullable 38 | @Override 39 | public Boolean reduce(List list) throws IgniteException { 40 | return list.stream().reduce(true, (acc, value) -> acc && (Boolean) value.getData(), (a, b) -> a && b); 41 | } 42 | 43 | public static void main(String[] args) throws IOException { 44 | try (Ignite ignite = Ignition.start(CLIENT_CONFIG)) { 45 | IgniteCompute compute = ignite.compute(); 46 | 47 | ValidateMessage[] validateMessages = TestDataGenerator.getValidateMessages(); 48 | 49 | Boolean result = compute.execute(new ForkJointWithSessionComputation(), validateMessages); 50 | System.out.println("result=" + result); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example6/ForkJoinWithCheckpointComputation.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example6; 2 | 3 | import org.apache.ignite.Ignite; 4 | import org.apache.ignite.IgniteCompute; 5 | import org.apache.ignite.IgniteException; 6 | import org.apache.ignite.Ignition; 7 | import org.apache.ignite.compute.ComputeJob; 8 | import org.apache.ignite.compute.ComputeJobResult; 9 | import org.apache.ignite.compute.ComputeTaskSessionFullSupport; 10 | import org.apache.ignite.compute.ComputeTaskSplitAdapter; 11 | import org.apache.ignite.configuration.CacheConfiguration; 12 | import com.blu.imdg.common.TestDataGenerator; 13 | import com.blu.imdg.example3.ValidateMessage; 14 | import org.apache.ignite.configuration.IgniteConfiguration; 15 | import org.apache.ignite.spi.checkpoint.cache.CacheCheckpointSpi; 16 | import org.apache.ignite.spi.failover.always.AlwaysFailoverSpi; 17 | import org.jetbrains.annotations.Nullable; 18 | 19 | import java.io.IOException; 20 | import java.util.Arrays; 21 | import java.util.Collection; 22 | import java.util.List; 23 | import java.util.stream.Collectors; 24 | 25 | import static com.blu.imdg.common.CommonConstants.CLIENT_CONFIG; 26 | 27 | /** 28 | * Created by mikl on 14.07.16. 29 | */ 30 | @ComputeTaskSessionFullSupport 31 | public class ForkJoinWithCheckpointComputation extends ComputeTaskSplitAdapter { 32 | 33 | 34 | @Override 35 | protected Collection split(int i, ValidateMessage[] messages) throws IgniteException { 36 | return Arrays.stream(messages).map(ForkJoinWithCheckpointJobAdapter::new).collect(Collectors.toList()); 37 | } 38 | 39 | 40 | @Nullable 41 | @Override 42 | public Boolean reduce(List list) throws IgniteException { 43 | return list.stream().reduce(true, (acc, value) -> acc && (Boolean) value.getData(), (a, b) -> a && b); 44 | } 45 | 46 | public static void main(String[] args) throws IOException { 47 | 48 | try (Ignite ignite = Ignition.start(CLIENT_CONFIG)) { 49 | IgniteCompute compute = ignite.compute(); 50 | CacheConfiguration cacheConfiguration = new CacheConfiguration("checkpoints"); 51 | // explicitly uses of checkpoint 52 | CacheCheckpointSpi cacheCheckpointSpi = new CacheCheckpointSpi(); 53 | cacheCheckpointSpi.setCacheName("checkpointCache"); 54 | //cacheConfiguration.setC 55 | ignite.configuration().setCheckpointSpi(cacheCheckpointSpi) 56 | .setFailoverSpi(new AlwaysFailoverSpi()); 57 | // create or get cache 58 | ignite.getOrCreateCache(cacheConfiguration); 59 | 60 | ValidateMessage[] validateMessages = TestDataGenerator.getValidateMessages(); 61 | 62 | Boolean result = compute.execute(new ForkJoinWithCheckpointComputation(), validateMessages); 63 | System.out.println("final result=" + result); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example7/DeployClusterSingleton.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example7; 2 | 3 | import com.blu.imdg.common.CommonConstants; 4 | import org.apache.ignite.Ignite; 5 | import org.apache.ignite.Ignition; 6 | 7 | import java.io.IOException; 8 | 9 | /** 10 | * Created by shamim on 25/12/16. 11 | */ 12 | public class DeployClusterSingleton { 13 | private static final String VALIDATING_SERVICE = "validatingService-cluster-singleton"; 14 | 15 | public static void main(String[] args) throws IOException { 16 | try (Ignite ignite = Ignition.start(CommonConstants.CLIENT_CONFIG)) { 17 | 18 | System.out.println("Deploy Node-singleton service!!"); 19 | ignite.services().deployClusterSingleton(VALIDATING_SERVICE, new XsdValidatingServiceImpl()); 20 | 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example7/DeployNodeSingleton.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example7; 2 | 3 | import com.blu.imdg.common.CommonConstants; 4 | import com.blu.imdg.common.TestDataGenerator; 5 | import com.blu.imdg.example3.ValidateMessage; 6 | import org.apache.ignite.Ignite; 7 | import org.apache.ignite.Ignition; 8 | 9 | import java.io.IOException; 10 | 11 | /** 12 | * Created by shamim on 25/12/16. 13 | */ 14 | public class DeployNodeSingleton { 15 | private static final String VALIDATING_SERVICE = "validatingService"; 16 | 17 | public static void main(String[] args) throws IOException{ 18 | try (Ignite ignite = Ignition.start(CommonConstants.CLIENT_CONFIG)) { 19 | 20 | System.out.println("Deploy Node-singleton service!!"); 21 | ignite.services().deployNodeSingleton(VALIDATING_SERVICE, new XsdValidatingServiceImpl()); 22 | 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example7/RunXsdValidationService.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example7; 2 | 3 | import com.blu.imdg.common.CommonConstants; 4 | import com.blu.imdg.common.TestDataGenerator; 5 | import com.blu.imdg.example3.ValidateMessage; 6 | import org.apache.ignite.Ignite; 7 | import org.apache.ignite.Ignition; 8 | 9 | import java.io.IOException; 10 | 11 | /** 12 | * Created by shamim on 25/12/16. 13 | */ 14 | public class RunXsdValidationService { 15 | private static final String VALIDATING_SERVICE = "validatingService"; 16 | 17 | public static void main(String[] args) throws IOException{ 18 | try (Ignite ignite = Ignition.start(CommonConstants.CLIENT_CONFIG)) { 19 | 20 | String sample1 = TestDataGenerator.getSample1(); 21 | String sample2 = TestDataGenerator.getSample2(); 22 | byte[] vaidateSchema = TestDataGenerator.getValidateSchema(); 23 | String validateScript = TestDataGenerator.getValidateScript(); 24 | 25 | System.out.println("Invoke remote service!!"); 26 | 27 | XsdValidatingService xsdValidatingService = ignite.services().serviceProxy(VALIDATING_SERVICE, XsdValidatingService.class, /*not-sticky*/false); 28 | 29 | System.out.println("result=" + xsdValidatingService.isOk(new ValidateMessage("1", sample1, vaidateSchema, validateScript))); 30 | System.out.println("result2=" + xsdValidatingService.isOk(new ValidateMessage("2", sample2, vaidateSchema, validateScript))); 31 | 32 | } 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example7/ServiceManagements.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example7; 2 | 3 | import com.blu.imdg.common.CommonConstants; 4 | import org.apache.ignite.Ignite; 5 | import org.apache.ignite.Ignition; 6 | import org.apache.ignite.services.ServiceDescriptor; 7 | 8 | import java.io.IOException; 9 | 10 | /** 11 | * Created by shamim on 25/12/16. 12 | */ 13 | public class ServiceManagements { 14 | public static void main(String[] args) throws IOException{ 15 | try (Ignite ignite = Ignition.start(CommonConstants.CLIENT_CONFIG)) { 16 | 17 | for(ServiceDescriptor serviceDescriptor : ignite.services().serviceDescriptors()){ 18 | System.out.println("Service Name: " + serviceDescriptor.name()); 19 | System.out.println("MaxPerNode count: " + serviceDescriptor.maxPerNodeCount()); 20 | System.out.println("Total count: " + serviceDescriptor.totalCount()); 21 | System.out.println("Service class Name: " + serviceDescriptor.serviceClass()); 22 | System.out.println("Origin Node ID: " + serviceDescriptor.originNodeId()); 23 | 24 | } 25 | 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example7/TestXsdValidatingService.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example7; 2 | 3 | import com.blu.imdg.common.CommonConstants; 4 | import com.blu.imdg.common.TestDataGenerator; 5 | import com.blu.imdg.example3.ValidateMessage; 6 | import org.apache.ignite.Ignite; 7 | import org.apache.ignite.Ignition; 8 | 9 | import java.io.IOException; 10 | 11 | /** 12 | * Created by mikl on 07.08.16. 13 | */ 14 | public class TestXsdValidatingService { 15 | 16 | private static final String VALIDATING_SERVICE = "validatingService"; 17 | 18 | public static void main(String[] args) throws IOException { 19 | try (Ignite ignite = Ignition.start(CommonConstants.CLIENT_CONFIG)) { 20 | 21 | String sample1 = TestDataGenerator.getSample1(); 22 | String sample2 = TestDataGenerator.getSample2(); 23 | byte[] vaidateSchema = TestDataGenerator.getValidateSchema(); 24 | String validateScript = TestDataGenerator.getValidateScript(); 25 | 26 | ignite.services().deployNodeSingleton(VALIDATING_SERVICE, new XsdValidatingServiceImpl()); 27 | 28 | XsdValidatingService xsdValidatingService = ignite.services().serviceProxy(VALIDATING_SERVICE, XsdValidatingService.class, /*not-sticky*/false); 29 | 30 | System.out.println("result=" + xsdValidatingService.isOk(new ValidateMessage("1", sample1, vaidateSchema, validateScript))); 31 | System.out.println("result2=" + xsdValidatingService.isOk(new ValidateMessage("2", sample2, vaidateSchema, validateScript))); 32 | 33 | ignite.services().cancel(VALIDATING_SERVICE); 34 | } 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example7/XsdValidatingService.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example7; 2 | 3 | import com.blu.imdg.example3.ValidateMessage; 4 | 5 | /** 6 | * Created by mikl on 07.08.16. 7 | */ 8 | public interface XsdValidatingService { 9 | boolean isOk(ValidateMessage msg); 10 | } 11 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example7/XsdValidatingServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example7; 2 | 3 | import com.blu.imdg.common.HttpAuditClient; 4 | import com.blu.imdg.common.XsdValidator; 5 | import com.blu.imdg.example3.ValidateMessage; 6 | import org.apache.http.impl.client.CloseableHttpClient; 7 | import org.apache.ignite.services.Service; 8 | import org.apache.ignite.services.ServiceContext; 9 | 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * Created by mikl on 07.08.16. 15 | */ 16 | public class XsdValidatingServiceImpl implements XsdValidatingService, Service { 17 | 18 | private CloseableHttpClient auditClient; 19 | 20 | @Override 21 | public boolean isOk(ValidateMessage msg) { 22 | Boolean validateXsdResult = XsdValidator.validate(msg.getMsg(), msg.getXsd()); 23 | sendResult(msg, validateXsdResult); 24 | return validateXsdResult; 25 | } 26 | 27 | private void sendResult(ValidateMessage msg, Boolean validateXsdResult) { 28 | try { 29 | HttpAuditClient.sendResult(auditClient, validateXsdResult, msg.getId()); 30 | } catch (Exception err) { 31 | err.printStackTrace(); 32 | } 33 | } 34 | 35 | //service methods 36 | 37 | @Override 38 | public void cancel(ServiceContext serviceContext) { 39 | System.out.println("cancel service"); 40 | try { 41 | auditClient.close(); 42 | } catch (IOException e) { 43 | e.printStackTrace(); 44 | } 45 | } 46 | 47 | @Override 48 | public void init(ServiceContext serviceContext) throws Exception { 49 | System.out.println("init service"); 50 | auditClient = (CloseableHttpClient) HttpAuditClient.createHttpClient(); 51 | } 52 | 53 | @Override 54 | public void execute(ServiceContext serviceContext) throws Exception { 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example8/TestAccountSavingsMain.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example8; 2 | 3 | import com.blu.imdg.common.CommonConstants; 4 | import com.blu.imdg.common.bankData.BankDataGenerator; 5 | import com.blu.imdg.common.bankData.model.*; 6 | import org.apache.ignite.Ignite; 7 | import org.apache.ignite.IgniteCache; 8 | import org.apache.ignite.IgniteCompute; 9 | import org.apache.ignite.Ignition; 10 | import org.apache.ignite.cache.query.SqlFieldsQuery; 11 | 12 | import java.math.BigDecimal; 13 | import java.util.List; 14 | 15 | /** 16 | * Created by mikl on 21.10.16. 17 | */ 18 | 19 | //mvn exec:java -Dexec.mainClass=com.blu.imdg.example8.TestAccountSavingsMain 20 | public class TestAccountSavingsMain { 21 | 22 | public static void main(String[] args) { 23 | 24 | try (Ignite ignite = Ignition.start(CommonConstants.CLIENT_CONFIG)) { 25 | IgniteCompute compute = ignite.compute(); 26 | 27 | IgniteCache cache = BankDataGenerator.createBankCache(ignite); 28 | IgniteCache savingsCache = BankDataGenerator.initSavigsCache(ignite); 29 | 30 | SqlFieldsQuery sql = new SqlFieldsQuery("select * from TransactionData where account = ?"); 31 | 32 | BigDecimal result = compute.affinityCall(BankDataGenerator.ACCOUNT_CACHE, new AccountKey(BankDataGenerator.TEST_ACCOUNT), () -> { 33 | //download all transactions for this account 34 | List> data = cache.query(sql.setArgs(BankDataGenerator.TEST_ACCOUNT)).getAll(); 35 | BigDecimal cashBack = new BigDecimal(0); 36 | for (List row : data) { 37 | TransactionKey key = (TransactionKey) row.get(0); 38 | TransactionData tr = (TransactionData) row.get(1); 39 | 40 | CashBackDictionaryData cashBackDictionaryData = savingsCache.get(tr.getTransactionType()); 41 | cashBack = cashBack.add(tr.getSum().multiply(cashBackDictionaryData.getCashBackPercent())); 42 | } 43 | //System.out.println("savings="+cashBack); 44 | return cashBack; 45 | }); 46 | 47 | System.out.println("CashBack="+result); 48 | 49 | } 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example9/BankService.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example9; 2 | 3 | import com.blu.imdg.example9.exception.AccountNotFoundException; 4 | import com.blu.imdg.example9.exception.LogServiceException; 5 | 6 | import java.math.BigDecimal; 7 | 8 | /** 9 | * Created by mikl on 26.10.16. 10 | */ 11 | public interface BankService { 12 | String NAME = "BANK_SERVICE"; 13 | 14 | boolean validateOperation(String account, BigDecimal sum) throws AccountNotFoundException, LogServiceException; 15 | } 16 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example9/DeployService.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example9; 2 | 3 | /** 4 | * Created by shamim on 01/01/17. 5 | */ 6 | import com.blu.imdg.common.CommonConstants; 7 | import com.blu.imdg.common.bankData.BankDataGenerator; 8 | import com.blu.imdg.common.bankData.model.AccountCacheData; 9 | import com.blu.imdg.common.bankData.model.AccountCacheKey; 10 | import com.blu.imdg.example9.exception.AccountNotFoundException; 11 | import com.blu.imdg.example9.exception.LogServiceException; 12 | import org.apache.ignite.Ignite; 13 | import org.apache.ignite.IgniteCache; 14 | import org.apache.ignite.IgniteServices; 15 | import org.apache.ignite.Ignition; 16 | 17 | public class DeployService { 18 | public static void main(String[] args) throws AccountNotFoundException, LogServiceException { 19 | 20 | try (Ignite ignite = Ignition.start(CommonConstants.CLIENT_CONFIG)) { 21 | 22 | IgniteCache cache = BankDataGenerator.createBankCache(ignite); 23 | 24 | IgniteServices services = ignite.services().withAsync(); 25 | 26 | services.deployNodeSingleton(LogService.NAME, new LogServiceImpl()); 27 | services.future().get(); 28 | 29 | services.deployNodeSingleton(BankService.NAME, new BankServiceImpl()); 30 | services.future().get(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example9/LogService.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example9; 2 | 3 | import com.blu.imdg.example9.exception.LogServiceException; 4 | 5 | /** 6 | * Created by mikl on 30.10.16. 7 | */ 8 | public interface LogService { 9 | String NAME = "logService"; 10 | 11 | void logOperation(String operationCode, Boolean result) throws LogServiceException; 12 | } 13 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example9/LogServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example9; 2 | 3 | import com.blu.imdg.common.HttpAuditClient; 4 | import com.blu.imdg.example9.exception.LogServiceException; 5 | import org.apache.http.impl.client.CloseableHttpClient; 6 | import org.apache.ignite.services.Service; 7 | import org.apache.ignite.services.ServiceContext; 8 | 9 | import java.io.IOException; 10 | 11 | /** 12 | * Created by mikl on 30.10.16. 13 | */ 14 | public class LogServiceImpl implements LogService, Service { 15 | private CloseableHttpClient auditClient; 16 | 17 | @Override 18 | public void logOperation(String operationCode, Boolean result) throws LogServiceException { 19 | try { 20 | HttpAuditClient.sendResult(auditClient, result, operationCode); 21 | }catch (Exception err) { 22 | throw new LogServiceException(err); 23 | } 24 | } 25 | 26 | @Override 27 | public void cancel(ServiceContext serviceContext) { 28 | try { 29 | auditClient.close(); 30 | } catch (IOException e) { 31 | e.printStackTrace(); 32 | } 33 | } 34 | 35 | @Override 36 | public void init(ServiceContext serviceContext) throws Exception { 37 | auditClient = (CloseableHttpClient) HttpAuditClient.createHttpClient(); 38 | } 39 | 40 | @Override 41 | public void execute(ServiceContext serviceContext) throws Exception { 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example9/ServiceHttpClient.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example9; 2 | 3 | /** 4 | * Created by shamim on 01/01/17. 5 | */ 6 | import com.blu.imdg.common.CommonConstants; 7 | import com.blu.imdg.common.bankData.BankDataGenerator; 8 | import com.sun.net.httpserver.HttpServer; 9 | import org.apache.ignite.Ignite; 10 | import org.apache.ignite.IgniteServices; 11 | import org.apache.ignite.Ignition; 12 | import org.glassfish.jersey.jdkhttp.JdkHttpServerFactory; 13 | import org.glassfish.jersey.server.ResourceConfig; 14 | 15 | import javax.ws.rs.GET; 16 | import javax.ws.rs.Path; 17 | import javax.ws.rs.Produces; 18 | import javax.ws.rs.QueryParam; 19 | import javax.ws.rs.core.MediaType; 20 | import javax.ws.rs.core.UriBuilder; 21 | import java.math.BigDecimal; 22 | import java.net.URI; 23 | /** 24 | * http://localhost:9988/service/withdrawlimit?accountnum=0000*1111&amount=100 25 | * mvn exec:java -Dexec.mainClass=com.blu.imdg.example9.ServiceHttpClient 26 | * */ 27 | 28 | @Path("/service") 29 | public class ServiceHttpClient { 30 | private static BankService bankService; 31 | @GET 32 | @Path("/withdrawlimit") 33 | @Produces(MediaType.TEXT_PLAIN) 34 | public boolean acceptResponse ( 35 | @QueryParam("accountnum") String accnum, 36 | @QueryParam("amount") int amount 37 | ) throws Exception 38 | { 39 | System.out.println("account number=" + accnum + " amount=" + amount); 40 | 41 | return bankService.validateOperation(accnum, new BigDecimal(amount)); 42 | } 43 | 44 | public static void main(String[] args) { 45 | URI baseUri = UriBuilder.fromUri("http://localhost/").port(9988).build(); 46 | // start the Ignite client 47 | Ignite ignite = Ignition.start(CommonConstants.CLIENT_CONFIG); 48 | IgniteServices services = ignite.services().withAsync(); 49 | 50 | bankService = services.serviceProxy(BankService.NAME, BankService.class, /*not-sticky*/false); 51 | 52 | ResourceConfig config = new ResourceConfig(ServiceHttpClient.class); 53 | HttpServer server = JdkHttpServerFactory.createHttpServer(baseUri, config); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example9/TestMicroServiceMain.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example9; 2 | 3 | import com.blu.imdg.common.CommonConstants; 4 | import com.blu.imdg.common.bankData.BankDataGenerator; 5 | import com.blu.imdg.common.bankData.model.AccountCacheData; 6 | import com.blu.imdg.common.bankData.model.AccountCacheKey; 7 | import com.blu.imdg.example9.exception.AccountNotFoundException; 8 | import com.blu.imdg.example9.exception.LogServiceException; 9 | import org.apache.ignite.Ignite; 10 | import org.apache.ignite.IgniteCache; 11 | import org.apache.ignite.IgniteServices; 12 | import org.apache.ignite.Ignition; 13 | 14 | import java.math.BigDecimal; 15 | 16 | /** 17 | * Created by mikl on 29.10.16. 18 | */ 19 | public class TestMicroServiceMain { 20 | 21 | public static void main(String[] args) throws AccountNotFoundException, LogServiceException { 22 | try (Ignite ignite = Ignition.start(CommonConstants.CLIENT_CONFIG)) { 23 | 24 | IgniteCache cache = BankDataGenerator.createBankCache(ignite); 25 | 26 | IgniteServices services = ignite.services().withAsync(); 27 | 28 | services.deployNodeSingleton(LogService.NAME, new LogServiceImpl()); 29 | services.future().get(); 30 | 31 | services.deployNodeSingleton(BankService.NAME, new BankServiceImpl()); 32 | services.future().get(); 33 | 34 | BankService bankService = services.serviceProxy(BankService.NAME, BankService.class, /*not-sticky*/false); 35 | 36 | System.out.println("result=" + bankService.validateOperation(BankDataGenerator.TEST_ACCOUNT, new BigDecimal(50))); 37 | System.out.println("result1=" + bankService.validateOperation(BankDataGenerator.TEST_ACCOUNT, new BigDecimal(40))); 38 | System.out.println("result2=" + bankService.validateOperation(BankDataGenerator.TEST_ACCOUNT, new BigDecimal(180))); 39 | 40 | services.cancel(BankService.NAME); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example9/exception/AccountNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example9.exception; 2 | 3 | /** 4 | * Created by mikl on 29.10.16. 5 | */ 6 | public class AccountNotFoundException extends Exception { 7 | public AccountNotFoundException(String message) { 8 | super(message); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/java/com/blu/imdg/example9/exception/LogServiceException.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.example9.exception; 2 | 3 | /** 4 | * Created by mikl on 30.10.16. 5 | */ 6 | public class LogServiceException extends Exception { 7 | public LogServiceException(Throwable cause) { 8 | super(cause); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/resources/META-INF/org/book/examples/cache-node-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/resources/META-INF/org/book/examples/data/sample1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | header1 5 | value1 6 | 7 | 8 | header2 9 | value2 10 | 11 | 12 | 1 13 | test 14 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/resources/META-INF/org/book/examples/data/sample2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | header1 5 | value1 6 | 7 | 8 | header2 9 | value2 10 | 11 | 12 | 1 13 | test 14 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/resources/META-INF/org/book/examples/data/sample3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | header1 5 | value1 6 | 7 | 8 | 1 9 | body3 10 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/resources/META-INF/org/book/examples/data/validate-schema.xsd: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/resources/META-INF/org/book/examples/data/validate-script.js: -------------------------------------------------------------------------------- 1 | xpath("//*[local-name()='message']/*[local-name()='body']").length >0 && xpath("//*[local-name()='message']/*[local-name()='priority']")==1 -------------------------------------------------------------------------------- /chapters/chapter-dist-computing/src/main/resources/META-INF/org/book/examples/simple-client-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /chapters/chapter-installation/src/main/java/com/blu/dto/Person.java: -------------------------------------------------------------------------------- 1 | package com.blu.dto; 2 | 3 | import org.apache.ignite.cache.query.annotations.QuerySqlField; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * Created by shamim on 19/10/16. 9 | */ 10 | public class Person implements Serializable 11 | { 12 | 13 | @QuerySqlField(index = true) 14 | private String name; 15 | 16 | @QuerySqlField(index = true) 17 | private int age; 18 | 19 | public Person(int age, String name) 20 | { 21 | this.age = age; 22 | this.name = name; 23 | } 24 | 25 | public String getName() { 26 | return name; 27 | } 28 | 29 | public void setName(String name) { 30 | this.name = name; 31 | } 32 | 33 | public int getAge() { 34 | return age; 35 | } 36 | 37 | public void setAge(int age) { 38 | this.age = age; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /chapters/chapter-installation/src/main/java/com/blu/imdg/HelloIgnite.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg; 2 | import org.apache.ignite.Ignite; 3 | import org.apache.ignite.IgniteCache; 4 | import org.apache.ignite.Ignition; 5 | import org.apache.ignite.configuration.IgniteConfiguration; 6 | import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; 7 | import org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder; 8 | 9 | 10 | import java.util.Arrays; 11 | /** 12 | * User: bsha 13 | * Date: 18.06.2016 14 | * Time: 11:45 15 | */ 16 | public class HelloIgnite { 17 | public static void main(String[] args) { 18 | System.out.println("Hello Ignite"); 19 | // create a new instance of TCP Discovery SPI 20 | TcpDiscoverySpi spi = new TcpDiscoverySpi(); 21 | // create a new instance of tcp discovery multicast ip finder 22 | TcpDiscoveryMulticastIpFinder tcMp = new TcpDiscoveryMulticastIpFinder(); 23 | tcMp.setAddresses(Arrays.asList("localhost")); // change your IP address here 24 | // set the multi cast ip finder for spi 25 | spi.setIpFinder(tcMp); 26 | // create new ignite configuration 27 | IgniteConfiguration cfg = new IgniteConfiguration(); 28 | cfg.setClientMode(false); 29 | // set the discovery spi to ignite configuration 30 | cfg.setDiscoverySpi(spi); 31 | // Start ignite 32 | Ignite ignite = Ignition.start(cfg); 33 | // get or create cache 34 | IgniteCache cache = ignite.getOrCreateCache("testCache"); 35 | // put some cache elements 36 | for(int i = 1; i <= 100; i++){ 37 | cache.put(i, Integer.toString(i)); 38 | } 39 | // get them from the cache and write to the console 40 | for(int i =1; i<= 100; i++){ 41 | System.out.println("Cache get:"+ cache.get(i)); 42 | } 43 | ignite.close(); 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /chapters/chapter-installation/src/main/java/com/blu/imdg/HelloIgniteAsyn.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg; 2 | 3 | import org.apache.ignite.Ignite; 4 | import org.apache.ignite.IgniteCache; 5 | import org.apache.ignite.Ignition; 6 | import org.apache.ignite.configuration.IgniteConfiguration; 7 | import org.apache.ignite.lang.IgniteFuture; 8 | import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; 9 | import org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder; 10 | 11 | import java.util.Arrays; 12 | 13 | /** 14 | * Created by shamim on 23/10/16. 15 | */ 16 | public class HelloIgniteAsyn { 17 | public static void main(String[] args) { 18 | System.out.println("Hello Ignite Asynchronous!!"); 19 | // create a new instance of TCP Discovery SPI 20 | TcpDiscoverySpi spi = new TcpDiscoverySpi(); 21 | // create a new instance of tcp discovery multicast ip finder 22 | TcpDiscoveryMulticastIpFinder tcMp = new TcpDiscoveryMulticastIpFinder(); 23 | tcMp.setAddresses(Arrays.asList("localhost")); // change your IP address here 24 | // set the multi cast ip finder for spi 25 | spi.setIpFinder(tcMp); 26 | // create new ignite configuration 27 | IgniteConfiguration cfg = new IgniteConfiguration(); 28 | cfg.setClientMode(false); 29 | // set the discovery spi to ignite configuration 30 | cfg.setDiscoverySpi(spi); 31 | // Start ignite 32 | Ignite ignite = Ignition.start(cfg); 33 | 34 | // get or create cache 35 | IgniteCache cache = ignite.getOrCreateCache("testCache"); 36 | // get an asynchronous cache 37 | IgniteCache asynCache = cache.withAsync(); 38 | 39 | // put some cache elements 40 | for(int i = 1; i <= 100; i++){ 41 | cache.put(i, Integer.toString(i)); 42 | } 43 | 44 | String val = asynCache.withAsync().get(1); 45 | System.out.println("Non future call:" + val); 46 | IgniteFuture igniteFuture = asynCache.future(); 47 | 48 | 49 | 50 | igniteFuture.listen(f-> System.out.println("Cache Value:" + f.get())); 51 | ignite.close(); 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /chapters/chapter-installation/src/main/java/com/blu/imdg/HelloIgniteSpring.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg; 2 | 3 | import com.blu.dto.Person; 4 | import org.apache.ignite.Ignite; 5 | import org.apache.ignite.IgniteCache; 6 | import org.apache.ignite.Ignition; 7 | import org.apache.ignite.configuration.CacheConfiguration; 8 | import org.apache.ignite.configuration.IgniteConfiguration; 9 | 10 | /** 11 | * Created by shamim on 19/10/16. 12 | */ 13 | public class HelloIgniteSpring { 14 | public static void main(String[] args) { 15 | // Start Ignite cluster 16 | Ignite ignite = Ignition.start("default-config.xml"); 17 | 18 | // get or create cache 19 | IgniteCache cache = ignite.getOrCreateCache("testCache"); 20 | Person p1 = new Person(37, "Shamim"); 21 | Person p2 = new Person(2, "Mishel"); 22 | Person p3 = new Person(55, "scott"); 23 | Person p4 = new Person(5, "Tiger"); 24 | 25 | cache.put(1, p1); 26 | cache.put(2, p2); 27 | cache.put(3, p3); 28 | cache.put(4, p4); 29 | 30 | System.out.println("Enter crtl-x to quite the application!!!"); 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/expiry/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.blu.imdg 8 | chapter-persistence 9 | 1.0-SNAPSHOT 10 | 11 | com.blu.imdg 12 | expiry 13 | 1.0-SNAPSHOT 14 | expiry 15 | http://maven.apache.org 16 | 17 | UTF-8 18 | 19 | 20 | 21 | junit 22 | junit 23 | 3.8.1 24 | test 25 | 26 | 27 | org.apache.ignite 28 | ignite-core 29 | ${ignite.version} 30 | 31 | 32 | org.apache.ignite 33 | ignite-spring 34 | 35 | 36 | 37 | 38 | 39 | org.apache.maven.plugins 40 | maven-compiler-plugin 41 | 42 | 1.8 43 | 1.8 44 | 45 | 46 | 47 | com.jolira 48 | onejar-maven-plugin 49 | 1.4.4 50 | 51 | 52 | expiry-entries 53 | 54 | com.blu.imdg.IgniteExpiryExample 55 | true 56 | onejar 57 | ignite-expiry.jar 58 | 59 | 60 | one-jar 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/expiry/src/main/java/com/blu/imdg/IgniteExpiryExample.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg; 2 | 3 | import org.apache.ignite.Ignite; 4 | import org.apache.ignite.IgniteCache; 5 | import org.apache.ignite.Ignition; 6 | import org.apache.ignite.cache.query.annotations.QuerySqlField; 7 | 8 | import java.io.Serializable; 9 | 10 | /** 11 | * Created by shamim on 02/01/17. 12 | */ 13 | public class IgniteExpiryExample { 14 | public static void main(String[] args) { 15 | // Start Ignite cluster 16 | Ignite ignite = Ignition.start("default-config.xml"); 17 | 18 | // get or create cache 19 | IgniteCache cache = ignite.getOrCreateCache("testCache"); 20 | Person p1 = new Person(37, "Shamim"); 21 | Person p2 = new Person(2, "Mishel"); 22 | Person p3 = new Person(55, "scott"); 23 | Person p4 = new Person(5, "Tiger"); 24 | 25 | cache.put(1, p1); 26 | cache.put(2, p2); 27 | cache.put(3, p3); 28 | cache.put(4, p4); 29 | 30 | System.out.println("Enter crtl-x to quite the application!!!"); 31 | 32 | } 33 | private static class Person implements Serializable 34 | { 35 | 36 | @QuerySqlField(index = true) 37 | private String name; 38 | 39 | @QuerySqlField(index = true) 40 | private int age; 41 | 42 | public Person(int age, String name) 43 | { 44 | this.age = age; 45 | this.name = name; 46 | } 47 | 48 | public String getName() { 49 | return name; 50 | } 51 | 52 | public void setName(String name) { 53 | this.name = name; 54 | } 55 | 56 | public int getAge() { 57 | return age; 58 | } 59 | 60 | public void setAge(int age) { 61 | this.age = age; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/persistence-store/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/persistence-store/src/main/java/com/blu/imdg/jdbc/model/Post.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.jdbc.model; 2 | 3 | import java.io.Serializable; 4 | import java.time.LocalDate; 5 | import java.util.Objects; 6 | 7 | /** 8 | * Created by developer on 9/26/16. 9 | */ 10 | public class Post implements Serializable { 11 | private static final long serialVersionUID = 0L; 12 | 13 | private String id; 14 | private String title; 15 | private String description; 16 | private LocalDate creationDate; 17 | private String author; 18 | 19 | public Post() { 20 | } 21 | 22 | public Post(String id, String title, String description, LocalDate creationDate, String author) { 23 | this.id = id; 24 | this.title = title; 25 | this.description = description; 26 | this.creationDate = creationDate; 27 | this.author = author; 28 | } 29 | 30 | public String getId() { 31 | return id; 32 | } 33 | 34 | public void setId(String id) { 35 | this.id = id; 36 | } 37 | 38 | public String getTitle() { 39 | return title; 40 | } 41 | 42 | public void setTitle(String title) { 43 | this.title = title; 44 | } 45 | 46 | public String getDescription() { 47 | return description; 48 | } 49 | 50 | public void setDescription(String description) { 51 | this.description = description; 52 | } 53 | 54 | public LocalDate getCreationDate() { 55 | return creationDate; 56 | } 57 | 58 | public void setCreationDate(LocalDate creationDate) { 59 | this.creationDate = creationDate; 60 | } 61 | 62 | public String getAuthor() { 63 | return author; 64 | } 65 | 66 | public void setAuthor(String author) { 67 | this.author = author; 68 | } 69 | 70 | @Override public boolean equals(Object o) { 71 | if (this == o) 72 | return true; 73 | if (o == null || getClass() != o.getClass()) 74 | return false; 75 | Post post = (Post)o; 76 | return Objects.equals(id, post.id) && 77 | Objects.equals(title, post.title) && 78 | Objects.equals(description, post.description) && 79 | Objects.equals(creationDate, post.creationDate) && 80 | Objects.equals(author, post.author); 81 | } 82 | 83 | @Override public int hashCode() { 84 | return Objects.hash(id, title, description, creationDate, author); 85 | } 86 | 87 | @Override public String toString() { 88 | return "Post{" + 89 | "id='" + id + '\'' + 90 | ", title='" + title + '\'' + 91 | ", description='" + description + '\'' + 92 | ", creationDate=" + creationDate + 93 | ", author='" + author + '\'' + 94 | '}'; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/persistence-store/src/main/java/com/blu/imdg/nosql/MongoDBStore.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.nosql; 2 | 3 | import com.blu.imdg.nosql.model.MongoPost; 4 | import javax.cache.Cache; 5 | import javax.cache.integration.CacheLoaderException; 6 | import javax.cache.integration.CacheWriterException; 7 | import org.apache.ignite.IgniteException; 8 | import org.apache.ignite.cache.store.CacheStoreAdapter; 9 | import org.apache.ignite.lifecycle.LifecycleAware; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.context.ConfigurableApplicationContext; 14 | import org.springframework.context.support.ClassPathXmlApplicationContext; 15 | import org.springframework.data.mongodb.core.MongoOperations; 16 | 17 | /** 18 | * Let's have a look at simple implemention of CacheStore for MongoDB. Created by developer on 9/26/16. 19 | */ 20 | public class MongoDBStore extends CacheStoreAdapter implements LifecycleAware { 21 | 22 | @Autowired 23 | private PostRepository postRepository; 24 | @Autowired 25 | private MongoOperations mongoOperations; 26 | 27 | private static Logger logger = LoggerFactory.getLogger(MongoDBStore.class); 28 | 29 | @Override public MongoPost load(String key) throws CacheLoaderException { 30 | 31 | logger.info(String.valueOf(postRepository)); 32 | return postRepository.findOne(key); 33 | } 34 | 35 | @Override public void write(Cache.Entry entry) throws CacheWriterException { 36 | MongoPost post = entry.getValue(); 37 | logger.info(String.valueOf(postRepository)); 38 | postRepository.save(post); 39 | } 40 | 41 | @Override public void delete(Object key) throws CacheWriterException { 42 | logger.info(String.valueOf(postRepository)); 43 | postRepository.delete((String)key); 44 | } 45 | 46 | @Override public void start() throws IgniteException { 47 | ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("mongo-context.xml"); 48 | postRepository = context.getBean(PostRepository.class); 49 | logger.info(String.valueOf(postRepository)); 50 | mongoOperations = context.getBean(MongoOperations.class); 51 | if (!mongoOperations.collectionExists(MongoPost.class)) 52 | mongoOperations.createCollection(MongoPost.class); 53 | 54 | } 55 | 56 | @Override public void stop() throws IgniteException { 57 | // if (mongoOperations.collectionExists(MongoPost.class)) 58 | // mongoOperations.dropCollection(MongoPost.class); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/persistence-store/src/main/java/com/blu/imdg/nosql/PostRepository.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.nosql; 2 | 3 | import com.blu.imdg.nosql.model.MongoPost; 4 | import org.springframework.data.mongodb.repository.MongoRepository; 5 | import org.springframework.data.querydsl.QueryDslPredicateExecutor; 6 | 7 | /** 8 | * Created by developer on 9/26/16. 9 | */ 10 | public interface PostRepository extends MongoRepository{ 11 | 12 | } 13 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/persistence-store/src/main/java/com/blu/imdg/nosql/model/MongoPost.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.nosql.model; 2 | 3 | import java.time.LocalDate; 4 | import java.util.Objects; 5 | import org.springframework.data.annotation.Id; 6 | import org.springframework.data.mongodb.core.mapping.Document; 7 | 8 | /** 9 | * Created by developer on 9/26/16. 10 | */ 11 | @Document 12 | public class MongoPost { 13 | @Id 14 | private String id; 15 | private String title; 16 | private String description; 17 | private LocalDate creationDate; 18 | private String author; 19 | 20 | public MongoPost() { 21 | } 22 | 23 | public MongoPost(String id, String title, String description, LocalDate creationDate, String author) { 24 | this.id = id; 25 | this.title = title; 26 | this.description = description; 27 | this.creationDate = creationDate; 28 | this.author = author; 29 | } 30 | 31 | public String getId() { 32 | return id; 33 | } 34 | 35 | public void setId(String id) { 36 | this.id = id; 37 | } 38 | 39 | public String getTitle() { 40 | return title; 41 | } 42 | 43 | public void setTitle(String title) { 44 | this.title = title; 45 | } 46 | 47 | public String getDescription() { 48 | return description; 49 | } 50 | 51 | public void setDescription(String description) { 52 | this.description = description; 53 | } 54 | 55 | public LocalDate getCreationDate() { 56 | return creationDate; 57 | } 58 | 59 | public void setCreationDate(LocalDate creationDate) { 60 | this.creationDate = creationDate; 61 | } 62 | 63 | public String getAuthor() { 64 | return author; 65 | } 66 | 67 | public void setAuthor(String author) { 68 | this.author = author; 69 | } 70 | 71 | @Override public boolean equals(Object o) { 72 | if (this == o) 73 | return true; 74 | if (o == null || getClass() != o.getClass()) 75 | return false; 76 | MongoPost post = (MongoPost)o; 77 | return Objects.equals(id, post.id) && 78 | Objects.equals(title, post.title) && 79 | Objects.equals(description, post.description) && 80 | Objects.equals(creationDate, post.creationDate) && 81 | Objects.equals(author, post.author); 82 | } 83 | 84 | @Override public int hashCode() { 85 | return Objects.hash(id, title, description, creationDate, author); 86 | } 87 | 88 | @Override public String toString() { 89 | return "MongoPost{" + 90 | "id='" + id + '\'' + 91 | ", title='" + title + '\'' + 92 | ", description='" + description + '\'' + 93 | ", creationDate=" + creationDate + 94 | ", author='" + author + '\'' + 95 | '}'; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/persistence-store/src/main/resources/create-db-scheme.ddl: -------------------------------------------------------------------------------- 1 | DROP TABLE IF EXISTS POSTS; 2 | CREATE TABLE POSTS ( 3 | id VARCHAR(150), 4 | title VARCHAR(255), 5 | description TEXT, 6 | creationDate DATE, 7 | author VARCHAR(150) 8 | ); 9 | DROP INDEX IF EXISTS posts_id_uindex; 10 | CREATE UNIQUE INDEX posts_id_uindex ON POSTS (id); 11 | ALTER TABLE POSTS 12 | ADD CONSTRAINT posts_id_pk PRIMARY KEY (id); 13 | ALTER TABLE POSTS 14 | ALTER COLUMN id SET NOT NULL; 15 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/persistence-store/src/main/resources/jdbc.properties: -------------------------------------------------------------------------------- 1 | jdbc.driver=org.postgresql.Driver 2 | jdbc.url=jdbc:postgresql://localhost:5432/postgres 3 | jdbc.username=postgres 4 | jdbc.password=postgres 5 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/persistence-store/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/persistence-store/src/main/resources/mongo-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/persistence-store/src/main/resources/postgres-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | com.blu.imdg 6 | chapters 7 | 1.0-SNAPSHOT 8 | ../../chapters 9 | 10 | com.blu.imdg 11 | chapter-persistence 12 | 1.0-SNAPSHOT 13 | chapter-persistence 14 | pom 15 | 16 | persistence-store 17 | sqlqueries 18 | textquery 19 | transactions 20 | expiry 21 | spring-data 22 | 23 | 24 | UTF-8 25 | 1.6.0 26 | 27 | 28 | 29 | junit 30 | junit 31 | 3.8.1 32 | test 33 | 34 | 35 | org.apache.ignite 36 | ignite-core 37 | ${ignite.version} 38 | 39 | 40 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/spring-data/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.blu.imdg 8 | chapter-persistence 9 | 1.0-SNAPSHOT 10 | 11 | com.blu.imdg 12 | spring-data 13 | 1.0-SNAPSHOT 14 | spring-data 15 | http://maven.apache.org 16 | 17 | UTF-8 18 | 2.0.0 19 | 1.6.1 20 | 1.0.1 21 | 22 | 23 | 24 | org.apache.ignite 25 | ignite-core 26 | 2.0.0 27 | 28 | 29 | org.apache.ignite 30 | ignite-spring 31 | 2.0.0 32 | 33 | 34 | org.apache.ignite 35 | ignite-spring-data 36 | 2.0.0 37 | 38 | 39 | org.apache.ignite 40 | ignite-indexing 41 | 2.0.0 42 | 43 | 44 | com.h2database 45 | h2 46 | 1.4.195 47 | 48 | 49 | 50 | 51 | 52 | org.apache.maven.plugins 53 | maven-compiler-plugin 54 | 55 | 1.8 56 | 1.8 57 | 58 | 59 | 60 | 61 | org.codehaus.mojo 62 | exec-maven-plugin 63 | 1.2.1 64 | 65 | 66 | 67 | java 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/spring-data/src/main/java/com/blu/imdg/App.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg; 2 | 3 | import com.blu.imdg.model.Breed; 4 | import com.blu.imdg.model.Dog; 5 | import com.blu.imdg.repositories.BreedRepository; 6 | import com.blu.imdg.repositories.DogRepository; 7 | import com.blu.imdg.repositories.SpringAppConfig; 8 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 9 | 10 | import java.sql.Date; 11 | import java.util.List; 12 | 13 | /** 14 | * Hello world! 15 | * 16 | */ 17 | public class App 18 | { 19 | private static AnnotationConfigApplicationContext ctx; 20 | private static BreedRepository breedRepository; 21 | private static DogRepository dogRepository; 22 | 23 | public static void main( String[] args ) 24 | { 25 | System.out.println( "Spring Data Example!" ); 26 | ctx = new AnnotationConfigApplicationContext(); 27 | ctx.register(SpringAppConfig.class); 28 | ctx.refresh(); 29 | 30 | breedRepository = ctx.getBean(BreedRepository.class); 31 | dogRepository = ctx.getBean(DogRepository.class); 32 | 33 | //fill the repository with data and Save 34 | Breed collie = new Breed(); 35 | collie.setId(1L); 36 | collie.setName("collie"); 37 | //save Breed with name collie 38 | breedRepository.save(1L, collie); 39 | 40 | System.out.println("Add one breed in the repository!"); 41 | // Query the breed 42 | List getAllBreeds = breedRepository.getAllBreedsByName("collie"); 43 | 44 | for(Breed breed : getAllBreeds){ 45 | System.out.println("Breed:" + breed); 46 | } 47 | //Add some dogs 48 | Dog dina = new Dog(); 49 | dina.setName("dina"); 50 | dina.setId(1L); 51 | dina.setBreedid(1L); 52 | dina.setBirthdate(new Date(System.currentTimeMillis())); 53 | //Save Dina 54 | dogRepository.save(2L,dina); 55 | System.out.println("Dog dina save into the cache!"); 56 | //Query the Dog Dina 57 | List dogs = dogRepository.getDogByName("dina"); 58 | for(Dog dog : dogs){ 59 | System.out.println("Dog:"+ dog); 60 | } 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/spring-data/src/main/java/com/blu/imdg/model/Breed.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.model; 2 | 3 | import org.apache.ignite.cache.query.annotations.QuerySqlField; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * Created by shamim on 08/07/17. 9 | */ 10 | public class Breed implements Serializable { 11 | 12 | @QuerySqlField(index = true) 13 | private Long id; 14 | 15 | @QuerySqlField(index = true) 16 | private String name; 17 | 18 | public Long getId() { 19 | 20 | return id; 21 | } 22 | 23 | public void setId(Long id) { 24 | this.id = id; 25 | } 26 | 27 | public String getName() { 28 | return name; 29 | } 30 | 31 | public void setName(String name) { 32 | this.name = name; 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return "Breed{" + 38 | "id='" + id + '\'' + 39 | ", name='" + name + '\'' + 40 | '}'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/spring-data/src/main/java/com/blu/imdg/model/Dog.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.model; 2 | 3 | import org.apache.ignite.cache.query.annotations.QuerySqlField; 4 | 5 | import java.io.Serializable; 6 | import java.sql.Date; 7 | 8 | /** 9 | * Created by shamim on 08/07/17. 10 | */ 11 | public class Dog implements Serializable { 12 | 13 | @QuerySqlField(index = true) 14 | private Long id; 15 | @QuerySqlField(index = true) 16 | private String name; 17 | @QuerySqlField(index = true) 18 | private Long breedid; 19 | @QuerySqlField(index = true) 20 | private Date birthdate; 21 | 22 | public Long getId() { 23 | return id; 24 | } 25 | 26 | public void setId(Long id) { 27 | this.id = id; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public void setName(String name) { 35 | this.name = name; 36 | } 37 | 38 | public Long getBreedid() { 39 | return breedid; 40 | } 41 | 42 | public void setBreedid(Long breedid) { 43 | this.breedid = breedid; 44 | } 45 | 46 | public Date getBirthdate() { 47 | return birthdate; 48 | } 49 | 50 | public void setBirthdate(Date birthdate) { 51 | this.birthdate = birthdate; 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return "Dog{" + 57 | "id=" + id + 58 | ", name='" + name + '\'' + 59 | ", breedid=" + breedid + 60 | ", birthdate=" + birthdate + 61 | '}'; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/spring-data/src/main/java/com/blu/imdg/repositories/BreedRepository.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.repositories; 2 | 3 | import com.blu.imdg.model.Breed; 4 | import org.apache.ignite.springdata.repository.IgniteRepository; 5 | import org.apache.ignite.springdata.repository.config.Query; 6 | import org.apache.ignite.springdata.repository.config.RepositoryConfig; 7 | import org.springframework.data.domain.Pageable; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * Created by shamim on 08/07/17. 13 | */ 14 | @RepositoryConfig(cacheName = "BreedCache") 15 | public interface BreedRepository extends IgniteRepository { 16 | 17 | List getAllBreedsByName (String name); 18 | 19 | @Query("SELECT id FROM Breed WHERE id = ?") 20 | List getById (long id, Pageable pageable); 21 | } 22 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/spring-data/src/main/java/com/blu/imdg/repositories/DogRepository.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.repositories; 2 | 3 | import com.blu.imdg.model.Dog; 4 | import org.apache.ignite.springdata.repository.IgniteRepository; 5 | import org.apache.ignite.springdata.repository.config.RepositoryConfig; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by shamim on 08/07/17. 11 | */ 12 | @RepositoryConfig(cacheName = "DogCache") 13 | public interface DogRepository extends IgniteRepository { 14 | List getDogByName(String name); 15 | Dog getDogById (Long id); 16 | } 17 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/spring-data/src/main/java/com/blu/imdg/repositories/SpringAppConfig.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.repositories; 2 | 3 | import com.blu.imdg.model.Breed; 4 | import com.blu.imdg.model.Dog; 5 | import org.apache.ignite.Ignite; 6 | import org.apache.ignite.Ignition; 7 | import org.apache.ignite.configuration.CacheConfiguration; 8 | import org.apache.ignite.configuration.IgniteConfiguration; 9 | import org.apache.ignite.springdata.repository.config.EnableIgniteRepositories; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.Configuration; 12 | 13 | /** 14 | * Created by shamim on 08/07/17. 15 | */ 16 | @Configuration 17 | @EnableIgniteRepositories 18 | public class SpringAppConfig { 19 | @Bean 20 | public Ignite igniteInstance() { 21 | IgniteConfiguration cfg = new IgniteConfiguration(); 22 | 23 | // Setting some custom name for the node. 24 | cfg.setIgniteInstanceName("springDataNode"); 25 | 26 | // Enabling peer-class loading feature. 27 | cfg.setPeerClassLoadingEnabled(true); 28 | 29 | // Defining and creating a new cache to be used by Ignite Spring Data 30 | // repository. 31 | CacheConfiguration ccfgDog = new CacheConfiguration("DogCache"); 32 | CacheConfiguration ccfgBreed = new CacheConfiguration("BreedCache"); 33 | 34 | // Setting SQL schema for the cache. 35 | ccfgBreed.setIndexedTypes(Long.class, Breed.class); 36 | ccfgDog.setIndexedTypes(Long.class, Dog.class); 37 | 38 | 39 | cfg.setCacheConfiguration(new CacheConfiguration[]{ccfgDog, ccfgBreed}); 40 | 41 | 42 | return Ignition.start(cfg); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/sqlqueries/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/sqlqueries/src/main/java/com/blu/imdg/model/Department.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.model; 2 | 3 | import java.io.Serializable; 4 | import java.util.Objects; 5 | import java.util.concurrent.atomic.AtomicInteger; 6 | import org.apache.ignite.cache.query.annotations.QuerySqlField; 7 | 8 | /** 9 | * Created by isatimur on 8/9/16. 10 | */ 11 | public class Department implements Serializable { 12 | private static final AtomicInteger GENERATED_ID = new AtomicInteger(); 13 | 14 | @QuerySqlField(index = true) 15 | private Integer deptno; 16 | 17 | @QuerySqlField 18 | private String dname; 19 | 20 | @QuerySqlField 21 | private String loc; 22 | 23 | public Department(String dname, String loc) { 24 | this.deptno = GENERATED_ID.incrementAndGet(); 25 | this.dname = dname; 26 | this.loc = loc; 27 | } 28 | 29 | public Integer getDeptno() { 30 | return deptno; 31 | } 32 | 33 | public void setDeptno(Integer deptno) { 34 | this.deptno = deptno; 35 | } 36 | 37 | public String getDname() { 38 | return dname; 39 | } 40 | 41 | public void setDname(String dname) { 42 | this.dname = dname; 43 | } 44 | 45 | public String getLoc() { 46 | return loc; 47 | } 48 | 49 | public void setLoc(String loc) { 50 | this.loc = loc; 51 | } 52 | 53 | @Override public boolean equals(Object o) { 54 | if (this == o) 55 | return true; 56 | if (o == null || getClass() != o.getClass()) 57 | return false; 58 | Department that = (Department)o; 59 | return Objects.equals(deptno, that.deptno) && 60 | Objects.equals(dname, that.dname) && 61 | Objects.equals(loc, that.loc); 62 | } 63 | 64 | @Override public int hashCode() { 65 | return Objects.hash(deptno, dname, loc); 66 | } 67 | 68 | @Override public String toString() { 69 | return "Department[" + 70 | "deptno=" + deptno + 71 | ", dname='" + dname + '\'' + 72 | ", loc='" + loc + '\'' + 73 | ']'; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/sqlqueries/src/main/java/com/blu/imdg/model/EmployeeKey.java: -------------------------------------------------------------------------------- 1 | package com.blu.imdg.model; 2 | 3 | import java.io.Serializable; 4 | import java.util.Objects; 5 | import org.apache.ignite.cache.affinity.AffinityKeyMapped; 6 | 7 | /** 8 | * Created by isatimur on 8/10/16. 9 | */ 10 | public class EmployeeKey implements Serializable { 11 | 12 | private final int empNo; 13 | 14 | @AffinityKeyMapped 15 | private final int deptNo; 16 | 17 | public EmployeeKey(int empNo, int deptNo) { 18 | this.empNo = empNo; 19 | this.deptNo = deptNo; 20 | } 21 | 22 | public int getEmpNo() { 23 | return empNo; 24 | } 25 | 26 | public int getDeptNo() { 27 | return deptNo; 28 | } 29 | 30 | @Override public boolean equals(Object o) { 31 | if (this == o) 32 | return true; 33 | if (o == null || getClass() != o.getClass()) 34 | return false; 35 | EmployeeKey key = (EmployeeKey)o; 36 | return empNo == key.empNo && 37 | deptNo == key.deptNo; 38 | } 39 | 40 | @Override public int hashCode() { 41 | return Objects.hash(empNo, deptNo); 42 | } 43 | 44 | @Override public String toString() { 45 | return "EmployeeKey[" + 46 | "empNo=" + empNo + 47 | ", deptNo=" + deptNo + 48 | ']'; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/sqlqueries/src/main/resources/create-table.ddl: -------------------------------------------------------------------------------- 1 | create table dept( 2 | deptno number(2,0), 3 | dname varchar2(14), 4 | loc varchar2(13), 5 | constraint pk_dept primary key (deptno) 6 | ); 7 | 8 | create table emp( 9 | empno number(4,0), 10 | ename varchar2(10), 11 | job varchar2(9), 12 | mgr number(4,0), 13 | hiredate date, 14 | sal number(7,2), 15 | comm number(7,2), 16 | deptno number(2,0), 17 | constraint pk_emp primary key (empno), 18 | constraint fk_deptno foreign key (deptno) references dept (deptno) 19 | ); 20 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/sqlqueries/src/main/resources/example-ignite.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 24 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 127.0.0.1:47500 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/sqlqueries/src/main/resources/insert-data.dml: -------------------------------------------------------------------------------- 1 | 2 | insert into dept 3 | values(10, 'ACCOUNTING', 'NEW YORK'); 4 | insert into dept 5 | values(20, 'RESEARCH', 'DALLAS'); 6 | insert into dept 7 | values(30, 'SALES', 'CHICAGO'); 8 | insert into dept 9 | values(40, 'OPERATIONS', 'BOSTON'); 10 | 11 | insert into emp 12 | values( 13 | 7839, 'KING', 'PRESIDENT', null, 14 | parsedatetime('17-11-1981 00:00:00.00', 'dd-MM-yyyy hh:mm:ss.SS'), 15 | 5000, null, 10 16 | ); 17 | insert into emp 18 | values( 19 | 7698, 'BLAKE', 'MANAGER', 7839, 20 | parsedatetime('1-5-1981 00:00:00.00', 'dd-MM-yyyy hh:mm:ss.SS'), 21 | 2850, null, 30 22 | ); 23 | insert into emp 24 | values( 25 | 7782, 'CLARK', 'MANAGER', 7839, 26 | parsedatetime('9-6-1981 00:00:00.00', 'dd-MM-yyyy hh:mm:ss.SS'), 27 | 2450, null, 10 28 | ); 29 | insert into emp 30 | values( 31 | 7566, 'JONES', 'MANAGER', 7839, 32 | parsedatetime('2-4-1981 00:00:00.00', 'dd-MM-yyyy hh:mm:ss.SS'), 33 | 2975, null, 20 34 | ); 35 | insert into emp 36 | values( 37 | 7788, 'SCOTT', 'ANALYST', 7566, 38 | parsedatetime('13-7-1987 00:00:00.00', 'dd-MM-yyyy hh:mm:ss.SS') - 85, 39 | 3000, null, 20 40 | ); 41 | insert into emp 42 | values( 43 | 7902, 'FORD', 'ANALYST', 7566, 44 | parsedatetime('3-12-1981 00:00:00.00', 'dd-MM-yyyy hh:mm:ss.SS'), 45 | 3000, null, 20 46 | ); 47 | insert into emp 48 | values( 49 | 7369, 'SMITH', 'CLERK', 7902, 50 | parsedatetime('17-12-1980 00:00:00.00', 'dd-MM-yyyy hh:mm:ss.SS'), 51 | 800, null, 20 52 | ); 53 | insert into emp 54 | values( 55 | 7499, 'ALLEN', 'SALESMAN', 7698, 56 | parsedatetime('20-2-1981 00:00:00.00', 'dd-MM-yyyy hh:mm:ss.SS'), 57 | 1600, 300, 30 58 | ); 59 | insert into emp 60 | values( 61 | 7521, 'WARD', 'SALESMAN', 7698, 62 | parsedatetime('22-2-1981 00:00:00.00', 'dd-MM-yyyy hh:mm:ss.SS'), 63 | 1250, 500, 30 64 | ); 65 | insert into emp 66 | values( 67 | 7654, 'MARTIN', 'SALESMAN', 7698, 68 | parsedatetime('28-9-1981 00:00:00.00', 'dd-MM-yyyy hh:mm:ss.SS'), 69 | 1250, 1400, 30 70 | ); 71 | insert into emp 72 | values( 73 | 7844, 'TURNER', 'SALESMAN', 7698, 74 | parsedatetime('8-9-1981 00:00:00.00', 'dd-MM-yyyy hh:mm:ss.SS'), 75 | 1500, 0, 30 76 | ); 77 | insert into emp 78 | values( 79 | 7876, 'ADAMS', 'CLERK', 7788, 80 | parsedatetime('13-7-1987 00:00:00.00', 'dd-MM-yyyy hh:mm:ss.SS') - 51, 81 | 1100, null, 20 82 | ); 83 | insert into emp 84 | values( 85 | 7900, 'JAMES', 'CLERK', 7698, 86 | parsedatetime('3-12-1981 00:00:00.00', 'dd-MM-yyyy hh:mm:ss.SS'), 87 | 950, null, 30 88 | ); 89 | insert into emp 90 | values( 91 | 7934, 'MILLER', 'CLERK', 7782, 92 | parsedatetime('23-1-1982 00:00:00.00', 'dd-MM-yyyy hh:mm:ss.SS'), 93 | 1300, null, 10 94 | ); -------------------------------------------------------------------------------- /chapters/chapter-persistence/sqlqueries/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/textquery/README.md: -------------------------------------------------------------------------------- 1 | *Ignite Java8 TextQuery TextFields* 2 | 3 | Build module with maven 4 | mvn clean install 5 | 6 | To run this standalone application execute following command in current directory folder: 7 | java -jar ./target/textquery-runnable.jar 8 | 9 | 10 | ***Description*** 11 | 12 | An example of searching objects in Ignite cache by text on the fields which were annotated as @QueryTextField 13 | 14 | The resource file @USA_NY_email_addresses.csv has been taken from open resource in the internet 15 | http://emailaddresseslists.com/downloads-email/download-usa-new-york-ny-email-database-mailing-list-addresses-ids-part-047-of-100-909152707/ 16 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/textquery/src/main/resources/example-ignite.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 24 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 127.0.0.1:47500 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/textquery/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/transactions/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chapters/chapter-persistence/transactions/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /highperfomance-mini.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/srecon/ignite-book-code-samples/34eb1453a2a39b96e3bcbdafb5fa89f96018e775/highperfomance-mini.jpg --------------------------------------------------------------------------------