package com.k13n.lt_codes;

public final class ErasureChannel {
  private final double erasureProbability;

  public static final byte[] ERASED = new byte[0];

  public ErasureChannel(double erasureProbability) {
    this.erasureProbability = erasureProbability;
  }

  public byte[] transmit(byte[] data)
  {
    if(Math.random() <= erasureProbability)
    {
      return ERASED;
    }
    else
      return data;
  }
}

package com.k13n.lt_codes;

public final class ErasureChannel {

  public interface Callback {
    public void call(ErasureChannel channel, byte[] data);
  }

  private final Callback callback;
  private final double erasureProbability;

  public ErasureChannel(Callback callback, double erasureProbability) {
    this.callback = callback;
    this.erasureProbability = erasureProbability;
  }

  public void transmit(byte[] data) {
    if (Math.random() > erasureProbability)
      callback.call(this, data);
  }

}

Change the ErasureChannel to fire a callback on packet transmission