SlideShare a Scribd company logo
1 of 22
Download to read offline
Posh: an OSGi Shell
         RFC132 in action!
                    Derek Baum
                  Paremus Limited
Posh OSGi Shell   Copyright © 2009 Paremus Limited. All rights reserved.   June 2009
The (Draft) Specification




Posh OSGi Shell   Copyright © 2009 Paremus Limited. All rights reserved.   June 2009
RFC132: Problem Description
No standard way for user to interact with an
 OSGi-based system.
• Different commands for common tasks
     – install, start, stop, status
• Different API to add commands
     – Commands are not reusable
• No script support



Posh OSGi Shell   Copyright © 2009 Paremus Limited. All rights reserved.   June 2009
Equinox & Felix Shells
$ java -jar org.eclipse.osgi_3.4.3.R34x_v20081215-1030.jar
$ java -jar org.eclipse.osgi_3.4.3.R34x_v20081215-1030.jar -console
osgi> ss
Framework is launched.
id State       Bundle
0 ACTIVE       org.eclipse.osgi_3.4.3.R34x_v20081215-1030
osgi> ^D$

$ java -jar bin/felix.jar
-> ss
Command not found.
-> ps
START LEVEL 1
    ID   State         Level Name
[    0] [Active    ] [     0] System Bundle (1.8.0)
[    1] [Active    ] [     1] Apache Felix Shell Service (1.2.0)
[    2] [Active    ] [     1] Apache Felix Shell TUI (1.2.0)
[    3] [Active    ] [     1] Apache Felix Bundle Repository (1.4.0)
-> ^DShellTUI: No standard input...exiting.
^C$
 Posh OSGi Shell    Copyright © 2009 Paremus Limited. All rights reserved.   June 2009
Hello, Equinox
import org.eclipse.osgi.framework.console.CommandInterpreter;
import org.eclipse.osgi.framework.console.CommandProvider;

public class Commands implements CommandProvider {

    public void _hello(CommandInterpreter ci) {
      ci.print("Hello, " + ci.nextArgument());
    }

    public String getHelp() {
      return "thello - say hellon";
    }
}




    Posh OSGi Shell   Copyright © 2009 Paremus Limited. All rights reserved.   June 2009
Hello, Felix
import org.apache.felix.shell.Command;

public class HelloCommand implements Command {

    public void execute(String s, PrintStream out, PrintStream err) {
      String[] args = s.split(“s+”);

        if (args.length < 2) {
          err.println(“Usage: ” + getUsage());
        }
        else {
          out.println(“Hello, “ + args[1]);
        }
    }

    public String getName() { return "hello";}
    public String getUsage() { return "hello name";}
    public String getShortDescription() { return "say hello";}
}


    Posh OSGi Shell     Copyright © 2009 Paremus Limited. All rights reserved.   June 2009
Hello, RFC132
public class Commands {

    public boolean hello(String name) {
      System.out.println(“Hello, “ + name);
      return name != null;
    }

}




    Posh OSGi Shell   Copyright © 2009 Paremus Limited. All rights reserved.   June 2009
RFC132 Command Interface
• Simple & lightweight to add commands
          – Promotes adding commands in any bundle

• Access to input and output streams
• Shared session state between commands
• Small (core runtime < 50Kb)




Posh OSGi Shell    Copyright © 2009 Paremus Limited. All rights reserved.   June 2009
Architecture
                      Console                 Telnet                 ...
                      Session                Session               Session



                                        CommandProvider


                     CommandSessionImpl                                 ThreadIO

                                         CommandSession
                                                        command providers
              Converter                                 scope=xxx, function=yyy


                      Basic                  Basic                    ...
                   Conversions             Commands                Commands



Posh OSGi Shell           Copyright © 2009 Paremus Limited. All rights reserved.   June 2009
CommandProcessor
package org.osgi.service.command;

public interface CommandProcessor {
    CommandSession createSession(InputStream in, PrintStream out,
     PrintStream err);
}




    Posh OSGi Shell   Copyright © 2009 Paremus Limited. All rights reserved.   June 2009
CommandSession
package org.osgi.service.command;

public interface CommandSession {
  Object execute(CharSequence program) throws Exception;
  void close();

    InputStream getKeyboard();
    PrintStream getConsole();

    Object get(String name);
    void put(String name, Object value);

    CharSequence format(Object target, int level);
    Object convert(Class<?> type, Object instance);
}




    Posh OSGi Shell   Copyright © 2009 Paremus Limited. All rights reserved.   June 2009
Command Provider
• There is no CommandProvider interface
• Parameters are coerced using reflection
• Any service can provide commands

    public void start(BundleContext ctx) {
        Commands cmd = new Commands();
        String functions[] = {“hello”, “goodbye”};
        Dictionary dict = new Dictionary();
        dict.put(“osgi.command.scope”, “myscope”);
        dict.put(“osgi.command.function”, functions);
        ctx.registerService(cmd.getClass().getName,() cmd, dict);
    }

Posh OSGi Shell       Copyright © 2009 Paremus Limited. All rights reserved.   June 2009
Any Command Interface
public boolean grep(String[] args) throws IOException;


public URI cd(CommandSession session, String dir);
public URI pwd(CommandSession session);


public void addCommand(String scope, Object target);
public void addCommand(String scope, Object target, Class<?> fc);
public void addCommand(String scope, Object target, String func);


public Bundle getBundle(long id);
public Bundle[] getBundles();
public ServiceRegistration registerService(
        String clazz, Object svcObj, Dictionary dict);




 Posh OSGi Shell    Copyright © 2009 Paremus Limited. All rights reserved.   June 2009
Grep command
public boolean grep(CommandSession session, List<String> args)
                                            throws IOException {
  Pattern pattern = Pattern.compile(args.remove(0));

    for (String arg : args) {
      InputStream in =
               Directory.resolve(session,arg).toURL().openStream();
      Reader rdr = new BufferedReader(new InputStreamReader(in));
      String s;

        while ((s = rdr.readLine()) != null) {
          if (pattern.matcher(s).find()) {
            match = true;
            System.out.println(s);
          }
        }
    }

    return match;
}

    Posh OSGi Shell     Copyright © 2009 Paremus Limited. All rights reserved.   June 2009
Interactive Shell Language
• Interactive shell requirements differ from
  those for scripting languages
            – Easy for users to type
            – Minimum parenthesis, semi-colons etc
            – Compatibility with Unix shells like bash

• Existing JVM languages not good for shell
            – Jacl: needs own TCL-derived library
            – BeanShell: syntax too verbose



Posh OSGi Shell       Copyright © 2009 Paremus Limited. All rights reserved.   June 2009
Tiny Shell Language - TSL
• Easy to use – no unnecessary syntax
• Provides lists, pipes and closures
• Leverages Java capabilities
            – Method calls using reflection
            – Argument coercion

• Commands can provide control primitives
• Small size (<50Kb)


Posh OSGi Shell      Copyright © 2009 Paremus Limited. All rights reserved.   June 2009
Closures implement Function
package org.osgi.service.command;
public interface Function {
    Object execute(CommandSession session, List<Object> arguments)
     throws Exception;
}




    Posh OSGi Shell   Copyright © 2009 Paremus Limited. All rights reserved.   June 2009
Add Control Primitives
public void each(CommandSession session, Collection<Object> list,
   Function closure) throws Exception {

    List<Object> args = new ArrayList<Object>();
    args.add(null);

    for (Object x : list) {
      args.set(0, x);
      closure.execute(session, args);
    }
}


% each [a, b, 1, 2] { echo $it }
a
b
1
2

    Posh OSGi Shell   Copyright © 2009 Paremus Limited. All rights reserved.   June 2009
RFC132: What's missing?
• Commands in osgi: scope are not defined
• Search order for unscoped commands
• List available commands and variables
• Script execution
• Command editing, history and completion




Posh OSGi Shell   Copyright © 2009 Paremus Limited. All rights reserved.   June 2009
Posh: in action!



Posh OSGi Shell      Copyright © 2009 Paremus Limited. All rights reserved.   June 2009
Posh in action!
Builds on basic RFC132 runtime
•        Adds SCOPE path
•        Shell builtins: set, type
•        Script execution
•        Command editing, history & completion
•        Control-C interrupt handling
•        And more…

Posh OSGi Shell    Copyright © 2009 Paremus Limited. All rights reserved.   June 2009
Links

RFC132 Draft Specification
www.osgi.org/download/osgi-4.2-early-draft.pdf

Posh “devcon” binary download
www.paremus.com/devcon2009download/

derek.baum@paremus.com



Posh OSGi Shell   Copyright © 2009 Paremus Limited. All rights reserved.   June 2009

More Related Content

What's hot

Speech for Windows Phone 8
Speech for Windows Phone 8Speech for Windows Phone 8
Speech for Windows Phone 8Marco Massarelli
 
Brno meetr: Packaging Ruby Gems into RPM
Brno meetr: Packaging Ruby Gems into RPMBrno meetr: Packaging Ruby Gems into RPM
Brno meetr: Packaging Ruby Gems into RPMLubomir Rintel
 
Using puppet
Using puppetUsing puppet
Using puppetAlex Su
 
Language Enhancement in ColdFusion 8 - CFUnited 2007
Language Enhancement in ColdFusion 8 - CFUnited 2007Language Enhancement in ColdFusion 8 - CFUnited 2007
Language Enhancement in ColdFusion 8 - CFUnited 2007Rupesh Kumar
 
Ios i pv4_access_lists
Ios i pv4_access_listsIos i pv4_access_lists
Ios i pv4_access_listsMohamed Gamel
 
解读server.xml文件
解读server.xml文件解读server.xml文件
解读server.xml文件wensheng wei
 
Coroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in PractiseCoroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in PractiseChristian Melchior
 
Eclipse HandsOn Workshop
Eclipse HandsOn WorkshopEclipse HandsOn Workshop
Eclipse HandsOn WorkshopBastian Feder
 
Python concurrency: libraries overview
Python concurrency: libraries overviewPython concurrency: libraries overview
Python concurrency: libraries overviewAndrii Mishkovskyi
 
CoreOS in a Nutshell
CoreOS in a NutshellCoreOS in a Nutshell
CoreOS in a NutshellCoreOS
 
When symfony met promises
When symfony met promises When symfony met promises
When symfony met promises Marc Morera
 

What's hot (19)

Speech for Windows Phone 8
Speech for Windows Phone 8Speech for Windows Phone 8
Speech for Windows Phone 8
 
Caché acelerador de contenido
Caché acelerador de contenidoCaché acelerador de contenido
Caché acelerador de contenido
 
Comredis
ComredisComredis
Comredis
 
Ip Access Lists
Ip Access ListsIp Access Lists
Ip Access Lists
 
Brno meetr: Packaging Ruby Gems into RPM
Brno meetr: Packaging Ruby Gems into RPMBrno meetr: Packaging Ruby Gems into RPM
Brno meetr: Packaging Ruby Gems into RPM
 
Using puppet
Using puppetUsing puppet
Using puppet
 
ECMAScript 2015
ECMAScript 2015ECMAScript 2015
ECMAScript 2015
 
Language Enhancement in ColdFusion 8 - CFUnited 2007
Language Enhancement in ColdFusion 8 - CFUnited 2007Language Enhancement in ColdFusion 8 - CFUnited 2007
Language Enhancement in ColdFusion 8 - CFUnited 2007
 
Pemrograman Jaringan
Pemrograman JaringanPemrograman Jaringan
Pemrograman Jaringan
 
Ios i pv4_access_lists
Ios i pv4_access_listsIos i pv4_access_lists
Ios i pv4_access_lists
 
解读server.xml文件
解读server.xml文件解读server.xml文件
解读server.xml文件
 
Coroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in PractiseCoroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in Practise
 
Python at Facebook
Python at FacebookPython at Facebook
Python at Facebook
 
Eclipse HandsOn Workshop
Eclipse HandsOn WorkshopEclipse HandsOn Workshop
Eclipse HandsOn Workshop
 
Python concurrency: libraries overview
Python concurrency: libraries overviewPython concurrency: libraries overview
Python concurrency: libraries overview
 
JAVA NIO
JAVA NIOJAVA NIO
JAVA NIO
 
CoreOS in a Nutshell
CoreOS in a NutshellCoreOS in a Nutshell
CoreOS in a Nutshell
 
When symfony met promises
When symfony met promises When symfony met promises
When symfony met promises
 
Raj apache
Raj apacheRaj apache
Raj apache
 

Viewers also liked

O triunfo dos nerds
O triunfo dos nerdsO triunfo dos nerds
O triunfo dos nerdsLuiz Borba
 
Posh Pows With Logan
Posh Pows With LoganPosh Pows With Logan
Posh Pows With Logansatonner
 
Posh Consulting Inc. Overview
Posh Consulting Inc. OverviewPosh Consulting Inc. Overview
Posh Consulting Inc. Overviewash321ash
 
Prevention of Sexual Harassment at Workplace Act
Prevention of Sexual Harassment at Workplace ActPrevention of Sexual Harassment at Workplace Act
Prevention of Sexual Harassment at Workplace ActAID FOR CHANGE
 

Viewers also liked (7)

O triunfo dos nerds
O triunfo dos nerdsO triunfo dos nerds
O triunfo dos nerds
 
Apresentacao nerd
Apresentacao nerdApresentacao nerd
Apresentacao nerd
 
Dia do Orgulho Nerd
Dia do Orgulho NerdDia do Orgulho Nerd
Dia do Orgulho Nerd
 
Posh Pows With Logan
Posh Pows With LoganPosh Pows With Logan
Posh Pows With Logan
 
Posh Consulting Inc. Overview
Posh Consulting Inc. OverviewPosh Consulting Inc. Overview
Posh Consulting Inc. Overview
 
Cultura nerd
Cultura nerdCultura nerd
Cultura nerd
 
Prevention of Sexual Harassment at Workplace Act
Prevention of Sexual Harassment at Workplace ActPrevention of Sexual Harassment at Workplace Act
Prevention of Sexual Harassment at Workplace Act
 

Similar to Posh Devcon2009

Shell scripting - By Vu Duy Tu from eXo Platform SEA
Shell scripting - By Vu Duy Tu from eXo Platform SEAShell scripting - By Vu Duy Tu from eXo Platform SEA
Shell scripting - By Vu Duy Tu from eXo Platform SEAThuy_Dang
 
Cloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Cloud meets Fog & Puppet A Story of Version Controlled InfrastructureCloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Cloud meets Fog & Puppet A Story of Version Controlled InfrastructureHabeeb Rahman
 
Monitoring OSGi Applications with the Web Console
Monitoring OSGi Applications with the Web ConsoleMonitoring OSGi Applications with the Web Console
Monitoring OSGi Applications with the Web ConsoleCarsten Ziegeler
 
Monitoring OSGi Applications with the Web Console - Carsten Ziegeler
Monitoring OSGi Applications with the Web Console - Carsten ZiegelerMonitoring OSGi Applications with the Web Console - Carsten Ziegeler
Monitoring OSGi Applications with the Web Console - Carsten Ziegelermfrancis
 
Monitoring OSGi Applications with the Web Console
Monitoring OSGi Applications with the Web ConsoleMonitoring OSGi Applications with the Web Console
Monitoring OSGi Applications with the Web ConsoleAdobe
 
20100730 phpstudy
20100730 phpstudy20100730 phpstudy
20100730 phpstudyYusuke Ando
 
Service oriented web development with OSGi
Service oriented web development with OSGiService oriented web development with OSGi
Service oriented web development with OSGiCarsten Ziegeler
 
Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevFelix Geisendörfer
 
Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)Eugene Yokota
 
Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Jimmy Schementi
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backendDavid Padbury
 
Java - A broad introduction
Java - A broad introductionJava - A broad introduction
Java - A broad introductionBirol Efe
 
Intro to Rust 2019
Intro to Rust 2019Intro to Rust 2019
Intro to Rust 2019Timothy Bess
 
Exchange 2010 PowerShell and the Exchange 2003 Administrator
Exchange 2010 PowerShell and the Exchange 2003 AdministratorExchange 2010 PowerShell and the Exchange 2003 Administrator
Exchange 2010 PowerShell and the Exchange 2003 AdministratorMichel de Rooij
 
Pure Java RAD and Scaffolding Tools Race
Pure Java RAD and Scaffolding Tools RacePure Java RAD and Scaffolding Tools Race
Pure Java RAD and Scaffolding Tools RaceBaruch Sadogursky
 
Import golang; struct microservice
Import golang; struct microserviceImport golang; struct microservice
Import golang; struct microserviceGiulio De Donato
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShellBoulos Dib
 
Python Programming Essentials - M25 - os and sys modules
Python Programming Essentials - M25 - os and sys modulesPython Programming Essentials - M25 - os and sys modules
Python Programming Essentials - M25 - os and sys modulesP3 InfoTech Solutions Pvt. Ltd.
 
Automated infrastructure is on the menu
Automated infrastructure is on the menuAutomated infrastructure is on the menu
Automated infrastructure is on the menujtimberman
 

Similar to Posh Devcon2009 (20)

Shell scripting - By Vu Duy Tu from eXo Platform SEA
Shell scripting - By Vu Duy Tu from eXo Platform SEAShell scripting - By Vu Duy Tu from eXo Platform SEA
Shell scripting - By Vu Duy Tu from eXo Platform SEA
 
Cloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Cloud meets Fog & Puppet A Story of Version Controlled InfrastructureCloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Cloud meets Fog & Puppet A Story of Version Controlled Infrastructure
 
Monitoring OSGi Applications with the Web Console
Monitoring OSGi Applications with the Web ConsoleMonitoring OSGi Applications with the Web Console
Monitoring OSGi Applications with the Web Console
 
Monitoring OSGi Applications with the Web Console - Carsten Ziegeler
Monitoring OSGi Applications with the Web Console - Carsten ZiegelerMonitoring OSGi Applications with the Web Console - Carsten Ziegeler
Monitoring OSGi Applications with the Web Console - Carsten Ziegeler
 
Monitoring OSGi Applications with the Web Console
Monitoring OSGi Applications with the Web ConsoleMonitoring OSGi Applications with the Web Console
Monitoring OSGi Applications with the Web Console
 
20100730 phpstudy
20100730 phpstudy20100730 phpstudy
20100730 phpstudy
 
Service oriented web development with OSGi
Service oriented web development with OSGiService oriented web development with OSGi
Service oriented web development with OSGi
 
Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredev
 
Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)
 
Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
 
Java - A broad introduction
Java - A broad introductionJava - A broad introduction
Java - A broad introduction
 
Intro to Rust 2019
Intro to Rust 2019Intro to Rust 2019
Intro to Rust 2019
 
Exchange 2010 PowerShell and the Exchange 2003 Administrator
Exchange 2010 PowerShell and the Exchange 2003 AdministratorExchange 2010 PowerShell and the Exchange 2003 Administrator
Exchange 2010 PowerShell and the Exchange 2003 Administrator
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
Pure Java RAD and Scaffolding Tools Race
Pure Java RAD and Scaffolding Tools RacePure Java RAD and Scaffolding Tools Race
Pure Java RAD and Scaffolding Tools Race
 
Import golang; struct microservice
Import golang; struct microserviceImport golang; struct microservice
Import golang; struct microservice
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
 
Python Programming Essentials - M25 - os and sys modules
Python Programming Essentials - M25 - os and sys modulesPython Programming Essentials - M25 - os and sys modules
Python Programming Essentials - M25 - os and sys modules
 
Automated infrastructure is on the menu
Automated infrastructure is on the menuAutomated infrastructure is on the menu
Automated infrastructure is on the menu
 

Recently uploaded

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 

Posh Devcon2009

  • 1. Posh: an OSGi Shell RFC132 in action! Derek Baum Paremus Limited Posh OSGi Shell Copyright © 2009 Paremus Limited. All rights reserved. June 2009
  • 2. The (Draft) Specification Posh OSGi Shell Copyright © 2009 Paremus Limited. All rights reserved. June 2009
  • 3. RFC132: Problem Description No standard way for user to interact with an OSGi-based system. • Different commands for common tasks – install, start, stop, status • Different API to add commands – Commands are not reusable • No script support Posh OSGi Shell Copyright © 2009 Paremus Limited. All rights reserved. June 2009
  • 4. Equinox & Felix Shells $ java -jar org.eclipse.osgi_3.4.3.R34x_v20081215-1030.jar $ java -jar org.eclipse.osgi_3.4.3.R34x_v20081215-1030.jar -console osgi> ss Framework is launched. id State Bundle 0 ACTIVE org.eclipse.osgi_3.4.3.R34x_v20081215-1030 osgi> ^D$ $ java -jar bin/felix.jar -> ss Command not found. -> ps START LEVEL 1 ID State Level Name [ 0] [Active ] [ 0] System Bundle (1.8.0) [ 1] [Active ] [ 1] Apache Felix Shell Service (1.2.0) [ 2] [Active ] [ 1] Apache Felix Shell TUI (1.2.0) [ 3] [Active ] [ 1] Apache Felix Bundle Repository (1.4.0) -> ^DShellTUI: No standard input...exiting. ^C$ Posh OSGi Shell Copyright © 2009 Paremus Limited. All rights reserved. June 2009
  • 5. Hello, Equinox import org.eclipse.osgi.framework.console.CommandInterpreter; import org.eclipse.osgi.framework.console.CommandProvider; public class Commands implements CommandProvider { public void _hello(CommandInterpreter ci) { ci.print("Hello, " + ci.nextArgument()); } public String getHelp() { return "thello - say hellon"; } } Posh OSGi Shell Copyright © 2009 Paremus Limited. All rights reserved. June 2009
  • 6. Hello, Felix import org.apache.felix.shell.Command; public class HelloCommand implements Command { public void execute(String s, PrintStream out, PrintStream err) { String[] args = s.split(“s+”); if (args.length < 2) { err.println(“Usage: ” + getUsage()); } else { out.println(“Hello, “ + args[1]); } } public String getName() { return "hello";} public String getUsage() { return "hello name";} public String getShortDescription() { return "say hello";} } Posh OSGi Shell Copyright © 2009 Paremus Limited. All rights reserved. June 2009
  • 7. Hello, RFC132 public class Commands { public boolean hello(String name) { System.out.println(“Hello, “ + name); return name != null; } } Posh OSGi Shell Copyright © 2009 Paremus Limited. All rights reserved. June 2009
  • 8. RFC132 Command Interface • Simple & lightweight to add commands – Promotes adding commands in any bundle • Access to input and output streams • Shared session state between commands • Small (core runtime < 50Kb) Posh OSGi Shell Copyright © 2009 Paremus Limited. All rights reserved. June 2009
  • 9. Architecture Console Telnet ... Session Session Session CommandProvider CommandSessionImpl ThreadIO CommandSession command providers Converter scope=xxx, function=yyy Basic Basic ... Conversions Commands Commands Posh OSGi Shell Copyright © 2009 Paremus Limited. All rights reserved. June 2009
  • 10. CommandProcessor package org.osgi.service.command; public interface CommandProcessor { CommandSession createSession(InputStream in, PrintStream out, PrintStream err); } Posh OSGi Shell Copyright © 2009 Paremus Limited. All rights reserved. June 2009
  • 11. CommandSession package org.osgi.service.command; public interface CommandSession { Object execute(CharSequence program) throws Exception; void close(); InputStream getKeyboard(); PrintStream getConsole(); Object get(String name); void put(String name, Object value); CharSequence format(Object target, int level); Object convert(Class<?> type, Object instance); } Posh OSGi Shell Copyright © 2009 Paremus Limited. All rights reserved. June 2009
  • 12. Command Provider • There is no CommandProvider interface • Parameters are coerced using reflection • Any service can provide commands public void start(BundleContext ctx) { Commands cmd = new Commands(); String functions[] = {“hello”, “goodbye”}; Dictionary dict = new Dictionary(); dict.put(“osgi.command.scope”, “myscope”); dict.put(“osgi.command.function”, functions); ctx.registerService(cmd.getClass().getName,() cmd, dict); } Posh OSGi Shell Copyright © 2009 Paremus Limited. All rights reserved. June 2009
  • 13. Any Command Interface public boolean grep(String[] args) throws IOException; public URI cd(CommandSession session, String dir); public URI pwd(CommandSession session); public void addCommand(String scope, Object target); public void addCommand(String scope, Object target, Class<?> fc); public void addCommand(String scope, Object target, String func); public Bundle getBundle(long id); public Bundle[] getBundles(); public ServiceRegistration registerService( String clazz, Object svcObj, Dictionary dict); Posh OSGi Shell Copyright © 2009 Paremus Limited. All rights reserved. June 2009
  • 14. Grep command public boolean grep(CommandSession session, List<String> args) throws IOException { Pattern pattern = Pattern.compile(args.remove(0)); for (String arg : args) { InputStream in = Directory.resolve(session,arg).toURL().openStream(); Reader rdr = new BufferedReader(new InputStreamReader(in)); String s; while ((s = rdr.readLine()) != null) { if (pattern.matcher(s).find()) { match = true; System.out.println(s); } } } return match; } Posh OSGi Shell Copyright © 2009 Paremus Limited. All rights reserved. June 2009
  • 15. Interactive Shell Language • Interactive shell requirements differ from those for scripting languages – Easy for users to type – Minimum parenthesis, semi-colons etc – Compatibility with Unix shells like bash • Existing JVM languages not good for shell – Jacl: needs own TCL-derived library – BeanShell: syntax too verbose Posh OSGi Shell Copyright © 2009 Paremus Limited. All rights reserved. June 2009
  • 16. Tiny Shell Language - TSL • Easy to use – no unnecessary syntax • Provides lists, pipes and closures • Leverages Java capabilities – Method calls using reflection – Argument coercion • Commands can provide control primitives • Small size (<50Kb) Posh OSGi Shell Copyright © 2009 Paremus Limited. All rights reserved. June 2009
  • 17. Closures implement Function package org.osgi.service.command; public interface Function { Object execute(CommandSession session, List<Object> arguments) throws Exception; } Posh OSGi Shell Copyright © 2009 Paremus Limited. All rights reserved. June 2009
  • 18. Add Control Primitives public void each(CommandSession session, Collection<Object> list, Function closure) throws Exception { List<Object> args = new ArrayList<Object>(); args.add(null); for (Object x : list) { args.set(0, x); closure.execute(session, args); } } % each [a, b, 1, 2] { echo $it } a b 1 2 Posh OSGi Shell Copyright © 2009 Paremus Limited. All rights reserved. June 2009
  • 19. RFC132: What's missing? • Commands in osgi: scope are not defined • Search order for unscoped commands • List available commands and variables • Script execution • Command editing, history and completion Posh OSGi Shell Copyright © 2009 Paremus Limited. All rights reserved. June 2009
  • 20. Posh: in action! Posh OSGi Shell Copyright © 2009 Paremus Limited. All rights reserved. June 2009
  • 21. Posh in action! Builds on basic RFC132 runtime • Adds SCOPE path • Shell builtins: set, type • Script execution • Command editing, history & completion • Control-C interrupt handling • And more… Posh OSGi Shell Copyright © 2009 Paremus Limited. All rights reserved. June 2009
  • 22. Links RFC132 Draft Specification www.osgi.org/download/osgi-4.2-early-draft.pdf Posh “devcon” binary download www.paremus.com/devcon2009download/ derek.baum@paremus.com Posh OSGi Shell Copyright © 2009 Paremus Limited. All rights reserved. June 2009