1 21 22 package org.opensubsystems.core.util; 23 24 import java.util.logging.Level ; 25 import java.util.logging.Logger ; 26 27 import org.opensubsystems.core.error.OSSException; 28 29 45 public class AsyncProcessor extends Thread 46 { 47 49 53 protected SynchronizedQueue m_syncQueue; 54 55 58 protected boolean m_bKeepRunning; 59 60 62 65 private static Logger s_logger = Log.getInstance(AsyncProcessor.class); 66 67 69 74 public AsyncProcessor( 75 String strName 76 ) 77 { 78 super(strName); 79 80 m_syncQueue = new SynchronizedQueue(); 81 m_bKeepRunning = true; 82 } 83 84 86 89 public void run( 90 ) 91 { 92 Object itemToProcess; 93 94 while (m_bKeepRunning) 95 { 96 try 97 { 98 itemToProcess = m_syncQueue.get(); 100 101 104 if (itemToProcess != null) 105 { 106 s_logger.log(Level.FINEST, getName() 107 + ": Going to process " + itemToProcess.toString()); 108 } 109 else 110 { 111 s_logger.log(Level.FINEST, getName() 112 + ": Going to process null object."); 113 } 114 processItemNow(itemToProcess); 115 } 116 catch (InterruptedException ieExc) 117 { 118 } 121 catch (Throwable thr) 122 { 123 s_logger.log(Level.WARNING, getName() 126 + ": Unexpected error has occured while processing data.", 127 thr); 128 } 129 } 130 } 131 132 136 public void stopProcessing( 137 ) 138 { 139 m_bKeepRunning = false; 143 interrupt(); 145 } 146 147 156 public void processItemLater( 157 Object objItem 158 ) 159 { 160 if (objItem != null) 162 { 163 s_logger.log(Level.FINEST, getName() 164 + ": Adding object to the queue " + objItem.toString()); 165 } 166 else 167 { 168 s_logger.log(Level.FINEST, getName() 169 + ": Adding null object to the queue."); 170 } 171 m_syncQueue.put(objItem); 172 } 173 174 187 protected void processItemNow( 188 Object objItem 189 ) throws OSSException 190 { 191 throw new UnsupportedOperationException ("This method must be overriden."); 192 } 193 } 194 | Popular Tags |