/*
 * Copyright 2017 Kryptnostic, Inc. (dba Loom)
 *
 * 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 com.kryptnostic.rhizome.core;

import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author Matthew Tamayo-Rios &lt;matthew@kryptnostic.com&gt;
 */
public class Cutting implements Serializable {
    private static final long serialVersionUID = -8431251486986674006L;
    private static final RhizomeApplicationServer RHIZOME_APPLICATION_SERVER = new RhizomeApplicationServer();
    private static final     CountDownLatch           latch                      = new CountDownLatch( 1 );
    private static final     Lock                     lock                       = new ReentrantLock();
    private final String[] activeProfiles;
    private final Class<?>[] additionalPods;

    public Cutting( String[] activeProfiles, Class<?> ... additionalPods ) {
        this.activeProfiles = activeProfiles;
        this.additionalPods = additionalPods;
    }

    public <T> T getBean( Class<T> clazz ) throws InterruptedException {
        ensureInitialized();
        return RHIZOME_APPLICATION_SERVER.getContext().getBean( clazz );
    }

    public <T> Map<String, T> getBeansOfType( Class<T> clazz ) throws InterruptedException {
        ensureInitialized();
        return RHIZOME_APPLICATION_SERVER.getContext().getBeansOfType( clazz );
    }

    public void ensureInitialized() throws InterruptedException {
        if ( !RHIZOME_APPLICATION_SERVER.getContext().isActive() && lock.tryLock() ) {
            RHIZOME_APPLICATION_SERVER.intercrop( additionalPods );
            RHIZOME_APPLICATION_SERVER.sprout( activeProfiles );
            latch.countDown();
        } else {
            latch.await();
        }
    }
}

@@ -981,16 +981,36 @@
 al long 
+                    
 serialVe
@@ -1018,16 +1018,26 @@
 sionUID 
+          
 = -84312
@@ -1189,20 +1189,16 @@
 c final 
-    
 CountDow
@@ -1293,20 +1293,16 @@
 c final 
-    
 Lock    
@@ -1386,32 +1386,55 @@
 e final String%5B%5D
+                       
  activeProfiles;
@@ -1462,16 +1462,37 @@
 ass%3C?%3E%5B%5D
+                     
  additio
@@ -1554,17 +1554,16 @@
 Class%3C?%3E
- 
 ... addi

Fix whitespace