JBoss OSGi用户指南(第三章:应用服务器整合)

3 应用服务器整合

3.1 本章内容

l  概述

l  配置

l  特性

l  兼容性矩阵

3.2 概述

The JBoss OSGi framework is fully integrated into the WildFly Application Server.

JBoss OSGi框架已经被全部整合到WildFly应用服务器中。

OSGi bundles can be deployed like any other deployment that is supported by WildFly.

WildFly支持Bundle像部署其他应用一样的方式部署。

Hot deployment is supported by dropping an OSGi bundle into the 'deployments' folder.

Bundle放到‘deployments’目录,JBoss的热部署机制允许从此文件夹启动各个bundle

Management is supported through the Command Line Console or the web-based Console Management.

支持命令行方式及基于Web的方式进行管理。

OSGi components can interact with non OSGi services that are natively provided by WildFly.

WildFly支持OSGi组件与非OSGi的服务进行交互,由WildFly提供的原生功能。

This includes, but is not limited to, the Transaction Service and Naming Service (JNDI).

这个特性不仅仅包括事务服务和JNDI服务。

Standard OSGi Config Admin functionality is supported and integrated with the WildFly domain management layer.

WildFly域管理层中集成了标准的OSGi配置管理服务功能。

By default the OSGi subsystem is activated on-demand and not part of the standard configuration.

默认情况下,OSGi子系统是通过命令方式启动的,并且不是标准的配置。

When configured and when there is an OSGi bundle deployment the subsystem activates and the respective OSGi services become available.

当打开OSGi的配置或者是有bundle部署到系统中的动作发生时,OSGi服务自动变为激活状态。

3.3 配置

The OSGi subsystem is configured like any other subsystem in the standalone/domain XML descriptor.

OSGi子系统的配置与其他模块的配置在独立发行版的XML中是一样的。

The configuration options are:

配置选项:

l  Subsystem Activation - By default the OSGi subsystem is activated on-demand. The activation attribute can be set to 'eager' to initialize the subsystem on server startup.

激活子模块 – OSGi模块默认是通过命令激活的。可以通过在配置文件中将activation属性设置为‘eager’来使其在服务器启动的时候被激活。

l  Framework Properties - OSGi supports the notion of framework properties. Property values are of type string. A typical configuration includes a set of packages that are provided by the server directly. Please refer to the OSGi core specification for a list of standard OSGi properties.

框架属性 – OSGi支持框架属性的概念。属性值是字符串类型的。一个典型的配置一组由服务器直接提供的包。请参考OSGi核心规范并可以得到一组标准的OSGi属性。

l  Module Dependencies - The Framework can export packages from server system modules. The property 'org.jboss.osgi.system.modules.extra' contains a list of module identifiers that are setup as dependencies of the OSGi Framework.

模块依赖 框架允许从服务器系统模块导出包。属性'org.jboss.osgi.system.modules.extra'就是一组用来标识OSGi框架的依赖配置选项。

l  Capabilities - OSGi bundles can be installed by providing coordinates to the OSGi Repository. Supported coordinates include but are not limited to Maven coordinates and module identifiers.

Capabilities – Bundle支持通过提供的Maven坐标从OSGi仓库中安装bundle。所支持的坐标系统不仅仅支持Maven类型的坐标和模块标识符两种类型。

l  Config Admin properties - Supported are multiple configurations identified by persistent id (PID). Each configuration may contain multiple configuration key/value pairs. Below is a sample configuration for the OSGi subsystem.

l  配置管理属性 支持通过持久化IDPID)进行多配置操作。每一个配置信息都可能包含很多的键值对信息。下面就是一个OSGi模块的简单配置示例:

<subsystem xmlns="urn:jboss:domain:osgi:1.2" activation="lazy">

  <properties>

    <property name="org.jboss.osgi.system.modules.extra">org.apache.log4j</property>

    <property

name="org.osgi.framework.system.packages.extra">org.apache.log4j;version=1.2</property>

    <property name="org.osgi.framework.startlevel.beginning">1</property>

  </properties>

  <capabilities>

    <capability name="javax.servlet.api:v25"/>

    <capability name="javax.transaction.api"/>

    <capability name="org.apache.felix.log" startlevel="1"/>

    <capability name="org.jboss.osgi.logging" startlevel="1"/>

    <capability name="org.apache.felix.configadmin" startlevel="1"/>

    <capability name="org.jboss.as.osgi.configadmin" startlevel="1"/>

  </capabilities>

</subsystem>

...

<subsystem xmlns="urn:jboss:domain:configadmin:1.0">

  <configuration pid="org.apache.felix.webconsole.internal.servlet.OsgiManager">

     <property name="manager.root">jboss-osgi</property>

  </configuration>

</subsystem>

For more details on WildFly configuration see WildFly8 Documentation.

如果想要了解更多关于WildFly配置的细节,请参阅WildFly8文档。

3.4 特性

The current JBoss OSGi feature set in AS includes

AS版本中支持的JBoss OSGi特性如下:

l  Blueprint Container Support - The OSGi Blueprint Container allows bundles to contain standard blueprint descriptors, which can be used to create or consume OSGi services. Blueprint components consume OSGi services via injection.

Blueprint容器支持 – OSGi Blueprint容器允许bundle包含标准的Blueprint描述符,这些描述符可以用来创建或者消费OSGi服务。Blueprint组件通过注入的方式消费OSGi服务。

l  Config Admin Support - ConfigAdmin support is provided by the Apache Felix Configuration Admin Service.

配置管理支持 配置管理服务是由Apache Felix配置管理服务提供的。

l  Declarative Services Support - Declarative Services support is provided by the Apache Felix     Service Component Runtime.

声明式服务支持 声明式服务是由Apache Felix运行时组件服务提供的。

l  EventAdmin Support - EventAdmin support is provided by the Apache Felix Event Admin Service .

事件管理支持 Apache Felix事件管理服务支持。

l  Hot Deployment - Scans the deployments folder for new or removed bundles.

热部署 通过扫描deployments文件夹的方式来获取新添加的bundle或者删除bundle

l  HttpService and WebApp Support - HttpService and WebApp support is provided by Pax Web.

HTTP服务和WebAppa支持 – HTTP服务和WebApp服务是由Pax Web提供的。

l  JMX Support - There is local as well as remote JSR160 support for JMX. The OSGi-JMX MBeans are provided through the Apache Aries JMX implementation .

JMX支持 JMX本地及远程JSR 160的支持是相同的。OSGi-JMX MBean是由Apache Aries JMX实现来支持的。

l  JNDI Support - Components can access the JNDI InitialContext as a service from the registry.

JNDI支持 组件可以从注册的服务中访问JNDI InitialContext

l  JTA Support - Components can interact with the JTA Transaction Manager and User Transaction service.

JTA支持 组件之间可以通过JTA事务管理和用户事务服务来相互影响。

l  Logging System - The logging bridge writes OSGi Log Service LogEntries to the server log file.

日志服务 日志服务通过桥接的方式使用LogEntries服务将服务器日志写入文件。

l  Repository Support - The OSGi repository can be used to provision the subsystem.

仓库支持 – OSGi仓库可以用来对系统进行配置。

l  XML Parser Support - The Runtime comes with an implementation of an XMLParserActivator which provides access to a SAXParserFactory and DocumentBuilderFactory.

XML解析器支持 这个特性是通过一个XMLParserActivator实现来支持的,它可以访问SAXParserFactoryDocumentBuilderFactory

3.5 兼容性矩阵

clip_image001

3.6 控制台命令行接口

The JBoss OSGi Framework in JBoss AS 7 can be controlled via the AS 7 Command Line Interface (CLI).

JBoss AS 7版本中集成的JBoss OSGi版本是通过AS7提供的命令行接口(CLI)来控制的。

The CLI supports an interactive mode as well as a scripted mode, for more information on using and launching the CLI, see the Command Line Interface documentation.

CLI支持交互模式及脚本模式,如果想要了解更多使用和启动CLI的信息,请参阅命令行接口文档。

Supported operations:

支持的操作:

l  Framework Configuration 框架配置

n  Setting the Subsystem Activation Mode 设置模块激活模式

n  Framework Properties 框架属性

n  Capabilities

l  Framework Management 框架管理

n  Activate the framework 激活框架

n  Manage the Start Level 管理启动级别

l  Bundle Management Bundle管理

n  Deploying and Un-deploying 部署及卸载

n  Starting, Stopping and Inspecting Bundles 启动,停止和检查Bundle操作

n  Listing Bundles 枚举Bundle

l  Configuration Admin 配置管理

n  Adding Configuration 添加配置

n  Listing Configurations 枚举配置信息

n  Inspecting Configuration 检查配置信息

n  Removing Configuration 删除配置信息

3.6.1 框架配置

Framework configuration is stored in the AS 7 XML configuration file (e.g. standalone.xml).

框架的配置信息保存在AS7XML配置文件中(如standalone.xml

The CLI provides a management interface to this configuration.

CLI为这个配置提供了一个管理接口。

设置模块的启动模式

The activation mode of the OSGi subsystem within AS 7 is specified in the activation attribute.

AS7中的OSGi模块启动模式使用activation配置属性来设置。

It specifies whether the OSGi subsystem is activated on startup of the Application Server (eager) or only once the first bundle is deployed (lazy). By default the activation mode is set to lazy .

它用来配置OSGi模式在应用服务器启动的时候激活(配置值eager),或者在第一个bundle被部署的时候启动(配置值lazy)。默认的激活模式是lazy(延迟加载)。

To read the current activation mode:

通过CLI读取当前的激活模式:

[standalone@localhost:9999 /] /subsystem=osgi:read-attribute(name=activation)

{

    "outcome" => "success",

    "result" => "lazy"

}

To change the activation mode to eager

设置激活模式为eager

[standalone@localhost:9999 /] /subsystem=osgi:write-attribute(name=activation,value=eager)

{"outcome" => "success"}

 

框架属性

Framework properties are stored as resources in the /subsystem=osgi/property location.

框架属性配置信息保存在/subsystem=osgi/property

Note that any changes to OSGi framework properties require a framework restart in order to become effective.

值得注意的是,对于框架属性的任何修改都必须重新启动才能生效。

Adding a property: the following command adds the org.osgi.framework.system.packages.extra framework property with value org.foo.bar;version=1.2.

添加一项属性:下面的命令行的作用是将org.osgi.framework.system.packages.extra系统属性配置为org.foo.bar;version=1.2

[standalone@localhost:9999 /]

/subsystem=osgi/property=org.osgi.framework.system.packages.extra:add(value=org.foo.bar;version=1.2)

{"outcome" => "success"}

To list the framework properties use the ls command:

使用ls命令列出所有的框架属性:

[standalone@localhost:9999 /] ls /subsystem=osgi/property

org.osgi.framework.startlevel.beginning

org.osgi.framework.system.packages.extra

To read the value of an individual framework property:

读取单个框架属性的值:

[standalone@localhost:9999 /]

/subsystem=osgi/property=org.osgi.framework.startlevel.beginning:read-resource

{

    "outcome" => "success",

    "result" => {"value" => "1"}

}

To remove a framework property:

删除一个框架属性:

[standalone@localhost:9999 /]

/subsystem=osgi/property=org.osgi.framework.system.packages.extra:remove

{"outcome" => "success"}

 

Capabilities

The capability name is an abstract identifier for some functional capability.

对于一些功能性的capability来说capability名称是一个抽象的标识符。

We currently support module identifiers (i.e. a pointer to some bundle or module available in the AS 7 product repository) and maven coordinates (i.e. a maven artifact identifier availbale in the public jboss nexus repository).

目前,我们支持模块标识符(例如一个指向在AS7产品库中的bundle或者module的指针)和Maven坐标(例如一个在公共的Jboss联系仓库中的构建标识符)。

Capabilities are automatically loaded when the OSGi framework is launched. In the case of bundle capabilities, these can also be started as part of this process. The modules repository can be found in the modules/ subdirectory of the AS 7 installation, while the bundles repository can be found in the bundles/ subdirectory.

OSGi框架启动的时候Capabilities会自动被加载。对于bundleCapabilities来说,它还可以由其自身的进程启动。这些bundle的仓库可以在bundle或者子目录中找到,同时模块的仓库也可以在AS7安装目录的模块或者子目录下找到。

The example command below adds a bundle capability org.projectodd.stilts. The system will look for capabilities at startup in the modules/ and bundles/ directories. In this example the org.projectodd.stilts module/bundle jar is searched in the modules/org/projectodd/stilts/main/ and bundles/org/projectodd/stilts/main/ locations.

下面的例子演示了对bundle org.projectodd.stilts添加一个bundle capability。在系统启动的时候将会寻找模块//目录。在下面这个例子中,org.projectodd.stilts模块/包是在模块/org/projectodd/stilts/main/及包/org/projectodd/stilts/main/下面找到的。

[standalone@localhost:9999 /] /subsystem=osgi/capability=org.projectodd.stilts:add(startlevel=2)

{"outcome" => "success"}

Note that only bundles can be started, so specifying the startlevel as is done in this example does not apply to modules.

请注意,只有bundle才能被启动,所以这个例子中虽然显示指定了启动级别,但是却没有应用到模块中。

To list configured capabilities use the ls command:

使用ls命令枚举所有已经配置的capabilities属性:

[standalone@localhost:9999 /] ls /subsystem=osgi/capability

javax.servlet.api:v25           javax.transaction.api

org.apache.felix.configadmin    org.apache.felix.log

org.jboss.as.osgi.configadmin   org.jboss.osgi.logging

org.projectodd.stilts

To inspect a capability, use the read-resource command:

如果要检查一个capability,请使用read-resource命令:

[standalone@localhost:9999 /] /subsystem=osgi/capability=org.projectodd.stilts:read-resource

{

    "outcome" => "success",

    "result" => {"startlevel" => 2}

}

Removing a capability can be done with the remove command:

删除一个capability可以使用如下的命令:

[standalone@localhost:9999 /] /subsystem=osgi/capability=org.projectodd.stilts:remove      

{"outcome" => "success"}

 

3.6.2 框架管理

Framework management refers to the monitoring and manipulating the OSGi Framework runtime state.

框架管理的作用就是监视和管理OSGi框架的运行时状态。

激活框架

The framework can be activated using the activate command.

框架可以通过如下的命令激活:

[standalone@localhost:9999 /] /subsystem=osgi:activate

{"outcome" => "success"}

管理启动级别

The current framework start level can be in found in the startlevel attribute in the osgi subsystem.

当前框架的启动级别可以在OSGi子系统的启动级别属性中找到。

For example:

[standalone@localhost:9999 /] ls subsystem=osgi

bundle            capability        property          activation=lazy

startlevel=1

To change the start level, write the desired new value to the startlevel attribute:

使用如下的命令来改变启动级别:

[standalone@localhost:9999 /] /subsystem=osgi:write-attribute(name=startlevel,value=3)

{"outcome" => "success"}

3.6.3 Bundle管理

The CLI can be used to deploy, undeploy, start and stop bundles and to inspect the current bundle state.

CLI可以用来部署,卸载,启动,停止bundle以及检查当前bundle的状态。

部署和卸载

Deployment and un-deployment of bundles is done through the regular deployment channels in AS 7. To deploy a bundle:

Bundle的部署及卸载时通过AS7中的定期部署通道。用下面命令部署一个Bundle:

[standalone@localhost:9999 /] deploy /home/someuser/test-osgi-bundle.jar

Undeploying is done with the undeploy command:

利用下面的命令卸载一个Bundle:

[standalone@localhost:9999 /] undeploy test-osgi-bundle.jar

Note that deploying a bundle will place it in the INSTALLED state, to become functional OSGi bundles need to be started.

当部署一个bundle的时候它的初始状态是INSTALLED,要变为可以使用的bundle,需要调用start命令。

启动,停止和检查Bundle

To start the test-osgi-bundle.jar as deployed above, use the following command:

使用如下的命令启动上面提到的test-osgi-bundle.jar

[standalone@localhost:9999 /] /subsystem=osgi/bundle=test-osgi-bundle.jar:start

{"outcome" => "success"}

To inspect the bundle state:

检查Bundle状态:

[standalone@localhost:9999 /]

/subsystem=osgi/bundle=test-osgi-bundle.jar:read-resource(include-runtime=true)

{

    "outcome" => "success",

    "result" => {

        "id" => 8L,

        "location" => "test-osgi-bundle.jar",

        "startlevel" => 1,

        "state" => "ACTIVE",

        "symbolic-name" => "TestOSGiBundle",

        "type" => "bundle",

        "version" => "1.0.0"

    }

}

To stop the bundle, issue one of the following commands:

使用下面其中一个命令来停止一个bundle

[standalone@localhost:9999 /] /subsystem=osgi/bundle=8:stop

{"outcome" => "success"}

or

[standalone@localhost:9999 /] /subsystem=osgi/bundle=test-osgi-bundle.jar:stop

{"outcome" => "success"}

列出Bundle

Bundles can be listed by bundle ID using the ls command:

可以使用ls命令来列出所有的bundle ID

[standalone@localhost:9999 /] ls /subsystem=osgi/bundle

0   1   2   3   4   5   6   8

or in more detail using the read-children-resources command:

或者使用read-children-resources命令来得到更多详细的信息:

[standalone@localhost:9999 /]

/subsystem=osgi:read-children-resources(child-type=bundle,include-runtime=true)

{

    "outcome" => "success",

    "result" => {

        "0" => {

            "id" => 0L,

            "location" => "System Bundle",

            "startlevel" => 0,

            "state" => "ACTIVE",

            "symbolic-name" => "system.bundle",

            "type" => "bundle",

            "version" => "0.0.0"

        },

        "1" => {

            "id" => 1L,

...and so on...

 

3.6.4 配置管理

OSGi Configuration Admin support is provided through the configadmin subsystem.

OSGi配置管理是由configadmin子模块来提供支持的。

By default the JBoss OSGi runtime in AS 7 provides the Configuration Admin Service.

AS7中的JBoss OSGi运行时环境提供了配置管理服务的支持。

For more information on the OSGi Configuration Admin Service see chapter 104 in the OSGi Compendium Specification.

如果想要了解更多关于OSGi配置管理服务的信息请查看OSGi纲要规范104章。

Configuration Admin is a dynamic system that supports re-configuration during operation, therefore all the related management operations take effect immediately and value changes will be propagated to the relevant configuration consumers without the need for a restart.

配置管理是一个动态的系统,它支持在运行时支持重新配置,因此所有与配置管理相关的配置都会立即生效并且改变后的值将会传播到相关的配置消费者模块而不需要重启。

添加配置项

Configuration Admin configurations objects are identified by a Persistent Identified (PID) and carry an associated map of configuration values. Create a configuration using the add command:

使用持久化IDPID)来标识一个配置管理对象并且携带了一组相关的映射配置值。使用如下的命令来创建一个配置项:

[standalone@localhost:9999 /]

/subsystem=configadmin/configuration=org.example.myPid:add(entries={"key"=>"value","anotherkey"=>"an

value"})

{"outcome" => "success"}

列出所有的配置项

List all the available configurations with the ls command:

使用ls命令来列出所有可用的配置项:

[standalone@localhost:9999 /] ls /subsystem=configadmin/configuration

org.example.myPid

检查配置项

Read the configuration data with the read-resource command:

使用read-resource来读取配置数据:

[standalone@localhost:9999 /]

/subsystem=configadmin/configuration=org.example.myPid:read-resource

{

    "outcome" => "success",

    "result" => {"entries" => {

        "key" => "value",

        "anotherkey" => "another value"

    }}

}

删除配置项

Configuration objects can be removed by issuing the remove command on the configuration pid resource:

配置对象可以通过配置PID来删除:

[standalone@localhost:9999 /] /subsystem=configadmin/configuration=org.example.myPid:remove   

{"outcome" => "success"}

 

3.7 管理控制台

JBoss Application Server 7 comes with a web-based management console. The console can be launched by opening a browser at http://localhost:9990/console

JBoss应用服务器7自带了一个基于Web的管理控制台。控制台可以通过打开浏览器访问http://localhost:9990/console

Supported operations:

支持的操作:

l  Framework Configuration 框架配置

l  Framework Management 框架管理

l  Bundle Management Bundle管理

l  Configuration Admin 配置管理

3.7.1 框架配置

The OSGi framework can be configured via the OSGi -> Framework panels on the Profile section.

OSGi框架的配置可以通过Profile中的OSGi -> Framework面板来配置:

clip_image003

3.7.2 框架管理

The OSGi Framework can be activated through the Runtime Operations -> OSGi -> Framework panel in the Runtime section. Additionally, the current framework start level can be managed here.

OSGi框架可以运行时面板通过Operations -> OSGi -> Framework面板来激活。除此之外,当前框架的启动级别也在这部分配置。

clip_image005

3.7.3 Bundle管理

Bundles can be deployed through the general AS 7 Management Console Deployment mechanism.

Bundle可以通过通用的AS7管理控制台部署机制来部署。

clip_image007

After deploying and enabling the deployment, the bundle needs to be started, which can be done from the Runtime Operations -> OSGi -> Bundles panel in the Runtime section. Other information about bundles deployed in the Framework is available here too.

当部署和部署生效后,Bundle需要启动,可以在Runtime Operations -> OSGi -> Bundles面板中进行操作。其他已经在框架中已经部署的Bundle信息也是可用的。

clip_image009

3.7.4 配置管理

The JBoss OSGi runtime in AS 7 provides the Configuration Admin Service.

AS7中的JBoss OSGi运行时提供了配置管理服务。

For more information on the OSGi Configuration Admin Service see chapter 104 in the OSGi Compendium Specification.

如果想要了解关于OSGi配置管理服务的更多信息,请参阅OSGi纲要规范第104章。

Configuration Admin is a dynamic system that supports re-configuration during operation, therefore all the related management operations take effect immediately and value changes will be propagated to the relevant configuration consumers without the need for a restart.

配置管理师一个动态的系统并支持在操作时重新配置,因此所有相关的配置信息都会在修改后立即生效,并将相关的配置传播到相关的配置消费那边儿不需要重启。

The Configuration Admin subsystem can be managed through the Core -> Config Admin panel in the Profile section.

配置管理模块可以在Profile节中的Core -> Config Admin面板中进行管理。

clip_image011

 

posted @ 2014-01-25 23:29  Rush_SONG  阅读(2287)  评论(0编辑  收藏  举报