npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yuna

v1.2.3

Published

Extra zookeeper support for Illyria.

Downloads

22

Readme

Yuna (ユウナ)

The extra Zookeeper support for Illyria client pool.

NPM TravisCI Status Coverage Status David Status

Yuna

Installation

$ npm install --save yuna

Yuna is a summoner embarking on a journey to defeat the world-threatening monster Sin. And in this project, she will summon multiple connections of illyria to defeat the instability of servers.

Usage

Create

First of all, you should create a new Yuna object.

var Yuna = require("yuna");
var yuna = Yuna.createPool(ZOOKEEPER_CONNECT_STRING, ZOOKEEPER_ROOT, ZOOKEEPER_PREFIX, OPTIONS);

Attention: all of the params above in Yuna.createPool are optional.

The parameters and their default value are shown below.

| Parameter | Default | Description | |------------------------------|-----------------|--------------------------------------------------------------------------------------| | ZOOKEEPER_CONNECT_STRING | "127.0.0.1" | The connect string for zookeeper. | | ZOOKEEPER_ROOT | "/illyria" | The root path for the certain server nodes. | | ZOOKEEPER_PREFIX | "/HB_" | The prefix for the certain server nodes. | | OPTIONS | [object Object] | The options for this pool. | | OPTIONS.maxPool | 10 | The maximum client count in the pool. | | OPTIONS.runTimeout | 10000 | Timeout for one sending operation in million second. (not including retry) | | OPTIONS.connectTimeout | 5000 | Timeout for the connecting to the server in million second. | | OPTIONS.retryForGetting | 5 | Times of retry for getting a usable connection. | | OPTIONS.gettingRetryInterval | 200 | Interval for retry of getting a usable connection. | | OPTIONS.zookeeper | {} | Refer to Illyria document. | | OPTIONS.? | - | Refer to io.js document. |

Tip: don't include connectString, root and prefix in option OPTIONS.zookeeper because it will be replaced by ZOOKEEPER_CONNECT_STRING, ZOOKEEPER_ROOT and ZOOKEEPER_PREFIX.

Send

The main method you should use in your program is Yuna::send. The parameters are the same as Illyria Client.

yuna.send("module", "method", DATA, function(err, data, conn) {
    // `conn` is the current connection
    console.log(err, data, conn);
});

Cast

Using cast protocol to send the message. Reference to Illyria Client.

yuna.cast("module", "method", DATA, function(err, data, conn) {
    // `conn` is the current connection
    // and data will always be `undefined`
    console.log(err, data, conn);
});

Destroy

Destroy this Yuna pool and disconnect all the connections.

yuna.destroy();

New Connection

Most time you needn't to use this method. It usually be used by other functions of Yuna like the constructor function.

yuna.newConnection([force], callback);

The optional parameter force is defined to tell the function weather the connection will be created forcely and ignore the maximum connection count of the pool.

The callback function is look like function(err, conn) {}.

Get Connection

Most time you needn't to use this method. This method will return you a usable Illyria connection just now if you really want to do this.

yuna.getConnection(function(err, conn) {
    // DO SOMETHING
});

Available Connection Count

Get current available connection count.

var availables = yuna.availableCount();

Client Position

Most time you needn't to use this method. It will tell the position of the connection you passed in in the connection pool.

var idx = yuna.clientPosition(conn);

Events

new

This event will be emitted when a new connection is set.

yuna.on("new", function() {
    // SOME CODE...
});

error

This event will be emitted when a connection has an error. (But Yuna will reconnect automatically)

yuna.on("error", function() {
    // SOME CODE...
});

close

This event will be emitted when a connection is disconnected.

yuna.on("close", function() {
    // SOME CODE...
});

Contribution

You're welcome to make pull requests.

「雖然我覺得不怎麼可能有人會關注我」