Package com.framed.io.dispatch
Class Dispatcher
java.lang.Object
com.framed.core.Service
com.framed.io.dispatch.Dispatcher
- Direct Known Subclasses:
FfillDispatcher,InfluxDispatcher,JsonlDispatcher
Drop-in replacement:
- Never blocks EventBus handler on IO.
- Retries on transient IO errors in a dedicated worker thread.
- Adds bounded queue to avoid unbounded memory growth (configurable via system properties).
-
Field Summary
Fields inherited from class com.framed.core.Service
ADDRESS_REGISTRY_SUFFIX, eventBus, formatter, logger -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDispatcher(EventBus eventBus, org.json.JSONArray devices) Creates a dispatcher bound to the given event bus and set of devices. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCalled when datapoint cannot be queued or pushed.protected voidonHandlerError(String deviceID, String address, Object rawMsg, Exception e) Called when handler fails before enqueueing (e.g., parse error).abstract voidPushes a single datapoint to the underlying sink.abstract voidPushes a batch of datapoints to the underlying sink.voidOptional: call this when stopping your service to stop worker thread.voidstop()Stops the service.Methods inherited from class com.framed.core.Service
addressRegistry, announceAddress
-
Constructor Details
-
Dispatcher
Creates a dispatcher bound to the given event bus and set of devices.Starts a dedicated single-thread push worker and, for each device, subscribes to that device's address-discovery topic so that channels announced by the device are dynamically registered and forwarded to
push(DataPoint).- Parameters:
eventBus- the event bus used to receive announced addresses and incoming messagesdevices- the device identifiers whose announced channels this dispatcher binds to
-
-
Method Details
-
onHandlerError
Called when handler fails before enqueueing (e.g., parse error). Override to write dead-letter files, metrics, etc.- Parameters:
deviceID- the identifier of the device whose message failed to be handledaddress- the channel address the failing message arrived onrawMsg- the raw, unparsed message payloade- the exception raised while handling the message
-
onDrop
Called when datapoint cannot be queued or pushed. Override for dead-letter storage / metrics.- Parameters:
dp- the datapoint that could not be queued or pushedcause- the reason the datapoint was dropped
-
shutdown
Optional: call this when stopping your service to stop worker thread. (Drop-in: doesn't require changes elsewhere, but recommended to call.)- Parameters:
drainTimeout- maximum time to wait for queued pushes to drain before forcing shutdown; ifnull, termination is not awaited
-
stop
public void stop()Description copied from class:ServiceStops the service.By default, this method logs a message indicating that no stop logic is implemented. Subclasses should override this method to provide custom shutdown behavior when necessary.
-
push
Pushes a single datapoint to the underlying sink.Invoked on the dispatcher's worker thread. Implementations may throw
IOExceptionto signal a transient failure, which triggers retry with exponential backoff.- Parameters:
dataPoint- the datapoint to push- Throws:
IOException- if the push fails due to a transient IO error and should be retried
-
pushBatch
Pushes a batch of datapoints to the underlying sink.- Parameters:
batch- the datapoints to push
-
