You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by bb...@apache.org on 2021/07/23 19:06:15 UTC
[geode-native] branch develop updated: GEODE-9360: Initial checkin
of .net core support (#823)
This is an automated email from the ASF dual-hosted git repository.
bbender pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git
The following commit(s) were added to refs/heads/develop by this push:
new d744586 GEODE-9360: Initial checkin of .net core support (#823)
d744586 is described below
commit d7445864c29d3b5e0152e7cad0dbd98278912436
Author: Blake Bender <bb...@pivotal.io>
AuthorDate: Fri Jul 23 12:06:09 2021 -0700
GEODE-9360: Initial checkin of .net core support (#823)
* GEODE-9360: Initial revision of Geode .net core library and tests
Co-authored-by: Matthew Reddington <mr...@vmware.com>
Co-authored-by: Mike Martell <ma...@vmware.com>
---
netcore/.clang-format | 3 +
netcore/.gitignore | 4 +
netcore/NetCore.Test/CacheFactoryTest.cs | 77 ++++++++++
netcore/NetCore.Test/CacheTest.cs | 130 ++++++++++++++++
netcore/NetCore.Test/NetCore.Test.csproj | 32 ++++
netcore/NetCore.Test/NetCoreCollectionFixture.cs | 33 ++++
netcore/NetCore.Test/ObjectLeakTest.cs | 34 +++++
netcore/NetCore.Test/PoolFactoryTest.cs | 71 +++++++++
netcore/NetCore.Test/PoolManagerTest.cs | 36 +++++
.../NetCore.Test/Properties/launchSettings.json | 8 +
netcore/NetCore.Test/RegionFactoryTest.cs | 106 +++++++++++++
netcore/NetCore.Test/xunit.runner.json | 5 +
netcore/NetCore/AuthInitialize.cs | 24 +++
netcore/NetCore/Cache.cs | 166 +++++++++++++++++++++
netcore/NetCore/CacheFactory.cs | 109 ++++++++++++++
netcore/NetCore/Client.cs | 41 +++++
netcore/NetCore/Constants.cs | 21 +++
netcore/NetCore/GeodeNativeObject.cs | 48 ++++++
netcore/NetCore/ICacheFactory.cs | 29 ++++
netcore/NetCore/IGeodeCache.cs | 34 +++++
netcore/NetCore/IRegionService.cs | 23 +++
netcore/NetCore/NetCore.csproj | 11 ++
netcore/NetCore/Pool.cs | 43 ++++++
netcore/NetCore/PoolFactory.cs | 55 +++++++
netcore/NetCore/PoolManager.cs | 41 +++++
netcore/NetCore/Region.cs | 114 ++++++++++++++
netcore/NetCore/RegionFactory.cs | 42 ++++++
netcore/NetCore/RegionShortcut.cs | 25 ++++
netcore/geode-dotnet-core.sln | 31 ++++
netcore/scripts/build-geode-native-netcore.sh | 54 +++++++
netcore/scripts/run-clang-format.cmd | 16 ++
netcore/scripts/startserver.ps1 | 65 ++++++++
netcore/scripts/startserver.sh | 48 ++++++
netcore/scripts/stopserver.ps1 | 47 ++++++
netcore/scripts/stopserver.sh | 35 +++++
netcore/utility/CMakeLists.txt | 35 +++++
netcore/utility/SimpleSecurityManager.java | 79 ++++++++++
netcore/utility/UserPasswordAuthInit.java | 81 ++++++++++
netcore/utility/UsernamePrincipal.java | 43 ++++++
39 files changed, 1899 insertions(+)
diff --git a/netcore/.clang-format b/netcore/.clang-format
new file mode 100644
index 0000000..750c3c7
--- /dev/null
+++ b/netcore/.clang-format
@@ -0,0 +1,3 @@
+---
+Language: CSharp
+BasedOnStyle: Google
diff --git a/netcore/.gitignore b/netcore/.gitignore
new file mode 100644
index 0000000..e89c87b
--- /dev/null
+++ b/netcore/.gitignore
@@ -0,0 +1,4 @@
+/*/bin/
+/*/obj/
+/*/build/
+
diff --git a/netcore/NetCore.Test/CacheFactoryTest.cs b/netcore/NetCore.Test/CacheFactoryTest.cs
new file mode 100644
index 0000000..442c825
--- /dev/null
+++ b/netcore/NetCore.Test/CacheFactoryTest.cs
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using Xunit;
+
+namespace Apache.Geode.Client {
+ [Collection("Geode .net Core Collection")]
+ public class CacheFactoryTest {
+ [Fact]
+ public void CreateFactoryNotNull() {
+ using (var cacheFactory = CacheFactory.Create()) {
+ Assert.NotNull(cacheFactory);
+ }
+ }
+
+ [Fact]
+ public void CacheFactoryGetVersion() {
+ using (var cacheFactory = CacheFactory.Create()) {
+ var version = cacheFactory.Version;
+ Assert.NotEqual(version, String.Empty);
+ }
+ }
+
+ [Fact]
+ public void CacheFactoryGetProductDescription() {
+ using (var cacheFactory = CacheFactory.Create()) {
+ var description = cacheFactory.ProductDescription;
+ Assert.NotEqual(description, String.Empty);
+ }
+ }
+
+ [Fact]
+ public void CacheFactorySetPdxIgnoreUnreadFields() {
+ using (var cacheFactory = CacheFactory.Create()) {
+ cacheFactory.PdxIgnoreUnreadFields = true;
+ cacheFactory.PdxIgnoreUnreadFields = false;
+ }
+ }
+
+ [Fact]
+ public void CacheFactorySetPdxReadSerialized() {
+ using (var cacheFactory = CacheFactory.Create()) {
+ cacheFactory.PdxReadSerialized = true;
+ cacheFactory.PdxReadSerialized = false;
+ }
+ }
+
+ [Fact]
+ public void CacheFactoryCreateCacheNotNull() {
+ using var cacheFactory = CacheFactory.Create();
+ Assert.NotNull(cacheFactory);
+ using var cache = cacheFactory.CreateCache(); // lgtm[cs / useless - assignment - to - local]
+ Assert.NotNull(cache);
+ }
+
+ [Fact]
+ public void CacheFactorySetProperty() {
+ using var cacheFactory = CacheFactory.Create();
+ Assert.NotNull(cacheFactory);
+ cacheFactory.SetProperty("log-level", "none").SetProperty("log-file", "geode_native.log");
+ }
+ }
+}
diff --git a/netcore/NetCore.Test/CacheTest.cs b/netcore/NetCore.Test/CacheTest.cs
new file mode 100644
index 0000000..d06d2fd
--- /dev/null
+++ b/netcore/NetCore.Test/CacheTest.cs
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Net.Cache;
+using Xunit;
+
+namespace Apache.Geode.Client {
+ [Collection("Geode .net Core Collection")]
+ public class CacheTest {
+ [Fact]
+ public void ClientCacheGetPdxReadSerialized() {
+ using var cacheFactory =
+ CacheFactory.Create()
+ .SetProperty("log-level", "debug")
+ .SetProperty("log-file", "TestClientCacheGetPdxReadSerialized.log");
+ try {
+ cacheFactory.PdxReadSerialized = true;
+ using var cache = cacheFactory.CreateCache();
+
+ Assert.True(cache.GetPdxReadSerialized());
+
+ cacheFactory.PdxReadSerialized = false;
+ using var otherCache = cacheFactory.CreateCache();
+
+ Assert.False(otherCache.GetPdxReadSerialized());
+ } catch (Exception e) {
+ Console.WriteLine(e);
+ throw;
+ }
+ }
+
+ [Fact]
+ public void ClientCacheGetPdxIgnoreUnreadFields() {
+ using var cacheFactory = CacheFactory.Create()
+ .SetProperty("log-level", "none")
+ .SetProperty("log-file", "geode_native.log");
+ cacheFactory.PdxIgnoreUnreadFields = true;
+ using var cache = cacheFactory.CreateCache();
+
+ Assert.True(cache.GetPdxIgnoreUnreadFields());
+
+ cacheFactory.PdxIgnoreUnreadFields = false;
+ using var otherCache = cacheFactory.CreateCache();
+ Assert.False(otherCache.GetPdxIgnoreUnreadFields());
+ }
+
+ [Fact]
+ public void ClientCacheGetPoolManagerObjectsNotNull() {
+ using var cacheFactory = CacheFactory.Create()
+ .SetProperty("log-level", "none")
+ .SetProperty("log-file", "geode_native.log");
+
+ cacheFactory.PdxIgnoreUnreadFields = true;
+ using var cache = cacheFactory.CreateCache(); // lgtm [cs/useless-assignment-to-local]
+ Assert.NotNull(cache);
+ using var poolManager = cache.PoolManager;
+ Assert.NotNull(poolManager);
+ }
+
+ [Fact]
+ public void ClientCacheCreateRegionFactoryObjectsNotNull() {
+ using var cacheFactory = CacheFactory.Create()
+ .SetProperty("log-level", "none")
+ .SetProperty("log-file", "geode_native.log");
+ Assert.NotNull(cacheFactory);
+ cacheFactory.PdxIgnoreUnreadFields = true;
+ using var cache = cacheFactory.CreateCache();
+ Assert.NotNull(cache);
+ using var regionFactory = cache.CreateRegionFactory(
+ RegionShortcut.Proxy); // lgtm[cs / useless - assignment - to - local]
+ Assert.NotNull(regionFactory);
+ }
+
+ [Fact]
+ public void ClientCacheGetName() {
+ using var cacheFactory = CacheFactory.Create().SetProperty("log-level", "none");
+ cacheFactory.PdxIgnoreUnreadFields = true;
+ using var cache = cacheFactory.CreateCache();
+ Assert.NotNull(cache);
+
+ var cacheName = cache.Name;
+ Assert.NotEqual(cacheName, String.Empty);
+ }
+
+ [Fact]
+ public void ClientCacheClose() {
+ using var cacheFactory = CacheFactory.Create().SetProperty("log-level", "none");
+ cacheFactory.PdxIgnoreUnreadFields = true;
+ using var cache = cacheFactory.CreateCache();
+ Assert.NotNull(cache);
+
+ Assert.False(cache.Closed);
+ cache.Close();
+ Assert.True(cache.Closed);
+ }
+
+ [Fact]
+ public void ClientCacheCloseWithKeepalive() {
+ using var cacheFactory = CacheFactory.Create().SetProperty("log-level", "none");
+ cacheFactory.PdxIgnoreUnreadFields = true;
+ using var cache = cacheFactory.CreateCache();
+ Assert.NotNull(cache);
+
+ Assert.False(cache.Closed);
+ cache.Close(true);
+ Assert.True(cache.Closed);
+
+ using var otherCache = cacheFactory.CreateCache();
+ Assert.NotNull(otherCache);
+
+ Assert.False(otherCache.Closed);
+ otherCache.Close(false);
+ Assert.True(otherCache.Closed);
+ }
+ }
+}
diff --git a/netcore/NetCore.Test/NetCore.Test.csproj b/netcore/NetCore.Test/NetCore.Test.csproj
new file mode 100644
index 0000000..3898983
--- /dev/null
+++ b/netcore/NetCore.Test/NetCore.Test.csproj
@@ -0,0 +1,32 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFramework>netcoreapp3.1</TargetFramework>
+
+ <IsPackable>false</IsPackable>
+
+ <Platforms>x64</Platforms>
+
+ <Configurations>Debug;Release;RelWithDebInfo</Configurations>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
+ <PackageReference Include="xunit" Version="2.4.1" />
+ <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
+ <PrivateAssets>all</PrivateAssets>
+ <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+ </PackageReference>
+ </ItemGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\NetCore\NetCore.csproj" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <None Update="xunit.runner.json">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </None>
+ </ItemGroup>
+
+</Project>
diff --git a/netcore/NetCore.Test/NetCoreCollectionFixture.cs b/netcore/NetCore.Test/NetCoreCollectionFixture.cs
new file mode 100644
index 0000000..d30833e
--- /dev/null
+++ b/netcore/NetCore.Test/NetCoreCollectionFixture.cs
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using Apache.Geode.Client;
+using Xunit;
+
+public class NetCoreCollectionFixture : IDisposable {
+ public NetCoreCollectionFixture() {
+ client_ = new Client();
+ }
+ public void Dispose() {
+ client_.Dispose();
+ }
+
+ Client client_;
+}
+
+[CollectionDefinition("Geode .net Core Collection")]
+public class NetCoreCollection : ICollectionFixture<NetCoreCollectionFixture> {}
diff --git a/netcore/NetCore.Test/ObjectLeakTest.cs b/netcore/NetCore.Test/ObjectLeakTest.cs
new file mode 100644
index 0000000..c1440f9
--- /dev/null
+++ b/netcore/NetCore.Test/ObjectLeakTest.cs
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using Xunit;
+
+namespace Apache.Geode.Client {
+ [Collection("Geode .net Core Collection")]
+ public class ObjectLeakTest {
+ [Fact]
+ public void LeakCacheFactoryVerifyThrows() {
+ var client = new Client();
+
+ using (var cacheFactory =
+ CacheFactory.Create()) // lgtm[cs / useless - assignment - to - local]
+ {
+ Assert.Throws<InvalidOperationException>(() => client.Dispose());
+ }
+ }
+ }
+}
diff --git a/netcore/NetCore.Test/PoolFactoryTest.cs b/netcore/NetCore.Test/PoolFactoryTest.cs
new file mode 100644
index 0000000..668be53
--- /dev/null
+++ b/netcore/NetCore.Test/PoolFactoryTest.cs
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System.Net.Cache;
+using Xunit;
+
+namespace Apache.Geode.Client {
+ [Collection("Geode .net Core Collection")]
+ public class PoolFactoryTest {
+ [Fact]
+ public void PoolFactoryAddLocatorAllObjectsNotNull() {
+ using var cacheFactory = CacheFactory.Create()
+ .SetProperty("log-level", "none")
+ .SetProperty("log-file", "geode_native.log");
+ using var cache = cacheFactory.CreateCache();
+ Assert.NotNull(cache);
+ using var poolManager = cache.PoolManager;
+ Assert.NotNull(poolManager);
+ using var poolFactory = poolManager.CreatePoolFactory();
+ Assert.NotNull(poolFactory);
+
+ poolFactory.AddLocator("localhost", 10334);
+ }
+
+ [Fact]
+ public void PoolFactoryCreatePoolAllObjectsNotNull() {
+ using var cacheFactory = CacheFactory.Create()
+ .SetProperty("log-level", "none")
+ .SetProperty("log-file", "geode_native.log");
+ using var cache = cacheFactory.CreateCache();
+ Assert.NotNull(cache);
+ using var poolManager = cache.PoolManager;
+ Assert.NotNull(poolManager);
+ using var poolFactory = poolManager.CreatePoolFactory();
+ Assert.NotNull(poolFactory);
+
+ poolFactory.AddLocator("localhost", 10334);
+ using var pool =
+ poolFactory.CreatePool("myPool"); // lgtm[cs / useless - assignment - to - local]
+ Assert.NotNull(pool);
+ }
+
+ [Fact]
+ public void CreatePoolWithoutPoolManagerAllObjectsNotNull() {
+ using var cacheFactory = CacheFactory.Create();
+ Assert.NotNull(cacheFactory);
+ using var cache = cacheFactory.CreateCache();
+ Assert.NotNull(cache);
+ using var poolFactory = cache.PoolFactory;
+ Assert.NotNull(poolFactory);
+
+ poolFactory.AddLocator("localhost", 10334);
+ using var pool =
+ poolFactory.CreatePool("myPool"); // lgtm[cs / useless - assignment - to - local]
+ Assert.NotNull(pool);
+ }
+ }
+}
diff --git a/netcore/NetCore.Test/PoolManagerTest.cs b/netcore/NetCore.Test/PoolManagerTest.cs
new file mode 100644
index 0000000..e33f53b
--- /dev/null
+++ b/netcore/NetCore.Test/PoolManagerTest.cs
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System.Net.Cache;
+using Xunit;
+
+namespace Apache.Geode.Client {
+ [Collection("Geode .net Core Collection")]
+ public class PoolManagerTest {
+ [Fact]
+ public void PoolManagerCreatePoolFactoryAllObjectsNotNull() {
+ using var cacheFactory = CacheFactory.Create();
+ Assert.NotNull(cacheFactory);
+ using var cache = cacheFactory.CreateCache();
+ Assert.NotNull(cache);
+ using var poolManager = cache.PoolManager;
+ Assert.NotNull(poolManager);
+ using var poolFactory =
+ poolManager.CreatePoolFactory(); // lgtm[cs / useless - assignment - to - local]
+ Assert.NotNull(poolFactory);
+ }
+ }
+}
diff --git a/netcore/NetCore.Test/Properties/launchSettings.json b/netcore/NetCore.Test/Properties/launchSettings.json
new file mode 100644
index 0000000..525b032
--- /dev/null
+++ b/netcore/NetCore.Test/Properties/launchSettings.json
@@ -0,0 +1,8 @@
+{
+ "profiles": {
+ "GemfireDotNetTest": {
+ "commandName": "Project",
+ "nativeDebugging": true
+ }
+ }
+}
diff --git a/netcore/NetCore.Test/RegionFactoryTest.cs b/netcore/NetCore.Test/RegionFactoryTest.cs
new file mode 100644
index 0000000..970109f
--- /dev/null
+++ b/netcore/NetCore.Test/RegionFactoryTest.cs
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Collections.Generic;
+using System.Net.Cache;
+using Xunit;
+
+namespace Apache.Geode.Client {
+ public class SimpleAuthInitialize : IAuthInitialize {
+ public Dictionary<string, string> GetCredentials() {
+ Console.WriteLine("SimpleAuthInitialize::GetCredentials called");
+ var credentials = new Dictionary<string, string>();
+ credentials.Add("security-username", "server");
+ credentials.Add("security-password", "server");
+ return credentials;
+ }
+
+ public void Close() {
+ Console.WriteLine("SimpleAuthInitialize::Close called");
+ }
+ }
+
+ [Collection("Geode .net Core Collection")]
+ public class RegionFactoryTest {
+ private const string Username1 = "rtimmons";
+ private const string Username2 = "scharles";
+
+ private void createPool(IGeodeCache cache, int port) {
+ using var poolManager = cache.PoolManager;
+ using var poolFactory = poolManager.CreatePoolFactory().AddLocator("localhost", port);
+ using var pool =
+ poolFactory.CreatePool("myPool"); // lgtm[cs / useless - assignment - to - local]
+ }
+
+ private void doPutsAndGets(Region region) {
+ var fullname1 = "Robert Timmons";
+ var fullname2 = "Sylvia Charles";
+
+ region.PutString(Username1, fullname1);
+ region.PutString(Username2, fullname2);
+
+ var user1 = region.GetString(Username1);
+ var user2 = region.GetString(Username2);
+
+ Assert.Equal(user1, fullname1);
+ Assert.Equal(user2, fullname2);
+ }
+
+ private void DoRemoves(Region region) {
+ region.Remove(Username1);
+ region.Remove(Username2);
+
+ var hasUser1 = region.ContainsValueForKey(Username1);
+ var hasUser2 = region.ContainsValueForKey(Username2);
+
+ Assert.False(hasUser1);
+ Assert.False(hasUser2);
+ }
+
+ private void CreateRegionAndDoWork(IGeodeCache cache, string regionName,
+ RegionShortcut regionType) {
+ using var regionFactory = cache.CreateRegionFactory(regionType);
+ using var region = regionFactory.CreateRegion(regionName);
+
+ doPutsAndGets(region);
+ DoRemoves(region);
+ }
+
+ [Fact]
+ public void RegionFactoryCreateProxyRegionStringPutGet() {
+ using var cacheFactory = CacheFactory.Create()
+ .SetProperty("log-level", "debug")
+ .SetProperty("log-file", "geode_native.log");
+ using var cache = cacheFactory.CreateCache();
+
+ createPool(cache, 10334);
+ CreateRegionAndDoWork(cache, "exampleRegion", RegionShortcut.Proxy);
+ }
+
+ [Fact]
+ public void RegionFactoryCreateRegionStringPutGetWithAuthentication() {
+ using var cacheFactory = CacheFactory.Create()
+ .SetProperty("log-level", "debug")
+ .SetProperty("log-file", "geode_native_with_auth.log");
+ cacheFactory.AuthInitialize = new SimpleAuthInitialize();
+ using var cache = cacheFactory.CreateCache();
+
+ createPool(cache, 10335);
+ CreateRegionAndDoWork(cache, "authExampleRegion", RegionShortcut.CachingProxy);
+ }
+ }
+}
diff --git a/netcore/NetCore.Test/xunit.runner.json b/netcore/NetCore.Test/xunit.runner.json
new file mode 100644
index 0000000..f8b2eef
--- /dev/null
+++ b/netcore/NetCore.Test/xunit.runner.json
@@ -0,0 +1,5 @@
+{
+ "methodDisplay": "classAndMethod",
+ "parallelizeAssembly": true,
+ "parallelizeTestCollections": true
+}
diff --git a/netcore/NetCore/AuthInitialize.cs b/netcore/NetCore/AuthInitialize.cs
new file mode 100644
index 0000000..d1e6024
--- /dev/null
+++ b/netcore/NetCore/AuthInitialize.cs
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System.Collections.Generic;
+
+namespace Apache.Geode.Client {
+ public interface IAuthInitialize {
+ Dictionary<string, string> GetCredentials();
+ void Close();
+ }
+}
diff --git a/netcore/NetCore/Cache.cs b/netcore/NetCore/Cache.cs
new file mode 100644
index 0000000..200e740
--- /dev/null
+++ b/netcore/NetCore/Cache.cs
@@ -0,0 +1,166 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Collections.Generic;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+namespace Apache.Geode.Client {
+ public class Cache : GeodeNativeObject, IGeodeCache {
+ private static string _name = String.Empty;
+ private PoolManager _poolManager = null;
+ private PoolFactory _poolFactory = null;
+ private IAuthInitialize _authInitialize;
+ private GetCredentialsDelegateInternal _getCredentialsDelegate;
+ private CloseDelegateInternal _closeDelegate;
+
+ internal delegate void GetCredentialsDelegateInternal(IntPtr cache);
+
+ internal delegate void CloseDelegateInternal();
+
+ [DllImport(Constants.libPath, CallingConvention = CallingConvention.Cdecl)]
+ private static extern void apache_geode_CacheFactory_SetAuthInitialize(
+ IntPtr factory, GetCredentialsDelegateInternal getCredentials,
+ CloseDelegateInternal close);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern IntPtr apache_geode_CacheFactory_CreateCache(IntPtr factory);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern bool apache_geode_Cache_GetPdxIgnoreUnreadFields(IntPtr cache);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern bool apache_geode_Cache_GetPdxReadSerialized(IntPtr cache);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern IntPtr apache_geode_Cache_GetName(IntPtr cache);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern void apache_geode_Cache_Close(IntPtr cache, bool keepalive);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern bool apache_geode_Cache_IsClosed(IntPtr cache);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern bool apache_geode_AuthInitialize_AddProperty(IntPtr properties,
+ IntPtr key,
+ IntPtr value);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern void apache_geode_DestroyCache(IntPtr cache);
+
+ internal Cache(IntPtr cacheFactory, IAuthInitialize authInitialize) {
+ _authInitialize = authInitialize;
+ if (_authInitialize != null) {
+ _getCredentialsDelegate = new GetCredentialsDelegateInternal(AuthGetCredentials);
+ _closeDelegate = new CloseDelegateInternal(AuthClose);
+
+ apache_geode_CacheFactory_SetAuthInitialize(cacheFactory, _getCredentialsDelegate,
+ _closeDelegate);
+ }
+ _containedObject = apache_geode_CacheFactory_CreateCache(cacheFactory);
+ }
+
+ internal void AuthGetCredentials(IntPtr properties) {
+ Console.WriteLine("In AuthInitialize::GetCredentials callback");
+ if (_authInitialize == null) {
+ throw new InvalidOperationException(
+ "AuthInitialize callback received for cache without authentication!");
+ }
+
+ var credentials = _authInitialize.GetCredentials();
+ foreach (KeyValuePair<string, string> entry in credentials) {
+ Console.WriteLine("Found credential: (k, v) = ({0}, {1})", entry.Key, entry.Value);
+ var keyPtr = Marshal.StringToCoTaskMemUTF8(entry.Key);
+ var valuePtr = Marshal.StringToCoTaskMemUTF8(entry.Value);
+ apache_geode_AuthInitialize_AddProperty(properties, keyPtr, valuePtr);
+ Marshal.FreeCoTaskMem(keyPtr);
+ Marshal.FreeCoTaskMem(valuePtr);
+ }
+ }
+
+ public void AuthClose() {
+ Console.WriteLine("In AuthInitialize::Close callback");
+ }
+
+ public void Close() {
+ apache_geode_Cache_Close(_containedObject, false);
+ }
+
+ public void Close(bool keepalive) {
+ apache_geode_Cache_Close(_containedObject, keepalive);
+ }
+
+ public bool GetPdxIgnoreUnreadFields() {
+ return apache_geode_Cache_GetPdxIgnoreUnreadFields(_containedObject);
+ }
+
+ public bool GetPdxReadSerialized() {
+ return apache_geode_Cache_GetPdxReadSerialized(_containedObject);
+ }
+
+ public string Name {
+ get {
+ if (_name == String.Empty) {
+ _name = Marshal.PtrToStringUTF8(apache_geode_Cache_GetName(_containedObject));
+ }
+
+ return _name;
+ }
+ }
+
+ public PoolManager PoolManager {
+ get {
+ if (_poolManager == null) {
+ _poolManager = new PoolManager(_containedObject);
+ }
+
+ return _poolManager;
+ }
+ }
+
+ public PoolFactory PoolFactory {
+ get {
+ if (_poolFactory == null) {
+ _poolFactory = PoolManager.CreatePoolFactory();
+ }
+
+ return _poolFactory;
+ }
+ }
+
+ public RegionFactory CreateRegionFactory(RegionShortcut regionType) {
+ return new RegionFactory(_containedObject, regionType);
+ }
+
+ public bool Closed => apache_geode_Cache_IsClosed(_containedObject);
+
+ protected override void DestroyContainedObject() {
+ // It turns out, C# "wrapper" objects need to get rid of
+ // *all* contained objects, due to vagaries of Geode
+ // Native object graph, in order to ensure a leak-free
+ // shutdown. We get rid of our non-cache objects first
+ // here, in case it makes a difference.
+ _poolManager?.Dispose();
+ _poolManager = null;
+ _poolFactory?.Dispose();
+ _poolFactory = null;
+ apache_geode_DestroyCache(_containedObject);
+ _containedObject = IntPtr.Zero;
+ }
+ }
+}
diff --git a/netcore/NetCore/CacheFactory.cs b/netcore/NetCore/CacheFactory.cs
new file mode 100644
index 0000000..5588e3c
--- /dev/null
+++ b/netcore/NetCore/CacheFactory.cs
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Runtime.InteropServices;
+
+namespace Apache.Geode.Client {
+ public class CacheFactory : GeodeNativeObject, ICacheFactory {
+ private string _version = String.Empty;
+ private string _productDescription = String.Empty;
+ private IAuthInitialize _authInitialize;
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern IntPtr apache_geode_CreateCacheFactory();
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern void apache_geode_DestroyCacheFactory(IntPtr factory);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern IntPtr apache_geode_CacheFactory_GetVersion(IntPtr factory);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern IntPtr apache_geode_CacheFactory_GetProductDescription(
+ IntPtr factory);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern void apache_geode_CacheFactory_SetPdxIgnoreUnreadFields(
+ IntPtr factory, bool pdxIgnoreUnreadFields);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern void apache_geode_CacheFactory_SetPdxReadSerialized(
+ IntPtr factory, bool pdxReadSerialized);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern void apache_geode_CacheFactory_SetProperty(IntPtr factory, IntPtr key,
+ IntPtr value);
+
+ public static ICacheFactory Create() {
+ return new CacheFactory();
+ }
+
+ public CacheFactory() {
+ _containedObject = apache_geode_CreateCacheFactory();
+ }
+
+ public string Version {
+ get {
+ if (_version == String.Empty) {
+ _version =
+ Marshal.PtrToStringUTF8(apache_geode_CacheFactory_GetVersion(_containedObject));
+ }
+
+ return _version;
+ }
+ }
+
+ public string ProductDescription {
+ get {
+ if (_productDescription == String.Empty) {
+ _productDescription = Marshal.PtrToStringUTF8(
+ apache_geode_CacheFactory_GetProductDescription(_containedObject));
+ }
+
+ return _productDescription;
+ }
+ }
+
+ public bool PdxIgnoreUnreadFields {
+ set => apache_geode_CacheFactory_SetPdxIgnoreUnreadFields(_containedObject, value);
+ }
+
+ public bool PdxReadSerialized {
+ set => apache_geode_CacheFactory_SetPdxReadSerialized(_containedObject, value);
+ }
+
+ public IGeodeCache CreateCache() {
+ return new Cache(_containedObject, _authInitialize);
+ }
+
+ public ICacheFactory SetProperty(string key, string value) {
+ var utf8Key = Marshal.StringToCoTaskMemUTF8(key);
+ var utf8Value = Marshal.StringToCoTaskMemUTF8(value);
+ apache_geode_CacheFactory_SetProperty(_containedObject, utf8Key, utf8Value);
+ Marshal.FreeCoTaskMem(utf8Key);
+ Marshal.FreeCoTaskMem(utf8Value);
+ return this;
+ }
+
+ public IAuthInitialize AuthInitialize { set => _authInitialize = value; }
+
+ protected override void DestroyContainedObject() {
+ apache_geode_DestroyCacheFactory(_containedObject);
+ _containedObject = IntPtr.Zero;
+ }
+ }
+}
diff --git a/netcore/NetCore/Client.cs b/netcore/NetCore/Client.cs
new file mode 100644
index 0000000..b62fe34
--- /dev/null
+++ b/netcore/NetCore/Client.cs
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Runtime.InteropServices;
+
+namespace Apache.Geode.Client {
+ public class Client : GeodeNativeObject {
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern IntPtr apache_geode_ClientInitialize();
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern int apache_geode_ClientUninitialize(IntPtr client);
+
+ public Client() {
+ _containedObject = apache_geode_ClientInitialize();
+ }
+
+ protected override void DestroyContainedObject() {
+ var err = apache_geode_ClientUninitialize(_containedObject);
+ _containedObject = IntPtr.Zero;
+ if (err != 0) {
+ throw new InvalidOperationException(
+ "One or more native objects was leaked! See Geode Native log for debugging info.");
+ }
+ }
+ }
+}
diff --git a/netcore/NetCore/Constants.cs b/netcore/NetCore/Constants.cs
new file mode 100644
index 0000000..e27dbe2
--- /dev/null
+++ b/netcore/NetCore/Constants.cs
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+namespace Apache.Geode.Client {
+ public class Constants {
+ public const string libPath = "apache-geode-c";
+ }
+}
diff --git a/netcore/NetCore/GeodeNativeObject.cs b/netcore/NetCore/GeodeNativeObject.cs
new file mode 100644
index 0000000..541fa31
--- /dev/null
+++ b/netcore/NetCore/GeodeNativeObject.cs
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+
+namespace Apache.Geode.Client {
+ public abstract class GeodeNativeObject : IDisposable {
+ private bool _disposed = false;
+ protected IntPtr _containedObject;
+
+ public void Dispose() {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ public IntPtr ContainedObject {
+ get { return _containedObject; }
+ }
+
+ protected virtual void Dispose(bool disposing) {
+ if (_disposed) {
+ return;
+ }
+
+ if (disposing) {
+ DestroyContainedObject();
+ _containedObject = IntPtr.Zero;
+ }
+
+ _disposed = true;
+ }
+
+ protected abstract void DestroyContainedObject();
+ }
+}
diff --git a/netcore/NetCore/ICacheFactory.cs b/netcore/NetCore/ICacheFactory.cs
new file mode 100644
index 0000000..5bb2ba7
--- /dev/null
+++ b/netcore/NetCore/ICacheFactory.cs
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+
+namespace Apache.Geode.Client {
+ public interface ICacheFactory : IDisposable {
+ IGeodeCache CreateCache();
+ ICacheFactory SetProperty(String name, String value);
+ IAuthInitialize AuthInitialize { set; }
+ bool PdxIgnoreUnreadFields { set; }
+ bool PdxReadSerialized { set; }
+ String Version { get; }
+ String ProductDescription { get; }
+ }
+}
diff --git a/netcore/NetCore/IGeodeCache.cs b/netcore/NetCore/IGeodeCache.cs
new file mode 100644
index 0000000..8591db6
--- /dev/null
+++ b/netcore/NetCore/IGeodeCache.cs
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+
+namespace Apache.Geode.Client {
+ public interface IGeodeCache : IRegionService, IDisposable {
+ bool GetPdxIgnoreUnreadFields();
+ bool GetPdxReadSerialized();
+ // void InitializeDeclarativeCache(String cacheXml);
+
+ // CacheTransactionManager CacheTransactionManager { get; }
+ // DistributedSystem DistributedSystem { get; }
+ String Name { get; }
+ PoolManager PoolManager { get; }
+ PoolFactory PoolFactory { get; }
+ void Close();
+ void Close(bool keepalive);
+ bool Closed { get; }
+ }
+}
diff --git a/netcore/NetCore/IRegionService.cs b/netcore/NetCore/IRegionService.cs
new file mode 100644
index 0000000..d635d71
--- /dev/null
+++ b/netcore/NetCore/IRegionService.cs
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+
+namespace Apache.Geode.Client {
+ public interface IRegionService {
+ RegionFactory CreateRegionFactory(RegionShortcut regionType);
+ }
+}
diff --git a/netcore/NetCore/NetCore.csproj b/netcore/NetCore/NetCore.csproj
new file mode 100644
index 0000000..0258bf1
--- /dev/null
+++ b/netcore/NetCore/NetCore.csproj
@@ -0,0 +1,11 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFramework>netcoreapp3.1</TargetFramework>
+ <RootNamespace>Apache.Geode.NetCore</RootNamespace>
+ <AssemblyName>Apache.Geode.NetCore</AssemblyName>
+ <Platforms>x64</Platforms>
+ <Configurations>Debug;Release;RelWithDebInfo</Configurations>
+ </PropertyGroup>
+
+</Project>
diff --git a/netcore/NetCore/Pool.cs b/netcore/NetCore/Pool.cs
new file mode 100644
index 0000000..c3e9b81
--- /dev/null
+++ b/netcore/NetCore/Pool.cs
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Runtime.InteropServices;
+
+namespace Apache.Geode.Client {
+ public class Pool : GeodeNativeObject {
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern IntPtr apache_geode_Cache_GetPoolManager(IntPtr cache);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern IntPtr apache_geode_PoolFactory_CreatePool(IntPtr poolFactory,
+ IntPtr poolName);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern void apache_geode_DestroyPool(IntPtr pool);
+
+ internal Pool(IntPtr poolFactory, string poolName) {
+ var poolNamePtr = Marshal.StringToCoTaskMemUTF8(poolName);
+ _containedObject = apache_geode_PoolFactory_CreatePool(poolFactory, poolNamePtr);
+ Marshal.FreeCoTaskMem(poolNamePtr);
+ }
+
+ protected override void DestroyContainedObject() {
+ apache_geode_DestroyPool(_containedObject);
+ _containedObject = IntPtr.Zero;
+ }
+ }
+}
diff --git a/netcore/NetCore/PoolFactory.cs b/netcore/NetCore/PoolFactory.cs
new file mode 100644
index 0000000..c00e8c8
--- /dev/null
+++ b/netcore/NetCore/PoolFactory.cs
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Runtime.InteropServices;
+
+namespace Apache.Geode.Client {
+ public class PoolFactory : GeodeNativeObject {
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern IntPtr apache_geode_Cache_GetPoolManager(IntPtr cache);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern IntPtr apache_geode_PoolManager_CreateFactory(IntPtr poolManager);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern IntPtr apache_geode_PoolFactory_AddLocator(IntPtr poolManager,
+ IntPtr hostname, int port);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern IntPtr apache_geode_DestroyPoolFactory(IntPtr poolManager);
+
+ internal PoolFactory(IntPtr poolManager) {
+ _containedObject = apache_geode_PoolManager_CreateFactory(poolManager);
+ }
+
+ public PoolFactory AddLocator(string hostname, int port) {
+ var hostnamePtr = Marshal.StringToCoTaskMemUTF8(hostname);
+ apache_geode_PoolFactory_AddLocator(_containedObject, hostnamePtr, port);
+ Marshal.FreeCoTaskMem(hostnamePtr);
+ return this;
+ }
+
+ public Pool CreatePool(string poolName) {
+ return new Pool(_containedObject, poolName);
+ }
+
+ protected override void DestroyContainedObject() {
+ apache_geode_DestroyPoolFactory(_containedObject);
+ _containedObject = IntPtr.Zero;
+ }
+ }
+}
diff --git a/netcore/NetCore/PoolManager.cs b/netcore/NetCore/PoolManager.cs
new file mode 100644
index 0000000..5a06436
--- /dev/null
+++ b/netcore/NetCore/PoolManager.cs
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Runtime.InteropServices;
+
+namespace Apache.Geode.Client {
+ public class PoolManager : GeodeNativeObject {
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern IntPtr apache_geode_Cache_GetPoolManager(IntPtr cache);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern IntPtr apache_geode_DestroyPoolManager(IntPtr poolManager);
+
+ internal PoolManager(IntPtr cache) {
+ _containedObject = apache_geode_Cache_GetPoolManager(cache);
+ }
+
+ public PoolFactory CreatePoolFactory() {
+ return new PoolFactory(_containedObject);
+ }
+
+ protected override void DestroyContainedObject() {
+ apache_geode_DestroyPoolManager(_containedObject);
+ _containedObject = IntPtr.Zero;
+ }
+ }
+}
diff --git a/netcore/NetCore/Region.cs b/netcore/NetCore/Region.cs
new file mode 100644
index 0000000..68d49a5
--- /dev/null
+++ b/netcore/NetCore/Region.cs
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Runtime.InteropServices;
+
+namespace Apache.Geode.Client {
+ public class Region : GeodeNativeObject {
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern IntPtr apache_geode_RegionFactory_CreateRegion(IntPtr cache,
+ IntPtr regionName);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern bool apache_geode_Region_PutString(IntPtr region, IntPtr key,
+ IntPtr value);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern bool apache_geode_Region_PutByteArray(IntPtr region, IntPtr key,
+ IntPtr value, int length);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern IntPtr apache_geode_Region_GetString(IntPtr region, IntPtr key);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern void apache_geode_Region_GetByteArray(IntPtr region, IntPtr key,
+ ref IntPtr value, ref int size);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern void apache_geode_Region_Remove(IntPtr region, IntPtr key);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern bool apache_geode_Region_ContainsValueForKey(IntPtr region,
+ IntPtr key);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern IntPtr apache_geode_DestroyRegion(IntPtr region);
+
+ internal Region(IntPtr regionFactory, string regionName) {
+ var regionNamePtr = Marshal.StringToCoTaskMemUTF8(regionName);
+ _containedObject = apache_geode_RegionFactory_CreateRegion(regionFactory, regionNamePtr);
+ Marshal.FreeCoTaskMem(regionNamePtr);
+ }
+
+ public void PutString(string key, string value) {
+ var keyPtr = Marshal.StringToCoTaskMemUTF8(key);
+ var valuePtr = Marshal.StringToCoTaskMemUTF8(value);
+ apache_geode_Region_PutString(_containedObject, keyPtr, valuePtr);
+ Marshal.FreeCoTaskMem(keyPtr);
+ Marshal.FreeCoTaskMem(valuePtr);
+ }
+
+ public void PutByteArray(string key, byte[] value) {
+ var keyPtr = Marshal.StringToCoTaskMemUTF8(key);
+ var valuePtr = Marshal.AllocCoTaskMem(value.Length);
+ Marshal.Copy(value, 0, valuePtr, value.Length);
+ apache_geode_Region_PutByteArray(_containedObject, keyPtr, valuePtr, value.Length);
+ Marshal.FreeCoTaskMem(keyPtr);
+ Marshal.FreeCoTaskMem(valuePtr);
+ }
+
+ public string GetString(string key) {
+ var keyPtr = Marshal.StringToCoTaskMemUTF8(key);
+ var result =
+ Marshal.PtrToStringUTF8(apache_geode_Region_GetString(_containedObject, keyPtr));
+ Marshal.FreeCoTaskMem(keyPtr);
+ return result;
+ }
+
+ public byte[] GetByteArray(string key) {
+ var keyPtr = Marshal.StringToCoTaskMemUTF8(key);
+ var valPtr = (IntPtr)0;
+ int size = 0;
+ apache_geode_Region_GetByteArray(_containedObject, keyPtr, ref valPtr, ref size);
+ if (size > 0) {
+ Byte[] byteArray = new Byte[size];
+ Marshal.Copy(valPtr, byteArray, 0, size);
+ Marshal.FreeCoTaskMem(valPtr);
+ return byteArray;
+ } else
+ return null;
+ }
+
+ public void Remove(string key) {
+ var keyPtr = Marshal.StringToCoTaskMemUTF8(key);
+ apache_geode_Region_Remove(_containedObject, keyPtr);
+ Marshal.FreeCoTaskMem(keyPtr);
+ }
+
+ public bool ContainsValueForKey(string key) {
+ var keyPtr = Marshal.StringToCoTaskMemUTF8(key);
+ bool result = apache_geode_Region_ContainsValueForKey(_containedObject, keyPtr);
+ Marshal.FreeCoTaskMem(keyPtr);
+ return result;
+ }
+
+ protected override void DestroyContainedObject() {
+ apache_geode_DestroyRegion(_containedObject);
+ _containedObject = IntPtr.Zero;
+ }
+ }
+}
diff --git a/netcore/NetCore/RegionFactory.cs b/netcore/NetCore/RegionFactory.cs
new file mode 100644
index 0000000..0cf2fd9
--- /dev/null
+++ b/netcore/NetCore/RegionFactory.cs
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using System.Runtime.InteropServices;
+
+namespace Apache.Geode.Client {
+ public class RegionFactory : GeodeNativeObject {
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern IntPtr apache_geode_Cache_CreateRegionFactory(IntPtr cache,
+ int regionType);
+
+ [DllImport(Constants.libPath, CharSet = CharSet.Auto)]
+ private static extern IntPtr apache_geode_DestroyRegionFactory(IntPtr regionFactory);
+
+ internal RegionFactory(IntPtr cache, RegionShortcut regionType) {
+ _containedObject = apache_geode_Cache_CreateRegionFactory(cache, (int)regionType);
+ }
+
+ public Region CreateRegion(string regionName) {
+ return new Region(_containedObject, regionName);
+ }
+
+ protected override void DestroyContainedObject() {
+ apache_geode_DestroyRegionFactory(_containedObject);
+ _containedObject = IntPtr.Zero;
+ }
+ }
+}
diff --git a/netcore/NetCore/RegionShortcut.cs b/netcore/NetCore/RegionShortcut.cs
new file mode 100644
index 0000000..6e1738a
--- /dev/null
+++ b/netcore/NetCore/RegionShortcut.cs
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+namespace Apache.Geode.Client {
+ public enum RegionShortcut {
+ Proxy = 0,
+ CachingProxy = 1,
+ CachingProxyEntryLru = 2,
+ Local = 3,
+ LocalEntryLru = 4
+ }
+}
diff --git a/netcore/geode-dotnet-core.sln b/netcore/geode-dotnet-core.sln
new file mode 100644
index 0000000..830ad88
--- /dev/null
+++ b/netcore/geode-dotnet-core.sln
@@ -0,0 +1,31 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.30001.183
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCore", "NetCore\NetCore.csproj", "{09ABBCE7-B217-43F1-A51B-CC5BDCD8EE98}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCore.Test", "NetCore.Test\NetCore.Test.csproj", "{501DEA7E-8985-42A8-8BC9-C073E1B6DFE0}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x64 = Debug|x64
+ Release|x64 = Release|x64
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {09ABBCE7-B217-43F1-A51B-CC5BDCD8EE98}.Debug|x64.ActiveCfg = Debug|x64
+ {09ABBCE7-B217-43F1-A51B-CC5BDCD8EE98}.Debug|x64.Build.0 = Debug|x64
+ {09ABBCE7-B217-43F1-A51B-CC5BDCD8EE98}.Release|x64.ActiveCfg = Release|x64
+ {09ABBCE7-B217-43F1-A51B-CC5BDCD8EE98}.Release|x64.Build.0 = Release|x64
+ {501DEA7E-8985-42A8-8BC9-C073E1B6DFE0}.Debug|x64.ActiveCfg = Debug|x64
+ {501DEA7E-8985-42A8-8BC9-C073E1B6DFE0}.Debug|x64.Build.0 = Debug|x64
+ {501DEA7E-8985-42A8-8BC9-C073E1B6DFE0}.Release|x64.ActiveCfg = Release|x64
+ {501DEA7E-8985-42A8-8BC9-C073E1B6DFE0}.Release|x64.Build.0 = Release|x64
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {B30A49F0-1C96-4D6C-A222-0088B1D7FBBE}
+ EndGlobalSection
+EndGlobal
diff --git a/netcore/scripts/build-geode-native-netcore.sh b/netcore/scripts/build-geode-native-netcore.sh
new file mode 100644
index 0000000..1233582
--- /dev/null
+++ b/netcore/scripts/build-geode-native-netcore.sh
@@ -0,0 +1,54 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#!/usr/bin/env bash
+
+set -e
+set -x
+# Setup GEODE_HOME, if not set use default
+if [ "$GEODE_HOME" == "" ]; then
+ export GEODE_HOME=$HOME/src/apache-geode
+fi
+
+# Setup BUILD_HOME, if not set use default
+if [ "$BUILD_HOME" == "" ]; then
+ export BUILD_HOME=$HOME/src/geode-native/netcore/build
+fi
+
+echo "Using environment vars GEODE_HOME=${GEODE_HOME} and BUILD_HOME=${BUILD_HOME}"
+
+# Build utility .jar file # BUild NetCore library
+pushd ./NetCore
+dotnet build
+popd
+
+# Build NetCore tests
+pushd ./NetCore.Test
+dotnet build
+popd
+
+# Build utility jar file used for auth test
+pushd ./utility
+if [ -d "./build" ]; then
+ :
+else
+ mkdir build
+fi
+
+cd build
+cmake ..
+cmake --build .
+popd
+
diff --git a/netcore/scripts/run-clang-format.cmd b/netcore/scripts/run-clang-format.cmd
new file mode 100644
index 0000000..01c8f8c
--- /dev/null
+++ b/netcore/scripts/run-clang-format.cmd
@@ -0,0 +1,16 @@
+rem Licensed to the Apache Software Foundation (ASF) under one or more
+rem contributor license agreements. See the NOTICE file distributed with
+rem this work for additional information regarding copyright ownership.
+rem The ASF licenses this file to You under the Apache License, Version 2.0
+rem (the "License"); you may not use this file except in compliance with
+rem the License. You may obtain a copy of the License at
+rem
+rem http://www.apache.org/licenses/LICENSE-2.0
+rem
+rem Unless required by applicable law or agreed to in writing, software
+rem distributed under the License is distributed on an "AS IS" BASIS,
+rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+rem See the License for the specific language governing permissions and
+rem limitations under the License.
+clang-format -i --style=file NetCore/*.cs
+clang-format -i --style=file NetCore.Test/*.cs
diff --git a/netcore/scripts/startserver.ps1 b/netcore/scripts/startserver.ps1
new file mode 100644
index 0000000..704be3e
--- /dev/null
+++ b/netcore/scripts/startserver.ps1
@@ -0,0 +1,65 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+$GFSH_PATH = ""
+if (Get-Command gfsh -ErrorAction SilentlyContinue)
+{
+ $GFSH_PATH = "gfsh"
+}
+else
+{
+ if (-not (Test-Path env:GEODE_HOME))
+ {
+ Write-Host "Could not find gfsh. Please set the GEODE_HOME path. e.g. "
+ Write-Host "(Powershell) `$env:GEODE_HOME = <path to Geode>"
+ Write-Host " OR"
+ Write-Host "(Command-line) set %GEODE_HOME% = <path to Geode>"
+ exit
+ }
+ else
+ {
+ $GFSH_PATH = "$env:GEODE_HOME\bin\gfsh.bat"
+ }
+}
+
+if ($env:BUILD_HOME -eq "" -or $env:BUILD_HOME -eq $null)
+{
+ Write-Host "Please set BUILD_HOME path to the root directory of a geode-native examples build."
+ Write-Host "startserver.ps1 needs to find 'example.jar' under BUILD_HOME/utilities to work properly."
+ exit
+}
+
+$AUTH_OPTS="--J=-Dgemfire.security-username=server"
+$AUTH_OPTS="$AUTH_OPTS --J=-Dgemfire.security-password=server"
+$AUTH_OPTS="$AUTH_OPTS --classpath=$env:BUILD_HOME/utilities/example.jar"
+
+$AUTH_LOCATOR_OPTS="$AUTH_OPTS --J=-Dgemfire.security-manager=javaobject.SimpleSecurityManager"
+
+if ($GFSH_PATH -ne "")
+{
+ $expression = "$GFSH_PATH " + `
+ "-e 'start locator --name=locator --port=10334 --http-service-port=6060 --J=-Dgemfire.jmx-manager-port=1099' " + `
+ "-e 'start server --name=server --server-port=0' " + `
+ "-e 'create region --name=exampleRegion --type=PARTITION'";
+ Invoke-Expression $expression
+
+ $expression = "$GFSH_PATH " + `
+ "-e 'start locator --name=auth_locator $AUTH_LOCATOR_OPTS --port=10335 --http-service-port=7070 --J=-Dgemfire.jmx-manager-port=2099' " + `
+ "-e 'connect --locator=localhost[10335] --user=server --password=server' " + `
+ "-e 'start server --name=auth_server $AUTH_OPTS --server-port=0' " + `
+ "-e 'create region --name=authExampleRegion --type=PARTITION'";
+ Invoke-Expression $expression
+}
+
diff --git a/netcore/scripts/startserver.sh b/netcore/scripts/startserver.sh
new file mode 100644
index 0000000..10d8283
--- /dev/null
+++ b/netcore/scripts/startserver.sh
@@ -0,0 +1,48 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#!/usr/bin/env bash
+GFSH_PATH=""
+which gfsh 2> /dev/null
+
+if [ $? -eq 0 ]; then
+ GFSH_PATH="gfsh"
+else
+ if [ "$GEODE_HOME" == "" ]; then
+ echo "Could not find gfsh. Please set the GEODE_HOME path."
+ echo "e.g. export GEODE_HOME=<path to Geode>"
+ else
+ GFSH_PATH=$GEODE_HOME/bin/gfsh
+ fi
+fi
+
+if [ "$NETCORE_JAVA_BUILD_HOME" == "" ]; then
+ NETCORE_JAVA_BUILD_HOME="`pwd -P`"/utility/build
+fi
+
+
+# These security items typically go into gfsecurity.properties file. For
+# simplicity we are including the security details on the commandline.
+
+AUTH_OPTS="--J=-Dgemfire.security-username=server"
+AUTH_OPTS="${AUTH_OPTS} --J=-Dgemfire.security-password=server"
+AUTH_OPTS="${AUTH_OPTS} --classpath=${NETCORE_JAVA_BUILD_HOME}/example.jar"
+
+AUTH_LOCATOR_OPTS="${AUTH_OPTS} --J=-Dgemfire.security-manager=javaobject.SimpleSecurityManager"
+
+
+$GFSH_PATH -e "start locator --name=locator --port=10334 --http-service-port=6060 --J=-Dgemfire.jmx-manager-port=1099" -e "start server --name=server --server-port=0" -e "create region --name=exampleRegion --type=PARTITION"
+
+$GFSH_PATH -e "start locator --name=auth_locator ${AUTH_LOCATOR_OPTS} --port=10335 --http-service-port=7070 --J=-Dgemfire.jmx-manager-port=2099" -e "connect --locator=localhost[10335] --user=server --password=server" -e "start server --name=auth_server ${AUTH_OPTS} --server-port=0" -e "create region --name=authExampleRegion --type=PARTITION"
diff --git a/netcore/scripts/stopserver.ps1 b/netcore/scripts/stopserver.ps1
new file mode 100644
index 0000000..25c2034
--- /dev/null
+++ b/netcore/scripts/stopserver.ps1
@@ -0,0 +1,47 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+$GFSH_PATH = ""
+if (Get-Command gfsh -ErrorAction SilentlyContinue)
+{
+ $GFSH_PATH = "gfsh"
+}
+else
+{
+ if (-not (Test-Path env:GEODE_HOME))
+ {
+ Write-Host "Could not find gfsh. Please set the GEODE_HOME path. e.g. "
+ Write-Host "(Powershell) `$env:GEODE_HOME = <path to Geode>"
+ Write-Host " OR"
+ Write-Host "(Command-line) set %GEODE_HOME% = <path to Geode>"
+ exit
+ }
+ else
+ {
+ $GFSH_PATH = "$env:GEODE_HOME\bin\gfsh.bat"
+ }
+}
+
+if ($GFSH_PATH -ne "")
+{
+ Invoke-Expression "$GFSH_PATH -e 'connect --locator=localhost[10335] --user=server --password=server' -e 'shutdown --include-locators=true'"
+ Invoke-Expression "$GFSH_PATH -e 'connect --locator=localhost[10334]' -e 'shutdown --include-locators=true'"
+ Start-Sleep -Seconds 5
+ Remove-Item -LiteralPath "locator" -Force -Recurse
+ Remove-Item -LiteralPath "server" -Force -Recurse
+ Remove-Item -LiteralPath "auth_locator" -Force -Recurse
+ Remove-Item -LiteralPath "auth_server" -Force -Recurse
+}
+
diff --git a/netcore/scripts/stopserver.sh b/netcore/scripts/stopserver.sh
new file mode 100644
index 0000000..d1ab4fa
--- /dev/null
+++ b/netcore/scripts/stopserver.sh
@@ -0,0 +1,35 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#!/usr/bin/env bash
+GFSH_PATH=""
+which gfsh 2> /dev/null
+
+if [ $? -eq 0 ]; then
+ GFSH_PATH="gfsh"
+else
+ if [ "$GEODE_HOME" == "" ]; then
+ echo "Could not find gfsh. Please set the GEODE_HOME path."
+ echo "e.g. export GEODE_HOME=<path to Geode>"
+ else
+ GFSH_PATH=$GEODE_HOME/bin/gfsh
+ fi
+fi
+
+$GFSH_PATH -e "connect --locator=localhost[10335] --user=server --password=server" -e "shutdown --include-locators=true"
+$GFSH_PATH -e "connect --locator=localhost[10334]" -e "shutdown --include-locators=true"
+
+rm -rf locator server auth_locator auth_server
+
diff --git a/netcore/utility/CMakeLists.txt b/netcore/utility/CMakeLists.txt
new file mode 100644
index 0000000..2640b07
--- /dev/null
+++ b/netcore/utility/CMakeLists.txt
@@ -0,0 +1,35 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+cmake_minimum_required (VERSION 3.10)
+project (example)
+
+set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake)
+
+find_package(Geode REQUIRED)
+find_package(Java REQUIRED)
+
+include(UseJava)
+
+file(GLOB_RECURSE SOURCES "*.java")
+
+add_jar(example ${SOURCES}
+ INCLUDE_JARS ${Geode_CLASSPATH}
+)
+
+file(GLOB SSL_CERTIFICATES
+ "${CMAKE_CURRENT_SOURCE_DIR}/*Keys"
+)
+
+
diff --git a/netcore/utility/SimpleSecurityManager.java b/netcore/utility/SimpleSecurityManager.java
new file mode 100644
index 0000000..7dc8bd7
--- /dev/null
+++ b/netcore/utility/SimpleSecurityManager.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package javaobject;
+
+import org.apache.geode.security.AuthenticationFailedException;
+import org.apache.geode.security.SecurityManager;
+
+import java.util.Properties;
+
+import javaobject.UserPasswordAuthInit;
+import javaobject.UsernamePrincipal;
+
+/**
+ * This Security manager only Authenticates - and allows any operations.
+ */
+public class SimpleSecurityManager implements SecurityManager {
+
+
+ /**
+ * Verify the credentials provided in the properties
+ * <p>
+ * Your security manager needs to validate credentials coming from all communication channels.
+ * If you use AuthInitialize to generate your client/peer credentials, then the input of this
+ * method is the output of your AuthInitialize.getCredentials method. But remember that this
+ * method will also need to validate credentials coming from gfsh/jmx/rest client, the framework
+ * is putting the username/password under security-username and security-password keys in the
+ * property, so your securityManager implementation needs to validate these kind of properties
+ * as well.
+ *
+ * @param credentials it contains the security-username and security-password as keys of the
+ * properties, also the properties generated by your AuthInitialize interface
+ * @return a serializable principal object
+ */
+ @Override
+ public Object authenticate(Properties props) throws AuthenticationFailedException {
+ String userName = props.getProperty(UserPasswordAuthInit.USER_NAME);
+ if (userName == null) {
+ throw new AuthenticationFailedException(
+ "SimpleSecurityManager: user name property ["
+ + UserPasswordAuthInit.USER_NAME + "] not provided");
+ }
+ String password = props.getProperty(UserPasswordAuthInit.PASSWORD);
+ if (password == null) {
+ throw new AuthenticationFailedException(
+ "SimpleSecurityManager: password property ["
+ + UserPasswordAuthInit.PASSWORD + "] not provided");
+ }
+
+ if (userName.equals(password) && testValidName(userName)) {
+ return new UsernamePrincipal(userName);
+ } else {
+ throw new AuthenticationFailedException(
+ "SimpleSecurityManager: Invalid user name [" + userName
+ + "], password supplied.");
+ }
+ }
+
+ private boolean testValidName(String userName) {
+
+ return (userName.startsWith("server") || userName.startsWith("user")
+ || userName.startsWith("reader") || userName.startsWith("writer")
+ || userName.equals("admin") || userName.equals("root")
+ || userName.equals("administrator"));
+ }
+}
diff --git a/netcore/utility/UserPasswordAuthInit.java b/netcore/utility/UserPasswordAuthInit.java
new file mode 100644
index 0000000..d40ba67
--- /dev/null
+++ b/netcore/utility/UserPasswordAuthInit.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package javaobject;
+
+import java.util.Properties;
+
+import org.apache.geode.LogWriter;
+import org.apache.geode.distributed.DistributedMember;
+import org.apache.geode.security.AuthInitialize;
+import org.apache.geode.security.AuthenticationFailedException;
+
+/**
+ * An {@link AuthInitialize} implementation that obtains the user name and
+ * password as the credentials from the given set of properties.
+ *
+ * To use this class the <c>security-client-auth-init</c> property should be
+ * set to the fully qualified name the static <code>create</code> function
+ * viz. <code>templates.security.UserPasswordAuthInit.create</code>
+ *
+ */
+public class UserPasswordAuthInit implements AuthInitialize {
+
+ public static final String USER_NAME = "security-username";
+
+ public static final String PASSWORD = "security-password";
+
+ protected LogWriter securitylog;
+
+ protected LogWriter systemlog;
+
+ public static AuthInitialize create() {
+ return new UserPasswordAuthInit();
+ }
+
+ public void init(LogWriter systemLogger, LogWriter securityLogger)
+ throws AuthenticationFailedException {
+ this.systemlog = systemLogger;
+ this.securitylog = securityLogger;
+ }
+
+ public UserPasswordAuthInit() {
+ }
+
+ public Properties getCredentials(Properties props, DistributedMember server,
+ boolean isPeer) throws AuthenticationFailedException {
+
+ Properties newProps = new Properties();
+ String userName = props.getProperty(USER_NAME);
+ if (userName == null) {
+ throw new AuthenticationFailedException(
+ "UserPasswordAuthInit: user name property [" + USER_NAME
+ + "] not set.");
+ }
+ newProps.setProperty(USER_NAME, userName);
+ String passwd = props.getProperty(PASSWORD);
+ // If password is not provided then use empty string as the password.
+ if (passwd == null) {
+ passwd = "";
+ }
+ newProps.setProperty(PASSWORD, passwd);
+ return newProps;
+ }
+
+ public void close() {
+ }
+
+}
diff --git a/netcore/utility/UsernamePrincipal.java b/netcore/utility/UsernamePrincipal.java
new file mode 100644
index 0000000..faeb770
--- /dev/null
+++ b/netcore/utility/UsernamePrincipal.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package javaobject;
+
+import java.io.Serializable;
+import java.security.Principal;
+
+/**
+ * An implementation of {@link Principal} class for a simple user name.
+ *
+ */
+public class UsernamePrincipal implements Principal, Serializable {
+
+ private final String userName;
+
+ public UsernamePrincipal(String userName) {
+ this.userName = userName;
+ }
+
+ public String getName() {
+ return this.userName;
+ }
+
+ @Override
+ public String toString() {
+ return this.userName;
+ }
+
+}