Skip to content

Commit

Permalink
Merge pull request apache#2636, move the classes of model from config…
Browse files Browse the repository at this point in the history
… to rpc-api for reusing.
  • Loading branch information
Jeff-Lv authored and chickenlj committed Oct 12, 2018
1 parent adb5b0e commit 45b3ab4
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import org.apache.dubbo.common.utils.ReflectUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.model.ApplicationModel;
import org.apache.dubbo.config.model.ConsumerModel;
import org.apache.dubbo.config.support.Parameter;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
Expand All @@ -38,6 +36,8 @@
import org.apache.dubbo.rpc.cluster.directory.StaticDirectory;
import org.apache.dubbo.rpc.cluster.support.AvailableCluster;
import org.apache.dubbo.rpc.cluster.support.ClusterUtils;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.ConsumerModel;
import org.apache.dubbo.rpc.protocol.injvm.InjvmProtocol;
import org.apache.dubbo.rpc.service.GenericService;
import org.apache.dubbo.rpc.support.ProtocolUtils;
Expand Down Expand Up @@ -334,7 +334,7 @@ private void init() {
//attributes are stored by system context.
StaticContext.getSystemContext().putAll(attributes);
ref = createProxy(map);
ConsumerModel consumerModel = new ConsumerModel(getUniqueServiceName(), this, ref, interfaceClass.getMethods());
ConsumerModel consumerModel = new ConsumerModel(getUniqueServiceName(), ref, interfaceClass.getMethods());
ApplicationModel.initConsumerModel(getUniqueServiceName(), consumerModel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.annotation.Service;
import org.apache.dubbo.config.invoker.DelegateProviderMetaDataInvoker;
import org.apache.dubbo.config.model.ApplicationModel;
import org.apache.dubbo.config.model.ProviderModel;
import org.apache.dubbo.config.support.Parameter;
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
import org.apache.dubbo.rpc.ProxyFactory;
import org.apache.dubbo.rpc.ServiceClassHolder;
import org.apache.dubbo.rpc.cluster.ConfiguratorFactory;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.ProviderModel;
import org.apache.dubbo.rpc.service.GenericService;
import org.apache.dubbo.rpc.support.ProtocolUtils;

Expand Down Expand Up @@ -315,7 +315,7 @@ protected synchronized void doExport() {
path = interfaceName;
}
doExportUrls();
ProviderModel providerModel = new ProviderModel(getUniqueServiceName(), this, ref);
ProviderModel providerModel = new ProviderModel(getUniqueServiceName(), ref, interfaceClass);
ApplicationModel.initProviderModel(getUniqueServiceName(), providerModel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
*/
package org.apache.dubbo.qos.command.impl;

import org.apache.dubbo.config.model.ApplicationModel;
import org.apache.dubbo.config.model.ConsumerModel;
import org.apache.dubbo.config.model.ProviderModel;
import org.apache.dubbo.qos.command.BaseCommand;
import org.apache.dubbo.qos.command.CommandContext;
import org.apache.dubbo.qos.command.annotation.Cmd;
import org.apache.dubbo.qos.textui.TTable;
import org.apache.dubbo.registry.support.ConsumerInvokerWrapper;
import org.apache.dubbo.registry.support.ProviderConsumerRegTable;
import org.apache.dubbo.registry.support.ProviderInvokerWrapper;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.ConsumerModel;
import org.apache.dubbo.rpc.model.ProviderModel;

import java.util.Collection;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.config.model.ApplicationModel;
import org.apache.dubbo.config.model.ProviderModel;
import org.apache.dubbo.qos.command.BaseCommand;
import org.apache.dubbo.qos.command.CommandContext;
import org.apache.dubbo.qos.command.annotation.Cmd;
import org.apache.dubbo.registry.Registry;
import org.apache.dubbo.registry.RegistryFactory;
import org.apache.dubbo.registry.support.ProviderConsumerRegTable;
import org.apache.dubbo.registry.support.ProviderInvokerWrapper;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.ProviderModel;

import java.util.Collection;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.config.model.ApplicationModel;
import org.apache.dubbo.config.model.ProviderModel;
import org.apache.dubbo.qos.command.BaseCommand;
import org.apache.dubbo.qos.command.CommandContext;
import org.apache.dubbo.qos.command.annotation.Cmd;
import org.apache.dubbo.registry.Registry;
import org.apache.dubbo.registry.RegistryFactory;
import org.apache.dubbo.registry.support.ProviderConsumerRegTable;
import org.apache.dubbo.registry.support.ProviderInvokerWrapper;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.ProviderModel;

import java.util.Collection;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
package org.apache.dubbo.qos.command.impl;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.config.model.ApplicationModel;
import org.apache.dubbo.config.model.ConsumerModel;
import org.apache.dubbo.config.model.ProviderModel;
import org.apache.dubbo.qos.command.CommandContext;
import org.apache.dubbo.registry.integration.RegistryDirectory;
import org.apache.dubbo.registry.support.ProviderConsumerRegTable;
import org.apache.dubbo.registry.support.ProviderInvokerWrapper;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.ConsumerModel;
import org.apache.dubbo.rpc.model.ProviderModel;
import org.junit.Test;
import org.mockito.Mockito;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
package org.apache.dubbo.qos.command.impl;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.config.model.ApplicationModel;
import org.apache.dubbo.config.model.ProviderModel;
import org.apache.dubbo.qos.command.CommandContext;
import org.apache.dubbo.registry.Registry;
import org.apache.dubbo.registry.support.ProviderConsumerRegTable;
import org.apache.dubbo.registry.support.ProviderInvokerWrapper;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.ProviderModel;
import org.junit.Test;
import org.mockito.Mockito;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
package org.apache.dubbo.qos.command.impl;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.config.model.ApplicationModel;
import org.apache.dubbo.config.model.ProviderModel;
import org.apache.dubbo.qos.command.CommandContext;
import org.apache.dubbo.registry.Registry;
import org.apache.dubbo.registry.support.ProviderConsumerRegTable;
import org.apache.dubbo.registry.support.ProviderInvokerWrapper;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.ProviderModel;
import org.junit.Test;

import static org.apache.dubbo.registry.support.ProviderConsumerRegTable.getProviderInvoker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.model;
package org.apache.dubbo.rpc.model;

import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
Expand All @@ -30,7 +30,7 @@

import static java.util.stream.Collectors.toSet;

// TODO need to adjust project structure in order to fully utilize the methods introduced here.
// adjust project structure in order to fully utilize the methods introduced here.
public class ApplicationModel {

protected static final Logger logger = LoggerFactory.getLogger(ApplicationModel.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.model;
package org.apache.dubbo.rpc.model;

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.config.ReferenceConfig;

import java.lang.reflect.Method;

public class ConsumerMethodModel {
private final Method method;
private final ReferenceConfig metadata;
// private final boolean isCallBack;
// private final boolean isCallBack;
// private final boolean isFuture;
private final String[] parameterTypes;
private final Class<?>[] parameterClasses;
private final Class<?> returnClass;
private final String methodName;
private final boolean generic;

public ConsumerMethodModel(Method method, ReferenceConfig metadata) {
public ConsumerMethodModel(Method method) {
this.method = method;
this.parameterClasses = method.getParameterTypes();
this.returnClass = method.getReturnType();
this.parameterTypes = this.createParamSignature(parameterClasses);
this.methodName = method.getName();
this.metadata = metadata;
this.generic = methodName.equals(Constants.$INVOKE) && parameterTypes != null && parameterTypes.length == 3;
}

Expand All @@ -51,7 +48,6 @@ public Class<?> getReturnClass() {
}



public String getMethodName() {
return methodName;
}
Expand All @@ -60,13 +56,9 @@ public String[] getParameterTypes() {
return parameterTypes;
}

public ReferenceConfig getMetadata() {
return metadata;
}

private String[] createParamSignature(Class<?>[] args) {
if (args == null || args.length == 0) {
return new String[] {};
return new String[]{};
}
String[] paramSig = new String[args.length];
for (int x = 0; x < args.length; x++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.model;

import org.apache.dubbo.config.ReferenceConfig;
package org.apache.dubbo.rpc.model;

import java.lang.reflect.Method;
import java.util.ArrayList;
Expand All @@ -25,33 +23,22 @@
import java.util.Map;

public class ConsumerModel {
private ReferenceConfig metadata;
private Object proxyObject;
private String serviceName;
private final Object proxyObject;
private final String serviceName;

private final Map<Method, ConsumerMethodModel> methodModels = new IdentityHashMap<Method, ConsumerMethodModel>();

public ConsumerModel(String serviceName,ReferenceConfig metadata, Object proxyObject, Method[] methods) {
public ConsumerModel(String serviceName, Object proxyObject, Method[] methods) {
this.serviceName = serviceName;
this.metadata = metadata;
this.proxyObject = proxyObject;

if (proxyObject != null) {
for (Method method : methods) {
methodModels.put(method, new ConsumerMethodModel(method, metadata));
methodModels.put(method, new ConsumerMethodModel(method));
}
}
}

/**
* Return service metadata for consumer
*
* @return service metadata
*/
public ReferenceConfig getMetadata() {
return metadata;
}

public Object getProxyObject() {
return proxyObject;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.model;
package org.apache.dubbo.rpc.model;

import java.lang.reflect.Method;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.model;

import org.apache.dubbo.config.ServiceConfig;
package org.apache.dubbo.rpc.model;

import java.lang.reflect.Method;
import java.util.ArrayList;
Expand All @@ -28,17 +26,17 @@
public class ProviderModel {
private final String serviceName;
private final Object serviceInstance;
private final ServiceConfig metadata;
private final Class<?> serviceInterfaceClass;
private final Map<String, List<ProviderMethodModel>> methods = new HashMap<String, List<ProviderMethodModel>>();

public ProviderModel(String serviceName, ServiceConfig metadata, Object serviceInstance) {
public ProviderModel(String serviceName, Object serviceInstance, Class<?> serviceInterfaceClass) {
if (null == serviceInstance) {
throw new IllegalArgumentException("Service[" + serviceName + "]Target is NULL.");
}

this.serviceName = serviceName;
this.metadata = metadata;
this.serviceInstance = serviceInstance;
this.serviceInterfaceClass = serviceInterfaceClass;

initMethod();
}
Expand All @@ -48,10 +46,6 @@ public String getServiceName() {
return serviceName;
}

public ServiceConfig getMetadata() {
return metadata;
}

public Object getServiceInstance() {
return serviceInstance;
}
Expand All @@ -78,7 +72,7 @@ public ProviderMethodModel getMethodModel(String methodName, String[] argTypes)

private void initMethod() {
Method[] methodsToExport = null;
methodsToExport = metadata.getInterfaceClass().getMethods();
methodsToExport = this.serviceInterfaceClass.getMethods();

for (Method method : methodsToExport) {
method.setAccessible(true);
Expand Down

0 comments on commit 45b3ab4

Please sign in to comment.