platform/bb/RubyVM/src/com/rho/ThreadQueue.java in rhodes-2.3.0 vs platform/bb/RubyVM/src/com/rho/ThreadQueue.java in rhodes-2.3.1.beta.1
- old
+ new
@@ -18,17 +18,20 @@
public interface IQueueCommand
{
public abstract boolean equals(IQueueCommand cmd);
public abstract String toString();
+
+ public abstract void cancel();
};
private RhoClassFactory m_ptrFactory;
private int m_nPollInterval;
private Object m_mxStackCommands;// = new Mutex();
private LinkedList m_stackCommands = new LinkedList();
-
+ private IQueueCommand m_pCurCmd;
+
boolean m_bNoThreaded;
public abstract void processCommand(IQueueCommand pCmd);
public void onTimeout(){}
@@ -40,10 +43,14 @@
public RhoClassFactory getFactory(){ return m_ptrFactory; }
public int getLastPollInterval(){ return 0;}
public boolean isSkipDuplicateCmd() { return false; }
+ protected Object getCommandLock(){ return m_mxStackCommands; }
+ protected IQueueCommand getCurCommand(){ return m_pCurCmd; }
+ protected LinkedList/*Ptr<IQueueCommand*>&*/ getCommands(){ return m_stackCommands; }
+
public ThreadQueue(RhoClassFactory factory)
{
super(factory);
m_nPollInterval = QUEUE_POLL_INTERVAL_SECONDS;
@@ -87,10 +94,40 @@
processCommands();
else if ( isAlive() )
stopWait();
}
+ public void stop(int nTimeoutToKill)
+ {
+ cancelCurrentCommand();
+ super.stop(nTimeoutToKill);
+ }
+
+ void cancelCurrentCommand()
+ {
+ synchronized(m_mxStackCommands)
+ {
+ if ( m_pCurCmd != null )
+ m_pCurCmd.cancel();
+ }
+ }
+
+ protected void processCommandBase(IQueueCommand pCmd)
+ {
+ synchronized(m_mxStackCommands)
+ {
+ m_pCurCmd = pCmd;
+ }
+
+ processCommand(pCmd);
+
+ synchronized(m_mxStackCommands)
+ {
+ m_pCurCmd = null;
+ }
+ }
+
public void run()
{
LOG.INFO("Starting main routine...");
int nLastPollInterval = getLastPollInterval();
@@ -153,10 +190,10 @@
synchronized(m_mxStackCommands)
{
pCmd = (IQueueCommand)m_stackCommands.removeFirst();
}
- processCommand(pCmd);
+ processCommandBase(pCmd);
}
}
public void setPollInterval(int nInterval)
{