1 package com.ubermq.kernel.overflow; 2 3 import com.ubermq.kernel.*; 4 import java.util.*; 5 6 12 public class HandlerChain 13 implements IConnectionOverflowHandler 14 { 15 private IOverflowHandler primary, secondary; 16 private boolean useSecondary; 17 18 24 public HandlerChain(IOverflowHandler primary, 25 IOverflowHandler secondary) 26 { 27 this.primary = primary; 28 this.secondary = secondary; 29 30 this.useSecondary = false; 32 33 } 34 35 42 public IOverflowHandler getRetryHandler() 43 { 44 if (useSecondary) { 45 return secondary; 46 } else { 47 return new HandlerChain(primary.getRetryHandler(), secondary); 48 } 49 } 50 51 56 private void useSecondaryHandler() 57 { 58 this.useSecondary = true; 59 } 60 61 65 public int overflow() 66 { 67 int a = primary.overflow(); 68 if (a == IOverflowHandler.ACTION_FAIL) { 69 useSecondaryHandler(); 70 a = IOverflowHandler.ACTION_RETRY; 71 } 72 73 return a; 74 } 75 76 86 public int overflow(IDatagram d, IConnectionInfo r, IMessageProcessor messageProcessor) 87 { 88 if (primary instanceof IConnectionOverflowHandler) { 89 int a = ((IConnectionOverflowHandler)primary).overflow(d, r, messageProcessor); 90 if (a == IOverflowHandler.ACTION_FAIL) { 91 useSecondaryHandler(); 92 a = IOverflowHandler.ACTION_RETRY; 93 } 94 return a; 95 } 96 else 97 return overflow(d); 98 } 99 100 107 public int overflow(IDatagram d) 108 { 109 int a = primary.overflow(d); 110 if (a == IOverflowHandler.ACTION_FAIL) { 111 useSecondaryHandler(); 112 a = IOverflowHandler.ACTION_RETRY; 113 } 114 115 return a; 116 } 117 118 119 } 120 121 122 | Popular Tags |