-
Notifications
You must be signed in to change notification settings - Fork 90
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
Event admin #738
Merged
Merged
Event admin #738
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ef72d72
Add event admin feature
xuzhenbao b75476f
Add event admin feature
xuzhenbao 2777331
Add event admin feature
xuzhenbao cf37e53
Add doc for event admin
xuzhenbao d3a22c2
remove event admin from misc/experimental/bundles
xuzhenbao 3a3f2b3
Fix doc for event admin
xuzhenbao 7d377c9
Merge branch 'master' of https://github.com/xuzhenbao/celix into even…
xuzhenbao 012f826
Change the header file include order
xuzhenbao a8fc3a7
Add error code for celix_eventAdmin_create
xuzhenbao 17bfe64
Resolve the build failure for macos
xuzhenbao 7ede7ee
Resolve the test failure for macos
xuzhenbao 8d138f6
Merge branch 'apache:master' into event_admin
xuzhenbao eb58535
Fix event admin doc grammar error
xuzhenbao 1335da9
Update bundles/event_admin/event_admin_api/include/celix_event_admin_…
xuzhenbao b9b2b56
Improve code based on code review
xuzhenbao 1f1ba1f
Improve code based on code review, and remove errno setting in celix_…
xuzhenbao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
celix_subproject(EVENT_ADMIN "Option to enable building the Event Admin bundles" ON) | ||
if (EVENT_ADMIN) | ||
add_subdirectory(event_admin_api) | ||
add_subdirectory(event_admin) | ||
add_subdirectory(examples) | ||
endif() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: Event Admin | ||
--- | ||
|
||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to You under the Apache License, Version 2.0 | ||
(the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
|
||
## Introduction | ||
|
||
The Event Admin subproject implements the [OSGi Event Admin Service Specification](https://docs.osgi.org/specification/osgi.cmpn/7.0.0/service.event.html). It consists of event admin implementation and corresponding examples. | ||
|
||
### Event Admin | ||
|
||
The Event Admin provides the pubsub mechanism for in-process communication. | ||
|
||
| **Bundle** | `Celix::event_admin` | | ||
|----------------------|----------------------| | ||
| **Configuration** | *None* | | ||
|
||
|
||
## Building | ||
|
||
To build the Event Admin subproject, the cmake option `BUILD_EVENT_ADMIN` or conan option `build_event_admin`must be enabled. These options are disabled by default. | ||
If we want to build the event admin examples, the cmake option `BUILD_EVENT_ADMIN_EXAMPLES` or conan option `build_event_admin_examples` must be enabled. These options are disabled by default. | ||
|
||
## Event Admin Bundles | ||
|
||
* [EventAdmin](event_admin/README.md) - The event admin implementation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
set(EVENT_ADMIN_SRC | ||
src/celix_event_admin_activator.c | ||
src/celix_event_admin.c | ||
src/celix_event.c | ||
src/celix_event_adapter.c | ||
) | ||
|
||
set(EVENT_ADMIN_DEPS | ||
Celix::event_admin_api | ||
Celix::log_helper | ||
Celix::framework | ||
Celix::utils | ||
) | ||
|
||
add_celix_bundle(event_admin | ||
SYMBOLIC_NAME "apache_celix_event_admin" | ||
VERSION "1.0.0" | ||
NAME "Apache Celix Event Admin" | ||
GROUP "Celix/event_admin" | ||
FILENAME celix_event_admin | ||
SOURCES | ||
${EVENT_ADMIN_SRC} | ||
) | ||
|
||
target_link_libraries(event_admin PRIVATE ${EVENT_ADMIN_DEPS}) | ||
|
||
target_include_directories(event_admin PRIVATE ${CMAKE_CURRENT_LIST_DIR}/src) | ||
|
||
install_celix_bundle(event_admin EXPORT celix COMPONENT event_admin) | ||
|
||
#Setup target aliases to match external usage | ||
add_library(Celix::event_admin ALIAS event_admin) | ||
|
||
if (ENABLE_TESTING) | ||
add_library(event_admin_cut STATIC ${EVENT_ADMIN_SRC}) | ||
target_include_directories(event_admin_cut PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src) | ||
target_link_libraries(event_admin_cut PUBLIC ${EVENT_ADMIN_DEPS}) | ||
add_subdirectory(gtest) | ||
endif(ENABLE_TESTING) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
--- | ||
title: Event Admin Service | ||
--- | ||
|
||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to You under the Apache License, Version 2.0 | ||
(the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
|
||
## Event Admin | ||
|
||
The Event Admin provides the pubsub mechanism for in-process communication. It has implemented two delivery mechanisms: | ||
- Synchronous delivery | ||
- Asynchronous delivery | ||
|
||
In addition, the Event Admin provides an adapter for the celix framework-level event. It maps the celix framework-level event to the | ||
event admin pubsub model, and events are delivered asynchronously. | ||
|
||
### Cmake options | ||
|
||
BUILD_EVENT_ADMIN=OFF | ||
|
||
### Conan options | ||
|
||
build_event_admin=false | ||
|
||
### Software Design | ||
|
||
#### Synchronous Delivery | ||
|
||
In the synchronous delivery, the event handler will be notified in the caller's thread. And the `sendEvent` method will return after all the event handlers have been called. | ||
The diagram of synchronous delivery is shown in the following figure: | ||
|
||
![sync_delivery_seq.png](diagrams/sync_delivery_seq.png) | ||
|
||
#### Asynchronous Delivery | ||
|
||
In the asynchronous delivery, the event handler will be notified in a separate event-delivery thread. And the `postEvent` method will return immediately. | ||
The diagram of asynchronous delivery is shown in the following figure: | ||
|
||
![sync_delivery_seq.png](diagrams/async_delivery_seq.png) | ||
|
||
In the above figure, if the event handler sets the "event.delivery" property to "async.ordered", each event handler can hold | ||
at most one event-delivery thread at a time, so that events can be delivered in order. If the event handler sets the | ||
"event.delivery" property to "async.unordered", the event handler can hold multiple event-delivery threads at the same | ||
time, so that events can be delivered in parallel. | ||
|
||
|
||
#### Event Adapter | ||
|
||
In order to present a consistent view of all the events occurring in the system, the Event Admin provides an adapter for the celix framework-level event. | ||
The events are mapped as follows: | ||
|
||
- **Celix Framework Event** | ||
|
||
For celix framework Event, we map the celix framework condition id to the event admin event topic. The event admin event properties are none. | ||
The details mappings are shown in the following table: | ||
|
||
| Celix Framework Condition ID | Event Admin Event topic | | ||
|------------------------------------|---------------------------------------------| | ||
| CELIX_CONDITION_ID_FRAMEWORK_READY | "org/osgi/framework/FrameworkEvent/STARTED" | | ||
| CELIX_CONDITION_ID_FRAMEWORK_ERROR | "org/osgi/framework/FrameworkEvent/ERROR" | | ||
|
||
- **Celix Bundle Event** | ||
|
||
For celix bundle Event, we map the celix bundle event type to the event admin event topic. And The event admin event properties are as follows: | ||
- bundle.id | ||
PengZheng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- bundle.symbolicName | ||
- bundle.version | ||
|
||
The details mappings are shown in the following table: | ||
|
||
| Celix Bundle Event Type | Event Admin Event topic | | ||
|--------------------------------|----------------------------------------------| | ||
| CELIX_BUNDLE_EVENT_INSTALLED | "org/osgi/framework/BundleEvent/INSTALLED" | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also mentioned for the service names, but I prefer that "org.osgi" or "osgi" is not used (inspired by, but not a implementation of). |
||
| CELIX_BUNDLE_EVENT_STARTED | "org/osgi/framework/BundleEvent/STARTED" | | ||
| CELIX_BUNDLE_EVENT_STOPPED | "org/osgi/framework/BundleEvent/STOPPED" | | ||
| CELIX_BUNDLE_EVENT_UPDATED | "org/osgi/framework/BundleEvent/UPDATED" | | ||
| CELIX_BUNDLE_EVENT_UNINSTALLED | "org/osgi/framework/BundleEvent/UNINSTALLED" | | ||
| CELIX_BUNDLE_EVENT_RESOLVED | "org/osgi/framework/BundleEvent/RESOLVED" | | ||
| CELIX_BUNDLE_EVENT_UNRESOLVED | "org/osgi/framework/BundleEvent/UNRESOLVED" | | ||
|
||
- **Celix Service Event** | ||
|
||
For celix service Event, we map the celix service register/unregister operation to the event admin event topic. And The event admin event properties are as follows: | ||
- service.id | ||
- service.objectClass | ||
- service.pid | ||
|
||
The details mappings are shown in the following table: | ||
|
||
| Celix Service Operation | Event Admin Event topic | | ||
|-------------------------|-------------------------------------------------| | ||
| Register Service | "org/osgi/framework/ServiceEvent/REGISTERED" | | ||
| Unregister Service | "org/osgi/framework/ServiceEvent/UNREGISTERING" | |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions
43
bundles/event_admin/event_admin/diagrams/async_delivery_seq.puml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to You under the Apache License, Version 2.0 | ||
(the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
|
||
@startuml | ||
'https://plantuml.com/sequence-diagram | ||
|
||
participant EventPublisher | ||
box "EventAdmin" | ||
participant EventAdmin | ||
== init == | ||
create queue EventQueue | ||
EventAdmin -> EventQueue: new | ||
create control DeliveryEventThreads | ||
EventAdmin -> DeliveryEventThreads: new | ||
end box | ||
== postEvent == | ||
EventPublisher -> EventAdmin: postEvent | ||
EventAdmin -> EventAdmin: collect event handlers for event | ||
EventAdmin -> EventQueue: add event with a list of event handlers to the queue | ||
EventQueue --> EventAdmin: return | ||
EventAdmin --> EventPublisher: return | ||
loop has event in queue | ||
EventQueue -> DeliveryEventThreads: get event and event handler | ||
DeliveryEventThreads -> EventHandler: handleEvent | ||
return | ||
alt event has been notified to all event handlers | ||
DeliveryEventThreads -> EventQueue: remove event from queue | ||
end alt | ||
end loop | ||
|
||
@enduml |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions
27
bundles/event_admin/event_admin/diagrams/sync_delivery_seq.puml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to You under the Apache License, Version 2.0 | ||
(the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
|
||
@startuml | ||
'https://plantuml.com/sequence-diagram | ||
|
||
EventPublisher -> EventAdmin: sendEvent | ||
EventAdmin -> EventAdmin: collect event handlers for event | ||
loop for each event handler | ||
EventAdmin -> EventHandler: handleEvent | ||
EventHandler --> EventAdmin: return | ||
end loop | ||
EventAdmin --> EventPublisher: return | ||
|
||
@enduml |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good choice and prevents additional needs to exposing a additional framework header.