commit 33a4e28cc893e8dbe6c1ec5d8022b3d16a686159
Author: LeszekKoltunski <leszek@koltunski.pl>
Date:   Wed Apr 16 12:12:47 2025 +0200

    message

diff --git a/src/main/java/org/distorted/library/message/EffectListener.kt b/src/main/java/org/distorted/library/message/EffectListener.kt
index 3140ba4..973e150 100644
--- a/src/main/java/org/distorted/library/message/EffectListener.kt
+++ b/src/main/java/org/distorted/library/message/EffectListener.kt
@@ -18,26 +18,21 @@
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA                //
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-package org.distorted.library.message;
+package org.distorted.library.message
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-import org.distorted.library.effect.Effect;
-
 /**
  * This interface lets users of the DistortedLibrary library get notified when a given effect finishes.
- * To receive the notifications, we first have to register with a call to {@link Effect#notifyWhenFinished(EffectListener)}.
+ * To receive the notifications, we first have to register with a call to [Effect.notifyWhenFinished].
  */
+interface EffectListener
+{
+    /**
+     * Gets called when Effect 'effectID' finishes execution (i.e. the Dynamic inside it reaches its final point).
+     *
+     * @param effectID ID of the finished effect, as returned by [org.distorted.library.effect.Effect.getID]
+     */
+    fun effectFinished(effectID: Long)
+}
 
-public interface EffectListener 
-  {
-/**
- * Gets called when Effect 'effectID' finishes execution (i.e. the Dynamic inside it reaches its final point).
- * 
- * @param effectID ID of the finished effect, as returned by {@link org.distorted.library.effect.Effect#getID() }
- */
-   
-  void effectFinished(final long effectID);
-  }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/message/EffectMessageSender.kt b/src/main/java/org/distorted/library/message/EffectMessageSender.kt
index 0bc97fc..091929f 100644
--- a/src/main/java/org/distorted/library/message/EffectMessageSender.kt
+++ b/src/main/java/org/distorted/library/message/EffectMessageSender.kt
@@ -18,11 +18,11 @@
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA                //
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-package org.distorted.library.message;
+package org.distorted.library.message
 
-import org.distorted.library.effect.Effect;
-
-import java.util.Vector;
+import org.distorted.library.effect.Effect
+import java.util.Vector
+import kotlin.concurrent.Volatile
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
@@ -30,151 +30,125 @@ import java.util.Vector;
  *
  * @y.exclude
  */
-public final class EffectMessageSender extends Thread
-  {
-  private static class Message
-    {
-    EffectListener mListener;
-    long mEffectID;
-
-    Message(EffectListener listener, long effectID)
-      {
-      mListener = listener;
-      mEffectID = effectID;
-      }
-    }
+class EffectMessageSender
+private constructor() : Thread()
+{
+    private class Message (var mListener: EffectListener, var mEffectID: Long)
 
-  private static final Object mLock        = new Object();
-  private static Vector<Message> mList     = null;
-  private static EffectMessageSender mThis = null;
-  private static volatile boolean mNotify  = false;
-
-  // debug only, to be removed later
-  private static int mNumStarts = 0;
-  private static long mStartTime, mStopTime;
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-   
-  private EffectMessageSender() 
+    override fun run()
     {
+        var tmp: Message
 
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  public static void startSending()
-    {
-    synchronized(mLock)
-      {
-      if( mThis==null )
+        while (mThis!=null)
         {
-        mStartTime = System.currentTimeMillis();
-        mNumStarts++;
-
-        mList = new Vector<>();
-        mThis = new EffectMessageSender();
-        mThis.start();
+            while (!mList!!.isEmpty())
+            {
+                tmp = mList!!.removeAt(0)
+                tmp.mListener.effectFinished(tmp.mEffectID)
+            }
+
+            synchronized(mLock)
+            {
+                if (!mNotify)
+                {
+                    try { mLock.wait() }
+                    catch (ignored: InterruptedException) { }
+                }
+                mNotify = false
+            }
         }
-      }
+
+        mList!!.clear()
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-  
-  public static void stopSending()
+    companion object
     {
-    synchronized(mLock)
-      {
-      if( mThis!=null )
-        {
-        mStopTime = System.currentTimeMillis();
-        mNumStarts--;
+        private val mLock = Object()
+        private var mList: Vector<Message>? = null
+        private var mThis: EffectMessageSender? = null
 
-        mThis=null;
-        mLock.notify();
-        }
-      }
-    }
-  
-///////////////////////////////////////////////////////////////////////////////////////////////////
-  
-  public void run()
-    {
-    Message tmp;  
-     
-    while(mThis!=null)
-      {
-      while( !mList.isEmpty() )
-        {
-        tmp = mList.remove(0);
-        tmp.mListener.effectFinished(tmp.mEffectID);
-        }
+        @Volatile
+        private var mNotify = false
 
-      synchronized(mLock)
+        // debug only, to be removed later
+        private var mNumStarts       = 0
+        private var mStartTime: Long = 0
+        private var mStopTime: Long  = 0
+
+        @JvmStatic fun startSending()
         {
-        if (!mNotify)
-          {
-          try  { mLock.wait(); }
-          catch(InterruptedException ignored) { }
-          }
-        mNotify = false;
+            synchronized(mLock)
+            {
+                if (mThis==null)
+                {
+                    mStartTime = System.currentTimeMillis()
+                    mNumStarts++
+
+                    mList = Vector()
+                    mThis = EffectMessageSender()
+                    mThis!!.start()
+                }
+            }
         }
-      }
-
-    mList.clear();
-    }
-  
-///////////////////////////////////////////////////////////////////////////////////////////////////
-        
-  public static void newMessage(Effect effect)
-    {
-    int numListeners = effect.getNumListeners();
 
-    if( numListeners>0 )
-      {
-      long id = effect.getID();
-
-      for(int i=0; i<numListeners; i++)
+        @JvmStatic fun stopSending()
         {
-        EffectListener listener = effect.removeFirstListener();
-        Message msg = new Message(listener,id);
-        mList.add(msg);
+            synchronized(mLock)
+            {
+                if (mThis!=null)
+                {
+                    mStopTime = System.currentTimeMillis()
+                    mNumStarts--
+
+                    mThis = null
+                    mLock.notify()
+                }
+            }
         }
 
-      synchronized(mLock)
+        @JvmStatic fun newMessage(effect: Effect)
         {
-        mNotify = true;
-        mLock.notify();
+            val numListeners = effect.numListeners
+
+            if (numListeners>0)
+            {
+                val id = effect.id
+
+                for (i in 0 until numListeners)
+                {
+                    val listener = effect.removeFirstListener()
+                    val msg = Message(listener, id)
+                    mList!!.add(msg)
+                }
+
+                synchronized(mLock)
+                {
+                    mNotify = true
+                    mLock.notify()
+                }
+            }
         }
-      }
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  public static boolean isRunning()
-    {
-    return mThis!=null;
-    }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
+        @JvmStatic val isRunning: Boolean
+            get() = mThis!=null
 
-  public static void restartThread()
-    {
-    synchronized(mLock)
-      {
-      if( mThis==null )
+        @JvmStatic fun restartThread()
         {
-        if( mList==null ) mList = new Vector<>();
-        mThis = new EffectMessageSender();
-        mThis.start();
+            synchronized(mLock)
+            {
+                if (mThis==null)
+                {
+                    if (mList==null) mList = Vector()
+                    mThis = EffectMessageSender()
+                    mThis!!.start()
+                }
+            }
         }
-      }
-    }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  public static String reportState()
-    {
-    return "running "+(mThis!=null)+" notify="+mNotify+" elements="+mList.size()+
-           " start="+mStartTime+" stop="+mStopTime+" numStarts="+mNumStarts;
+        @JvmStatic fun reportState(): String
+        {
+            return "running "+(mThis!=null)+" notify="+mNotify+" elements="+mList!!.size+
+                    " start="+mStartTime+" stop="+mStopTime+" numStarts="+mNumStarts
+        }
     }
-  }
+}
