Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support skip seralize #379

Merged
merged 5 commits into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion healthcheck-sofa-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-boot-runtime</artifactId>
<version>2.6.1</version>
<version>2.6.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion infra-sofa-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-boot-runtime</artifactId>
<version>2.6.1</version>
<version>2.6.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@
<xsd:attribute name="registry" type="xsd:string" use="optional"/>
<xsd:attribute name="serialize-type" type="xsd:string" use="optional"/>
</xsd:complexType>
<!-- binding.jvm in reference -->
<xsd:complexType name="BBindingJvmReference">
<xsd:attribute name="serialize" type="xsd:boolean" default="false" use="optional"/>
</xsd:complexType>
<!-- binding.bolt in reference -->
<xsd:complexType name="BBindingTRReference">
<xsd:complexContent>
Expand All @@ -141,6 +145,10 @@
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<!--jvm service-->
<xsd:complexType name="BBindingJvmService">
<xsd:attribute name="serialize" type="xsd:boolean" default="true" use="optional"/>
</xsd:complexType>
<!-- binding.bolt in service -->
<xsd:complexType name="BBindingTRService">
<xsd:complexContent>
Expand Down Expand Up @@ -567,7 +575,7 @@
<xsd:complexContent>
<xsd:extension base="beans:identifiedType">
<xsd:all minOccurs="0" maxOccurs="1">
<xsd:element name="binding.jvm" minOccurs="0"/>
<xsd:element name="binding.jvm" type="BBindingJvmReference" minOccurs="0"/>
<xsd:element name="binding.bolt" type="BBindingTRReference" minOccurs="0"/>
<xsd:element name="binding.rest" type="RestBindingTRReference" minOccurs="0"/>
<xsd:element name="binding.dubbo" type="DubboBindingTRReference" minOccurs="0"/>
Expand All @@ -590,7 +598,7 @@
<xsd:complexContent>
<xsd:extension base="beans:identifiedType">
<xsd:all minOccurs="0" maxOccurs="1">
<xsd:element name="binding.jvm" minOccurs="0"/>
<xsd:element name="binding.jvm" type="BBindingJvmService" minOccurs="0"/>
<xsd:element name="binding.bolt" type="BBindingTRService" minOccurs="0"/>
<xsd:element name="binding.rest" type="RestBindingTRService" minOccurs="0"/>
<xsd:element name="binding.dubbo" type="DubboBindingTRService" minOccurs="0"/>
Expand Down
2 changes: 1 addition & 1 deletion isle-sofa-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-boot-runtime</artifactId>
<version>2.6.1</version>
<version>2.6.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofaboot-dependencies</artifactId>
<version>2.6.1</version>
<version>2.6.3-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>sofa-boot-runtime</artifactId>
<packaging>pom</packaging>
<version>2.6.2-SNAPSHOT</version>

<name>SOFABoot Runtime</name>
<description>SOFABoot Runtime</description>
Expand Down
146 changes: 78 additions & 68 deletions runtime-sofa-boot-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-boot-runtime</artifactId>
<version>2.6.1</version>
<version>2.6.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand All @@ -46,77 +46,87 @@
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-ark-plugin-maven-plugin</artifactId>
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>ark-plugin</goal>
</goals>
<profiles>
<profile>
<id>jdk8</id>
<activation>
<jdk>1.8</jdk>
</activation>

<configuration>
<priority>1500</priority>
<pluginName>${ark.plugin.name}</pluginName>
<activator>com.alipay.sofa.runtime.integration.activator.SofaRuntimeActivator</activator>
<build>
<plugins>
<plugin>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-ark-plugin-maven-plugin</artifactId>
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>ark-plugin</goal>
</goals>

<exported>
<packages>
<package>com.alipay.sofa.runtime.api.*</package>
<package>com.alipay.sofa.runtime.client.*</package>
<package>com.alipay.sofa.runtime.component.*</package>
<package>com.alipay.sofa.runtime.constants.*</package>
<package>com.alipay.sofa.runtime.integration.*</package>
<package>com.alipay.sofa.runtime.model.*</package>
<package>com.alipay.sofa.runtime.service.component</package>
<package>com.alipay.sofa.runtime.service.helper</package>
<package>com.alipay.sofa.runtime.spi.client</package>
<package>com.alipay.sofa.runtime.spi.component</package>
<package>com.alipay.sofa.runtime.spi.health</package>
<package>com.alipay.sofa.runtime.spi.log</package>
<package>com.alipay.sofa.runtime.spi.binding</package>
<package>com.alipay.sofa.runtime.spi.service</package>
<package>com.alipay.sofa.runtime.spi.util</package>
<package>org.aopalliance.aop</package>
<package>org.aopalliance.intercept</package>
</packages>
<configuration>
<priority>1500</priority>
<pluginName>${ark.plugin.name}</pluginName>
<activator>com.alipay.sofa.runtime.integration.activator.SofaRuntimeActivator</activator>

<classes>
<class>com.alipay.sofa.runtime.service.binding.JvmBinding</class>
<class>com.alipay.sofa.runtime.SofaFramework</class>
<class>com.alipay.sofa.runtime.SofaRuntimeProperties</class>
</classes>
</exported>
<exported>
<packages>
<package>com.alipay.sofa.runtime.api.*</package>
<package>com.alipay.sofa.runtime.client.*</package>
<package>com.alipay.sofa.runtime.component.*</package>
<package>com.alipay.sofa.runtime.constants.*</package>
<package>com.alipay.sofa.runtime.integration.*</package>
<package>com.alipay.sofa.runtime.model.*</package>
<package>com.alipay.sofa.runtime.service.component</package>
<package>com.alipay.sofa.runtime.service.helper</package>
<package>com.alipay.sofa.runtime.spi.client</package>
<package>com.alipay.sofa.runtime.spi.component</package>
<package>com.alipay.sofa.runtime.spi.health</package>
<package>com.alipay.sofa.runtime.spi.log</package>
<package>com.alipay.sofa.runtime.spi.binding</package>
<package>com.alipay.sofa.runtime.spi.util</package>
<package>org.aopalliance.aop</package>
<package>org.aopalliance.intercept</package>
</packages>

<excludeGroupIds>
<excludeGroupId>org.springframework</excludeGroupId>
<excludeGroupId>org.springframework.boot</excludeGroupId>
<excludeGroupId>org.apache.tomcat.embed</excludeGroupId>
</excludeGroupIds>
<classes>
<class>com.alipay.sofa.runtime.service.binding.JvmBinding</class>
<class>com.alipay.sofa.runtime.SofaFramework</class>
<class>com.alipay.sofa.runtime.SofaRuntimeProperties</class>
<class>com.alipay.sofa.runtime.service.binding.JvmBindingParam</class>
<class>com.alipay.sofa.runtime.spi.service.ServiceProxy</class>
</classes>
</exported>

<excludeArtifactIds>
<excludeArtifactId>hibernate-validator</excludeArtifactId>
<excludeArtifactId>classmate</excludeArtifactId>
<excludeArtifactId>jboss-logging</excludeArtifactId>
<excludeArtifactId>jackson-annotations</excludeArtifactId>
<excludeArtifactId>jackson-core</excludeArtifactId>
<excludeArtifactId>jackson-databind</excludeArtifactId>
<excludeArtifactId>jcl-over-slf4j</excludeArtifactId>
<excludeArtifactId>jul-to-slf4j</excludeArtifactId>
<excludeArtifactId>log4j-over-slf4j</excludeArtifactId>
<excludeArtifactId>logback-core</excludeArtifactId>
<excludeArtifactId>logback-classic</excludeArtifactId>
<excludeArtifactId>snakeyaml</excludeArtifactId>
<excludeArtifactId>validation-api</excludeArtifactId>
</excludeArtifactIds>
<excludeGroupIds>
<excludeGroupId>org.springframework</excludeGroupId>
<excludeGroupId>org.springframework.boot</excludeGroupId>
<excludeGroupId>org.apache.tomcat.embed</excludeGroupId>
</excludeGroupIds>

</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<excludeArtifactIds>
<excludeArtifactId>hibernate-validator</excludeArtifactId>
<excludeArtifactId>classmate</excludeArtifactId>
<excludeArtifactId>jboss-logging</excludeArtifactId>
<excludeArtifactId>jackson-annotations</excludeArtifactId>
<excludeArtifactId>jackson-core</excludeArtifactId>
<excludeArtifactId>jackson-databind</excludeArtifactId>
<excludeArtifactId>jcl-over-slf4j</excludeArtifactId>
<excludeArtifactId>jul-to-slf4j</excludeArtifactId>
<excludeArtifactId>log4j-over-slf4j</excludeArtifactId>
<excludeArtifactId>logback-core</excludeArtifactId>
<excludeArtifactId>logback-classic</excludeArtifactId>
<excludeArtifactId>snakeyaml</excludeArtifactId>
<excludeArtifactId>validation-api</excludeArtifactId>
</excludeArtifactIds>

</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
2 changes: 1 addition & 1 deletion runtime-sofa-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-boot-runtime</artifactId>
<version>2.6.1</version>
<version>2.6.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,14 @@
* @return parameters of consumer
*/
SofaParameter[] parameters() default {};

/**
* serialization between biz, default is false.
* only serialize of reference and service is false
* then invocation between biz would skip serialization
* Note that the serialize of {@link SofaServiceBinding} is true
*
* @return
*/
boolean serialize() default false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,15 @@
* @return parameters of service
*/
SofaParameter[] parameters() default {};

/**
* serialization between biz, default is true.
* only serialize of reference and service is false
* then invocation between biz would skip serialization
*
* Note that the serialize of {@link SofaReferenceBinding} is false
*
* @return
*/
boolean serialize() default true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.alipay.sofa.ark.spi.model.BizState;
import com.alipay.sofa.ark.spi.service.ArkInject;
import com.alipay.sofa.ark.spi.service.biz.BizManagerService;
import com.alipay.sofa.runtime.service.binding.JvmBinding;
import com.alipay.sofa.runtime.service.component.ServiceComponent;
import com.alipay.sofa.runtime.SofaFramework;
import com.alipay.sofa.runtime.spi.binding.Contract;
Expand Down Expand Up @@ -70,9 +71,15 @@ public ServiceProxy findServiceProxy(ClassLoader clientClassloader, Contract con
ServiceComponent serviceComponent = findServiceComponent(uniqueId, interfaceType,
sofaRuntimeManager.getComponentManager());
if (serviceComponent != null) {
JvmBinding referenceJvmBinding = (JvmBinding) contract
.getBinding(JvmBinding.JVM_BINDING_TYPE);
JvmBinding serviceJvmBinding = (JvmBinding) serviceComponent.getService()
.getBinding(JvmBinding.JVM_BINDING_TYPE);
boolean serialize = referenceJvmBinding.getJvmBindingParam().isSerialize()
|| serviceJvmBinding.getJvmBindingParam().isSerialize();
return new DynamicJvmServiceInvoker(clientClassloader,
sofaRuntimeManager.getAppClassLoader(), serviceComponent.getService()
.getTarget(), contract, biz.getIdentity());
.getTarget(), contract, biz.getIdentity(), serialize);
}
}
}
Expand Down Expand Up @@ -123,19 +130,21 @@ static class DynamicJvmServiceInvoker extends ServiceProxy {
private Object targetService;
private String bizIdentity;
private ThreadLocal<ClassLoader> clientClassloader = new ThreadLocal<>();
private boolean serialize;

static protected final String TOSTRING_METHOD = "toString";
static protected final String EQUALS_METHOD = "equals";
static protected final String HASHCODE_METHOD = "hashCode";

public DynamicJvmServiceInvoker(ClassLoader clientClassloader,
ClassLoader serviceClassLoader, Object targetService,
Contract contract, String bizIdentity) {
Contract contract, String bizIdentity, boolean serialize) {
super(serviceClassLoader);
this.clientClassloader.set(clientClassloader);
this.targetService = targetService;
this.contract = contract;
this.bizIdentity = bizIdentity;
this.serialize = serialize;
}

@Override
Expand All @@ -148,6 +157,16 @@ protected Object doInvoke(MethodInvocation invocation) throws Throwable {
.debug(">> Start in Cross App JVM service invoke, the service interface is - "
+ getInterfaceType());

if (!serialize) {
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
try {
pushThreadContextClassLoader(getServiceClassLoader());
return targetMethod.invoke(targetService, targetArguments);
} finally {
pushThreadContextClassLoader(tcl);
}
}

if (TOSTRING_METHOD.equalsIgnoreCase(targetMethod.getName())
&& targetMethod.getParameterTypes().length == 0) {
return targetService.toString();
Expand Down Expand Up @@ -182,7 +201,9 @@ protected void doCatch(MethodInvocation invocation, Throwable e, long startTime)

@Override
protected void doFinally(MethodInvocation invocation, long startTime) {
SofaLogger.debug(getCommonInvocationLog("Finally", invocation, startTime));
if (SofaLogger.isDebugEnabled()) {
SofaLogger.debug(getCommonInvocationLog("Finally", invocation, startTime));
}
}

private Class getInterfaceType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package com.alipay.sofa.runtime.integration.service;

import com.alipay.sofa.ark.spi.constant.Constants;
import com.alipay.sofa.ark.spi.event.ArkEvent;
import com.alipay.sofa.ark.spi.event.BizEvent;
import com.alipay.sofa.ark.spi.model.Biz;
Expand All @@ -30,11 +29,15 @@
* @since 2.5.0
*/
public class SofaEventHandler implements EventHandler {
// TODO FIX After Release SOFAArk 1.0.0, the constant variable would be removed.
public final static String BIZ_EVENT_TOPIC_AFTER_INVOKE_BIZ_START = "AFTER-INVOKE-BIZ-START";
public final static String BIZ_EVENT_TOPIC_AFTER_INVOKE_BIZ_STOP = "AFTER-INVOKE-BIZ-STOP";

@Override
public void handleEvent(ArkEvent event) {
if (Constants.BIZ_EVENT_TOPIC_UNINSTALL.equals(event.getTopic())) {
if (BIZ_EVENT_TOPIC_AFTER_INVOKE_BIZ_STOP.equals(event.getTopic())) {
doUninstallBiz((BizEvent) event);
} else if (Constants.BIZ_EVENT_TOPIC_HEALTH_CHECK.equals(event.getTopic())) {
} else if (BIZ_EVENT_TOPIC_AFTER_INVOKE_BIZ_START.equals(event.getTopic())) {
doHealthCheck((BizEvent) event);
}
}
Expand Down
Loading