COMMUNICATION  entre un OUTPUTPIPE et un INPUTPIPE

 INTER-PEER  
COMMUNICATION (IPC)


 Un site très bien pour apprendre le JXTA Shell :  

http://www-106.ibm.com/developerworks/java/library/j-p2pint2/

ETAPES:

1- Création d'un pipe adverstisement.
2- Création d'un InputPipe basé sur cet adverstisement.
3- Démarrer un nouveau shell .
4- Dans le nouveau shell on crée un output pipe basé sur le meme advertisement.
5- Dans le nouveau shell, on crée un message.
6- Dans le nouveau shell, on met dans l'objet shell Message, on met le contenu d'un fichier.
7- Mettre le premier shell en attente d'un message.
8- Dans le nouveau shell, envoyer le message du output pipe vers le input pipe.


// newpipe permet de créer un nouveau pipeAdvertisement avec un id généré aléatoirement.
Ce pipe est de type UnicastPipe  par défaut.  

 JXTA>pipeadv = newpipe -n nompipe
 

  JXTA>env
 stdin = Default InputPipe (class net.jxta.impl.shell.ShellInputPipe)
 PG@worldgroup = World Peer Group (class net.jxta.impl.peergroup.PeerGroupInterface)
 SHELL = Root Shell (class net.jxta.impl.shell.bin.Shell.Shell)
 History = History (class net.jxta.impl.shell.bin.history.HistoryQueue)
 Shell = Root Shell (class net.jxta.impl.shell.bin.Shell.Shell)
 PG@netgroup = Network Peer Group (class
 net.jxta.impl.peergroup.RefCountPeerGroupInterface)
 stdout = Default OutputPipe (class net.jxta.impl.shell.ShellOutputPipe)
 consout = Default Console OutputPipe (class net.jxta.impl.shell.ShellOutputPipe)
 consin = Default Console InputPipe (class net.jxta.impl.shell.ShellInputPipe)
 stdgroup = Default Group (class net.jxta.impl.peergroup.RefCountPeerGroupInterface)
 pipeadv = Pipe Advertisement (class net.jxta.impl.protocol.PipeAdv)
 

 JXTA>cat pipeadv

<?xml version="1.0"?>
<!DOCTYPE jxta:PipeAdvertisement>
<jxta:PipeAdvertisement xmlns:jxta="http://jxta.org">
    <Id>
        urn:jxta:uuid-59616261646162614E50472050325033A79CF951DD1C4DEFA287FD1F1A86EAC304
    </Id>
    <Type>
        JxtaUnicast
    </Type>
    <Name>
        nompipe
    </Name>
</jxta:PipeAdvertisement>
 
// Création d'un InputPipe et association avec le pipeadv

  JXTA>inpipe = mkpipe -i pipeadv
 

  JXTA>env
 stdin = Default InputPipe (class net.jxta.impl.shell.ShellInputPipe)
 PG@worldgroup = World Peer Group (class net.jxta.impl.peergroup.PeerGroupInterface)
 SHELL = Root Shell (class net.jxta.impl.shell.bin.Shell.Shell)
 History = History (class net.jxta.impl.shell.bin.history.HistoryQueue)
 Shell = Root Shell (class net.jxta.impl.shell.bin.Shell.Shell)
 PG@netgroup = Network Peer Group (class
 net.jxta.impl.peergroup.RefCountPeerGroupInterface)
 stdout = Default OutputPipe (class net.jxta.impl.shell.ShellOutputPipe)
 consout = Default Console OutputPipe (class net.jxta.impl.shell.ShellOutputPipe)
 consin = Default Console InputPipe (class net.jxta.impl.shell.ShellInputPipe)
 stdgroup = Default Group (class net.jxta.impl.peergroup.RefCountPeerGroupInterface)
 inpipe = InputPipe of pipeadv (class net.jxta.impl.pipe.UnicastInputPipeImpl)
 pipeadv = Pipe Advertisement (class net.jxta.impl.protocol.PipeAdv)
 

 JXTA>cat inpipe
 net.jxta.impl.pipe.UnicastInputPipeImpl@768dc8 // référence de l'input pipe.
 

 JXTA>Shell -s  // Si vous travaillez sur le meme peer(meme répertoire ...voir .jxta ).

// Si 2 peers différents soit sur la meme machine, soit 2 machines différentes doivent posséder le meme pipeadv.


//Dans le premier shell on se met à l'écoute de l'inpipe et le contenu ira dans la variable dwnewmsg

//Mais si on utilise 2 peers différents alors, il faut d'abord publier l'advertisement. (share pipeadv)

 JXTA>dwnewmsg = recv inpipe
 recv has received a message
 JXTA>
 
 
 
 
 

 =========================================================
 ========= Welcome to the JXTA Shell Version 2.2 =========
 =========================================================

 The JXTA Shell provides an interactive environment to the JXTA
 platform. The Shell provides basic commands to discover peers and
 peergroups, to join and resign from peergroups, to create pipes
 between peers, and to send pipe messages. The Shell provides environment
 variables that permit binding symbolic names to Jxta platform objects.
 Environment variables allow Shell commands to exchange data between
 themselves. The shell command 'env' displays all defined environment
 variables in the current Shell session.

 The Shell creates a Jxta InputPipe (stdin) for reading input from
 the keyboard, and a Jxta OutputPipe (stdout) to display information
 on the Shell console. All commands executed by the Shell have their
 initial 'stdin' and 'stdout' set up to the Shell's stdin and stdout pipes.
 The Shell also creates the environment variable 'stdgroup' that
 contains the current JXTA PeerGroup in which the Shell and commands
 are executed.

 A new Shell can be forked within a Shell. The 'Shell -s'
 command starts a new Shell with a new Shell window. The Shell can
 also read a command script file via the 'Shell -f myfile'.
 'Shell -e cmd1;cmd2;cmd3' allows execution of multiple cmds within
 a single command line.

 A 'man' command is available to list the commands available.
 Type 'man <command>' to get help about a particular command.
 To exit the Shell, use the 'exit' command.
 
 
 // Creation d'un OutputPipe et "binding" lien avec le meme pipeadv qui été utilisé coté InputPipe.
// La variable jxta shell dwoutpipe contient la reférence vers ce OutputPipe.

  JXTA>dwoutpipe = mkpipe -o pipeadv

/// Si sur 2 peers différents
//
JXTA>dwoutpipe = mkpipe -o pipeadv
//cat: cannot access pipeadv
//JXTA>
//  
//  Pourquoi ne peut-on pas obtenir  le pipeadv ?

// Rep:1- La variable pipeadv n'est partagée par les 2 peers .
//        
2- Il faut que celui qui crée le pipeadv le publie sur le réseau
//             JXTANet.

// Pour publier le pipe advertisment la commande share pipeadv doit //  //etre utilisée.

//Sur l'autre peer la commade search -r doit etre utilisé.

JXTA>env
dwoutpipe = OutputPipe of pipeadv (class net.jxta.impl.pipe.NonBlockingOutputPipe)
stdin = Default InputPipe (class net.jxta.impl.shell.ShellInputPipe)
PG@worldgroup = World Peer Group (class net.jxta.impl.peergroup.PeerGroupInterface)
SHELL = Root Shell (class net.jxta.impl.shell.bin.Shell.Shell)
History = History (class net.jxta.impl.shell.bin.history.HistoryQueue)
parentShell = Root Shell (class net.jxta.impl.shell.bin.Shell.Shell)
Shell = Root Shell (class net.jxta.impl.shell.bin.Shell.Shell)
PG@netgroup = Network Peer Group (class net.jxta.impl.peergroup.RefCountPeerGroupInterface)
stdout = Default OutputPipe (class net.jxta.impl.shell.ShellOutputPipe)
consout = Default Console OutputPipe (class net.jxta.impl.shell.ShellOutputPipe)
consin = Default Console InputPipe (class net.jxta.impl.shell.ShellInputPipe)
stdgroup = Default Group (class net.jxta.impl.peergroup.RefCountPeerGroupInterface)
inpipe = InputPipe of pipeadv (class net.jxta.impl.pipe.UnicastInputPipeImpl)
pipeadv = Pipe Advertisement (class net.jxta.impl.protocol.PipeAdv)

 JXTA>cat dwoutpipe
net.jxta.impl.pipe.NonBlockingOutputPipe@1b31c23

  JXTA>dwmsg = mkmsg

JXTA>env
dwoutpipe = OutputPipe of pipeadv (class net.jxta.impl.pipe.NonBlockingOutputPipe)
stdin = Default InputPipe (class net.jxta.impl.shell.ShellInputPipe)
PG@worldgroup = World Peer Group (class net.jxta.impl.peergroup.PeerGroupInterface)
SHELL = Root Shell (class net.jxta.impl.shell.bin.Shell.Shell)
History = History (class net.jxta.impl.shell.bin.history.HistoryQueue)
parentShell = Root Shell (class net.jxta.impl.shell.bin.Shell.Shell)
Shell = Root Shell (class net.jxta.impl.shell.bin.Shell.Shell)
dwmsg = Message (class net.jxta.endpoint.Message)
PG@netgroup = Network Peer Group (class net.jxta.impl.peergroup.RefCountPeerGroupInterface)
stdout = Default OutputPipe (class net.jxta.impl.shell.ShellOutputPipe)
consout = Default Console OutputPipe (class net.jxta.impl.shell.ShellOutputPipe)
consin = Default Console InputPipe (class net.jxta.impl.shell.ShellInputPipe)
stdgroup = Default Group (class net.jxta.impl.peergroup.RefCountPeerGroupInterface)
inpipe = InputPipe of pipeadv (class net.jxta.impl.pipe.UnicastInputPipeImpl)
pipeadv = Pipe Advertisement (class net.jxta.impl.protocol.PipeAdv)

 JXTA>importfile -f  /etudiants/deptinfo/k/kouad_k0/rmipdf.txt dwData

JXTA>env
dwoutpipe = OutputPipe of pipeadv (class net.jxta.impl.pipe.NonBlockingOutputPipe)
dwData = StructuredDocument (class net.jxta.impl.document.LiteXMLDocument)
stdin = Default InputPipe (class net.jxta.impl.shell.ShellInputPipe)
PG@worldgroup = World Peer Group (class net.jxta.impl.peergroup.PeerGroupInterface)
SHELL = Root Shell (class net.jxta.impl.shell.bin.Shell.Shell)
History = History (class net.jxta.impl.shell.bin.history.HistoryQueue)
parentShell = Root Shell (class net.jxta.impl.shell.bin.Shell.Shell)
Shell = Root Shell (class net.jxta.impl.shell.bin.Shell.Shell)
dwmsg = Message (class net.jxta.endpoint.Message)
PG@netgroup = Network Peer Group (class net.jxta.impl.peergroup.RefCountPeerGroupInterface)
stdout = Default OutputPipe (class net.jxta.impl.shell.ShellOutputPipe)
consout = Default Console OutputPipe (class net.jxta.impl.shell.ShellOutputPipe)
consin = Default Console InputPipe (class net.jxta.impl.shell.ShellInputPipe)
stdgroup = Default Group (class net.jxta.impl.peergroup.RefCountPeerGroupInterface)
inpipe = InputPipe of pipeadv (class net.jxta.impl.pipe.UnicastInputPipeImpl)
pipeadv = Pipe Advertisement (class net.jxta.impl.protocol.PipeAdv)


JXTA>cat dwData

<?xml version="1.0"?>
<ShellDoc>
    <Item>
       
RMI
Le gestionnaire de régistre dans RMI est NAMING. C'est en utilisant
les API de RMI ( Naming.lookup() que client obtient l'adresse complète
de localisation de l'objet distant et qu'il arrive à se connceter au serveur
pour invoquer les méthodes des objets distants.

    </Item>
</ShellDoc>
JXTA>

  JXTA>put dwmsg dwtag dwData
 

 JXTA>cat dwmsg

 JXTA>env
 dwoutpipe = OutputPipe of pipeadv (class net.jxta.impl.pipe.NonBlockingOutputPipe)
 dwData = StructuredDocument (class net.jxta.impl.document.LiteXMLDocument)
 stdin = Default InputPipe (class net.jxta.impl.shell.ShellInputPipe)
 PG@worldgroup = World Peer Group (class net.jxta.impl.peergroup.PeerGroupInterface)
 SHELL = Root Shell (class net.jxta.impl.shell.bin.Shell.Shell)
 History = History (class net.jxta.impl.shell.bin.history.HistoryQueue)
 parentShell = Root Shell (class net.jxta.impl.shell.bin.Shell.Shell)
 Shell = Root Shell (class net.jxta.impl.shell.bin.Shell.Shell)
 dwmsg = Message (class net.jxta.endpoint.Message)
 PG@netgroup = Network Peer Group (class
 net.jxta.impl.peergroup.RefCountPeerGroupInterface)
 stdout = Default OutputPipe (class net.jxta.impl.shell.ShellOutputPipe)
 consout = Default Console OutputPipe (class net.jxta.impl.shell.ShellOutputPipe)
 consin = Default Console InputPipe (class net.jxta.impl.shell.ShellInputPipe)
 stdgroup = Default Group (class net.jxta.impl.peergroup.RefCountPeerGroupInterface)
 inpipe = InputPipe of pipeadv (class net.jxta.impl.pipe.UnicastInputPipeImpl)
 pipeadv = Pipe Advertisement (class net.jxta.impl.protocol.PipeAdv)

// Envoi du message a partir du OutputPipe vers le InputPipe  les deux sont liés au meme pipeAdv

 JXTA>send dwoutpipe dwmsg
 

// Revenons au premier shell  :
JXTA1>Shell -s
JXTA1>dwnewmsg = recv inpipe
recv has received a message
JXTA1>

JXTA1>env
stdin = Default InputPipe (class net.jxta.impl.shell.ShellInputPipe)
PG@worldgroup = World Peer Group (class net.jxta.impl.peergroup.PeerGroupInterface)
SHELL = Root Shell (class net.jxta.impl.shell.bin.Shell.Shell)
History = History (class net.jxta.impl.shell.bin.history.HistoryQueue)
Shell = Root Shell (class net.jxta.impl.shell.bin.Shell.Shell)
env1 = Child Shell (class net.jxta.impl.shell.bin.Shell.Shell)
PG@netgroup = Network Peer Group (class net.jxta.impl.peergroup.RefCountPeerGroupInterface)
stdout = Default OutputPipe (class net.jxta.impl.shell.ShellOutputPipe)
consout = Default Console OutputPipe (class net.jxta.impl.shell.ShellOutputPipe)
dwnewmsg = Message from  inpipe (class net.jxta.endpoint.Message)
consin = Default Console InputPipe (class net.jxta.impl.shell.ShellInputPipe)
stdgroup = Default Group (class net.jxta.impl.peergroup.RefCountPeerGroupInterface)
inpipe = InputPipe of pipeadv (class net.jxta.impl.pipe.UnicastInputPipeImpl)
pipeadv = Pipe Advertisement (class net.jxta.impl.protocol.PipeAdv)
JXTA1>

JXTA1>cat dwnewmsg  
// Si vous voulez voir le contenu : JXTA>vard = get dwmsg dwtag
// JXTA>cat vard
JXTA1>


JXTA1>dwnewfile = get dwnewmsg dwtag

JXTA1>cat dwnewfile 

JXTA1> exportfile  -f  recu.txt  dwnewfile