Re: Adding a listener to an input pipe

"Leandro Quiroga" <[email protected]> Fri, 29 Dec 2006 14:46:41 -0300
Newsgroups gmane.comp.java.jxta.user
Message-ID <[email protected]>
------=_NextPart_000_006F_01C72B58.26D729A0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

But, what you can do is adding an indirection level creating a value =
holder class that implements the listener interface.
Something like this (I don't remember the exact class names),

   PipeMsgListener listener =3D new ValueHolderListener();
=20
   myInputPipe =3D pipeService.createInputPipe(pipeAdv, listener);
   .....
   .....=20

When you want to add the listener, just:
   listener.setListener(new YourListener());

The ValueHolderListener class delegates the listen method to your =
listener.

I hope this could help

Leandro

  ----- Original Message -----=20
  From: Ashutosh Adkar=20
  To: [email protected]=20
  Sent: Friday, December 29, 2006 2:34 PM
  Subject: Re: [JXTA user] Adding a listener to an input pipe


  Okay.Maybe it wont.
  BTW Hugo why do you want to add the listener later?I mean whats wrong =
with assigning it as it is...


  On 12/29/06, Leandro Quiroga < [email protected]> wrote:
    Hi, this would not work, because Java uses reference by value =
parameters passing.
    Happy new year!!

    Leandro

      ----- Original Message -----=20
      From: Ashutosh Adkar=20
      To: [email protected]=20
      Sent: Friday, December 29, 2006 12:58 AM
      Subject: Re: [JXTA user] Adding a listener to an input pipe


      Funny.I thought there was method like =
myInputPipe.addListener(....).But I just check the docs and there isn't =
one.I think one way to get around this is is to pass a null reference to =
a listener and then assign that reference to a live object when you want =
to assign a listener to that pipe.=20
      Something like this,

         PipeMsgListener listener =3D null;
      =20
         myInputPipe =3D pipeService.createInputPipe(pipeAdv,listener);
         .....
         .....=20
         listener =3D new PipeMsgListener() {
         ....
         ....=20
         };
        =20
         Think this should work though ... :-P



      On 12/27/06, Hugo Giusti <[email protected] > wrote:=20
        Hi everyone,


        I've been using myInputPipe =3D pipeService.createInputPipe =
(pipeAdv,listener) to create an input pipe and add a listener to it but =
I was wondering if there is a way to create the pipe and add the =
listener later, can anyone tell me how to do this?

        Thanks in advance.
        Hugo=20




        __________________________________________________
        Correo Yahoo!
        Espacio para todos tus mensajes, antivirus y antispam =A1gratis!
        =A1Abr=ED tu cuenta ya! - http://correo.yahoo.com.ar=20

        =
---------------------------------------------------------------------
        To unsubscribe, e-mail: [email protected]
        For additional commands, e-mail: [email protected]






------=_NextPart_000_006F_01C72B58.26D729A0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.3020" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>But, what you can do is adding an =
indirection level=20
creating a value holder class that implements the listener=20
interface.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2><FONT face=3D"Times New Roman" =
size=3D3>Something like=20
this (I don't remember the exact class names),<BR><BR>&nbsp;&nbsp;=20
PipeMsgListener listener =3D new =
ValueHolderListener();<BR>&nbsp;<BR>&nbsp;&nbsp;=20
myInputPipe =3D pipeService.createInputPipe(pipeAdv, =
listener);<BR>&nbsp;&nbsp;=20
....<BR>&nbsp;&nbsp; ..... <BR></FONT></FONT><FONT face=3DArial=20
size=3D2></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>When you want to add the listener,=20
just:</FONT></DIV>
<DIV>&nbsp;&nbsp; listener.setListener(new YourListener());</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>The ValueHolderListener class delegates =
the listen=20
method to your listener.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I hope this could help</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Leandro</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<BLOCKQUOTE=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A [email protected] =
href=3D"mailto:[email protected]">Ashutosh=20
  Adkar</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A [email protected]=20
  href=3D"mailto:[email protected]">[email protected]</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Friday, December 29, 2006 =
2:34=20
  PM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Re: [JXTA user] Adding =
a=20
  listener to an input pipe</DIV>
  <DIV><BR></DIV>Okay.Maybe it wont.<BR>BTW Hugo why do you want to add =
the=20
  listener later?I mean whats wrong with assigning it as it =
is...<BR><BR>
  <DIV><SPAN class=3Dgmail_quote>On 12/29/06, <B =
class=3Dgmail_sendername>Leandro=20
  Quiroga</B> &lt; <A=20
  href=3D"mailto:[email protected]">[email protected]</A>&gt; =
wrote:</SPAN>
  <BLOCKQUOTE class=3Dgmail_quote=20
  style=3D"PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: =
rgb(204,204,204) 1px solid">
    <DIV bgcolor=3D"#ffffff">
    <DIV><FONT face=3DArial size=3D2>Hi, this would not work, because =
Java uses=20
    reference by value parameters passing.</FONT></DIV>
    <DIV><FONT face=3DArial size=3D2>Happy new year!!</FONT></DIV><SPAN =
class=3Dsg>
    <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
    <DIV><FONT face=3DArial size=3D2>Leandro</FONT></DIV></SPAN>
    <DIV><SPAN class=3De id=3Dq_10fced7fd0f5ec55_2>
    <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
    <BLOCKQUOTE=20
    style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: rgb(0,0,0) 2px solid; MARGIN-RIGHT: 0px">
      <DIV=20
      style=3D"FONT: 10pt arial; font-size-adjust: none; font-stretch: =
normal">-----=20
      Original Message ----- </DIV>
      <DIV=20
      style=3D"BACKGROUND: rgb(228,228,228) 0% 50%; FONT: 10pt arial; =
font-size-adjust: none; font-stretch: normal; moz-background-clip: =
-moz-initial; moz-background-origin: -moz-initial; =
moz-background-inline-policy: -moz-initial"><B>From:</B>=20
      <A [email protected]=20
      onclick=3D"return top.js.OpenExtLink(window,event,this)"=20
      href=3D"mailto:[email protected]" target=3D_blank>Ashutosh =
Adkar</A> </DIV>
      <DIV=20
      style=3D"FONT: 10pt arial; font-size-adjust: none; font-stretch: =
normal"><B>To:</B>=20
      <A [email protected]=20
      onclick=3D"return top.js.OpenExtLink(window,event,this)"=20
      href=3D"mailto:[email protected]" target=3D_blank>[email protected]</A> =
</DIV>
      <DIV=20
      style=3D"FONT: 10pt arial; font-size-adjust: none; font-stretch: =
normal"><B>Sent:</B>=20
      Friday, December 29, 2006 12:58 AM</DIV>
      <DIV=20
      style=3D"FONT: 10pt arial; font-size-adjust: none; font-stretch: =
normal"><B>Subject:</B>=20
      Re: [JXTA user] Adding a listener to an input pipe</DIV>
      <DIV><BR></DIV>Funny.I thought there was method like=20
      myInputPipe.addListener(....).But I just check the docs and there =
isn't=20
      one.I think one way to get around this is is to pass a null =
reference to a=20
      listener and then assign that reference to a live object when you =
want to=20
      assign a listener to that pipe. <BR>Something like=20
      this,<BR><BR>&nbsp;&nbsp; PipeMsgListener listener =3D=20
      null;<BR>&nbsp;<BR>&nbsp;&nbsp; myInputPipe =3D=20
      pipeService.createInputPipe(pipeAdv,listener);<BR>&nbsp;&nbsp;=20
      .....<BR>&nbsp;&nbsp; ..... <BR>&nbsp;&nbsp; listener =3D new=20
      PipeMsgListener() {<BR>&nbsp;&nbsp; ....<BR>&nbsp;&nbsp; ....=20
      <BR>&nbsp;&nbsp; };<BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp; Think this =
should=20
      work though ... :-P<BR><BR><BR>
      <DIV><SPAN class=3Dgmail_quote>On 12/27/06, <B =
class=3Dgmail_sendername>Hugo=20
      Giusti</B> &lt;<A onclick=3D"return =
top.js.OpenExtLink(window,event,this)"=20
      href=3D"mailto:[email protected]"=20
      target=3D_blank>[email protected] </A>&gt; wrote:</SPAN>=20
      <BLOCKQUOTE class=3Dgmail_quote=20
      style=3D"PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; =
BORDER-LEFT: rgb(204,204,204) 1px solid">Hi=20
        everyone,<BR><BR><BR>I've been using myInputPipe =3D=20
        pipeService.createInputPipe (pipeAdv,listener) to create an =
input pipe=20
        and add a listener to it but I was wondering if there is a way =
to create=20
        the pipe and add the listener later, can anyone tell me how to =
do=20
        this?<BR><BR>Thanks in advance.<BR>Hugo=20
        =
<BR><BR><BR><BR><BR>__________________________________________________<BR=
>Correo=20
        Yahoo!<BR>Espacio para todos tus mensajes, antivirus y antispam=20
        =A1gratis!<BR>=A1Abr=ED tu cuenta ya! - <A=20
        onclick=3D"return top.js.OpenExtLink(window,event,this)"=20
        href=3D"http://correo.yahoo.com.ar"=20
        target=3D_blank>http://correo.yahoo.com.ar=20
        =
</A><BR><BR>-------------------------------------------------------------=
--------<BR>To=20
        unsubscribe, e-mail: <A=20
        onclick=3D"return top.js.OpenExtLink(window,event,this)"=20
        href=3D"mailto:[email protected]"=20
        target=3D_blank>[email protected]</A><BR>For additional =
commands,=20
        e-mail: <A onclick=3D"return =
top.js.OpenExtLink(window,event,this)"=20
        href=3D"mailto:[email protected]"=20
        =
target=3D_blank>[email protected]</A><BR><BR></BLOCKQUOTE></DIV><BR></BL=
OCKQUOTE></SPAN></DIV></DIV></BLOCKQUOTE></DIV><BR></BLOCKQUOTE></BODY></=
HTML>

------=_NextPart_000_006F_01C72B58.26D729A0--