/*
 * Copyright 2015-2017 Spotify AB
 * Copyright 2016-2018 The Last Pickle Ltd
 *
 * 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.
 */

package io.cassandrareaper;

import io.cassandrareaper.jmx.JmxConnectionFactory;
import io.cassandrareaper.service.RepairManager;
import io.cassandrareaper.service.SchedulingManager;
import io.cassandrareaper.storage.IStorage;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;

import com.codahale.metrics.MetricRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Single class to hold all application global interfacing objects, and app global options.
 */
public final class AppContext {

  public static final UUID REAPER_INSTANCE_ID = UUID.randomUUID();
  public static final String REAPER_INSTANCE_ADDRESS = initialiseInstanceAddress();

  private static final String DEFAULT_INSTANCE_ADDRESS = "127.0.0.1";
  private static final Logger LOG = LoggerFactory.getLogger(AppContext.class);

  public final AtomicBoolean isRunning = new AtomicBoolean(true);
  public IStorage storage;
  public RepairManager repairManager;
  public SchedulingManager schedulingManager;
  public JmxConnectionFactory jmxConnectionFactory;
  public ReaperApplicationConfiguration config;
  public MetricRegistry metricRegistry = new MetricRegistry();

  private static String initialiseInstanceAddress() {
    String reaperInstanceAddress;
    try {
      reaperInstanceAddress = InetAddress.getLocalHost().getHostAddress();
    } catch (UnknownHostException e) {
      LOG.warn("Cannot get instance address", e);
      reaperInstanceAddress = DEFAULT_INSTANCE_ADDRESS;
    }
    return reaperInstanceAddress;
  }
}

@@ -1362,16 +1362,24 @@
 DRESS = 
+Private.
 initiali
@@ -1404,158 +1404,8 @@
 );%0A%0A
-  private static final String DEFAULT_INSTANCE_ADDRESS = %22127.0.0.1%22;%0A  private static final Logger LOG = LoggerFactory.getLogger(AppContext.class);%0A%0A
   pu
@@ -1741,16 +1741,17 @@
 try();%0A%0A
+%0A
   privat
@@ -1763,62 +1763,214 @@
 tic 
-String initialiseInstanceAddress() %7B%0A    String reaper
+class Private %7B%0A    private static final Logger LOG = LoggerFactory.getLogger(AppContext.class);%0A    private static final String DEFAULT_INSTANCE_ADDRESS = %22127.0.0.1%22;%0A%0A    private static String initialise
 Inst
@@ -1980,22 +1980,27 @@
 eAddress
-;%0A
+() %7B%0A 
     
+ 
 try %7B%0A  
@@ -2003,39 +2003,25 @@
 %7B%0A      
-reaperInstanceAddress =
+  return 
  InetAdd
@@ -2062,16 +2062,18 @@
 ();%0A    
+  
 %7D catch 
@@ -2095,24 +2095,26 @@
 eption e) %7B%0A
+  
       LOG.wa
@@ -2161,31 +2161,22 @@
     
-reaperInstanceAddress =
+%7D%0A      return
  DEF
@@ -2208,42 +2208,8 @@
   %7D%0A
-    return reaperInstanceAddress;%0A
   %7D%0A

Fix initialisation ordering of AppContext