title: How do I intercept method calls in order to delay the execution, group all calls together and execute in java?
body: <p>I've been attempting to resolve my problem for about a day now, but can't seem to get anywhere.  The problem:</p>
  
  <p>I have a java class, ExternalClass which has 30 methods in it.
  I also have an interface ExternalClassFacade.</p>
  
  <pre><code>public class ExternalClass {
    public method1() {...}
    public method2() {...}
    ...
    ...
    public metod30(...) {...}
  }
  </code></pre>
  
  <p>This class is an external library and I cannot modify it's code.
  The class works well but I have a situation where I need to group up multiple calls on an undefined timespan to all 30 methods, delay the execution, and execute all at once (serial or parallel I don't care) at some moment.</p>
  
  <p>For example, over 10 minutes, methods 1 to 30 will be called randomly 500 times, I want them to do nothing at the moment of being invoked, but after 10 minutes I want to invoke all 500 calls as they were originally called.</p>
  
  <p>most of the methods require parameters which I need to remember for the moment in which i will call the methods.</p>
  
  <p>I'm looking for a way to extend/wrap/composite this class, so that when someone calls any of these methods, or, a special method that will bridge the calls to the original methods so that they will be delayed till the right moment comes.</p>
  
  <p>I was thinking about extending the class and overriding all methods, and managing 30 Struct-Like classes to hold the info about the calls, but that would require :</p>
  
  <ul>
  <li>30 overrides</li>
  <li>30 lists</li>
  <li>30 classes</li>
  </ul>
  
  <p>Lots of code, not very smart.</p>
  
  <p>I'm looking for a better way to do this, I was thinking about catching the calls and keeping the pointer to the original method call, but this is java, so it's not possible.</p>