Search in sources :

Example 1 with GENERIC_KEY

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

the class RmiProtocol method doRefer.

@Override
@SuppressWarnings("unchecked")
protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcException {
    final RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean();
    final String generic = url.getParameter(GENERIC_KEY);
    final boolean isGeneric = ProtocolUtils.isGeneric(generic) || serviceType.equals(GenericService.class);
    /*
          RMI needs extra parameter since it uses customized remote invocation object

          The customized RemoteInvocation was firstly introduced in v2.6.3; The package was renamed to 'org.apache.*' since v2.7.0
          Considering the above two conditions, we need to check before sending customized RemoteInvocation:
          1. if the provider version is v2.7.0 or higher, send 'org.apache.dubbo.rpc.protocol.rmi.RmiRemoteInvocation'.
          2. if the provider version is v2.6.3 or higher, send 'com.alibaba.dubbo.rpc.protocol.rmi.RmiRemoteInvocation'.
          3. if the provider version is lower than v2.6.3, does not use customized RemoteInvocation.
         */
    if (isRelease270OrHigher(url.getParameter(RELEASE_KEY))) {
        rmiProxyFactoryBean.setRemoteInvocationFactory(methodInvocation -> {
            RemoteInvocation invocation = new RmiRemoteInvocation(methodInvocation);
            if (isGeneric) {
                invocation.addAttribute(GENERIC_KEY, generic);
            }
            return invocation;
        });
    } else if (isRelease263OrHigher(url.getParameter(DUBBO_VERSION_KEY))) {
        rmiProxyFactoryBean.setRemoteInvocationFactory(methodInvocation -> {
            RemoteInvocation invocation = new com.alibaba.dubbo.rpc.protocol.rmi.RmiRemoteInvocation(methodInvocation);
            if (isGeneric) {
                invocation.addAttribute(GENERIC_KEY, generic);
            }
            return invocation;
        });
    }
    String serviceUrl = url.toIdentityString();
    if (isGeneric) {
        serviceUrl = serviceUrl + "/" + GENERIC_KEY;
    }
    rmiProxyFactoryBean.setServiceUrl(serviceUrl);
    rmiProxyFactoryBean.setServiceInterface(serviceType);
    rmiProxyFactoryBean.setCacheStub(true);
    rmiProxyFactoryBean.setLookupStubOnStartup(true);
    rmiProxyFactoryBean.setRefreshStubOnConnectFailure(true);
    rmiProxyFactoryBean.afterPropertiesSet();
    return (T) rmiProxyFactoryBean.getObject();
}
Also used : RemoteInvocation(org.springframework.remoting.support.RemoteInvocation) Version.isRelease263OrHigher(org.apache.dubbo.common.Version.isRelease263OrHigher) Version.isRelease270OrHigher(org.apache.dubbo.common.Version.isRelease270OrHigher) AbstractProxyProtocol(org.apache.dubbo.rpc.protocol.AbstractProxyProtocol) RemoteInvocation(org.springframework.remoting.support.RemoteInvocation) RmiProxyFactoryBean(org.springframework.remoting.rmi.RmiProxyFactoryBean) IOException(java.io.IOException) RpcException(org.apache.dubbo.rpc.RpcException) RemoteAccessException(org.springframework.remoting.RemoteAccessException) RemoteException(java.rmi.RemoteException) ProtocolUtils(org.apache.dubbo.rpc.support.ProtocolUtils) DUBBO_VERSION_KEY(org.apache.dubbo.common.constants.CommonConstants.DUBBO_VERSION_KEY) URL(org.apache.dubbo.common.URL) RmiServiceExporter(org.springframework.remoting.rmi.RmiServiceExporter) RELEASE_KEY(org.apache.dubbo.common.constants.CommonConstants.RELEASE_KEY) GENERIC_KEY(org.apache.dubbo.rpc.Constants.GENERIC_KEY) GenericService(org.apache.dubbo.rpc.service.GenericService) SocketTimeoutException(java.net.SocketTimeoutException) GenericService(org.apache.dubbo.rpc.service.GenericService) RmiProxyFactoryBean(org.springframework.remoting.rmi.RmiProxyFactoryBean)

Aggregations

IOException (java.io.IOException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 RemoteException (java.rmi.RemoteException)1 URL (org.apache.dubbo.common.URL)1 Version.isRelease263OrHigher (org.apache.dubbo.common.Version.isRelease263OrHigher)1 Version.isRelease270OrHigher (org.apache.dubbo.common.Version.isRelease270OrHigher)1 DUBBO_VERSION_KEY (org.apache.dubbo.common.constants.CommonConstants.DUBBO_VERSION_KEY)1 RELEASE_KEY (org.apache.dubbo.common.constants.CommonConstants.RELEASE_KEY)1 GENERIC_KEY (org.apache.dubbo.rpc.Constants.GENERIC_KEY)1 RpcException (org.apache.dubbo.rpc.RpcException)1 AbstractProxyProtocol (org.apache.dubbo.rpc.protocol.AbstractProxyProtocol)1 GenericService (org.apache.dubbo.rpc.service.GenericService)1 ProtocolUtils (org.apache.dubbo.rpc.support.ProtocolUtils)1 RemoteAccessException (org.springframework.remoting.RemoteAccessException)1 RmiProxyFactoryBean (org.springframework.remoting.rmi.RmiProxyFactoryBean)1 RmiServiceExporter (org.springframework.remoting.rmi.RmiServiceExporter)1 RemoteInvocation (org.springframework.remoting.support.RemoteInvocation)1