Class DefaultAiServiceListenerRegistrar
java.lang.Object
dev.langchain4j.observability.api.DefaultAiServiceListenerRegistrar
- All Implemented Interfaces:
AiServiceListenerRegistrar
A default registrar for registering
AiServiceListeners.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T extends AiServiceEvent>
voidfireEvent(T event) Fires the given event to all registeredAiServiceListeners.<T extends AiServiceEvent>
voidregister(AiServiceListener<T> listener) Registers a listener to receiveAiServiceEventnotifications.voidshouldThrowExceptionOnEventError(boolean shouldThrowExceptionOnEventError) Configures whether exceptions should be thrown when an error occurs during event processing.<T extends AiServiceEvent>
voidunregister(AiServiceListener<T> listener) Unregisters a previously registeredAiServiceListener, stopping it from receiving furtherAiServiceEventnotifications.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface AiServiceListenerRegistrar
register, register, unregister, unregister
-
Constructor Details
-
DefaultAiServiceListenerRegistrar
public DefaultAiServiceListenerRegistrar()
-
-
Method Details
-
register
Registers a listener to receiveAiServiceEventnotifications.- Specified by:
registerin interfaceAiServiceListenerRegistrar
-
unregister
Unregisters a previously registeredAiServiceListener, stopping it from receiving furtherAiServiceEventnotifications.- Specified by:
unregisterin interfaceAiServiceListenerRegistrar
-
fireEvent
Fires the given event to all registeredAiServiceListeners.If an
AiServiceInvocationSummaryEventlistener is registered when the invocation starts, or the events of itsparent invocationare being recorded, the event is also recorded against its invocation. When the invocation ends with anAiServiceCompletedEvent, anAiServiceErrorEventor anAiServiceCancelledEvent, a singleAiServiceInvocationSummaryEventcontaining all of the recorded events is added to the recorded events of the parent invocation (if it has not ended yet) and fired after the event itself.- Specified by:
fireEventin interfaceAiServiceListenerRegistrar- Type Parameters:
T- The type of the event, which must be a subtype ofAiServiceEvent.- Parameters:
event- The event to be fired to the listeners. Must not be null.- Throws:
IllegalArgumentException- if the event is anAiServiceInvocationSummaryEvent, which is only ever fired by the registrar itself
-
shouldThrowExceptionOnEventError
public void shouldThrowExceptionOnEventError(boolean shouldThrowExceptionOnEventError) Description copied from interface:AiServiceListenerRegistrarConfigures whether exceptions should be thrown when an error occurs during event processing. If set totrue, any error that occurs while processing an event will result in an exception propagating to the caller. If set tofalse, errors will be silently handled or logged without interrupting the normal execution flow.- Specified by:
shouldThrowExceptionOnEventErrorin interfaceAiServiceListenerRegistrar- Parameters:
shouldThrowExceptionOnEventError- Indicates whether to throw exceptions on event errors. Iftrue, exceptions will be thrown; otherwise, errors will be handled silently. Default isfalse.
-