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

xin.alum.aim.AIM Maven / Gradle / Ivy

There is a newer version: 1.9.6
Show newest version
package xin.alum.aim;

import xin.alum.aim.constant.AIMConstant;
import xin.alum.aim.groups.ClusterFactory;
import xin.alum.aim.handler.AimReceiver;
import xin.alum.aim.config.AimProperties;
import xin.alum.aim.server.AimServer;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import lombok.SneakyThrows;
import lombok.experimental.UtilityClass;
import org.springframework.context.ApplicationContext;

/**
 * @auther alum(alum @ live.cn)
 * @date 2021/8/4 18:32
 */
@UtilityClass
public class AIM {

    protected InternalLogger logger =
            InternalLoggerFactory.getInstance(AIM.class);

    public ClusterFactory clusterFactory;

    /**
     * AIM 配置项
     */
    public AimProperties properties = new AimProperties();

    /**
     * AIM 业务处理
     */
    public AimReceiver request = new AimReceiver();


    public static class Builder {

        public Builder setAimRequest(AimReceiver request) {
            AIM.request = request;
            return this;
        }

        @SneakyThrows
        public void run() {
            this.run(properties);
        }

        @SneakyThrows
        public void run(AimProperties aimProperties) {
            properties = aimProperties;
            AimServer.run(aimProperties);
        }

        @SneakyThrows
        public void run(ApplicationContext context) {
            properties = context.getBean(AimProperties.class);
            switch (properties.getCluster().getMode()) {
                case None:
                    logger.warn("{} 服务未开启集群模式", AIMConstant.PROJECT_NAME);
                    break;
                default:
                    //注入集群
                    logger.warn("{} 服务开启【{}】集群模式", AIMConstant.PROJECT_NAME, properties.getCluster().getMode());
                    clusterFactory = context.getBean(ClusterFactory.class);
                    break;
            }
            AimServer.run(properties);
        }

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy