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

Adding external listener #3

Open
AnjaliSankaran opened this issue Apr 15, 2021 · 7 comments
Open

Adding external listener #3

AnjaliSankaran opened this issue Apr 15, 2021 · 7 comments

Comments

@AnjaliSankaran
Copy link

Hi,
How can we add SCXML execution listener which can listen to a port. please guide, how can we attain this.

thanks,
Anjali

@Touffy
Copy link
Owner

Touffy commented Apr 16, 2021

I'm not sure what you are asking for, but I assume you want some network events to be injected into the State Chart. You can inject events by calling fireEvent on the instance of JSSC (see the API documentation).

However, JSSC is meant to run on the client-side, and you can't just listen to a port with client-side JavaScript. That's not a limitation of JSSC, but of the browser environment.

@AnjaliSankaran
Copy link
Author

AnjaliSankaran commented Apr 19, 2021

I have tried to make my query more clear.

How we can listen to SCXML events on the remote server,
Here we are trying to connect JSSCXML UI with the SCXML executing in the remote server (java environment) on a remote location, can JSSCXML UI reflect the execution on the browser.

Is it possible to visualize the whole execution of SCXML (executing on remote server) using JSCXML .

thanks

@Touffy
Copy link
Owner

Touffy commented Apr 19, 2021

I see.

  1. To listen to server-sent events, use server-sent-events. I mean literally. There is a built-in extension in JSSC to connect to an SSE stream, where all the default ('message') events in the stream are injected into the SC. It's pretty simple to implement on the server-side, too.

  2. JSSC does not support remote debugging of an SC running in another environment (you won't be able to pause the server when you pause the client, for example), but if you load the same SCXML and send it exactly the same events, it should behave pretty much like its twin on the server.

@AnjaliSankaran
Copy link
Author

1.The SCXML is executing on the server (Java SCXML Apache SCXML2)
2.When the SCXML executes on server, it will generate events (server-side-events)
Can my JSSCXML client listen to those server side events and then accordingly make transition to different states,
can you help me with an example, how we can listen to server-sent events.

thanks

@Touffy
Copy link
Owner

Touffy commented Apr 21, 2021

Yes, absolutely, you can do that with JSSC. Your server needs to emit those events, of course.

Your spec is a little vague so I'm going to make assumptions. Please correct them.

On the client-side, the SSE is an <invoke> that represents the connection. Following invocation semantics, the connection is created by the client when you enter the state containing the invocation and closed when you exit it. While in the state, it will inject events from the stream into the SC. It's all documented in the connection-like invoke and the event-stream invoke type.

On the server-side, you can't open the SSE connection, you can only listen and react when a client tries to open one. So you can't use an invocation. The easiest solution is if you want to send all clients the same events, then you don't need to keep track of each individual client in the back-end SC. I'm going to assume that is the case, and you can extrapolate if not. I'm also going to assume you can have multiple clients for a server. I won't help you code the implementation because I don't want to so much as install a JVM on my machine, let alone edit Java code 😜 but I'll describe it.

So what you need is a SSE server library in Java that you can glue into an SCXML event-type extension and that supports last-event-id and an event cache. Your server SC will blindly <send> "SSE"-type events, and the extension will store the events (for future clients who will have missed them) and push them through any open SSE connection (for currently connected clients). When a client opens a new connection, the extension will send them all the cached events after the given last-event-id so they can catch up (I assume you want that, otherwise of course you can ignore that part and all the caching).

You can inject some events from your server-side extension to notify the SC when a client connects and disconnects, so that for example you can exit the states generating those events when no client is listening.

@AnjaliSankaran
Copy link
Author

AnjaliSankaran commented Apr 29, 2021

Here I have included a small example for my scxml script

image

In the invoke statement I have specified the port where the server is running, which listen to the events send.

Can you tell whether this is the correct way to use invoke statement, if not kindly advice how to use them.

@Touffy
Copy link
Owner

Touffy commented Apr 29, 2021

It's not, and markup languages don't have "statements". The <invoke> element must be a child of a <state> or <parallel> element. You can't just put it at the root of your SC.

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

No branches or pull requests

2 participants