Merge "Adjust Tx rate limiter for unused transactions"
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / common / actor / AbstractUntypedPersistentActor.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.common.actor;
10
11 import akka.persistence.UntypedPersistentActor;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
14
15 public abstract class AbstractUntypedPersistentActor extends UntypedPersistentActor {
16
17     protected final Logger LOG = LoggerFactory.getLogger(getClass());
18
19     public AbstractUntypedPersistentActor() {
20         if(LOG.isTraceEnabled()) {
21             LOG.trace("Actor created {}", getSelf());
22         }
23         getContext().
24             system().
25             actorSelection("user/termination-monitor").
26             tell(new Monitor(getSelf()), getSelf());
27
28     }
29
30
31     @Override public void onReceiveCommand(Object message) throws Exception {
32         final String messageType = message.getClass().getSimpleName();
33         if(LOG.isTraceEnabled()) {
34             LOG.trace("Received message {}", messageType);
35         }
36         handleCommand(message);
37         if(LOG.isTraceEnabled()) {
38             LOG.trace("Done handling message {}", messageType);
39         }
40
41     }
42
43     @Override public void onReceiveRecover(Object message) throws Exception {
44         final String messageType = message.getClass().getSimpleName();
45         if(LOG.isTraceEnabled()) {
46             LOG.trace("Received message {}", messageType);
47         }
48         handleRecover(message);
49         if(LOG.isTraceEnabled()) {
50             LOG.trace("Done handling message {}", messageType);
51         }
52
53     }
54
55     protected abstract void handleRecover(Object message) throws Exception;
56
57     protected abstract void handleCommand(Object message) throws Exception;
58
59     protected void ignoreMessage(Object message) {
60         LOG.debug("Unhandled message {} ", message);
61     }
62
63     protected void unknownMessage(Object message) throws Exception {
64         if(LOG.isDebugEnabled()) {
65             LOG.debug("Received unhandled message {}", message);
66         }
67         unhandled(message);
68     }
69 }