Java: What are my event notification options in my own API?

Suppose you have an API that you wrote that collects real-time data in an independent flow . Access to data is thread safe and through the interface. For instance. getData()that does not block or provide the latest information. This API is used in a number of applications; some graphical interfaces, other console programs.

What parameters should you notify your application that there was a data update? We definitely don’t want the API to be application dependent, so we don’t want fireTableDataChanged()something like that from the API. (In our graphics application we will call fireTableDataChanged(), etc. After the API notifies us or we look at the API.)

Thank you so much!

+3
source share
3 answers

One option is to create your own extension class.

  • IEventListener <EVENT>
  • IEventProducer <LISTENER extends IEventListener <EVENT>, EVENT>
  • EventProducer <LISTENER extends IEventListener <EVENT>, EVENT> implements IEventProducer <LISTENER, EVENT>

IEventListener is implemented by observers. It has a way to receive an event.

IEventProducer EventProducer. .

EventProducer . CopyOnWriteArrayList . , . .

IEventProducer EventProducer.

, erasure , add/delete listener - .

+3

Observable Observer. , , API, , . Observable. , , Observer . API 1.0, , , . , Observer/Observable Java, .

+2

.

1) API, , .
2) API, , .

API Observer. , Observable Observer, . :

  • ( API) , - /. , .
  • , /, API, .
  • ( ), .
+2

Source: https://habr.com/ru/post/1790759/


All Articles