Catching Push registry event? - java-me

Is there any way to know that whether the application has been invoked manually or by push registry?

PushRegistry.listConnections(true) returns a String[] of registered connections currently being used --- so if this is an empty array, the MIDlet was started manually.
See http://developers.sun.com/mobility/midp/articles/pushreg/ under "Discovering Whether a MIDlet Was Push-Activated".

and be care of that if you need information of whether the middlet was runned by alarm, described way is not about it, its only about different push events like incoming connections. here is the quote from http://developers.sun.com/mobility/midp/articles/pushreg/
"Note that the PushRegistry API doesn't provide a way to discover whether the MIDlet was activated by an alarm. If that knowledge is important, you must implement your own detection method. One way is to save information, such as the time of launch, in the RMS, then compare the saved time with the current time when the MIDlet is launched"

Related

Is there a way to hold "STOP CASTING" for some time

I want to make an AJAX call for analytics purpose after user clicks on STOP CASTING and before receiver application actually shutdowns. Is there any message interceptor for STOP_CASTING? Or any other way to achieve this?
You cannot delay the stop casting behavior. There is typically a very small window where your code might have a chance to run. A more reliable way to handle analytics is to periodically post updates while the media is playing.

Spotify API player update event

Basically I want to display the current track on a website.
I already searched quite a bit for a possibility to get notified when player state (play/pause, track, current position) changes.
My question:
Is it possible to get notified (socket, hook call) or is the only possibility I have to call the Web API like every second and fetch the state?
I fear that I'm running into rate limits when multiple users connect their accounts and display the current track.
Nope, there's still no way to do that. To achieve what you'd like, you need to pool the Spotify API continuously.
You can however use the Spotify SDK that you can pass a function to be executed on playback state change. The SDK is incompatible with a few platforms (see supported browsers), but for those you could catch the SDK initialization error and then switch to continuous polling via the API. You will have a lot fewer requests then.
A second option would be to only update the currently playing song after the last song should have ended. When getting the playback state for the currently playing song, you could use the field duration_ms and progress_ms to calculate the remaining time of the song. Then schedule another API requests for when the song should have ended and you're good. Whether that's a good strategy for your use case or not depends on the type of playback and how often the playback changes in your app.
I hope I could help!
As of now, it seems to be possible to receive player state events with a listener:
https://developer.spotify.com/documentation/web-playback-sdk/guide/#playback-information-display
I haven't tested the Web version, I'm currently using the analogous Android APIs, and Android's seems to work for play/pause change and track change (but not for position change)

What is a correct design pattern for an API mailing/notification system?

I am developing a Rest API using node js, mongo and express as technologies. My models include users, venues, etc. In addition each user has states. Examples of states could be when a user signup the first state is 'new_user', after one week the state must be 'first_week_user' and so on.
The purpose of these states is to notify the user according to his or her state. For example if a user like a picture and the user is in the first week (he has the 'first_week' state) so an email must be sent to him. I am in the design stage right now, so I want to know if somebody had to face the same issue before.
The design that I have in mind is to put a notification_profile inside the user object and using a cron job to check the state and the actions of the day and according to that send the emails/push notifications.
What do you think? Are there a better option? e.g. I can have an email API and queue the emails hitting this API. Do you know where I can find information about design patterns facing this problem?
Thanks a lot for your help.
Without more detail, this sounds like you need the Observer pattern.
Essentially, your Email component would subscribe to each Person object's like(photo photo) event, and either execute an email-send job immediately, or schedule the job to run later, as part of a batch.
One way to specify the state transitions would be as a hierarchical state machine. See http://www.eventhelix.com/realtimemantra/hierarchicalstatemachine.htm#.VNJIflXF--o and http://en.wikipedia.org/wiki/UML_state_machine
I don't have a good node.js example but here's a C# implementation that also includes the concept of timed events. Essentially the state machine keeps track of a NextTimedEventAt so you can efficiently pull it back out of a database at the right time to fire a time-based event.
Actions happen on state transitions: as you enter a state or leave a state.

Using the browser client, how can I set the sounds.disconnect() on every call?

Using the browser client, how can I set the sounds.disconnect() on every call? Is there a way to access the device singleton to modify that setting? I know I can access when I get the device.ready callback, but I want to modify the setting on every call.
I received a helpful reply back from Twilio support:
--
That parameter will be instantiated in Twilio.Device either True or False once the web page loads, so to change it, I believe you would necessarily need to also reload the page.
This would create another control layer in effect, that isn't provided out of the box by Twilio: you'd need to build a web page to change the variable that determines sounds.outgoing(), and then trigger the page to reload.
Another option would be simply create a second Client instance running on a separate tab, and have both instances use the same outbound caller ID. That might be easier.
--
In my scenario I'll need to find a different approach, and will look in to disabling the Twilio sounds and using my own.

Why does my Workflow Service (4.0) variable go null in a DoWhile Activity?

I have a WF service that I'm trying to setup receive activities to "Subscribe" and "Unsubscribe". I'm using This WF Durable Duplex Tutorial as a basis because my service performs callbacks to clients. Basically, think of it as a chat service.
I can make client calls to the two receive activities just fine. What happens is the callback address of the client is passed in to Subscribe() on the service. The address is stored as a variable in the WF service and everything looks like it would work as to be expected.
When a client calls Unsubscribe(), my watch I have set on the address var during debugging shows it as null. So what gives?
Here's the basic setup of my WF service layout...
Everything is enveloped in a DoWhile activity. Inside of that is a Pick activity and two Pick branches. The first branch is for subscribing activities. It has a receive-sendreply activity that assigns the string passed by the client to the WF address var. The second branch handles unsubscribing. The trigger is the Request activity and the client address is again passed in.
From there it goes into a sequence, starting with an If. It checks to see if the unsubscribeAddress equals the address already subscribed. If it does, then it sets the address to String.Empty and sends a success message back to the client.
Why would a variable that's scoped to the enveloping DoWhile activity be implicitly assigned to null? I'm trying to get this to work so I can implement multiple client subscribers from there and work on triggers that invoke callbacks to multiple clients.
CONCAT EDIT: I set a breakpoint at the DoWhile level and my var is null once Unsubscribe() is called. When Subscribe() is invoked, the watch shows a value in the var all the way through. Until I Unsubscribe() with a client. Should I be using a While Activity instead?
Without seeing the workflow I can only make a few guesses but the things I would look for are:
Is the variable scoped to a sequence or something that is inside of the DoWhile activity? BTW there is no benefit ti changing it to a While activity, the only difference is that the condition is tested at the beginning or the end.
Is the variable used somewhere else and cleared that way. Try renaming it and see what gives.
Is there persitence in play and is the type not persisted> I assume its either a string or a Uri and both should be good to go.
Is there a problem with correlation and is your Unsubscribe message being processed by a different workflow? Mare sure the CanCreateInstance is set to false.
try making a class scoped private {get; set;} and see if the problem still rears its head, thats the best I can do without seeing the actual source code as from what you described I cant see any issues.
Wow, ok scary stuff. I had to hand edit the xamlx file earlier and the references I edited for the SendReplyToReceive saved funny when I switched back to the activity designer. It made it look like I had two Unsubscribe()'s and not only that but the correlation handles for each branch were crossing between branches.
I'm all set now. To fix the issue I removed all the messaging activities, dropped in a new ReceiveAndSendReply activity into branch 1's action block. Then I dragged the Receive activity to the Trigger for branch 1 and configured it as I had before. I did the same for branch 2, except I placed the SendReplyToReceive activity below my If activity that validates matching addresses.

Resources