/// <summary>
 /// Construct an instance, for the given parameters.
 /// </summary>
 protected PrimaryBasedLogViewAdaptor(ILogViewAdaptorHost <TLogView, TLogEntry> host,
                                      TLogView initialstate, ILogConsistencyProtocolServices services)
 {
     Debug.Assert(host != null && services != null && initialstate != null);
     this.Host     = host;
     this.Services = services;
     InitializeConfirmedView(initialstate);
     worker = new BatchWorkerFromDelegate(Work);
 }
예제 #2
0
 /// <summary>
 /// Initialize a new instance of CustomStorageAdaptor class
 /// </summary>
 public CustomStorageAdaptor(ILogViewAdaptorHost <TLogView, TLogEntry> host, TLogView initialState,
                             ILogConsistencyProtocolServices services, string primaryCluster)
     : base(host, initialState, services)
 {
     if (!(host is ICustomStorageInterface <TLogView, TLogEntry>))
     {
         throw new BadProviderConfigException("Must implement ICustomStorageInterface<TLogView,TLogEntry> for CustomStorageLogView provider");
     }
     this.primaryCluster = primaryCluster;
 }
예제 #3
0
        private void InstallLogViewAdaptor(
            Factory <Grain, ILogConsistencyProtocolServices> protocolServicesFactory,
            ILogViewAdaptorFactory factory,
            IGrainStorage grainStorage)
        {
            // encapsulate runtime services used by consistency adaptors
            ILogConsistencyProtocolServices svc = protocolServicesFactory(this);

            TView state = (TView)Activator.CreateInstance(typeof(TView));

            this.InstallAdaptor(factory, state, this.GetType().FullName, grainStorage, svc);
        }
예제 #4
0
        private void InstallLogViewAdaptor(
            IMultiClusterRegistrationStrategy mcRegistrationStrategy,
            Factory <Grain, IMultiClusterRegistrationStrategy, ILogConsistencyProtocolServices> protocolServicesFactory,
            ILogViewAdaptorFactory factory,
            IStorageProvider storageProvider)
        {
            // encapsulate runtime services used by consistency adaptors
            ILogConsistencyProtocolServices svc = protocolServicesFactory(this, mcRegistrationStrategy);

            TView state = (TView)Activator.CreateInstance(typeof(TView));

            this.InstallAdaptor(factory, state, this.GetType().FullName, storageProvider, svc);
        }
예제 #5
0
        public NotificationTracker(ILogConsistencyProtocolServices services, IEnumerable <string> remoteInstances, int maxNotificationBatchSize, IConnectionIssueListener listener)
        {
            this.services = services;
            this.listener = listener;
            sendWorkers   = new Dictionary <string, NotificationWorker>();
            this.maxNotificationBatchSize = maxNotificationBatchSize;

            foreach (var x in remoteInstances)
            {
                services.Log(Severity.Verbose, "Now sending notifications to {0}", x);
                sendWorkers.Add(x, new NotificationWorker(this, x));
            }
        }
예제 #6
0
 /// <summary>
 /// if there is a recorded issue, notify listener and clear it.
 /// </summary>
 /// <param name="listener">the listener for connection issues</param>
 /// <param name="services">for reporting exceptions in listener</param>
 public void Resolve(IConnectionIssueListener listener, ILogConsistencyProtocolServices services)
 {
     if (Issue != null)
     {
         try
         {
             listener.OnConnectionIssueResolved(Issue);
         }
         catch (Exception e)
         {
             services.CaughtUserCodeException("OnConnectionIssueResolved", nameof(Record), e);
         }
         Issue = null;
     }
 }
예제 #7
0
 public ILogViewAdaptor <TLogView, TLogEntry> MakeLogViewAdaptor <TLogView, TLogEntry>(
     ILogViewAdaptorHost <TLogView, TLogEntry> hostGrain,
     TLogView initialState,
     string grainTypeName,
     IGrainStorage grainStorage,
     ILogConsistencyProtocolServices services)
     where TLogView : class, new()
     where TLogEntry : class
 {
     return(new LogViewAdaptor <TLogView, TLogEntry>(
                hostGrain,
                initialState,
                grainStorage,
                grainTypeName,
                _snapshotStrategy,
                services,
                _options.UseIndependentEventStorage,
                _eventStorage));
 }
        public LogViewAdaptor(
            ILogViewAdaptorHost <TLogView, TLogEntry> host,
            TLogView initialState,
            IGrainStorage grainStorage,
            string grainTypeName,
            Func <SnapshotStrategyInfo, bool> snapshotStrategy,
            ILogConsistencyProtocolServices services,
            bool useIndependentEventStorage,
            IGrainEventStorage eventStorage)
            : base(host, initialState, services)
        {
            _grainStorage               = grainStorage;
            _grainTypeName              = grainTypeName;
            _snapshotStrategy           = snapshotStrategy;
            _useIndependentEventStorage = useIndependentEventStorage;

            if (useIndependentEventStorage)
            {
                _eventStorage = eventStorage
                                ?? throw new ArgumentNullException(nameof(eventStorage),
                                                                   "Must set eventStorage when useIndependentEventStorage is true");
            }
        }
예제 #9
0
 /// <summary>
 /// called right after grain construction to install the log view adaptor
 /// </summary>
 /// <param name="factory"> The adaptor factory to use </param>
 /// <param name="state"> The initial state of the view </param>
 /// <param name="grainTypeName"> The type name of the grain </param>
 /// <param name="storageProvider"> The storage provider, if needed </param>
 /// <param name="services"> Protocol services </param>
 protected abstract void InstallAdaptor(ILogViewAdaptorFactory factory, object state, string grainTypeName, IStorageProvider storageProvider, ILogConsistencyProtocolServices services);
예제 #10
0
 /// <summary>
 /// Make log view adaptor
 /// </summary>
 /// <typeparam name="TView">The type of the view</typeparam>
 /// <typeparam name="TEntry">The type of the log entries</typeparam>
 /// <param name="hostGrain">The grain that is hosting this adaptor</param>
 /// <param name="initialState">The initial state for this view</param>
 /// <param name="grainTypeName">The type name of the grain</param>
 /// <param name="grainStorage">Storage provider</param>
 /// <param name="services">Runtime services for multi-cluster coherence protocols</param>
 public ILogViewAdaptor <TView, TEntry> MakeLogViewAdaptor <TView, TEntry>(ILogViewAdaptorHost <TView, TEntry> hostGrain, TView initialState, string grainTypeName, IGrainStorage grainStorage, ILogConsistencyProtocolServices services)
     where TView : class, new()
     where TEntry : class
 {
     return(new LogViewAdaptor <TView, TEntry>(hostGrain, initialState, grainStorage, grainTypeName, services));
 }
예제 #11
0
 /// <summary>
 /// Initialize a StorageProviderLogViewAdaptor class
 /// </summary>
 public LogViewAdaptor(ILogViewAdaptorHost <TLogView, TLogEntry> host, TLogView initialState, IStorageProvider globalStorageProvider, string grainTypeName, ILogConsistencyProtocolServices services)
     : base(host, initialState, services)
 {
     this.globalStorageProvider = globalStorageProvider;
     this.grainTypeName         = grainTypeName;
 }
예제 #12
0
 /// <inheritdoc/>
 public ILogViewAdaptor <TView, TEntry> MakeLogViewAdaptor <TView, TEntry>(ILogViewAdaptorHost <TView, TEntry> hostgrain, TView initialstate, string graintypename, IGrainStorage grainStorage, ILogConsistencyProtocolServices services)
     where TView : class, new()
     where TEntry : class
 {
     return(new CustomStorageAdaptor <TView, TEntry>(hostgrain, initialstate, services, PrimaryCluster));
 }
예제 #13
0
 public ILogViewAdaptor <T, E> MakeLogViewAdaptor <T, E>(ILogViewAdaptorHost <T, E> hostgrain, T initialstate, string graintypename, IStorageProvider storageProvider, ILogConsistencyProtocolServices services)
     where T : class, new() where E : class
 {
     return(new LogViewAdaptor <T, E>(hostgrain, initialstate, storageProvider, graintypename, services));
 }
예제 #14
0
 /// <summary>
 /// record a connection issue, filling in timestamps etc.
 /// and notify the listener
 /// </summary>
 /// <param name="newIssue">the connection issue to be recorded</param>
 /// <param name="listener">the listener for connection issues</param>
 /// <param name="services">for reporting exceptions in listener</param>
 public void Record(ConnectionIssue newIssue, IConnectionIssueListener listener, ILogConsistencyProtocolServices services)
 {
     newIssue.TimeStamp = DateTime.UtcNow;
     if (Issue != null)
     {
         newIssue.TimeOfFirstFailure          = Issue.TimeOfFirstFailure;
         newIssue.NumberOfConsecutiveFailures = Issue.NumberOfConsecutiveFailures + 1;
         newIssue.RetryDelay = newIssue.ComputeRetryDelay(Issue.RetryDelay);
     }
     else
     {
         newIssue.TimeOfFirstFailure          = newIssue.TimeStamp;
         newIssue.NumberOfConsecutiveFailures = 1;
         newIssue.RetryDelay = newIssue.ComputeRetryDelay(null);
     }
     try
     {
         listener.OnConnectionIssue(newIssue);
     }
     catch (Exception e)
     {
         services.CaughtUserCodeException("OnConnectionIssue", nameof(Record), e);
     }
 }
예제 #15
0
        public LogViewAdaptor(ILogViewAdaptorHost <TLogView, TLogEntry> host, TLogView initialState, string grainTypeName, ILogConsistencyProtocolServices services, DocumentClient dbClient, DocumentClient spClient, EventStorageOptions options, JsonSerializerSettings serializerSettings) : base(host, initialState, services)
        {
            _grainTypeName      = grainTypeName;
            _client             = dbClient;
            _storedProcClient   = spClient;
            _serializerSettings = serializerSettings;
            _options            = options;

            _databaseUri         = UriFactory.CreateDatabaseUri(options.DatabaseName);
            _collectionUri       = UriFactory.CreateDocumentCollectionUri(options.DatabaseName, options.CollectionName);
            _commitStoredProcUri = UriFactory.CreateStoredProcedureUri(options.DatabaseName, options.CollectionName, ServerSideRegistry.StoredProcedures.Commit);
        }
예제 #16
0
 public ILogViewAdaptor <TLogView, TLogEntry> MakeLogViewAdaptor <TLogView, TLogEntry>(ILogViewAdaptorHost <TLogView, TLogEntry> hostGrain, TLogView initialState, string grainTypeName, IStorageProvider storageProvider, ILogConsistencyProtocolServices services)
     where TLogView : class, new()
     where TLogEntry : class
 {
     return(new LogViewAdaptor <TLogView, TLogEntry>(hostGrain, initialState, grainTypeName, services, _dbClient, _spClient, _options, _serializerSettings));
 }