home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-05-08 | 2.4 KB | 72 lines |
- /*
- * Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
- *
- * This SOURCE CODE FILE, which has been provided by Borland as part
- * of a Borland product for use ONLY by licensed users of the product,
- * includes CONFIDENTIAL and PROPRIETARY information of Borland.
- *
- * USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS
- * OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
- * THE PRODUCT.
- *
- * IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
- * COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
- * OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
- * OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
- * OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
- * OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
- * CODE FILE.
- */
- //--------------------------------------------------------------------------------------------------
- // CORBA Reference Application
- // Copyright (c) 1997 by Borland International, All Rights Reserved
- //
- // Contains TimedConnect Class.
- //--------------------------------------------------------------------------------------------------
-
- package borland.reference.creditapproval.server;
-
- import borland.sql.dataset.*;
- import borland.jbcl.dataset.*;
- import java.util.*;
-
- /**
- * TimedConnect class repeatedly attempts to connect to a database
- * every X number of seconds for a total specified number of seconds.
- * If unable to connect, the Dataset/SQLException is rethrown.
- */
- public class TimedConnect {
-
- public TimedConnect(Database connectDb, int retrySeconds, int totalSeconds )
- throws DataSetException {
-
- long current;
- long nextRetry;
-
- long end = System.currentTimeMillis() + totalSeconds * 1000l;
-
- do {
- try {
- connectDb.openConnection();
- break;
- } catch (DataSetException e) {
- System.err.println(e);
-
- // Pause for the specified number of seconds before attempting
- // to connect again
- nextRetry = System.currentTimeMillis() + retrySeconds * 1000l;
-
- do {
-
- current = System.currentTimeMillis();
-
- // Re-throw the exception if the maximum amount of
- // time specified to attempt a connection has expired.
- if (current >= end) throw e;
-
- } while (current < nextRetry );
- }
- } while (current < end);
- }
- }
-