Return-Path: X-Original-To: apmail-zest-commits-archive@minotaur.apache.org Delivered-To: apmail-zest-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E7D2E172E6 for ; Fri, 17 Apr 2015 16:47:25 +0000 (UTC) Received: (qmail 95820 invoked by uid 500); 17 Apr 2015 16:47:25 -0000 Delivered-To: apmail-zest-commits-archive@zest.apache.org Received: (qmail 95775 invoked by uid 500); 17 Apr 2015 16:47:25 -0000 Mailing-List: contact commits-help@zest.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zest.apache.org Delivered-To: mailing list commits@zest.apache.org Received: (qmail 95756 invoked by uid 99); 17 Apr 2015 16:47:25 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Apr 2015 16:47:25 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9460BDFC12; Fri, 17 Apr 2015 16:47:25 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: niclas@apache.org To: commits@zest.apache.org Date: Fri, 17 Apr 2015 16:47:25 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/2] zest-sandbox git commit: Gigaspaces entitystore was laying around on my disk from somewhere. committing it, to not loose it, but it is probably for pre-1.0 Repository: zest-sandbox Updated Branches: refs/heads/gigaspaces_impl 1b2bbf649 -> 5105c6e47 Gigaspaces entitystore was laying around on my disk from somewhere. committing it, to not loose it, but it is probably for pre-1.0 Project: http://git-wip-us.apache.org/repos/asf/zest-sandbox/repo Commit: http://git-wip-us.apache.org/repos/asf/zest-sandbox/commit/c5da67d3 Tree: http://git-wip-us.apache.org/repos/asf/zest-sandbox/tree/c5da67d3 Diff: http://git-wip-us.apache.org/repos/asf/zest-sandbox/diff/c5da67d3 Branch: refs/heads/gigaspaces_impl Commit: c5da67d3b7cb7bc87fb06dd4f423444d7db68f50 Parents: b74044f Author: Niclas Hedhman Authored: Sat Apr 18 00:11:15 2015 +0800 Committer: Niclas Hedhman Committed: Sat Apr 18 00:11:15 2015 +0800 ---------------------------------------------------------------------- .../qi4j-entitystore-gs-sample/common/pom.xml | 25 ++++ .../entitystore/gigaspaces/common/Data.java | 122 +++++++++++++++++++ .../feeder/Feeder.launch | 13 ++ .../qi4j-entitystore-gs-sample/feeder/pom.xml | 50 ++++++++ .../feeder/src/main/assembly/assembly.xml | 37 ++++++ .../entitystore/gigaspaces/feeder/Feeder.java | 101 +++++++++++++++ .../src/main/resources/META-INF/spring/pu.xml | 50 ++++++++ .../qi4j-entitystore-gs-sample/pom.xml | 69 +++++++++++ .../processor/Processor.launch | 12 ++ .../processor/Processor_2_1.launch | 13 ++ .../processor/pom.xml | 50 ++++++++ .../processor/src/main/assembly/assembly.xml | 37 ++++++ .../gigaspaces/processor/Processor.java | 44 +++++++ .../src/main/resources/META-INF/spring/pu.xml | 64 ++++++++++ .../src/main/resources/META-INF/spring/sla.xml | 20 +++ .../ProcessorIntegrationTest-context.xml | 58 +++++++++ .../processor/ProcessorIntegrationTest.java | 55 +++++++++ .../gigaspaces/processor/ProcessorTest.java | 25 ++++ .../qi4j-entitystore-gs-sample/readme.txt | 106 ++++++++++++++++ 19 files changed, 951 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/c5da67d3/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/common/pom.xml ---------------------------------------------------------------------- diff --git a/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/common/pom.xml b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/common/pom.xml new file mode 100644 index 0000000..e32f4e5 --- /dev/null +++ b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/common/pom.xml @@ -0,0 +1,25 @@ + + 4.0.0 + org.qi4j.entitystore.gigaspaces + common + jar + 1.0-SNAPSHOT + common + + org.qi4j.entitystore.gigaspaces + qi4j-entitystore-gs-sample + 1.0-SNAPSHOT + + + qi4j-entitystore-gs-sample-common + + + src/main/java + + **/*.xml + + + + + http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/c5da67d3/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/common/src/main/java/org/qi4j/entitystore/gigaspaces/common/Data.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/common/src/main/java/org/qi4j/entitystore/gigaspaces/common/Data.java b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/common/src/main/java/org/qi4j/entitystore/gigaspaces/common/Data.java new file mode 100644 index 0000000..b8b5838 --- /dev/null +++ b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/common/src/main/java/org/qi4j/entitystore/gigaspaces/common/Data.java @@ -0,0 +1,122 @@ +package org.qi4j.entitystore.gigaspaces.common; + +import com.gigaspaces.annotation.pojo.SpaceClass; +import com.gigaspaces.annotation.pojo.SpaceId; +import com.gigaspaces.annotation.pojo.SpaceRouting; + + +/** + * A simple object used to work with the Space. Important properties include the id + * of the object, a type (used to perform routing when working with partitioned space), + * the raw data and processed data, and a boolean flag indicating if this Data object + * was processed or not. + */ +@SpaceClass +public class Data { + + private String id; + + private Long type; + + private String rawData; + + private String data; + + private Boolean processed; + + /** + * Constructs a new Data object. + */ + public Data() { + + } + + /** + * Constructs a new Data object with the given type + * and raw data. + */ + public Data(long type, String rawData) { + this.type = type; + this.rawData = rawData; + this.processed = false; + } + + /** + * The id of this object. + */ + @SpaceId(autoGenerate=true) + public String getId() { + return id; + } + + /** + * The id of this object. Its value will be auto generated when it is written + * to the space. + */ + public void setId(String id) { + this.id = id; + } + + /** + * The type of the data object. Used as the routing field when working with + * a partitioned space. + */ + @SpaceRouting + public Long getType() { + return type; + } + + /** + * The type of the data object. Used as the routing field when working with + * a partitioned space. + */ + public void setType(Long type) { + this.type = type; + } + + /** + * The raw data this object holds. + */ + public String getRawData() { + return rawData; + } + + /** + * The raw data this object holds. + */ + public void setRawData(String rawData) { + this.rawData = rawData; + } + + /** + * The processed data this object holds. + */ + public String getData() { + return data; + } + + /** + * The processed data this object holds. + */ + public void setData(String data) { + this.data = data; + } + + /** + * A boolean flag indicating if the data object was processed or not. + */ + public Boolean isProcessed() { + return processed; + } + + /** + * A boolean flag indicating if the data object was processed or not. + */ + public void setProcessed(Boolean processed) { + this.processed = processed; + } + + public String toString() { + return "id[" + id + "] type[" + type + "] rawData[" + rawData + "] data[" + data + "] processed[" + processed + "]"; + } +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/c5da67d3/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/feeder/Feeder.launch ---------------------------------------------------------------------- diff --git a/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/feeder/Feeder.launch b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/feeder/Feeder.launch new file mode 100644 index 0000000..75d453e --- /dev/null +++ b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/feeder/Feeder.launch @@ -0,0 +1,13 @@ + + + + + + + + + + + + http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/c5da67d3/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/feeder/pom.xml ---------------------------------------------------------------------- diff --git a/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/feeder/pom.xml b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/feeder/pom.xml new file mode 100644 index 0000000..7e6c90d --- /dev/null +++ b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/feeder/pom.xml @@ -0,0 +1,50 @@ + + 4.0.0 + org.qi4j.entitystore.gigaspaces + feeder + jar + 1.0-SNAPSHOT + feeder + + org.qi4j.entitystore.gigaspaces + qi4j-entitystore-gs-sample + 1.0-SNAPSHOT + + + PU + + + + org.qi4j.entitystore.gigaspaces + common + 1.0-SNAPSHOT + compile + + + + qi4j-entitystore-gs-sample-feeder + + + maven-assembly-plugin + + false + false + true + + src/main/assembly/assembly.xml + + + + + assembly + package + + single + + + + + + + http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/c5da67d3/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/feeder/src/main/assembly/assembly.xml ---------------------------------------------------------------------- diff --git a/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/feeder/src/main/assembly/assembly.xml b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/feeder/src/main/assembly/assembly.xml new file mode 100644 index 0000000..aac9f1f --- /dev/null +++ b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/feeder/src/main/assembly/assembly.xml @@ -0,0 +1,37 @@ + + assemble-pu + + jar + dir + + false + + + target/classes + keep + / + + **/** + + + + + + false + false + lib + + org.qi4j.entitystore.gigaspaces:common + + + + false + true + true + lib + + org.qi4j.entitystore.gigaspaces:common + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/c5da67d3/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/feeder/src/main/java/org/qi4j/entitystore/gigaspaces/feeder/Feeder.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/feeder/src/main/java/org/qi4j/entitystore/gigaspaces/feeder/Feeder.java b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/feeder/src/main/java/org/qi4j/entitystore/gigaspaces/feeder/Feeder.java new file mode 100644 index 0000000..6622d96 --- /dev/null +++ b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/feeder/src/main/java/org/qi4j/entitystore/gigaspaces/feeder/Feeder.java @@ -0,0 +1,101 @@ +package org.qi4j.entitystore.gigaspaces.feeder; + +import org.qi4j.entitystore.gigaspaces.common.Data; + +import org.openspaces.core.GigaSpace; +import org.openspaces.core.SpaceInterruptedException; +import org.openspaces.core.context.GigaSpaceContext; + +import org.springframework.beans.factory.DisposableBean; +import org.springframework.beans.factory.InitializingBean; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; + + +/** + * A feeder bean starts a scheduled task that writes a new Data objects to the space + * (in an unprocessed state). + * + *

The space is injected into this bean using OpenSpaces support for @GigaSpaceContext + * annotation. + * + *

The scheduling uses the java.util.concurrent Scheduled Executor Service. It + * is started and stopped based on Spring life cycle events. + * + * @author kimchy + */ +public class Feeder implements InitializingBean, DisposableBean { + + private ScheduledExecutorService executorService; + + private ScheduledFuture sf; + + private long numberOfTypes = 10; + + private long defaultDelay = 1000; + + private FeederTask feederTask; + + @GigaSpaceContext + private GigaSpace gigaSpace; + + /** + * Sets the number of types that will be used to set {@link org.openspaces.example.data.common.Data#setType(Long)}. + * + *

The type is used as the routing index for partitioned space. This will affect the distribution of Data + * objects over a partitioned space. + */ + public void setNumberOfTypes(long numberOfTypes) { + this.numberOfTypes = numberOfTypes; + } + + public void setDefaultDelay(long defaultDelay) { + this.defaultDelay = defaultDelay; + } + + public void afterPropertiesSet() throws Exception { + System.out.println("--- STARTING FEEDER WITH CYCLE [" + defaultDelay + "]"); + executorService = Executors.newScheduledThreadPool(1); + feederTask = new FeederTask(); + sf = executorService.scheduleAtFixedRate(feederTask, defaultDelay, defaultDelay, + TimeUnit.MILLISECONDS); + } + + public void destroy() throws Exception { + sf.cancel(false); + sf = null; + executorService.shutdown(); + } + + public long getFeedCount() { + return feederTask.getCounter(); + } + + + public class FeederTask implements Runnable { + + private long counter = 1; + + public void run() { + try { + long time = System.currentTimeMillis(); + Data data = new Data((counter++ % numberOfTypes), "FEEDER " + Long.toString(time)); + gigaSpace.write(data); + System.out.println("--- FEEDER WROTE " + data); + } catch (SpaceInterruptedException e) { + // ignore, we are being shutdown + } catch (Exception e) { + e.printStackTrace(); + } + } + + public long getCounter() { + return counter; + } + } + + +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/c5da67d3/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/feeder/src/main/resources/META-INF/spring/pu.xml ---------------------------------------------------------------------- diff --git a/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/feeder/src/main/resources/META-INF/spring/pu.xml b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/feeder/src/main/resources/META-INF/spring/pu.xml new file mode 100644 index 0000000..3813bf3 --- /dev/null +++ b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/feeder/src/main/resources/META-INF/spring/pu.xml @@ -0,0 +1,50 @@ + + + + + + + + + 100 + + + + + + + + + + + + + + + + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/c5da67d3/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/pom.xml ---------------------------------------------------------------------- diff --git a/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/pom.xml b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/pom.xml new file mode 100644 index 0000000..0b0da1d --- /dev/null +++ b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/pom.xml @@ -0,0 +1,69 @@ + + 4.0.0 + org.qi4j.entitystore.gigaspaces + qi4j-entitystore-gs-sample + 1.0-SNAPSHOT + qi4j-entitystore-gs-sample + pom + + 7.1.2 + 3.0.3.RELEASE + + + common + processor + feeder + + + + com.gigaspaces + gs-openspaces + ${gsVersion} + provided + + + junit + junit + 4.8.1 + test + + + org.springframework + spring-test + ${springVersion} + test + + + + package + + + src/test/java + + **/*.xml + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.2-beta-2 + + + org.apache.maven.plugins + maven-openspaces-plugin + ${gsVersion} + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/c5da67d3/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/Processor.launch ---------------------------------------------------------------------- diff --git a/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/Processor.launch b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/Processor.launch new file mode 100644 index 0000000..c659d29 --- /dev/null +++ b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/Processor.launch @@ -0,0 +1,12 @@ + + + + + + + + + + + + http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/c5da67d3/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/Processor_2_1.launch ---------------------------------------------------------------------- diff --git a/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/Processor_2_1.launch b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/Processor_2_1.launch new file mode 100644 index 0000000..074b360 --- /dev/null +++ b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/Processor_2_1.launch @@ -0,0 +1,13 @@ + + + + + + + + + + + + + http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/c5da67d3/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/pom.xml ---------------------------------------------------------------------- diff --git a/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/pom.xml b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/pom.xml new file mode 100644 index 0000000..7a2f223 --- /dev/null +++ b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/pom.xml @@ -0,0 +1,50 @@ + + 4.0.0 + org.qi4j.entitystore.gigaspaces + processor + jar + 1.0-SNAPSHOT + processor + + org.qi4j.entitystore.gigaspaces + qi4j-entitystore-gs-sample + 1.0-SNAPSHOT + + + PU + + + + org.qi4j.entitystore.gigaspaces + common + 1.0-SNAPSHOT + compile + + + + qi4j-entitystore-gs-sample-processor + + + maven-assembly-plugin + + false + false + true + + src/main/assembly/assembly.xml + + + + + assembly + package + + single + + + + + + + http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/c5da67d3/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/main/assembly/assembly.xml ---------------------------------------------------------------------- diff --git a/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/main/assembly/assembly.xml b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/main/assembly/assembly.xml new file mode 100644 index 0000000..aac9f1f --- /dev/null +++ b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/main/assembly/assembly.xml @@ -0,0 +1,37 @@ + + assemble-pu + + jar + dir + + false + + + target/classes + keep + / + + **/** + + + + + + false + false + lib + + org.qi4j.entitystore.gigaspaces:common + + + + false + true + true + lib + + org.qi4j.entitystore.gigaspaces:common + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/c5da67d3/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/main/java/org/qi4j/entitystore/gigaspaces/processor/Processor.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/main/java/org/qi4j/entitystore/gigaspaces/processor/Processor.java b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/main/java/org/qi4j/entitystore/gigaspaces/processor/Processor.java new file mode 100644 index 0000000..5ffdf7b --- /dev/null +++ b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/main/java/org/qi4j/entitystore/gigaspaces/processor/Processor.java @@ -0,0 +1,44 @@ +package org.qi4j.entitystore.gigaspaces.processor; + +import org.qi4j.entitystore.gigaspaces.common.Data; + +import org.openspaces.events.adapter.SpaceDataEvent; + + +/** + * The processor simulates work done no un-processed Data object. The processData + * accepts a Data object, simulate work by sleeping, and then sets the processed + * flag to true and returns the processed Data. + */ +public class Processor { + + private long workDuration = 100; + + /** + * Sets the simulated work duration (in milliseconds). Default to 100. + */ + public void setWorkDuration(long workDuration) { + this.workDuration = workDuration; + } + + /** + * Process the given Data object and returning the processed Data. + * + * Can be invoked using OpenSpaces Events when a matching event + * occurs. + */ + @SpaceDataEvent + public Data processData(Data data) { + // sleep to simulate some work + try { + Thread.sleep(workDuration); + } catch (InterruptedException e) { + // do nothing + } + data.setProcessed(true); + data.setData("PROCESSED : " + data.getRawData()); + System.out.println(" ------ PROCESSED : " + data); + return data; + } + +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/c5da67d3/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/main/resources/META-INF/spring/pu.xml ---------------------------------------------------------------------- diff --git a/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/main/resources/META-INF/spring/pu.xml b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/main/resources/META-INF/spring/pu.xml new file mode 100644 index 0000000..d7e98cb --- /dev/null +++ b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/main/resources/META-INF/spring/pu.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/c5da67d3/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/main/resources/META-INF/spring/sla.xml ---------------------------------------------------------------------- diff --git a/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/main/resources/META-INF/spring/sla.xml b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/main/resources/META-INF/spring/sla.xml new file mode 100644 index 0000000..83931d1 --- /dev/null +++ b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/main/resources/META-INF/spring/sla.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/c5da67d3/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/test/java/org/qi4j/entitystore/gigaspaces/processor/ProcessorIntegrationTest-context.xml ---------------------------------------------------------------------- diff --git a/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/test/java/org/qi4j/entitystore/gigaspaces/processor/ProcessorIntegrationTest-context.xml b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/test/java/org/qi4j/entitystore/gigaspaces/processor/ProcessorIntegrationTest-context.xml new file mode 100644 index 0000000..15df896 --- /dev/null +++ b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/test/java/org/qi4j/entitystore/gigaspaces/processor/ProcessorIntegrationTest-context.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/c5da67d3/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/test/java/org/qi4j/entitystore/gigaspaces/processor/ProcessorIntegrationTest.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/test/java/org/qi4j/entitystore/gigaspaces/processor/ProcessorIntegrationTest.java b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/test/java/org/qi4j/entitystore/gigaspaces/processor/ProcessorIntegrationTest.java new file mode 100644 index 0000000..ee9aabe --- /dev/null +++ b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/test/java/org/qi4j/entitystore/gigaspaces/processor/ProcessorIntegrationTest.java @@ -0,0 +1,55 @@ +package org.qi4j.entitystore.gigaspaces.processor; + +import org.qi4j.entitystore.gigaspaces.common.Data; + +import org.junit.runner.RunWith; +import org.junit.Before; +import org.junit.After; +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.beans.factory.annotation.Autowired; + +import org.openspaces.core.GigaSpace; + + +/** + * Integration test for the Processor. Uses similar xml definition file (ProcessorIntegrationTest-context.xml) + * to the actual pu.xml. Writs an unprocessed Data to the Space, and verifies that it has been processed by + * taking a processed one from the space. + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration +public class ProcessorIntegrationTest { + + @Autowired + GigaSpace gigaSpace; + + @Before + @After + public void clearSpace() { + gigaSpace.clear(null); + } + + @Test + public void verifyProcessing() throws Exception { + // write the data to be processed to the Space + Data data = new Data(1, "test"); + gigaSpace.write(data); + + // create a template of the processed data (processed) + Data template = new Data(); + template.setType(1l); + template.setProcessed(true); + + // wait for the result + Data result = gigaSpace.take(template, 500); + // verify it + assertNotNull("No data object was processed", result); + assertEquals("Processed Flag is false, data was not processed", true, result.isProcessed()); + assertEquals("Processed text mismatch", "PROCESSED : " + data.getRawData(), result.getData()); + } +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/c5da67d3/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/test/java/org/qi4j/entitystore/gigaspaces/processor/ProcessorTest.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/test/java/org/qi4j/entitystore/gigaspaces/processor/ProcessorTest.java b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/test/java/org/qi4j/entitystore/gigaspaces/processor/ProcessorTest.java new file mode 100644 index 0000000..f815204 --- /dev/null +++ b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/processor/src/test/java/org/qi4j/entitystore/gigaspaces/processor/ProcessorTest.java @@ -0,0 +1,25 @@ +package org.qi4j.entitystore.gigaspaces.processor; + +import org.qi4j.entitystore.gigaspaces.common.Data; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; + + +/** + * A simple unit test that verifies the Processor processData method actually processes + * the Data object. + */ +public class ProcessorTest { + + @Test + public void verifyProcessedFlag() { + Processor processor = new Processor(); + Data data = new Data(1, "test"); + + Data result = processor.processData(data); + assertEquals("verify that the data object was processed", true, result.isProcessed()); + assertEquals("verify the data was processed", "PROCESSED : " + data.getRawData(), result.getData()); + assertEquals("verify the type was not changed", data.getType(), result.getType()); + } +} http://git-wip-us.apache.org/repos/asf/zest-sandbox/blob/c5da67d3/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/readme.txt ---------------------------------------------------------------------- diff --git a/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/readme.txt b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/readme.txt new file mode 100644 index 0000000..75b3019 --- /dev/null +++ b/extensions/entitystore-gigaspaces/qi4j-entitystore-gs-sample/readme.txt @@ -0,0 +1,106 @@ +Creates a basic SBA application with two processing units. The Feeder +processing unit sends Data objects through the Space to a Processor. +The Space and the Processor are collocated in the same processing unit. +JVM: >= 5. + +GENERAL DESCRIPTION: +-------------------- + + The project consists of three modules: common, processor and feeder. The common +module includes all the shared resources and classes between both the processor +and the feeder. In our case, the common module includes the "Data" class which +is written and taken from the Space. + + The processor module, which is a processing unit, starts up a Space and on top of +it starts a polling container that performs a take from the Space of unprocessed Data +entries. The take operation results in an "event" that will end up executing the +"Processor" class. The Processor "processes" the Data object (by setting its processed +flag to true) and returns it. The return value is automatically written back to the Space. + The processor also comes with both a unit test and integration test that verifies its behavior. + + The feeder module, which is also a processing unit, connects to a Space remotely and +writes unprocessed Data objects to the Space (resulting in events firing up within +the processor processing unit). + +BUILDING, PACKAGING, RUNNING, DEPLOYING +--------------------------------------- + +Quick list: + +* mvn compile: Compiles the project. +* mvn os:run: Runs the project. +* mvn test: Runs the tests in the project. +* mvn package: Compiles and packages the project. +* mvn os:run-standalone: Runs a packaged application (from the jars). +* mvn os:deploy: Deploys the project onto the Service Grid. +* mvn os:undeploy: Removes the project from the Service Grid. + + In order to build the example, a simple "mvn compile" executed from the root of the +project will compile all the different modules. + + Packaging the application can be done using "mvn package" (note, by default, it also +runs the tests, in order to disable it, use -DskipTests). The packaging process jars up +the common module. The feeder and processor modules packaging process creates a +"processing unit structure" directory within the target directory called [app-name]-[module]. +It also creates a jar from the mentioned directory called [app-name]-[module].jar. + + In order to simply run both the processor and the feeder (after compiling), "mvn os:run" can be used. +This will run a single instance of the processor and a single instance of the feeder within +the same JVM using the compilation level classpath (no need for packaging). + A specific module can also be executed by itself, which in this case, executing more than +one instance of the processing unit can be done. For example, running the processor module with +a cluster topology of 2 partitions, each with one backup, the following command can be used: +mvn os:run -Dmodule=processor -Dcluster="total_members=2,1". + + In order to run a packaged processing unit, "mvn package os:run-standalone" can be used (if +"mvn package" was already executed, it can be omitted). This operation will run the processing units +using the packaged jar files. Running a specific module with a cluster topology can be executed using: +mvn package os:run-standalone -Dmodule=processor -Dcluster="total_members=2,1". + + Deploying the application requires starting up a GSM and at least 2 GSCs (scripts located under +the bin directory within the GigaSpaces installation). Once started, running "mvn package os:deploy" +will deploy the two processing units. + When deploying, the SLA elements within each processing unit descriptor (pu.xml) are taken into +account. This means that by default when deploying the application, 2 partitions, each with +one backup will be created for the processor, and a single instance of the feeder will be created. + A special note regarding groups and deployment: If the GSM and GSCs were started under a specific +group, the -Dgroups=[group-name] will need to be used in the deploy command. + +WORKING WITH ECLIPSE +-------------------- + + In order to generate eclipse project the following command need to be executed from the root of +the application: "mvn eclipse:eclipse". Pointing the Eclipse import existing project wizard +to the application root directory will result in importing the three modules. +If this is a fresh Eclipse installation, the M2_REPO needs be defined and pointed to the local +maven repository (which resides under USER_HOME/.m2/repository). + + The application itself comes with built in launch targets allowing to run the processor and the +feeder using Eclipse run (or debug) targets. + +A NOTE OF CLUSTERING +-------------------- + + This application focus on showing how SBA is used. The processor starts up an embedded Space and +works directly on it. When deploying 2 partitions of the processor, two embedded spaces (within the +same cluster) will be created, with each polling container working only on the cluster member it +started in an in memory and transactional manner. This is the power of such an architecture, where +the processing of the Data happens in a collocated manner with the Data. If we want to add High +Availability to the processor, we can deploy 2 partitions, each with one backup (2,1). In this +case, the processor instances that ends up starting a cluster member Space which is the backup +will not perform any processing since the polling container identifies the Space state and won't +perform the take operation. If one of the processor primaries instances will fail, the backup +instance will become primary (with an up to date data), and its polling container will start +processing all the relevant Data. Note, when deploying on top of the Service Grid, the Service +Grid will also identify that one instance failed, and will automatically start it over in another +container (GSC). + + The feeder works with a clustered view of the Space (the 2,1 cluster topology looking as one), and +simply writes unprocessed Data objects to the Space. The routing (@SpaceRouting) controls to which +partition the unprocessed Data will be written and consequently which instance will process it. + +MAVEN PLUGIN WIKI PAGE +--------------------------------- + + For more information about the Maven Plugin please refer to: +http://www.gigaspaces.com/wiki/display/XAP71/Maven+Plugin \ No newline at end of file