How to Kill Processes on hitting a button flex spark - apache-flex

When I send request to backend(java) its taking time to get the response, so If I hit cancel button, it only removing my title window but the process is still going on. So, after hitting cancel button how to stop Listening to the response immediately?

If remoteObject is using then we can cancel listening to the response by this small line
remoteObject.getOperation("serviceYouWantToStop").cancel();

You can stop listening for a response by removing the event listeners for the response. How you do this depends on the service you're using and how you call it, but generically like this:
myService.removeEventListener(ResultEvent.RESULT, myResultHandler);
myService.removeEventListener(FaultEvent.FAULT, myFaultHandler);
You should consider editing your question to provide those details. To actually stop the RemoteObject call, you can use the cancel() method of HTTPService; the disconnect() method on RemoteObject and a disconnect() method on WebService

Related

How do I make a Vertx handler execute earlier in eventloop?

I'm using Vertx 3.5.0 and very new to it. I'm trying to cancel the code execution when a client cancels their request.
Currently it's setup to where the first thing we do is deploy a verticle to run an HttpServer, and we add all of our Routes to the Router. From here we have a handler function per route. Inside this handler I'm trying this:
routingContext.request().connection().closeHandler({
//execute logic for ending execution
});
This is the only method I've seen that actually catches the closing of the connection, but the problem is it doesn't execute the handler early enough in the eventloop. So if I have any logs in there it will look like:
...[vert.x-eventloop-thread-0].....
...[vert.x-eventloop-thread-0]..... (Let's say I cancelled the request at this point)
...[vert.x-eventloop-thread-0].....
...[vert.x-eventloop-thread-0]..... (Final log of regular execution before waiting on asynchronous db calls)
...[vert.x-eventloop-thread-0]..... (Execution of closeHandler code)
I'd like for the closeHandler code to interrupt the process and execute essentially when the event actually happens.
This seems to always be the case regardless of when I cancel the request so I figure I'm missing something about how Vertx is handling the asynchronousity.
I've tried executing the closeHandler code via a worker verticle, inside the blockingHandler from the Router object, and inside the connectionHandler from the HttpServer object. All had the same result.
The main code execution is also not executed by a worker verticle, just a regular one.
Thanks!
It seems you misunderstand what a closeHandler is. It's a callback method, that Vert.x invokes when the request is being closed. It is not way to terminate the request early.
If you would like to terminate request early, one way is to use response().close() instead.
As a footnote, I'd like to mention that Vert.x 3.5.0 is 4 years old now, and you should be upgrading to 3.9, or, if you can, to 4.0

Long Polling does not hit hub class?

When the browser says long polling but the debugger in the constructor of hub class does not hit. What is the problem?
Basically what I want is everytime the long polling happens, I also want a particular functionality like a database call to be executed.
poll requests are receive channel (i.e. are only used by the server to send data to the client if there is any) and as the result they don't cause instantiating hubs. However you can override the ProcessRequest method on the server side - it is being called for each HTTP request the server is receiving so you can do whatever you want there.

Is there any way to abort an ipc async request sending in electron?

I wrote some code for sending an async request via ipc in electron, but I wanna know that how can I abort or cancel the ipc requests which I already sent out.
ipc.on('receivedSoftwareInfo', (info) => {
// TO-DO
});
ipc.send('getSoftwareInfo');
I had searched the api documents from Repo of electron, and got an information that I can stop by invoking removeListener like following code so that events I bind won't trigger.
ipc.removeAllListeners();
But I think there is a potential problem if user click the button and request again immediately, it will remove all of listener by program's side, then ipc send request second time.
It will look like following flow:
Events are removed -> async request is still there -> bind events again -> trigger
(I don't want it happen and trigger by old request)
So, is there any way to abort an ipc async request sending in electron? I think it's better than removing all of listeners to solve this question.
Unfortunaly, that is not possible. An IPC request is managed by the browser (here, Electron) and cannot be managed in JavaScript.

Understanding how netty works

I'm trying to understand how netty works, and after reading some of the documentation I was to see if I understood how things work at a high level.
Basically netty has an event cycle, so whenever you make a call it gets serialized and the request gets pushed down to the o/s level, and it uses epoll and waits for an event to send back to netty.
When the operation system generates an event that netty subscribed to, netty then has an event loop that gets triggered.
Now the interested part here is, the event that gets triggered has to be parsed, and the client code (or custom code) has to figure out who actually this event is for.
So for example, if this was for a chat application, when a message is sent, it is up to the client code to figure out to send this message via ajax to the correct user.
Is this, at a high level, a correct overview of how netty works?
BTW, when netty listens for events sent via epoll, is this event loop single threaded or does it work from a pool of threads?
Sounds correct to me.
There are more than one event loop thread in Netty, but it does not mean a single Channel's event is handled by multiple event loop threads. Netty picks one thread and assigns it to a Channel. Once assigned, all events related with the Channel is handled by the picked thread.
It does not also necessarily mean that an event loop thread handles only one Channel. An event loop thread can handle multiple Channels.

Can a request be handled and ended prematurely, early in the pipeline?

I have an HttpModule that has bound an event handler to EndRequest.
Is there any way to handle the request inside the event handler? Meaning, I don't just want to run code and keep the request moving -- I want to stop it dead in its tracks, return a 200 Status Code, and call it a day, without it request continuing to the next step in the pipeline.
HttpContext.Current.ApplicationInstance.CompleteRequest();
Documentation

Resources