Apache Felix Shell. Apache Felix Shell. Overview. How the Shell Service Works. package org.apache.felix.shell;

Similar documents
Apache Felix Framework Launching and Embedding

CS5233 Components Models and Engineering

OSGi in Action. Ada Diaconescu

Introduction to OSGi. Marcel Offermans. luminis

Introduction IS

Developing Java Applications with OSGi Capital District Java Developers Network. Michael P. Redlich March 20, 2008

Patterns and Best Practices for dynamic OSGi Applications

Modular Java Applications with Spring, dm Server and OSGi

CS486: Tutorial on SOC, OSGi, and Knopflerfish. Ryan Babbitt (props to Dr. Hen-I Yang, CS415X) Feb. 3, 2011

Apache Felix. Richard S. Hall. A Standard Plugin Model for Apache. Atlanta, Georgia U.S.A. November 13th, 2007

OSGi. Building and Managing Pluggable Applications

Compiling expressions

OSGi. Building LinkedIn's Next Generation Architecture with OSGI

Building LinkedIn's Next Generation Architecture with OSGI

Agenda. Why OSGi. What is OSGi. How OSGi Works. Apache projects related to OSGi Progress Software Corporation. All rights reserved.

Building Secure OSGi Applications. Karl Pauls Marcel Offermans. luminis

7. Component Models. Distributed Systems Prof. Dr. Alexander Schill

Using the Bridge Design Pattern for OSGi Service Update

Modularity in Java. With OSGi. Alex Docklands.LJC January Copyright 2016 Alex Blewitt

Using Apache Felix: OSGi best practices. Marcel Offermans luminis

Chapter 4 Java Language Fundamentals

ESB, OSGi, and the Cloud

Brekeke PBX Version 2 ARS Plug-in Developer s Guide Brekeke Software, Inc.

Distributed OSGi through Apache CXF and Web Services

OOP Lab Factory Method, Singleton, and Properties Page 1

Today. Book-keeping. File I/O. Subscribe to sipb-iap-java-students. Inner classes. Debugging tools

Brekeke PBX Version 3 ARS Plug-in Developer s Guide Brekeke Software, Inc.

8. Component Software

JBoss Tattletale. Betraying all your project's naughty little secrets

Richard S. Hall Karl Pauls Stuart McCulloch David Savage

OSGi Service Platform Core Specification. The OSGi Alliance

1.2. Name(s) and address of Document Author(s)/Supplier: Sahoo: 1.3. Date of This Document: 12 July 2008

Servlets. How to use Apache FOP in a Servlet $Revision: $ Table of contents

Table of Contents. Tutorial API Deployment Prerequisites... 1

Text User Interfaces. Keyboard IO plus

Class Dependency Analyzer CDA Developer Guide

Unit 10: exception handling and file I/O

OSGi Best Practices. Emily

Exploiting Java Code Interactions

Scripting Languages in OSGi. Thursday, November 8, 12

Exceptions and Libraries

Fall 2017 CISC124 10/1/2017

This chapter describes basic cadexceptions, debug, and network configuration procedures. This is a placeholder since zero is not an error.

New York University Computer Science Department Courant Institute of Mathematical Sciences

Programming - 2. Common Errors

OSGi and Equinox. Creating Highly Modular Java. Systems

For Review Purposes Only. Oracle GlassFish Server 3.1 Application Development Guide

Managed Smart Clients

Introduction to Computer Science II (ITI 1121) Midterm Examination

1.00 Lecture 30. Sending information to a Java program

ASSIGNMENT 5 Data Structures, Files, Exceptions, and To-Do Lists

1 OBJECT-ORIENTED PROGRAMMING 1

Getting Started in Java. Bill Pugh Dept. of Computer Science Univ. of Maryland, College Park

Ibis Communication Library User s Guide

Dependencies, dependencies, dependencies

ESC/Java2 Use and Features David Cok, Joe Kiniry, Erik Poll Eastman Kodak Company, University College Dublin, and Radboud University Nijmegen

Managing Installations and Provisioning of OSGi Applications. Carsten Ziegeler

This is a placeholder since 0 (zero) is not an error. No action. Not an error.

Peter Kriens OSGi Evangelist/Director. OSGi R4.3 // Next Release Overview

Install and Configure ANTLR 4 on Eclipse and Ubuntu

Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently.

2.3 Unix Streaming and Piping

Comparing JavaBeans and OSGi

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

Project 1: Remote Method Invocation CSE 291 Spring 2016

EXCEPTIONS. Fundamentals of Computer Science I

Java in 21 minutes. Hello world. hello world. exceptions. basic data types. constructors. classes & objects I/O. program structure.

Frequently Asked Questions

Downloading Tweet Streams and Parsing

SHIFTLEFT OCULAR THE CODE PROPERTY GRAPH

Objec-ves JAR FILES. Jar files. Excep-ons. Files Streams. Ø Wrap up Ø Why Excep-ons? 9/30/16. Oct 3, 2016 Sprenkle - CSCI209 1

RMI Case Study. A Typical RMI Application

Signicat Connector for Java Version 2.6. Document version 3

Patterns and Best Practices for Dynamic OSGi Applications

Project Compiler. CS031 TA Help Session November 28, 2011

JSR 277, 291 and OSGi, Oh My! - OSGi and Java Modularity

Tuesday, April 26, 2011

Some Notes on R Event Handling

OSGi Cloud Ecosystems. David Bosschaert Principal Engineer, JBoss/Red Hat March 2013

Java obfuscator: implementation. Re-Trust quarterly meeting Villach, March 11, 2008

Creating a custom control using Java

Testing Exceptions with Enforcer

The following steps will create an Eclipse project containing source code for Problem Set 1:

USING THE OOSIML/JAVA. With a Terminal Window

SAP Edge Services, cloud edition Edge Services Predictive Analytics Service Guide Version 1803

CPSC 211 Data Structures & Implementations (c) Texas A&M University [ 165] Postfix Expressions

CSE 142/143 Unofficial Commenting Guide Eric Arendt, Alyssa Harding, Melissa Winstanley

The Interceptor Architectural Pattern

Customizing the WebSphere Portal login and logout commands

Table of Contents. 1 Context 2. 2 Problem statement 2. 3 Related work 2

CS11 Advanced Java. Winter Lecture 2

BEAAquaLogic. Service Bus. Interoperability With EJB Transport

WebSphere Message Broker. Programming

About me. Jesper Pedersen. Project lead for. Chairman for Boston JBoss User Group. Core developer, JBoss by Red Hat

OSGi. Tales from the Trenches. OSGitales from the trenches

Chapter 1. JOnAS and JMX, registering and manipulating MBeans

Pace University. Fundamental Concepts of CS121 1

API Developer Notes. A Galileo Web Services Java Connection Class Using Axis. 29 June Version 1.3

ValWorkBench library Developer Guide

ASSIGNMENT 5 Objects, Files, and More Garage Management

Transcription:

Apache Felix Shell Apache Felix Shell Overview How the Shell Service Works How Commands Work Creating a Command Security and the Shell Service Feedback Overview In order to interact with Felix it is necessary to have some sort of interactive shell that allows you to issue commands to the framework and to obtain information from it. The OSGi specification does not define how an OSGi framework should provide this interactivity. Felix defines a shell service for creating and executing arbitrary commands. The shell service does not define a user interface, only a service API. The benefit of the Felix shell service approach is that it is possible to: have multiple shell user interfaces (e.g., textual and graphical), add custom commands to the shell (i.e., bundles can make commands available via the shell service), and use the shell service from other bundles/services. The remainder of this document describes how the shell service works and how to create custom commands for it. This document does not describe how to use the command shell, nor does it describe the text-based or GUI-based user interfaces that are available for the shell. How the Shell Service Works The Felix shell service is intended to be a simple, but extensible shell service that can have multiple user interface implementations, all of which are independent from the Felix framework. The shell service is currently not intended to be sophisticated, rather it is just a mechanism to execute commands. The shell service maintains a list of command services, each of which have a unique command name. The shell service is defined by the following service interface: package org.apache.felix.shell; public interface ShellService public String[] getcommands(); public String getcommandusage(string name); public String getcommanddescription(string name); public ServiceReference getcommandreference(string name); public void executecommand( String commandline, PrintStream out, PrintStream err) throws Exception; Using the shell service interface, it is possible to access and execute available commands. The shell service methods perform the following functions: getcommands() - returns an array of strings that correspond to the names of the installed shell commands. getcommandusage() - returns the command usage string for a particular command name getcommanddescription() - returns a short description for a particular command name. getcommandreference() - returns the service reference for a particular command name. executecommand() - executes a particular command using the specified command line and print streams.

Most of the shell service methods require no explanation except for the executecommand() method. Even though this method is the most complex, it is still fairly simplistic. The assumption of the shell service is that a command line will be typed by the user (or perhaps constructed by a GUI) and passed into it for execution. The shell service interprets the command line in a very simplistic fashion; it takes the leading string of characters terminated by a space character (not including it) and assumes that this leading token is the command name. Consider the following command line: update 3 http://www.foo.com/bar.jar The shell service interprets this as an update command and will search for a command service with the same name. If a corresponding command service is not found, then it will print an error message to the error print stream. If a corresponding command service is found, then it will pass the entire command line string and the print streams into the executecommand() method of the command service (for a more detailed description of command services, see the next section). Notice that there is no method to add commands to the shell service interface. This is because commands are implemented as OSGi services and the shell service listens for service events and when a command service registers/unregisters it automatically updates its list of commands accordingly. How Commands Work All commands available in the shell service are implemented as OSGi services. The advantage of this approach is two-fold: the shell service can leverage OSGi service events to maintain its list of available commands and the set available commands is dynamically extendable by installed bundles. The command service interface is defined as follows: package org.apache.felix.shell; public interface Command public String getname(); public String getusage(); public String getshortdescription(); public void execute(string line, PrintStream out, PrintStream err); The semantics of the command service methods are: getname() - returns the name of the command; this must not contain whitespace and must be unique. getusage() - returns the usage string of the command; this should be one line and as short as possible (this is used for generating the help command output). getshortdescription() - returns a short description of the command; this should be one line and as short as possible (this is used for generating the help command output). execute() - executes the command's functionality using supplied command line and print streams. Creating a Command The following example creates a simple version of the start command. package test; import java.io.printstream; import java.net.url; import java.net.malformedurlexception; import java.util.stringtokenizer;

import org.osgi.framework.*; import org.apache.felix.shell.shellservice; import org.apache.felix.shell.command; public class MyStartCommandImpl implements Command private BundleContext m_context = null; public MyStartCommandImpl(BundleContext context) m_context = context; public String getname() return "mystart"; public String getusage() return "mystart <id> [<id>...]"; public String getshortdescription() return "start bundle(s)."; public void execute(string s, PrintStream out, PrintStream err) StringTokenizer st = new StringTokenizer(s, " "); // Ignore the command name. st.nexttoken(); // There should be at least one bundle id. if (st.counttokens() >= 1) while (st.hasmoretokens()) String id = st.nexttoken().trim(); try long l = Long.valueOf(id).longValue(); Bundle bundle = m_context.getbundle(l); if (bundle!= null) bundle.start(); err.println("bundle ID " + id + " is invalid.");

catch (NumberFormatException ex) err.println("unable to parse id '" + id + "'."); catch (BundleException ex) if (ex.getnestedexception()!= null) err.println(ex.getnestedexception().tostring()); err.println(ex.tostring()); catch (Exception ex) err.println(ex.tostring()); err.println("incorrect number of arguments"); A bundle activator class is needed for packaging the command servce; the bundle activator registers the command service in its start() method. Note: You do not need one activator per command, a single activator can register any number of commands. package test; import org.osgi.framework.bundleactivator; import org.osgi.framework.bundlecontext; public class MyStartActivator implements BundleActivator private transient BundleContext m_context = null; public void start(bundlecontext context) m_context = context; // Register the command service. context.registerservice( org.apache.felix.shell.command.class.getname(), new MyStartCommandImpl(m_context), null); public void stop(bundlecontext context) // Services are automatically unregistered so // we don't have to unregister the factory here. To compile these classes you will need to have org.apache.felix.framework-x.y.z.jar and org.apache.felix.shell-x.y.z.jar on your class path. Compile all of the source files using a command like:

java -cp org.apache.felix.framework-1.8.1.jar:org.apache.felix.shell-1.2.0. jar -d c:\classes *.java This command compiles all of the source files and outputs the generated class files into a subdirectory of the c:\classes directory, called test, named after the package of the source files; for the above command to work, the c:\classes directory must exist. Once you have compiled all of the above classes, you need to create a bundle JAR file of the generated package directory. The bundle JAR file needs a manifest, so create a file called manifest.mf with the following contents: Bundle-Name: My Start Command Bundle-Description: A 'start' command for the shell service. Bundle-Activator: test.mystartactivator Bundle-ClassPath:. Import-Package: org.apache.felix.shell,org.osgi.framework To create the bundle JAR file, issue the command: jar cfm mystart.jar manifest.mf -C c:\classes test This command creates a JAR file using the manifest you created and includes all of the classes in the test directory inside of the c:\classes directory. Once the bundle JAR file is created, you are ready to add the command service to the shell service; simply start Felix and install and start the bundle created by the above command. By doing so, the new mystart command is made available via the shell service. Security and the Shell Service The shell service security handling is quite simple, all security is handled by the standard OSGi framework mechanisms. For example, if a bundle should not be able to register a shell service, then it should not be given the corresponding service permission. Security handling may change in future release after some experience is gained through usage. Feedback Subscribe to the Felix users mailing list by sending a message to users-subscribe@felix.apache.org; after subscribing, email questions or feedback to users@felix.apache.org.