Skip to content

Commit

Permalink
DOC-404 Added Storing Partition Summary topic to dev guide from SBP
Browse files Browse the repository at this point in the history
  • Loading branch information
PeninaR committed Aug 2, 2018
1 parent 52dc724 commit edf37ab
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
---
type: post
title: Storing Partition Summary Information
categories: SBP
parent: data-access-patterns.html
weight: 650
categories: XAP123, OSS
parent: task-execution-overview.html
weight: 300
---

|Author|XAP Version|Last Updated | Reference | Download |
|------|-----------|-------------|-----------|----------|
| Dixson Huie| 9.7 | March 2016 | | |


# Overview
You may have a scenario where computation is done on a partition by partition basis and you wish to save the results, instead of recalculating them each time. This example calculates values per partition and saves it to the current partition. It will work regardless of the number of partitions that are running in the space. The example uses an Executor Service to make the calcuations on each partition. The `ClusterInfo` object is used to get information about the partition the service is currently executing in. The results are then saved to a PartitionSummary object.

The following code demonstrates Space Based Remoting, aka Service Executor. A complete example can be found [here](/download_files/sbp/Store-Partition-Summary.zip).

{{% tabs %}}
# Service Interface

{{% tab "Service Interface" %}}
Configure the service interface as follows:

```java
public interface ISummary {
public void summary();
}
```

{{% /tab %}}
# Service Implementation

{{% tab "Service Implementation" %}}
The Service Implementation includes the code that is to be run on each partition and saves the summary information. The `ClusterInfo` object is used to gather the partition information.

```java
Expand Down Expand Up @@ -76,9 +69,9 @@ public class SummaryService implements ISummary {
}

```
{{% /tab %}}

{{% tab "The Client" %}}
# Client

This is how a client might invoke the service:

```java
Expand All @@ -90,35 +83,4 @@ This is how a client might invoke the service:
iSummary.summary();

```
{{% /tab %}}

{{% /tabs %}}

# ProtectiveMode Exception
The second part of this example explains how to correct the `ProtectiveMode` exception that may occur.

In XAP 9.7, a `ProtectiveMode` was added to protect against writing an object directly to a partition that is assigned the wrong routing value.

If an application writes directly to one of the partitions and assigns the wrong routing value you’ll get the following exception:

```java
com.gigaspaces.client.protective.ProtectiveModeException: Operation is rejected - the routing value in the written entry of type 'PartitionSummary' does not match this space partition id. The value within the entry's routing property named 'routingId' is 1 which matches partition id 2 while current partition id is 1...
```
This ProtectiveMode Exception can be suppressed, by setting the `-Dcom.gs.protectiveMode.wrongEntryRoutingUsage=false` System property. However, the code example given corrects the `ProtectiveMode` exception, without suppressing exception message. This is done by adjusting the calculation of the routing id field in the PartitionSummary object.
```java
@SpaceClass
public class PartitionSummary implements Serializable {
...
@SpaceRouting
public Integer getRoutingId() {
return routingId;
}
public void setRoutingId(Integer routingId) {
this.routingId = (routingId - 1); // need to subtract 1 because objects are routed by routing value.hashCode % num. of partitions + 1
}
```

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ type: post123
title: Dynamic Language Tasks
categories: XAP123, OSS
parent: task-execution-overview.html
weight: 300
weight: 100
---


Expand Down
2 changes: 1 addition & 1 deletion site/content/xap/12.3/dev-java/task-metadata.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ type: post123
title: Metadata
categories: XAP123, OSS
parent: task-execution-overview.html
weight: 400
weight: 200
---


Expand Down

0 comments on commit edf37ab

Please sign in to comment.