Merge "Fix for possible NPE if Bundle is stopped."
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / utils / ConditionalProbe.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.utils;
10
11 import akka.actor.ActorRef;
12 import com.google.common.base.Predicate;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15
16 public class ConditionalProbe {
17     private final ActorRef actorRef;
18     private final Predicate predicate;
19     Logger log = LoggerFactory.getLogger(ConditionalProbe.class);
20
21     public ConditionalProbe(ActorRef actorRef, Predicate predicate) {
22         this.actorRef = actorRef;
23         this.predicate = predicate;
24     }
25
26     public void tell(Object message, ActorRef sender){
27         if(predicate.apply(message)) {
28             log.info("sending message to probe {}", message);
29             actorRef.tell(message, sender);
30         }
31     }
32 }