My design is in a spot of bother, mainly because a requirement of it is to be able to support cancellation of NSURLConnections that are in progress.
I've heard plenty of people say that you cannot send the cancel message to NSURLConnections objects that are running in synchronous mode, but is this solely because of the logistics of it? For example, if an NSURLConnection is loading synchronously, then the cancel message sent on the same thread wouldn't be received by the connection object until after the connection has finished anyway.
What I'm hoping is that it is possible to send a SYNCHRONOUS NSURLConnection object the cancel message from another thread.
Does anyone know if this is possible or have tried it before?
Regards,
Nick
Answering my own question:
No, it isn't! Quite simply because the class method to which you start a synchronous NSURLConnection doesn't return a connection object (upon which you would call the cancel method) - it returns an NSData object instead!
Related
I am using Spring AMQP v1.4.2 and trying to find a send method, possibly in RabbitTemplate, that blocks the thread until a confirm is received from the server to make sure we do not lose messages.
I have seen the sendAndReceive() method but it waits for a reply message in an RPC style, while I just want to wait for a confirm on the channel. I know that I can use the setConfirmCallback() method but then it means it is not synchronous and I may end up on a different thread when the confirmation arrives and I will lose my thread-locals, i.e. lots of Spring goodies.
Is there anyway to achieve that in Spring AMQP?
RabbitMQ gets huge performance benefits by using asynchronous publishing. As you say, you can configure publisher confirms to get an asynchronous confirmation that a message was delivered to a queue.
If you really want to block, you can use setChannelTransacted(true) on the RabbitTemplate; the commit will block until the message is secured in the queue(s).
I have wrote one sample com server which implements com connection point. I am calling one method in this COM object which in turn calling some other method in my client code using connection point mechanism.
But all the above listed operation is synchronous communication. I would like to make COM server pure async so that if my COM server get some event it should fire the data back to its client.
please suggest how it is possible using COM connection point.
Note :- My COM server is running as a exe out of proc.
Thanks in advance!!!
Regards
Ashish
Threading is never a minor detail in COM, just as it isn't in any runtime environment. You must observe the apartment state that the COM client program selected. And if it is STA, by far the most common selection, then it is your duty to fire the event on the thread that the client code selected. Ignoring that requirement just produces impossible to diagnose bugs in the client program.
So if you fire the event from a worker thread in your own code, the only way to get event handlers to run async, then you must marshal the interface pointer. CoMarshalThreadInterfaceInStream() or the easier-to-use IGlobalInterfaceTable gets that job done. Rock-hard requirement. It will run asynchronously when the client program opted-in by using COINIT_MULTITHREADED when it called CoInitializeEx(). The only thing you can do is publish the fact that your code is thread-safe by picking the ThreadingModel registry value, using "Both" or "Free".
Same as you do it without COM:
the client of your server object calls a method;
the method starts a background operation and returns;
The background operation can use a separate thread, an async I/O API, a timer API, etc. When the background operation has completed, it fires an event (calls a method on the client-provided sink interface);
the client handles the event.
Back to COM, all method invocations in COM are synchronous by default. When you fire an event on the client-provided sink interface, the call will block until the client returns. There's one exception to this behavior: IAdviseSink. The methods of this interface are asynchronous, if the callee resides in a different COM apartment from the caller. However, IAdviseSink is probably not what you're looking for.
The standard way to use asynchronous COM requires that the interface have an separate UUID for the asynchronous interface. IConnectionPoint does not have an async UUID, so you can't use ICallFactory to implement asynchronous COM.
I'm just trying to figure out how these two things work. Obviously websocket's use push technology, so the client doesn't have to do long polling, or constantly refresh and check if something has changed (Kind of like an event listener).
But with delegation, like in objective C, are delegates constantly checking, by sending requests over and over again, to see if a method has been fired. Or is the information that a method has been fired PUSHed over to the delegates?
Or my third theory about delegates is, since they are of course in the same program, do the two classes (protocol and delegate class) always have an "open connection", kind of like Polling. Or is it like my second paragraph, where the information is truly being PUSHed.
WebSockets are a bi-directional full-duplex message based communication channel. Many push technologies can get low server to client (browser) latency, but with WebSockets you also get low client to server latency (and therefore low round-trip latency).
From my reading (I'm not an Objective-C expert), delegates are a just a way of creating a loose protocol (in the object sense, not in the network sense) between objects. I don't know the implementation details but I'm certain that there is no polling going on. The delegate methods are probably just looked up when needed. There is no need for an "open connection" or polling. Think of delegates as a way of doing function/method calls, not as a network transport (like WebSockets). This Apple doc goes into deeper detail.
I have an application that must log all events that the user does in a remote database, so,I´ve choice to use the webservice format (the application call the webservice with the event parameters).
So, i did a remote EJB to perform that, but it is running with a bad performance, because the application needs to wait for the webservice´s response to proceed the request.
Is JMS an alternative?
What you suggest?
Thanks.
JMS will be much lighter & can asynchronously process the events. They can be used to capture application events or audit logs for the activities occurring in the system. Can send a message to a queue with proper details & those can be fetched at receiving end to process further.
If you are using EJB-3.1, then can annotate your method with #Asynchronous which returns AsyncResult implementation of Future which can be used to retrieve result, but can also be used with methods returning void.
I'm using a message listener to process some messages from MQ based on Spring's DefaultMessageListenerContainer. After I receive a message, I have to make a Web Service (WS) call. However, I don't want to do this in the onMessage method because it would block the onMessage method until the invocation of WS is successful and this introduces latency in dequeuing of messages from the queue. How can I decouple the invocation of the Web Service by calling it outside of the onMesage method or without impacting the dequeuing of messages?
Thanks,
I think you might actually want to invoke the web service from your onMessage. Why do you want to dequeue messages quickly, then delay further processing? If you do what you're saying, you'd probably have to introduce another level of queueing, or some sort of temporary "holding" collection, which is redundant. The point of the queue is to hold messages, and your message listener will pull them off and process them as quickly as possible.
If you are looking for a way to maximize throughput on the queue, you might think about making it multi-threaded, so that you have multiple threads pulling messages off the queue to invoke the web service. You can easily do this by setting the "concurrentConsumers" configuration on the DefaultMessageListenerContainer. If you set concurrentConsumers to 5, you'll have 5 threads pulling messages off the queue to process. It does get tricky if you have to maintain ordering on the messages, but there may be solutions to that problem if that's the case.
I agree with answer provided before me , however I can see a usecase similar to this very common in practice. I'm adding my two cents It might be valid in some cases that you don't want to do time consuming work in your onMessage Thread (which is pulling message from Q)
We have something similar in one workflow, where if user selects some XYZ option on GUI that means at server we need to connect to another external webservice to get ABCD in this case we do not make call to webservice in onMessage Thread and use ThreadPool to dispatch and handle that call.
If something wrong happens during webservice call we broadcast that to GUI as separate Message , there is concept of request id which is preserved across messages so that GUI can relate error messages. You can use ExecutorService implementation to submit task.
hope it helps.