Coverage report

  %line %branch
org.apache.jcs.auxiliary.remote.RemoteUtils
49% 
85% 

 1  
 package org.apache.jcs.auxiliary.remote;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.io.IOException;
 23  
 import java.io.InputStream;
 24  
 import java.rmi.RMISecurityManager;
 25  
 import java.rmi.RemoteException;
 26  
 import java.rmi.registry.LocateRegistry;
 27  
 import java.rmi.registry.Registry;
 28  
 import java.util.Enumeration;
 29  
 import java.util.Properties;
 30  
 
 31  
 import org.apache.commons.logging.Log;
 32  
 import org.apache.commons.logging.LogFactory;
 33  
 
 34  
 /**
 35  
  * This class provides some basic utilities for doing things such as starting
 36  
  * the registry properly.
 37  
  */
 38  
 public class RemoteUtils
 39  
 {
 40  28
     private final static Log log = LogFactory.getLog( RemoteUtils.class );
 41  
 
 42  
     /** No instances please. */
 43  
     private RemoteUtils()
 44  
     {
 45  0
         super();
 46  0
     }
 47  
 
 48  
     /**
 49  
      * Creates and exports a registry on the specified port of the local host.
 50  
      * <p>
 51  
      * @param port
 52  
      * @return the port the registry was started on
 53  
      * @throws RemoteException
 54  
      */
 55  
     public static int createRegistry( class="keyword">int port )
 56  
         throws RemoteException
 57  
     {
 58  14
         if ( log.isInfoEnabled() )
 59  
         {
 60  14
             log.info( "createRegistry> setting security manager" );
 61  
         }
 62  14
         System.setSecurityManager( new RMISecurityManager() );
 63  
 
 64  14
         if ( port < 1024 )
 65  
         {
 66  0
             if ( log.isInfoEnabled() )
 67  
             {
 68  0
                 log.info( "Port chosen was less than 1024, will use default [" + Registry.REGISTRY_PORT + "] instead." );
 69  
             }
 70  0
             port = Registry.REGISTRY_PORT;
 71  
         }
 72  
 
 73  14
         if ( log.isInfoEnabled() )
 74  
         {
 75  14
             log.info( "createRegistry> creating registry on port [" + port + "]" );
 76  
         }
 77  14
         LocateRegistry.createRegistry( port );
 78  7
         return port;
 79  
     }
 80  
 
 81  
     /**
 82  
      * Loads properties for the named props file.
 83  
      * <p>
 84  
      * @param propFile
 85  
      * @return The properties object for the file
 86  
      * @throws IOException
 87  
      */
 88  
     public static Properties loadProps( String propFile )
 89  
         throws IOException
 90  
     {
 91  7
         InputStream is = RemoteUtils.class.getResourceAsStream( propFile );
 92  7
         Properties props = new Properties();
 93  
         try
 94  
         {
 95  7
             props.load( is );
 96  7
             if ( log.isDebugEnabled() )
 97  
             {
 98  0
                 log.debug( "props.size=" + props.size() );
 99  
             }
 100  
 
 101  7
             if ( log.isDebugEnabled() )
 102  
             {
 103  0
                 if ( props != null )
 104  
                 {
 105  0
                     Enumeration en = props.keys();
 106  0
                     StringBuffer buf = new StringBuffer();
 107  0
                     while ( en.hasMoreElements() )
 108  
                     {
 109  0
                         String key = (String) en.nextElement();
 110  0
                         buf.append( "\n" + key + " = " + props.getProperty( key ) );
 111  0
                     }
 112  0
                     log.debug( buf.toString() );
 113  0
                 }
 114  
                 else
 115  
                 {
 116  0
                     log.debug( "props is null" );
 117  
                 }
 118  
             }
 119  
 
 120  
         }
 121  0
         catch ( Exception ex )
 122  
         {
 123  0
             log.error( "Error loading remote properties, for file name [" + propFile + "]", ex );
 124  
         }
 125  
         finally
 126  
         {
 127  7
             if ( is != null )
 128  
             {
 129  7
                 is.close();
 130  7
             }
 131  0
         }
 132  7
         return props;
 133  
     }
 134  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.