1 package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.common.config.impl.rev140326;
3 import java.text.SimpleDateFormat;
6 import org.opendaylight.openflowplugin.openflow.md.core.sal.OpenflowPluginProvider;
7 import org.opendaylight.openflowplugin.api.openflow.statistics.MessageCountDumper;
8 import org.opendaylight.openflowplugin.api.openflow.statistics.MessageObservatory;
9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory;
13 * MsgSpyServiceModul implements and register own MsgSpyServiceRuntimeMXBean
14 * which is linked to {@link MessageObservatory} from {@link OpenflowPluginProvider}
16 * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
19 public class MsgSpyServiceModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.common.config.impl.rev140326.AbstractMsgSpyServiceModule {
20 private static final Logger log = LoggerFactory.getLogger(MsgSpyServiceModule.class);
22 private static final SimpleDateFormat ft = new SimpleDateFormat ("E yyyy.MM.dd 'at' hh:mm:ss a zzz");
24 public MsgSpyServiceModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
25 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
27 super(identifier, dependencyResolver);
30 public MsgSpyServiceModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
31 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
32 final MsgSpyServiceModule oldModule, final java.lang.AutoCloseable oldInstance) {
34 super(identifier, dependencyResolver, oldModule, oldInstance);
38 public void customValidation() {
39 // No need to validate dependencies, since all dependencies are mandatory
40 // config-subsystem will perform the validation
44 public java.lang.AutoCloseable createInstance() {
45 final MessageCountDumper msg = getOpenflowPluginProviderDependency().getMessageCountDumper();
47 /* Internal MXBean implementation -> make statMsg from dumpMessageCounst only yet */
48 final MsgSpyServiceRuntimeMXBean msgSpyBean = new MsgSpyServiceRuntimeMXBean() {
51 public String makeMsgStatistics() {
53 return "Message Spy Count Dumper is not avaliable.";
55 List<String> statList = msg.dumpMessageCounts();
57 StringBuilder strBuilder = new StringBuilder(ft.format(System.currentTimeMillis()));
58 for (String stat : statList) {
59 strBuilder.append("\n").append(stat);
61 return strBuilder.toString();
65 public String getMsgStatistics() {
66 return makeMsgStatistics();
70 /* MXBean registration */
71 final MsgSpyServiceRuntimeRegistration runtimeReg =
72 getRootRuntimeBeanRegistratorWrapper().register(msgSpyBean);
74 /* Internal MsgSpyService implementation */
75 final class AutoClosableMsgSpyService implements MessageCountDumper, AutoCloseable {
79 if (runtimeReg != null) {
84 String errMsg = "Error by stop MsgSpyService.";
86 throw new IllegalStateException(errMsg, e);
89 log.info(" Msg Stat Service consumer (instance {} turn down.)", this);
93 public List<String> dumpMessageCounts() {
94 return msg.dumpMessageCounts();
98 AutoCloseable ret = new AutoClosableMsgSpyService();
99 log.info("MsgStatService (instance {}) initialized.", ret);