SlideShare a Scribd company logo
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

PDF
OSGi for mere mortals
PDF
What's cool in the new and updated OSGi Specs (EclipseCon 2014)
PDF
Maximize the power of OSGi
PDF
Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix
PPTX
ARGUS - THE OMNISCIENT CI
PDF
OSGi Cloud Ecosystems (EclipseCon 2013)
PDF
cq_cxf_integration
PDF
CoreOS: Control Your Fleet
OSGi for mere mortals
What's cool in the new and updated OSGi Specs (EclipseCon 2014)
Maximize the power of OSGi
Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix
ARGUS - THE OMNISCIENT CI
OSGi Cloud Ecosystems (EclipseCon 2013)
cq_cxf_integration
CoreOS: Control Your Fleet

What's hot (19)

PDF
Speech for Windows Phone 8
PDF
Caché acelerador de contenido
PDF
Comredis
PDF
Ip Access Lists
PDF
Brno meetr: Packaging Ruby Gems into RPM
PPTX
Using puppet
PPTX
ECMAScript 2015
PPT
Language Enhancement in ColdFusion 8 - CFUnited 2007
PPT
Pemrograman Jaringan
PDF
Ios i pv4_access_lists
DOC
解读server.xml文件
PDF
Coroutines for Kotlin Multiplatform in Practise
PPTX
Python at Facebook
PDF
Eclipse HandsOn Workshop
PDF
Python concurrency: libraries overview
PDF
JAVA NIO
PPTX
CoreOS in a Nutshell
PDF
When symfony met promises
PPT
Raj apache
Speech for Windows Phone 8
Caché acelerador de contenido
Comredis
Ip Access Lists
Brno meetr: Packaging Ruby Gems into RPM
Using puppet
ECMAScript 2015
Language Enhancement in ColdFusion 8 - CFUnited 2007
Pemrograman Jaringan
Ios i pv4_access_lists
解读server.xml文件
Coroutines for Kotlin Multiplatform in Practise
Python at Facebook
Eclipse HandsOn Workshop
Python concurrency: libraries overview
JAVA NIO
CoreOS in a Nutshell
When symfony met promises
Raj apache
Ad

Viewers also liked (7)

PDF
O triunfo dos nerds
PPT
Apresentacao nerd
PDF
Dia do Orgulho Nerd
PPT
Posh Pows With Logan
PDF
Posh Consulting Inc. Overview
PDF
Cultura nerd
PPTX
Prevention of Sexual Harassment at Workplace Act
O triunfo dos nerds
Apresentacao nerd
Dia do Orgulho Nerd
Posh Pows With Logan
Posh Consulting Inc. Overview
Cultura nerd
Prevention of Sexual Harassment at Workplace Act
Ad

Similar to Posh Devcon2009 (20)

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

Recently uploaded (20)

PDF
Getting Started with Data Integration: FME Form 101
PPTX
Chapter 5: Probability Theory and Statistics
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
1. Introduction to Computer Programming.pptx
PPTX
TLE Review Electricity (Electricity).pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Hybrid model detection and classification of lung cancer
PDF
project resource management chapter-09.pdf
PDF
WOOl fibre morphology and structure.pdf for textiles
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Encapsulation theory and applications.pdf
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
A novel scalable deep ensemble learning framework for big data classification...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Getting Started with Data Integration: FME Form 101
Chapter 5: Probability Theory and Statistics
Encapsulation_ Review paper, used for researhc scholars
Agricultural_Statistics_at_a_Glance_2022_0.pdf
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
1. Introduction to Computer Programming.pptx
TLE Review Electricity (Electricity).pptx
NewMind AI Weekly Chronicles - August'25-Week II
Hybrid model detection and classification of lung cancer
project resource management chapter-09.pdf
WOOl fibre morphology and structure.pdf for textiles
SOPHOS-XG Firewall Administrator PPT.pptx
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
Univ-Connecticut-ChatGPT-Presentaion.pdf
Encapsulation theory and applications.pdf
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Enhancing emotion recognition model for a student engagement use case through...
A novel scalable deep ensemble learning framework for big data classification...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx

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