KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > notification > engine > TaskProcessorRetryStrategy


1 package org.jacorb.notification.engine;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2004 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 import org.jacorb.notification.interfaces.IProxyPushSupplier;
24
25 import EDU.oswego.cs.dl.util.concurrent.SynchronizedBoolean;
26
27 /**
28  * @author Alphonse Bendt
29  * @version $Id: TaskProcessorRetryStrategy.java,v 1.11 2005/04/27 10:48:40 alphonse.bendt Exp $
30  */

31 public class TaskProcessorRetryStrategy extends AbstractRetryStrategy implements
32         PushTaskExecutor.PushTask
33 {
34     /**
35      * retry the failed operation. schedule the retry for delivery.
36      */

37     public final Runnable JavaDoc retryPushOperation_ = new Runnable JavaDoc()
38     {
39         public void run()
40         {
41             pushSupplier_.schedulePush(TaskProcessorRetryStrategy.this);
42         }
43     };
44
45     private SynchronizedBoolean isCancelled_ = new SynchronizedBoolean(false);
46     
47     private final TaskProcessor taskProcessor_;
48
49     private final long backoutInterval_;
50
51     public TaskProcessorRetryStrategy(IProxyPushSupplier pushSupplier, PushOperation pushOperation,
52             TaskProcessor taskProcessor, long backoutInterval)
53     {
54         super(pushSupplier, pushOperation);
55
56         taskProcessor_ = taskProcessor;
57         backoutInterval_ = backoutInterval;
58     }
59
60     protected long getTimeToWait()
61     {
62         return 0;
63     }
64
65     protected void retryInternal() throws RetryException
66     {
67         if (!pushSupplier_.isDisposed())
68         {
69             pushSupplier_.disableDelivery();
70
71             taskProcessor_.executeTaskAfterDelay(backoutInterval_, retryPushOperation_);
72         }
73     }
74
75     public void doPush()
76     {
77         if (!isCancelled_.get())
78         {
79             try
80             {
81                 if (!pushSupplier_.isDisposed())
82                 {
83                     pushOperation_.invokePush();
84                     pushSupplier_.pushPendingData();
85                 }
86
87                 dispose();
88             } catch (Throwable JavaDoc error)
89             {
90                 try
91                 {
92                     remoteExceptionOccured(error);
93                     retry();
94                 } catch (RetryException e)
95                 {
96                     dispose();
97                 }
98             }
99         }
100     }
101
102     public void cancel()
103     {
104         isCancelled_.set(true);
105         
106         dispose();
107     }
108 }
109
Popular Tags