├── .asf.yaml ├── .github └── workflows │ └── gradle.yml ├── .gitignore ├── LICENSE ├── NOTICE ├── README.md ├── async ├── README.md ├── scripts │ ├── start.gfsh │ └── stop.gfsh └── src │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── geode_examples │ │ └── async │ │ ├── Example.java │ │ ├── ExampleAsyncEventListener.java │ │ └── LevenshteinDistance.java │ └── test │ └── java │ └── org │ └── apache │ └── geode │ └── examples │ └── async │ ├── ExampleAsyncEventListenerTest.java │ ├── ExampleTest.java │ └── LevenshteinDistanceTest.java ├── build.gradle ├── buildSrc └── src │ └── main │ └── groovy │ └── org │ └── apache │ └── geode │ └── gradle │ └── PasswordDialog.groovy ├── clientSecurity ├── README.md ├── example_security.properties ├── keystore.jks ├── scripts │ ├── start.gfsh │ └── stop.gfsh ├── src │ └── main │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── geode_examples │ │ │ └── clientSecurity │ │ │ ├── Example.java │ │ │ └── ExampleAuthInit.java │ │ └── resources │ │ └── example_security.json └── truststore.jks ├── colocation ├── README.md ├── scripts │ ├── start.gfsh │ └── stop.gfsh └── src │ └── main │ └── java │ └── org │ └── apache │ └── geode_examples │ └── colocation │ ├── Customer.java │ ├── Example.java │ ├── Order.java │ ├── OrderKey.java │ └── OrderPartitionResolver.java ├── compression ├── README.md ├── scripts │ ├── start.gfsh │ └── stop.gfsh └── src │ └── main │ └── java │ └── org │ └── apache │ └── geode_examples │ └── compression │ └── Example.java ├── cq ├── README.md ├── scripts │ ├── start.gfsh │ └── stop.gfsh └── src │ └── main │ └── java │ └── org │ └── apache │ └── geode_examples │ └── cq │ ├── Example.java │ └── RandomEventListener.java ├── durableMessaging ├── README.md ├── scripts │ ├── start.gfsh │ └── stop.gfsh └── src │ └── main │ └── java │ └── org │ └── apache │ └── geode_examples │ └── durableMessaging │ └── Example.java ├── etc ├── eclipse-java-google-style.xml ├── eclipseOrganizeImports.importorder └── intellij-java-google-style.xml ├── eviction ├── README.md ├── scripts │ ├── start.gfsh │ └── stop.gfsh └── src │ └── main │ └── java │ └── org │ └── apache │ └── geode_examples │ └── eviction │ └── Example.java ├── expiration ├── README.md ├── scripts │ ├── start.gfsh │ └── stop.gfsh └── src │ └── main │ └── java │ └── org │ └── apache │ └── geode_examples │ └── expiration │ └── Example.java ├── functions ├── README.md ├── scripts │ ├── start.gfsh │ └── stop.gfsh └── src │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── geode_examples │ │ └── functions │ │ ├── Example.java │ │ └── PrimeNumber.java │ └── test │ └── java │ └── org │ └── apache │ └── geode_examples │ └── functions │ └── ExampleTest.java ├── gradle.properties ├── gradle ├── ide.gradle ├── rat.gradle ├── release.gradle ├── spotless.gradle └── wrapper │ └── gradle-wrapper.properties ├── gradlew ├── indexes ├── README.md ├── scripts │ ├── start.gfsh │ └── stop.gfsh └── src │ └── main │ └── java │ └── org │ └── apache │ └── geode_examples │ └── indexes │ ├── Example.java │ ├── FlightCode.java │ ├── Passenger.java │ └── RegionPopulator.java ├── jdbc ├── README.md ├── connector.svg ├── scripts │ ├── start.gfsh │ └── stop.gfsh └── src │ └── main │ └── java │ └── org │ └── apache │ └── geode_examples │ └── jdbc │ ├── Example.java │ └── Parent.java ├── listener ├── README.md ├── scripts │ ├── start.gfsh │ └── stop.gfsh └── src │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── geode_examples │ │ └── listener │ │ ├── Example.java │ │ └── ExampleCacheListener.java │ └── test │ └── java │ └── org │ └── apache │ └── geode │ └── examples │ └── listener │ └── ExampleTest.java ├── loader ├── README.md ├── scripts │ ├── start.gfsh │ └── stop.gfsh └── src │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── geode_examples │ │ └── loader │ │ ├── Example.java │ │ └── QuoteLoader.java │ └── test │ └── java │ └── org │ └── apache │ └── geode │ └── examples │ └── loader │ └── ExampleTest.java ├── lucene ├── README.md ├── build.gradle ├── scripts │ ├── start.gfsh │ └── stop.gfsh └── src │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── geode_examples │ │ └── lucene │ │ ├── Contact.java │ │ ├── EmployeeData.java │ │ └── Example.java │ └── test │ └── java │ └── org │ └── apache │ └── geode │ └── examples │ └── lucene │ └── ExampleTest.java ├── luceneSpatial ├── README.md ├── build.gradle ├── scripts │ ├── start.gfsh │ └── stop.gfsh └── src │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── geode_examples │ │ └── luceneSpatial │ │ ├── Example.java │ │ ├── SpatialHelper.java │ │ ├── TrainStop.java │ │ └── TrainStopSerializer.java │ └── test │ └── java │ └── org │ └── apache │ └── geode │ └── examples │ └── luceneSpatial │ ├── ExampleTest.java │ ├── SpatialHelperTest.java │ └── TrainStopSerializerTest.java ├── micrometerMetrics ├── README.md ├── build.gradle ├── prometheus-graph.png ├── prometheus-targets.png ├── prometheus.yml ├── scripts │ ├── start.gfsh │ └── stop.gfsh └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── geode_examples │ │ │ └── micrometerMetrics │ │ │ ├── Example.java │ │ │ └── SimpleMetricsPublishingService.java │ └── resources │ │ └── META-INF │ │ └── services │ │ └── org.apache.geode.metrics.MetricsPublishingService │ └── test │ └── java │ └── org │ └── apache │ └── geode_examples │ └── micrometerMetrics │ └── SimpleMetricsPublishingServiceTest.java ├── overflow ├── README.md └── scripts │ ├── start.gfsh │ └── stop.gfsh ├── partitioned ├── README.md ├── scripts │ ├── start.gfsh │ └── stop.gfsh └── src │ └── main │ └── java │ └── org │ └── apache │ └── geode_examples │ └── partitioned │ ├── EmployeeData.java │ ├── EmployeeKey.java │ └── Example.java ├── persistence ├── README.md ├── scripts │ ├── restart.gfsh │ ├── start.gfsh │ └── stop.gfsh └── src │ └── main │ └── java │ └── org │ └── apache │ └── geode_examples │ └── persistence │ └── Example.java ├── putall ├── README.md ├── scripts │ ├── start.gfsh │ └── stop.gfsh └── src │ └── main │ └── java │ └── org │ └── apache │ └── geode_examples │ └── putall │ └── Example.java ├── queries ├── README.md ├── scripts │ ├── start.gfsh │ └── stop.gfsh └── src │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── geode_examples │ │ └── queries │ │ ├── EmployeeData.java │ │ └── Example.java │ └── test │ └── java │ └── org │ └── apache │ └── geode_examples │ └── queries │ └── ExampleTest.java ├── replicated ├── .gitignore ├── README.md ├── scripts │ ├── start.gfsh │ └── stop.gfsh └── src │ └── main │ └── java │ └── org │ └── apache │ └── geode_examples │ └── replicated │ └── Example.java ├── rest ├── README.md ├── scripts │ ├── start.gfsh │ └── stop.gfsh └── src │ └── main │ └── java │ └── org │ └── apache │ └── geode_examples │ └── rest │ └── Example.java ├── serialization ├── README.md ├── scripts │ ├── start.gfsh │ └── stop.gfsh └── src │ └── main │ └── java │ └── org │ └── apache │ └── geode_examples │ └── serialization │ ├── Country.java │ └── Example.java ├── sessionState ├── README.md ├── scripts │ ├── example-setup.sh │ ├── example-shutdown.sh │ ├── shutdown-example.gfsh │ ├── start.gfsh │ └── stop.gfsh ├── src │ └── main │ │ └── java │ │ └── org │ │ └── apache │ │ └── geode_examples │ │ └── sessionState │ │ └── Example.java └── webapp │ ├── build.gradle │ ├── gradle │ └── wrapper │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── settings.gradle │ └── src │ └── main │ ├── java │ └── GeodeSessionStateServlet.java │ └── webapp │ └── index.jsp ├── settings.gradle ├── transaction ├── README.md ├── scripts │ ├── start.gfsh │ └── stop.gfsh └── src │ └── main │ └── java │ └── org │ └── apache │ └── geode_examples │ └── transaction │ ├── Example.java │ └── Incrementer.java ├── wan ├── README.md ├── scripts │ ├── start-ln.gfsh │ ├── start-ny.gfsh │ ├── start-wan.gfsh │ ├── start.gfsh │ └── stop.gfsh └── src │ └── main │ └── java │ └── org │ └── apache │ └── geode_examples │ └── wan │ └── Example.java └── writer ├── README.md ├── scripts ├── start.gfsh └── stop.gfsh └── src ├── main └── java │ └── org │ └── apache │ └── geode │ └── examples │ └── writer │ ├── Example.java │ ├── ExampleCacheWriter.java │ └── SSNVetter.java └── test └── java └── org └── apache └── geode_examples └── writer ├── ExampleCacheWriterTest.java ├── ExampleTest.java └── SSNVetterTest.java /.asf.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # http://www.apache.org/licenses/LICENSE-2.0 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | 10 | notifications: 11 | commits: commits@geode.apache.org 12 | issues: issues@geode.apache.org 13 | pullrequests: notifications@geode.apache.org 14 | jira_options: link label comment 15 | -------------------------------------------------------------------------------- /.github/workflows/gradle.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | name: develop 19 | 20 | on: 21 | push: 22 | branches: [ "develop" ] 23 | pull_request: 24 | branches: [ "develop" ] 25 | 26 | permissions: 27 | contents: read 28 | 29 | jobs: 30 | runAll: 31 | strategy: 32 | fail-fast: false 33 | matrix: 34 | os: [ubuntu-latest] 35 | distribution: ['liberica'] 36 | runs-on: ${{ matrix.os }} 37 | steps: 38 | - uses: actions/checkout@v3 39 | - name: Set up JDK 40 | uses: actions/setup-java@v3 41 | with: 42 | distribution: ${{ matrix.distribution }} 43 | java-version: '8' 44 | - name: Run All 45 | uses: gradle/gradle-build-action@v2 46 | with: 47 | arguments: runAll --console=plain --no-daemon -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # This file should contain patterns all developers want to ignore 2 | # If you have workspace specific files, add them 3 | # to .git/info/exclude. 4 | # 5 | # see git help gitignore for more details 6 | build/ 7 | .idea/ 8 | .gradle/ 9 | .classpath 10 | .project 11 | .settings/ 12 | .idea/ 13 | build-eclipse/ 14 | /tags 15 | out/ 16 | 17 | locator 18 | locator1 19 | l1 20 | server 21 | *server1 22 | *server2 23 | 24 | *.iml 25 | *.ipr 26 | *.iws 27 | *.swp 28 | *.log 29 | *.patch 30 | *.diff 31 | *.dat 32 | *.rej 33 | *.orig 34 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Apache Geode Examples 2 | Copyright 2017-2022 The Apache Software Foundation. 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | -------------------------------------------------------------------------------- /async/README.md: -------------------------------------------------------------------------------- 1 | 17 | 18 | # Geode Asynchronous Event Queues & Listeners Example 19 | 20 | This is a simple example that demonstrates asynchronous event queues and listeners. 21 | 22 | An asynchronous event queue is an ordered collection of events that occurred on a region, e.g., create a new entry, update an existing entry. An asynchronous event listener has its method invoked from time to time with batches of events that have occurred previously. The method invocation occurs inside the JVM of the server and can _not_ affect the operation on the region. 23 | 24 | In this example, an asynchronous event queue is created for the region of incoming words. An asynchronous event listener is specified for that asynchronous event queue. Whenever the `processEvents` method is invoked on the listener, it uses the Levenshtein distance for each word to perform simplistic spell-checking. The proposed revision is the put in the outgoing region. A cache listener is installed that captures all of the creation events for the outgoing region and displays the proposal on the terminal. In other applications, the asynchronous event listener could perform some other calculation on the data. 25 | 26 | This example assumes you have installed Java and Geode. 27 | 28 | ## Steps 29 | 30 | 1. From the `geode-examples/async` directory, build the example, and 31 | run unit tests. 32 | 33 | $ ../gradlew build 34 | 35 | 2. Next start a locator, start two servers, create two regions, and deploy the asynchronous event listener. 36 | 37 | $ gfsh run --file=scripts/start.gfsh 38 | 39 | 3. Run the example to put entries into the incoming region and get entries from the outgoing region. 40 | 41 | $ ../gradlew run 42 | 43 | 4. Notice the output. 44 | 45 | that -> that 46 | teh -> the 47 | wil -> will 48 | i -> I 49 | 50 | 5. Shut down the system. 51 | 52 | $ gfsh run --file=scripts/stop.gfsh 53 | -------------------------------------------------------------------------------- /async/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | start locator --name=locator --bind-address=127.0.0.1 19 | 20 | start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 21 | start server --name=server2 --locators=127.0.0.1[10334] --server-port=0 22 | 23 | deploy --jar=build/libs/async.jar 24 | list functions 25 | 26 | create async-event-queue --id=example-async-event-queue \ 27 | --parallel=false \ 28 | --enable-batch-conflation=false \ 29 | --batch-size=1 \ 30 | --batch-time-interval=0 \ 31 | --listener=org.apache.geode_examples.async.ExampleAsyncEventListener 32 | list async-event-queues 33 | 34 | create region --name=incoming-region --type=REPLICATE --async-event-queue-id=example-async-event-queue 35 | create region --name=outgoing-region --type=REPLICATE 36 | 37 | list members 38 | describe region --name=incoming-region 39 | describe region --name=outgoing-region 40 | -------------------------------------------------------------------------------- /async/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | connect --locator=127.0.0.1[10334] 19 | undeploy --jar=build/libs/async.jar 20 | shutdown --include-locators=true 21 | -------------------------------------------------------------------------------- /async/src/main/java/org/apache/geode_examples/async/LevenshteinDistance.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.async; 16 | 17 | /** 18 | * The Levenshtein distance is a measure of the difference between two strings of characters. It can 19 | * be useful in determining when two strings are very much alike, e.g., a transposed character. 20 | * While not as powerful as other techniques, one use is simple spell-checking. 21 | */ 22 | public class LevenshteinDistance { 23 | public int calculate(String first, String second) { 24 | if (first == null || first.isEmpty()) 25 | return (second == null ? 0 : second.length()); 26 | if (second == null || second.isEmpty()) 27 | return (first == null ? 0 : first.length()); 28 | 29 | final String firstPrime = first.substring(0, first.length() - 1); 30 | final String secondPrime = second.substring(0, second.length() - 1); 31 | final int cost = 32 | ((first.charAt(first.length() - 1) == second.charAt(second.length() - 1)) ? 0 : 1); 33 | return Math.min(Math.min(calculate(firstPrime, second) + 1, calculate(first, secondPrime) + 1), 34 | calculate(firstPrime, secondPrime) + cost); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /async/src/test/java/org/apache/geode/examples/async/ExampleTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.async; 16 | 17 | import static org.mockito.ArgumentMatchers.eq; 18 | import static org.mockito.Mockito.mock; 19 | import static org.mockito.Mockito.verify; 20 | import static org.mockito.Mockito.when; 21 | 22 | import java.util.Arrays; 23 | import java.util.List; 24 | 25 | import org.apache.geode.cache.Region; 26 | 27 | import org.junit.Test; 28 | 29 | public class ExampleTest { 30 | @Test 31 | public void testExample() throws Exception { 32 | Example example = new Example(); 33 | 34 | Region outgoingRegion = mock(Region.class); 35 | Region incomingRegion = mock(Region.class); 36 | 37 | final List words = Arrays.asList(new String[] {"that", "teh"}); 38 | when(outgoingRegion.sizeOnServer()).thenReturn(words.size()); 39 | example.checkWords(incomingRegion, outgoingRegion, words); 40 | 41 | verify(incomingRegion).put(eq(0), eq(words.get(0))); 42 | verify(incomingRegion).put(eq(1), eq(words.get(1))); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /async/src/test/java/org/apache/geode/examples/async/LevenshteinDistanceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.async; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | import org.junit.Test; 20 | 21 | public class LevenshteinDistanceTest { 22 | @Test 23 | public void testCalculate() throws Exception { 24 | LevenshteinDistance distance = new LevenshteinDistance(); 25 | assertEquals(0, distance.calculate(null, null)); 26 | assertEquals(0, distance.calculate(null, "")); 27 | assertEquals(0, distance.calculate("", null)); 28 | assertEquals(0, distance.calculate("", "")); 29 | assertEquals(3, distance.calculate(null, "foo")); 30 | assertEquals(3, distance.calculate("foo", null)); 31 | assertEquals(3, distance.calculate("", "foo")); 32 | assertEquals(3, distance.calculate("foo", "")); 33 | assertEquals(3, distance.calculate("foo", "bar")); 34 | assertEquals(2, distance.calculate("foo", "ofo")); 35 | assertEquals(2, distance.calculate("foo", "oof")); 36 | assertEquals(1, distance.calculate("the", "th")); 37 | assertEquals(1, distance.calculate("the", "he")); 38 | assertEquals(2, distance.calculate("the", "teh")); 39 | assertEquals(2, distance.calculate("project", "porject")); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /buildSrc/src/main/groovy/org/apache/geode/gradle/PasswordDialog.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | import groovy.swing.SwingBuilder 18 | class PasswordDialog { 19 | static String askPassword(String prompt) { 20 | def password = '' 21 | new SwingBuilder().edt { 22 | dialog(modal: true, 23 | title: 'Password', 24 | alwaysOnTop: true, 25 | locationRelativeTo: null, 26 | pack: true, 27 | show: true 28 | ) { 29 | vbox { 30 | label(text: prompt) 31 | input = passwordField() 32 | button(defaultButton: true, text: 'OK', actionPerformed: { 33 | password = input.password.toString(); // Set pass variable to value of input field 34 | dispose(); // Close dialog 35 | }) 36 | } 37 | } 38 | } 39 | return password 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /clientSecurity/example_security.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more contributor license 2 | # agreements. See the NOTICE file distributed with this work for additional information regarding 3 | # copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 4 | # "License"); you may not use this file except in compliance with the License. You may obtain a 5 | # copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License 10 | # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | # or implied. See the License for the specific language governing permissions and limitations under 12 | # the License. 13 | 14 | security-manager = org.apache.geode.examples.security.ExampleSecurityManager 15 | security-json = example_security.json 16 | 17 | ssl-enabled-components=all 18 | ssl-keystore=./../keystore.jks 19 | ssl-keystore-password=password 20 | ssl-truststore=./../truststore.jks 21 | ssl-truststore-password=password -------------------------------------------------------------------------------- /clientSecurity/keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/geode-examples/56b3a1f09c53aeef8988b34b1c9d4355e656e1a7/clientSecurity/keystore.jks -------------------------------------------------------------------------------- /clientSecurity/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | # Start a locator. 19 | # The security properties file specifies the ExampleSecurityManager to be the security manager. 20 | # This requires that the example_security.json be on the classpath. 21 | # Recall that the --classpath option is specified relative to the locator's working directory. 22 | 23 | start locator --name=locator --bind-address=127.0.0.1 --connect=false\ 24 | --security-properties-file=example_security.properties --classpath=../build/resources/main/ 25 | 26 | # Now we may start our cluster. 27 | # Servers also require security properties to be set and a copy of the security JSON 28 | # We use `--server-port=0` to use a random available port. 29 | # Note that we can start a server with any user with CLUSTER:MANAGE permissions 30 | 31 | start server --name=server1 --locators=127.0.0.1[10334]\ 32 | --classpath=../build/resources/main/:../build/classes/java/main/\ 33 | --security-properties-file=./example_security.properties --server-port=0\ 34 | --user=superUser --password=123 35 | 36 | start server --name=server2 --locators=127.0.0.1[10334]\ 37 | --classpath=../build/resources/main/:../build/classes/java/main/\ 38 | --security-properties-file=./example_security.properties --server-port=0\ 39 | --user=superUser --password=123 40 | 41 | # To execute any online commands, we need to connect to the locator 42 | # To create a region, we can connect as any user with CLUSTER:MANAGE 43 | 44 | connect --user=superUser --password=123 --use-ssl=true \ 45 | --key-store=keystore.jks --key-store-password=password \ 46 | --trust-store=truststore.jks --trust-store-password=password 47 | 48 | create region --name=region1 --type=REPLICATE 49 | create region --name=region2 --type=PARTITION 50 | -------------------------------------------------------------------------------- /clientSecurity/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | connect --locator=127.0.0.1[10334] --user=superUser --password=123 --use-ssl=true \ 18 | --key-store=./keystore.jks --key-store-password=password \ 19 | --trust-store=./truststore.jks --trust-store-password=password 20 | shutdown --include-locators=true 21 | -------------------------------------------------------------------------------- /clientSecurity/src/main/resources/example_security.json: -------------------------------------------------------------------------------- 1 | { 2 | "roles": [ 3 | { 4 | "name": "data", 5 | "operationsAllowed": [ 6 | "DATA:MANAGE", 7 | "DATA:WRITE", 8 | "DATA:READ" 9 | ] 10 | }, 11 | { 12 | "name": "cluster", 13 | "operationsAllowed": [ 14 | "CLUSTER:MANAGE", 15 | "CLUSTER:WRITE", 16 | "CLUSTER:READ" 17 | ] 18 | }, 19 | { 20 | "name": "region1data", 21 | "operationsAllowed": [ 22 | "DATA:MANAGE", 23 | "DATA:WRITE", 24 | "DATA:READ" 25 | ], 26 | "regions": ["region1"] 27 | }, 28 | { 29 | "name": "dataReader", 30 | "operationsAllowed": [ 31 | "DATA:READ" 32 | ] 33 | }, 34 | { 35 | "name": "dataWriter", 36 | "operationsAllowed": [ 37 | "DATA:WRITE" 38 | ] 39 | } 40 | ], 41 | "users": [ 42 | { 43 | "name": "superUser", 44 | "password": "123", 45 | "roles": [ 46 | "cluster", 47 | "data" 48 | ] 49 | }, 50 | { 51 | "name": "region1dataAdmin", 52 | "password": "123", 53 | "roles": [ 54 | "region1data" 55 | ] 56 | }, 57 | { 58 | "name": "dataReader", 59 | "password": "123", 60 | "roles": [ 61 | "dataReader" 62 | ] 63 | }, 64 | { 65 | "name": "dataWriter", 66 | "password": "123", 67 | "roles": [ 68 | "dataWriter" 69 | ] 70 | } 71 | ] 72 | } 73 | -------------------------------------------------------------------------------- /clientSecurity/truststore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/geode-examples/56b3a1f09c53aeef8988b34b1c9d4355e656e1a7/clientSecurity/truststore.jks -------------------------------------------------------------------------------- /colocation/README.md: -------------------------------------------------------------------------------- 1 | 17 | 18 | # Geode colocation example 19 | 20 | This is a simple example that illustrates how to colocate the data of two regions. 21 | 22 | By default, Geode selects the data locations for a partitioned region independent of the data locations for any other partitioned region using a hashing policy on the key. This example shows how to modify this policy in order to store related data from two regions (`order`and `customer`) in the same member. 23 | 24 | `customer` region stores `Customer` objects using an `int` as key: 25 | 26 | ``` 27 | Region customerRegion 28 | ``` 29 | 30 | `order` region stores `Order` object using an `OrderKey` object as key: 31 | 32 | ``` 33 | Region accountRegion 34 | ``` 35 | In order to store `Order` objects in the same member than their related customer info, a custom partition-resolved is needed: `OrderPartitionResolved`. When this partition resolver receives an `OrderKey` object, it returns the same key (the customer id) that was used to store the related customer. In this way, Geode applies the hashing policy over the same key for `Order`and `Customer` related objects and as a consequence, they are stored in the same member. 36 | 37 | ## Steps 38 | 39 | 1. From the `geode-examples/colocation` directory, build the example. 40 | 41 | $ ../gradlew build 42 | 43 | 2. Next start a locator, start two servers, create `customer` region, and create `order`region colocated with `customer` region. 44 | 45 | $ ../gradlew start 46 | 47 | 3. Run the example to put entries into both regions. 48 | 49 | $ ../gradlew run 50 | 51 | 4. Shut down the system. 52 | 53 | $ ../gradlew stop 54 | -------------------------------------------------------------------------------- /colocation/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | start locator --name=locator --bind-address=127.0.0.1 19 | 20 | start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/classes/java/main 21 | start server --name=server2 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/classes/java/main 22 | 23 | create region --name=customer --type=PARTITION 24 | create region --name=order --type=PARTITION --colocated-with=/customer \ 25 | --partition-resolver=org.apache.geode_examples.colocation.OrderPartitionResolver 26 | 27 | list members 28 | describe region --name=customer 29 | describe region --name=order 30 | 31 | -------------------------------------------------------------------------------- /colocation/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | connect --locator=127.0.0.1[10334] 19 | shutdown --include-locators=true 20 | -------------------------------------------------------------------------------- /colocation/src/main/java/org/apache/geode_examples/colocation/Customer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.colocation; 16 | 17 | import java.io.Serializable; 18 | 19 | public class Customer implements Serializable { 20 | 21 | private static final long serialVersionUID = 95541179L; 22 | 23 | private int id; 24 | private String firstName; 25 | private String lastName; 26 | private String email; 27 | 28 | public Customer() {} 29 | 30 | public Customer(int id, String firstName, String lastName, String email) { 31 | this.id = id; 32 | this.firstName = firstName; 33 | this.lastName = lastName; 34 | this.email = email; 35 | } 36 | 37 | public int getId() { 38 | return id; 39 | } 40 | 41 | public String getFirstName() { 42 | return firstName; 43 | } 44 | 45 | public String getLastName() { 46 | return lastName; 47 | } 48 | 49 | public String getEmail() { 50 | return email; 51 | } 52 | 53 | public String toString() { 54 | return "Customer [id=" + id + "firstName=" + firstName + ", lastName=" + lastName + ", email=" 55 | + email + "]"; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /colocation/src/main/java/org/apache/geode_examples/colocation/Order.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.colocation; 16 | 17 | import java.io.Serializable; 18 | 19 | public class Order implements Serializable { 20 | 21 | private static final long serialVersionUID = 41372560L; 22 | 23 | private OrderKey key; 24 | 25 | public Order() {} 26 | 27 | public Order(int orderId, int customerId) { 28 | this.key = new OrderKey(orderId, customerId); 29 | } 30 | 31 | public OrderKey getKey() { 32 | return key; 33 | } 34 | 35 | public int getOrderId() { 36 | return this.getKey().getOrderId(); 37 | } 38 | 39 | public int getCustomerId() { 40 | return this.getKey().getCustomerId(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /colocation/src/main/java/org/apache/geode_examples/colocation/OrderKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.colocation; 16 | 17 | import java.io.Serializable; 18 | 19 | public class OrderKey implements Serializable { 20 | private static final long serialVersionUID = 60372860L; 21 | 22 | private Integer customerId; 23 | private Integer orderId; 24 | 25 | public OrderKey() {} 26 | 27 | public OrderKey(Integer orderId, Integer customerId) { 28 | this.orderId = orderId; 29 | this.customerId = customerId; 30 | } 31 | 32 | public Integer getCustomerId() { 33 | return customerId; 34 | } 35 | 36 | public Integer getOrderId() { 37 | return orderId; 38 | } 39 | 40 | @Override 41 | public int hashCode() { 42 | int result = orderId.hashCode(); 43 | result = 31 * result + customerId; 44 | return result; 45 | } 46 | 47 | @Override 48 | public boolean equals(Object obj) { 49 | if (this == obj) 50 | return true; 51 | if (obj == null) 52 | return false; 53 | if (getClass() != obj.getClass()) 54 | return false; 55 | OrderKey other = (OrderKey) obj; 56 | if (!orderId.equals(other.getOrderId())) 57 | return false; 58 | if (!customerId.equals(other.getCustomerId())) 59 | return false; 60 | return true; 61 | } 62 | 63 | @Override 64 | public String toString() { 65 | return "OrderKey [orderId=" + orderId + ", customerId=" + customerId + "]"; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /colocation/src/main/java/org/apache/geode_examples/colocation/OrderPartitionResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.colocation; 16 | 17 | import org.apache.geode.cache.EntryOperation; 18 | import org.apache.geode.cache.PartitionResolver; 19 | 20 | public class OrderPartitionResolver implements PartitionResolver { 21 | 22 | @Override 23 | public Object getRoutingObject(EntryOperation opDetails) { 24 | OrderKey key = (OrderKey) opDetails.getKey(); 25 | return key.getCustomerId(); 26 | } 27 | 28 | @Override 29 | public String getName() { 30 | return getClass().getName(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /compression/README.md: -------------------------------------------------------------------------------- 1 | 17 | 18 | # Geode Compression example 19 | 20 | This is a simple example that demonstrates enabling Compression in a 21 | replicated region. The Default compression algorithm included with Geode is Snappy. Additionally, you can specify your own compressor algorithm as well by implementing `org.apache.geode.compression.Compression` Interface. For enabling compression on a Geode region you can follow the official [document](https://geode.apache.org/docs/guide/113/managing/region_compression.html#topic_inm_whc_gl). 22 | 23 | This example assumes you have installed Java and Geode. 24 | 25 | ## Steps 26 | 27 | 1. From the `geode-examples/compression` directory, build the example and 28 | run unit tests 29 | 30 | $ ../gradlew build 31 | 32 | 2. Next start the locator, two servers and create replicated region `example-region` with `compression` enabled. 33 | 34 | $ gfsh run --file=scripts/start.gfsh 35 | 36 | 3. Run the example to create and get entries using Geode Java Client from the region 37 | 38 | $ ../gradlew run 39 | 40 | 4. Shut down the system: 41 | 42 | $ gfsh run --file=scripts/stop.gfsh 43 | -------------------------------------------------------------------------------- /compression/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | start locator --name=locator --bind-address=127.0.0.1 18 | 19 | start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 20 | start server --name=server2 --locators=127.0.0.1[10334] --server-port=0 21 | 22 | create region --name=example-region --type=REPLICATE --compressor=org.apache.geode.compression.SnappyCompressor 23 | 24 | list members 25 | describe region --name=example-region 26 | -------------------------------------------------------------------------------- /compression/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | connect --locator=127.0.0.1[10334] 18 | shutdown --include-locators=true -------------------------------------------------------------------------------- /compression/src/main/java/org/apache/geode_examples/compression/Example.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.compression; 16 | 17 | import java.util.HashSet; 18 | import java.util.Set; 19 | import java.util.stream.IntStream; 20 | 21 | import org.apache.geode.cache.Region; 22 | import org.apache.geode.cache.client.*; 23 | 24 | public class Example { 25 | private final Region region; 26 | private static final String POOL_NAME = "client-pool"; 27 | 28 | public Example(Region region) { 29 | this.region = region; 30 | } 31 | 32 | public static void main(String[] args) { 33 | ClientCache cache = new ClientCacheFactory().set("log-level", "WARN").create(); 34 | // connect to the locator using default port 10334 35 | PoolFactory poolFactory = PoolManager.createFactory(); 36 | poolFactory.addLocator("127.0.0.1", 10334); 37 | poolFactory.create(POOL_NAME); 38 | 39 | // create a local region that matches the server region 40 | Region region = 41 | cache.createClientRegionFactory(ClientRegionShortcut.PROXY) 42 | .setPoolName(POOL_NAME).create("example-region"); 43 | 44 | Example example = new Example(region); 45 | example.putValues(10); 46 | example.printValues(example.getValues()); 47 | 48 | cache.close(); 49 | } 50 | 51 | Set getValues() { 52 | return new HashSet<>(region.keySetOnServer()); 53 | } 54 | 55 | void putValues(int upperLimit) { 56 | IntStream.rangeClosed(1, upperLimit).forEach(i -> region.put(i, "value" + i)); 57 | } 58 | 59 | void printValues(Set values) { 60 | values.forEach(key -> System.out.println(String.format("%d:%s", key, region.get(key)))); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /cq/README.md: -------------------------------------------------------------------------------- 1 | 17 | 18 | # Geode Continuous Query Example 19 | 20 | This is a simple example that demonstrates Apache Geode's Continuous Queries(CQs) feature. CQs allow clients to subscribe 21 | to server-side events using a SQL-like query. When a client registers a CQ, the client will receive all events that 22 | modify the query results. 23 | 24 | In this example, the client program will first register a CQ with the query 25 | `SELECT * FROM /example-region i where i > 70`. The region has keys and values that are both Integer types. 26 | 27 | The program loops, randomly generating two integers to put on the server as the key and value. 28 | 29 | If a value is either created or updated that is greater than 70, the above CQ will trigger the `RandomEventLister`, 30 | which prints to stdout. 31 | 32 | The client will generate data for 20 seconds, close the CQ and Cache, and then exit. 33 | 34 | This example assumes you have installed Java and Geode. 35 | 36 | ## Steps 37 | 38 | 1. From the `geode-examples/cq` directory, build the example. 39 | 40 | $ ../gradlew build 41 | 42 | 2. Next start a locator, start a server, and create a region. 43 | 44 | $ gfsh run --file=scripts/start.gfsh 45 | 46 | 3. Run the example to demonstrate continues queries. 47 | 48 | $ ../gradlew run 49 | 50 | 4. Shut down the server. 51 | 52 | $ gfsh run --file=scripts/stop.gfsh 53 | -------------------------------------------------------------------------------- /cq/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | start locator --name=locator --bind-address=127.0.0.1 19 | start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/classes/java/main 20 | start server --name=server2 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/classes/java/main 21 | list members 22 | 23 | create region --name=example-region --type=REPLICATE 24 | describe region --name=example-region 25 | -------------------------------------------------------------------------------- /cq/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | connect --locator=127.0.0.1[10334] 19 | shutdown --include-locators=true 20 | -------------------------------------------------------------------------------- /cq/src/main/java/org/apache/geode_examples/cq/RandomEventListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | 16 | package org.apache.geode_examples.cq; 17 | 18 | import org.apache.geode.cache.Operation; 19 | import org.apache.geode.cache.query.CqEvent; 20 | import org.apache.geode.cache.query.CqListener; 21 | 22 | public class RandomEventListener implements CqListener { 23 | 24 | @Override 25 | public void onEvent(CqEvent cqEvent) { 26 | 27 | Operation queryOperation = cqEvent.getQueryOperation(); 28 | 29 | 30 | if (queryOperation.isUpdate()) { 31 | System.out.print("-------Updated Value\n"); 32 | } else if (queryOperation.isCreate()) { 33 | System.out.print("-------Value Created\n"); 34 | } 35 | } 36 | 37 | @Override 38 | public void onError(CqEvent cqEvent) { 39 | System.out.print("**Something bad happened**"); 40 | } 41 | 42 | @Override 43 | public void close() { 44 | 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /durableMessaging/README.md: -------------------------------------------------------------------------------- 1 | 17 | 18 | # Geode Durable Messaging Example 19 | 20 | This example demonstrates Apache Geode's Durable Messaging feature. 21 | Use durable messaging for subscriptions that you need maintained for your clients even when your clients are down or disconnected. 22 | You can configure any of your event subscriptions as durable. Events for durable queries and subscriptions are saved in a queue when the client 23 | is disconnected and played back when the client reconnects. Other queries and subscriptions are removed from the queue. 24 | 25 | The example performs the following tasks to demonstrate durable messaging: 26 | 27 | 1. Create a client cache with durable messaging enabled 28 | 2. Register interest in all keys in the example region with durable messaging enabled 29 | 3. Close the client cache, simulating a disconnection 30 | 4. Start a second client, and do puts while the first client is down 31 | 5. Restart the first client, and observe that the create events in the durable queue are delivered. A simple cache listener is used to print output to the terminal as create events are received. If interested, see [Cache Listeners](listener/README.md) for more details on how cache listeners work. 32 | 33 | This example assumes you have installed Java and Geode. 34 | 35 | ## Steps 36 | 37 | 1. From the `geode-examples/durableMessaging` directory, build the example. 38 | 39 | $ ../gradlew build 40 | 41 | 2. Next start a locator, start a server, and create a region. 42 | 43 | $ gfsh run --file=scripts/start.gfsh 44 | 45 | 3. Run the example to demonstrate durable messaging. 46 | 47 | $ ../gradlew run 48 | 49 | 4. Shut down the server. 50 | 51 | $ gfsh run --file=scripts/stop.gfsh 52 | -------------------------------------------------------------------------------- /durableMessaging/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | start locator --name=locator --bind-address=127.0.0.1 18 | 19 | start server --name=server --locators=127.0.0.1[10334] --server-port=0 20 | 21 | list members 22 | 23 | create region --name=example-region --type=REPLICATE 24 | describe region --name=example-region 25 | -------------------------------------------------------------------------------- /durableMessaging/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | connect --locator=127.0.0.1[10334] 18 | shutdown --include-locators=true 19 | -------------------------------------------------------------------------------- /etc/eclipseOrganizeImports.importorder: -------------------------------------------------------------------------------- 1 | #Organize Import Order 2 | #Thu Sep 15 13:10:33 PDT 2016 3 | 5=com.gemstone 4 | 4=org.apache.geode 5 | 3= 6 | 2=javax 7 | 1=java 8 | 0=\# 9 | -------------------------------------------------------------------------------- /eviction/README.md: -------------------------------------------------------------------------------- 1 | 17 | 18 | # Geode Eviction Example 19 | 20 | This is a simple example that demonstrates eviction of entries from a region. This allows control 21 | over the system resources consumed by any given region. 22 | 23 | A region is a collection of entries which are tuples of key and value. Each entry requires memory 24 | for the key object, the value object, and some overhead. Regions that contain a large number of 25 | entries, entries of a large size, or both can consume enough system resources to impact overall 26 | system performance, even for other regions. 27 | 28 | A region can have eviction enabled to enforce an upper limit on either the total number of entries 29 | _or_ the total amount of memory consumed by the entries. The region will then enforce the specified 30 | limits on its in-memory resource consumption. When an operation would exceed those limits, the 31 | region will take an action to assure that the limits will not be exceeded after the operation 32 | completes. The region can either destroy one or more entries or overflow one or more entries to disk. 33 | 34 | This example assumes you have installed Java and Geode. 35 | 36 | ## Steps 37 | 38 | 1. From the `geode-examples/eviction` directory, build the example and 39 | run unit tests. 40 | 41 | $ ../gradlew build 42 | 43 | 2. Next start a locator, start a server, and create a region. 44 | 45 | $ gfsh run --file=scripts/start.gfsh 46 | 47 | 3. Run the example to demonstrate eviction. 48 | 49 | $ ../gradlew run 50 | 51 | 4. Shut down the system. 52 | 53 | $ gfsh run --file=scripts/stop.gfsh 54 | -------------------------------------------------------------------------------- /eviction/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | start locator --name=locator --bind-address=127.0.0.1 19 | start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/classes/java/main 20 | start server --name=server2 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/classes/java/main 21 | list members 22 | 23 | create region --name=example-region --type=REPLICATE --skip-if-exists=true \ 24 | --eviction-entry-count=10 --eviction-action=local-destroy 25 | describe region --name=example-region 26 | -------------------------------------------------------------------------------- /eviction/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | connect --locator=127.0.0.1[10334] 19 | shutdown --include-locators=true 20 | -------------------------------------------------------------------------------- /expiration/README.md: -------------------------------------------------------------------------------- 1 | 17 | 18 | # Geode Expiration Example 19 | 20 | This is a simple example that demonstrates expiration of entries from a region. This can be used to 21 | prevent stale entries from lingering in a region. This also allows control over the system resources 22 | consumed by any given region. 23 | 24 | A region is a collection of entries which are tuples of key and value. When statistics-gathering is 25 | enabled, the region maintains access and modification times for each entry. With entry expiration 26 | configured, the region will enforce time-to-live limits on entries. When the time since access or 27 | modification exceeds the configured duration, the region will take an action to expire the entry. 28 | The region can either destroy expired entries in their entirety or invalidate expired entries by 29 | removing their values. 30 | 31 | This example creates a region where the entries are destroyed after ten seconds without being 32 | updated. The example first puts ten random integers into the region. Then the example loops, 33 | printing the number of entries in the region, until the region is empty. 34 | 35 | This example assumes you have installed Java and Geode. 36 | 37 | ## Steps 38 | 39 | 1. From the `geode-examples/expiration` directory, build the example and 40 | run unit tests. 41 | 42 | $ ../gradlew build 43 | 44 | 2. Next start a locator, start a server, and create a region. 45 | 46 | $ gfsh run --file=scripts/start.gfsh 47 | 48 | 3. Run the example to demonstrate expiration. 49 | 50 | $ ../gradlew run 51 | 52 | 4. Shut down the system. 53 | 54 | $ gfsh run --file=scripts/stop.gfsh 55 | -------------------------------------------------------------------------------- /expiration/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | start locator --name=locator --bind-address=127.0.0.1 19 | start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/classes/java/main 20 | start server --name=server2 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/classes/java/main 21 | list members 22 | 23 | create region --name=example-region --type=REPLICATE --skip-if-exists=true \ 24 | --enable-statistics=true \ 25 | --entry-time-to-live-expiration=10 --entry-time-to-live-expiration-action=local-destroy 26 | describe region --name=example-region 27 | -------------------------------------------------------------------------------- /expiration/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | connect --locator=127.0.0.1[10334] 19 | shutdown --include-locators=true 20 | -------------------------------------------------------------------------------- /functions/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | start locator --name=locator --bind-address=127.0.0.1 19 | 20 | start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 21 | start server --name=server2 --locators=127.0.0.1[10334] --server-port=0 22 | 23 | create region --name=example-region --type=REPLICATE 24 | 25 | list members 26 | describe region --name=example-region 27 | 28 | deploy --jar=build/libs/functions.jar 29 | list functions 30 | -------------------------------------------------------------------------------- /functions/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | connect --locator=127.0.0.1[10334] 19 | shutdown --include-locators=true 20 | -------------------------------------------------------------------------------- /functions/src/main/java/org/apache/geode_examples/functions/PrimeNumber.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.functions; 16 | 17 | import java.util.ArrayList; 18 | import java.util.Collections; 19 | import java.util.List; 20 | import java.util.Set; 21 | 22 | import org.apache.geode.cache.Region; 23 | import org.apache.geode.cache.execute.Function; 24 | import org.apache.geode.cache.execute.FunctionContext; 25 | import org.apache.geode.cache.execute.RegionFunctionContext; 26 | 27 | public class PrimeNumber implements Function { 28 | public static final String ID = PrimeNumber.class.getSimpleName(); 29 | 30 | private boolean isPrime(int number) { 31 | int limit = (int) Math.floor(Math.sqrt(number)); 32 | for (int divisor = 2; divisor <= limit; ++divisor) { 33 | if (number % divisor == 0) { 34 | return false; 35 | } 36 | } 37 | return true; 38 | } 39 | 40 | @Override 41 | public String getId() { 42 | return ID; 43 | } 44 | 45 | @Override 46 | public void execute(FunctionContext context) { 47 | RegionFunctionContext regionContext = (RegionFunctionContext) context; 48 | Region region = regionContext.getDataSet(); 49 | 50 | List primes = new ArrayList<>(); 51 | Set keys = region.keySet(); 52 | for (Integer key : keys) { 53 | if (isPrime(key)) { 54 | primes.add(key); 55 | } 56 | } 57 | Collections.sort(primes); 58 | 59 | context.getResultSender().lastResult(primes); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /functions/src/test/java/org/apache/geode_examples/functions/ExampleTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.functions; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | import static org.mockito.Mockito.mock; 19 | import static org.mockito.Mockito.when; 20 | 21 | import java.util.Arrays; 22 | import java.util.HashSet; 23 | import java.util.List; 24 | 25 | import org.junit.Test; 26 | 27 | import org.apache.geode.cache.Region; 28 | import org.apache.geode.cache.execute.Execution; 29 | import org.apache.geode.cache.execute.ResultCollector; 30 | 31 | public class ExampleTest { 32 | @Test 33 | public void testExample() throws Exception { 34 | Example example = new Example(10); 35 | 36 | Region region = mock(Region.class); 37 | List primes = Arrays.asList(1, 2, 3, 5, 7); 38 | ResultCollector resultCollector = mock(ResultCollector.class); 39 | when(resultCollector.getResult()).thenReturn(primes); 40 | Execution execution = mock(Execution.class); 41 | when(execution.execute(PrimeNumber.ID)).thenReturn(resultCollector); 42 | 43 | assertEquals(new HashSet(primes), example.getPrimes(region, execution)); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | # Develop to use latest 1.15.1 artifacts until CI is rebuilt 19 | # GEODE-10436 20 | version = 1.15.1-build.0 21 | geodeVersion = 1.15.+ 22 | 23 | # release properties, set these on the command line to validate against 24 | # a release candidate 25 | geodeRepositoryUrl = 26 | geodeReleaseUrl = 27 | 28 | # dependency versions not found in geode-all-bom 29 | micrometerVersion = 1.2.1 30 | -------------------------------------------------------------------------------- /gradle/ide.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | subprojects { 18 | apply plugin: 'eclipse' 19 | eclipse { 20 | classpath { 21 | defaultOutputDir = file('build-eclipse') 22 | downloadSources = true 23 | file { 24 | whenMerged { classpath -> 25 | // Remove missing resource dirs 26 | classpath.entries.removeAll { entry -> (entry.path.contains('geode-examples/build/resources')) } 27 | } 28 | } 29 | } 30 | } 31 | 32 | apply plugin: 'idea' 33 | idea { 34 | module { downloadSources = true } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /gradle/rat.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | apply plugin: "org.nosphere.apache.rat" 18 | 19 | rat { 20 | excludes = [ 21 | // git 22 | '.git/**', 23 | '**/.gitignore', 24 | '**/.gitkeep', 25 | 26 | // gradle 27 | '**/.gradle/**', 28 | '**/gradlew', 29 | '**/gradlew.bat', 30 | '**/gradle/wrapper/gradle-wrapper.properties', 31 | 'caches/**', 32 | 'daemon/**', 33 | 'native/**', 34 | 'wrapper/**', 35 | '**/build/**', 36 | '.buildinfo', 37 | 38 | // IDE 39 | 'etc/eclipse-java-google-style.xml', 40 | 'etc/intellij-java-google-style.xml', 41 | 'etc/eclipseOrganizeImports.importorder', 42 | '**/.project', 43 | '**/.classpath', 44 | '**/.settings/**', 45 | '**/build-eclipse/**', 46 | '**/*.iml', 47 | '**/*.ipr', 48 | '**/*.iws', 49 | '**/.idea/**', 50 | '**/tags', 51 | 52 | // text files 53 | '**/*.log', 54 | '**/*.patch', 55 | '**/*.diff', 56 | '**/*.rej', 57 | '**/*.orig', 58 | '**/*.json', 59 | 60 | // image files 61 | '**/*.svg', 62 | 63 | // working directories 64 | '**/locator/**', 65 | '**/server/**', 66 | '**/server1/**', 67 | '**/server2/**', 68 | '**/locator-ln/**', 69 | '**/server-ln-1/**', 70 | '**/server-ln-2/**', 71 | '**/locator-ny/**', 72 | '**/server-ny-1/**', 73 | '**/server-ny-2/**', 74 | 75 | '**/META-INF/**' 76 | ] 77 | } 78 | 79 | subprojects { 80 | check.dependsOn rat 81 | } 82 | -------------------------------------------------------------------------------- /gradle/spotless.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | subprojects { 18 | apply plugin: "com.diffplug.gradle.spotless" 19 | spotless { 20 | lineEndings = 'unix'; 21 | java { 22 | target project.fileTree(project.projectDir) { include '**/*.java' } 23 | eclipseFormatFile "${rootProject.projectDir}/etc/eclipse-java-google-style.xml" 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jun 12 15:19:00 PDT 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip 7 | -------------------------------------------------------------------------------- /indexes/README.md: -------------------------------------------------------------------------------- 1 | 17 | 18 | # Geode OQL Indexing Example 19 | 20 | This example demonstrates an index for OQL 21 | [queries](https://geode.apache.org/docs/guide/11/developing/query_index/query_index.html) 22 | on a region. 23 | 24 | A region can contain objects of arbitrary complexity, including objects that contain other objects. 25 | The values of a region can be queried using 26 | [OQL](https://geode.apache.org/docs/guide/11/developing/querying_basics/chapter_overview.html) and 27 | OQL queries can reference fields in the objects in the region. Indexes can be created to improve 28 | the performance of queries. Certain optimizations occur for top-level fields but indexes can also be 29 | created for nested fields, i.e., fields of objects that are contained with the objects in the 30 | region. 31 | 32 | This example uses a mock database of passengers and flights stored in a single region. Since the 33 | region contains passenger objects, the index on passenger name uses a top-level field. 34 | Since flight code objects are contained within a passenger object, the index on airline code uses a 35 | nested field. After randomly populating the mock database, this example shows the results of queries 36 | that use no index, a top-level index, and a nested index. 37 | 38 | This example assumes that Java and Geode are installed. 39 | 40 | ## Steps 41 | 42 | 1. From the `geode-examples/indexes` directory, build the example and 43 | run unit tests. 44 | 45 | $ ../gradlew build 46 | 47 | 2. Next start the locator and two servers. 48 | 49 | $ gfsh run --file=scripts/start.gfsh 50 | 51 | 3. Run the example to create indexes in the region. 52 | 53 | $ ../gradlew run 54 | 55 | 4. Shut down the system. 56 | 57 | $ gfsh run --file=scripts/stop.gfsh 58 | -------------------------------------------------------------------------------- /indexes/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | start locator --name=locator --bind-address=127.0.0.1 19 | start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/classes/java/main 20 | start server --name=server2 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/classes/java/main 21 | list members 22 | 23 | create region --name=example-region --type=REPLICATE --skip-if-exists=true 24 | create index --name=topLevelIndex --expression=name --region=/example-region 25 | create index --name=nestedIndex --expression=flight.airlineCode --region=/example-region 26 | describe region --name=example-region 27 | -------------------------------------------------------------------------------- /indexes/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | connect --locator=127.0.0.1[10334] 19 | shutdown --include-locators=true 20 | -------------------------------------------------------------------------------- /indexes/src/main/java/org/apache/geode_examples/indexes/FlightCode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.indexes; 16 | 17 | import java.io.Serializable; 18 | 19 | public class FlightCode implements Serializable { 20 | private static final long serialVersionUID = -4252046061229265115L; 21 | 22 | String airlineCode; 23 | int flightNumber; 24 | String departure; 25 | String arrival; 26 | 27 | public FlightCode(String airlineCode, int flightNumber, String departure, String arrival) { 28 | this.airlineCode = airlineCode; 29 | this.flightNumber = flightNumber; 30 | this.departure = departure; 31 | this.arrival = arrival; 32 | } 33 | 34 | public String getAirlineCode() { 35 | return airlineCode; 36 | } 37 | 38 | public int getFlightNumber() { 39 | return flightNumber; 40 | } 41 | 42 | public String getDeparture() { 43 | return departure; 44 | } 45 | 46 | public String getArrival() { 47 | return arrival; 48 | } 49 | 50 | public String toString() { 51 | return getAirlineCode() + String.format("%03d", getFlightNumber()) + " from " + getDeparture() 52 | + " to " + getArrival(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /indexes/src/main/java/org/apache/geode_examples/indexes/Passenger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.indexes; 16 | 17 | import java.io.Serializable; 18 | import java.text.DateFormat; 19 | import java.text.SimpleDateFormat; 20 | import java.util.Date; 21 | 22 | public class Passenger implements Serializable { 23 | private static final long serialVersionUID = -991115968572408216L; 24 | static final DateFormat ISO_8601_TIMESTAMP_FORMAT = 25 | new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); 26 | 27 | String name; 28 | int age; 29 | FlightCode flight; 30 | Date departure; 31 | Date arrival; 32 | 33 | public Passenger(String name, int age, FlightCode flight, Date departure, Date arrival) { 34 | this.name = name; 35 | this.age = age; 36 | this.flight = flight; 37 | this.departure = departure; 38 | this.arrival = arrival; 39 | } 40 | 41 | public String getName() { 42 | return name; 43 | } 44 | 45 | public int getAge() { 46 | return age; 47 | } 48 | 49 | public FlightCode getFlight() { 50 | return flight; 51 | } 52 | 53 | public Date getDeparture() { 54 | return departure; 55 | } 56 | 57 | public Date getArrival() { 58 | return arrival; 59 | } 60 | 61 | public String toString() { 62 | return getName() + ", age " + getAge() + ", flight " + getFlight() + ", departing at " 63 | + ISO_8601_TIMESTAMP_FORMAT.format(getDeparture()) + ", arriving at " 64 | + ISO_8601_TIMESTAMP_FORMAT.format(getArrival()); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /jdbc/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | start locator --name=locator --bind-address=127.0.0.1 --include-system-classpath 19 | 20 | configure pdx --auto-serializable-classes=org.apache.geode_examples.jdbc.Parent 21 | 22 | start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 --include-system-classpath 23 | 24 | start server --name=server2 --locators=127.0.0.1[10334] --server-port=0 --include-system-classpath 25 | 26 | create region --name=Parent --type=REPLICATE 27 | 28 | list members 29 | 30 | describe region --name=Parent -------------------------------------------------------------------------------- /jdbc/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | connect --locator=127.0.0.1[10334] 19 | 20 | shutdown --include-locators=true -------------------------------------------------------------------------------- /jdbc/src/main/java/org/apache/geode_examples/jdbc/Parent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.jdbc; 16 | 17 | public class Parent { 18 | private Long id; 19 | private String name; 20 | private Double income; 21 | 22 | public Parent() {} 23 | 24 | public Parent(Long id, String name, Double income) { 25 | this.id = id; 26 | this.name = name; 27 | this.income = income; 28 | } 29 | 30 | public Long getId() { 31 | return this.id; 32 | } 33 | 34 | public String getName() { 35 | return this.name; 36 | } 37 | 38 | public Double getIncome() { 39 | return this.income; 40 | } 41 | 42 | public void setId(Long id) { 43 | this.id = id; 44 | } 45 | 46 | public void setName(String name) { 47 | this.name = name; 48 | } 49 | 50 | public void setIncome(Double income) { 51 | this.income = income; 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return "Parent [Id=" + id + ", name=" + name + ", income=" + income + "]"; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /listener/README.md: -------------------------------------------------------------------------------- 1 | 17 | 18 | # Geode Cache Listener Example 19 | 20 | This is a simple example that demonstrates the use of a cache listener to capture modifications to a region. 21 | 22 | A cache listener is added to a region when the region is created. _After_ an event (e.g., create a new entry, update an existing entry) occurs on that region, the cache listener has the appropriate handler method invoked, e.g., `afterCreate()` for creating a new entry. This method invocation can _not_ affect the operation on the region. 23 | 24 | In this example, a cache listener is installed that captures all of the creation events for the region. A number of entries are created in the region. The cache listener is notified of each creation and adds it to its queue of events. In other applications, the event could either be persisted to some other data store (i.e., write-behind) or a notification about the activity could be sent via some other mechanism. 25 | 26 | This example assumes you have installed Java and Geode. 27 | 28 | ## Steps 29 | 30 | 1. From the `geode-examples/listener` directory, build the example and 31 | run unit tests. 32 | 33 | $ ../gradlew build 34 | 35 | 2. Next start a locator, start a server, and create a region. 36 | 37 | $ gfsh run --file=scripts/start.gfsh 38 | 39 | 3. Run the example to add a cache listener, put entries into the region, and capture the events. 40 | 41 | $ ../gradlew run 42 | 43 | 4. Shut down the system. 44 | 45 | $ gfsh run --file=scripts/stop.gfsh 46 | -------------------------------------------------------------------------------- /listener/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | start locator --name=locator --bind-address=127.0.0.1 19 | start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/classes/java/main 20 | start server --name=server2 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/classes/java/main 21 | list members 22 | 23 | create region --name=example-region --type=REPLICATE --cache-listener=org.apache.geode_examples.listener.ExampleCacheListener 24 | describe region --name=example-region 25 | -------------------------------------------------------------------------------- /listener/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | connect --locator=127.0.0.1[10334] 19 | shutdown --include-locators=true 20 | -------------------------------------------------------------------------------- /listener/src/main/java/org/apache/geode_examples/listener/ExampleCacheListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.listener; 16 | 17 | import java.util.LinkedList; 18 | import java.util.Queue; 19 | 20 | import org.apache.geode.cache.CacheListener; 21 | import org.apache.geode.cache.EntryEvent; 22 | import org.apache.geode.cache.RegionEvent; 23 | import org.apache.geode.cache.util.CacheListenerAdapter; 24 | 25 | public class ExampleCacheListener extends CacheListenerAdapter { 26 | public ExampleCacheListener() {} 27 | 28 | @Override 29 | public void afterCreate(EntryEvent event) { 30 | System.out.println("received create for key " + event.getKey()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /listener/src/test/java/org/apache/geode/examples/listener/ExampleTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.listener; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | import org.junit.Test; 23 | 24 | public class ExampleTest { 25 | @Test 26 | public void testExample() throws Exception { 27 | Example example = new Example(); 28 | Map region = new HashMap<>(); 29 | example.putEntries(region); 30 | 31 | assertEquals(Example.ITERATIONS, region.size()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /loader/README.md: -------------------------------------------------------------------------------- 1 | 17 | 18 | # Geode cache loader example 19 | 20 | This is a simple example that demonstrates loading values using a 21 | `CacheLoader`. Invoking `Region.get()` causes the `CacheLoader` to 22 | produce a value that is stored in the region. This approach is 23 | commonly used to fetch data from other systems like a database. 24 | 25 | This example assumes you have installed Java and Geode. 26 | 27 | ## Steps 28 | 29 | 1. From the `geode-examples/loader` directory, build the example and 30 | run unit tests 31 | 32 | $ ../gradlew build 33 | 34 | 2. Next start the locator and two servers 35 | 36 | $ gfsh run --file=scripts/start.gfsh 37 | 38 | 3. Run the example to load the entries 39 | 40 | $ ../gradlew run 41 | 42 | The example fetches the entries twice. The first retrieval is slow, 43 | simulating a network call. Subsequent retrievals are much faster since the 44 | values are stored in the cache. The loader logs requests into the Geode 45 | server logs. You can find those at `build/server1/server1.log` or 46 | `build/server2/server2.log`. 47 | 48 | 4. Shut down the system: 49 | 50 | $ gfsh run --file=scripts/stop.gfsh 51 | -------------------------------------------------------------------------------- /loader/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | start locator --name=locator --bind-address=127.0.0.1 18 | 19 | start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/classes/java/main 20 | start server --name=server2 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/classes/java/main 21 | 22 | create region --name=example-region --type=REPLICATE --cache-loader=org.apache.geode_examples.loader.QuoteLoader 23 | 24 | list members 25 | describe region --name=example-region 26 | -------------------------------------------------------------------------------- /loader/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | connect --locator=127.0.0.1[10334] 18 | shutdown --include-locators=true -------------------------------------------------------------------------------- /loader/src/test/java/org/apache/geode/examples/loader/ExampleTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.loader; 16 | 17 | import static org.apache.geode_examples.loader.Example.printQuotes; 18 | import static org.assertj.core.api.Assertions.assertThat; 19 | import static org.mockito.ArgumentMatchers.any; 20 | import static org.mockito.Mockito.mock; 21 | import static org.mockito.Mockito.when; 22 | 23 | import java.util.HashMap; 24 | import java.util.Map; 25 | 26 | import org.apache.geode.cache.LoaderHelper; 27 | 28 | import org.junit.Rule; 29 | import org.junit.Test; 30 | import org.junit.contrib.java.lang.system.SystemOutRule; 31 | import org.mockito.Mockito; 32 | 33 | public class ExampleTest { 34 | 35 | @Rule 36 | public SystemOutRule systemOutRule = new SystemOutRule().enableLog(); 37 | 38 | @Test 39 | public void testExample() throws Exception { 40 | QuoteLoader loader = new QuoteLoader(); 41 | Map region = Mockito.spy(new HashMap<>()); 42 | 43 | when(region.get(any())).then(inv -> { 44 | String key = inv.getArgument(0); 45 | LoaderHelper helper = mock(LoaderHelper.class); 46 | when(helper.getKey()).thenReturn(key); 47 | 48 | return loader.load(helper); 49 | }); 50 | 51 | printQuotes(region); 52 | 53 | assertThat(systemOutRule.getLog()).contains("Anton Chekhov"); 54 | assertThat(systemOutRule.getLog()).contains("Loaded 20 definitions"); 55 | assertThat(systemOutRule.getLog()).contains("Fetched 20 cached definitions"); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /lucene/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | dependencies { 18 | compile "org.apache.geode:geode-lucene:$geodeVersion" 19 | } -------------------------------------------------------------------------------- /lucene/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | start locator --name=locator --bind-address=localhost 18 | 19 | start server --name=server1 --locators=localhost[10334] --server-port=0 --classpath=../build/classes/java/main --enable-time-statistics --statistic-archive-file=lucene1.gfs 20 | start server --name=server2 --locators=localhost[10334] --server-port=0 --classpath=../build/classes/java/main --enable-time-statistics --statistic-archive-file=lucene2.gfs 21 | 22 | ## simpleIndex uses default Lucene StandardAnalyzer 23 | create lucene index --name=simpleIndex --region=example-region --field=firstName,lastName 24 | 25 | ## analyzerIndex uses both the default StandardAnalyzer and the KeywordAnalyzer 26 | create lucene index --name=analyzerIndex --region=example-region --field=lastName,email --analyzer=DEFAULT,org.apache.lucene.analysis.core.KeywordAnalyzer 27 | 28 | ## nestedObjectIndex will index on nested objects or collection objects 29 | create lucene index --name=nestedObjectIndex --region=example-region --field=contacts.phoneNumbers --serializer=org.apache.geode.cache.lucene.FlatFormatSerializer 30 | 31 | create region --name=example-region --type=PARTITION --enable-statistics=true 32 | 33 | list members 34 | describe region --name=example-region 35 | 36 | -------------------------------------------------------------------------------- /lucene/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | connect --locator=127.0.0.1[10334] 18 | shutdown --include-locators=true -------------------------------------------------------------------------------- /lucene/src/main/java/org/apache/geode_examples/lucene/Contact.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.lucene; 16 | 17 | import java.io.Serializable; 18 | import java.util.Arrays; 19 | 20 | public class Contact implements Serializable { 21 | private String name; 22 | private String[] phoneNumbers; 23 | 24 | Contact(String name, String[] phoneNumbers) { 25 | this.name = name; 26 | this.phoneNumbers = phoneNumbers; 27 | } 28 | 29 | public String getName() { 30 | return this.name; 31 | } 32 | 33 | public String[] getPhones() { 34 | return this.phoneNumbers; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return "(name=" + name + ", phones=" + Arrays.toString(phoneNumbers) + ")"; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /lucene/src/main/java/org/apache/geode_examples/lucene/EmployeeData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.lucene; 16 | 17 | import java.io.Serializable; 18 | import java.util.Collection; 19 | 20 | public class EmployeeData implements Serializable { 21 | private static final long serialVersionUID = 1L; 22 | 23 | private String firstName; 24 | private String lastName; 25 | private int emplNumber; 26 | private String email; 27 | private int salary; 28 | private int hoursPerWeek; 29 | private Collection contacts; 30 | 31 | public EmployeeData(String firstName, String lastName, int emplNumber, String email, int salary, 32 | int hoursPerWeek, Collection contacts) { 33 | this.firstName = firstName; 34 | this.lastName = lastName; 35 | this.emplNumber = emplNumber; 36 | this.email = email; 37 | this.salary = salary; 38 | this.hoursPerWeek = hoursPerWeek; 39 | this.contacts = contacts; 40 | } 41 | 42 | public String getFirstName() { 43 | return firstName; 44 | } 45 | 46 | public String getLastName() { 47 | return lastName; 48 | } 49 | 50 | public int getEmplNumber() { 51 | return emplNumber; 52 | } 53 | 54 | public String getEmail() { 55 | return email; 56 | } 57 | 58 | public int getSalary() { 59 | return salary; 60 | } 61 | 62 | public int getHoursPerWeek() { 63 | return hoursPerWeek; 64 | } 65 | 66 | public Collection getContacts() { 67 | return this.contacts; 68 | } 69 | 70 | @Override 71 | public String toString() { 72 | return "EmployeeData [firstName=" + firstName + ", lastName=" + lastName + ", emplNumber=" 73 | + emplNumber + ", email= " + email + ", salary=" + salary + ", hoursPerWeek=" + hoursPerWeek 74 | + ", contacts=" + contacts + "]"; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /lucene/src/test/java/org/apache/geode/examples/lucene/ExampleTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.lucene; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | import org.junit.Test; 23 | 24 | public class ExampleTest { 25 | 26 | @Test 27 | public void testInsertEntries() throws Exception { 28 | Map region = new HashMap<>(); 29 | Example.insertValues(region); 30 | 31 | assertEquals(10, region.size()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /luceneSpatial/README.md: -------------------------------------------------------------------------------- 1 | 17 | 18 | # Geode Lucene Spatial Indexing Example 19 | 20 | This examples demonstrates how to use Geode's LuceneSerializer and LuceneQueryProvider APIs 21 | to customize how Geode data is stored and indexed in Lucene. 22 | 23 | In this example two servers host a partitioned region that stores train station stop information, 24 | including GPS coordinates. The region has lucene index that allows spatial queries to be performed 25 | against the data. The example shows how to do a spatial query to find nearby train stations. 26 | 27 | This example assumes that Java and Geode are installed. 28 | 29 | ## Set up the Lucene index and region 30 | 1. Set directory ```geode-examples/luceneSpatial``` to be the 31 | current working directory. 32 | Each step in this example specifies paths relative to that directory. 33 | 34 | 2. Build the example 35 | 36 | $ ../gradlew build 37 | 38 | 3. Run a script that starts a locator and two servers, creates a Lucene index 39 | called ```simpleIndex``` with a custom LuceneSerializer that indexes spatial data. The script 40 | then creates the ```example-region``` region. 41 | 42 | $ gfsh run --file=scripts/start.gfsh 43 | 44 | 4. Run the example. This program adds data to the example-region, and then looks 45 | for train stations with a 1 mile of a specific GPS coordinate. Look at Example.java to see 46 | what this program does. 47 | 48 | 49 | $ ../gradlew run 50 | 51 | 52 | 5. Shut down the cluster 53 | 54 | $ gfsh run --file=scripts/stop.gfsh 55 | 56 | 6. Clean up any generated directories and files so this example can be rerun. 57 | 58 | $ ../gradlew cleanServer 59 | 60 | -------------------------------------------------------------------------------- /luceneSpatial/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | dependencies { 18 | compile "org.apache.geode:geode-lucene:$geodeVersion" 19 | compile "org.apache.lucene:lucene-spatial-extras:6.4.1" 20 | } 21 | 22 | task copyDependencies(type:Copy) { 23 | into "$buildDir/libs" 24 | from configurations['runtime'] 25 | } 26 | 27 | build.dependsOn(copyDependencies) 28 | -------------------------------------------------------------------------------- /luceneSpatial/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | start locator --name=locator --bind-address=127.0.0.1 18 | 19 | set variable --name=STAR --value=* 20 | start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/libs/${STAR} --enable-time-statistics --statistic-archive-file=lucene1.gfs 21 | start server --name=server2 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/libs/${STAR} --enable-time-statistics --statistic-archive-file=lucene2.gfs 22 | 23 | ## Create a lucene index with our custom serializer 24 | create lucene index --name=simpleIndex --region=example-region --field=name --serializer=org.apache.geode_examples.luceneSpatial.TrainStopSerializer 25 | 26 | create region --name=example-region --type=PARTITION 27 | 28 | list members 29 | describe region --name=example-region 30 | -------------------------------------------------------------------------------- /luceneSpatial/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | connect --locator=127.0.0.1[10334] 18 | shutdown --include-locators=true -------------------------------------------------------------------------------- /luceneSpatial/src/main/java/org/apache/geode_examples/luceneSpatial/TrainStop.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.luceneSpatial; 16 | 17 | import java.io.Serializable; 18 | 19 | public class TrainStop implements Serializable { 20 | private static final long serialVersionUID = 1L; 21 | 22 | private String name; 23 | private double latitude; 24 | private double longitude; 25 | 26 | public TrainStop(String name, double longitude, double latitude) { 27 | this.name = name; 28 | this.longitude = longitude; 29 | this.latitude = latitude; 30 | } 31 | 32 | public String getName() { 33 | return name; 34 | } 35 | 36 | public double getLatitude() { 37 | return latitude; 38 | } 39 | 40 | public double getLongitude() { 41 | return longitude; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return "TrainStop [name=" + name + ", location=" + longitude + ", " + latitude + "]"; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /luceneSpatial/src/main/java/org/apache/geode_examples/luceneSpatial/TrainStopSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.luceneSpatial; 16 | 17 | import java.util.Collection; 18 | import java.util.Collections; 19 | 20 | import org.apache.lucene.document.Document; 21 | import org.apache.lucene.document.Field; 22 | import org.apache.lucene.document.TextField; 23 | import org.apache.lucene.spatial.vector.PointVectorStrategy; 24 | 25 | import org.apache.geode.cache.lucene.LuceneIndex; 26 | import org.apache.geode.cache.lucene.LuceneSerializer; 27 | 28 | /** 29 | * LuceneSerializer that converts train stops into lucene documents with the gps coordinates indexed 30 | * using lucene's {@link PointVectorStrategy} 31 | */ 32 | public class TrainStopSerializer implements LuceneSerializer { 33 | @Override 34 | public Collection toDocuments(LuceneIndex index, TrainStop value) { 35 | 36 | Document doc = new Document(); 37 | // Index the name of the train stop 38 | doc.add(new TextField("name", value.getName(), Field.Store.NO)); 39 | 40 | Field[] fields = SpatialHelper.getIndexableFields(value.getLongitude(), value.getLatitude()); 41 | 42 | for (Field field : fields) { 43 | doc.add(field); 44 | } 45 | 46 | return Collections.singleton(doc); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /luceneSpatial/src/test/java/org/apache/geode/examples/luceneSpatial/ExampleTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.luceneSpatial; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | import static org.mockito.Mockito.mock; 19 | 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | 23 | import org.junit.Test; 24 | 25 | import org.apache.geode.cache.lucene.LuceneService; 26 | 27 | public class ExampleTest { 28 | 29 | @Test 30 | public void testPutEntries() throws InterruptedException { 31 | LuceneService service = mock(LuceneService.class); 32 | Map region = new HashMap(); 33 | Example.putEntries(service, region); 34 | assertEquals(3, region.size()); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /luceneSpatial/src/test/java/org/apache/geode/examples/luceneSpatial/SpatialHelperTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.luceneSpatial; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | import java.io.IOException; 20 | 21 | import org.apache.lucene.document.Document; 22 | import org.apache.lucene.document.Field; 23 | import org.apache.lucene.document.TextField; 24 | import org.apache.lucene.index.IndexWriter; 25 | import org.apache.lucene.index.IndexWriterConfig; 26 | import org.apache.lucene.search.IndexSearcher; 27 | import org.apache.lucene.search.Query; 28 | import org.apache.lucene.search.SearcherManager; 29 | import org.apache.lucene.search.TopDocs; 30 | import org.apache.lucene.store.RAMDirectory; 31 | import org.junit.Test; 32 | 33 | public class SpatialHelperTest { 34 | 35 | @Test 36 | public void queryFindsADocumentThatWasAdded() throws IOException { 37 | 38 | // Create an in memory lucene index to add a document to 39 | RAMDirectory directory = new RAMDirectory(); 40 | IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig()); 41 | 42 | // Add a document to the lucene index 43 | Document document = new Document(); 44 | document.add(new TextField("name", "name", Field.Store.YES)); 45 | Field[] fields = SpatialHelper.getIndexableFields(-122.8515139, 45.5099231); 46 | for (Field field : fields) { 47 | document.add(field); 48 | } 49 | writer.addDocument(document); 50 | writer.commit(); 51 | 52 | 53 | // Make sure a findWithin query locates the document 54 | Query query = SpatialHelper.findWithin(-122.8515239, 45.5099331, 1); 55 | SearcherManager searcherManager = new SearcherManager(writer, null); 56 | IndexSearcher searcher = searcherManager.acquire(); 57 | TopDocs results = searcher.search(query, 100); 58 | assertEquals(1, results.totalHits); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /luceneSpatial/src/test/java/org/apache/geode/examples/luceneSpatial/TrainStopSerializerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.luceneSpatial; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | import java.util.Collection; 20 | 21 | import org.apache.lucene.document.Document; 22 | import org.junit.Test; 23 | 24 | public class TrainStopSerializerTest { 25 | 26 | @Test 27 | public void serializerReturnsSingleDocument() { 28 | TrainStopSerializer serializer = new TrainStopSerializer(); 29 | Collection documents = 30 | serializer.toDocuments(null, new TrainStop("here", -122.8515139, 45.5099231)); 31 | 32 | assertEquals(1, documents.size()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /micrometerMetrics/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | configurations { 19 | dependenciesToIncludeInEndpointJar 20 | } 21 | 22 | dependencies { 23 | dependenciesToIncludeInEndpointJar "io.micrometer:micrometer-registry-prometheus:$micrometerVersion" 24 | configurations.compile.extendsFrom(configurations.dependenciesToIncludeInEndpointJar) 25 | } 26 | 27 | jar { 28 | from { 29 | configurations.dependenciesToIncludeInEndpointJar.collect { it.isDirectory() ? it : zipTree(it) } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /micrometerMetrics/prometheus-graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/geode-examples/56b3a1f09c53aeef8988b34b1c9d4355e656e1a7/micrometerMetrics/prometheus-graph.png -------------------------------------------------------------------------------- /micrometerMetrics/prometheus-targets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/geode-examples/56b3a1f09c53aeef8988b34b1c9d4355e656e1a7/micrometerMetrics/prometheus-targets.png -------------------------------------------------------------------------------- /micrometerMetrics/prometheus.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more contributor license 2 | # agreements. See the NOTICE file distributed with this work for additional information regarding 3 | # copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 4 | # "License"); you may not use this file except in compliance with the License. You may obtain a 5 | # copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License 10 | # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | # or implied. See the License for the specific language governing permissions and limitations under 12 | # the License. 13 | 14 | global: 15 | scrape_interval: 2s 16 | scrape_configs: 17 | - job_name: 'geode-examples' 18 | metrics_path: / 19 | static_configs: 20 | - targets: ['localhost:9914'] 21 | - targets: ['localhost:9915'] 22 | -------------------------------------------------------------------------------- /micrometerMetrics/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | # ports 9914 and 9915 chosen at random 19 | 20 | start locator --name=locator --bind-address=127.0.0.1 --classpath=../build/libs/micrometerMetrics.jar --J=-Dprometheus.metrics.port=9914 21 | 22 | start server --name=server --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/libs/micrometerMetrics.jar --J=-Dprometheus.metrics.port=9915 23 | 24 | create region --name=example-region --type=REPLICATE 25 | -------------------------------------------------------------------------------- /micrometerMetrics/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | connect --locator=127.0.0.1[10334] 19 | shutdown --include-locators=true 20 | -------------------------------------------------------------------------------- /micrometerMetrics/src/main/resources/META-INF/services/org.apache.geode.metrics.MetricsPublishingService: -------------------------------------------------------------------------------- 1 | org.apache.geode_examples.micrometerMetrics.SimpleMetricsPublishingService -------------------------------------------------------------------------------- /overflow/README.md: -------------------------------------------------------------------------------- 1 | 17 | 18 | # Geode Overflow Example 19 | 20 | This examples demonstrates how to use Geode's Overflow to disk. 21 | 22 | In this example, a server hosts a partitioned region that stores strings. 23 | The example shows entry values being overflowed to disk and removed from memory. 24 | 25 | This example assumes that Geode is installed. 26 | 27 | ## Set up the region 28 | 1. Set directory ```geode-examples/overflow``` to be the 29 | current working directory. 30 | Each step in this example specifies paths relative to that directory. 31 | 32 | 2. Run a script that starts a locator and two servers. The script 33 | then creates the ```example-region``` region and puts 4 entries. 34 | 35 | $ gfsh run --file=scripts/start.gfsh 36 | 37 | Note that both the region size and `totalEntriesOnlyOnDisk` are 0 before we put any entries. 38 | 39 | 3. Shut down the cluster 40 | 41 | $ gfsh run --file=scripts/stop.gfsh 42 | 43 | 4. In the output of the second `show metrics --region=example-region` command, notice the line 44 | 45 | `diskstore | totalEntriesOnlyOnDisk | 2` 46 | 47 | This shows that 2 values have been overflowed to disk and are no longer in memory. 48 | Notice that the size from the second `describe region --name=example-region` 49 | is still 4 50 | 51 | `Region | size | 4` 52 | 53 | Because all the keys remain in memory. 54 | The entries are still accessible. 55 | 56 | 57 | -------------------------------------------------------------------------------- /overflow/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | start locator --name=locator --bind-address=127.0.0.1 18 | 19 | start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 20 | 21 | create region --name=example-region --type=PARTITION_OVERFLOW --eviction-entry-count=2 --eviction-action=overflow-to-disk 22 | 23 | list members 24 | describe region --name=example-region 25 | show metrics --region=example-region 26 | 27 | put --key=1 --value=one --region=example-region 28 | put --key=2 --value=two --region=example-region 29 | put --key=3 --value=three --region=example-region 30 | put --key=4 --value=four --region=example-region 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /overflow/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | connect --locator=127.0.0.1[10334] 18 | 19 | describe region --name=example-region 20 | show metrics --region=example-region 21 | 22 | shutdown --include-locators=true -------------------------------------------------------------------------------- /partitioned/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | start locator --name=locator --bind-address=127.0.0.1 18 | 19 | start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/classes/java/main 20 | start server --name=server2 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/classes/java/main 21 | 22 | create region --name=example-region --type=PARTITION 23 | 24 | list members 25 | describe region --name=example-region -------------------------------------------------------------------------------- /partitioned/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | connect --locator=127.0.0.1[10334] 18 | shutdown --include-locators=true -------------------------------------------------------------------------------- /partitioned/src/main/java/org/apache/geode_examples/partitioned/EmployeeData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.partitioned; 16 | 17 | import java.io.Serializable; 18 | 19 | public class EmployeeData implements Serializable { 20 | private static final long serialVersionUID = 2095541179L; 21 | private final EmployeeKey nameAndNumber; 22 | private final int salary; 23 | private final int hoursPerWeek; 24 | 25 | public EmployeeData(EmployeeKey nameAndNumber, int salary, int hoursPerWeek) { 26 | this.nameAndNumber = nameAndNumber; 27 | this.salary = salary; 28 | this.hoursPerWeek = hoursPerWeek; 29 | } 30 | 31 | public EmployeeKey getNameAndNumber() { 32 | return nameAndNumber; 33 | } 34 | 35 | public int getSalary() { 36 | return salary; 37 | } 38 | 39 | public int getHoursPerWeek() { 40 | return hoursPerWeek; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "EmployeeData [nameAndNumber=" + nameAndNumber + ", salary=" + salary + ", hoursPerWeek=" 46 | + hoursPerWeek + "]"; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /partitioned/src/main/java/org/apache/geode_examples/partitioned/EmployeeKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.partitioned; 16 | 17 | import java.io.Serializable; 18 | 19 | public class EmployeeKey implements Serializable { 20 | private static final long serialVersionUID = 160372860L; 21 | private final String name; 22 | private final int emplNumber; 23 | 24 | public EmployeeKey(String name, int emplNumber) { 25 | this.name = name; 26 | this.emplNumber = emplNumber; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public int getEmplNumber() { 34 | return emplNumber; 35 | } 36 | 37 | @Override 38 | public int hashCode() { 39 | int result = name.hashCode(); 40 | result = 31 * result + emplNumber; 41 | return result; 42 | } 43 | 44 | @Override 45 | public boolean equals(Object obj) { 46 | if (this == obj) 47 | return true; 48 | if (obj == null) 49 | return false; 50 | if (getClass() != obj.getClass()) 51 | return false; 52 | EmployeeKey other = (EmployeeKey) obj; 53 | if (emplNumber != other.emplNumber) 54 | return false; 55 | if (name == null) { 56 | if (other.name != null) 57 | return false; 58 | } else if (!name.equals(other.name)) 59 | return false; 60 | return true; 61 | } 62 | 63 | @Override 64 | public String toString() { 65 | return "EmployeeKey [name=" + name + ", emplNumber=" + emplNumber + "]"; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /persistence/README.md: -------------------------------------------------------------------------------- 1 | 17 | 18 | # Geode Persistence Example 19 | 20 | This is a simple example that demonstrates persistent regions. 21 | 22 | The data for a region resides in memory in the JVM for the server. When a region is persistent, the data for that region is also preserved in a disk store. The disk store uses a directory in a file system to save the operations on regions. Unlike non-persistent regions, the data for a persistent region is available even after a period where no servers for that region are running. 23 | 24 | This example assumes you have installed Java and Geode. 25 | 26 | ## Steps 27 | 28 | 1. From the `geode-examples/persistence` directory, build the example, and 29 | run unit tests. 30 | 31 | $ ../gradlew build 32 | 33 | 2. Next start a locator, start a server, create a disk store, and create a persistent region. 34 | 35 | $ gfsh run --file=scripts/start.gfsh 36 | 37 | 3. Run the example to increment an entry the region. 38 | 39 | $ ../gradlew run 40 | 41 | 4. Observe that the first time an initial value is used. 42 | 43 | Initialized counter to 0 44 | Incremented counter to 1 45 | 46 | 5. Restart down the server. 47 | 48 | $ gfsh run --file=scripts/restart.gfsh 49 | 50 | 6. Run the example to increment an entry the region. 51 | 52 | $ ../gradlew run 53 | 54 | 7. Observe that the second time the previous value is used. 55 | 56 | Retrieved counter of 1 57 | Incremented counter to 2 58 | 59 | 8. Shut down the system. 60 | 61 | $ gfsh run --file=scripts/stop.gfsh 62 | -------------------------------------------------------------------------------- /persistence/scripts/restart.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | connect --locator=127.0.0.1[10334] 19 | 20 | stop server --name=server1 21 | 22 | start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 23 | list members 24 | -------------------------------------------------------------------------------- /persistence/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | start locator --name=locator --bind-address=127.0.0.1 19 | 20 | start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 21 | list members 22 | 23 | create region --name=example-region --type=REPLICATE_PERSISTENT 24 | describe region --name=example-region 25 | -------------------------------------------------------------------------------- /persistence/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | connect --locator=127.0.0.1[10334] 19 | 20 | shutdown --include-locators=true 21 | -------------------------------------------------------------------------------- /persistence/src/main/java/org/apache/geode_examples/persistence/Example.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.persistence; 16 | 17 | import org.apache.geode.cache.Region; 18 | import org.apache.geode.cache.client.ClientCache; 19 | import org.apache.geode.cache.client.ClientCacheFactory; 20 | import org.apache.geode.cache.client.ClientRegionShortcut; 21 | 22 | public class Example { 23 | private static final String KEY = "counter"; 24 | private final Region region; 25 | 26 | public static void main(String[] args) { 27 | // connect to the locator using default port 10334 28 | ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334) 29 | .set("log-level", "WARN").create(); 30 | 31 | // create a local region that matches the server region 32 | Region region = 33 | cache.createClientRegionFactory(ClientRegionShortcut.PROXY) 34 | .create("example-region"); 35 | 36 | Example example = new Example(region); 37 | final int previous = example.getCounter(); 38 | example.increment(); 39 | final int current = example.getCounter(); 40 | System.out.println(previous + " -> " + current); 41 | 42 | cache.close(); 43 | } 44 | 45 | public Example(Region region) { 46 | this.region = region; 47 | if (!region.containsKeyOnServer(KEY)) { 48 | region.put(KEY, 0); 49 | } 50 | } 51 | 52 | public int getCounter() { 53 | return region.get(KEY); 54 | } 55 | 56 | public void increment() { 57 | region.put(KEY, region.get(KEY) + 1); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /putall/README.md: -------------------------------------------------------------------------------- 1 | 17 | 18 | # Geode Put Multiple Values at Once Example 19 | 20 | This is a simple example that demonstrates putting a map of values into a region, checking the size, and retrieving the values. 21 | 22 | This example assumes you have installed Java and Geode. 23 | 24 | ## Steps 25 | 26 | 1. From the `geode-examples/putall` directory, build the example and 27 | run unit tests. 28 | 29 | $ ../gradlew build 30 | 31 | 2. Next start a locator, start a server, and create a region. 32 | 33 | $ gfsh run --file=scripts/start.gfsh 34 | 35 | 3. Run the example to put entries into the region. 36 | 37 | $ ../gradlew run 38 | 39 | 4. Shut down the system. 40 | 41 | $ gfsh run --file=scripts/stop.gfsh 42 | -------------------------------------------------------------------------------- /putall/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | start locator --name=locator --bind-address=127.0.0.1 18 | 19 | start server --name=server --locators=127.0.0.1[10334] --server-port=0 20 | 21 | create region --name=example-region --type=REPLICATE 22 | 23 | list members 24 | describe region --name=example-region 25 | -------------------------------------------------------------------------------- /putall/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | connect --locator=127.0.0.1[10334] 18 | shutdown --include-locators=true 19 | -------------------------------------------------------------------------------- /putall/src/main/java/org/apache/geode_examples/putall/Example.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.putall; 16 | 17 | import java.util.HashMap; 18 | import java.util.HashSet; 19 | import java.util.Map; 20 | import java.util.Set; 21 | import java.util.stream.IntStream; 22 | 23 | import org.apache.geode.cache.Region; 24 | import org.apache.geode.cache.client.ClientCache; 25 | import org.apache.geode.cache.client.ClientCacheFactory; 26 | import org.apache.geode.cache.client.ClientRegionShortcut; 27 | 28 | public class Example { 29 | private final Region region; 30 | 31 | public Example(Region region) { 32 | this.region = region; 33 | } 34 | 35 | public static void main(String[] args) { 36 | // connect to the locator using default port 10334 37 | ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334) 38 | .set("log-level", "WARN").create(); 39 | 40 | // create a local region that matches the server region 41 | Region region = 42 | cache.createClientRegionFactory(ClientRegionShortcut.PROXY) 43 | .create("example-region"); 44 | 45 | Example example = new Example(region); 46 | example.insertValues(10); 47 | example.printValues(example.getValues()); 48 | 49 | cache.close(); 50 | } 51 | 52 | Set getValues() { 53 | return new HashSet<>(region.keySetOnServer()); 54 | } 55 | 56 | void insertValues(int upperLimit) { 57 | Map values = new HashMap(); 58 | IntStream.rangeClosed(1, upperLimit).forEach(i -> values.put(i, "value" + i)); 59 | region.putAll(values); 60 | } 61 | 62 | void printValues(Set values) { 63 | values.forEach(key -> System.out.println(String.format("%d:%s", key, region.get(key)))); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /queries/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | start locator --name=locator --bind-address=127.0.0.1 18 | 19 | start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/classes/java/main 20 | start server --name=server2 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/classes/java/main 21 | 22 | create region --name=example-region --type=PARTITION 23 | 24 | list members 25 | describe region --name=example-region 26 | -------------------------------------------------------------------------------- /queries/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | connect --locator=127.0.0.1[10334] 18 | shutdown --include-locators=true -------------------------------------------------------------------------------- /queries/src/main/java/org/apache/geode_examples/queries/EmployeeData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.queries; 16 | 17 | import java.io.Serializable; 18 | 19 | public class EmployeeData implements Serializable { 20 | private static final long serialVersionUID = 1L; 21 | 22 | private String firstName; 23 | private String lastName; 24 | private int emplNumber; 25 | private String email; 26 | private int salary; 27 | private int hoursPerWeek; 28 | 29 | public EmployeeData(String firstName, String lastName, int emplNumber, String email, int salary, 30 | int hoursPerWeek) { 31 | this.firstName = firstName; 32 | this.lastName = lastName; 33 | this.emplNumber = emplNumber; 34 | this.email = email; 35 | this.salary = salary; 36 | this.hoursPerWeek = hoursPerWeek; 37 | } 38 | 39 | public String getFirstName() { 40 | return firstName; 41 | } 42 | 43 | public String getLastName() { 44 | return lastName; 45 | } 46 | 47 | public int getEmplNumber() { 48 | return emplNumber; 49 | } 50 | 51 | public String getEmail() { 52 | return email; 53 | } 54 | 55 | public int getSalary() { 56 | return salary; 57 | } 58 | 59 | public int getHoursPerWeek() { 60 | return hoursPerWeek; 61 | } 62 | 63 | public String toString() { 64 | return "EmployeeData [firstName=" + firstName + ", lastName=" + lastName + ", emplNumber=" 65 | + emplNumber + ", email= " + email + ", salary=" + salary + ", hoursPerWeek=" + hoursPerWeek 66 | + "]"; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /queries/src/test/java/org/apache/geode_examples/queries/ExampleTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.queries; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | import org.junit.Test; 20 | 21 | import java.util.Map; 22 | 23 | public class ExampleTest { 24 | 25 | @Test 26 | public void testCreateEmployeeData() { 27 | Map data = Example.createEmployeeData(); 28 | assertEquals(14, data.size()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /replicated/.gitignore: -------------------------------------------------------------------------------- 1 | server*/* 2 | locator*/* 3 | -------------------------------------------------------------------------------- /replicated/README.md: -------------------------------------------------------------------------------- 1 | 17 | 18 | # Geode replicated region example 19 | 20 | This is a simple example that demonstrates putting values into a 21 | replicated region, checking the size, and retrieving the values. 22 | 23 | This example assumes you have installed Java and Geode. 24 | 25 | ## Steps 26 | 27 | 1. From the `geode-examples/replicated` directory, build the example and 28 | run unit tests 29 | 30 | $ ../gradlew build 31 | 32 | 2. Next start the locator and two servers 33 | 34 | $ gfsh run --file=scripts/start.gfsh 35 | 36 | 3. Run the example to create entries in the region 37 | 38 | $ ../gradlew run 39 | 40 | 4. Kill one of the servers 41 | 42 | $ gfsh -e "connect --locator=127.0.0.1[10334]" -e "stop server --name=server1" 43 | 44 | 5. Run a gfsh query, and notice that all the entries are still available due to replication 45 | 46 | $ gfsh -e "connect --locator=127.0.0.1[10334]" -e "query --query='select e.key from /example-region.entries e'" 47 | 48 | 6. Shut down the system: 49 | 50 | $ gfsh run --file=scripts/stop.gfsh 51 | -------------------------------------------------------------------------------- /replicated/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | start locator --name=locator --bind-address=127.0.0.1 18 | 19 | start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 20 | start server --name=server2 --locators=127.0.0.1[10334] --server-port=0 21 | 22 | create region --name=example-region --type=REPLICATE 23 | 24 | list members 25 | describe region --name=example-region 26 | -------------------------------------------------------------------------------- /replicated/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | connect --locator=127.0.0.1[10334] 18 | shutdown --include-locators=true -------------------------------------------------------------------------------- /replicated/src/main/java/org/apache/geode_examples/replicated/Example.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.replicated; 16 | 17 | import java.util.HashSet; 18 | import java.util.Set; 19 | import java.util.stream.IntStream; 20 | 21 | import org.apache.geode.cache.Region; 22 | import org.apache.geode.cache.client.ClientCache; 23 | import org.apache.geode.cache.client.ClientCacheFactory; 24 | import org.apache.geode.cache.client.ClientRegionShortcut; 25 | 26 | public class Example { 27 | private final Region region; 28 | 29 | public Example(Region region) { 30 | this.region = region; 31 | } 32 | 33 | public static void main(String[] args) { 34 | // connect to the locator using default port 10334 35 | ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334) 36 | .set("log-level", "WARN").create(); 37 | 38 | // create a local region that matches the server region 39 | Region region = 40 | cache.createClientRegionFactory(ClientRegionShortcut.PROXY) 41 | .create("example-region"); 42 | 43 | Example example = new Example(region); 44 | example.insertValues(10); 45 | example.printValues(example.getValues()); 46 | 47 | cache.close(); 48 | } 49 | 50 | Set getValues() { 51 | return new HashSet<>(region.keySetOnServer()); 52 | } 53 | 54 | void insertValues(int upperLimit) { 55 | IntStream.rangeClosed(1, upperLimit).forEach(i -> region.put(i, "value" + i)); 56 | } 57 | 58 | void printValues(Set values) { 59 | values.forEach(key -> System.out.println(String.format("%d:%s", key, region.get(key)))); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /rest/README.md: -------------------------------------------------------------------------------- 1 | 17 | 18 | # Geode REST API example 19 | 20 | This is a simple example that demonstrates putting values into a 21 | replicated region and retrieving the values using the Geode REST API. For enabling the REST API you can follow the official [document](https://geode.apache.org/docs/guide/19/rest_apps/setup_config.html#setup_config_enabling_rest). 22 | 23 | This example assumes you have installed Java and Geode. 24 | 25 | ## Steps 26 | 27 | 1. From the `geode-examples/rest` directory, build the example and 28 | run unit tests 29 | 30 | $ ../gradlew build 31 | 32 | 2. Next start the locator and two servers 33 | 34 | $ gfsh run --file=scripts/start.gfsh 35 | 36 | 3. Run the example to create and get entries using HTTP Java Client from the region 37 | 38 | $ ../gradlew run 39 | 40 | 4. Shut down the system: 41 | 42 | $ gfsh run --file=scripts/stop.gfsh 43 | -------------------------------------------------------------------------------- /rest/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | start locator --name=locator --bind-address=127.0.0.1 18 | 19 | start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 --start-rest-api --http-service-bind-address=127.0.0.1 --http-service-port=8080 20 | start server --name=server2 --locators=127.0.0.1[10334] --server-port=0 --start-rest-api --http-service-bind-address=127.0.0.1 --http-service-port=8081 21 | 22 | create region --name=example-region --type=REPLICATE 23 | 24 | list members 25 | describe region --name=example-region 26 | -------------------------------------------------------------------------------- /rest/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | connect --locator=127.0.0.1[10334] 18 | shutdown --include-locators=true -------------------------------------------------------------------------------- /serialization/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | start locator --name=locator --bind-address=127.0.0.1 18 | 19 | start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 20 | start server --name=server2 --locators=127.0.0.1[10334] --server-port=0 21 | list members 22 | 23 | create region --name=example-region --type=REPLICATE --skip-if-exists=true 24 | describe region --name=example-region 25 | -------------------------------------------------------------------------------- /serialization/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | connect --locator=127.0.0.1[10334] 18 | 19 | shutdown --include-locators=true -------------------------------------------------------------------------------- /sessionState/scripts/example-shutdown.sh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | # agreements. See the NOTICE file distributed with this work for additional information regarding 4 | # copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | # "License"); you may not use this file except in compliance with the License. You may obtain a 6 | # copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software distributed under the License 11 | # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | # or implied. See the License for the specific language governing permissions and limitations under 13 | # the License. 14 | # 15 | 16 | #!bin/bash 17 | 18 | #Shutdown server and locator 19 | $1/bin/gfsh run --file=shutdown-example.gfsh 20 | 21 | -------------------------------------------------------------------------------- /sessionState/scripts/shutdown-example.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | connect --locator=127.0.0.1[10334] 19 | shutdown --include-locators=true 20 | -------------------------------------------------------------------------------- /sessionState/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | -------------------------------------------------------------------------------- /sessionState/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | -------------------------------------------------------------------------------- /sessionState/src/main/java/org/apache/geode_examples/sessionState/Example.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.sessionState; 16 | 17 | public class Example { 18 | public static void main(String[] args) { 19 | System.out.println( 20 | "Refer to the README.md located in geode_examples/sessionState for info on how to run the session state demo."); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /sessionState/webapp/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | plugins { 16 | id 'java' 17 | id 'war' 18 | } 19 | 20 | version '1.0-SNAPSHOT' 21 | 22 | sourceCompatibility = 1.8 23 | 24 | repositories { 25 | mavenCentral() 26 | } 27 | 28 | dependencies { 29 | // https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api 30 | providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0' 31 | 32 | testCompile group: 'junit', name: 'junit', version: '4.11' 33 | testCompile group: 'junit', name: 'junit', version: '4.12' 34 | } 35 | -------------------------------------------------------------------------------- /sessionState/webapp/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jun 12 15:19:00 PDT 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4-all.zip 7 | -------------------------------------------------------------------------------- /sessionState/webapp/settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | rootProject.name = 'SessionStateDemo' 16 | 17 | -------------------------------------------------------------------------------- /sessionState/webapp/src/main/java/GeodeSessionStateServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | import java.io.IOException; 16 | 17 | import javax.servlet.ServletException; 18 | import javax.servlet.annotation.WebServlet; 19 | import javax.servlet.http.HttpServlet; 20 | import javax.servlet.http.HttpServletRequest; 21 | import javax.servlet.http.HttpServletResponse; 22 | import javax.servlet.http.HttpSession; 23 | 24 | @WebServlet(name = "GeodeSessionStateServlet", urlPatterns = {"/index"}) 25 | public class GeodeSessionStateServlet extends HttpServlet { 26 | protected void doGet(HttpServletRequest request, HttpServletResponse response) 27 | throws ServletException, IOException { 28 | HttpSession session = request.getSession(); 29 | if (session.isNew()) { 30 | request.setAttribute("isNew", "Session is new."); 31 | } else { 32 | request.setAttribute("isNew", "Session already existing"); 33 | session.setMaxInactiveInterval(90); 34 | } 35 | 36 | if (request.getParameter("action") != null) { 37 | if (request.getParameter("action").equals("Set Attribute") 38 | && request.getParameter("key") != null && !request.getParameter("value").equals("null")) { 39 | session.setAttribute(request.getParameter("key"), request.getParameter("value")); 40 | } 41 | 42 | if (request.getParameter("action").equals("Get Attribute") 43 | && request.getParameter("key") != null) { 44 | request.setAttribute("getKey", session.getAttribute(request.getParameter("key"))); 45 | } 46 | 47 | if (request.getParameter("action").equals("Delete Attribute") 48 | && request.getParameter("key") != null) { 49 | session.removeAttribute(request.getParameter("key")); 50 | } 51 | } 52 | 53 | request.getRequestDispatcher("/index.jsp").forward(request, response); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /transaction/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | start locator --name=locator --bind-address=127.0.0.1 19 | start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/classes/java/main 20 | start server --name=server2 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/classes/java/main 21 | list members 22 | 23 | create region --name=example-region --type=REPLICATE --skip-if-exists=true 24 | describe region --name=example-region 25 | -------------------------------------------------------------------------------- /transaction/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | connect --locator=127.0.0.1[10334] 19 | shutdown --include-locators=true 20 | -------------------------------------------------------------------------------- /wan/scripts/start-ln.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | # Start locator for London (ln) cluster 19 | start locator --name=locator-ln --port=10332 --locators=localhost[10332] --mcast-port=0 --log-level=config \ 20 | --J=-Dgemfire.remote-locators=localhost[10331] --J=-Dgemfire.distributed-system-id=2 \ 21 | --J=-Dgemfire.jmx-manager-start=true --J=-Dgemfire.jmx-manager-http-port=8082 \ 22 | --J=-Dgemfire.jmx-manager-port=1092 23 | 24 | start server --name=server-ln-1 --locators=localhost[10332] --mcast-port=0 --log-level=config \ 25 | --enable-time-statistics=true --statistic-archive-file=cacheserver.gfs --server-port=0 \ 26 | --classpath=../build/classes/java/main --J=-Dgemfire.statistic-sampling-enabled=true \ 27 | --J=-Dgemfire.distributed-system-id=2 --J=-Dgemfire.conserve-sockets=false \ 28 | --J=-Dgemfire.log-file=cacheserver.log 29 | 30 | start server --name=server-ln-2 --locators=localhost[10332] --mcast-port=0 --log-level=config \ 31 | --enable-time-statistics=true --statistic-archive-file=cacheserver.gfs --server-port=0 \ 32 | --classpath=../build/classes/java/main --J=-Dgemfire.statistic-sampling-enabled=true \ 33 | --J=-Dgemfire.distributed-system-id=2 --J=-Dgemfire.conserve-sockets=false \ 34 | --J=-Dgemfire.log-file=cacheserver.log 35 | 36 | # Create gateway receivers for all servers in the London site 37 | create gateway-receiver 38 | 39 | # Create gateway senders to send updates to the New York site 40 | create gateway-sender --id="ny" --parallel="true" --remote-distributed-system-id="1" 41 | 42 | list members 43 | 44 | -------------------------------------------------------------------------------- /wan/scripts/start-ny.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | # Start locator for New York (ny) cluster 19 | start locator --name=locator-ny --port=10331 --locators=localhost[10331] --mcast-port=0 --log-level=config \ 20 | --J=-Dgemfire.remote-locators=localhost[10332] --J=-Dgemfire.distributed-system-id=1 \ 21 | --J=-Dgemfire.jmx-manager-start=true --J=-Dgemfire.jmx-manager-http-port=8081 \ 22 | --J=-Dgemfire.jmx-manager-port=1091 23 | 24 | start server --name=server-ny-1 --locators=localhost[10331] --mcast-port=0 --log-level=config \ 25 | --enable-time-statistics=true --statistic-archive-file=cacheserver.gfs --server-port=0 \ 26 | --classpath=../build/classes/java/main --J=-Dgemfire.statistic-sampling-enabled=true \ 27 | --J=-Dgemfire.distributed-system-id=1 --J=-Dgemfire.conserve-sockets=false \ 28 | --J=-Dgemfire.log-file=cacheserver.log 29 | 30 | start server --name=server-ny-2 --locators=localhost[10331] --mcast-port=0 --log-level=config \ 31 | --enable-time-statistics=true --statistic-archive-file=cacheserver.gfs --server-port=0 \ 32 | --classpath=../build/classes/java/main --J=-Dgemfire.statistic-sampling-enabled=true \ 33 | --J=-Dgemfire.distributed-system-id=1 --J=-Dgemfire.conserve-sockets=false \ 34 | --J=-Dgemfire.log-file=cacheserver.log 35 | 36 | # Create gateway receivers for all servers in the New York cluster 37 | create gateway-receiver 38 | 39 | # Create gateway senders for servers to send updates to the London site 40 | create gateway-sender --id="ln" --parallel="true" --remote-distributed-system-id="2" 41 | 42 | list members 43 | 44 | -------------------------------------------------------------------------------- /wan/scripts/start-wan.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | # Connect to New York site and create gateway sender 19 | connect --locator=localhost[10331] 20 | 21 | # Create the region that will share data with the London site 22 | create region --name=example-region --type=PARTITION_REDUNDANT --gateway-sender-id="ln" 23 | 24 | # Check the status of the London site 25 | list members 26 | describe region --name=example-region 27 | 28 | # Disconnect from New York site and connect to London site 29 | disconnect 30 | connect --locator=localhost[10332] 31 | 32 | # Create the region that will share data with the New York site 33 | create region --name=example-region --type=PARTITION_REDUNDANT --gateway-sender-id="ny" 34 | 35 | # Check the status of the London site 36 | list members 37 | describe region --name=example-region 38 | 39 | -------------------------------------------------------------------------------- /wan/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | # Start the London (ln) cluster 19 | run --file=./scripts/start-ln.gfsh 20 | disconnect 21 | 22 | # Start the New York (ny) cluster 23 | run --file=./scripts/start-ny.gfsh 24 | disconnect 25 | sh sleep 5 26 | 27 | # Create the region on each cluster and bind the gateway senders/receivers to region 28 | run --file=./scripts/start-wan.gfsh 29 | 30 | -------------------------------------------------------------------------------- /wan/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | #shutdown london site 19 | connect --locator=localhost[10332] 20 | shutdown --include-locators=true 21 | disconnect 22 | 23 | #shutdown ny site 24 | connect --locator=localhost[10331] 25 | shutdown --include-locators=true 26 | 27 | -------------------------------------------------------------------------------- /wan/src/main/java/org/apache/geode_examples/wan/Example.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.wan; 16 | 17 | import java.util.HashSet; 18 | import java.util.Set; 19 | import java.util.stream.IntStream; 20 | 21 | import org.apache.geode.cache.Region; 22 | import org.apache.geode.cache.client.ClientCache; 23 | import org.apache.geode.cache.client.ClientCacheFactory; 24 | import org.apache.geode.cache.client.ClientRegionShortcut; 25 | 26 | public class Example { 27 | private final Region region; 28 | 29 | public Example(Region region) { 30 | this.region = region; 31 | } 32 | 33 | public static void main(String[] args) { 34 | // connect to the locator in London cluster using port 10332 35 | ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10332) 36 | .set("log-level", "WARN").create(); 37 | 38 | // create a local region that matches the server region 39 | Region region = 40 | cache.createClientRegionFactory(ClientRegionShortcut.PROXY) 41 | .create("example-region"); 42 | 43 | Example example = new Example(region); 44 | example.insertValues(10); 45 | example.printValues(example.getValues()); 46 | 47 | cache.close(); 48 | } 49 | 50 | Set getValues() { 51 | return new HashSet<>(region.keySetOnServer()); 52 | } 53 | 54 | void insertValues(int upperLimit) { 55 | IntStream.rangeClosed(1, upperLimit).forEach(i -> region.put(i, "value" + i)); 56 | } 57 | 58 | void printValues(Set values) { 59 | values.forEach(key -> System.out.println(String.format("%d:%s", key, region.get(key)))); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /writer/README.md: -------------------------------------------------------------------------------- 1 | 17 | 18 | # Geode Cache Writer Example 19 | 20 | This is a simple example that demonstrates the use of a cache writer to validate modifications to a region. 21 | 22 | A cache writer is added to a region as the region is created. _Before_ an event (e.g., create a new entry, update an existing entry) occurs on that region, the cache writer has the appropriate handler method invoked, e.g., `beforeCreate()` for creating a new entry. This method invocation _can_ affect the operation on the region: if it throws `CacheWriterException` the operation is aborted. 23 | 24 | In this example, a cache writer is installed that vets all of the creation events for the region for proper formatting of Social Security numbers. A number of entries are created in the region. The cache writer vets the supplied key for valid formatting. In other applications, the event could either be persisted to some other data store (i.e., write-ahead) or a notification about the activity could be sent via some other mechanism. 25 | 26 | This example assumes you have installed Java and Geode. 27 | 28 | ## Steps 29 | 30 | 1. From the `geode-examples/writer` directory, build the example and 31 | run unit tests. 32 | 33 | $ ../gradlew build 34 | 35 | 2. Next start a locator, start a server, and create a region. 36 | 37 | $ gfsh run --file=scripts/start.gfsh 38 | 39 | 3. Run the example to add a cache listener, put entries into the region, and capture the events. 40 | 41 | $ ../gradlew run 42 | 43 | 4. Shut down the system. 44 | 45 | $ gfsh run --file=scripts/stop.gfsh 46 | -------------------------------------------------------------------------------- /writer/scripts/start.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | start locator --name=locator --bind-address=127.0.0.1 19 | 20 | start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 21 | start server --name=server2 --locators=127.0.0.1[10334] --server-port=0 22 | 23 | deploy --jar=build/libs/writer.jar 24 | 25 | create region --name=example-region --type=REPLICATE --cache-writer=org.apache.geode_examples.writer.ExampleCacheWriter 26 | 27 | list members 28 | describe region --name=example-region 29 | -------------------------------------------------------------------------------- /writer/scripts/stop.gfsh: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | connect --locator=127.0.0.1[10334] 19 | shutdown --include-locators=true 20 | -------------------------------------------------------------------------------- /writer/src/main/java/org/apache/geode/examples/writer/Example.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.writer; 16 | 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | 20 | import org.apache.geode.cache.CacheWriterException; 21 | import org.apache.geode.cache.Region; 22 | import org.apache.geode.cache.client.ClientCache; 23 | import org.apache.geode.cache.client.ClientCacheFactory; 24 | import org.apache.geode.cache.client.ClientRegionShortcut; 25 | import org.apache.geode.cache.client.ServerOperationException; 26 | 27 | public class Example { 28 | public static void main(String[] args) { 29 | // connect to the locator using default port 10334 30 | ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334) 31 | .set("log-level", "WARN").create(); 32 | 33 | // create a local region that matches the server region 34 | Region region = 35 | cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY) 36 | .create("example-region"); 37 | 38 | new Example().getValidNames(region); 39 | cache.close(); 40 | } 41 | 42 | private void addName(Region region, String ssn, String name, List names) { 43 | try { 44 | region.put(ssn, name); 45 | names.add(name); 46 | } catch (CacheWriterException | ServerOperationException e) { 47 | System.out.println("Invalid SSN: " + ssn); 48 | } 49 | } 50 | 51 | public List getValidNames(Region region) { 52 | List names = new ArrayList<>(); 53 | addName(region, "123-45-6789", "Bart Simpson", names); 54 | addName(region, "666-66-6666", "Bill Gates", names); 55 | addName(region, "777-77-7777", "Raymond Babbitt", names); 56 | addName(region, "8675309", "Jenny", names); 57 | addName(region, "999-000-0000", "Blackberry", names); 58 | return names; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /writer/src/main/java/org/apache/geode/examples/writer/ExampleCacheWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.writer; 16 | 17 | import org.apache.geode.cache.CacheWriter; 18 | import org.apache.geode.cache.CacheWriterException; 19 | import org.apache.geode.cache.EntryEvent; 20 | import org.apache.geode.cache.RegionEvent; 21 | 22 | public class ExampleCacheWriter implements CacheWriter { 23 | final SSNVetter vetter = new SSNVetter(); 24 | 25 | @Override 26 | public void beforeUpdate(EntryEvent event) throws CacheWriterException { 27 | if (!vetter.isValid(event.getKey())) { 28 | throw new CacheWriterException("Invalid SSN"); 29 | } 30 | } 31 | 32 | @Override 33 | public void beforeCreate(EntryEvent event) throws CacheWriterException { 34 | if (!vetter.isValid(event.getKey())) { 35 | throw new CacheWriterException("Invalid SSN"); 36 | } 37 | } 38 | 39 | @Override 40 | public void beforeDestroy(EntryEvent event) throws CacheWriterException { 41 | // N/A 42 | } 43 | 44 | @Override 45 | public void beforeRegionDestroy(RegionEvent event) throws CacheWriterException { 46 | // N/A 47 | } 48 | 49 | @Override 50 | public void beforeRegionClear(RegionEvent event) throws CacheWriterException { 51 | // N/A 52 | } 53 | 54 | @Override 55 | public void close() { 56 | // N/A 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /writer/src/main/java/org/apache/geode/examples/writer/SSNVetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.writer; 16 | 17 | import java.util.regex.Matcher; 18 | import java.util.regex.Pattern; 19 | 20 | public class SSNVetter { 21 | private final Pattern ssnPattern = Pattern.compile("^\\s*([0-8]\\d{2})-?\\d{2}-?\\d{4}\\s*$"); 22 | 23 | public boolean isValid(String text) { 24 | final Matcher m = ssnPattern.matcher(text); 25 | if (m.matches() && !m.group(1).equals("666")) { 26 | return true; 27 | } 28 | return false; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /writer/src/test/java/org/apache/geode_examples/writer/ExampleCacheWriterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.writer; 16 | 17 | import static org.mockito.Mockito.mock; 18 | import static org.mockito.Mockito.when; 19 | 20 | import org.junit.Test; 21 | 22 | import org.apache.geode.cache.CacheWriterException; 23 | import org.apache.geode.cache.EntryEvent; 24 | 25 | public class ExampleCacheWriterTest { 26 | @Test(expected = CacheWriterException.class) 27 | public void testBeforeCreateFailsForBadSSN() throws Exception { 28 | ExampleCacheWriter writer = new ExampleCacheWriter(); 29 | 30 | EntryEvent event = mock(EntryEvent.class); 31 | when(event.getKey()).thenReturn("666-66-6666"); 32 | writer.beforeCreate(event); 33 | } 34 | 35 | @Test 36 | public void testBeforeCreatePassesWithGoodSSN() throws Exception { 37 | ExampleCacheWriter writer = new ExampleCacheWriter(); 38 | 39 | EntryEvent event = mock(EntryEvent.class); 40 | when(event.getKey()).thenReturn("555-66-6666"); 41 | writer.beforeCreate(event); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /writer/src/test/java/org/apache/geode_examples/writer/ExampleTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.writer; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | import static org.mockito.ArgumentMatchers.any; 19 | import static org.mockito.ArgumentMatchers.eq; 20 | import static org.mockito.Mockito.mock; 21 | import static org.mockito.Mockito.when; 22 | 23 | import java.util.Arrays; 24 | 25 | import org.apache.geode.cache.CacheWriterException; 26 | import org.apache.geode.cache.Region; 27 | 28 | import org.junit.Test; 29 | 30 | public class ExampleTest { 31 | @Test 32 | public void testExample() throws Exception { 33 | Example example = new Example(); 34 | 35 | Region region = mock(Region.class); 36 | when(region.put(eq("666-66-6666"), any())).thenThrow(new CacheWriterException()); 37 | when(region.put(eq("8675309"), any())).thenThrow(new CacheWriterException()); 38 | when(region.put(eq("999-000-0000"), any())).thenThrow(new CacheWriterException()); 39 | 40 | assertEquals(Arrays.asList(new String[] {"Bart Simpson", "Raymond Babbitt"}), 41 | example.getValidNames(region)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /writer/src/test/java/org/apache/geode_examples/writer/SSNVetterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding 4 | * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a 6 | * copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | */ 15 | package org.apache.geode_examples.writer; 16 | 17 | import static org.junit.Assert.assertFalse; 18 | import static org.junit.Assert.assertTrue; 19 | 20 | import org.junit.Test; 21 | 22 | public class SSNVetterTest { 23 | @Test 24 | public void testIsValid() throws Exception { 25 | SSNVetter vetter = new SSNVetter(); 26 | 27 | assertTrue(vetter.isValid("123-45-6789")); 28 | assertFalse(vetter.isValid("666-66-6666")); 29 | assertTrue(vetter.isValid("777-77-7777")); 30 | assertFalse(vetter.isValid("8675309")); 31 | assertFalse(vetter.isValid("999-000-0000")); 32 | } 33 | } 34 | --------------------------------------------------------------------------------