# Process Registry Handler

Getting Started | API | Elements | Actions | Validators | Handlers | Configuration Options | About

## Table of Contents

- 1 Process Registry Handler

## 1 Process Registry Handler

The process registry handler is a simple key-value store specifically for storing and retrieving Erlang Pids from Keys. It's primary uses are in session tracking and in tracking Pids for comet. The default nitrogen process registry is based around nprocreg, which connects and synchronizes Nitrogen nodes' process registries together.

### Behavior Functions

##### `init(Config, State)`

Initialize the Process Registry handler

- Return Value - `{ok, NewState}`

##### `finish(Config, State)`

Clean up the Process Registry handler

- Return Value - `{ok, NewState}`

##### `get_pid(Key, Config, State)`

Returns a Pid from the provided `Key`.

- `Key` - Any erlang term to use as a key. For the session handler, Nitrogen uses the SessionID, while for the comet functions, Nitrogen uses the comet pool ID, or a timer Pid. The point is, `Key` can be just about anything.
- Return Value - `{ok, Pid, NewState}`. If `Key` is not found, then `Pid` will be `undefined`.

##### `get_pid(Key, Function, Config, State)`

Returns a Pid from the provided `Key`.

- `Key` - Same as above.
- `Function` - If `Key` is not found, the process registry should spawn off a new process using the provided `Function` (which should have arity of 0), then return the pid of the newly spawned process.
- Return Value - `{ok, Pid, NewState}`. If `Key` is not found, then `Pid` will be the Pid of the newly spawned process based on `Function`.

### Example

Here is the complete text of the default process registry handler (nprocreg_process_registry), which is very simple.

    -module (nprocreg_registry_handler).
    -behaviour (process_registry_handler).
    -include_lib ("wf.hrl").
    -export ([
        init/2,
        finish/2,
        get_pid/3,
        get_pid/4
    ]).

    init(_Config, State) ->
        {ok, State}.

    finish(_Config, State) ->
        {ok, State}.

    get_pid(Key, _Config, State) ->
        Pid = nprocreg:get_pid(Key),
        {ok, Pid, State}.

    get_pid(Key, Function, _Config, State) ->
        Pid = nprocreg:get_pid(Key, Function),
        {ok, Pid, State}.

### See Also

- Handler Overview

Date: 2012-10-18 03:24:23 CDT

Author: Jesse Gumm (@jessegumm)

Org version 7.8.02 with Emacs version 23

Validate XHTML 1.0

## Comments

Note:To specify code blocks, just use the generic code block syntax:

    <pre><code>your code here</code></pre>

comments powered by Disqus