blob: 4b43e015d9aff156057277a89ef0515eca7392f0 [file] [log] [blame]
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
var vanadium = require('vanadium');
var defineClass = require('./util/define-class');
var GroupManager = defineClass({
publics: {
createSyncGroup: function(name, prefixes) {
var self = this;
return this.prereq.then(function() {
var sg = self.syncbaseWrapper.syncGroup(self.sgAdmin, name);
var spec = sg.buildSpec(
prefixes,
[self.name('sgmt', name)]
);
/* TODO(rosswang): Right now, duplicate SyncBase creates on
* different SyncBase instances results in siloed SyncGroups.
* Revisit this logic once it merges properly. */
return sg.joinOrCreate(spec);
});
}
},
init: function(vanadiumWrapper, syncbaseWrapper, mountNames) {
this.syncbaseWrapper = syncbaseWrapper;
this.name = function() {
var parts = [mountNames.app];
Array.prototype.push.apply(parts, arguments);
return vanadium.naming.join(parts);
};
this.sgAdmin = this.name('sgadmin');
/* TODO(rosswang): Once Vanadium supports global sync-group admin
* creation, remove this. For now, use the first local SyncBase
* instance to administrate. */
this.prereq = vanadiumWrapper.mount(this.sgAdmin, syncbaseWrapper.mountName,
vanadiumWrapper.multiMount.FAIL);
}
});
module.exports = GroupManager;