External system generates signals at random intervals. You need to implement Java filter that accepts at most N signals per minute (at any time).
Filter must implement the following interface:
interface Filter {
boolean isSignalAllowed();
}
The following pseudo-code illustrates how your filter could be used:
Filter frequencyFilter = new YourFilter(N);
while (true) {
Signal signal = waitForSignal();
if (frequencyFilter.isSignalAllowed()) {
process (signal);
}
}
Implementation must be efficient and thread-safe. Parameter N can be a immutable for lifetime of the filter. Another example can be found here.
If you have questions don't hesitate to ask.