Coverage Report - org.jscsi.target.Activator
 
Classes in this File Line Coverage Branch Coverage Complexity
Activator
0%
0/20
0%
0/10
4
 
 1  
 package org.jscsi.target;
 2  
 
 3  
 import java.io.File;
 4  
 import java.net.InetAddress;
 5  
 import java.nio.file.Files;
 6  
 import java.util.concurrent.ExecutorService;
 7  
 import java.util.concurrent.Executors;
 8  
 
 9  
 import org.osgi.framework.BundleActivator;
 10  
 import org.osgi.framework.BundleContext;
 11  
 
 12  
 /**
 13  
  * This osgi bundle activator
 14  
  * is used to start a jscsi target within an
 15  
  * osgi environment.
 16  
  * 
 17  
  * @author Andreas Rain, University of Konstanz
 18  
  * 
 19  
  */
 20  0
 public class Activator implements BundleActivator {
 21  
 
 22  
     private ExecutorService runner;
 23  
     private TargetServer target;
 24  
     
 25  
     @Override
 26  
     public void start(BundleContext context) throws Exception {
 27  
         // The osgi container or system properties have to supply
 28  
         // a property 'jscsi_target-published_ip', to determine
 29  
         // which ip address should be used.
 30  0
         System.out.println("Starting up jscsi bundle");
 31  0
         String pIp = context.getProperty("jscsi_target-published_ip");
 32  0
         InetAddress addr = InetAddress.getByName(pIp);
 33  
 
 34  0
         if (addr == null)
 35  0
             throw new IllegalArgumentException(
 36  
                 "Either the address provided with 'jscsi_target-published_ip' is illegal or not contained within the available network interfaces.");
 37  
       
 38  0
         File schemaFile = new File("jscsi-target.xsd");
 39  
         
 40  0
         if(schemaFile.exists() == false){
 41  0
             Files.copy(context.getBundle().getResource("/jscsi-target.xsd").openStream(), schemaFile.toPath());
 42  
         }
 43  
         
 44  0
         System.out.println("Schemafile: " + ((schemaFile.exists())? "exists" : "does not exist"));
 45  
         
 46  0
         File configFile = new File("jscsi-target.xml");
 47  0
         if(configFile.exists() == false){
 48  0
             Files.copy(context.getBundle().getResource("/jscsi-target.xml").openStream(), configFile.toPath());
 49  
         }
 50  
         
 51  0
         System.out.println("Configfile: " + ((configFile.exists())? "exists" : "does not exist"));
 52  
 
 53  0
         target = new TargetServer(Configuration.create(schemaFile, configFile, addr.getHostAddress()));
 54  
 
 55  0
         runner = Executors.newSingleThreadExecutor();
 56  0
         runner.submit(target);
 57  0
     }
 58  
 
 59  
     @Override
 60  
     public void stop(BundleContext context) throws Exception {
 61  
         // Need to provide a shutdown method within the jscsi target
 62  0
         runner.shutdown();
 63  0
     }
 64  
 
 65  
 }