Author: gatfora
Date: Fri Dec  8 03:52:57 2006
New Revision: 483957

URL: http://svn.apache.org/viewvc?view=rev&rev=483957
Log:
More logic moved to the SandeshaThread, see SANDESHA2-61

Modified:
    
webservices/sandesha/trunk/java/src/org/apache/sandesha2/workers/Invoker.java
    
webservices/sandesha/trunk/java/src/org/apache/sandesha2/workers/SandeshaThread.java
    webservices/sandesha/trunk/java/src/org/apache/sandesha2/workers/Sender.java

Modified: 
webservices/sandesha/trunk/java/src/org/apache/sandesha2/workers/Invoker.java
URL: 
http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/workers/Invoker.java?view=diff&rev=483957&r1=483956&r2=483957
==============================================================================
--- 
webservices/sandesha/trunk/java/src/org/apache/sandesha2/workers/Invoker.java 
(original)
+++ 
webservices/sandesha/trunk/java/src/org/apache/sandesha2/workers/Invoker.java 
Fri Dec  8 03:52:57 2006
@@ -50,13 +50,8 @@
 
        private static final Log log = LogFactory.getLog(Invoker.class);
        
-       public static final int INVOKER_THREADPOOL_SIZE = 5;
-
-       private WorkerLock lock = null;
-       
        public Invoker() {
-               super(INVOKER_THREADPOOL_SIZE, 
Sandesha2Constants.INVOKER_SLEEP_TIME);
-               lock = new WorkerLock ();
+               super(Sandesha2Constants.INVOKER_SLEEP_TIME);
        }
        
        /**
@@ -113,7 +108,7 @@
                                                                
messageContextKey, 
                                                                true); //want 
to ignore the enxt msg number
                                                
-                                               worker.setLock(lock);
+                                               worker.setLock(getWorkerLock());
                                                worker.setWorkId(workId);
                                                
                                                //before we execute we need to 
set the 
@@ -122,7 +117,7 @@
                                        
                                                //adding the workId to the lock 
after assigning it to a thread makes sure 
                                                //that all the workIds in the 
Lock are handled by threads.
-                                               lock.addWork(workId);
+                                               getWorkerLock().addWork(workId);
 
                                                long msgNumber = 
invoker.getMsgNo();
                                                //if necessary, update the 
"next message number" bean under this transaction
@@ -318,7 +313,7 @@
                                                                                
                                                   //piece of work that will be 
assigned to the Worker.
                                                                                
                                        //check whether the bean is already 
assigned to a worker.
-                                       if (lock.isWorkPresent(workId)) {
+                                       if 
(getWorkerLock().isWorkPresent(workId)) {
                                                String message = 
SandeshaMessageHelper.getMessage(SandeshaMessageKeys.workAlreadyAssigned, 
workId);
                                                log.debug(message);
                                                continue;
@@ -334,14 +329,14 @@
                                                        beanIsOutOfOrderMsg); 
//only ignore nextMsgNumber if the bean is an
                                                                                
                                                                //out of order 
message
                                        
-                                       worker.setLock(lock);
+                                       worker.setLock(getWorkerLock());
                                        worker.setWorkId(workId);
                                        
                                        threadPool.execute(worker);
                                        
                                        //adding the workId to the lock after 
assigning it to a thread makes sure 
                                        //that all the workIds in the Lock are 
handled by threads.
-                                       lock.addWork(workId);
+                                       getWorkerLock().addWork(workId);
                                }
 
                        } catch (Exception e) {

Modified: 
webservices/sandesha/trunk/java/src/org/apache/sandesha2/workers/SandeshaThread.java
URL: 
http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/workers/SandeshaThread.java?view=diff&rev=483957&r1=483956&r2=483957
==============================================================================
--- 
webservices/sandesha/trunk/java/src/org/apache/sandesha2/workers/SandeshaThread.java
 (original)
+++ 
webservices/sandesha/trunk/java/src/org/apache/sandesha2/workers/SandeshaThread.java
 Fri Dec  8 03:52:57 2006
@@ -20,7 +20,6 @@
 
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.util.threadpool.ThreadFactory;
-import org.apache.axis2.util.threadpool.ThreadPool;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.sandesha2.i18n.SandeshaMessageHelper;
@@ -39,15 +38,20 @@
        private boolean pauseRequired = false;
        
        private int sleepTime;
-       
+  private WorkerLock lock = null;
+
        private ArrayList workingSequences = new ArrayList();
        
        protected transient ThreadFactory threadPool;
        protected ConfigurationContext context = null;
        
-       protected SandeshaThread(int threadPoolSize, int sleepTime){
-               threadPool = new ThreadPool(threadPoolSize, threadPoolSize);
+       public SandeshaThread(int sleepTime) {
                this.sleepTime = sleepTime;
+       lock = new WorkerLock ();
+       }
+       
+       public final WorkerLock getWorkerLock() {
+               return lock;
        }
        
        public synchronized void stopThreadForSequence(String sequenceID){
@@ -136,6 +140,9 @@
                        workingSequences.add(sequenceID);
                if (!isThreadStarted()) {
                        this.context = context;
+                       // Get the axis2 thread pool
+                       threadPool = context.getThreadPool();
+                       
                        runThread = true; // so that isStarted()=true.
                        super.start();
                }               

Modified: 
webservices/sandesha/trunk/java/src/org/apache/sandesha2/workers/Sender.java
URL: 
http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/workers/Sender.java?view=diff&rev=483957&r1=483956&r2=483957
==============================================================================
--- 
webservices/sandesha/trunk/java/src/org/apache/sandesha2/workers/Sender.java 
(original)
+++ 
webservices/sandesha/trunk/java/src/org/apache/sandesha2/workers/Sender.java 
Fri Dec  8 03:52:57 2006
@@ -38,17 +38,10 @@
 
 public class Sender extends SandeshaThread {
 
-
        private static final Log log = LogFactory.getLog(Sender.class);
-       
-
-  public static final int SENDER_THREADPOOL_SIZE = 5;
-  
-  private WorkerLock lock = null;
-    
+           
   public Sender () {
-       super(SENDER_THREADPOOL_SIZE, Sandesha2Constants.SENDER_SLEEP_TIME);
-       lock = new WorkerLock ();
+       super(Sandesha2Constants.SENDER_SLEEP_TIME);
   }    
 
        protected void internalRun() {
@@ -138,7 +131,7 @@
                                String workId = senderBean.getMessageID();
 
                                // check weather the bean is already assigned 
to a worker.
-                               if (lock.isWorkPresent(workId)) {
+                               if (getWorkerLock().isWorkPresent(workId)) {
                                        if (log.isDebugEnabled()) {
                                                String message = 
SandeshaMessageHelper
                                                                .getMessage(
@@ -153,14 +146,14 @@
 
                                // start a worker which will work on this 
messages.
                                SenderWorker worker = new SenderWorker(context, 
senderBean);
-                               worker.setLock(lock);
+                               worker.setLock(getWorkerLock());
                                worker.setWorkId(workId);
                                threadPool.execute(worker);
 
                                // adding the workId to the lock after 
assigning it to a thread
                                // makes sure
                                // that all the workIds in the Lock are handled 
by threads.
-                               lock.addWork(workId);
+                               getWorkerLock().addWork(workId);
 
                        } catch (Exception e) {
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to