I was wondering if there was a way too start a timer from an WampServerInterface instance?
I saw that you can set it on the server object. But I need to create it from my WanpServerInterface object if somebody subscribe to a certain event.
Any toughts?
Regards,
Timer is a function on the loop object so it can be called by getting the loop object. But as the documentation is really minimalistic, it took me sometime to find the answer (couple of hours and more)and get back here.
class MyObject implements WampServerInterface
{
...
$this->loop->addPeriodicTimer(2, function($timer) { call_user_func(array($this, 'startCountdown'), $timer); }) ;
...
}
You can inject the EventLoop that's passed/created in IoServer into your WAMP application and create timers with it once users subscribe to your desired Topic.
Related
I'm buliding a watch face and want to display the remaining time on the timer.
I've been looking for ways to access (presumably) "com.google.android.deskclock" for the timer data, but have not found anything on the net.
Thank you for your help.
There's no official API for this, but because the system Clock app exposes this value via a complication, you can access it that way.
Start by specifying the timer complication as a default:
setDefaultComplicationProvider(myComplicationId,
new ComponentName("com.google.android.deskclock",
"com.google.android.deskclock.complications.TimerProviderService"),
ComplicationData.TYPE_SHORT_TEXT);
If your watch face already supports complications, you could just feed this provider into that logic. Otherwise - if you want to do something else with the timer value - you'll need to extract it from the ComplicationData. So, in your WatchFaceService.Engine subclass:
#Override
public void onComplicationDataUpdate(int complicationId, ComplicationData complicationData) {
super.onComplicationDataUpdate(watchFaceComplicationId, data);
if (complicationId == myComplicationId) {
// This is the timer complication
CharSequence timerValue = complicationData.getShortText()
.getText(getBaseContext(), System.currentTimeMillis());
}
}
This gives you the current timerValue to do whatever you'd like with.
A couple of caveats to this approach:
Because this isn't one of the published system providers, there's always a chance that it won't work on some watch somewhere - or that an update may break it.
The user will need to have granted complication permission to your app. If your face is already showing other complications, this may be a non-issue, but otherwise it's your call if this is an acceptable UX.
I have a scheduler that puts some value(N or Y) into a topic for every 10 mins(usually 'N', unless something abnormal happens with topic). When the topic goes down, the scheduler will populate a property(kind of inter-scheduler communication), so that it can be used during scheduler's next cycle, as way of telling the scheduler that something bad happened during last cycle, so that, it'll place a different value('Y') in topic in this cycle. But the problem here is normal exchange property isn't helping. The property is always null during every scheduler cycle.
When i went through the http://camel.apache.org/schema/blueprint/camel-blueprint.xsd, looking out for something similar to global properties, i got this one "tns:properties"
which can be set at context level.
Can this be used as a global property?
is there a way to read/write it in my scheduler route?
I'm also thinking about having a bean with an instance variable to hold this inter-scheduler-communication property.
Can anyone suggest the right option?
What you've described sounds to me like a means for maintaining state between processes, and using the properties for that will be problematic for a number of reasons.
I suggest breaking the app into a couple different pieces, and use a shared OSGi service to maintain the state.
public interface MyScheduleState() {
public setSomeValue(String x)
public String getSomeValue()
}
Route 1: Timer starts the task .. check the service for values.. send event. if error occurs, sends error message to some queue://MY.ERRORS
Route 2: Listen for errors on MY.ERRORS and update the OSGi service with new values
This gives you control over the behavior and you can change how the "stateful service" stores its data.. either in memory, on disk as a file or in a cache" and your routes will never know the specifics.
Take a look to http://camel.apache.org/properties.html
It seems to be exactly you are looking for - context properties. You can set a property value on each cycle and it will be available in the next cycle too.
Say,there is a requirement that a customer object is loaded from the db to a silverlight application, so that the customer details are shown in the UI. We need to detect if the user is changing any data in the UI.
We are listening to property changed notifications from the view model. However, when the notifications are result of property change as part of the loading process we have to discard it.
class CustomerLoader
{
Helper helerobj;
Address addressobj;
Profile profileobj;
void LoadFromDb()
{
helperobj.Load();
addressobj.Load();
profileobj.Load();
//start listening after the loading finished
this.propertychanged += new PropertyChangedEventHandler(handlepropertychanged);
}
The trouble with this is the inner objects might be calling asynchronous functions which might set properties. So by the time we started the property change listening, the loading might not have been finished.
We need to know when the loading is actually done. As of now we are asking the developers who are developing the inner object classes to accept a callback in the parameter which they should call when the function is finished.
Is there any other way to do it?
You want nothing but a really classic asynchronous objet loading.
So yes, the only solution is to ask developers working on the loading to propose an asynchronous function. Now you hav several solution to achieve asynchronicity in Silverlight.
You could either provide a callback as you do, or use async and await to manage your asynch task as explain here: http://10rem.net/blog/2012/05/22/using-async-and-await-in-silverlight-5-and-net-4-in-visual-studio-11-with-the-async-targeting-pack
I have a TimerConfig and a Timer Object and use EJB 3.0. All works well, but "onTimeout" I want to get the information, when the timer was initialized. I cannot find a method such as timerStartDate.
Should I use timerConfig.setInfo and put the date when timer is initialized? Is this the only way?
Yes, if you want to know when createTimer was called, then you'll have to store it in setInfo. There is no builtin mechanism.
I have often times wondered about it but now that I have encountered a piece of logic that incorporates it, I thought I should go ahead and get some help on deciphering the fundamentals. The problem is as follows, I am looking at a WPF application that is utilizing the Composite Application Library. Within the source of the application I came across the following line of code in the Presentation of a view. For the sake of convinience I will call it Presentation A:
private void OnSomethingChanged(SomeArgumentType arguement)
{
UnityImplementation.EventAggregator.GetEvent<EventA>().Publish(null);
}
When I saw the method Publish in the above given method, my gut told me there must be a Subscribe somewhere and in another class, I will call it Presentation B there was the following:
UnityImplementation.EventAggregator.GetEvent(Of EventA).Subscribe(AddressOf OnSomeEventA)
There was a private function in the same class called OnSomeEventA that had some logic in it.
My question here is that how is everything wired over here? What exactly is achieved by the 'Publish' 'Subscribe' here? When 'something' changes, how does the compiler know it has to follow the logic in OnSomethingChanged that will 'Publish' an event that is 'Subscribed' by another class where the logic of the event handler has been described? It will be great to understand the underlying wiring of this process.
Thanks
The first time GetEvent<T> is called for each event (identified by the type parameter T) the EventAggregator creates an empty list of methods to call when that event is published. Typically, this will happen immediately before the first call to Publish or Subscribe (as in your examples).
Then:
Whenever Subscribe is called a method is added to the list.
Whenever Publish is called it walks through the list and makes those calls.
So, the call to Publish() in Presentation A results in all of the methods that have been registered by calling Subscribe being called, which in your example would include Presentation B's OnSomeEventA method.
Try setting a breakpoint in the OnSomeEventA method and take a look at the stack, and don't forget the source is available, too!