# Disk based configuration format #

The current `-dhd` option in the code automatically creates a number of
stats handlers. All the command line driven code does the same so the
core of the configuration should be a list of handlers with options. Using a
JSON format, we could have something like:

    {
        "handlers": [
            {
                "name": "handler name",
                "type": "uk.org.opentrv.comms.statshandlers.builtin.DummyStatsHandler",
                "options": {
                    "option1": "value1"
                }
            }
        ]
    }

The list of options is then specific to a particular handler type.

Questions:
- Is it sensible to have a fully qualified Java class name as the type?
- Should the name be mandatory? We need an anonymous handler option for
  wrapped handlers anyway so we could also rely on the index in the handlers
  array.

Example with a RKDAP handler:

    {
        "handlers": [
            {
                "name": "EnergyDeck stats handler",
                "type": "uk.org.comms.http.RkdapHandler",
                "options": {
                    "dadID": "ED256",
                    "url": "https://energydeck.com"
                }
            }
        ]
    }

Example with a wrapped handler:

    {
        "handlers": [
            {
                "name": "My async handler",
                "type": "uk.org.opentrv.comms.statshandlers.filter.AsyncStatsHandlerWrapper",
                "options": {
                    "handler": {
                        "type": "uk.org.opentrv.comms.statshandlers.builtin.SimpleFileLoggingStatsHandler",
                        "options": {
                            "statsDirName": "stats"
                        }
                    },
                    "maxQueueSize": 32
                }
            }
        ]
    }

Full `-dhd` flag example:

    {
        "handlers": [
            {
                "name": "File log",
                "type": "uk.org.opentrv.comms.statshandlers.builtin.SimpleFileLoggingStatsHandler",
                "options": {
                    "file": "out_test/stats"
                }
            },
            {
                "name": "Twitter Temp b39a",
                "type": "uk.org.opentrv.comms.statshandlers.builtin.twitter.SingleTwitterChannelTemperature",
                "options": {
                    "hexID": "b39a"
                }
            },
            {
                "name": "Twitter Temp 819c",
                "type": "uk.org.opentrv.comms.statshandlers.builtin.twitter.SingleTwitterChannelTemperature",
                "options": {
                    "hexID": "819c"
                }
            },
            {
                "name": "Recent stats file",
                "type": "uk.org.opentrv.comms.statshandlers.filter.SimpleStaticFilterStatsHandlerWrapper",
                "options": {
                    "handler": {
                        "type": "uk.org.opentrv.comms.statshandlers.builtin.RecentStatsWindowFileWriter",
                        "options": {
                            "targetFile": "out_test/edx.json"
                        }
                    },
                    "allowedIDs": [ "b39a", "819c" ]
                }
            },
            {
                "name": "EMON CMS",
                "type": "uk.org.opentrv.comms.statshandlers.builtin.openemon.OpenEnergyMonitorPostSimple",
                "options": {
                    "credentials": "emonserver1",
                    "sourceIDIn": "819c",
                    "statsTypeIn": "{",
                    "mapping": {
                        "T|C16": "Temp16",
                        "B|cV": "BattcV",
                        "L": "L"
                    },
                    "emonNodeOut": "819c"
                }
            }
        ]
    }

The implication of that configuration file is that the existing stats handlers
will need to be refactored so that all handlers use a one argument constructor
that takes a configuration object.
A possible extension to that format would be to have a mapping between
short name and fully qualified Java class at the beginning of the file
to simplify the handler definitions.
