~ubuntu-branches/ubuntu/trusty/mysql-connector-java/trusty

« back to all changes in this revision

Viewing changes to src/com/mysql/jdbc/LoadBalancingConnectionProxy.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg
  • Date: 2013-11-06 23:49:02 UTC
  • mfrom: (1.1.10) (3.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20131106234902-fhupetvkmt34mg01
Tags: 5.1.27-1
* New upstream release
* Refreshed the patches
* Updated Standards-Version to 3.9.5 (no changes)
* Use XZ compression for the upstream tarball
* Switch to debhelper level 9

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
        private long transactionCount = 0;
73
73
        private ConnectionGroup connectionGroup = null;
74
74
        protected String closedReason = null;
 
75
        protected boolean closedExplicitly = false;
 
76
        protected boolean autoReconnect = false;
75
77
 
76
78
        public static final String BLACKLIST_TIMEOUT_PROPERTY_KEY = "loadBalanceBlacklistTimeout";
77
79
 
210
212
                        hosts = new ArrayList<String>(this.connectionGroup.getInitialHosts());
211
213
                }
212
214
                
 
215
                this.autoReconnect = "true".equalsIgnoreCase(props.getProperty("autoReconnect")) ||
 
216
                                "true".equalsIgnoreCase(props.getProperty("autoReconnectForPools"));
 
217
                
213
218
                this.hostList = hosts;
214
219
 
215
220
                int numHosts = this.hostList.size();
580
585
 
581
586
                        this.isClosed = true;
582
587
                        this.closedReason = "Connection explicitly closed.";
 
588
                        this.closedExplicitly = true;
583
589
 
584
590
                        return null;
585
591
                }
603
609
                }
604
610
 
605
611
                if (this.isClosed) {
 
612
                        if(this.autoReconnect && !this.closedExplicitly){
 
613
                                // try to reconnect first!
 
614
                                this.currentConn = null;
 
615
                                this.pickNewConnection();
 
616
                                this.isClosed = false;
 
617
                                this.closedReason = null;
 
618
                        } else {
606
619
                        String reason = "No operations allowed after connection closed.";
607
620
                        if(this.closedReason != null){
608
621
                                reason += ("  " + this.closedReason);
614
627
                                                                                                                                 * a interceptor
615
628
                                                                                                                                 * here...
616
629
                                                                                                                                 */);
 
630
                        }
617
631
                }
618
632
 
619
633
                if (!inTransaction) {
648
662
                                // in invalidateCurrenctConnection()
649
663
                                if (host != null) {
650
664
                                        synchronized (this.responseTimes) {
651
 
                                                int hostIndex = (this.hostsToListIndexMap
652
 
                                                                .get(host)).intValue();
 
665
                                                Integer hostIndex = (this.hostsToListIndexMap
 
666
                                                                .get(host));
653
667
 
654
 
                                                if(hostIndex < this.responseTimes.length){
 
668
                                                if(hostIndex != null && hostIndex.intValue() < this.responseTimes.length){
655
669
                                                        this.responseTimes[hostIndex] = getLocalTimeBestResolution()
656
670
                                                                        - this.transactionStartTime;
657
671
                                                }
671
685
         * @throws SQLException
672
686
         */
673
687
        protected synchronized void pickNewConnection() throws SQLException {
674
 
                if (this.isClosed && "Connection explicitly closed.".equals(this.closedReason)) {
 
688
                if (this.isClosed && this.closedExplicitly) {
675
689
                        return;
676
690
                }
677
691