private static void throwThrottlingException(final Type type, final long waitInterval) throws ThrottlingException { String msg = MSG_TYPE[type.ordinal()] + MSG_WAIT + formatTime(waitInterval); throw new ThrottlingException(type, waitInterval, msg); }
public static void throwNumWriteRequestsExceeded(final long waitInterval) throws ThrottlingException { throwThrottlingException(Type.NumWriteRequestsExceeded, waitInterval); }
public ThrottlingException(String msg) { super(msg); // Dirty workaround to get the information after // ((RemoteException)e.getCause()).unwrapRemoteException() for (int i = 0; i < MSG_TYPE.length; ++i) { int index = msg.indexOf(MSG_TYPE[i]); if (index >= 0) { String waitTimeStr = msg.substring(index + MSG_TYPE[i].length() + MSG_WAIT.length()); type = Type.values()[i]; waitInterval = timeFromString(waitTimeStr); break; } } }
@Override public void checkQuota(long writeSize, long readSize) throws ThrottlingException { if (!reqsLimiter.canExecute()) { ThrottlingException.throwNumRequestsExceeded(reqsLimiter.waitInterval()); } if (!reqSizeLimiter.canExecute(writeSize + readSize)) { ThrottlingException.throwRequestSizeExceeded(reqSizeLimiter .waitInterval(writeSize + readSize)); } if (writeSize > 0) { if (!writeReqsLimiter.canExecute()) { ThrottlingException.throwNumWriteRequestsExceeded(writeReqsLimiter.waitInterval()); } if (!writeSizeLimiter.canExecute(writeSize)) { ThrottlingException.throwWriteSizeExceeded(writeSizeLimiter.waitInterval(writeSize)); } } if (readSize > 0) { if (!readReqsLimiter.canExecute()) { ThrottlingException.throwNumReadRequestsExceeded(readReqsLimiter.waitInterval()); } if (!readSizeLimiter.canExecute(readSize)) { ThrottlingException.throwReadSizeExceeded(readSizeLimiter.waitInterval(readSize)); } } }
@Before(pointcut="execution(* com.company.xyz.method())") public void invoke() throws ThrottlingException { if (throttler.isThrottled(throttleKey)) { throw new ThrottlingException("Call Throttled"); } }
LOG.debug("Throttling exception for user=" + ugi.getUserName() + " table=" + table + " numWrites=" + numWrites + " numReads=" + numReads + " numScans=" + numScans + ": " + e.getMessage()); throw e;
package de.scrum_master.aspect; import java.util.Random; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import de.scrum_master.app.ThrottlingException; @Aspect public class ThrottlingInterceptor { private static final Random RANDOM = new Random(); @Before("execution(* doSomething())") public void invoke(JoinPoint thisJoinPoint) throws ThrottlingException { System.out.println(getClass().getSimpleName() + " -> " + thisJoinPoint); if (isThrottled()) { throw new ThrottlingException("call throttled"); } } private boolean isThrottled() { return RANDOM.nextInt(3) > 0; } }
public static void throwReadSizeExceeded(final long waitInterval) throws ThrottlingException { throwThrottlingException(Type.ReadSizeExceeded, waitInterval); }
private static void throwThrottlingException(final Type type, final long waitInterval) throws ThrottlingException { String msg = MSG_TYPE[type.ordinal()] + MSG_WAIT + formatTime(waitInterval); throw new ThrottlingException(type, waitInterval, msg); }
public ThrottlingException(String msg) { super(msg); // Dirty workaround to get the information after // ((RemoteException)e.getCause()).unwrapRemoteException() for (int i = 0; i < MSG_TYPE.length; ++i) { int index = msg.indexOf(MSG_TYPE[i]); if (index >= 0) { String waitTimeStr = msg.substring(index + MSG_TYPE[i].length() + MSG_WAIT.length()); type = Type.values()[i]; waitInterval = timeFromString(waitTimeStr); break; } } }
public static void throwRequestSizeExceeded(final long waitInterval) throws ThrottlingException { throwThrottlingException(Type.RequestSizeExceeded, waitInterval); }
private static void throwThrottlingException(final Type type, final long waitInterval) throws ThrottlingException { String msg = MSG_TYPE[type.ordinal()] + MSG_WAIT + formatTime(waitInterval); throw new ThrottlingException(type, waitInterval, msg); }
public ThrottlingException(String msg) { super(msg); // Dirty workaround to get the information after // ((RemoteException)e.getCause()).unwrapRemoteException() for (int i = 0; i < MSG_TYPE.length; ++i) { int index = msg.indexOf(MSG_TYPE[i]); if (index >= 0) { String waitTimeStr = msg.substring(index + MSG_TYPE[i].length() + MSG_WAIT.length()); type = Type.values()[i]; waitInterval = timeFromString(waitTimeStr); break; } } }
public static void throwNumRequestsExceeded(final long waitInterval) throws ThrottlingException { throwThrottlingException(Type.NumRequestsExceeded, waitInterval); }
private static void throwThrottlingException(final Type type, final long waitInterval) throws ThrottlingException { String msg = MSG_TYPE[type.ordinal()] + MSG_WAIT + formatTime(waitInterval); throw new ThrottlingException(type, waitInterval, msg); }
public ThrottlingException(String msg) { super(msg); // Dirty workaround to get the information after // ((RemoteException)e.getCause()).unwrapRemoteException() for (int i = 0; i < MSG_TYPE.length; ++i) { int index = msg.indexOf(MSG_TYPE[i]); if (index >= 0) { String waitTimeStr = msg.substring(index + MSG_TYPE[i].length() + MSG_WAIT.length()); type = Type.values()[i]; waitInterval = timeFromString(waitTimeStr); break; } } }
public static void throwNumReadRequestsExceeded(final long waitInterval) throws ThrottlingException { throwThrottlingException(Type.NumReadRequestsExceeded, waitInterval); }
public static void throwWriteSizeExceeded(final long waitInterval) throws ThrottlingException { throwThrottlingException(Type.WriteSizeExceeded, waitInterval); }
public static void throwNumRequestsExceeded(final long waitInterval) throws ThrottlingException { throwThrottlingException(Type.NumRequestsExceeded, waitInterval); }
public static void throwRequestSizeExceeded(final long waitInterval) throws ThrottlingException { throwThrottlingException(Type.RequestSizeExceeded, waitInterval); }