Guest User

Untitled

a guest
Mar 31st, 2016
177
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import coreb.FIFOArray;
  3.  
  4. /**
  5.  *
  6.  * @author Jure
  7.  */
  8. public class ATCommandHandler
  9. {
  10.     private FIFOArray FIFOThreads = new FIFOArray(20);
  11.     private String currentThreadId = "0";
  12.    
  13.     public ATCommandHandler()
  14.     {
  15.         System.out.println("ATCommandHandler cons");
  16.     }
  17.  
  18.     public synchronized boolean addATCommand(String id)
  19.     {
  20.         if(FIFOThreads.isFull())
  21.         {
  22.             return false; //it would be good to restart
  23.         }
  24.         if(FIFOThreads.isEmptey() && currentThreadId.equals("0"))
  25.         {
  26.             FIFOThreads.addElement(id);
  27.             currentThreadId = (String)FIFOThreads.getOldestElement(true);
  28.         }
  29.         else
  30.         {
  31.             FIFOThreads.addElement(id);
  32.         }
  33.        
  34.        
  35.         return true;
  36.     }
  37.    
  38.     public synchronized void commandFinished()
  39.     {
  40.         if(!FIFOThreads.isEmptey())
  41.         {
  42.             currentThreadId = (String)FIFOThreads.getOldestElement(true);
  43.         }
  44.         else
  45.         {
  46.             currentThreadId = "0";
  47.         }
  48.     }
  49.    
  50.     public String getThreadId()
  51.     {
  52.         return currentThreadId;
  53.     }
  54.    
  55.     //SINGELTON
  56.     private static class Loader
  57.     {
  58.         static ATCommandHandler INSTANCE = new ATCommandHandler();
  59.     }
  60.  
  61.     public static ATCommandHandler getInstance()
  62.     {
  63.         return ATCommandHandler.Loader.INSTANCE;
  64.     }    
  65. }
RAW Paste Data