In google realtime, is there a way to know that a compound operation is complete? - google-drive-realtime-api

I can know that a particular event is part of a compound operation, even a particular operation...
tags.addEventListener(gapi.drive.realtime.EventType.VALUES_SET,handleEvent);
function handleEvent(serialized) {
if (serialized.compoundOperationNames.indexOf("LOTS OF TAGS CHANGING") > -1) {
};
...but how can I know that the compound operation is complete, and it's now a good time to do something about it?
I'd like to be able to do something like this:
if (serialized.lastCompoundOpEvent) {
// Read all the tags and do an expensive bulk operation here
}

I don't think there is any way to do specifically what you list describe there.
If the goal is just find out all events for a particular compound operation, you could listen for ObjectChangedEvent. The one ObjectChangedEvent should include the list of all events for the compound op for the object and its children.

Related

Flink: Can we update a keyed state for only some elements in processBroadcastElement function?

As mentioned in the answer here, I can use applyToKeyedState to update all states across all keys in the same manner.
If my broadcast event has a subset of all keys and I only want to update those, can I make it a part of the KeyedStateFunction?
Example
ctx.applyToKeyedState(stateDescriptor, new KeyedStateFunction[K, ValueState[Boolean]]() {
override def process(k: K, state: ValueState[Boolean]): Unit = {
val key = k.asInstanceOf[String]
if (broadcastEvent.contains(key)) {
state.update(true))
}
}
})
Nothing prevents you from employing whatever logic you desire in your KeyedStateFunction, but you could get yourself into trouble. The issue is this: each instance of your keyed broadcast function operator will be applying this function independently. And the job might crash at any point -- perhaps after some instances have applied the KeyedStateFunction, and others have not.
You should limit yourself to operations on the keyed state that will never give rise to inconsistencies, even after failure/recovery or after rescaling.

How do you represent a function call as an if condition statement in Sequence Diagram?

I've been drawing a sequence diagram of a module recently, while reverse engineering.
I encountered a control statement, and it is like,
if (func_A() == True)
{
DoSomeThing();
}
else
{
DoSomeThingElse();
}
The problem is how to draw the condition?
As I mentioned, It is reverse engineering. The code cannot be modified now.
I drew two diagrams, and I don't know which way is right,
The first one is this, I think it's wrong because it doesn't show the function call as a message from A to B.
This is the second, It shows a message func_A.
What do you think about to do this right?
To complete the other answer there is anyway a problem in the second proposal because we do not know if in [func_A() == True] you reuse the value return by the previous call or you do a second call, to avoid that add the explicit return in your diagram :
Out of that do you know the activities ? A sequence diagram is "just" an interaction while an activity is a behavior and can be more adapted :
It depends. If func_A is an operation defined in Object2 the second representation would be correct. The first does not tell where the operation is defined. Most likely (!) one would interpret func_A as an operation local to ObjectA which your code seems to say. (Btw. you have two completely different object sets AB vs. 12 in your examples.) But that is uncertain. So the 2nd variant is more explicit (and correct).
In any case I advise to not overdo SDs with fragments as "graphical programming" doesn't make things easier to read (my practical experience). It's excellent to show message flows in various collaborations. But when it comes to conditions it's getting messy very soon. A better way is to create different sub-diagrams or even use pseudo code if there are too nested if conditions. In many cases such if clauses are a good fit for state machines.

Terminate activity diagram from subactivity

I´m trying to draw an UML activity diagram for a fnction that is (highly simplified) represented by the following code snippet. My intention is to have a subactivity for the lines that check the mode parameter (if-else).
ErrorType DoSomething(int mode) {
if(mode==MODE1) {
...
}
else {
return MODE_NOT_AVAILABLE;
}
SomethingElse...
return NO_ERROR;
}
You can see, the return-Statement in the else-Block leads to termination of function DoSomething. So if it´s executed, there is no way for SomethingElse... to be executed.
As I mentioned, this else-block should be in a subactivity.
How do I visualize that an action in a subactivity (return MODE_NOT_AVAILABLE) has the consequence that it´s parental activity diagram has to be in a final state?
In the following picture you can see my try to solve it. Is this a correct solution?
Since you are dealing with some kind of exception, I'd model it with an exception handler like you see here http://www.sparxsystems.com.au/images/screenshots/uml2_tutorial/ad11.GIF. Even though your concrete implementation uses if/else, that should be a way which makes it easy to understand what you want to achieve (prevent the subroutine from being executed in wrong mode).
You can see more details about the notation here: http://edn.embarcadero.com/article/30169
It depends on how much you want to dictate the actual implementation. UML itself is langage-unaware, and so are most stakeholders.

Can I "jump around" in an XMLStreamWriter's output stream

I just have this question around the Stax XMLStreamWriter. Best explained by example:
Say I need to produce a document somehow like this:
<buddies>
<buddies name="tim"/>
<buddies name="toady"/>
</buddies>
, where the tim and toady guys are created by some callback that receives the XMLStreamWriter as an argument.
writer.writeElement("buddies");
callback1.writeBuddies(writer);
callback2.writeBuddies(writer);
write.writeEndElement();
Now the thing is, the whole document must conform to a schema that states: If there's a <buddies> element, there must be at least one <buddy> inside, so if none of my callbacks write anything on the stream I'd have an empty element which is invalid. Question is: Can I delay the writeElement("buddies") somehow like this:
// Pseudocode
Mark mark = writer.getPos()
boolean written = callback1.writeBuddies(writer)
written |= callback2.writeBuddies(writer)
if (written){
writer.writeStartElement(mark, "buddies") // write at mark
writer.writeStopElement() // write at the end of stream
}
Or am I completely off the track?
StAX is a forward only streaming API. To achieve what you are asking is a potential requirement for DOM parser where you construct the node "buddies" separately and attach it to the main document if it is not empty.

Modifying the last element of an array in MongoDB

I have an object structure like this:
{
name: "...",
pockets: [
{
cdate: "....",
items: [...]
}
...
]
}
In an update operation, I want to add some records into the items field of the last pocket item. Using dot notation is the only way that I know to access a sub document, but I can't get what I want. So, I'm looking for something like these:
pockets.-1.items
pockets.$last.items
Is it possible to modify the last element? If yes, how?
I don't know of a way to do this using a single-line query. But you could select the record, update and then save it.
var query = <insert query here>;
var mydocs = db.mycollection.find(query);
for (var i=0 ; i<mydocs.length ; i++) {
mydocs[i].pockets[pockets.length-1].items.push('new item');
db.mycollection.save(mydoc);
}
I don't believe it is possible to do it atomically. There is a request for this functionality to be added to MongoDB.
If you can assure thread-safety in your application code, you could probably use a sequence of $pop from pockets array (that removes the last element from pockets) to variable p and then $addToSet to p.items, now you can $push p back into pockets. But if your application doesn't have a way to assure only one process may be doing this at one time, then another process could modify the array in the middle of those steps and you may end up losing that update.
You might also look into "Update if current" semantics here to see another way you can work around possible race by multiple threads issue.

Resources