Skip to content

Commit

Permalink
DUBBO-627 ServiceConfig 支持配置 generic
Browse files Browse the repository at this point in the history
  • Loading branch information
kimi committed Jan 8, 2013
1 parent f489972 commit 3dccbc6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.alibaba.dubbo.rpc.ProxyFactory;
import com.alibaba.dubbo.rpc.cluster.ConfiguratorFactory;
import com.alibaba.dubbo.rpc.service.GenericService;
import com.alibaba.dubbo.rpc.support.ProtocolUtils;

/**
* ServiceConfig
Expand Down Expand Up @@ -87,7 +88,7 @@ public class ServiceConfig<T> extends AbstractServiceConfig {

private transient volatile boolean unexported;

private transient volatile boolean generic;
private volatile String generic;

public ServiceConfig() {
}
Expand Down Expand Up @@ -191,7 +192,9 @@ protected synchronized void doExport() {
}
if (ref instanceof GenericService) {
interfaceClass = GenericService.class;
generic = true;
if (StringUtils.isEmpty(generic)) {
generic = Boolean.TRUE.toString();
}
} else {
try {
interfaceClass = Class.forName(interfaceName, true, Thread.currentThread()
Expand All @@ -201,7 +204,7 @@ protected synchronized void doExport() {
}
checkInterfaceAndMethods(interfaceClass, methods);
checkRef();
generic = false;
generic = Boolean.FALSE.toString();
}
if(local !=null){
if(local=="true"){
Expand Down Expand Up @@ -414,8 +417,8 @@ private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List<URL> r
} // end of methods for
}

if (generic) {
map.put("generic", String.valueOf(true));
if (ProtocolUtils.isGeneric(generic)) {
map.put("generic", generic);
map.put("methods", Constants.ANY_VALUE);
} else {
String revision = Version.getVersion(interfaceClass, version);
Expand Down Expand Up @@ -612,6 +615,19 @@ public ProviderConfig getProvider() {
return provider;
}

public void setGeneric(String generic) {
if (StringUtils.isEmpty(generic)) { return; }
if (ProtocolUtils.isGeneric(generic)) {
this.generic = generic;
} else {
throw new IllegalArgumentException("Unsupported generic type " + generic);
}
}

public String getGeneric() {
return generic;
}

public void setProvider(ProviderConfig provider) {
this.provider = provider;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,11 @@
<xsd:documentation><![CDATA[ Deprecated. Replace to protocol. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="generic" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ Generic service. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:anyAttribute namespace="##other" processContents="lax" />
</xsd:extension>
</xsd:complexContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.extension.ExtensionLoader;
import com.alibaba.dubbo.common.utils.NetUtils;
Expand Down Expand Up @@ -939,6 +940,28 @@ public void testReferGenericExport() throws Exception {
}
}

@Test
public void testGenericServiceConfig() throws Exception {
ServiceConfig<GenericService> service = new ServiceConfig<GenericService>();
service.setApplication(new ApplicationConfig("test"));
service.setRegistry(new RegistryConfig("N/A"));
service.setInterface(DemoService.class.getName());
service.setGeneric(Constants.GENERIC_SERIALIZATION_BEAN);
service.setRef(new GenericService(){

public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException {
return null;
}
});
try {
service.export();
URL url = service.getExportedUrls().get(0);
Assert.assertEquals(Constants.GENERIC_SERIALIZATION_BEAN, url.getParameter(Constants.GENERIC_KEY));
} finally {
service.unexport();
}
}

private static void unexportService(ServiceConfig<?> config) {
if (config != null) {
config.unexport();
Expand Down

0 comments on commit 3dccbc6

Please sign in to comment.