Two Google_Client objects in the same script - google-mirror-api

I'm trying to create two Google_MirrorService objects on the same script: one to send a timeline card to one user and other to update other user timeline card. The problem is that when I create those objects, I have to use two different Google_Client objects. When I create the second Google_Client object, then the first Google_MirrorService get broken. After trying to discover what's happening, I discover that Google_Client uses static vars (static $auth, static $io, static $cache and static $useBatch). I think that the problem because second Google_Client object overwrites those static vars on first object.
Can anyone help me?
Thanks kindly

Related

Oozie: pass parameter via separate file

I'm experimenting with the loop 'hack' to iterate the same workflow over a list of of values and I am trying to load that list at run-time.
The list contains a number of files that I would like to process and so this list will change every time.
In the example the value is passed via the job.properties file and I can also pass it in the workflow itself as a key/value pair but than the values are hard-coded in my workflow and I would like to prevent that (as the list will change every time).
I found a similar question:
OOZIE: properties defined in file referenced in global job-xml not visible in workflow.xml
and the answer there explains also my initial mistakes (parameters vs properties) where I tried to pass it via a global job.xml file (which is only for properties and not for parameters) but a good solution is not provided.
One solution would be to read the parameter from a file via a shell action and capturing the output but I think there could be a more elegant way of reading this parameter in my workflow?

How to safely associate data to factory array while still seeing automatic updates from factory in Angular?

Lets say I have an angular factory responsible for loading all Foos from the backend, and intermittently polls and updates foos. Everyone uses my FooFactory to reference Foo objects so they get updates when foo data changes.
In one directive I would like to associate some information with a foo object, lets say sorting information for what order someone wishes to list some child element of foo in a table.
At first glance it would be easy to set foo.sort="blah" on each foo object to store this data. However, this would change the foo objects shared by everyone, if someone in some other directive also did the same thing to store their table sorting data we would keep changing the others data, not good.
I could instead clone the foo object, then add my sort to the cloned object. However, now my foo is different then the one in the FooFactory. If FooFactory polls my backend and gets updated data my cloned foo will not see it, this is bad for me.
I could of course either keep a separate map of Foo objects to sort data, or some use of broadcast to keep my cloned foo objects up to date with fooFactory. This works, but takes some small effort to implement every where I want to associate data.
I'm wondering if angular already has a more convenient means of doing this. Is there some syntax that will allow me to 'clone' an object, so that data I add to the clone will not affect the original object, but still ensure the object is automatically updated when the original 'cloned' object is? basically to Alias all the existing data of an object but ensure new data appended to it is only appended to my copy of the object?

onSync Event and its properties

Hello People of Stackoverflow, I am using a persistent SharedObject for Adobe Media Server to store and share date in real-time for multiple clients. I am using the SyncEvent to dispatch any event that has been updated.
Reading through the documerntation the SyncEvent contains numerous properties. What i want to achieve is to use remote shared object to store a list of people who are online when one client disconnects all the other clients listed will be updated of the disconnection.
Adobe docs unfortunately doesnt provide any examples how to do this.
Would the best approach be to create a changeList array that contains properties of all members then execute a loop?
Or can anyone suggest any other method?
Thanks
The changelist property of the event contains only the properties that got changed. So, if your shared object contains the list of ids, you should be able to get what you achieve.
Note, that the notification is done for the top level properties stored in the shared object. So, what you want would probably look like:
idSo.setProperty("1", true);
while adding. To remove the user, you should use:
idSo.setProperty("1", null);
To reassert, having
idSo.setProperty("ids", <array of ids>)
would send the whole array when it's updated. So, this would be a bad approach
This sync event would be sent to all the connected shared objects.

Grails - Where to store properties related to domains

This is something I have been struggling about for some time now. The thing is: I have many (20 or so) static arrays of values. I say static because that is how I'm actually storing them, as static arrays inside some domains. For example, if I have a list of known websites, I do:
class Website {
...
static websites = ["web1", "web2" ...]
}
But I do this just while developing, because I can easily change the arrays if needed, but what I'm going to do when the application is ready for deployment? In my project it is very probable that, at some point, these arrays of values change. I've been researching on that matter, one can store application properties inside an external .properties file, but it will be impossible to store an array, even futile, because if some array gets an additional value, the application can't recognize it until the name of the new property is added where needed.
Another approach is to store this information in the database, but for some reason it seems like a waste to add 20 or more tables that will have just two rows, an id and a name.
And the last option, as far as I know, would be an XML, but I'm not very experienced with those. It seems groovy has a way of creating and reading XML files relatively easy, but I don't know how difficult would be to modify an XML whose layout is predefined in the application.
Needless to say that storing them in the config.groovy is not an option since any change will require to recompile.
I haven't come across some "standard" (maybe a best practice?) way of dealing with these.
So the questions is: Where to store these arrays?
Use Enum for a fixed set of attributes. Do this, if you rely at some places in your code on some concrete values.
If you do not rely on the attributes within your code (which you obviously don't), use a String-type. In this case, if you need to provide a select box, just do a distinct-query on this property in your database.
Default: Use a domain class per dynamic set of attributes. Another table is OK.
For something as simple as arrays you should use groovy own type of property files. They allow you too define properties as proper groovy variables (not just strings) and obviously loading them would be done dinamically in a simple way by using ConfigSlurper. For an example on how to use this kind of file you can have a look at the following ConfigSlurper:
For defining properties:
my.property.array=[1,2,3,4]
For loading property files:
def config = new ConfigSlurper().parse(new File('myconfig.groovy').toURL())
assert [1,2,3,4] == config.my.property.array
Tip: When you want to access the property files you want to do it in a way that can work for any environment. To make paths environment-independent use the following path as the root path:
import org.codehaus.groovy.grails.commons.ApplicationHolder
def ctx = ApplicationHolder.application.mainContext.servletContext
def rootPath = ctx.contextPath

SSRS Code Shared Variables and Simultaneous Report Execution

We have some SSRS reports that are failing when two of them are executed very close together.
I've found out that if two instances of an SSRS report run at the same time, any Code variables declared at the class level (not inside a function) can collide. I suspect this may be the cause of our report failures and I'm working up a potential fix.
The reason we're using the Code portion of SSRS at all is for things like custom group and page header calculation. The code is called from expressions in TextBoxes and returns what the current label should be. The code needs to maintain state to remember what the last header value was in order return it when unknown or to store the new header value for reuse.
Note: here are my resources for the variable collision problem:
The MSDN SSRS Forum:
Because this uses static variables, if two people run the report at the exact same
moment, there's a slim chance one will smash the other's variable state (In SQL 2000,
this could occasionally happen due to two users paginating through the same report at
the same time, not just due to exactly simultaneous executions). If you need to be 100%
certain to avoid this, you can make each of the shared variables a hash table based on
user ID (Globals!UserID).
Embedded Code in Reporting Services:
... if multiple users are executing the report with this code at the same time, both
reports will be changing the same Count field (that is why it is a shared field). You
don’t want to debug these sorts of interactions – stick to shared functions using only
local variables (variables passed ByVal or declared in the function body).
I guess the idea is that on the report generation server, the report is loaded and the Code module is a static class. If a second clients ask for the same report as another quickly enough, it connects to the same instance of that static class. (You're welcome to correct my description if I'm getting this wrong.)
So, I was proceeding with the idea of using a hash table to keep things isolated. I was planning on the hash key being an internal report parameter called InstanceID with default =Guid.NewGuid().ToString().
Part way through my research into this, though, I found that it is even more complicated because Hashtables aren't thread-safe, according to Maintaining State in Reporting Services.
That writer has code similar to what I was developing, only the whole thread-safe thing is completely outside my experience. It's going to take me hours to research all this and put together sensible code that I can be confident of and that performs well.
So before I go too much farther, I'm wondering if anyone else has already been down this path and could give me some advice. Here's the code I have so far:
Private Shared Data As New System.Collections.Hashtable()
Public Shared Function Initialize() As String
If Not Data.ContainsKey(Parameters!InstanceID.Value) Then
Data.Add(Parameters!InstanceID.Value, New System.Collections.Hashtable())
End If
LetValue("SomethingCount", 0)
Return ""
End Function
Private Shared Function GetValue(ByVal Name As String) As Object
Return Data.Item(Parameters!InstanceID.Value).Item(Name)
End Function
Private Shared Sub LetValue(ByVal Name As String, ByVal Value As Object)
Dim V As System.Collections.Hashtable = Data.Item(Parameters!InstanceID.Value)
If Not V.ContainsKey(Name) Then
V.Add(Name, Value)
Else
V.Item(Name) = Value
End If
End Sub
Public Shared Function SomethingCount() As Long
SomethingCount = GetValue("SomethingCount") + 1
LetValue("SomethingCount", SomethingCount)
End Function
My biggest concern here is thread safety. I might be able to figure out the rest of the questions below, but I am not experienced with this and I know it is an area that it is EASY to go wrong in. The link above uses the method Dim _sht as System.Collections.Hashtable = System.Collections.Hashtable.Synchronized(_hashtable). Is that best? What about Mutex? Semaphore? I have no experience in this.
I think the namespace System.Collections for Hashtable is correct, but I'm having trouble adding System.Collections as a reference in my report to try to cure my current error of "Could not load file or assembly 'System.Collections'". When I browse to add the reference, it's not an available component to select.
I just confirmed that I can call code from a parameter's default value expression, so I'll put my Initialize code there. I also just found out about the OnInit procedure, but this has its own gotchas to research and work around: the Parameters collection may not be referenced from the OnInit method during parameter initialization.
I'm unsure about declaring the Data variable as New, perhaps it should be only be instantiated in the initializer if not already done (but I worry about race conditions because of the delay between the check that it's empty and the instantiation of it).
I also have a question about the Shared keyword. Is it necessary in all cases? I get errors if I leave it off function declarations, but it appears to work when I leave it off the variable declaration. Testing multiple simultaneous report executions is difficult... Could someone explain what Shared means specifically in the context of SSRS Code?
Is there a better way to initialize variables? Should I provide a second parameter to the GetValue function which is the default value to use if it finds that the variable doesn't exist in the hashtable yet?
Is it better to have nested Hashtables as I chose in my implementation, or to concatenate my InstanceID with the variable name to have a flat hashtable?
I'd really appreciate guidance, ideas and/or critiques on any aspect of what I've presented here.
Thank you!
Erik
Your code looks fine. For thread safety only the root (shared) hashtable Data needs to be synchronised. If you want to avoid using your InstanceID you could use Globals.ExecutionTime and User.UserID concatenated.
Basically I think you just want to change to initialize like this:
Private Shared Data As System.Collections.Hashtable
If Data Is Nothing Then
Set Data = Hashtable.Synchronized(New System.Collections.Hashtable())
End If
The contained hashtables should only be used by one thread at a time anyway, but if in doubt, you could synchronize them too.

Resources