首页 > 其他分享 >设计模式11

设计模式11

时间:2024-10-11 21:22:49浏览次数:1  
标签:11 return notification void long rule 设计模式 public

package com.example.principle.ocp;

public class ApiInfo {

    private String api;
    private long requestCount;
    private long errorCount;
    private long durationOfSeconds;

    // private long timeoutCount;


    public String getApi() {
        return api;
    }

    public void setApi(String api) {
        this.api = api;
    }

    public long getRequestCount() {
        return requestCount;
    }

    public void setRequestCount(long requestCount) {
        this.requestCount = requestCount;
    }

    public long getErrorCount() {
        return errorCount;
    }

    public void setErrorCount(long errorCount) {
        this.errorCount = errorCount;
    }

    public long getDurationOfSeconds() {
        return durationOfSeconds;
    }

    public void setDurationOfSeconds(long durationOfSeconds) {
        this.durationOfSeconds = durationOfSeconds;
    }
}
package com.example.principle.ocp;

// 存储告警规则
public class AlertRule {


    public MatchRule getMatchedRule(String api) {
        return null;
    }

    class MatchRule {

        long maxTps;
        long maxErrorCount;

        //...... Maxtimeout


        public long getMaxTps() {
            return maxTps;
        }

        public void setMaxTps(long maxTps) {
            this.maxTps = maxTps;
        }

        public long getMaxErrorCount() {
            return maxErrorCount;
        }

        public void setMaxErrorCount(long maxErrorCount) {
            this.maxErrorCount = maxErrorCount;
        }
    }
}
package com.example.principle.ocp;

// 通知类 支持邮件、短信、微信、手机等多种通知渠道
public class Notification {

    // 通知
    void notify(NotificationEmergencyLevel level,String content) {
        // 略
    }


    // 表示通知的紧急程度,
    //包括 SEVERE(严重)、URGENCY(紧急)、NORMAL(普通)、TRIVIAL(无关紧要),不同的紧急程度对应不同的发送渠道
     enum NotificationEmergencyLevel {

        SEVERE(0,0),URGENCY(1,1),NORMAL(2,2),TRIVIAL(3,3);

        int channel ; //渠道
        int level; // 等级

        NotificationEmergencyLevel(int channel, int level) {
            this.channel = channel;
            this.level = level;
        }

        public int getChannel() {
            return channel;
        }

        public void setChannel(int channel) {
            this.channel = channel;
        }

        public int getLevel() {
            return level;
        }

        public void setLevel(int level) {
            this.level = level;
        }
    }
}
package com.example.principle.ocp;

public abstract class AlertHandler {

    protected AlertRule rule;
    protected Notification notification;

    public AlertHandler(AlertRule rule, Notification notification) {
        this.rule = rule;
        this.notification = notification;
    }


    public abstract void adaptiveAlert(ApiInfo apiInfo);
}

class TpsAlertHandler extends AlertHandler {

    public TpsAlertHandler(AlertRule rule, Notification notification) {
        super(rule, notification);
    }

    @Override
    public void adaptiveAlert(ApiInfo apiInfo) {
        long tps = apiInfo.getRequestCount() / apiInfo.getDurationOfSeconds();
        if (tps > rule.getMatchedRule(apiInfo.getApi()).getMaxTps()) {
            notification.notify(Notification.NotificationEmergencyLevel.URGENCY,".........");
        }
    }
}

class ErrorCountAlertHandler extends AlertHandler{

    public ErrorCountAlertHandler(AlertRule rule, Notification notification) {
        super(rule, notification);
    }

    @Override
    public void adaptiveAlert(ApiInfo apiInfo) {
        if (apiInfo.getErrorCount() > rule.getMatchedRule(apiInfo.getApi()).getMaxErrorCount()) {
            notification.notify(Notification.NotificationEmergencyLevel.URGENCY,"........");
        }
    }
}


class TimeoutAlertHandler extends AlertHandler {

    public TimeoutAlertHandler(AlertRule rule, Notification notification) {
        super(rule, notification);
    }

    @Override
    public void adaptiveAlert(ApiInfo apiInfo) {

    }
}

 

标签:11,return,notification,void,long,rule,设计模式,public
From: https://www.cnblogs.com/wscp/p/18459363

相关文章

  • Win11安装及卸载 PL/SQL Developer
    安装1.plsqldev12707x64.msi单击plsqldev12707x64.msi按Ctrl键+Shift键+Enter键以管理员身份运行plsqldev12707x64.msi进行安装,否则容易安装失败。基本都是默认,修改安装目录,没有复杂的地方。 2.PL/SQL登录 运行桌面PLSQLDeveloper14(64bit)。因为本地......
  • 软考11——信息安全
    1.信息安全和信息系统安全文老师软考教育1SO网络参考模型应用层表示层会话层传输层网络层链路层物理层安全对等实体认证服务访问控制服务>数据保密服务>数据完整性服务>数据源点认证服务》禁止否认服务犯罪证据提供服务安全服务安全机制◆信息安全系统的体系架构×轴是“安全机制......
  • win11专业版打开安全中心变成应用商店的问题
    有一位雨林木风官网的小伙伴,反馈这么一个问题,当他用win11专业版系统的时候,点击安全中心时,会有提示要求您启动应用商店,不知道是哪里出了问题!面对这个问题,很多人不知道如何解决。然后本期win11教程将为大多数用户提供答案。如何解决win11安全中心打不开跳出应用商店的问题?......
  • [10.11]CSP-S模拟赛
    宝贵经验:写题的时候想出时间正确的方法后千万注意计算空间,能不用数组的地方就不要用,否则可能会像我一样:\(35\to15\to0\)赛前小L说比上次简单。赛时T1一开始没有思路,但是注意到了两个关键条件:询问数\(\le300\)\(n,m\le10^9\)然后想到正解绝对不是去直接修改。注......
  • AI预测体彩排3采取888=3策略+和值012路或胆码测试10月11日升级新模型预测第101弹
            经过100多期的测试,当然有很多彩友也一直在观察我每天发的预测结果,得到了一个非常有价值的信息,那就是9码定位的命中率非常高,已到达90%的命中率,这给喜欢打私菜的朋友提供了极高价值的预测结果~当然了,大部分菜友还是走的正常渠道,因此,得想办法进行缩水,尽可能少的缩......
  • AI预测福彩3D采取888=3策略+和值012路或胆码测试10月11日新模型预测第107弹
            经过100多期的测试,当然有很多彩友也一直在观察我每天发的预测结果,得到了一个非常有价值的信息,那就是9码定位的命中率非常高,100多期一共只错了12次,这给喜欢打私房菜的朋友提供了极高价值的预测结果~当然了,大部分菜友还是走的正常渠道,因此,得想办法进行缩水,尽可能......
  • 20241011-2
    1.判断最大值:定义一个无符号的整型数组,求数组中的最大值。思路:inta1=10,a2=20,a3=5; 两两相比,求最大值2.从终端获取字符串,将整个字符串倒置存储。(提示:可以使用辅助数组)3.10层杨辉三角#include<stdio.h>#include<string.h>#defineARR15typedefunsigned......
  • 20241011-1 字符串函数自写
    #include<stdio.h>#include<string.h>unsignedintmystrlen(char*str){ unsignedintcount=0; while('\0'!=*(str++)) { count++; } returncount;}/*str1:目的字符串str2:源字符串*/voidmystrcpy(char*str1,char*str2){ ch......
  • 10.11 模拟赛(云智计划 模拟测#26)
    S---【云智计划】---6月23日---模拟测#26div1【补题】-比赛-梦熊联盟(mna.wang)S---【云智计划】---6月23日---模拟测#26div2【补题】-比赛-梦熊联盟(mna.wang)复盘A。看到\(n\)为偶数思路秒出。10min过样例。B。好像不太会做啊。模拟了样例2,猜出了一个很优的......
  • 20222311 2024-2025-1 《网络与系统攻防技术》实验一实验报告
    202223112024-2025-1《网络与系统攻防技术》实验一实验报告1.实验内容本次实验主要内容为BOF注入攻击,任务如下:掌握反汇编及其指令修改程序的机器指令,从而实现BOF注入攻击注入一段Shellcode,以实现BOF注入攻击2.实验过程任务1:修改可执行文件机器指令,改变程......