Coverage Report - org.apache.onami.autobind.install.InstallationContext
 
Classes in this File Line Coverage Branch Coverage Complexity
InstallationContext
0%
0/26
0%
0/10
2.25
InstallationContext$StageableRequest
N/A
N/A
2.25
 
 1  
 package org.apache.onami.autobind.install;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 5  
  * contributor license agreements.  See the NOTICE file distributed with
 6  
  * this work for additional information regarding copyright ownership.
 7  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 8  
  * (the "License"); you may not use this file except in compliance with
 9  
  * the License.  You may obtain a copy of the License at
 10  
  *
 11  
  *  http://www.apache.org/licenses/LICENSE-2.0
 12  
  *
 13  
  * Unless required by applicable law or agreed to in writing, software
 14  
  * distributed under the License is distributed on an "AS IS" BASIS,
 15  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 16  
  * See the License for the specific language governing permissions and
 17  
  * limitations under the License.
 18  
  */
 19  
 
 20  
 import java.util.ArrayList;
 21  
 import java.util.HashMap;
 22  
 import java.util.List;
 23  
 import java.util.Map;
 24  
 import java.util.concurrent.Callable;
 25  
 
 26  
 /**
 27  
  * This class is internally used, to bind Installation Requests and process them
 28  
  * sequentially in a predefined order.
 29  
  */
 30  0
 public class InstallationContext {
 31  
 
 32  0
     private final Map<BindingStage, List<Callable<?>>> context = new HashMap<BindingStage, List<Callable<?>>>();
 33  
 
 34  
     public void process()
 35  
         throws Exception
 36  
     {
 37  0
         for ( BindingStage stage : BindingStage.ORDERED )
 38  
         {
 39  0
             List<Callable<?>> requests = context.get( stage );
 40  0
             if ( requests != null )
 41  
             {
 42  0
                 for ( Callable<?> request : requests )
 43  
                 {
 44  0
                     request.call();
 45  
                 }
 46  
             }
 47  0
         }
 48  0
     }
 49  
 
 50  
     public void add( BindingStage stage, Callable<?> request )
 51  
     {
 52  0
         synchronized ( context )
 53  
         {
 54  0
             List<Callable<?>> requests = context.get( stage );
 55  0
             if ( requests == null )
 56  
             {
 57  0
                 requests = new ArrayList<Callable<?>>();
 58  0
                 context.put( stage, requests );
 59  
             }
 60  0
             requests.add( request );
 61  0
         }
 62  0
     }
 63  
 
 64  
     public void add( StageableRequest request )
 65  
     {
 66  0
         synchronized ( context )
 67  
         {
 68  0
             List<Callable<?>> requests = context.get( request.getExecutionStage() );
 69  0
             if ( requests == null )
 70  
             {
 71  0
                 requests = new ArrayList<Callable<?>>();
 72  0
                 context.put( request.getExecutionStage(), requests );
 73  
             }
 74  0
             requests.add( request );
 75  0
         }
 76  0
     }
 77  
 
 78  0
     public static interface StageableRequest
 79  
         extends Callable<Void>
 80  
     {
 81  
 
 82  
         BindingStage getExecutionStage();
 83  
 
 84  
     }
 85  
 
 86  
 }