Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ged/cztop-reactor
An implementation of the Reactor pattern for ZeroMQ sockets (git mirror)
https://github.com/ged/cztop-reactor
async async-programming czmq cztop reactor ruby socket-io zeromq
Last synced: about 1 month ago
JSON representation
An implementation of the Reactor pattern for ZeroMQ sockets (git mirror)
- Host: GitHub
- URL: https://github.com/ged/cztop-reactor
- Owner: ged
- License: mit
- Created: 2017-03-16T22:37:56.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-31T23:06:52.000Z (over 6 years ago)
- Last Synced: 2024-10-31T01:42:14.210Z (3 months ago)
- Topics: async, async-programming, czmq, cztop, reactor, ruby, socket-io, zeromq
- Language: Ruby
- Homepage: https://bitbucket.org/ged/cztop-reactor
- Size: 110 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# CZTop-Reactor
home
: http://deveiate.org/projects/CZTop-Reactorcode
: http://bitbucket.org/ged/cztop-reactorgithub
: https://github.com/ged/cztop-reactordocs
: http://deveiate.org/code/cztop-reactor## Description
This is an implementation of the Reactor pattern described in [Pattern-Oriented
Software Architecture (Volume 2)][POSA2]. It allows an asynchronous application
to be described as one or more "reactions" to events, in this case either I/O
conditions on a ZMQ socket or a timer expiring.A simple example:
# Start a SERVER socket, and print out any messages sent to it
reactor = CZTop::Reactor.new
socket = CZTop::Socket::SERVER.new
socket.bind( 'tcp://0.0.0.0:8' )
reactor.register( socket, :read ) do |event|
if event.readable?
message = event.socket.receive
puts "Read: %p" % [ message.to_a ]
end
end
reactor.start_polling## Prerequisites
It should run under any Ruby interpreter that CZTop will, which at the time of
this writing includes:* MRI (2.3, 2.2)
* Rubinius (HEAD)
* JRuby 9000 (HEAD)I am also using it (and CZTop) under MRI 2.4.
## Installation
$ gem install cztop-reactor
## Reasons
I considered submitting this as a patch to `cztop`, but in the end elected to
distribute it as a gem for two reasons:1. It depends on the `timers` gem, and I didn't want to add this dependency to
`cztop`. If the [`ztimerset`][ztimerset] spec ever comes out of draft status
and `cztop` adds an implementation of it, this wouldn't be necessary.
2. I'm not confident enough in my FFI knowledge to know if this is an
appropriate way to implement this class. I've written numerous C extensions
for Ruby, but FFI is still a bit of a mystery to me, and likely will remain
so for the foreseeable future given my misgivings about using it.## Contributing
You can check out the current development source with Mercurial via its
{project page}[http://bitbucket.org/ged/cztop-reactor]. Or if you prefer Git,
via {its Github mirror}[https://github.com/ged/cztop-reactor].After checking out the source, run:
$ rake newb
This task will install any missing dependencies, run the tests/specs,
and generate the API documentation.## License
This library includes source from the CZTop gem by Patrik Wenger, which is
distributed under the terms of the [ISC
License](http://opensource.org/licenses/ISC):> Copyright (c) 2016, Patrik Wenger
>
> Permission to use, copy, modify, and/or distribute this software for
> any purpose with or without fee is hereby granted, provided that
> the above copyright notice and this permission notice appear in all
> copies.
>
> THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
> WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
> WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
> AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
> DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
> OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
> TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
> PERFORMANCE OF THIS SOFTWARE.Everything else is distributed under the same license but is:
Copyright (c) 2017, Michael Granger
[POSA2]: http://www.cs.wustl.edu/~schmidt/POSA/POSA2/
[ztimerset]: http://czmq.zeromq.org/czmq4-0:ztimerset