All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.cattleframework.cloud.discovery.reflect.ServiceRegistryAspect Maven / Gradle / Ivy

There is a newer version: 1.0.1-M5
Show newest version
/*
 * Copyright (C) 2018 the original author or authors.
 *
 * Licensed 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 org.cattleframework.cloud.discovery.reflect;

import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.cattleframework.cloud.discovery.event.ServiceRegistryEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.client.serviceregistry.Registration;

/**
 * 服务注册切面类
 * 
 * @author orange
 *
 */
@Aspect
public class ServiceRegistryAspect {

    private static final Logger logger = LoggerFactory.getLogger(ServiceRegistryAspect.class);

    private final List serviceRegistryEvents;

    public ServiceRegistryAspect(List serviceRegistryEvents) {
	this.serviceRegistryEvents = serviceRegistryEvents;
    }

    @Pointcut("execution(public * org.springframework.cloud.client.serviceregistry.ServiceRegistry.register(..))")
    public void registerAspect() {
    }

    @Around("registerAspect()")
    public void register(ProceedingJoinPoint joinPoint) throws Throwable {
	if (CollectionUtils.isNotEmpty(serviceRegistryEvents)) {
	    Registration registration = (Registration) joinPoint.getArgs()[0];
	    serviceRegistryEvents.forEach(serviceRegistryEvent -> {
		logger.debug("执行服务注册事件类:{}", serviceRegistryEvent.getClass().getName());
		serviceRegistryEvent.onRegister(registration);
	    });
	}
	joinPoint.proceed();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy