More working, mid Infinispan/EhCache change.
This commit is contained in:
parent
0446fdeb30
commit
5e5c53af8a
23 changed files with 1067 additions and 425 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
.idea
|
||||
target
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
|
19
README
Normal file
19
README
Normal file
|
@ -0,0 +1,19 @@
|
|||
docker run --name mongodb -p 27017:27017 -d mongo --storageEngine wiredTiger
|
||||
docker run --name castrato -p 9042:9042 -p 9162:9162 -p 7000:7000 -e CASSANDRA_START_RPC=true -d stratio/cassandra-lucene-index:3.10.0
|
||||
|
||||
drop table books; drop table products; drop table inventory; drop table magazines; desc tables;
|
||||
|
||||
mvn clean compile -Dmaven.compiler.showDeprecation=true -Dmaven.compiler.showWarnings=true
|
||||
|
||||
https://www.one-tab.com/page/K4XlsjF2TyugqYE_8ORqxg
|
||||
|
||||
|
||||
|
||||
|
||||
https://apple.stackexchange.com/questions/215919/enable-multicast-on-mac
|
||||
ifconfig -a
|
||||
sudo route -nv add -net 239.9.9.9 -interface en0
|
||||
netstat -nr | grep 239.9.9.9
|
||||
ping -t 1 -c 2 239.9.9.9
|
||||
sudo tcpdump -vvv -ni en0 host 239.9.9.9
|
||||
sudo route -v delete -inet 239.9.9.9
|
154
build.xml
154
build.xml
|
@ -1,154 +0,0 @@
|
|||
<!--
|
||||
===================================================================
|
||||
build
|
||||
===================================================================
|
||||
-->
|
||||
<project name="crud" default="compile">
|
||||
|
||||
<!-- environment -->
|
||||
<property environment="env"/>
|
||||
<property name="project.location" location="."/>
|
||||
<property name="project.build.debug" value="on"/>
|
||||
<property name="Name" value="crud"/>
|
||||
<property name="name" value="${Name}"/>
|
||||
<property name="version" value="4.0"/>
|
||||
|
||||
<!-- project workspace directories -->
|
||||
<property name="java.dir" value="src/main/java"/>
|
||||
<property name="resources.dir" value="src/main/resources"/>
|
||||
<property name="lib.dir" value="lib"/>
|
||||
<property name="classes.dir" value="target/classes"/>
|
||||
|
||||
<!--
|
||||
===================================================================
|
||||
Classpath properties
|
||||
===================================================================
|
||||
-->
|
||||
|
||||
<!-- the classpath for running -->
|
||||
<path id="run.classpath">
|
||||
<fileset dir="${lib.dir}">
|
||||
<include name="**/*.jar"/>
|
||||
</fileset>
|
||||
<pathelement location="${classes.dir}"/>
|
||||
<pathelement location="${basedir}"/>
|
||||
</path>
|
||||
|
||||
<!-- the classpath for the compile -->
|
||||
<path id="compile.classpath">
|
||||
<pathelement location="${classes.dir}"/>
|
||||
<fileset dir="${lib.dir}">
|
||||
<include name="**/*.jar"/>
|
||||
</fileset>
|
||||
<pathelement location="${classes.dir}"/>
|
||||
<pathelement location="${basedir}"/>
|
||||
</path>
|
||||
|
||||
<!--
|
||||
===================================================================
|
||||
TARGET : clean
|
||||
===================================================================
|
||||
-->
|
||||
<target name="clean">
|
||||
<delete includeEmptyDirs="true" quiet="true">
|
||||
<fileset dir="${basedir}/target"/>
|
||||
</delete>
|
||||
</target>
|
||||
|
||||
<!--
|
||||
===================================================================
|
||||
TARGET : prepare
|
||||
===================================================================
|
||||
-->
|
||||
<target name="prepare">
|
||||
<mkdir dir="${classes.dir}"/>
|
||||
</target>
|
||||
|
||||
<!--
|
||||
===================================================================
|
||||
TARGET : compile.java
|
||||
===================================================================
|
||||
-->
|
||||
<target name="compile" depends="clean,prepare">
|
||||
<echo message="==================================================================="/>
|
||||
<echo message="Compile configuration:"/>
|
||||
<echo message="java.dir = ${java.dir}"/>
|
||||
<echo message="classes.dir = ${classes.dir}"/>
|
||||
<echo message="==================================================================="/>
|
||||
<javac srcdir="${java.dir}" destdir="${classes.dir}" debug="${project.build.debug}" classpathref="compile.classpath">
|
||||
<include name="**/*.java"/>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<!--
|
||||
===================================================================
|
||||
TARGET : copy metadata files
|
||||
===================================================================
|
||||
-->
|
||||
<target name="copy.metadata">
|
||||
<copy todir="${classes.dir}">
|
||||
<fileset dir="${resources.dir}" includes="**/*.xml"/>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<!--
|
||||
===================================================================
|
||||
TARGET : enhance
|
||||
===================================================================
|
||||
-->
|
||||
<target name="enhance" depends="compile,copy.metadata">
|
||||
|
||||
<!-- define the task enhancer -->
|
||||
<taskdef name="enhancer" classname="org.datanucleus.enhancer.EnhancerTask">
|
||||
<classpath refid="run.classpath"/>
|
||||
</taskdef>
|
||||
|
||||
<!-- enhance -->
|
||||
<enhancer classpathref="run.classpath" dir="${classes.dir}" verbose="true" api="JPA" persistenceUnit="crud">
|
||||
<sysproperty key="log4j.configuration" value="file:log4j.xml"/>
|
||||
</enhancer>
|
||||
</target>
|
||||
|
||||
<!-- SchemaTool "create" -->
|
||||
<target name="createschema">
|
||||
<taskdef name="schematool" classname="org.datanucleus.store.schema.SchemaToolTask">
|
||||
<classpath refid="run.classpath"/>
|
||||
</taskdef>
|
||||
|
||||
<schematool classpathref="run.classpath" failonerror="true" verbose="true"
|
||||
mode="create" api="JPA" persistenceUnit="crud">
|
||||
<sysproperty key="log4j.configuration" value="file:${basedir}/log4j.xml"/>
|
||||
</schematool>
|
||||
</target>
|
||||
|
||||
<!-- SchemaTool "delete" -->
|
||||
<target name="deleteschema">
|
||||
<taskdef name="schematool" classname="org.datanucleus.store.schema.SchemaToolTask">
|
||||
<classpath refid="run.classpath"/>
|
||||
</taskdef>
|
||||
|
||||
<schematool classpathref="run.classpath" failonerror="true" fork="true" verbose="true"
|
||||
mode="delete" api="JPA" persistenceUnit="crud">
|
||||
<sysproperty key="log4j.configuration" value="file:${basedir}/log4j.xml"/>
|
||||
</schematool>
|
||||
</target>
|
||||
|
||||
<!-- SchemaTool "dbinfo" -->
|
||||
<target name="schemainfo">
|
||||
<taskdef name="schematool" classname="org.datanucleus.store.schema.SchemaToolTask">
|
||||
<classpath refid="run.classpath"/>
|
||||
</taskdef>
|
||||
|
||||
<schematool classpathref="run.classpath" failonerror="true" fork="true" verbose="true"
|
||||
mode="dbinfo" api="JPA" persistenceUnit="crud">
|
||||
<sysproperty key="log4j.configuration" value="file:${basedir}/log4j.xml"/>
|
||||
</schematool>
|
||||
</target>
|
||||
|
||||
<!-- Run the application -->
|
||||
<target name="run" description="Run the application">
|
||||
<copy file="log4j.properties"
|
||||
tofile="${classes.dir}/log4j.properties"/>
|
||||
<java classname="com.example.crud.Main" classpathref="run.classpath" fork="true"/>
|
||||
</target>
|
||||
</project>
|
55
crud.iml
55
crud.iml
|
@ -15,6 +15,15 @@
|
|||
<facet type="Spring" name="Spring">
|
||||
<configuration />
|
||||
</facet>
|
||||
<facet type="AspectJ" name="AspectJ">
|
||||
<configuration>
|
||||
<option name="aspectPath">
|
||||
<projectLibrary>
|
||||
<option name="name" value="Maven: io.astefanutti.metrics.aspectj:metrics-aspectj:1.2.0" />
|
||||
</projectLibrary>
|
||||
</option>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
|
@ -34,6 +43,7 @@
|
|||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.0.13" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-access:1.2.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:jcl-over-slf4j:1.7.25" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:log4j-over-slf4j:1.7.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.datanucleus:datanucleus-mongodb:5.1.0-m3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:3.4.2" level="project" />
|
||||
|
@ -57,20 +67,45 @@
|
|||
<orderEntry type="library" name="Maven: com.github.jnr:jnr-x86asm:1.0.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.jnr:jnr-posix:3.0.27" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.jnr:jnr-constants:0.9.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.datanucleus:datanucleus-cache:5.0.0-release" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.infinispan:infinispan-embedded:9.0.2.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:1.0.1.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.infinispan:infinispan-jcache:9.0.2.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.infinispan:infinispan-core:9.0.2.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.infinispan:infinispan-commons:9.0.2.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jgroups:jgroups:4.0.3.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.ben-manes.caffeine:caffeine:2.4.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jboss.marshalling:jboss-marshalling-osgi:2.0.0.Beta3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.3.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.infinispan:infinispan-jcache-commons:9.0.2.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.cache:cache-api:1.0.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.ehcache:ehcache:3.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.0.0.M5" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.0.0.M5" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.0.0.M5" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.0.0.M5" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.0.0.M5" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-jpa:2.0.0.M4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-commons:2.0.0.M4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-orm:5.0.0.RC2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-jdbc:5.0.0.RC2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.0.0.RC2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.0.0.RC2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.0.0.RC2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-tx:5.0.0.RC2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.0.0.RC2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.0.0.RC2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.0.0.RC2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.aspectj:aspectjrt:1.8.10" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-keyvalue:2.0.0.M4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-orm:5.0.0.M5" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-jdbc:5.0.0.M5" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-tx:5.0.0.M5" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.security:spring-security-web:5.0.0.M2" level="project" />
|
||||
<orderEntry type="library" name="Maven: aopalliance:aopalliance:1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.security:spring-security-core:5.0.0.M2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-web:5.0.0.M5" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-aspects:5.0.0.M5" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.aspectj:aspectjweaver:1.9.0.BETA-5" level="project" />
|
||||
<orderEntry type="library" name="Maven: joda-time:joda-time:2.9.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.projectlombok:lombok:1.16.16" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.astefanutti.metrics.aspectj:metrics-aspectj:1.2.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.dropwizard.metrics:metrics-annotation:3.2.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.glassfish.web:javax.el:2.2.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.el:javax.el-api:2.2.5" level="project" />
|
||||
</component>
|
||||
</module>
|
334
pom.xml
334
pom.xml
|
@ -11,8 +11,13 @@
|
|||
|
||||
<properties>
|
||||
<encoding>UTF-8</encoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<java.version>1.8</java.version>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<org.datanucleus.version>[5.1.0-m3, 5.9)</org.datanucleus.version>
|
||||
<aspectj.version>1.8.10</aspectj.version>
|
||||
<spring.version>5.0.0.M5</spring.version>
|
||||
<spring-data.version>Kay-M4</spring-data.version>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
|
@ -26,22 +31,46 @@
|
|||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-releasetrain</artifactId>
|
||||
<version>${spring-data.version}</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.datanucleus</groupId>
|
||||
<artifactId>datanucleus-core</artifactId>
|
||||
<version>[5.0.0-m1, 5.9)</version>
|
||||
<version>${org.datanucleus.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.datanucleus</groupId>
|
||||
<artifactId>datanucleus-api-jpa</artifactId>
|
||||
<version>[5.0.0-m1, 5.9)</version>
|
||||
<version>${org.datanucleus.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.datanucleus</groupId>
|
||||
<artifactId>javax.persistence</artifactId>
|
||||
<version>2.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
|
@ -52,82 +81,22 @@
|
|||
<artifactId>logback-access</artifactId>
|
||||
<version>1.2.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>1.7.25</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
<version>1.7.7</version>
|
||||
</dependency>
|
||||
|
||||
<!-- ENABLE THIS FOR H2 -->
|
||||
<!-- <dependency>
|
||||
<groupId>org.datanucleus</groupId>
|
||||
<artifactId>datanucleus-rdbms</artifactId>
|
||||
<version>[5.0.0-m1, 5.9)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>1.3.168</version>
|
||||
</dependency> -->
|
||||
|
||||
<!-- ENABLE THIS FOR HSQLDB -->
|
||||
<!--dependency>
|
||||
<groupId>org.datanucleus</groupId>
|
||||
<artifactId>datanucleus-rdbms</artifactId>
|
||||
<version>[5.0.0-m1, 5.9)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>hsqldb</groupId>
|
||||
<artifactId>hsqldb</artifactId>
|
||||
<version>2.3.3</version>
|
||||
</dependency-->
|
||||
|
||||
<!-- ENABLE THIS FOR MYSQL -->
|
||||
<!--dependency>
|
||||
<groupId>org.datanucleus</groupId>
|
||||
<artifactId>datanucleus-rdbms</artifactId>
|
||||
<version>[5.0.0-m1, 5.9)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.17</version>
|
||||
</dependency-->
|
||||
|
||||
<!-- ENABLE THIS FOR ODF -->
|
||||
<!--dependency>
|
||||
<groupId>org.datanucleus</groupId>
|
||||
<artifactId>datanucleus-odf</artifactId>
|
||||
<version>[5.0.0-m1, 5.9)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.odftoolkit</groupId>
|
||||
<artifactId>odfdom-java</artifactId>
|
||||
<version>0.8.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xerces</groupId>
|
||||
<artifactId>xercesImpl</artifactId>
|
||||
<version>[2.8, 3.0)</version>
|
||||
</dependency-->
|
||||
|
||||
<!-- ENABLE THIS FOR EXCEL -->
|
||||
<!--dependency>
|
||||
<groupId>org.datanucleus</groupId>
|
||||
<artifactId>datanucleus-excel</artifactId>
|
||||
<version>[5.0.0-m1, 5.9)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi</artifactId>
|
||||
<version>3.6</version>
|
||||
</dependency-->
|
||||
|
||||
<!-- ENABLE THIS FOR MongoDB -->
|
||||
<!-- MongoDB -->
|
||||
<dependency>
|
||||
<groupId>org.datanucleus</groupId>
|
||||
<artifactId>datanucleus-mongodb</artifactId>
|
||||
<version>[5.0.0-m1, 5.9)</version>
|
||||
<version>${org.datanucleus.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mongodb</groupId>
|
||||
|
@ -135,63 +104,37 @@
|
|||
<version>3.4.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- ENABLE THIS FOR HBase -->
|
||||
<!--dependency>
|
||||
<groupId>org.datanucleus</groupId>
|
||||
<artifactId>datanucleus-hbase</artifactId>
|
||||
<version>[5.0.0-m1, 5.9)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.hbase</groupId>
|
||||
<artifactId>hbase-client</artifactId>
|
||||
<version>1.1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>1.1</version>
|
||||
</dependency-->
|
||||
|
||||
<!-- ENABLE THIS FOR Neo4j -->
|
||||
<!--dependency>
|
||||
<groupId>org.datanucleus</groupId>
|
||||
<artifactId>datanucleus-neo4j</artifactId>
|
||||
<version>[5.0.0-m1, 5.9)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.neo4j</groupId>
|
||||
<artifactId>neo4j</artifactId>
|
||||
<version>2.3.0</version>
|
||||
</dependency-->
|
||||
|
||||
<!-- ENABLE THIS FOR Cassandra -->
|
||||
<!-- Cassandra -->
|
||||
<dependency>
|
||||
<groupId>org.datanucleus</groupId>
|
||||
<artifactId>datanucleus-cassandra</artifactId>
|
||||
<version>[5.0.0-m1, 5.9)</version>
|
||||
<version>${org.datanucleus.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.datastax.cassandra</groupId>
|
||||
<artifactId>cassandra-driver-core</artifactId>
|
||||
<version>3.0.2</version>
|
||||
<version>3.2.0</version>
|
||||
</dependency>
|
||||
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>org.datanucleus</groupId>
|
||||
<artifactId>datanucleus-cache</artifactId>
|
||||
<version>5.0.0-release</version>
|
||||
</dependency>
|
||||
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>org.datanucleus</groupId>
|
||||
<artifactId>datanucleus-guava</artifactId>
|
||||
<version>5.0.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.datanucleus</groupId>
|
||||
<artifactId>datanucleus-jodatime</artifactId>
|
||||
<version>5.0.0-release</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.datanucleus</groupId>
|
||||
<artifactId>datanucleus-java8</artifactId>
|
||||
|
@ -199,19 +142,115 @@
|
|||
</dependency>
|
||||
-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.infinispan</groupId>
|
||||
<artifactId>infinispan-embedded</artifactId>
|
||||
<version>9.0.2.Final</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.jboss.slf4j</groupId>
|
||||
<artifactId>slf4j-jboss-logging</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.infinispan</groupId>
|
||||
<artifactId>infinispan-jcache</artifactId>
|
||||
<version>9.0.2.Final</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.cache</groupId>
|
||||
<artifactId>cache-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.ehcache</groupId>
|
||||
<artifactId>ehcache</artifactId>
|
||||
<version>3.3.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- dependency>
|
||||
<groupId>org.infinispan</groupId>
|
||||
<artifactId>infinispan-spring4-embedded</artifactId>
|
||||
<version>9.0.2.Final</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.jboss.slf4j</groupId>
|
||||
<artifactId>slf4j-jboss-logging</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency -->
|
||||
|
||||
<!-- depending on a use case, one should use Spring Context or Spring Boot jars -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-jpa</artifactId>
|
||||
<version>2.0.0.M4</version>
|
||||
<!-- version>${org.spring.release-train}</version -->
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-keyvalue</artifactId>
|
||||
<!-- version>${org.spring.release-train}</version -->
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-orm</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-web</artifactId>
|
||||
<version>5.0.0.M2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-aspects</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- ... -->
|
||||
|
||||
<dependency>
|
||||
<groupId>com.datastax.cassandra</groupId>
|
||||
<artifactId>cassandra-driver-core</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>2.9.9</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
|
@ -224,6 +263,19 @@
|
|||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.astefanutti.metrics.aspectj</groupId>
|
||||
<artifactId>metrics-aspectj</artifactId>
|
||||
<version>1.2.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.glassfish.web</groupId>
|
||||
<artifactId>javax.el</artifactId>
|
||||
<version>2.2.6</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -237,10 +289,6 @@
|
|||
<directory>${basedir}</directory>
|
||||
<includes>
|
||||
<include>*.log</include>
|
||||
<include>tutorial.xls</include>
|
||||
<include>tutorial.ods</include>
|
||||
<include>tutorial.ooxml</include>
|
||||
<include>tutorial.xml</include>
|
||||
</includes>
|
||||
</fileset>
|
||||
<fileset>
|
||||
|
@ -253,6 +301,65 @@
|
|||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.5.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>aspectj-maven-plugin</artifactId>
|
||||
<version>1.10</version>
|
||||
<configuration>
|
||||
<aspectLibraries>
|
||||
<aspectLibrary>
|
||||
<groupId>io.astefanutti.metrics.aspectj</groupId>
|
||||
<artifactId>metrics-aspectj</artifactId>
|
||||
</aspectLibrary>
|
||||
</aspectLibraries>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>process-classes</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<showWeaveInfo/>
|
||||
<forceAjcCompile>true</forceAjcCompile>
|
||||
<sources/>
|
||||
<weaveDirectories>
|
||||
<weaveDirectory>${project.build.directory}/classes</weaveDirectory>
|
||||
</weaveDirectories>
|
||||
<complianceLevel>${java.version}</complianceLevel>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
<Xlint>ignore</Xlint>
|
||||
<!--
|
||||
<aspectLibraries>
|
||||
<aspectLibrary>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjrt</artifactId>
|
||||
</aspectLibrary>
|
||||
<aspectLibrary>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-aspects</artifactId>
|
||||
</aspectLibrary>
|
||||
</aspectLibraries>
|
||||
-->
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjrt</artifactId>
|
||||
<version>${aspectj.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjtools</artifactId>
|
||||
<version>${aspectj.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
<!-- DataNucleus compile time weaving
|
||||
<plugin>
|
||||
<groupId>org.datanucleus</groupId>
|
||||
<artifactId>datanucleus-maven-plugin</artifactId>
|
||||
|
@ -272,7 +379,8 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
-->
|
||||
<!-- -->
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
|
|
|
@ -1,22 +1,52 @@
|
|||
package com.example.crud;
|
||||
|
||||
import com.example.crud.entities.AbstractAuditableEntity;
|
||||
import com.example.crud.entities.AbstractEntity;
|
||||
import com.example.crud.entities.Product;
|
||||
import org.datanucleus.enhancer.DataNucleusEnhancer;
|
||||
import org.infinispan.configuration.cache.CacheMode;
|
||||
import org.infinispan.configuration.cache.ConfigurationBuilder;
|
||||
import org.infinispan.configuration.global.GlobalConfigurationBuilder;
|
||||
import org.infinispan.manager.DefaultCacheManager;
|
||||
import org.infinispan.manager.EmbeddedCacheManager;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
import org.springframework.data.domain.AuditorAware;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.Persistence;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
@Configuration
|
||||
@EnableJpaRepositories
|
||||
@EnableJpaAuditing
|
||||
@EnableScheduling
|
||||
@EnableAspectJAutoProxy
|
||||
@EnableCaching
|
||||
@EnableTransactionManagement
|
||||
class ApplicationConfig {
|
||||
|
||||
@PostConstruct
|
||||
private void enhanceModelObjectBytecode() {
|
||||
DataNucleusEnhancer enhancer = new DataNucleusEnhancer("JPA", null);
|
||||
enhancer.setVerbose(true);
|
||||
enhancer.addClasses(AbstractEntity.class.getName());
|
||||
enhancer.addClasses(AbstractAuditableEntity.class.getName());
|
||||
enhancer.addClasses(Product.class.getName());
|
||||
enhancer.addPersistenceUnit("crud");
|
||||
enhancer.addPersistenceUnit("mongo");
|
||||
enhancer.enhance();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public EntityManagerFactory entityManagerFactory() {
|
||||
EntityManagerFactory emf = Persistence.createEntityManagerFactory("crud");
|
||||
|
@ -29,4 +59,44 @@ class ApplicationConfig {
|
|||
txManager.setEntityManagerFactory(entityManagerFactory());
|
||||
return txManager;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public EmbeddedCacheManager cacheManager() {
|
||||
return infinispanEmbeddedDistributedCacheManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AuditorAware<String> auditorAware() {
|
||||
return new UsernameAuditorAware();
|
||||
}
|
||||
|
||||
private EmbeddedCacheManager infinispanEmbeddedDistributedCacheManager() {
|
||||
String nodeName = null;
|
||||
try {
|
||||
nodeName = java.net.InetAddress.getLocalHost().getHostName();
|
||||
} catch (UnknownHostException e) {
|
||||
nodeName = "localhost";
|
||||
}
|
||||
// ConfigurationBuilder cb = new ConfigurationBuilder(); cb.addCluster("HighQCacheCluster").addClusterNode("jboss1ind1", 11222).addClusterNode("udit.local.com", 11222); RemoteCacheManager rmc = new RemoteCacheManager(cb.build());
|
||||
|
||||
DefaultCacheManager cacheManager = new DefaultCacheManager(
|
||||
GlobalConfigurationBuilder.defaultClusteredBuilder()
|
||||
.transport().nodeName(nodeName).addProperty("configurationFile",
|
||||
"jgroups-l2-cache-udp-largecluster.xml")
|
||||
.build(),
|
||||
new ConfigurationBuilder()
|
||||
.clustering()
|
||||
.cacheMode(CacheMode.INVALIDATION_SYNC)
|
||||
.build()
|
||||
);
|
||||
// The only way to get the "repl" cache to be exactly the same as the default cache is to not define it at all
|
||||
cacheManager.defineConfiguration("dist", new ConfigurationBuilder()
|
||||
.clustering()
|
||||
.cacheMode(CacheMode.DIST_SYNC)
|
||||
.hash().numOwners(2)
|
||||
.build()
|
||||
);
|
||||
return cacheManager;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
52
src/main/java/com/example/crud/CacheClusterListener.java
Normal file
52
src/main/java/com/example/crud/CacheClusterListener.java
Normal file
|
@ -0,0 +1,52 @@
|
|||
package com.example.crud;
|
||||
|
||||
import org.infinispan.notifications.Listener;
|
||||
import org.infinispan.notifications.cachelistener.annotation.CacheEntryCreated;
|
||||
import org.infinispan.notifications.cachelistener.annotation.CacheEntryModified;
|
||||
import org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved;
|
||||
import org.infinispan.notifications.cachelistener.annotation.TopologyChanged;
|
||||
import org.infinispan.notifications.cachelistener.event.CacheEntryCreatedEvent;
|
||||
import org.infinispan.notifications.cachelistener.event.CacheEntryModifiedEvent;
|
||||
import org.infinispan.notifications.cachelistener.event.CacheEntryRemovedEvent;
|
||||
import org.infinispan.notifications.cachelistener.event.TopologyChangedEvent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
@Listener(clustered = true)
|
||||
public class CacheClusterListener {
|
||||
private Logger log = LoggerFactory.getLogger(getClass().getName());
|
||||
|
||||
@CacheEntryCreated
|
||||
public void observeAdd(CacheEntryCreatedEvent<String, String> event) {
|
||||
if (event.isPre())
|
||||
return;
|
||||
|
||||
log.info("Cache entry %s added in cache %s", event.getKey(), event.getCache());
|
||||
}
|
||||
|
||||
@CacheEntryModified
|
||||
public void observeUpdate(CacheEntryModifiedEvent<String, String> event) {
|
||||
if (event.isPre())
|
||||
return;
|
||||
|
||||
log.info("Cache entry %s = %s modified in cache %s", event.getKey(), event.getValue(), event.getCache());
|
||||
}
|
||||
|
||||
@CacheEntryRemoved
|
||||
public void observeRemove(CacheEntryRemovedEvent<String, String> event) {
|
||||
if (event.isPre())
|
||||
return;
|
||||
|
||||
log.info("Cache entry %s removed in cache %s", event.getKey(), event.getCache());
|
||||
}
|
||||
|
||||
@TopologyChanged
|
||||
public void observeTopologyChange(TopologyChangedEvent<String, String> event) {
|
||||
if (event.isPre())
|
||||
return;
|
||||
|
||||
log.info("Cache %s topology changed, new membership is %s", event.getCache().getName(), event.getConsistentHashAtEnd().getMembers());
|
||||
}
|
||||
|
||||
}
|
236
src/main/java/com/example/crud/JGroups.java
Normal file
236
src/main/java/com/example/crud/JGroups.java
Normal file
|
@ -0,0 +1,236 @@
|
|||
package com.example.crud;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.regex.Pattern;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.jgroups.*;
|
||||
import org.jgroups.blocks.locking.LockService;
|
||||
|
||||
public class JGroups {
|
||||
private Logger log = LoggerFactory.getLogger(getClass().getName());
|
||||
/* this variable indicates whether I have become the master or I'm just a client*/
|
||||
public volatile AtomicBoolean becomeMaster = new AtomicBoolean(false);
|
||||
/* The address of the server if we are a client or of ourself if we are
|
||||
* server */
|
||||
public String serverAddress;
|
||||
/* A channel on which to acquire a lock, so that only one can become server */
|
||||
private JChannel lockChannel;
|
||||
/* A shared channel ffor communication between client and master*/
|
||||
private JChannel communicationChannel;
|
||||
private LockService lockService;
|
||||
/* A thread which tries to acquire a lock */
|
||||
private Thread acquiringThread;
|
||||
/* A thread which listens for the server ip which may change */
|
||||
private Thread listeningThread;
|
||||
/* A thread which lists the status and initializes the acquiring thread*/
|
||||
private Thread statusThread;
|
||||
private String name;
|
||||
/* If we pass from being a client to being a server we must stop the listening
|
||||
* thread however we cannot call listeningThread.stop() but instead we change
|
||||
* the stopListening boolean to true */
|
||||
private boolean stopListening = false;
|
||||
/* This lock communicates I have finally become either master or client so
|
||||
* the serverAddress and becomeMaster variables are correctly set */
|
||||
public final Object finishedLock = new Object();
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
//System.setProperty("jgroups.udp.mcast_addr", "127.0.0.1");
|
||||
Thread.currentThread().setName("MyMainThread");
|
||||
Random rand = new Random();
|
||||
|
||||
JGroups master = new JGroups("Node" + rand.nextInt(10));
|
||||
|
||||
master.lockChannel = new JChannel(JGroups.class.getClassLoader().getResource(
|
||||
"jgroups-l2-cache-udp-largecluster.xml"));
|
||||
master.lockChannel.connect("lock-channel");
|
||||
|
||||
master.communicationChannel = new JChannel(
|
||||
JGroups.class.getClassLoader().getResource("jgroups-l2-cache-udp-largecluster.xml"));
|
||||
master.communicationChannel.connect("communication-channel");
|
||||
|
||||
master.lockService = new LockService(master.lockChannel);
|
||||
master.startStatusPrinterThread();
|
||||
}
|
||||
|
||||
public JGroups(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public JGroups() {
|
||||
try {
|
||||
Thread.currentThread().setName("MyMainThread");
|
||||
Random rand = new Random();
|
||||
|
||||
this.name = ("Node" + rand.nextInt(10));
|
||||
|
||||
lockChannel = new JChannel(JGroups.class.getClassLoader().getResource("/resource/udp.xml"));
|
||||
lockChannel.connect("lock-channel");
|
||||
|
||||
communicationChannel = new JChannel(JGroups.class.getClassLoader().getResource("/resource/udp.xml"));
|
||||
communicationChannel.connect("communication-channel");
|
||||
|
||||
lockService = new LockService(lockChannel);
|
||||
startStatusPrinterThread();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
log.error(ex.getStackTrace().toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void startAcquiringThread() {
|
||||
acquiringThread = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
//if you have become Master send your ip every now and then
|
||||
if (becomeMaster.get()) {
|
||||
try {
|
||||
StringBuffer buffer = new StringBuffer("serverip " + serverAddress);
|
||||
communicationChannel.send(new Message(null, buffer));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
log.error(ex.getStackTrace().toString());
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Thread.currentThread().setName(name + "AcquiringThread");
|
||||
Lock lock = lockService.getLock("serverLock");
|
||||
if (lock.tryLock(4, TimeUnit.SECONDS)) {
|
||||
becomeMaster.set(true);
|
||||
stopListening = true;
|
||||
/* Now that I'm server I must find out my own ip address on which to listen */
|
||||
Enumeration<NetworkInterface> networkInterfaces;
|
||||
try {
|
||||
networkInterfaces = NetworkInterface.getNetworkInterfaces();
|
||||
for (NetworkInterface netint : Collections.list(networkInterfaces)) {
|
||||
Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
|
||||
for (InetAddress inetAddress : Collections.list(inetAddresses)) {
|
||||
if (isIPAddress(inetAddress.getHostAddress())
|
||||
&& !inetAddress.getHostAddress().equals("127.0.0.1")) {
|
||||
serverAddress = inetAddress.getHostAddress();
|
||||
}
|
||||
}
|
||||
}
|
||||
/* I notify to the rest of the program I have correctly initialized
|
||||
* becomeMaster and serverAddress */
|
||||
synchronized (finishedLock) {
|
||||
finishedLock.notify();
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
log.error(ex.getStackTrace().toString());
|
||||
System.exit(0);
|
||||
}
|
||||
log.info(Thread.currentThread().getName()
|
||||
+ ": I acquired lock! will become master! my ip is " + serverAddress);
|
||||
} else {
|
||||
becomeMaster.set(false);
|
||||
stopListening = false;
|
||||
if (listeningThread == null || !listeningThread.isAlive()) {
|
||||
if (!stopListening) {
|
||||
//??? this codnition might be useless
|
||||
startListeningThread();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
try {
|
||||
sleep(5000L);
|
||||
}
|
||||
catch (InterruptedException ex) {
|
||||
log.error(ex.getStackTrace().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
acquiringThread.setDaemon(true);
|
||||
acquiringThread.start();
|
||||
}
|
||||
|
||||
public void startListeningThread() {
|
||||
listeningThread = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
while (true) {
|
||||
Thread.currentThread().setName(name + "ListeningThread");
|
||||
communicationChannel.setReceiver(new ReceiverAdapter() {
|
||||
@Override
|
||||
public void receive(Message msg) {
|
||||
if (msg.getObject() != null) {
|
||||
String leaderServerAddress = (msg.getObject().toString().substring(9));
|
||||
if (isIPAddress(leaderServerAddress)) {
|
||||
serverAddress = leaderServerAddress;
|
||||
log.info(name + " Master server has ip" + serverAddress);
|
||||
/* I notify to the rest of the program I have correctly initialized
|
||||
* becomeMaster and serverAddress */
|
||||
synchronized (finishedLock) {
|
||||
finishedLock.notify();
|
||||
}
|
||||
} else {
|
||||
log.info(name + ": discarded message " + msg.getObject().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
sleep(10000L);
|
||||
if (stopListening) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
listeningThread.setDaemon(true);
|
||||
listeningThread.start();
|
||||
}
|
||||
|
||||
private void startStatusPrinterThread() {
|
||||
statusThread = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName(name + "StatusPrinterThread");
|
||||
startAcquiringThread();
|
||||
while (true) {
|
||||
try {
|
||||
if (becomeMaster.get()) {
|
||||
log.info(name + " startStatusPrinterThread(): I am happily a Master!");
|
||||
} else {
|
||||
if (!acquiringThread.isAlive()) {
|
||||
startAcquiringThread();
|
||||
}
|
||||
}
|
||||
sleep(5000L);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
statusThread.setDaemon(true);
|
||||
statusThread.start();
|
||||
}
|
||||
|
||||
private static boolean isIPAddress(String str) {
|
||||
Pattern ipPattern = Pattern.compile("^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
|
||||
+ "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
|
||||
+ "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
|
||||
+ "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");
|
||||
return ipPattern.matcher(str).matches();
|
||||
}
|
||||
}
|
|
@ -1,40 +1,62 @@
|
|||
package com.example.crud;
|
||||
|
||||
import com.example.crud.entities.*;
|
||||
import com.example.crud.repositories.InventoryRepository;
|
||||
import org.datanucleus.util.NucleusLogger;
|
||||
import org.infinispan.Cache;
|
||||
import org.infinispan.configuration.cache.ConfigurationBuilder;
|
||||
import org.infinispan.manager.DefaultCacheManager;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.EntityTransaction;
|
||||
import javax.persistence.EntityGraph;
|
||||
import javax.persistence.Persistence;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import com.example.crud.entities.*;
|
||||
|
||||
import com.example.crud.repositories.InventoryRepository;
|
||||
import org.datanucleus.enhancer.DataNucleusEnhancer;
|
||||
import org.datanucleus.util.NucleusLogger;
|
||||
import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
|
||||
|
||||
/**
|
||||
* Controlling application for the DataNucleus Tutorial using JPA.
|
||||
* Uses the "persistence-unit" called "Tutorial".
|
||||
*/
|
||||
public class Main {
|
||||
|
||||
public static void cacheTest() {
|
||||
// Construct a simple local cache manager with default configuration
|
||||
DefaultCacheManager cacheManager = new DefaultCacheManager();
|
||||
// Define local cache configuration
|
||||
cacheManager.defineConfiguration("local", new ConfigurationBuilder().build());
|
||||
// Obtain the local cache
|
||||
Cache<String, String> cache = cacheManager.getCache("local");
|
||||
// Register a listener
|
||||
cache.addListener(new CacheClusterListener());
|
||||
// Store some values
|
||||
cache.put("key1", "value1");
|
||||
cache.put("key2", "value2");
|
||||
cache.put("key1", "newValue");
|
||||
// Stop the cache manager and release all resources
|
||||
cacheManager.stop();
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
DataNucleusEnhancer enhancer = new DataNucleusEnhancer("JPA", null);
|
||||
enhancer.setVerbose(true);
|
||||
enhancer.addPersistenceUnit("crud");
|
||||
enhancer.addPersistenceUnit("mongo");
|
||||
enhancer.enhance();
|
||||
//cacheTest();
|
||||
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(ApplicationConfig.class);
|
||||
ctx.refresh();
|
||||
|
||||
// Create an EntityManagerFactory for this "persistence-unit"
|
||||
// See the file "META-INF/persistence.xml"
|
||||
EntityManagerFactory emf = Persistence.createEntityManagerFactory("crud");
|
||||
EntityManagerFactory emf_mongo = Persistence.createEntityManagerFactory("mongo");
|
||||
//MergingPersistenceUnitmanager
|
||||
|
||||
// TODO:
|
||||
// * types: int, bool, etc.
|
||||
// * Set<>
|
||||
// * L2/Caching via Infinispan (embedded, clustered)
|
||||
// * MergingPersistenceUnitmanager
|
||||
// * Draft/(Fluent)Builder Immutable Entites
|
||||
|
||||
// Persistence of a Product and a Book.
|
||||
EntityManager em = emf.createEntityManager();
|
||||
|
@ -44,16 +66,18 @@ public class Main {
|
|||
|
||||
Inventory inv = em.merge(new Inventory("My Inventory"));
|
||||
Product product = new Product("Sony Discman", "A standard discman from Sony", 200.00);
|
||||
inv.getProducts().add(product);
|
||||
inv.addProduct(product);
|
||||
Book book = new Book("Lord of the Rings by Tolkien", "The classic story", 49.99, "JRR Tolkien",
|
||||
"12345678", "MyBooks Factory");
|
||||
Magazine magazine = new Magazine("Field and Stream", "A hunter's guide to the outdoors.", 3.29, "F&S, Inc.", "23984729347", "F&S, Inc.");
|
||||
inv.getProducts().add(book);
|
||||
inv.getProducts().add(magazine);
|
||||
inv.addProduct(book);
|
||||
inv.addProduct(magazine);
|
||||
em.persist(inv);
|
||||
|
||||
tx.commit();
|
||||
System.out.println("Product and Book have been persisted");
|
||||
// SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(inv);
|
||||
// SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(product);
|
||||
// System.out.println("Product and Book have been persisted, inventory: " + inv.getPrimaryKey().toString() + ", product: " + product.getPrimaryKey().toString());
|
||||
}
|
||||
catch (Exception e) {
|
||||
NucleusLogger.GENERAL.error(">> Exception persisting data", e);
|
||||
|
@ -168,6 +192,7 @@ public class Main {
|
|||
em.close();
|
||||
|
||||
// Clean out the database
|
||||
emf.getCache().evictAll();
|
||||
em = emf.createEntityManager();
|
||||
tx = em.getTransaction();
|
||||
try {
|
||||
|
@ -177,7 +202,7 @@ public class Main {
|
|||
inv = (Inventory) em.find(Inventory.class, "My Inventory");
|
||||
|
||||
System.out.println("Clearing out Inventory");
|
||||
inv.getProducts().clear();
|
||||
inv.clearProducts();
|
||||
em.flush();
|
||||
|
||||
System.out.println("Deleting Inventory");
|
||||
|
|
26
src/main/java/com/example/crud/UsernameAuditorAware.java
Normal file
26
src/main/java/com/example/crud/UsernameAuditorAware.java
Normal file
|
@ -0,0 +1,26 @@
|
|||
package com.example.crud;
|
||||
|
||||
import org.springframework.data.domain.AuditorAware;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class UsernameAuditorAware implements AuditorAware<String> {
|
||||
|
||||
@Override
|
||||
public Optional<String> getCurrentAuditor() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
|
||||
if (authentication == null || !authentication.isAuthenticated()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
User user = (User)authentication.getPrincipal();
|
||||
String username = null;
|
||||
if (user != null) {
|
||||
username = user.getUsername();
|
||||
}
|
||||
return (username == null) ? Optional.empty() : Optional.of(username);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.example.crud.entities;
|
||||
|
||||
import org.springframework.data.annotation.CreatedBy;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedBy;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@MappedSuperclass
|
||||
@EntityListeners({AuditingEntityListener.class})
|
||||
public abstract class AbstractAuditableEntity<ID extends Serializable> extends AbstractEntity<ID> {
|
||||
|
||||
@CreatedDate
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date createdDateTime;
|
||||
|
||||
@LastModifiedDate
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date lastModifiedDateTime;
|
||||
|
||||
@CreatedBy
|
||||
private String createdByUser;
|
||||
|
||||
@LastModifiedBy
|
||||
private String modifiedByUser;
|
||||
|
||||
}
|
26
src/main/java/com/example/crud/entities/AbstractEntity.java
Normal file
26
src/main/java/com/example/crud/entities/AbstractEntity.java
Normal file
|
@ -0,0 +1,26 @@
|
|||
package com.example.crud.entities;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@MappedSuperclass
|
||||
public abstract class AbstractEntity<ID extends Serializable> {
|
||||
|
||||
@Transient
|
||||
@Autowired
|
||||
EntityManagerFactory emf;
|
||||
|
||||
@Version
|
||||
protected long version;
|
||||
|
||||
public ID getPrimaryKey() {
|
||||
final PersistenceUnitUtil util = emf.getPersistenceUnitUtil();
|
||||
Object id = util.getIdentifier(this);
|
||||
return (ID)id;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,34 +1,45 @@
|
|||
package com.example.crud.entities;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* Definition of an Inventory of products.
|
||||
*/
|
||||
@Data @Entity
|
||||
@ToString
|
||||
@NamedEntityGraph(name="allProps",
|
||||
attributeNodes={@NamedAttributeNode("name"), @NamedAttributeNode("products")})
|
||||
public class Inventory
|
||||
{
|
||||
@NamedEntityGraph(name = "allProps",
|
||||
attributeNodes = { @NamedAttributeNode("name"), @NamedAttributeNode("products") })
|
||||
public class Inventory extends AbstractAuditableEntity<String> {
|
||||
|
||||
@Id
|
||||
private String name=null;
|
||||
|
||||
@OneToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH}, fetch=FetchType.EAGER)
|
||||
public Set<Product> products = new HashSet<Product>();
|
||||
@OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH }, fetch = FetchType.EAGER)
|
||||
private Set<Product> products = new HashSet<Product>();
|
||||
|
||||
@Version
|
||||
long version;
|
||||
public Inventory() {
|
||||
}
|
||||
|
||||
public Inventory() { }
|
||||
public Inventory(String name)
|
||||
{
|
||||
public Inventory(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void addProduct(Product product) {
|
||||
products.add(product);
|
||||
}
|
||||
|
||||
public Iterable<Product> getProducts() {
|
||||
return ImmutableSet.copyOf(products);
|
||||
}
|
||||
|
||||
public void clearProducts() {
|
||||
products.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,27 +7,30 @@ import lombok.ToString;
|
|||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Index;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* Definition of a Book. Extends basic Product class.
|
||||
**/
|
||||
@Data @Entity
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ToString
|
||||
@AllArgsConstructor
|
||||
public class Magazine extends Product
|
||||
{
|
||||
/** Author of the Book. */
|
||||
public class Magazine extends Product {
|
||||
/**
|
||||
* Author of the Book.
|
||||
*/
|
||||
@Basic
|
||||
private String author = null;
|
||||
|
||||
/** ISBN number of the book. */
|
||||
/**
|
||||
* ISBN number of the book.
|
||||
*/
|
||||
@Basic
|
||||
private String isbn = null;
|
||||
|
||||
/** Publisher of the Book. */
|
||||
/**
|
||||
* Publisher of the Book.
|
||||
*/
|
||||
@Basic
|
||||
private String publisher = null;
|
||||
|
||||
|
@ -40,6 +43,7 @@ public class Magazine extends Product
|
|||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param name name of product
|
||||
* @param description description of product
|
||||
* @param price Price
|
||||
|
@ -53,7 +57,7 @@ public class Magazine extends Product
|
|||
String author,
|
||||
String isbn,
|
||||
String publisher) {
|
||||
super(name,description,price);
|
||||
super(name, description, price);
|
||||
this.author = author;
|
||||
this.isbn = isbn;
|
||||
this.publisher = publisher;
|
||||
|
|
|
@ -8,66 +8,64 @@ import java.util.List;
|
|||
*/
|
||||
@Entity
|
||||
@Cacheable
|
||||
@Table( name = "PERSON",
|
||||
@Table(name = "PERSON",
|
||||
indexes = {
|
||||
@Index(name = "last_name_idx", columnList="PERSON_LAST_NAME", unique = false)
|
||||
/*, @Index(name = "email_idx", columnList="EMAIL", unique = false)*/})
|
||||
public class Person
|
||||
{
|
||||
/** The person id. */
|
||||
@Id @GeneratedValue(strategy=GenerationType.AUTO)
|
||||
@Column(name = "PERSON_ID")
|
||||
@Index(name = "last_name_idx", columnList = "PERSON_LAST_NAME", unique = false)
|
||||
/*, @Index(name = "email_idx", columnList="EMAIL", unique = false)*/ })
|
||||
public class Person extends AbstractAuditableEntity {
|
||||
/**
|
||||
* The person id.
|
||||
*/
|
||||
@Id @GeneratedValue(strategy = GenerationType.AUTO)
|
||||
@Column(name = "ID")
|
||||
private String personId;
|
||||
|
||||
/** The person first name. */
|
||||
/**
|
||||
* The person first name.
|
||||
*/
|
||||
@Column(name = "PERSON_FIRST_NAME")
|
||||
private String personFirstName;
|
||||
|
||||
/** The person last name. */
|
||||
/**
|
||||
* The person last name.
|
||||
*/
|
||||
@Column(name = "PERSON_LAST_NAME", nullable = false)
|
||||
private String personLastName;
|
||||
|
||||
/** The age. */
|
||||
/**
|
||||
* The age.
|
||||
*/
|
||||
@Column(name = "AGE")
|
||||
private int age;
|
||||
|
||||
/** Email addresses.
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "EMAIL")
|
||||
@Transient
|
||||
private Set<String> email = new HashSet<>();
|
||||
|
||||
@Column(name = "UPDATED")
|
||||
@Temporal(TemporalType.DATE)
|
||||
private Date updated;
|
||||
/**
|
||||
* Email addresses.
|
||||
*
|
||||
* @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||
* @JoinColumn(name = "EMAIL")
|
||||
* @Transient private Set<String> email = new HashSet<>();
|
||||
* @Column(name = "UPDATED")
|
||||
* @Temporal(TemporalType.DATE) private Date updated;
|
||||
*/
|
||||
|
||||
@OneToMany(mappedBy = "seller")
|
||||
private List<Product> products;
|
||||
|
||||
@Column(name = "VERSION")
|
||||
@Version
|
||||
private long version;
|
||||
|
||||
|
||||
/**
|
||||
* Gets the person id.
|
||||
*
|
||||
* @return the person id
|
||||
*/
|
||||
public String getPersonId()
|
||||
{
|
||||
public String getPersonId() {
|
||||
return personId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the person id.
|
||||
*
|
||||
* @param personId
|
||||
* the new person id
|
||||
* @param personId the new person id
|
||||
*/
|
||||
public void setPersonId(String personId)
|
||||
{
|
||||
public void setPersonId(String personId) {
|
||||
this.personId = personId;
|
||||
}
|
||||
|
||||
|
@ -76,8 +74,7 @@ public class Person
|
|||
*
|
||||
* @return the person name
|
||||
*/
|
||||
public String getPersonName()
|
||||
{
|
||||
public String getPersonName() {
|
||||
return personFirstName + " " + personLastName;
|
||||
}
|
||||
|
||||
|
@ -86,19 +83,16 @@ public class Person
|
|||
*
|
||||
* @return the person first name
|
||||
*/
|
||||
public String getPersonFirstName()
|
||||
{
|
||||
public String getPersonFirstName() {
|
||||
return personFirstName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the person first name.
|
||||
*
|
||||
* @param personFirstName
|
||||
* the new person first name
|
||||
* @param personFirstName the new person first name
|
||||
*/
|
||||
public void setPersonFirstName(String personFirstName)
|
||||
{
|
||||
public void setPersonFirstName(String personFirstName) {
|
||||
this.personFirstName = personFirstName;
|
||||
}
|
||||
|
||||
|
@ -107,19 +101,16 @@ public class Person
|
|||
*
|
||||
* @return the person last name
|
||||
*/
|
||||
public String getPersonLastName()
|
||||
{
|
||||
public String getPersonLastName() {
|
||||
return personLastName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the person last name.
|
||||
*
|
||||
* @param personLastName
|
||||
* the new person last name
|
||||
* @param personLastName the new person last name
|
||||
*/
|
||||
public void setPersonLastName(String personLastName)
|
||||
{
|
||||
public void setPersonLastName(String personLastName) {
|
||||
this.personLastName = personLastName;
|
||||
}
|
||||
|
||||
|
@ -128,22 +119,19 @@ public class Person
|
|||
*
|
||||
* @return the age
|
||||
*/
|
||||
public int getAge()
|
||||
{
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the age.
|
||||
*
|
||||
* @param age
|
||||
* the new age
|
||||
* @param age the new age
|
||||
*/
|
||||
public void setAge(int age)
|
||||
{
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
// public void addEmail(String email) { this.email.add(email); }
|
||||
// public void addEmail(String email) { this.email.add(email); }
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.example.crud.entities;
|
|||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.annotation.Generated;
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
|
@ -12,26 +11,36 @@ import javax.persistence.*;
|
|||
**/
|
||||
@Data @Entity
|
||||
@ToString
|
||||
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
|
||||
public class Product
|
||||
{
|
||||
/** Id for the product. */
|
||||
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
|
||||
public class Product extends AbstractAuditableEntity {
|
||||
|
||||
/**
|
||||
* Id for the product.
|
||||
*/
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
/** Name of the Product. */
|
||||
/**
|
||||
* Name of the Product.
|
||||
*/
|
||||
@Basic
|
||||
private String name=null;
|
||||
private String name = null;
|
||||
|
||||
/** Description of the Product. */
|
||||
/**
|
||||
* Description of the Product.
|
||||
*/
|
||||
@Basic
|
||||
private String description=null;
|
||||
private String description = null;
|
||||
|
||||
/** Price of the Product. */
|
||||
/**
|
||||
* Price of the Product.
|
||||
*/
|
||||
@Basic
|
||||
private double price=0.0;
|
||||
private double price = 0.0;
|
||||
|
||||
/** Seller of this product. */
|
||||
/**
|
||||
* Seller of this product.
|
||||
*/
|
||||
@ManyToOne(optional = false)
|
||||
private Person seller;
|
||||
|
||||
|
@ -43,6 +52,7 @@ public class Product
|
|||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param name name of product
|
||||
* @param description description of product
|
||||
* @param price Price
|
||||
|
@ -53,4 +63,12 @@ public class Product
|
|||
this.price = price;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,19 +1,34 @@
|
|||
package com.example.crud.repositories;
|
||||
|
||||
import com.codahale.metrics.annotation.Metered;
|
||||
import com.example.crud.entities.Inventory;
|
||||
import com.example.crud.entities.Product;
|
||||
import io.astefanutti.metrics.aspectj.Metrics;
|
||||
import org.datanucleus.api.jpa.annotations.ReadOnly;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface InventoryRepository extends JpaRepository<Inventory, String> {
|
||||
//@Metrics(registry = "${this.registry}")
|
||||
public interface InventoryRepository extends JpaRepository<Inventory, String>, JpaSpecificationExecutor {
|
||||
|
||||
//@Metered(name = "${this.id}")
|
||||
@Transactional
|
||||
@Cacheable(value = "inventory", key = "#name")
|
||||
Inventory findByName(String name);
|
||||
|
||||
@ReadOnly
|
||||
@Query(value = "select * from inventory where product_id_eid contains :productId allow filtering",
|
||||
nativeQuery = true)
|
||||
List<Inventory> findByProduct(@Param("productId") String productId);
|
||||
|
||||
@Transactional
|
||||
@CacheEvict(value = "inventory", key = "#name")
|
||||
void deleteInventoryBy(String name);
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,30 @@
|
|||
<description>JPA Mapping for CRUD/JPA</description>
|
||||
<package>com.example.crud.entities</package>
|
||||
|
||||
<entity class="com.example.crud.entities.AbstractEntity" name="AbstractEntity">
|
||||
<version name="version">
|
||||
<column name="VERSION"></column>
|
||||
</version>
|
||||
</entity>
|
||||
|
||||
|
||||
<entity class="com.example.crud.entities.AbstractAuditableEntity" name="AbstractAuditableEntity">
|
||||
<attributes>
|
||||
<basic name="createdDateTime">
|
||||
<column name="created" nullable="=false"/>
|
||||
</basic>
|
||||
<basic name="lastModifiedDateTime">
|
||||
<column name="modified" nullable="=false"/>
|
||||
</basic>
|
||||
<basic name="createdByUser">
|
||||
<column name="created_by" nullable="false"/>
|
||||
</basic>
|
||||
<basic name="modifiedByUser">
|
||||
<column name="modified_by" nullable="false"/>
|
||||
</basic>
|
||||
</attributes>
|
||||
</entity>
|
||||
|
||||
<!--
|
||||
@Table(indexes = {@Index(columnList="PRICE")})
|
||||
-->
|
||||
|
@ -48,9 +72,6 @@
|
|||
<id name="name">
|
||||
<column name="NAME" length="40"></column>
|
||||
</id>
|
||||
<version name="version">
|
||||
<column name="VERSION"></column>
|
||||
</version>
|
||||
<one-to-many name="products">
|
||||
<join-table name="INVENTORY_PRODUCTS">
|
||||
<join-column name="INVENTORY_ID_OID"/>
|
||||
|
|
|
@ -25,6 +25,9 @@
|
|||
<properties>
|
||||
<property name="javax.persistence.jdbc.url" value="cassandra:"/>
|
||||
<property name="datanucleus.mapping.Schema" value="kc"/>
|
||||
<property name="datanucleus.cache.level2.type" value="jcache"/>
|
||||
<property name="datanucleus.cache.level2.cacheName" value="dist"/>
|
||||
<property name="datanucleus.cache.level2.timeout" value="10000"/>
|
||||
<property name="datanucleus.schema.autoCreateAll" value="true"/>
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
|
|
13
src/main/resources/ehcache.xml
Normal file
13
src/main/resources/ehcache.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" name="webCache" >
|
||||
<diskStore path="java.io.tmpdir/webCache"/>
|
||||
<cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory" properties="jgroups-l2-cache-udp-largecluster.xml"/>
|
||||
<cache name="crud"
|
||||
maxElementsInMemory="1000"
|
||||
eternal="false"
|
||||
timeToIdleSeconds="600"
|
||||
timeToLiveSeconds="6000"
|
||||
overflowToDisk="true">
|
||||
<cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory" properties="replicateAsynchronously=true,replicatePuts=true,replicateUpdates=true,replicateUpdatesViaCopy=false,replicateRemovals=true" />
|
||||
</cache>
|
||||
</ehcache>
|
18
src/main/resources/infinispan.xml
Normal file
18
src/main/resources/infinispan.xml
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<infinispan
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="urn:infinispan:config:9.1 http://www.infinispan.org/schemas/infinispan-config-9.1.xsd"
|
||||
xmlns="urn:infinispan:config:9.1">
|
||||
|
||||
<jgroups>
|
||||
<stack-file name="udp" path="jgroups.xml" />
|
||||
</jgroups>
|
||||
|
||||
<cache-container default-cache="default">
|
||||
<transport stack="udp" node-name="${nodeName}" />
|
||||
<replicated-cache name="repl" mode="SYNC" />
|
||||
<distributed-cache name="dist" mode="SYNC" owners="2" />
|
||||
</cache-container>
|
||||
|
||||
</infinispan>
|
||||
|
61
src/main/resources/jgroups-l2-cache-udp-largecluster.xml
Normal file
61
src/main/resources/jgroups-l2-cache-udp-largecluster.xml
Normal file
|
@ -0,0 +1,61 @@
|
|||
<!--
|
||||
UDP based stack modified to run well in clusters of large size. This is ongoing work<p/>
|
||||
JIRA: https://issues.jboss.org/browse/JGRP-100
|
||||
author: Bela Ban
|
||||
src: https://github.com/belaban/JGroups/blob/master/conf/udp-largecluster.xml
|
||||
-->
|
||||
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="urn:org:jgroups"
|
||||
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd">
|
||||
|
||||
<UDP mcast_addr="${jgroups.udp.mcast_addr:239.9.9.9}"
|
||||
mcast_port="${jgroups.udp.mcast_port:45588}"
|
||||
tos="8"
|
||||
ucast_recv_buf_size="5M"
|
||||
ucast_send_buf_size="5M"
|
||||
mcast_recv_buf_size="5M"
|
||||
mcast_send_buf_size="5M"
|
||||
max_bundle_size="64K"
|
||||
enable_diagnostics="true"
|
||||
thread_naming_pattern="cl"
|
||||
logical_addr_cache_max_size="1000"
|
||||
|
||||
thread_pool.min_threads="0"
|
||||
thread_pool.max_threads="500"
|
||||
thread_pool.keep_alive_time="5000"/>
|
||||
|
||||
<PING break_on_coord_rsp="true" />
|
||||
<MERGE3 max_interval="30000"
|
||||
min_interval="10000"/>
|
||||
<FD_SOCK/>
|
||||
<FD_ALL/>
|
||||
<VERIFY_SUSPECT timeout="1500" />
|
||||
<BARRIER />
|
||||
<pbcast.NAKACK2 xmit_interval="500"
|
||||
xmit_table_num_rows="100"
|
||||
xmit_table_msgs_per_row="2000"
|
||||
xmit_table_max_compaction_time="30000"
|
||||
use_mcast_xmit="true"
|
||||
discard_delivered_msgs="true"/>
|
||||
<UNICAST3
|
||||
xmit_table_num_rows="100"
|
||||
xmit_table_msgs_per_row="1000"
|
||||
xmit_table_max_compaction_time="30000"/>
|
||||
<pbcast.STABLE desired_avg_gossip="60000"
|
||||
max_bytes="4M"/>
|
||||
<pbcast.GMS print_local_addr="true"
|
||||
join_timeout="10000"
|
||||
view_bundling="true"
|
||||
max_bundling_time="1000"
|
||||
merge_timeout="5000"
|
||||
resume_task_timeout="15000"
|
||||
/>
|
||||
<UFC max_credits="4M"
|
||||
min_threshold="0.4"/>
|
||||
<MFC max_credits="4M"
|
||||
min_threshold="0.4"/>
|
||||
<FRAG2 frag_size="60K" />
|
||||
<RSVP resend_interval="2000" timeout="10000"/>
|
||||
<pbcast.STATE_TRANSFER />
|
||||
</config>
|
|
@ -17,6 +17,10 @@
|
|||
</filter>
|
||||
</appender>
|
||||
|
||||
<category name="com.example.crud">
|
||||
<priority value="TRACE"/>
|
||||
</category>
|
||||
|
||||
<logger name="com.mchange.v2.resourcepool" level="INFO">
|
||||
<appender-ref ref="console"/>
|
||||
</logger>
|
||||
|
@ -38,10 +42,6 @@
|
|||
<appender-ref ref="console"/>
|
||||
</logger>
|
||||
|
||||
<logger name="org.mongodb.driver" level="TRACE">
|
||||
<appender-ref ref="console"/>
|
||||
</logger>
|
||||
|
||||
<logger name="org.springdata.cassandra" level="TRACE">
|
||||
<appender-ref ref="console"/>
|
||||
</logger>
|
||||
|
@ -82,6 +82,18 @@
|
|||
<appender-ref ref="console"/>
|
||||
</logger>
|
||||
|
||||
<category name="org.infinispan">
|
||||
<priority value="TRACE"/>
|
||||
</category>
|
||||
|
||||
<category name="org.jgroups">
|
||||
<priority value="WARN"/>
|
||||
</category>
|
||||
|
||||
<logger name="org.mongodb.driver" level="TRACE">
|
||||
<appender-ref ref="console"/>
|
||||
</logger>
|
||||
|
||||
<logger name="net.spy.memcached" level="TRACE">
|
||||
<appender-ref ref="console"/>
|
||||
</logger>
|
||||
|
|
Loading…
Reference in a new issue