Problems with OpenRTI callbacks - hla

How in the OpenRTI to make the rti send callbacks? For example, reserve a name with the reserveObjectInstanceName
_rtiAmbassador->reserveObjectInstanceName(name);
Errors:
terminate called after throwing an instance of
'rti1516e::ObjectInstanceNameNotReserved'

If you are using the HLA 1516e API (as opposed to HLA 1516 or HLA 1.3) when you make a call to connect you can specify a CallbackModel which is either SYNCHRONOUS or ASYNCHRONOUS. In a synchronous callback model, the federate has to call the method evokeCallback in order to trigger the RTI to send whatever is queued up. In asynchronous, the callbacks are sent automatically.
What you should do in this instance is have something like this:
_rtiAmbassador->reserveObjectInstanceName(std::wstring(L"MyObject"));
_rtiAmbassador->evokeMultipleCallbacks();
MyFederateAmbassador::objectInstanceNameReservationSucceeded(std::wstring const & name){
_rtiAmbassador->registerObjectInstance(handle, std::wstring(L"MyObject"));
}

After each call to RTI, to get a callback, you need to call
evokeCallback()

Related

GRPC future vs blocking stub in client

I'm writing a client application in Kotlin where I need to call a GRPC service that has both a future based and a blocking stub.
In case I choose to go with the future option, I will need at some point to do something like a CompletableFuture.get() call, which means I will be blocking anyway.
So, what's the difference between one and the other for this case? Or is it the same?
I will need at some point to do something like a CompletableFuture.get() call, which means I will be blocking anyway
Not necessarily. With a ListenableFuture, CompletableFuture, or other completion-hookable mechanisms, you don't have to block at all. You could register an action to do on completion, or you could wrap them in suspend calls to work with coroutines etc.
Also, even if you did call get() and block, it still allows you to block later than the start of the call, and do other things between the initial call and the get(), which would be concurrent with it:
val future = callSomethingWithFuture()
doStuffConcurrently()
val result = future.get()

What is the use of add_callback_threadsafe() method in pika?

From the description in the pika documentation, I can't quite get what add_callback_threadsafe() method does. It says, "Requests a call to the given function as soon as possible in the context of this connection’s thread". Specifically, which event does this callback get associated to? Since, add_callback_threadsafe() doesn't receive any "event" argument, how does pika know when to invoke that callback?
Also, in the official example, why do we even need to build the partial function and register the callback in the do_work() method? Could we not just call the ack_message() method after the time.sleep() is over?
The reason why the method exists:
How to add multiprocessing to consumer with pika (RabbitMQ) in python
If you use the same rabbit connection/channel with multiple threads/processes then you'll be prone to crashes. If you want to avoid that, you need to use that method.
Could we not just call the ack_message() method after the
time.sleep() is over?
No, you would be calling ack_message from a different thread than the main one, that's not thread safe and prone to crashes. You need to call ack_message from a thread-safe context, i.e., the add_callback_threadsafe().

Using Twilio StatusCallback when a call on queue hangs up

I'm implementing a Twilio-powered Call Center and I'm currently using Enqueue to hold calls until an operator can answer them. I'd like to use StatusCallback to warn operators that a call that was on hold is now "completed" (caller terminated the call) but StatusCallback seems only to work with a "Client" verb. I'd want to use it with along with "Enqueue" or a "Gather" in the WaitURL.
Am I missing something?
I found that setting the StatusCallback endpoint in the Application configuration in the Twilio Dashboard globally solves this.

Load xml file on start of Windows 8.1 Universal App

in my Windows 8.1 universal app I want to retrieve a local XML file on application start. But I'm confused with async / await. I use GetFileAsync, so it needs to be in an async function. But I could not call it from the initialization of the app. When I just call the function it says i need to add await. If I await, it says I could use await only in an async method, and therefore I could not do it in the initialization. So how could this be done?
Many thanks!
See here: How to call asynchronous method from synchronous method in C#?
"If you have a simple asynchronous method that doesn't need to synchronize back to its context, then you can use Task.WaitAndUnwrapException"
So put the code into a separate method and use the method above or the second method RunTask.

WCF Service - Async How to?

I am consuming a 'third party' WCF service. I am making to call to their method in Async mode from C# console application.
The order I am making call is
1. WCF.MethodA (Async)
2. WCF.MethodB (Async)
3. WCF.MethodC (Async)
I wanted to raise an event (which makes call to 'MethodB') after call to 'MethodA' is successfully complete. Can anyone tell me how to do that? Is that something the service needs to support (raising events)?
Thanks
If you turn on the asynchronous option when you add the service reference, you'll get asynchronous calls with events.
For example, you should get WCF.MethodAAsync with a WCF.MethodACompleted event automatically. You can subscribe to the completion events, and start the next method upon completion.