8000 refactor aware processor by taobaorun · Pull Request #1130 · sofastack/sofa-boot · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

refactor aware processor #1130

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

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import com.alipay.sofa.runtime.spi.service.BindingConverterFactory;
import com.alipay.sofa.runtime.spring.AsyncInitBeanFactoryPostProcessor;
import com.alipay.sofa.runtime.spring.AsyncProxyBeanPostProcessor;
import com.alipay.sofa.runtime.spring.JvmFilterPostProcessor;
import com.alipay.sofa.runtime.spring.RuntimeContextBeanFactoryPostProcessor;
import com.alipay.sofa.runtime.spring.ServiceBeanFactoryPostProcessor;
import com.alipay.sofa.runtime.spring.SofaShareBeanFactoryPostProcessor;
Expand Down Expand Up @@ -130,12 +129,6 @@ public static RuntimeContextBeanFactoryPostProcessor runtimeContextBeanFactoryPo
return new RuntimeContextBeanFactoryPostProcessor();
}

@Bean
@ConditionalOnMissingBean
public static JvmFilterPostProcessor jvmFilterPostProcessor() {
return new JvmFilterPostProcessor();
}

@Bean
@ConditionalOnMissingBean
@ConditionalOnClass(name = "com.alipay.sofa.isle.ApplicationRuntimeModel")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,37 @@
*/
package com.alipay.sofa.runtime.spring;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

import com.alipay.sofa.boot.error.ErrorCode;
import com.alipay.sofa.runtime.api.annotation.SofaClientFactory;
import com.alipay.sofa.runtime.api.aware.ClientFactoryAware;
import com.alipay.sofa.runtime.api.client.ClientFactory;
import com.alipay.sofa.runtime.client.impl.ClientFactoryImpl;
import com.alipay.sofa.runtime.spring.singleton.SingletonSofaPostProcessor;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.core.PriorityOrdered;
import org.springframework.util.ReflectionUtils;

import com.alipay.sofa.runtime.api.annotation.SofaClientFactory;
import com.alipay.sofa.runtime.api.aware.ClientFactoryAware;
import com.alipay.sofa.runtime.api.client.ClientFactory;
import com.alipay.sofa.runtime.client.impl.ClientFactoryImpl;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

/**
* {@link ClientFactoryAware}
* {@link ClientFactoryAware}
* {@link SofaClientFactory} handler
*
* @author xuanbei 18/3/2
*/
public class ClientFactoryBeanPostProcessor implements BeanPostProcessor, PriorityOrdered {
@SingletonSofaPostProcessor
public class ClientFactoryAnnotationBeanPostProcessor implements BeanPostProcessor, PriorityOrdered {
private ClientFactory clientFactory;

public ClientFactoryBeanPostProcessor(ClientFactory clientFactory) {
public ClientFactoryAnnotationBeanPostProcessor(ClientFactory clientFactory) {
this.clientFactory = clientFactory;
}

@Override
public Object postProcessBeforeInitialization(final Object bean, String beanName)
throws BeansException {
if (bean instanceof ClientFactoryAware) {
((ClientFactoryAware) bean).setClientFactory(clientFactory);
}

ReflectionUtils.doWithFields(bean.getClass(), new ReflectionUtils.FieldCallback() {

@Override
Expand Down Expand Up @@ -80,12 +77,6 @@ public boolean matches(Field field) {
return bean;
}

@Override
public Object postProcessAfterInitialization(Object bean, String beanName)
throws BeansException {
return bean;
}

@Override
public int getOrder() {
return PriorityOrdered.HIGHEST_PRECEDENCE;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
*/
package com.alipay.sofa.runtime.spring;

import com.alipay.sofa.runtime.spi.binding.BindingAdapterFactory;
import com.alipay.sofa.runtime.spi.component.SofaRuntimeContext;
import com.alipay.sofa.runtime.spi.service.BindingConverterFactory;
import com.alipay.sofa.runtime.spring.bean.SofaParameterNameDiscoverer;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
Expand All @@ -25,12 +29,6 @@
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;

import com.alipay.sofa.runtime.ext.client.ExtensionClientImpl;
import com.alipay.sofa.runtime.spi.binding.BindingAdapterFactory;
import com.alipay.sofa.runtime.spi.component.SofaRuntimeContext;
import com.alipay.sofa.runtime.spi.service.BindingConverterFactory;
import com.alipay.sofa.runtime.spring.bean.SofaParameterNameDiscoverer;

/**
* @author qilong.zql
* @since 3.2.0
Expand Down Expand Up @@ -59,18 +57,14 @@ public RuntimeContextBeanFactoryPostProcessor(BindingAdapterFactory bindingAdapt
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
throws BeansException {
// work on all bean
beanFactory.addBeanPostProcessor(new SofaRuntimeContextAwareProcessor(sofaRuntimeContext));
beanFactory.addBeanPostProcessor(new ClientFactoryBeanPostProcessor(sofaRuntimeContext
.getClientFactory()));
beanFactory.addBeanPostProcessor(new ExtensionClientBeanPostProcessor(
new ExtensionClientImpl(sofaRuntimeContext)));
beanFactory.addBeanPostProcessor(new SofaRuntimeAwareProcessor(sofaRuntimeContext
.getSofaRuntimeManager()));
beanFactory.addBeanPostProcessor(new ClientFactoryAnnotationBeanPostProcessor(
sofaRuntimeContext.getClientFactory()));
beanFactory
.addBeanPostProcessor(new ReferenceAnnotationBeanPostProcessor(applicationContext,
sofaRuntimeContext, bindingAdapterFactory, bindingConverterFactory));

beanFactory.registerSingleton(RuntimeShutdownAwarePostProcessor.class.getSimpleName(),
new RuntimeShutdownAwarePostProcessor(sofaRuntimeContext.getSofaRuntimeManager()));

if (beanFactory instanceof AbstractAutowireCapableBeanFactory) {
((AbstractAutowireCapableBeanFactory) beanFactory)
.setParameterNameDiscoverer(new SofaParameterNameDiscoverer(applicationContext
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.runtime.spring;

import com.alipay.sofa.runtime.SofaRuntimeUtils;
import com.alipay.sofa.runtime.api.aware.ClientFactoryAware;
import com.alipay.sofa.runtime.api.aware.ExtensionClientAware;
import com.alipay.sofa.runtime.ext.client.ExtensionClientImpl;
import com.alipay.sofa.runtime.filter.JvmFilter;
import com.alipay.sofa.runtime.filter.JvmFilterHolder;
import com.alipay.sofa.runtime.spi.client.ClientFactoryInternal;
import com.alipay.sofa.runtime.spi.component.SofaRuntimeContext;
import com.alipay.sofa.runtime.spi.component.SofaRuntimeManager;
import com.alipay.sofa.runtime.spi.spring.RuntimeShutdownAware;
import com.alipay.sofa.runtime.spi.spring.SofaRuntimeContextAware;
import com.alipay.sofa.runtime.spring.singleton.SingletonSofaPostProcessor;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.core.PriorityOrdered;

/**
* @author yuanxuan
* @version : SofaRuntimeAwareProcessor.java, v 0.1 2023年03月28日 15:52 yuanxuan Exp $
*/
@SingletonSofaPostProcessor
public class SofaRuntimeAwareProcessor implements BeanPostProcessor, PriorityOrdered {

private final SofaRuntimeManager sofaRuntimeManager;

private final SofaRuntimeContext sofaRuntimeContext;

private final ClientFactoryInternal clientFactory;

private final ExtensionClientImpl extensionClient;

public SofaRuntimeAwareProcessor(SofaRuntimeManager sofaRuntimeManager) {
this.sofaRuntimeManager = sofaRuntimeManager;
this.sofaRuntimeContext = sofaRuntimeManager.getSofaRuntimeContext();
this.clientFactory = sofaRuntimeManager.getClientFactoryInternal();
this.extensionClient = new ExtensionClientImpl(sofaRuntimeContext);
}

@Override
public int getOrder() {
return PriorityOrdered.HIGHEST_PRECEDENCE;
}

@Override
public Object postProcessBeforeInitialization(Object bean, String beanName)
throws BeansException {
if (bean instanceof SofaRuntimeContextAware) {
((SofaRuntimeContextAware) bean).setSofaRuntimeContext(sofaRuntimeContext);
}
if (bean instanceof ClientFactoryAware) {
((ClientFactoryAware) bean).setClientFactory(clientFactory);
}
if (bean instanceof ExtensionClientAware) {
((ExtensionClientAware) bean).setExtensionClient(extensionClient);
}
if (!SofaRuntimeUtils.isArkEnvironment() || SofaRuntimeUtils.onMasterBiz()) {
if (bean instanceof JvmFilter) {
JvmFilterHolder.addJvmFilter((JvmFilter) bean);
}
}
if (bean instanceof RuntimeShutdownAware) {
sofaRuntimeManager.registerShutdownAware((RuntimeShutdownAware) bean);
}
return bean;
}
}
Loading
0