Implement rest of the methods for TransactionProxy
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / utils / MessageCollectorActor.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.cluster.datastore.utils;
10
11 import akka.actor.UntypedActor;
12
13 import java.util.ArrayList;
14 import java.util.List;
15
16 /**
17  * MessageCollectorActor collects messages as it receives them. It can send
18  * those collected messages to any sender which sends it the "messages" message
19  * <p>
20  *     This class would be useful as a mock to test whether messages were sent
21  *     to a remote actor or not.
22  * </p>
23  */
24 public class MessageCollectorActor extends UntypedActor {
25     private List<Object> messages = new ArrayList<>();
26
27     @Override public void onReceive(Object message) throws Exception {
28         if(message instanceof String){
29             if("messages".equals(message)){
30                 getSender().tell(messages, getSelf());
31             }
32         } else {
33             messages.add(message);
34         }
35     }
36 }