For Programmers: Free Programming Magazines  


Home > Archive > PERL POE > January 2007 > Proper way to access HEAP variables between Sessions









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Proper way to access HEAP variables between Sessions
jeff.konz@thomson.com

2007-01-12, 7:16 pm

Hello,

I am trying to capture counts of the lines seen on a
POE::Component::Client::TCP session at three different intervals.

POE::Session->create
(inline_states =>
{
_start => \&init,
_stop => \&shutdown,
Timer_10 => \&count_sec,
Timer_60 => \&count_min,
Timer_3600 => \&count_hour,
p_input => \&count_seen,
}
);

POE::Component::Client::TCP->new (
RemoteAddress => "emporia.int.westgroup.net",
RemotePort => "55075",
ServerInput => \&srv_input,
Disconnected => \&discon,
);


$poe_kernel->run();
exit 0;

sub init {

my ($session,$heap) = @_[SESSION, HEAP];

$heap->{int_session} = $session;
$heap->{cnt_10} = 0;
$heap->{cnt_60} = 0;
$heap->{cnt_3600} = 0;
$heap->{iter_10} = 0;
$heap->{iter_60} = 0;
$heap->{iter_3600} = 0;


$_[KERNEL]->delay ('Timer_10', 10);
$_[KERNEL]->delay ('Timer_60', 60);
$_[KERNEL]->delay ('Timer_3600', 3600);

}

sub srv_input {

$heap->{cnt_10}++;
$heap->{cnt_60}++;
$heap->{cnt_3600}++;
print SYSINFO $input . "\n";
}

sub count_sec {

my ($session,$heap) = @_[SESSION, HEAP];

$_[KERNEL]->delay('Timer_10', 10);
my $sec_count = $heap->{cnt_10};
my $sec_iter = $heap->{iter_10};
print POETLOG "10 Second Iteration: $sec_iter Count: $sec_count\n";
$heap->{cnt_10} = 0;
$heap->{iter_10}++;

}

svr_input is updating the heap that belongs to the PoCo, I would like to
update the heap from the session that controls the timers.

So there are two ways to do it, update a the timer heap from the PoCo,
or access the PoCo heap information from the timer session. I know
getting the information is the better way, but I can not figure out how
to access the ifromation.

Can someone give me a clue?

Thanks,

Jeff
Jeff Konz
Thomson Legal & Regulatory
Technical Services - EMAT
651.687.5090


Rocco Caputo

2007-01-12, 7:16 pm

On Jan 12, 2007, at 13:58, <jeff.konz@thomson.com> wrote:

> Hello,
>
> I am trying to capture counts of the lines seen on a
> POE::Component::Client::TCP session at three different intervals.


....

> svr_input is updating the heap that belongs to the PoCo, I would
> like to
> update the heap from the session that controls the timers.
>
> So there are two ways to do it, update a the timer heap from the PoCo,
> or access the PoCo heap information from the timer session. I know
> getting the information is the better way, but I can not figure out
> how
> to access the ifromation.


A third way: Put the accumulators in a scope shared by both sessions.

my $cnt_10 = 0;
my $cnt_60 = 0;
my $cnt_3600 = 0;

my $iter_10 = 0;
my $iter_60 = 0;
my $iter_3600 = 0;

....

> sub srv_input {

$cnt_10++;
$cnt_60++;
$cnt_3600++;
> print SYSINFO $input . "\n";
> }
>
> sub count_sec {
> my ($session,$heap) = @_[SESSION, HEAP];
>
> $_[KERNEL]->delay('Timer_10', 10);

print POETLOG "10 Second Iteration: $iter_10 Count: $cnt_10\n";
$cnt_10 = 0;
$iter_10++;
> }


.... etc.

--
Rocco Caputo - rcaputo@pobox.com


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com