/**
 * Copyright (C) 2009 - 2010 by OpenGamma Inc.
 *
 * Please see distribution for license.
 */
package com.opengamma.transport;

import java.util.LinkedList;
import java.util.List;

import org.fudgemsg.FudgeContext;
import org.fudgemsg.FudgeMsgEnvelope;

/**
 * Collects all Fudge message envelopes in an array for later analysis.
 *
 * @author kirk
 */
public class CollectingFudgeMessageReceiver implements FudgeMessageReceiver {
  private final List<FudgeMsgEnvelope> _messages = new LinkedList<FudgeMsgEnvelope>();

  @Override
  public synchronized void messageReceived(FudgeContext fudgeContext,
      FudgeMsgEnvelope msgEnvelope) {
    _messages.add(msgEnvelope);
  }
  
  public List<FudgeMsgEnvelope> getMessages() {
    return _messages;
  }
  
  public synchronized void clear() {
    _messages.clear();
  }

}

@@ -176,16 +176,146 @@
 il.List;
+%0Aimport java.util.concurrent.BlockingQueue;%0Aimport java.util.concurrent.LinkedBlockingQueue;%0Aimport java.util.concurrent.TimeUnit;
 %0A%0Aimport
@@ -574,20 +574,29 @@
 e final 
-List
+BlockingQueue
 %3CFudgeMs
@@ -628,20 +628,29 @@
 w Linked
-List
+BlockingQueue
 %3CFudgeMs
@@ -681,37 +681,24 @@
 de%0A  public 
-synchronized 
 void message
@@ -736,14 +736,8 @@
 ext,
-%0A     
  Fud
@@ -863,16 +863,49 @@
  return 
+new LinkedList%3CFudgeMsgEnvelope%3E(
 _message
@@ -905,16 +905,17 @@
 messages
+)
 ;%0A  %7D%0A  
@@ -928,21 +928,8 @@
 lic 
-synchronized 
 void
@@ -967,10 +967,225 @@
 );%0A  %7D%0A%0A
+  public FudgeMsgEnvelope waitForMessage(final long timeoutMillis) %7B%0A    try %7B%0A      return _messages.poll(timeoutMillis, TimeUnit.MILLISECONDS);%0A    %7D catch (InterruptedException e) %7B%0A      return null;%0A    %7D%0A  %7D%0A%0A
 %7D%0A

Use a blocking queue rather than a list so that tests can wait for a message to have arrived.