001 // Copyright 2004, 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.hivemind.impl.servicemodel; 016 017 import org.apache.hivemind.events.RegistryShutdownListener; 018 import org.apache.hivemind.impl.ConstructableServicePoint; 019 020 /** 021 * Implementation of {@link org.apache.hivemind.internal.ServiceModel} for the primitive services 022 * (that do not include the standard deferred instantiation proxy). 023 * 024 * @author Howard Lewis Ship 025 */ 026 public final class PrimitiveServiceModel extends AbstractServiceModelImpl 027 { 028 private Object _constructedService; 029 030 public PrimitiveServiceModel(ConstructableServicePoint servicePoint) 031 { 032 super(servicePoint); 033 } 034 035 /** 036 * Constructs the service (the first time this is invoked) and returns it. 037 */ 038 public synchronized Object getService() 039 { 040 if (_constructedService == null) 041 { 042 _constructedService = constructServiceImplementation(); 043 if( _constructedService instanceof RegistryShutdownListener ) 044 { 045 getShutdownCoordinatorService().addRegistryShutdownListener( ( RegistryShutdownListener )_constructedService ); 046 } 047 } 048 049 // Note: if the service's declared interface is a class AND 050 // the service has interceptors, then it will not be possible 051 // to cast the result (since the returned interceptor will implement 052 // the synthetic service interface). 053 054 return _constructedService; 055 } 056 057 /** 058 * Invokes {@link #getService()} to ensure that the core service implementation has been 059 * instantiated. 060 */ 061 public void instantiateService() 062 { 063 getService(); 064 } 065 066 }