Logs for the RingoJS IRC channel, as logged by ringostarr.

2011-05-31

[08:25] <rrmckinley> Anyone familiar with sync(…, lock)?

[09:37] <rrmckinley> What is a good way to supply properties to Java? SomeClass.java: new SomeClass( SomeKindOfRingJSProperties.get("my.settings.something") );?

[09:38] <rrmckinley> Should be: new SomeClass( SomeKindOfRingoJSProperties.get("my.settings.something") );?

[10:08] <rrmckinley> oberhamsi: i'm looking at your use of sql/store in ositestats. Can you help me with a threading question?

[10:24] <oberhamsi> rrmckinley: uh, maybe... what's the question?

[10:27] <rrmckinley> oberhamsi: I see that you use var {store} = require('./config'); repeatedly to get the store object. I need to do the same with a sort of db connection pool, but the object will need to have a synchronized method.

[10:28] <rrmckinley> var {dbConext} = require("./configdb");

[10:29] <oberhamsi> okay

[10:29] <rrmckinley> followed by.

[10:30] <rrmckinley> exports.index = function(req) { var db = dbContext.getDb(); db.doStuff('foo'); }

[10:31] <rrmckinley> getDb would be synchronized.

[10:32] <oberhamsi> that should just work. i disabled module reloading on production system just in case.

[10:32] <oberhamsi> are you afraid it's not thread safe or does it fail?

[10:33] <rrmckinley> if I did it in Java the method would be: public static synchronized Database getDb() { return db; }

[10:33] <oberhamsi> okay, well you have to wrap the method in sync() where you define it

[10:33] <oberhamsi> var getDb = sync(function() ...

[10:34] <rrmckinley> I'd like to know what to put in my configdb.js.

[10:34] <rrmckinley> Right, ok. Where should var lock = new java.langObject() live?

[10:35] <oberhamsi> if you don't provide a lock object then it will sync on `this`

[10:35] <oberhamsi> put the lock into configdb.js

[10:35] <rrmckinley> What is this in that case?

[10:35] <oberhamsi> can't say without seeing the code :)

[10:36] <oberhamsi> rrmckinley: okay sync(function, lock). so: var lock = {}; sync(function(){}

[10:36] <oberhamsi> , lock);

[10:37] <oberhamsi> the only thing i sync in my ositestats code is the HitQueue in actions.js, maybe take a look

[10:37] <oberhamsi> if i talk to the database, the database code has to deal with threading and i don't notice.

[10:38] <rrmckinley> I'm thinking:

[10:39] <rrmckinley> var DbContext = function(path) {

[10:39] <rrmckinley> var lock = new java.lang.Object();

[10:39] <oberhamsi> pastebin.com or gist.github.com ?

[10:39] <oberhamsi> much easier

[10:39] <rrmckinley> k

[10:42] <oberhamsi> brb

[10:55] <rrmckinley> oberhamsi: https://gist.github.com/e02489e4244eebf287c6

[11:02] <tom_i> hannesw_: when I run a clean install of Ringo using ringo main.js I receive the following…

[11:02] <tom_i> Cannot find module 'config' (ringo/jsgi/connector.js#27)

[11:04] <tom_i> I last pulled from git about -12 hrs

[11:07] <rrmckinley> tom_i: I had a problem and pulled more recently. Could be unrelated, but works fine now.

[11:11] <tom_i> rrmckinley: great, I’ll try

[11:11] <rrmckinley> tom_i: hey, the problem's back for me. bin/ringo-admin, Cannot find module 'admin' tools/admin/main.js:23

[11:14] <tom_i> still receive the same error

[11:16] <rrmckinley> var description = require(res.moduleName).description;

[11:16] <rrmckinley> That would place the blame on require

[11:18] <rrmckinley> RingoGlobal.java#156

[11:26] <rrmckinley> tom_i: this is good. Deleting the repo and cloning it again makes it fine. I did that a few hours ago, but something messed it up again.

[11:28] <rrmckinley> it is also bad because that is strange voodoo.

[12:28] <tom_i> rrmckinley: cloning again worked, thx

[12:29] <tom_i> I wonder the reason why?

[12:44] <tom_i> where has config.js disappeared? or am I missing something?

[12:44] <oberhamsi> rrmckinley: looks good, but this would only make access to the method getDb() threadsafe

[12:46] <rrmckinley> Isn't 'new' threadsafe? The other members are private, no?

[12:47] <oberhamsi> that came out wrong. it looks good.

[12:49] <oberhamsi> re: update problems. did you guys try `ant clean jar`?

[12:50] <oberhamsi> bin/ringo-admin works for me

[12:51] <rrmckinley> No, but I can't imagine what was wrong. I only installed stick and opened a bunch of ringo files in MacVim. I should have dug deeper. If it returns I will. It could have been a resource bug exposed by vim swap files.

[12:52] <rrmckinley> something.js.swp, you know. Bad pattern matching in require.

[12:59] <oberhamsi> hm, weird

[13:12] <rrmckinley> Is there a concept of init(), start(), stop(), destroy() for packages? Would it be safe to require httpserver.js or daemon.js in my package main and get those functions called?

[13:27] <hannesw> rrmckinley: not for packages in general

[13:27] <hannesw> these are called by the debian start script only

[13:28] <rrmckinley> How can jars in a package be loaded before they are needed?

[13:29] <rrmckinley> That is what I am trying to solve.

[13:29] <hannesw> these days you have to load them manually, i.e. addToClasspath(module.resolve("../xyz.jar"))

[13:29] <hannesw> they used to be added automatically

[13:31] <rrmckinley> Yes, I am using this https://gist.github.com/1c32e5768113fc8645e2 in my main.js#exports.init(). Looking for a better home for it.

[13:34] <rrmckinley> I suppose I will call it when I use the package:

[13:35] <rrmckinley> var dbContext = new require("some-db").DbContext("data/db1");

[13:37] <rrmckinley> I'll load the jars inside of DbContext(path) { … }. Does that sound good? Only one DbContext should be created per runtime so the jars will only be loaded once.

[13:45] <hannesw> i think new require("...").Ctor() will not work, as the new is applied to require(), not Ctor()

[13:46] <hannesw> I think the best is just to add jar files to the classpath at the beginning of the main module

[13:47] <hannesw> like here: https://github.com/hns/ringo-cometd/blob/master/lib/cometd.js

[13:48] <rrmckinley> Thanks for the advice on new...

[13:49] <hannesw> that's a silly gotcha

[13:49] <hannesw> doesn't act as you'd expect

[13:52] <rrmckinley> Do you see any problems with this as a package main? https://gist.github.com/e9567c099c3e45cc3233

[13:53] <rrmckinley> Am I threadsafe ready?

[13:55] <oberhamsi> wrt threads. maybe it's confusing what exactly ringo does when you require()?

[13:56] <oberhamsi> it will only execute the module once (your `for each` will only run once) if you disable module reloading (imo you should disable it in production)

[13:58] <oberhamsi> and this is true: require('foo') === require('foo'); require() always returns the one module object

[14:03] <rrmckinley> bummer, require('db') always runs before the package can add jars. Even in 'new'. I don't want to inflict jar management onto the web app main.js.

[14:04] <rrmckinley> Oh, perhaps not! Package missing!

[14:09] <hannesw> rrmckinley: 'db' is your module or package?

[14:09] <rrmckinley> OK, Packages sorted, but there is still the problem that you cannot require until jars are loaded.

[14:10] <rrmckinley> db is my package.

[14:10] <rrmckinley> That is a placeholder name

[14:10] <hannesw> are you using standard ringo command line, or some special embedding (e.g. servlet container)?

[14:11] <hannesw> adding to classpath should make jar immediately available

[14:11] <hannesw> just make sure to restart, java package access caches missing packages

[14:12] <hannesw> so you can't access a java package/class after you accessed it when it was missing

[14:12] <hannesw> even if it was added to the classpath in the meantime

[14:12] <hannesw> maybe that's the problem?

[14:12] <rrmckinley> You are right, i'm missing something.

[14:13] <rrmckinley> What is my path to a package jars folder? I'm using getRepository("./jars").getResources(true)

[14:13] <rrmckinley> That is top level in package main.

[14:14] <rrmckinley> Yes, I'm using bin/ringo main.js only and restarting everytime.

[14:15] <rrmckinley> Is "./jars" wrong for package work?

[14:16] <rrmckinley> Ah, I see from your previous link. I am in lib/vendor/db/db.js. I'll need some ../../..

[14:24] <rrmckinley> Something is caching in ringo. I'm getting an error on a line that I have commented out in my package main. This is odd.

[14:28] <rrmckinley> OK, I got it all sorted. Thanks for your help!

[14:29] <rrmckinley> File management problems at the end there.

[19:12] <rrmckinley> Is anyone able to get stop() destroy() working in 0.8? init() and start() work, but not the others.

[22:15] <hannesw> rrmckinley: they're only called with the init script (ringojs-daemon debian package)