Search in sources :

Example 1 with DEFAULT_STUB_EVENT

use of org.apache.dubbo.rpc.Constants.DEFAULT_STUB_EVENT in project dubbo by alibaba.

the class DubboProtocol method export.

@Override
public <T> Exporter<T> export(Invoker<T> invoker) throws RpcException {
    URL url = invoker.getUrl();
    // export service.
    String key = serviceKey(url);
    DubboExporter<T> exporter = new DubboExporter<T>(invoker, key, exporterMap);
    exporterMap.addExportMap(key, exporter);
    // export an stub service for dispatching event
    Boolean isStubSupportEvent = url.getParameter(STUB_EVENT_KEY, DEFAULT_STUB_EVENT);
    Boolean isCallbackservice = url.getParameter(IS_CALLBACK_SERVICE, false);
    if (isStubSupportEvent && !isCallbackservice) {
        String stubServiceMethods = url.getParameter(STUB_EVENT_METHODS_KEY);
        if (stubServiceMethods == null || stubServiceMethods.length() == 0) {
            if (logger.isWarnEnabled()) {
                logger.warn(new IllegalStateException("consumer [" + url.getParameter(INTERFACE_KEY) + "], has set stubproxy support event ,but no stub methods founded."));
            }
        }
    }
    openServer(url);
    optimizeSerialization(url);
    return exporter;
}
Also used : DEFAULT_STUB_EVENT(org.apache.dubbo.rpc.Constants.DEFAULT_STUB_EVENT) DEFAULT_HEARTBEAT(org.apache.dubbo.remoting.Constants.DEFAULT_HEARTBEAT) DEFAULT_REMOTING_CLIENT(org.apache.dubbo.remoting.Constants.DEFAULT_REMOTING_CLIENT) URL(org.apache.dubbo.common.URL)

Example 2 with DEFAULT_STUB_EVENT

use of org.apache.dubbo.rpc.Constants.DEFAULT_STUB_EVENT in project dubbo by alibaba.

the class StubProxyFactoryWrapper method getProxy.

@Override
public <T> T getProxy(Invoker<T> invoker, boolean generic) throws RpcException {
    T proxy = proxyFactory.getProxy(invoker, generic);
    if (GenericService.class != invoker.getInterface()) {
        URL url = invoker.getUrl();
        String stub = url.getParameter(STUB_KEY, url.getParameter(LOCAL_KEY));
        if (ConfigUtils.isNotEmpty(stub)) {
            Class<?> serviceType = invoker.getInterface();
            if (ConfigUtils.isDefault(stub)) {
                if (url.hasParameter(STUB_KEY)) {
                    stub = serviceType.getName() + "Stub";
                } else {
                    stub = serviceType.getName() + "Local";
                }
            }
            try {
                Class<?> stubClass = ReflectUtils.forName(stub);
                if (!serviceType.isAssignableFrom(stubClass)) {
                    throw new IllegalStateException("The stub implementation class " + stubClass.getName() + " not implement interface " + serviceType.getName());
                }
                try {
                    Constructor<?> constructor = ReflectUtils.findConstructor(stubClass, serviceType);
                    proxy = (T) constructor.newInstance(new Object[] { proxy });
                    // export stub service
                    URLBuilder urlBuilder = URLBuilder.from(url);
                    if (url.getParameter(STUB_EVENT_KEY, DEFAULT_STUB_EVENT)) {
                        urlBuilder.addParameter(STUB_EVENT_METHODS_KEY, StringUtils.join(Wrapper.getWrapper(proxy.getClass()).getDeclaredMethodNames(), ","));
                        urlBuilder.addParameter(IS_SERVER_KEY, Boolean.FALSE.toString());
                        try {
                            export(proxy, (Class) invoker.getInterface(), urlBuilder.build());
                        } catch (Exception e) {
                            LOGGER.error("export a stub service error.", e);
                        }
                    }
                } catch (NoSuchMethodException e) {
                    throw new IllegalStateException("No such constructor \"public " + stubClass.getSimpleName() + "(" + serviceType.getName() + ")\" in stub implementation class " + stubClass.getName(), e);
                }
            } catch (Throwable t) {
                LOGGER.error("Failed to create stub implementation class " + stub + " in consumer " + NetUtils.getLocalHost() + " use dubbo version " + Version.getVersion() + ", cause: " + t.getMessage(), t);
            // ignore
            }
        }
    }
    return proxy;
}
Also used : DEFAULT_STUB_EVENT(org.apache.dubbo.rpc.Constants.DEFAULT_STUB_EVENT) URL(org.apache.dubbo.common.URL) RpcException(org.apache.dubbo.rpc.RpcException) URLBuilder(org.apache.dubbo.common.URLBuilder)

Aggregations

URL (org.apache.dubbo.common.URL)2 DEFAULT_STUB_EVENT (org.apache.dubbo.rpc.Constants.DEFAULT_STUB_EVENT)2 URLBuilder (org.apache.dubbo.common.URLBuilder)1 DEFAULT_HEARTBEAT (org.apache.dubbo.remoting.Constants.DEFAULT_HEARTBEAT)1 DEFAULT_REMOTING_CLIENT (org.apache.dubbo.remoting.Constants.DEFAULT_REMOTING_CLIENT)1 RpcException (org.apache.dubbo.rpc.RpcException)1