Project

General

Profile

« Previous | Next » 

Revision c337dd1c

Added by Leszek Koltunski about 3 years ago

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

View differences:

src/main/java/org/distorted/library/message/EffectMessageSender.java
47 47
  private static Vector<Message> mList     = null;
48 48
  private static EffectMessageSender mThis = null;
49 49
  private static volatile boolean mNotify  = false;
50
  private static volatile boolean mRunning = false;
50
  private static int mNumStarts            = 0;
51 51

  
52 52
  private static long mStartTime, mStopTime;
53 53

  
......
62 62

  
63 63
  public static void startSending()
64 64
    {
65
    mStartTime = System.currentTimeMillis();
66

  
67 65
    synchronized(mLock)
68 66
      {
69
      mRunning = true;
67
      mStartTime = System.currentTimeMillis();
68
      mNumStarts++;
70 69

  
71 70
      if( mThis==null )
72 71
        {
......
74 73
        mThis = new EffectMessageSender();
75 74
        mThis.start();
76 75
        }
77
      else mLock.notify();
78 76
      }
79 77
    }
80 78

  
......
82 80
  
83 81
  public static void stopSending()
84 82
    {
85
    mStopTime = System.currentTimeMillis();
86

  
87 83
    synchronized(mLock)
88 84
      {
89
      mRunning = false;
90
      if( mThis!=null ) mLock.notify();
85
      mStopTime = System.currentTimeMillis();
86
      mNumStarts--;
87

  
88
      if( mThis!=null )
89
        {
90
        mThis=null;
91
        mLock.notify();
92
        }
91 93
      }
92 94
    }
93 95
  
......
97 99
    {
98 100
    Message tmp;  
99 101
     
100
    while(mRunning)
102
    while(mThis!=null)
101 103
      {
102 104
      while( mList.size()>0 )
103 105
        {
......
116 118
        }
117 119
      }
118 120

  
119
    mThis = null;
120 121
    mList.clear();
121 122
    }
122 123
  
......
145 146
      }
146 147
    }
147 148

  
149
///////////////////////////////////////////////////////////////////////////////////////////////////
150

  
151
  public static boolean isRunning()
152
    {
153
    return mThis!=null;
154
    }
155

  
156
///////////////////////////////////////////////////////////////////////////////////////////////////
157

  
158
  public static void restartThread()
159
    {
160
    synchronized(mLock)
161
      {
162
      if( mThis==null )
163
        {
164
        if( mList==null ) mList = new Vector<>();
165
        mThis = new EffectMessageSender();
166
        mThis.start();
167
        }
168
      }
169
    }
170

  
148 171
///////////////////////////////////////////////////////////////////////////////////////////////////
149 172

  
150 173
  public static String reportState()
151 174
    {
152
    return "mRunning="+mRunning+" mNotify="+mNotify+" mThis null="+(mThis==null)+
153
           " mList elements="+mList.size()+" start time="+mStartTime+" mStopTime="+mStopTime;
175
    return "running "+(mThis!=null)+" notify="+mNotify+" elements="+mList.size()+
176
           " start="+mStartTime+" stop="+mStopTime+" numStarts="+mNumStarts;
154 177
    }
155 178
  }

Also available in: Unified diff