KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
26  * @author Alphonse Bendt
27  * @version $Id: WaitRetryStrategy.java,v 1.6 2005/04/27 10:48:40 alphonse.bendt Exp $
28  */

29
30 public class WaitRetryStrategy extends AbstractRetryStrategy
31 {
32     public static final long WAIT_TIME_DEFAULT = 1000;
33
34     public static final long WAIT_INCREMENT_DEFAULT = 3000;
35
36     private long currentTimeToWait_;
37
38     private long waitTimeIncrement_;
39
40     // //////////////////////////////////////
41

42     public WaitRetryStrategy(IProxyPushSupplier pushSupplier, PushOperation pushOperation)
43     {
44         this(pushSupplier, pushOperation, WAIT_TIME_DEFAULT, WAIT_INCREMENT_DEFAULT);
45     }
46
47     public WaitRetryStrategy(IProxyPushSupplier pushSupplier, PushOperation pushOperation,
48             long startingWaitTime, long waitTimeIncrement)
49     {
50         super(pushSupplier, pushOperation);
51
52         currentTimeToWait_ = startingWaitTime;
53
54         waitTimeIncrement_ = waitTimeIncrement;
55     }
56
57     // //////////////////////////////////////
58

59     protected long getTimeToWait()
60     {
61         long _timeToWait = currentTimeToWait_;
62
63         currentTimeToWait_ += waitTimeIncrement_;
64
65         return _timeToWait;
66     }
67
68     protected void retryInternal() throws RetryException
69     {
70         try
71         {
72             while (isRetryAllowed())
73             {
74                 try
75                 {
76                     pushOperation_.invokePush();
77
78                     return;
79                 } catch (Throwable JavaDoc error)
80                 {
81                     remoteExceptionOccured(error);
82                 }
83             }
84             throw new RetryException("no more retries possible");
85         } finally
86         {
87             dispose();
88         }
89     }
90 }
91
Popular Tags