Integrating Command Line Programs with Java Clients - PowerPoint PPT Presentation

About This Presentation
Title:

Integrating Command Line Programs with Java Clients

Description:

Access the suite of command line utilities from a standalone application. ... Fakes a terminal device that reads from and writes to the command line program. ... – PowerPoint PPT presentation

Number of Views:48
Avg rating:3.0/5.0
Slides: 13
Provided by: wfis
Learn more at: https://w3.pppl.gov
Category:

less

Transcript and Presenter's Notes

Title: Integrating Command Line Programs with Java Clients


1
Integrating Command Line Programs with Java
Clients
  • Will Fisher
  • PPPL Summer Intern
  • Science Education Program
  • August 11th, 2005

2
Motivation
  • What did we want out of a command line system?
  • Access the suite of command line utilities from a
    standalone application.
  • Preserve the functionality and performance.
  • Minimize changes to the programs.
  • Editing the programs was not an option.
  • Must capture their output and feed them input.
  • Add graphical user interface to the command line.
  • Java is a good language to use for the client
    application given its portability.
  • Ultimate goal Java client ?? command line
    program.

3
Issues with Standard I/O
  • Buffering
  • Causes problems for reading and writing data as
    needed.
  • Java API does not work well, directly, with
    terminal applications because of buffering.
  • Java communication, apparently, has no such
    issues as client/servlet communication is handled
    fully and completely by the Java system.

4
PTY Implementation
  • Pseudo-terminals
  • Special interprocess communication channel that
    acts like a terminal.
  • One end is called the master, the other end is
    called the slave.
  • Data written to the master is received by the
    slave as if it were the result of a user typing
    at an ordinary terminal.
  • Data written to the slave is sent to the master
    as if it were written on an ordinary terminal.
  • Our use of them
  • Used for communication with the command line
    program.
  • Fakes a terminal device that reads from and
    writes to the command line program.
  • Set terminal attributes in order to kill the
    buffering and the echoing.

5
CLTerm Technology Solution
  • Forking the program
  • Use the forkpty() command to fork CLTerm into two
    processes.
  • The two processes are connected via a
    master-slave pseudo-terminal.
  • The child process replaces its own program image
    with the image of the command line program by
    calling the subroutine execl(program).
  • The new program thinks its running normally but
    is connected to a pseudo-terminal.
  • The parent monitors the output and feeds input to
    the child.
  • Java client ? ? CLTerm ? ? Command Line Program

6
System Architecture
User Computers
Franks Computer
Alices Computer
Bobs Computer
Java Client 1
Java Client 3
Java Applet
Java Client 2
The Network Chasm

Transpgrid PPPL Cluster
clterm
genxpl
HTTP Servlet
clterm
rplot
clterm
trxpl
clterm
rplot
7
The Servlet
  • Servlet complements Java applet / application
  • Applet has limited sandbox on users computer
  • Servlet runs on cluster http connection to
    client
  • Run programs
  • Access user files
  • Enforce security
  • Added 2 methods
  • Runcl start a new clterm session
  • Inputcl send a line of user input to clterm

8
CLTerm.c
  • How it works
  • One instance of CLTerm is launched for each
    client.
  • Each instance connects to one command line
    program.
  • It forks a new child process which in turn
    launches the program in its place.
  • They talk via a pseudo-terminal and CLTerm
    forwards the output to the servlet and feeds the
    data it gets from the servlet into the child via
    the pseudo-terminal.
  • CLTerm checks each iteration of its I/O loop,
    that the child is still alive. If not then it
    sends an exit byte down the line.

9
CLPanel.java
  • How it works
  • CLPanel inherits from JPanel and can be
    implemented in either a JFrame or a
    JInternalFrame like in ElVis.
  • Has all the communication and GUI code.
  • Has an I/O loop that first reads the users input
    and then looks for the programs response, sent
    via the servlet.
  • If the user closes the CLPanel window, it will
    send an exit byte (ASCII code 25) down the line
    so that everything else is informed.

10
CLTerm In Action
11
Conclusion
  • End result and advantages
  • Successfully integrated a solution for Java
    clients to talk to command line programs.
  • Minimal changes to the existing infrastructure.
  • CLTerm is appropriate for larger applications
    given its encapsulated nature.
  • CLPanel lets Java developers incorporate this
    panel into their own applications.
  • CLPanel is a class which can be instantiated
    multiple times in the same application multiple
    windows/connections in the same app.
  • Can also run as an Applet in a browser.
  • Opportunity to expand PPL Fusion Grid Services.

12
CLTerm Demo!
Write a Comment
User Comments (0)
About PowerShow.com