Skip to content
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

[io] Refactor of ThreadIO #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pkriens
Copy link
Contributor

@pkriens pkriens commented Sep 11, 2020

The ThreadIO service replaces the System streams so that the output and input on a thread associated with a command can be captured.

Unfortunately, this occupies the singletons of System.in/out/err. There are many others that want to use the same mechanism.

This change introduces a SystemIO service that dispatches the System streams to any number of listeners. The ThreadIO is modified to use this service.

By default, the Gogo runtime will register its own SystemIO service. However, it is possible to disable this with the "org.apache.felix.gogo.systemio.timeout" (SystemIO.TIMEOUT) framework property. If this is set to a numeric value, it will indicate that Gogo should look for an external service. The numeric value indicates the amount of time Gogo should wait for this service. 30000 is a common value.

Additionally, there is an onClose method added to the session so that it is possible to get a callback when the session closes. Gogo commands can use this to cancel any activity related to a session. The lambda is weakly referenced so it is necessary that the command keeps a strong reference to the callback.

Signed-off-by: Peter Kriens [email protected]

@pkriens pkriens closed this Feb 15, 2021
@pkriens pkriens reopened this Mar 30, 2021
@pkriens pkriens requested a review from jbonofre March 30, 2021 13:07
The ThreadIO service replaces the System streams so that the output and input on a thread associated with a command can be captured.

Unfortunately, this occupies the singletons of System.in/out/err. There are many others that want to use the same mechanism.

This change introduces a SystemIO service that dispatches the System streams to any number of listeners. The ThreadIO is modified to use this service.

By default, the Gogo runtime will register its own SystemIO service. However, it is possible to disable this with the "org.apache.felix.gogo.systemio.timeout" (SystemIO.TIMEOUT) framework property. If this is set to a numeric value, it will indicate that Gogo should look for an external service. The numeric value indicates the amount of time Gogo should wait for this service. 30000 is a common value. 

Additionally, there is an onClose method added to the session so that it is possible to get a callback when the session closes. Gogo commands can use this to cancel any activity related to a session. The lambda is weakly referenced so it is necessary that the command keeps a strong reference to the callback.

Signed-off-by: Peter Kriens <[email protected]>
@amitjoy
Copy link
Contributor

amitjoy commented Mar 31, 2021

I just tested the branch and it works like a charm 👍. I strongly believe that this is a great enhancement to Gogo runtime.

@rotty3000
Copy link
Contributor

rotty3000 commented Mar 31, 2021 via email

@amitjoy
Copy link
Contributor

amitjoy commented Mar 31, 2021

@rotty3000 What I noticed earlier that if I start a local Felix runtime in Eclipse with Gogo and simultaneously connect the runtime using Telnet, all commands executed in the Telnet console get captured by ThreadIO, and the execution result gets dispatched to all available streams. The result gets displayed not only on the Telnet console but also on the Eclipse IDE console. In my opinion, the result should not have been displayed in IDE if the command is executed on Telnet and vice versa. This is why, after discussing with @pkriens, it has been decided that it would have been great to disable the use of ThreadIO on demand which @pkriens accomplished in this PR by introducing the SystemIO service. In my scenario, I just needed to export a custom implementation of SystemIO with the framework property org.apache.felix.gogo.systemio.timeout set to a proper timeout value (i.e. 20000 milliseconds).

@rotty3000
Copy link
Contributor

rotty3000 commented Mar 31, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants