commit c337dd1c18f9444f4266396e3add41b789b8c9af
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Tue Sep 14 23:55:40 2021 +0200

    1) add missing call to BlockController.onPause() / onResume() to the Tutorial activity
    2) rearrange BlockController's error reporting to make the case where the MessageSender thread has died separate
    3) in such case, resurrect the thread
    4) simplify and harden the EffectMessageSender

diff --git a/src/main/java/org/distorted/library/message/EffectMessageSender.java b/src/main/java/org/distorted/library/message/EffectMessageSender.java
index ea4a0f6..82ba4c7 100644
--- a/src/main/java/org/distorted/library/message/EffectMessageSender.java
+++ b/src/main/java/org/distorted/library/message/EffectMessageSender.java
@@ -47,7 +47,7 @@ public final class EffectMessageSender extends Thread
   private static Vector<Message> mList     = null;
   private static EffectMessageSender mThis = null;
   private static volatile boolean mNotify  = false;
-  private static volatile boolean mRunning = false;
+  private static int mNumStarts            = 0;
 
   private static long mStartTime, mStopTime;
 
@@ -62,11 +62,10 @@ public final class EffectMessageSender extends Thread
 
   public static void startSending()
     {
-    mStartTime = System.currentTimeMillis();
-
     synchronized(mLock)
       {
-      mRunning = true;
+      mStartTime = System.currentTimeMillis();
+      mNumStarts++;
 
       if( mThis==null )
         {
@@ -74,7 +73,6 @@ public final class EffectMessageSender extends Thread
         mThis = new EffectMessageSender();
         mThis.start();
         }
-      else mLock.notify();
       }
     }
 
@@ -82,12 +80,16 @@ public final class EffectMessageSender extends Thread
   
   public static void stopSending()
     {
-    mStopTime = System.currentTimeMillis();
-
     synchronized(mLock)
       {
-      mRunning = false;
-      if( mThis!=null ) mLock.notify();
+      mStopTime = System.currentTimeMillis();
+      mNumStarts--;
+
+      if( mThis!=null )
+        {
+        mThis=null;
+        mLock.notify();
+        }
       }
     }
   
@@ -97,7 +99,7 @@ public final class EffectMessageSender extends Thread
     {
     Message tmp;  
      
-    while(mRunning)
+    while(mThis!=null)
       {
       while( mList.size()>0 )
         {
@@ -116,7 +118,6 @@ public final class EffectMessageSender extends Thread
         }
       }
 
-    mThis = null;
     mList.clear();
     }
   
@@ -145,11 +146,33 @@ public final class EffectMessageSender extends Thread
       }
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public static boolean isRunning()
+    {
+    return mThis!=null;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public static void restartThread()
+    {
+    synchronized(mLock)
+      {
+      if( mThis==null )
+        {
+        if( mList==null ) mList = new Vector<>();
+        mThis = new EffectMessageSender();
+        mThis.start();
+        }
+      }
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public static String reportState()
     {
-    return "mRunning="+mRunning+" mNotify="+mNotify+" mThis null="+(mThis==null)+
-           " mList elements="+mList.size()+" start time="+mStartTime+" mStopTime="+mStopTime;
+    return "running "+(mThis!=null)+" notify="+mNotify+" elements="+mList.size()+
+           " start="+mStartTime+" stop="+mStopTime+" numStarts="+mNumStarts;
     }
   }
