Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

no-network handler

  • Loading branch information...
commit 2c1af78b2086b9cbcba451e0d2d6126673855e98 1 parent d5da671
@dakkar authored
Showing with 73 additions and 8 deletions.
  1. +13 −8 lib/Plack/Handler/Stomp.pm
  2. +60 −0 lib/Plack/Handler/Stomp/NoNetwork.pm
View
21 lib/Plack/Handler/Stomp.pm
@@ -134,14 +134,7 @@ sub run {
$self->connect();
$self->subscribe();
- FRAME_LOOP:
- while (1) {
- my $frame = $self->connection->receive_frame();
- $self->handle_stomp_frame($app, $frame);
-
- Plack::Handler::Stomp::Exceptions::OneShot->throw()
- if $self->one_shot;
- }
+ $self->frame_loop($app);
} catch {
$exception = $_;
};
@@ -166,6 +159,18 @@ sub run {
}
}
+sub frame_loop {
+ my ($self,$app) = @_;
+
+ while (1) {
+ my $frame = $self->connection->receive_frame();
+ $self->handle_stomp_frame($app, $frame);
+
+ Plack::Handler::Stomp::Exceptions::OneShot->throw()
+ if $self->one_shot;
+ }
+}
+
=method C<handle_stomp_frame>
Delegates the handling to L</handle_stomp_message>,
View
60 lib/Plack/Handler/Stomp/NoNetwork.pm
@@ -0,0 +1,60 @@
+package Plack::Handler::Stomp::NoNetwork;
+use Moose;
+use namespace::autoclean;
+use Try::Tiny;
+use File::ChangeNotify;
+use Net::Stomp::MooseHelpers::ReadTrace;
+extends 'Plack::Handler::Stomp';
+
+with 'Net::Stomp::MooseHelpers::TraceOnly';
+
+has file_watcher => (
+ is => 'ro',
+ isa => 'File::ChangeNotify::Watcher',
+ lazy_build => 1,
+);
+sub _build_file_watcher {
+ my ($self) = @_;
+
+ return File::ChangeNotify->instantiate_watcher(
+ directories => [ $self->trace_basedir->stringify ],
+ filter => qr{^\d+\.\d+-send-},
+ );
+}
+
+has frame_reader => (
+ is => 'ro',
+ lazy_build => 1,
+);
+sub _build_frame_reader {
+ my ($self) = @_;
+
+ return Net::Stomp::MooseHelpers::ReadTrace->new({
+ trace_basedir => $self->trace_basedir,
+ });
+}
+
+sub frame_loop {
+ my ($self,$app) = @_;
+
+ while (1) {
+ my @events = $self->file_watcher->wait_for_events();
+ for my $event (@events) {
+ next unless $event->type eq 'create';
+ next unless -f $event->path;
+ my $frame = $self->frame_reader
+ ->read_frame_from_filename($event->path);
+
+ $frame->command('MESSAGE') if $frame->command eq 'SEND';
+
+ $self->handle_stomp_frame($app, $frame);
+
+ Plack::Handler::Stomp::Exceptions::OneShot->throw()
+ if $self->one_shot;
+ }
+ }
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
Please sign in to comment.
Something went wrong with that request. Please try again.