How to use thywill - 10 common examples

To help you get started, we’ve selected a few thywill examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github exratione / thywill / test / lib / tools.js View on Github external
var childProcess = require('child_process');
var path = require('path');
var http = require('http');
var async = require('async');
var vows = require('vows');
var assert = require('assert');
var clone = require('clone');
var express = require('express');
var redis = require('redis');
var Client = require('work-already').Client;
var MemorySocketStore = require('socket.io/lib/stores/memory');
var RedisSocketStore = require('socket.io/lib/stores/redis');
var RedisSessionStore = require('connect-redis')(express);
var MemorySessionStore = require('connect/lib/middleware/session/memory');
var Thywill = require('thywill');
var Message = Thywill.getBaseClass('Message');


// ------------------------------------------------------------
// Relating to setting up headless Thywill instances without
// applications running in this process.
// ------------------------------------------------------------

exports.headless = {};

/**
 * Utility function to create a client for a local Redis server.
 * @return {object}
 *   A Redis client.
 */
function createRedisClient () {
  var options = {};
github exratione / thywill / test / lib / echo.js View on Github external
/**
 * @fileOverview
 * Batches for testing the Echo example application.
 */

var assert = require("assert");
var Thywill = require("thywill");
var Message = Thywill.getBaseClass("Message");
var tools = require("./tools");

/**
 * Add general tests for the Echo application to the suite.
 */
exports.general = function (suite) {
  var instanceIndex = 0;
  var applicationIndex = 0;
  // The initial batches load the application page and then connect via
  // Socket.IO. The matches are checked against the page contents. Here
  // we're looking at the templates that should be included.
  var pageMatches = [
    "<button>{{buttonText}}</button>",
    '<div class="echoed-message">{{data}}</div>'
  ];
  tools.workAlready.addInitialBatches(suite, instanceIndex, pageMatches);
github exratione / thywill / test / lib / calculations.js View on Github external
/**
 * @fileOverview
 * Batches for testing the Calculations example application.
 */

var assert = require("assert");
var Thywill = require("thywill");
var Message = Thywill.getBaseClass("Message");
var RpcCapableApplication = Thywill.getBaseClass("RpcCapableApplication");
var tools = require("./tools");

/**
 * Add general tests for the Calculations application to the suite.
 */
exports.general = function (suite) {
  var instanceIndex = 0;
  var applicationIndex = 0;
  // The initial batches load the application page and then connect via
  // Socket.IO. The matches are checked against the page contents. Here
  // we're looking at the templates that should be included.
  var pageMatches = [
    '<div id="calculations-wrapper">'
  ];
  tools.workAlready.addInitialBatches(suite, instanceIndex, pageMatches);</div>
github exratione / thywill / core / lib / component / cluster / cluster.js View on Github external
* });
 *
 * thywill.cluster.on(thywill.cluster.eventNames.CLUSTER_MEMBER_UP, function (data) {
 *   console.log('Cluster process up: ' + data.clusterMemberId);
 * });
 *
 */
function Cluster() {
  Cluster.super_.call(this);
  this.componentType = 'cluster';

  // Useful shortcuts.
  this.clusterMemberStatus = Cluster.CLUSTER_MEMBER_STATUS;
  this.eventNames = Cluster.EVENT_NAMES;
}
util.inherits(Cluster, Thywill.getBaseClass('Component'));
var p = Cluster.prototype;

//-----------------------------------------------------------
// 'Static' parameters
//-----------------------------------------------------------

Cluster.EVENT_NAMES = {
  CLUSTER_MEMBER_DOWN: 'thywill.cluster.down',
  CLUSTER_MEMBER_UP: 'thywill.cluster.up'
};

Cluster.CLUSTER_MEMBER_STATUS = {
  DOWN: false,
  UNKNOWN: undefined,
  UP: true
};
github exratione / thywill / extra / lib / component / clientTracker / inMemoryClientTracker.js View on Github external
/**
 * @fileOverview
 * InMemoryClientTracker class definition.
 */

var util = require('util');
var Thywill = require('thywill');
var Client = Thywill.getBaseClass('Client');

//-----------------------------------------------------------
// Class Definition
//-----------------------------------------------------------

/**
 * @class
 * A ClientTracker implementation that stores all data in memory. Every cluster
 * member process keeps an up to date record of client connections to all
 * cluster processes.
 *
 * Obviously this doesn't scale as well as other implementations to large
 * numbers of cluster member processes - there is a lot of cross-talk needed
 * between cluster members to keep the data updated in all of them. It is best
 * used when your applications must make very frequent requests to ClientTracker
 * methods.
github exratione / thywill / extra / lib / component / clientTracker / clientTracker.js View on Github external
* Emit when a client disconnects from this or any other cluster member.
 * clientTracker.on(clientTracker.events.CONNECTION_TO, function (clusterMemberId, client {});
 *
 * Emit on disconnection of a client to this cluster member.
 * clientTracker.on(clientTracker.events.DISCONNECTION, function (client) {});
 *
 * Emit when a client disconnects from this or any other cluster member.
 * clientTracker.on(clientTracker.events.DISCONNECTION_FROM, function (clusterMemberId, client) {});
 */
function ClientTracker() {
  ClientTracker.super_.call(this);
  this.componentType = 'clientTracker';
  // Convenience reference.
  this.events = ClientTracker.EVENTS;
}
util.inherits(ClientTracker, Thywill.getBaseClass('Component'));
var p = ClientTracker.prototype;

//-----------------------------------------------------------
// 'Static'
//-----------------------------------------------------------

ClientTracker.EVENTS = {
  CONNECTION: 'connection',
  CONNECTION_TO: 'connectionTo',
  DISCONNECTION: 'disconnection',
  DISCONNECTION_FROM: 'disconnectionFrom',
  CLUSTER_MEMBER_DOWN: 'clusterMemberDown'
};

//-----------------------------------------------------------
// Methods
github exratione / thywill / extra / lib / component / channelManager / channelManager.js View on Github external
* A channelManager implementation must emit the following events, which
 * require integration with the cluster communication mechanisms.
 *
 * Sessions are added to a channel in any process in the cluster.
 * channelManager.on(channelManager.events.SESSIONS_ADDED, function (channelId, sessionIds) {});
 *
 * Sessions are removed from a channel in any process in the cluster.
 * channelManager.on(channelManager.events.SESSIONS_REMOVED, function (channelId, sessionIds) {});
 */
function ChannelManager() {
  ChannelManager.super_.call(this);
  this.componentType = 'channelManager';
  // Convenience reference.
  this.events = ChannelManager.EVENTS;
}
util.inherits(ChannelManager, Thywill.getBaseClass('Component'));
var p = ChannelManager.prototype;

//-----------------------------------------------------------
// 'Static'
//-----------------------------------------------------------

ChannelManager.EVENTS = {
  SESSIONS_ADDED: 'sessionsAdded',
  SESSIONS_REMOVED: 'sessionsRemoved'
};

//-----------------------------------------------------------
// Methods
//-----------------------------------------------------------

/**
github exratione / thywill / core / lib / component / templateEngine / templateEngine.js View on Github external
var util = require('util');
var Thywill = require('thywill');

//-----------------------------------------------------------
// Class Definition
//-----------------------------------------------------------

/**
 * @class
 * The superclass for interfaces to templating systems.
 */
function TemplateEngine() {
  TemplateEngine.super_.call(this);
  this.componentType = 'templateEngine';
}
util.inherits(TemplateEngine, Thywill.getBaseClass('Component'));
var p = TemplateEngine.prototype;

//-----------------------------------------------------------
// Methods.
//-----------------------------------------------------------

/**
 * @see Component#_getDependencies
 */
p._getDependencies = function () {
  return {
    components: [
      'log'
    ]
  };
};
github exratione / thywill / extra / lib / component / channelManager / redisChannelManager.js View on Github external
* A channel manager that stores channel information in Redis.
 *
 * It maintains lookup sets for each channel and each session that belongs to
 * at least one channel.
 *
 * This implementation requires that a clientTracker implementation is used.
 *
 * TODO: mechanisms for clearing out old sessions?
 *
 * @see ChannelManager
 */
function RedisChannelManager() {
  RedisChannelManager.super_.call(this);
  this.channels = {};
}
util.inherits(RedisChannelManager, Thywill.getBaseClass('ChannelManager'));
var p = RedisChannelManager.prototype;

//-----------------------------------------------------------
// 'Static' parameters
//-----------------------------------------------------------

RedisChannelManager.CONFIG_TEMPLATE = {
  redisPrefix: {
    _configInfo: {
      description: 'A prefix applied to Redis keys.',
      types: 'string',
      required: true
    }
  },
  redisClient: {
    _configInfo: {
github exratione / thywill / core / lib / component / messageManager / simpleMessageManager.js View on Github external
var Thywill = require("thywill");
var Message = require("./message");

//-----------------------------------------------------------
// Class Definition
//-----------------------------------------------------------

/**
 * @class
 * A trivial synchronous in-memory resource manager.
 */
function SimpleMessageManager () {
  SimpleMessageManager.super_.call(this);
  this.data = {};
}
util.inherits(SimpleMessageManager, Thywill.getBaseClass("MessageManager"));
var p = SimpleMessageManager.prototype;

//-----------------------------------------------------------
// "Static" parameters
//-----------------------------------------------------------

SimpleMessageManager.CONFIG_TEMPLATE = null;

//-----------------------------------------------------------
// Methods
//-----------------------------------------------------------

/**
 * @see MessageManager#createMessage
 */
p.createMessage = function (data, metadata) {

thywill

A Node.js clustered framework for single page web applications based on asynchronous messaging.

MIT
Latest version published 11 years ago

Package Health Score

36 / 100
Full package analysis

Popular thywill functions

Similar packages