/*
 * Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you
 * may not use this file except in compliance with the License. You
 * may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License. See accompanying
 * LICENSE file.
 */

package com.pivotal.gemfirexd.internal.engine.fabricservice;

import java.sql.SQLException;
import java.util.Properties;

import com.gemstone.gemfire.SystemFailure;
import com.pivotal.gemfirexd.FabricServer;

/**
 * Implementation of {@link FabricServer} API. Future product versions may
 * extend this class to alter its behaviour.
 * 
 * @author soubhikc
 */
public class FabricServerImpl extends FabricServiceImpl implements FabricServer {

  @Override
  public boolean isServer() {
    return true;
  }

  /**
   * @see FabricServer#start(Properties)
   */
  @Override
  public void start(Properties bootProperties) throws SQLException {
    start(bootProperties, false);
  }

  /**
   * @see FabricServer#start(Properties, boolean)
   */
  @Override
  public synchronized void start(Properties bootProperties,
      boolean ignoreIfStarted) throws SQLException {

    try {
      startImpl(bootProperties, ignoreIfStarted, false);
    } catch (Throwable t) {
      Error err;
      if (t instanceof Error && SystemFailure.isJVMFailureError(
          err = (Error)t)) {
        FabricServiceUtils.clearSystemProperties(monitorlite, sysProps);
        SystemFailure.initiateFailure(err);
        // If this ever returns, rethrow the error. We're poisoned
        // now, so don't let this thread continue.
        throw err;
      }
      // Whenever you catch Error or Throwable, you must also
      // check for fatal JVM error (see above).  However, there is
      // _still_ a possibility that you are dealing with a cascading
      // error condition, so you also need to check to see if the JVM
      // is still usable:
      SystemFailure.checkFailure();
      handleThrowable(t);
    }
  }
}

@@ -825,16 +825,125 @@
 ailure;%0A
+import com.gemstone.gemfire.cache.CacheFactory;%0Aimport com.gemstone.gemfire.internal.cache.GemFireCacheImpl;%0A
 import c
@@ -1104,17 +1104,16 @@
 iour.%0A *
- 
 %0A * @aut
@@ -1536,21 +1536,8 @@
 lic 
-synchronized 
 void
@@ -1627,19 +1627,259 @@
 n %7B%0A
-%0A    try %7B%0A
+    // take locks acquired by IDS.tryReconnect first to avoid deadlock%0A    // between start and reconnect thread%0A    synchronized (CacheFactory.class) %7B%0A      synchronized (GemFireCacheImpl.class) %7B%0A        synchronized (this) %7B%0A          try %7B%0A      
     
@@ -1931,16 +1931,22 @@
 false);%0A
+      
     %7D ca
@@ -1961,24 +1961,30 @@
 owable t) %7B%0A
+      
       Error 
@@ -1984,24 +1984,30 @@
  Error err;%0A
+      
       if (t 
@@ -2059,16 +2059,22 @@
 eError(%0A
+      
         
@@ -2102,16 +2102,22 @@
         
+      
 FabricSe
@@ -2173,16 +2173,22 @@
 Props);%0A
+      
         
@@ -2231,16 +2231,22 @@
         
+      
 // If th
@@ -2296,16 +2296,22 @@
 oisoned%0A
+      
         
@@ -2361,16 +2361,22 @@
         
+      
 throw er
@@ -2382,16 +2382,22 @@
 rr;%0A
+      
       %7D%0A
     
@@ -2392,16 +2392,22 @@
       %7D%0A
+      
       //
@@ -2460,16 +2460,22 @@
 st also%0A
+      
       //
@@ -2533,16 +2533,22 @@
 here is%0A
+      
       //
@@ -2608,16 +2608,22 @@
 scading%0A
+      
       //
@@ -2684,16 +2684,22 @@
 the JVM%0A
+      
       //
@@ -2716,16 +2716,22 @@
 usable:%0A
+      
       Sy
@@ -2758,16 +2758,22 @@
 lure();%0A
+      
       ha
@@ -2790,16 +2790,46 @@
 ble(t);%0A
+          %7D%0A        %7D%0A      %7D%0A
     %7D%0A  

fix a deadlock between server start and reconnect thread