-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EventAdmin #515
Comments
@pnoltes Do you have a development plan for EventAdmin? If no, I'd like do it. And I have a question about netstring serialization. |
I had no concrete plans for this yet, so please feel free to pick this up 😄.
Yes you are correct, if #470 is merged, properties will support property value type. So I agree an other option would be better. Note that there is a old and experimental implementation of the event admin at: https://github.com/apache/celix/tree/rel/celix-2.3.0/misc/experimental/bundles/event_admin/event_admin What I remember from the experimental event admin impl is that we struggled with when a Event object could be destroyed and who should destroy it. An option to solve this (IMO) more elegant is to drop the Event type and just reuse a string and celix properties. So a event admin interface like: typedef struct celix_event_admin {
void* handle;
/**
* @brief async post event call. Event admin will take ownership of the eventProperties and destroy it when no longer needed (events are handled)
*/
celix_status_t postEvent(void* handle, const char* eventTopic, celix_properties_t* eventProperties);
/**
* @brief sync send event call. Caller keeps ownership of eventProperties and eventProperties can safely be destroyed after the call returns
*/
celix_status_t sendEvent(void* handle, const char* eventTopic, const celix_properties_t* eventProperties);
} celix_event_admin_t; |
How about define a event object like : typedef struct celix_event_private {
const char *topic;
celix_properties_t *properties;
struct celix_ref ref;
}celix_event_private_t;
typedef struct celix_event {
/**
* @brief event private data
*/
celix_event_private_t privateData;
celix_status_t (*getTopic)(celix_event_t *event, const char **topic);
celix_status_t (*matches)( celix_event_t *event);
celix_status_t (*getProperty)(celix_event_t *event, char *propertyKey, celix_properties_entry_t **propertyEntry);
...
}celix_event_t;
/**
*@brief Create event
*/
celix_event_t *celix_event_create(const char *topic, celix_properties_t* eventProperties);
/**
*@brief Retains(increases the ref count) the event
*/
void celix_event_retain(celix_event_t *event);
/**
*@brief Release(decreases the ref count) the event
*/
void celix_event_release(celix_event_t *event); |
Yes, that will also work. I think the function pointers are not needed (unless we would like a polymorphism event object) and maybe a the event object should own the topic string. |
I agree with @pnoltes that function pointers are not needed unless polymorphism is involved. Even if it's absolutely necessary, please note that any object passing through a dynamic interface (like Celix service) must be managed some way by the interface provider so that when the interface goes away, the object is not available to the outsider any more. Of course, the above consideration does not apply if event is used only within EventAdmin. |
@pnoltes Do you have any plans to merge type_support_for_properties? The event properties might need to support 'byte' type arrays property. Additionally, according to the OSGI specification 133.9,event properties should support arrays of primitive data types. Should we necessarily support arrays of all primitive types? In my opinion, 'byte' type arrays can handle most scenarios in our daily work, we can first support only byte type arrays. |
There is a back-pressure issue inherent in any asynchronous messaging system: what if we have slow message consumers and fast consumers at the same time? Even if an event is relatively small, permitting messages accumulate indefinitely in a slow consumer's queue is never a good idea. That means we may need some QoS mechanism. |
Because the changes "type support for propeties" PR is breaking, I want to merge this after Apache Celix 2.4.0 is released. So when the master branch is working towards a Apache Celix 3.0.0. But IMO this should hold back the event admin development. In the spec a Event structure primary contains a topic and properties and this can already be done with the current properties. When the properties are updated for type support, I expect this will have minimal or no impact on the Event impl. |
Concerning remote event admin. I think it is wise to start with a local event admin implementation, mostly following the spec (if possible) and only after that start on the remote event admin. I also expect that we still need to have a few discussion about the event admin. For example:
|
The technology used to publish remote events should be plug-able. IMO, it might be an event handler proxy and register an event handler service that subscribes to all local events and then pushes events subscribed by remote subscribers to the remote distributor. When the remote distributor receives a remote event, it sends the event to the event admin(use
We could consider using a broker-like solution and then reuse the discovery of remote service(discovery_zeroconf,etc.) to announce the broker's information. If we use the solution of discovering remote endpoints, we don't know which publisher service endpoints will be created until the
Could it be based on the remote technology used? If the remote technology is TCP/UDP, we should add a reusable wire protocol. If the remote technology is websocket, since websocket already support message fragmentation, is it possible for the distributor to define its own wire protocol (like
I think event handlers should receive all events that they subscribe to, whether remote or local. If there are no remote subscribers, the event admin should not push the event to the remote, otherwise, it should push the event to the remote. Additionally, to distinguish between remote and local events, we can add an event property, such as
We can start with implementing
we can use threadpool, and the max thread number can be configured by the property of event admin bundle. For event handlers that require a order of events, it should be ensured that its
To ensure order of events, a single thread maybe be used for the same remote address, but multiple threads maybe be supported for different remote addresses.
We can use a blacklisting mechanism to limit or disconnect event handlers that take too long in the
Considering the different requirements for event reliability in different scenarios, we can first implement two QOS policies: at most once, at least once (like MQTT). And set QOS as a property of event. |
To remote event admin, I have the following ideas. First of all, the remote distribution provider should be pluggable, and its interface definition is as follows:
The service includes properties:
In addition, the event properties retain the property name with the "$" prefix. These properties are used to represent the specific information of the remote distribution provider or control the API behavior. The properties that control the API behavior include:
Note: The above event properties only take effect for remote events. In addition, I don't intend to forward framework events to remote currently, because I am not sure about the meaning of forwarding framework events to remote. If it needs to be forwarded to remote, it should add the property "org.osgi.framework.uuid". I plan to implement the remote distribution provider in two ways, one is based on RSA, and the other is based on MQTT. For the implementation based on MQTT, I plan to use the mosquitto library to implement it. The implementation based on RSA For the implementation based on RSA, it will add the remote interface Note:I don't consider attaching the subscription information of process B to the The definition of
The component relationship diagram is as follows: Some other key points to consider in the implementation:
The implementation based on MQTT For the implementation based on MQTT, I will add the remote interface The definition of
The component relationship diagram is as follows: Some other key points to consider in the implementation:
|
Considering the RSA approach, will event delivery be expensive? |
Yes, this is a weakness of RSA, maybe it can be solved by improve RSA, such as supporting long links, supporting asynchronous calls.Its advantage is that the communication method can be expanded with the expansion of RSA. If this approach is controversial, I will consider not implementing it, until the implementation of RSA meets the requirements of event admin. |
Nice detailed plan for the Remote Event Admin. I have several remarks:
Lastly, please note that these are my thoughts. If there is an immediate need to couple a Remote Event Admin with RSA, we can, of course, more directly pursue that. |
In some rare cases, where performance is not a concern, we still need sync semantics.
Yes, conventionally messaging middle-wire lies below RPC, i.e. RPC can be implemented with messaging middle-wire. I think the main motivation is to unify the service discovery of RSA/REA(RemoteEventAdmin). |
According to the EventAdmin specification:
Maybe we can implement an EventAdminWrapper, which implements the Event Admin Service, and its service ranking is the highest. In this way, EventAdminWrapper can forward events to remote (use EventRemoteProvider) or to local (use EventAdmin). And EventAdmin can be unaware of remote events. In addition, should we consider multiple EventRemoteProviders existing? If yes, EventAdminWrapper can also be used to implement a strategy to select the perfect EventRemoteProvider to forward remote events. For the MQTT broker address information, it maybe requires dynamic discovery in my work.
|
Rethinking this, I think the proposed solution (using a
If discovery is needed, RSA indeed could be used for this. Maybe a bit an overkill, but on the other hand the code exists, is tested and can be used for this (marker interface with some configuration properties). |
Implement the EventAdmin OSGi specification for Apache Celix.
The initial implementation should be a local useable EventAdmin, but can be prepared to function as a remote EventAdmin.
For a remote EventAdmin additional SPI should be designed to that transport and discovery can be plugged in.
Serialization could also be plug-able, but arguable this is not needed and straight forward netstring serialization can be reused.
Additionally if celix_properties is extended to support a "bytes" value type, the event admin could be used to communicate arbitrary message using a "payload" property entry. In this case, serialization for the "bytes" value type should be a low overhead solution.
The text was updated successfully, but these errors were encountered: