Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2005-2012 The Kuali Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.opensource.org/licenses/ecl2.php Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
package org.kuali.rice.ksb.messaging;
This class creates a proxy for services deployed on KSB. A reference to the service is obtained only upon the first method invocation.

Author(s):
Kuali Rice Team (rice.collab@kuali.org)
public class KSBClientProxy implements InvocationHandler {
private static final Logger LOG = Logger.getLogger(KSBClientProxy.class);
    
    private QName serviceName;
    private volatile Object service;
    public static <T> T newInstance(String serviceQNameClass<T> interfaceClassthrows InstantiationExceptionIllegalAccessException {
        if (StringUtils.isBlank(serviceQName)) {
            throw new IllegalArgumentException("the qname was blank");
        }
        if (interfaceClass == null) {
            throw new IllegalArgumentException("the interfaceClass was null");
        }
        @SuppressWarnings("unchecked")
        final T t = (T)Proxy.newProxyInstance(interfaceClass.getClassLoader(), new Class[] { interfaceClass }, new KSBClientProxy(serviceQName));
        return t;
    }
    public KSBClientProxy(String serviceQName){
        if (StringUtils.isBlank(serviceQName)) {
            throw new IllegalArgumentException("the qname was blank");
        }
        this. = QName.valueOf(serviceQName);
    }
    
    public Object invoke(Object proxyMethod methodObject[] argsthrows Throwable {
        //using DCL idiom
        //see effective java 2nd ed. pg. 71
        Object s = ;
        if (s == null) {
            synchronized (this) {
                s = ;
                if (s == null) {
                     = s = GlobalResourceLoader.getService();
                }
            }
        }
        if (s != null) {
            return method.invoke(sargs);
        }
        .warn("serviceName: " +  + " was not found");
        return null;
    }
New to GrepCode? Check out our FAQ X