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

eventsExecutorService: how does it work? #49

Open
HelgeStenstrom opened this issue Sep 24, 2019 · 0 comments
Open

eventsExecutorService: how does it work? #49

HelgeStenstrom opened this issue Sep 24, 2019 · 0 comments
Labels

Comments

@HelgeStenstrom
Copy link
Collaborator

Can you please explain a bit how this works:

/**
* Notify listeners about a BasicPlayerEvent.
*
* @param status event code.
* @param encodedStreamPosition in the stream when the event occurs.
* @param description the description
*
* @return A String Describing if any problem occurred
*/
private String generateEvent(final Status status, final int encodedStreamPosition, final Object description) {
try {
return eventsExecutorService
.submit(new StreamPlayerEventLauncher(this, status, encodedStreamPosition, description, listeners))
.get();
} catch (InterruptedException | ExecutionException ex) {
logger.log(Level.WARNING, "Problem in StreamPlayer generateEvent() method", ex);
}
return "Problem in StreamPlayer generateEvent() method";
}

From what I understand, there is a StreamPlayerEventLauncher task which holds information about source, player position, a list of listeners and some other stuff.

The task is submitted to eventsExecutorService.submit(task) and returns a Future.

Then .get() is called on this object. get() blocks until the task is done, i.e., until all listeners have been notified by the call() method of the StreamPlayerEventLauncher.

Since get() is blocking, I wonder why this has to be in a separate thread. What is the lifetime of the thread? It seems to be extremely short, or am I wrong?

Wouldn't the behavior be the same with a simple
new StreamPlayerEventLauncher(this, status, encodedStreamPosition, description, listeners).call();

and no eventsExecutorService at all?

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

No branches or pull requests

1 participant