Alachisoft NCache 4.1 - Online Documentation

Implementing IBridgeConflictResolver Interface

 
NOTE: This feature is not available in NCache Express and Professional edition.
 
Implementing IBridgeConflictResolver
 
Following is a list of methods needs to be defined by the class implementing interface and a brief description of their purpose.
 
  • void Init(IDictionary parameters);
 
This method performs tasks like allocating resources, acquiring connections etc. When the cache is initialized and finds that the Conflict Resolvers is enabled, it calls the Init method to notify the client that cache is initializing and you may initialize your conflict resolver too. The parameters passed as an argument contains all the parameters (if any) that were specified using NCache Manager cache/cluster views. These parameters can be utilized in many ways.
 
  • void Dispose();
 
This method performs tasks like releasing the resources etc. When Cache is stopped or the task is completed, it calls the Dispose() method to notify the client that you can free the resources related to your task.
 
  • ConflictResolution Resolve(ProviderBridgeItem oldEntry, ProviderBridgeItem newEntry);
 
This method should contain the logic to resolve the conflict occur while replicating an operation from bridge for a key that already exists in the cache. Whenever any conflict occurs, cache call BridgeConflictResolution to decides which operation to apply on the cache depending upon rules implemented in it. It takes two parameters/entries, both are of ProviderBridgeItem type. ProviderBridgeItem contains the following parameters:
 
  • BridgeItemVersion contains version of an item.
  • Key contains key of an item.
  • Value of an item contains value of an item.
  • BridgeItemOpCodes contains conflicted operation.
 
 
Using IBridgeConflictResolver:
 
Here is how your class should look like for IBridgeConflictResolver:
 
namespace BridgeConflictResolverImpl
{
    public class BridgeConflictResolverImpl : IBridgeConflictResolver
    {
        private bool _enableLogging;
        private TextWriter _textLogger;
 
        #region IBridgeConflictResolver Members
 
        public void Init(System.Collections.IDictionary parameters)
        {
            if (parameters.Contains("logging"))
            {
                _enableLogging = Convert.ToBoolean(parameters["logging"]);
            }
 
            if (_enableLogging)
            {
              _textLogger = new StreamWriter("bridgeResolverLog.txt");
              _textLogger.WriteLine("Initializing bridg Conflict Resolver");
            }
        }
 
        public ConflictResolution Resolve(ProviderBridgeItem oldEntry, ProviderBridgeItem newEntry)
        {
            ConflictResolution conflictResolution = new ConflictResolution();
            switch (oldEntry.BridgeItemVersion)
            {
                case BridgeItemVersion.OLD:
                {
                    conflictResolution.ResolutionAction = ResolutionAction.ReplaceWithNewEntry;
                }
                break;
                case BridgeItemVersion.LATEST:
                {
                    conflictResolution.ResolutionAction = ResolutionAction.KeepOldEntry;
                }
                break;
                case BridgeItemVersion.SAME:
                {
                    if (oldEntry.OpCode == BridgeItemOpCodes.Remove)
                    {
                        conflictResolution.ResolutionAction = ResolutionAction.ReplaceWithNewEntry;
                    }
                    else
                    {
                        conflictResolution.ResolutionAction = ResolutionAction.KeepOldEntry;
                    }
                }
                break;
            }
 
            if (_enableLogging)
                _textLogger.WriteLine("Resolve Key {0} and decision taken {1}", oldEntry.Key, conflictResolution.ResolutionAction.ToString());
 
            return conflictResolution;
        }
 
        public void Dispose()
        {
            if (_enableLogging)
            {
                _textLogger.WriteLine("Closing logger");
                _textLogger.Close();
            }
        }
        #endregion
    }
}
 
 
NCache logs the warnings in Application event log in case of an exception during loading the assemblies.
 
 
See Also
 
Copyright © 2005-2012 Alachisoft. All rights reserved.