Class AbstractSynchronizedStateProvider<P,​F>

  • All Implemented Interfaces:
    SynchronizedStateProvider<P,​F>

    public abstract class AbstractSynchronizedStateProvider<P,​F>
    extends java.lang.Object
    implements SynchronizedStateProvider<P,​F>
    A simple base definition for SynchronizedStateProvider. Does the following by default:
    - Returns FALSE for isBidirectional()
    - Returns a random uuid for default initial version.
    • Constructor Detail

      • AbstractSynchronizedStateProvider

        public AbstractSynchronizedStateProvider​(GatewayContext context,
                                                 java.lang.String id)
    • Method Detail

      • getLogger

        protected LoggerEx getLogger()
      • createLogger

        protected abstract LoggerEx createLogger()
      • isStarted

        protected boolean isStarted()
      • isMaster

        protected boolean isMaster()
      • isActive

        protected boolean isActive()
      • init

        public void init​(SyncController controller)
        Description copied from interface: SynchronizedStateProvider
        "Starts" the provider. The controller can be used to request sync whenever the provider thinks there has been a change. It can be called freely, the parent system will coalesce calls into single operations that happen periodically.
        Specified by:
        init in interface SynchronizedStateProvider<P,​F>
      • shutdown

        public void shutdown()
        Description copied from interface: SynchronizedStateProvider
        Called when the system is being shut down or the gateway has changed role. It should be expected that startup may be called again on the same instance.
        Specified by:
        shutdown in interface SynchronizedStateProvider<P,​F>
      • initializeVersion

        protected VersionToken initializeVersion()
        Called when starting up, should generate a version that represents the current state.
      • incrementVersion

        protected void incrementVersion()
        Helper function - Updates the version revision and requests sync.
      • hasChanges

        protected boolean hasChanges()
        Returns whether we have partial changes we expect to sync. Should be overridden for bi-directional providers, especially if using updateBiDirectionalVersion.
      • updateBiDirectionalVersion

        protected void updateBiDirectionalVersion​(VersionToken incoming)
      • getVersion

        public VersionToken getVersion()
        Description copied from interface: SynchronizedStateProvider
        This represents the current version of the state. It is a *little* tricky, however, when it comes to bi-directional states. Bi-directional states mean that changes can happen on both sides and are merged when synchronized. How this works: 1) Utimately the goal is to have the version be the same on both sides. 2) The state synchronizer will keep track of the last version seen, both locally and remotely. 3) When a partial state is applied here, this provider determines if it still has changes. If so, it requests a sync. 4) When the partial pull comes in, it will be for an older revision- this revision is relative to this side. At this point, the provider returns the outstanding changes with an id equal to what was last received. If in the mean time the other side has modified the state again, it the cycle would continue- except in step 3 there shouldn't be any more outstanding changes. This logic is handled by the AbstractSynchronizedStateProvider.
        Specified by:
        getVersion in interface SynchronizedStateProvider<P,​F>
      • setVersion

        protected void setVersion​(VersionToken version)
      • requestSync

        protected void requestSync()
      • requestForcedSync

        protected void requestForcedSync()