Class RuntimeManager


  • public class RuntimeManager
    extends java.lang.Object
    Manager that contains library state and locks
    • Constructor Summary

      Constructors 
      Constructor Description
      RuntimeManager()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean changeState​(ChangeStateAction action)
      Execute an action to modify the state
      boolean changeStateIf​(State wantedState, ChangeStateAction action)
      Execute an action to modify the state if the current state equals the wanted one
      void clearSessionManager()  
      void decrementServiceRefCount()
      Decrement the number of services retaining Batch.
      android.app.Activity getActivity()
      Get the activity
      android.content.Context getContext()
      Get the context
      java.util.Date getLastUserStartDate()
      Get the last time Batch was started for user activity.
      java.lang.String getSessionIdentifier()  
      SessionManager getSessionManager()  
      void incrementServiceRefCount()
      Increment the number of calls to onServiceCreate registered
      boolean isApplicationInForeground()  
      boolean isReady()
      Checks if Batch is ready
      boolean isRetainedByService()
      Checks if the service's refcount is greater than 0
      java.lang.Long onStart()
      Method to call when onStart is called to get the last stop timestamp (if any)
      This method is NOT thread safe, should only be called on a changeState method
      void onStopWithoutFinishing()
      Method to call when onStop is called without a finishing activity This method is NOT thread safe, should only be called on a changeState method
      void registerActivityListenerIfNeeded​(android.app.Application application)  
      void registerSessionManagerIfNeeded​(android.app.Application application, boolean simulateActivityStart)  
      void resetServiceRefCount()
      Forces the service ref count to be zero Dangerous
      void run​(StateAction action)
      Execute an action with read lock
      boolean runIf​(State wantedState, StateAction action)
      Execute an action with read lock if the current state equals the wanted state
      boolean runIf​(State wantedState, java.lang.Runnable action)
      Run this action if Batch is at the given wanted state
      boolean runIfReady​(java.lang.Runnable action)
      Run this action if Batch is ready
      void setActivity​(android.app.Activity activity)
      Set the activity, you should NEVER call this method outside of a changeState method
      This method is NOT thread safe
      void setContext​(android.content.Context context)
      Set the context, you should NEVER call this method outside of a changeState method
      This method is NOT thread safe
      void updateLastUserStartDate()
      Set the last time the Batch was started for user activity to now.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RuntimeManager

        public RuntimeManager()
    • Method Detail

      • changeState

        public boolean changeState​(ChangeStateAction action)
        Execute an action to modify the state
        Parameters:
        action - action that will modify the given state
        Returns:
        true if the state has been set, false otherwise
      • changeStateIf

        public boolean changeStateIf​(State wantedState,
                                     ChangeStateAction action)
        Execute an action to modify the state if the current state equals the wanted one
        Parameters:
        wantedState -
        action -
        Returns:
        true if the state has been set, false otherwise
      • run

        public void run​(StateAction action)
        Execute an action with read lock
        Parameters:
        action - action that can read the given state
      • runIf

        public boolean runIf​(State wantedState,
                             StateAction action)
        Execute an action with read lock if the current state equals the wanted state
        Parameters:
        wantedState -
        action -
        Returns:
        true if the action has been run, false otherwise
      • runIfReady

        public boolean runIfReady​(java.lang.Runnable action)
        Run this action if Batch is ready
        Parameters:
        action -
        Returns:
        true if the action has been runned, false otherwise
      • runIf

        public boolean runIf​(State wantedState,
                             java.lang.Runnable action)
        Run this action if Batch is at the given wanted state
        Parameters:
        wantedState -
        action -
        Returns:
        true if the action has been runned, false otherwise
      • onStart

        public java.lang.Long onStart()
        Method to call when onStart is called to get the last stop timestamp (if any)
        This method is NOT thread safe, should only be called on a changeState method
        Returns:
        the timestamp of the last stop if any, null otherwise. If null, you should always restart
      • onStopWithoutFinishing

        public void onStopWithoutFinishing()
        Method to call when onStop is called without a finishing activity This method is NOT thread safe, should only be called on a changeState method
      • setActivity

        public void setActivity​(android.app.Activity activity)
        Set the activity, you should NEVER call this method outside of a changeState method
        This method is NOT thread safe
        Parameters:
        activity -
      • getActivity

        public android.app.Activity getActivity()
        Get the activity
        Returns:
        activity or null depending on the state
      • incrementServiceRefCount

        public void incrementServiceRefCount()
        Increment the number of calls to onServiceCreate registered
      • decrementServiceRefCount

        public void decrementServiceRefCount()
        Decrement the number of services retaining Batch.
      • resetServiceRefCount

        public void resetServiceRefCount()
        Forces the service ref count to be zero Dangerous
      • isReady

        public boolean isReady()
        Checks if Batch is ready
      • isRetainedByService

        public boolean isRetainedByService()
        Checks if the service's refcount is greater than 0
      • updateLastUserStartDate

        public void updateLastUserStartDate()
        Set the last time the Batch was started for user activity to now. You should NEVER call this method outside of a changeState method
        This method is NOT thread safe
      • getLastUserStartDate

        public java.util.Date getLastUserStartDate()
        Get the last time Batch was started for user activity.
        Returns:
        last user activity start date or null depending on the state
      • setContext

        public void setContext​(android.content.Context context)
        Set the context, you should NEVER call this method outside of a changeState method
        This method is NOT thread safe
        Parameters:
        context -
      • getContext

        @Nullable
        public android.content.Context getContext()
        Get the context
        Returns:
        context or null
      • registerActivityListenerIfNeeded

        public void registerActivityListenerIfNeeded​(@NonNull
                                                     android.app.Application application)
      • isApplicationInForeground

        public boolean isApplicationInForeground()
      • registerSessionManagerIfNeeded

        public void registerSessionManagerIfNeeded​(@NonNull
                                                   android.app.Application application,
                                                   boolean simulateActivityStart)
      • getSessionIdentifier

        public java.lang.String getSessionIdentifier()
      • clearSessionManager

        public void clearSessionManager()