Skip to content

Commit

Permalink
Enh 37059890 - Port UniversalExtractor and UniversalUpdater to C++ an…
Browse files Browse the repository at this point in the history
…d .NET

- UniversalUpdater

[git-p4: depot-paths = "//dev/main.net/": change = 111548]
  • Loading branch information
fryp committed Sep 24, 2024
1 parent 8fc8593 commit d4ea212
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/Coherence/Config/coherence-pof-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,11 @@
<class-name>Tangosol.Util.Extractor.UniversalExtractor, Coherence</class-name>
</user-type>

<user-type>
<type-id>193</type-id>
<class-name>Tangosol.Util.Extractor.UniversalUpdater, Coherence</class-name>
</user-type>

<!-- Tangosol.Util.Aggregator namespace (continued) (250-259) -->

<user-type>
Expand Down
137 changes: 137 additions & 0 deletions src/Coherence/Util/Extractor/UniversalUpdater.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
*/
using System;
using System.Diagnostics;
using System.IO;

using Tangosol.IO.Pof;

namespace Tangosol.Util.Extractor
{
/// <summary>
/// Universal <see cref="IValueUpdater"/> implementation.
/// </summary>
/// <remarks>
/// UniversalUpdater can only run within the Coherence cluster.
/// Refer to the Coherence for Java documentation for more information.
/// </remarks>
/// <author>Gene Gleyzer 2005.10.27</author>
/// <author>Joe Fialli 2017.11.28</author>
/// <author>Patrick Fry 2024.09.23</author>
/// <since>14.1.2.0.0</since>
public class UniversalUpdater : IValueUpdater, IPortableObject
{
#region Properties

/// <summary>
/// Get the method or property name.
/// </summary>
/// <value>
/// the method or property name.
/// </value>
public virtual string Name
{
get { return m_name; }
}

#endregion

#region Constructors

/// <summary>
/// Default constructor (necessary for the IPortableObject interface).
/// </summary>
public UniversalUpdater()
{
}

/// <summary>
/// Construct a UniversalUpdater for the provided name.
/// </summary>
/// <param name="name">
/// A method or property name.
/// </param>
public UniversalUpdater(string name)
{
Debug.Assert(name != null);

m_name = name;
}

#endregion

#region IValueUpdater implementation

/// <summary>
/// Update the passed target object using the specified value.
/// </summary>
/// <remarks>
/// This method will always throw a <see cref="NotSupportedException"/>
/// if called directly by the .NET client application, as its execution
/// is only meaningful within the cluster.
/// </remarks>
/// <param name="target">
/// The object to update.
/// </param>
/// <param name="value">
/// The new value to update the target's property with.
/// </param>
/// <exception cref="NotSupportedException">
/// Always, as it is expected that this extractor will only be
/// executed within the cluster.
/// </exception>
public void Update(object target, object value)
{
throw new NotSupportedException();
}

#endregion

#region IPortableObject implementation

/// <summary>
/// Restore the contents of a user type instance by reading its state
/// using the specified <see cref="IPofReader"/> object.
/// </summary>
/// <param name="reader">
/// The <b>IPofReader</b> from which to read the object's state.
/// </param>
/// <exception cref="IOException">
/// If an I/O error occurs.
/// </exception>
public void ReadExternal(IPofReader reader)
{
m_name = reader.ReadString(0);
}

/// <summary>
/// Save the contents of a POF user type instance by writing its
/// state using the specified <see cref="IPofWriter"/> object.
/// </summary>
/// <param name="writer">
/// The <b>IPofWriter</b> to which to write the object's state.
/// </param>
/// <exception cref="IOException">
/// If an I/O error occurs.
/// </exception>
public void WriteExternal(IPofWriter writer)
{
writer.WriteString(0, Name);
}

#endregion

#region Data members

/// <summary>
/// A method name, or a property name.
/// </summary>
protected string m_name;

#endregion
}
}
32 changes: 29 additions & 3 deletions tests/Coherence.Tests/Util/Extractor/UpdaterTests.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
/*
* Copyright (c) 2000, 2020, Oracle and/or its affiliates.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
* https://oss.oracle.com/licenses/upl.
*/
using System;
using System.Collections.Specialized;
using System.IO;

using NUnit.Framework;

using Tangosol.IO;
using Tangosol.IO.Pof;
using Tangosol.IO.Pof.Reflection;
using Tangosol.Net;
using Tangosol.Net.Cache;
using Tangosol.Util.Processor;

namespace Tangosol.Util.Extractor
Expand Down Expand Up @@ -160,5 +163,28 @@ public void TestPofUpdater()

CacheFactory.Shutdown();
}

[Test]
public void TestUniversalUpdater()
{
INamedCache cache = CacheFactory.GetCache(CacheName);
cache.Clear();

string key = "p1";
string lastName = "Van Halen";
SimplePerson person = new SimplePerson("123-45-6789", "Eddie", lastName, 1955,
"987-65-4321", new String[] { "456-78-9123" });
UniversalUpdater updater = new UniversalUpdater("LastName");

cache[key] = person;
Assert.AreEqual(lastName, ((SimplePerson) cache[key]).LastName);

// update the last name
lastName = "Van Helen";
cache.Invoke(key, new UpdaterProcessor(updater, lastName));
Assert.AreEqual(lastName, ((SimplePerson) cache[key]).LastName);

CacheFactory.Shutdown();
}
}
}
}

0 comments on commit d4ea212

Please sign in to comment.