public class Service extends java.lang.Object implements IService, IServiceControl
In most cases, the default values are appropriate, so the service will operate correctly without any additional configuration. You will need to enter specific weather station data (station ID, password, latitude, longitude, etc.) in order to post data to Weather Underground Data Exchange and APRS Citizen Weather Observer Program (CWOP).
All configuration times are expressed in milliseconds (1 second = 1000 milliseconds; 1 minute = 60 seconds = 60000 milliseconds, etc.).
Modifier and Type | Class and Description |
---|---|
private class |
Service.DataExchange
Handles exchanging data between sensors and formatters.
|
private class |
Service.DataExchangeListener
Notifies service listenerArray that data has changed.
|
Modifier and Type | Field and Description |
---|---|
private com.dalsemi.onewire.adapter.DSPortAdapter |
adapter
1-Wire port adapter.
|
static java.lang.String |
BASE_DIR
Base directory name.
|
static java.lang.String |
CFG_ADMINISTRATOR_KEY
Administrator key configuration key.
|
static java.lang.String |
CFG_CLASS_NAME_KEY
Installable task class name configuration sensor-name.key suffix.
|
private java.util.Properties |
config
Configuration properties.
|
private static java.lang.String |
CONFIG_FILE
Configuration file name.
|
private static int |
CORE_POOL_SIZE
Core pool size for ScheduledThreadPoolExecutor.
|
private IDataExchange |
dataExchange
Data exchange for posting data to formatters.
|
private java.util.Properties |
defaults
Default configuration properties.
|
static java.lang.String |
FILE_SEPARATOR
Platform dependent file separator.
|
private java.util.List<IServiceListener> |
listeners
List of listeners.
|
static java.lang.String |
LOG_DIR
Log directory name.
|
private static java.util.logging.Logger |
LOGGER
Logger for this class.
|
static java.lang.String |
NAME
Server name.
|
static java.lang.String |
RESOURCE_NAME
Resource bundle name.
|
static java.util.ResourceBundle |
RESOURCES
Localizable resources for the service.
|
private java.util.concurrent.ScheduledThreadPoolExecutor |
scheduler
Thread pool task scheduler.
|
static java.lang.String |
USER_HOME
User home directory.
|
Constructor and Description |
---|
Service(boolean inproc)
Creates a new instance of Service.
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(IServiceListener listener)
Adds a listener for sensor updates.
|
private void |
authenticate(java.util.Properties config)
Checks the authentication string in the cfg properties against the
configured authorized users.
|
private void |
configureLogging()
Sets the logging level of the root logger.
|
private void |
createDeviceTasks()
Creates sensor tasks specified in wxservice.properties under the
CFG_CLASS_NAME_KEY property. |
private void |
createFormatterTasks()
Creates formatter tasks specified in wxservice.properties under
the
CFG_CLASS_NAME_KEY property. |
java.util.Properties |
getConfiguration()
Configuration properties accessor.
|
java.util.List<java.lang.String> |
getFileData(java.lang.String name)
Returns data from the specified file as a sting array.
|
java.util.List<java.lang.String> |
getFileNames()
File names property accessor.
|
private void |
initConfiguration()
Initializes the server configuration.
|
private void |
initializeDefaults()
Initializes the default server configuration.
|
private void |
initializeLogger(boolean inproc)
Initializes the logger.
|
void |
initializeService()
Clears out any pre-existing tasks, then initializes the service and
starts tasks as configured.
|
private void |
initOneWire()
Initializes the 1-Wire network.
|
void |
removeListener(IServiceListener listener)
Removes a listener for sensor updates.
|
private void |
resetAdapter()
Resets the 1-Wire adapter.
|
void |
scheduleTask(java.lang.Runnable task,
long delay,
long interval)
Schedules a task for execution by the scheduled thread pool executor.
|
void |
setConfiguration(java.util.Properties config)
Configuration properties accessor.
|
static java.lang.String |
toMessage(java.lang.Throwable tx)
Utility method for extracting a legal message from an exception.
|
public static final java.lang.String CFG_ADMINISTRATOR_KEY
public static final java.lang.String CFG_CLASS_NAME_KEY
public static final java.lang.String RESOURCE_NAME
public static final java.util.ResourceBundle RESOURCES
public static final java.lang.String USER_HOME
public static final java.lang.String FILE_SEPARATOR
public static final java.lang.String BASE_DIR
public static final java.lang.String LOG_DIR
private static final java.lang.String CONFIG_FILE
public static final java.lang.String NAME
private static final java.util.logging.Logger LOGGER
private static final int CORE_POOL_SIZE
private java.util.concurrent.ScheduledThreadPoolExecutor scheduler
private java.util.Properties defaults
private java.util.Properties config
private java.util.List<IServiceListener> listeners
private com.dalsemi.onewire.adapter.DSPortAdapter adapter
private IDataExchange dataExchange
public Service(boolean inproc) throws ServiceException
inproc
- true if the service is running in process.ServiceException
- if an unrecoverable initialization failure
occurs.public java.util.Properties getConfiguration() throws ServiceException
IService
getConfiguration
in interface IService
ServiceException
- if communication or application error occurs.public void setConfiguration(java.util.Properties config) throws ServiceException
IService
setConfiguration
in interface IService
config
- modified configuration properties.ServiceException
- if communication or application error occurs.public java.util.List<java.lang.String> getFileNames() throws ServiceException
IService
getFileNames
in interface IService
ServiceException
- if communication or application error occurs.public java.util.List<java.lang.String> getFileData(java.lang.String name) throws ServiceException
IService
getFileData
in interface IService
name
- of the file in the ./log directory.ServiceException
- if communication or application error occurs.public void addListener(IServiceListener listener) throws ServiceException
IService
addListener
in interface IService
listener
- the listener to add.ServiceException
- if communication or application error occurs.public void removeListener(IServiceListener listener) throws ServiceException
IService
removeListener
in interface IService
listener
- the listener to remove.ServiceException
- if communication or application error occurs.public final void initializeService() throws java.io.IOException, com.dalsemi.onewire.OneWireException
IServiceControl
initializeService
in interface IServiceControl
java.io.IOException
- if configuration fails.com.dalsemi.onewire.OneWireException
- if 1-Wire initialization fails.public final void scheduleTask(java.lang.Runnable task, long delay, long interval)
IServiceControl
scheduleTask
in interface IServiceControl
task
- to schedule.delay
- in milliseconds before starting task.interval
- in milliseonds between successive scheduled runs.public static java.lang.String toMessage(java.lang.Throwable tx)
Throwable.toString()
.tx
- throwable to evaluate.Throwable.toString()
.private void initializeLogger(boolean inproc) throws java.io.IOException
inproc
- if true, add a daily stream log handler.java.io.IOException
- if initialization fails.private void initializeDefaults()
private void initConfiguration() throws java.io.IOException
java.io.IOException
- if resource read access fails.private void configureLogging()
private void initOneWire() throws com.dalsemi.onewire.OneWireException
com.dalsemi.onewire.OneWireException
- if initialization fails.private void resetAdapter() throws com.dalsemi.onewire.OneWireException
com.dalsemi.onewire.OneWireException
- if reset fails.private void createDeviceTasks()
CFG_CLASS_NAME_KEY
property.private void createFormatterTasks()
CFG_CLASS_NAME_KEY
property.private void authenticate(java.util.Properties config) throws AuthException
config
- properties containing the administrator key.AuthException
- due to authentication failure.