漏桶算法通过 限制容量池大小 来控制流量,而 令牌桶算法 则通过 限制发放令牌的速率 来控制流量
public interface IDecorator { void decorate(); }
public class Decorator implements IDecorator { @Override public void decorate() { System.out.println("Decorator"); } }
@AllArgsConstructor public class BaseDecorator implements IDecorator { private IDecorator decorator; @Override public void decorate() { if (decorator != null) { decorator.decorate(); } } }
public class ADecorator extends BaseDecorator { public ADecorator(IDecorator decorator) { super(decorator); } @Override public void decorate() { System.out.println("ADecorator"); super.decorate(); } }
public class BDecorator extends BaseDecorator { public BDecorator(IDecorator decorator) { super(decorator); } @Override public void decorate() { System.out.println("BDecorator"); super.decorate(); } public static void main(String[] args) { new BDecorator(new ADecorator(new Decorator())).decorate(); // BDecorator // ADecorator // Decorator } }