Recurring action when a user leaves a place - gwt

I want to schedule a recurring action in my Activity (I am using Activities and Places design pattern). When my user leaves a place associated with this activity, how quickly can I expect this action to stop? Will the inclusion of the recurring action somehow affect the way an Activity is disposed of?
I don't need an immediate guarantee. If an activity is disposed of normally, it's acceptable in my use case.

It is your responsibility to cancel anything that you started in your activity, if you need/want so.
With a Scheduler.RepeatingCommand, you'd have to keep the command around and, in the activity's onStop, set a flag on it so that the next time it's run it exits early and returns false.

Related

Is there a standard / built-in way to handle race conditions with CKFetchRecordZoneChangesOperation?

I'm building my first CloudKit application, and am using CKFetchRecordZoneChangesOperation on startup to get any new records changed while the current device was offline.
I am also calling CKFetchRecordZoneChangesOperation when I receive a subscription notification of changes.
It is possible the subscription notification could come in before the startup call finishes. I am currently using a lock to prevent the 2nd call from starting until the recordZoneFetchCompletionBlock handler is called, signalling that the first one is done. This works, but it also smells a bit hacky.

Why my form go to the top of my screen when my UI freeze?

I have a little issue with a form in a delphy XE2 application:
It's an old issue on this application and i have begin to work on it just since a little time.
When the user choose to launch the process with a button's event, my application launch a connexion with an OPCServer , an SQLServer and construct the form for a good following of data take on the tow servers.
The construction of my form involves a blockage of the interface (for approximately 15 sec) because of lot's of data which are necessary for make it.
When it freeze, if the user want drag the form, she go far away, and usually with the TMainMenu which go out of the screen. After that, it's impossible to use the application because we can't drag and we need to close and re-open.
In the old version, the form be already construct before the connexion. So the modification for a dynamic form isn't in link with this issue.
Life of my event :
-Open connexion with OPC Server
-Open SQL Connexion
-Send SQL Command Text
-FieldByName('') for update my UI (Button.Caption// TPage.TStaticText.Caption // TPage.Label1.Caption)
-FieldByName('') for update an array of record
-Close SQL Connexion
-Open SQL Connexion
-Send SQL CommandText
-FieldByName('') for update an other array of record
-Panel.Visible(false)
-TPage.Panel.Show;
-TPage.Panel.BringToFront;
So I haven't MainForm modification can change its position.
I'm a young developer, so I don't know why it moving and what I can make for repair that...
If you want a part of code, ask me what and i edit this, it's very long and i don't want spam answer.
Thank's for read.
The core of your problem is that you have a lengthy process (form construction) which completely blocks the main thread so your application isn't able to process normal Windows messages at the same time. That is why when you move your application it doesn't properly update its interface.
Now based on your description you already have this form construction process split into multiple steps so you could call Application.ProcessMessages between them.
This will force your application to update its UI part.
But beware calling Application.ProcessMessages often could hurt your application performance quite a bit. Why? It is usually a lengthy process because it forces your application to process all the messages that are in its queue.
Normally not all of these messages get processed as soon as they arrive. Windows groups them in the message queue by their priority list, making sure that high priority messages like WM_PAINT are processed as soon as possible while some other low priority messages like demand for application to respond to OS so that OS can see if the application is still working are mostly processed when application is idle or when they are in queue for certain amount of time.
So that is why Application.ProcessMessages can be so slow as it forces your application to process all messages regardless of their priority.
Also bear in mind that using Application.ProcessMessages can in certain scenarios actually become a bit dangerous.
Let me give you an example:
Lets say that clicking on a button starts a lengthy job which can take some time to finish. Now in order to allow your form to be updated you call Application.ProcessMessages in certain intervals. So far it is all good. But what happens if user clicks on that button again?
Since you are calling Application.ProcessMessages which forces your application to process all the messages and since clicking on button creates a MouseClick message which then fires buttons OnClick event which then executes the OnClick method that has been assigned to buttons OnClick event in the end this will cause the same method that was executed on first button click to be executed again.
So now you have this method partially done from first button click and same method executing again for second mouse click. Now the method that was executed from the second click will finish first and then the method that was started from first button click but was interrupted with Application.ProcessMessages handling the second button click will continue its execution to the end.
This all can lead to strange bugs which are hard to track, because you as a programmer normally don't predict that your end user might have clicked the button twice.
So to avoid this I strongly recommend you implement some safeguard mechanisms to prevent such scenarios by temporarily disabling a button for instance.
But the best solution is always to show your user that your application is working which in most cases will dissuade them from clicking the button again, but unfortunately not always.
You should also take a good care when dynamically constructing a form to enable the controls only after all of the controls have been successfully constructed. Failing to do so the user might click on one of your controls and that control could attempt to access some other control which hasn't yet been created at the time. The result hard to track bug which causes Access Violation.
You might also consider showing a splash screen at start instead of half built form. Why?
For once it is much nicer to see and it tells your users to wait a bit. And for second having main form hidden until it is fully created makes sure that user won't be doing any clicks on it prematurely.

Replaying events - validating transitions

I'm wondering exactly what logic should be contained when applying an event to a state while replaying events using some event sourcing solution.
Specifically, I'm wondering about validation, say I've got entity which can be in one of the following status:
Logged
Active
Close
Cancelled
and the progress needs to be Logged->Active->Close or Logged->Active->Cancelled, we cannot jump from Logged to Close directly for example.
Now, I understand, the validation should be contained in commands: UpdateState would check if the entity current state allows transition to desired one, and would produce appropriate event StatusUpdated which would be persisted into the event store.
Question is, what should I do when replaying it back? Should I just update the status, or should I perform same validation (so that if status transition requirements change it won't be possible to load some previously updated entities unless we add some additional logic), to ensure we won't end up with entities that do not satisfy our current logic?
PS. I think I've got problems grasping it because in my understanding events are essentialy just about 'announcing' something that happened already (and the sender state is already modified) so that interesting parties can react accordingly. And in case of events loading/replaying, you need to alter said state instead of actually 'announce' anything...
You do not need to perform any validation when replaying the event stream.
Commands model things that will be done in the future: You ask the system do to something for you. It's up to the system to decide whether to do it or not, e.g. based on business rules and validation.
Events in contrast model things that have already happened. As in the reality, you can not change the past.
So, this means, when an event gets persisted, it was in consequence of a command which was taken as valid at the point in time when it was processed. Replaying an event stream simply means to have a look at what happened in the past, and you can not change this.
Hence, you do not need to run any validation again.
Moreover, this means that if one day your business logic changes, all the things (business accidents!) that happened in the past still have happened, so they must not change. Hence you are not allowed to use any validation logic, as it may be another one today than when it was when you stored the events.
And again: You can not (and should not) change the past :-)
Example
Supposed you have a way of validating credit card numbers. A customer comes to your shop, pays, you consider his / her card as valid given your current set of rules, and everything is fine.
Then, one day the credit card institute changes the way credit card numbers are calculated, and hence you have another validation algorithm.
When you now play back your past events, the payment had happened, with or without the new validation rules - and you can not change the fact that it had happened! If you wanted to you had to create a new transaction to send money back to the customer. Again, this would result in a new event, not in a changed one from the past.
So, to cut a long story short: Don't validate events against anything. They are valid by definition, as they had happened before.
Any event stream that's been written to the event store should be valid to be played back without introducing any logic in the event handlers. If you needed to change your transitioning process, you'd need to look at doing some sort of conversion, along the lines of this example.
Regarding your last point. Event sourcing is a technique for persisting and restoring the state of an entity using a historical record of ordered events. It just so happens that when you're saving the entity, you can also publish these events for any interested parties to consume.

The difference between suspend and suspendAll

What is the difference between suspend and suspendAll in SCORM 2004 3rd ED?
Can I suspend more than one activity in one session?
In SCORM 2004, "suspending" something indicates that you want to preserve it's state. Think of it conceptually as a pause button, a way to stop and come back to the same place later.
"Suspend" and "SuspendAll" are used in two different contexts. As you probably are aware by now, the SCORM run-time and SCORM sequencing books are separate but related.
"Suspend" is a concept from the run-time book (if I read and understand your question correctly). Setting cmi.exit to suspend indicates that you want to save this set of run-time data for the current SCO so that when the activity is relaunched the data will still be available.
"SuspendAll" is a concept from the sequencing book. It is a navigation request that indicates the learner wants to pause and exit the entire activity tree. When a suspendAll navigation request is processed, the activity tree state (the sequencing data) is preserved and when the course is relaunched, the learner will resume from the current activity.
Some other thing to note:
suspendAll is not related to the preservation of run-time data. If you issue a suspendAll navigation request, that won't in itself preserve the current activity's run-time data.
To confuse matters a bit further, there are two more ways the word "suspend" is used:
"The Suspended Activity" - The activity that was current when a suspendAll navigation request was issued. This is the activity that will be resumed when the course is relaunched.
"Suspended" - a property of every activity that indicates whether it was last exited in a suspended state.
So, to answer your second question, there can only be one "suspended activity" at any given time, but many activities can be "suspended".

How to get a sequence into a windows workflow statemachine?

I have a Windows Workflow Foundation (3.0) state machine in which I need certain states to change state based on the age of the state. For example, when the work flow enters state X the user needs to action it within 5 days. If this has not been done, the work flow needs to transition into state Y. So what I think I want is a state with an EventDriven Activity to handle the user's action, and a Sequence activity with a Delay activity that has a SetState activity which causes the state transition if the user hasn't actioned it in time.
States don't accept a Sequence activity directly, so I have tried to put this logic in the StateInitialization activity, but it doesn't allow Delays. I could put the delay in the previous state and another EventDriven activity and then transition to which ever state is appropriate but that doesn't really fit the business flow.
Is there a way this can be done in State Machines or should I be using a Sequential work flow?
You can achive this using state machine workflows easily.
You need to put a StateInitializationActivity and an EventDrivenActivity into your states. The EventDrivenActivity accepts a delay activity, put the logic after the timeout there, for example set another state. If the timer elapses earlier than the activities within the StateInitializationActivity, the state will be changed.