Coverage Report - org.kuali.rice.ksb.impl.bus.LazyEndpoint
 
Classes in this File Line Coverage Branch Coverage Complexity
LazyEndpoint
0%
0/15
0%
0/6
2.333
 
 1  
 package org.kuali.rice.ksb.impl.bus;
 2  
 
 3  
 import org.kuali.rice.ksb.api.bus.Endpoint;
 4  
 import org.kuali.rice.ksb.api.bus.ServiceConfiguration;
 5  
 import org.kuali.rice.ksb.messaging.serviceconnectors.ServiceConnectorFactory;
 6  
 
 7  
 public class LazyEndpoint implements Endpoint {
 8  
 
 9  0
         private final Object lock = new Object();
 10  
         
 11  
         private final ServiceConfiguration serviceConfiguration;
 12  
         private volatile Object service;
 13  
         
 14  0
         public LazyEndpoint(ServiceConfiguration serviceConfiguration) {
 15  0
                 if (serviceConfiguration == null) {
 16  0
                         throw new IllegalArgumentException("serviceConfiguration was null");
 17  
                 }
 18  0
                 this.serviceConfiguration = serviceConfiguration;
 19  0
         }
 20  
         
 21  
         @Override
 22  
         public ServiceConfiguration getServiceConfiguration() {
 23  0
                 return this.serviceConfiguration;
 24  
         }
 25  
 
 26  
         @Override
 27  
         public Object getService() {
 28  
                 // double-checked locking idiom - see Effective Java, Item 71
 29  0
                 Object internalService = this.service;
 30  0
                 if (internalService == null) {
 31  0
                         synchronized (lock) {
 32  0
                                 internalService = this.service;
 33  0
                                 if (internalService == null) {
 34  0
                                         this.service = internalService = ServiceConnectorFactory.getServiceConnector(serviceConfiguration).getService(); 
 35  
                                 }
 36  0
                         }
 37  
                 }
 38  0
                 return internalService;
 39  
         }
 40  
 
 41  
 }