Is your existing application monolithic or tiered in seperate processes/layers?
If tiered, you can convert the middle/app-tier to run in an OSGi container.
In my team's experience, we've found trying to do web-stuff in OSGi painful. Other pain points are Hibernate and Jakarta Commons Logging.
I find the OSGi specs pretty readable and I recommend you print out the flowchart that shows the algorithm for class loading. I'll guarantee you'll have moments of, "why am I getting a NoClassDefFoundError?": the flowchart will tell you why.
至于运行时,您不能只添加现有应用程序并使其启用 OSGi。 它需要被设计成动态的。 Spring DM 可以轻松地向您隐藏这一点,但它仍然存在,您需要注意它。
I really like the Apache Felix tutorials. However, I think in general leveraging OSGi in your application isn't one of those "let's use this framework, because it's hype" decision. It's more of a design question, but then everything that OSGi gives you in terms of design, you can have with vanilla Java as well.
As for the runtime, you cannot just add an existing application and make it OSGi enabled. It needs to be design to be dynamic. Spring DM makes it easy to hide that from you, but it's still there and you need to be aware of it.
There are a couple of thinks to keep in mind if you are starting with OSGi.
As mentioned elsewhere in this thread, knowing about classloading is really important. In my experience everybody sooner or later runs into problems with it.
Another important thing to remember is: never hold references! Have a look at the whiteboard pattern on which the services concept of OSGi is build (see the link in one of the other answers).
In my experience you should not try to convert a monolitic application into an OSGi-based one. This usually leads to a badly and unmanageable mess. Start anew.
Download one of the freely available stand-alone OSGi implementations. I found Knopflerfish rather good and stable (I use it in many projects). It also comes with lots of source code. You can find it here: http://www.knopflerfish.org
Well, since you can not have one part OSGi and one part non-OSGi you'll need to make your entire app OSGi. In its simplest form you make a single OSGi bundle out of your entire application. Clearly this is not a best practice but it can be useful to get a feel for deploying a bundle in an OSGi container (Equinox, Felix, Knoplerfish, etc).
To take it to the next level you'll want to start splitting your app into components, components should typically have a set of responsibilities that can be isolated from the rest of your application through a set of interfaces and class dependencies. Identifying these purely by hand can range from rather straightforward for a well designed highly cohesive but loosely coupled application to a nightmare for interlocked source code that you are not familiar with.
Some help can come from tools like JDepend which can show you the coupling of Java packages against other packages/classes in your system. A package with low efferent coupling should be easier to extract into an OSGi bundle than one with high efferent coupling. Even more architectural insight can be had with pro tools like Structure 101.
Purely on a technical level, working daily with an application that consists of 160 OSGi bundles and using Spring DM I can confirm that the transition from "normal" Spring to Spring DM is largely pain free. The extra namespace and the fact that you can (and should) isolate your OSGi specific Spring configuration in separate files makes it even easier to have both with and without OSGi deployment scenarios.
OSGi is a deep and wide component model, documentation I recommend:
OSGi R4 Specification: Get the PDFs of the Core and Compendium specification, they are canonical, authoritative and very readable. Have a shortcut to them handy at all times, you will consult them.
Read up on OSGi best practices, there is a large set of things you can do but a somewhat smaller set of things you should do and there are some things you should never do (DynamicImport: * for example).
这个答案是在问题提出近三年后出现的,但是 link 我刚刚发现非常好,特别是对于使用 maven 的初学者来说。 一步一步的解释。
This answer comes nearly 3 years after the question was asked, but the link I just found is really good, especially for starters using maven. A step-by-step explanation.
When learning a new technology rich tooling gets you into things without big headaches. At this point the community at ops4j.org provides a rich toolset called "PAX" which includes:
Pax Runner: Run and switch between Felix, Equinox, Knopflerfish and Concierge easily
Pax Construct: Construct, Organize & Build OSGi projects with maven easily
Pax Drone: Test your OSGi bundles with Junit while being framework independent (uses PaxRunner)
Then there are many implementations of OSGi compendium services:
Pax Logging (logging),
Pax Web (http service),
Pax Web Extender (war support),
Pax Coin (configuration),
Pax Shell (shell implementation, part of the next osgi release)
and much more.
.. and there is a helpful, framework independend community, - but thats now advertisement ;-)
发布评论
评论(8)
尝试http://neilbartlett.name/blog/osgibook/。 本书提供了 OSGi 最佳实践的实际示例。
Try http://neilbartlett.name/blog/osgibook/. The book has hands on examples with OSGi best practices.
尝试 http://njbartlett.name/files/osgibook_preview_20091217.pdf
或
http://www.manning.com/hall/
第二个不是我自己读过的书,但我听说过好东西关于它。
第一个对我来说非常有用。 他首先带您了解架构,然后实际操作 OSGi。
Try http://njbartlett.name/files/osgibook_preview_20091217.pdf
OR
http://www.manning.com/hall/
The second is not a book i have read myself but I have heard good things about it.
The first was very useful for me. He takes you through the architecture initially and then it's hands on OSGi.
您现有的应用程序是单一的还是分层在单独的进程/层中?
如果分层,您可以将中间/应用层转换为在 OSGi 容器中运行。
根据我团队的经验,我们发现尝试在 OSGi 中执行 Web 操作非常痛苦。 其他痛点包括 Hibernate 和 Jakarta Commons Logging。
我发现 OSGi 规范非常可读,我建议您打印出显示类加载算法的流程图。 我保证您会有这样的时刻:“为什么我会收到 NoClassDefFoundError?”:流程图会告诉您原因。
Is your existing application monolithic or tiered in seperate processes/layers?
If tiered, you can convert the middle/app-tier to run in an OSGi container.
In my team's experience, we've found trying to do web-stuff in OSGi painful. Other pain points are Hibernate and Jakarta Commons Logging.
I find the OSGi specs pretty readable and I recommend you print out the flowchart that shows the algorithm for class loading. I'll guarantee you'll have moments of, "why am I getting a NoClassDefFoundError?": the flowchart will tell you why.
我真的很喜欢 Apache Felix 教程。 然而,我认为总的来说,在应用程序中利用 OSGi 并不是“让我们使用这个框架,因为它是炒作”的决定之一。 这更多的是一个设计问题,但是 OSGi 在设计方面为您提供的一切,您也可以通过普通 Java 获得。
至于运行时,您不能只添加现有应用程序并使其启用 OSGi。 它需要被设计成动态的。 Spring DM 可以轻松地向您隐藏这一点,但它仍然存在,您需要注意它。
I really like the Apache Felix tutorials. However, I think in general leveraging OSGi in your application isn't one of those "let's use this framework, because it's hype" decision. It's more of a design question, but then everything that OSGi gives you in terms of design, you can have with vanilla Java as well.
As for the runtime, you cannot just add an existing application and make it OSGi enabled. It needs to be design to be dynamic. Spring DM makes it easy to hide that from you, but it's still there and you need to be aware of it.
如果您开始使用 OSGi,则需要记住一些想法。
正如本线程其他地方提到的,了解类加载非常重要。 根据我的经验,每个人迟早都会遇到问题。
另一件要记住的重要事情是:永远不要保留参考资料! 看一下构建 OSGi 服务概念的白板模式(请参阅其他答案之一中的链接)。
根据我的经验,您不应该尝试将单一应用程序转换为基于 OSGi 的应用程序。 这通常会导致严重且难以管理的混乱。 重新开始。
下载免费提供的独立 OSGi 实现之一。 我发现 Knopflerfish 相当好且稳定(我在很多项目中使用它)。 它还附带大量源代码。 您可以在这里找到它: http://www.knopflerfish.org
另一个很好的教程可以是在这里找到的。 https://pro40.abac.com/deanhiller/cgi-bin/ moin.cgi/OsgiTutorial
OSGi 联盟的 Peter Kriens 进行了一次精彩的采访: http://www.infoq.com/interviews/osgi-peter-kriens。 他的主页和博客(总是值得一读,可以在这里找到:http://www.aqute.biz
There are a couple of thinks to keep in mind if you are starting with OSGi.
As mentioned elsewhere in this thread, knowing about classloading is really important. In my experience everybody sooner or later runs into problems with it.
Another important thing to remember is: never hold references! Have a look at the whiteboard pattern on which the services concept of OSGi is build (see the link in one of the other answers).
In my experience you should not try to convert a monolitic application into an OSGi-based one. This usually leads to a badly and unmanageable mess. Start anew.
Download one of the freely available stand-alone OSGi implementations. I found Knopflerfish rather good and stable (I use it in many projects). It also comes with lots of source code. You can find it here: http://www.knopflerfish.org
Another good tutorial can be found here. https://pro40.abac.com/deanhiller/cgi-bin/moin.cgi/OsgiTutorial
Peter Kriens of the OSGi Alliance gave a nice interview: http://www.infoq.com/interviews/osgi-peter-kriens. His homepage and blog (which is always a good read can be found here: http://www.aqute.biz
好吧,由于您不能拥有一部分 OSGi 和一部分非 OSGi,因此您需要将整个应用程序制作为 OSGi。 以最简单的形式,您可以从整个应用程序中创建一个 OSGi 包。 显然,这不是最佳实践,但它对于了解在 OSGi 容器(Equinox、Felix、Knoplerfish 等)中部署包的感觉可能很有用。
为了将其提升到一个新的水平,您需要开始将应用程序拆分为组件,组件通常应该具有一组职责,可以通过一组接口和类依赖项将它们与应用程序的其余部分隔离。 纯粹手动识别这些内容的范围可以从对于设计良好的高度内聚但松散耦合的应用程序的相当简单到对于您不熟悉的互锁源代码的噩梦。
一些帮助可以来自 JDepend 等工具,它可以向您展示 Java 包与其他包的耦合/系统中的类。 具有低传出耦合的包应该比具有高传出耦合的包更容易提取到 OSGi 包中。 使用 Structure 101 等专业工具可以获得更多架构洞察。
纯粹在技术层面上,每天使用由 160 个 OSGi 包组成的应用程序并使用 Spring DM,我可以确认从“正常”Spring 到 Spring DM 的过渡基本上是轻松的。 额外的命名空间以及您可以(并且应该)将特定于 OSGi 的 Spring 配置隔离在单独的文件中这一事实,使得拥有和不拥有 OSGi 部署方案变得更加容易。
OSGi 是一个深入而广泛的组件模型,我推荐的文档:
一些链接:
Spring DM Google 群组 在我看来反应非常迅速且友好经验Spring DM Google 群组是不再活跃,并已作为 Gemini Blueprint 项目移至 Eclipse.org,该项目有一个论坛 此处。
Well, since you can not have one part OSGi and one part non-OSGi you'll need to make your entire app OSGi. In its simplest form you make a single OSGi bundle out of your entire application. Clearly this is not a best practice but it can be useful to get a feel for deploying a bundle in an OSGi container (Equinox, Felix, Knoplerfish, etc).
To take it to the next level you'll want to start splitting your app into components, components should typically have a set of responsibilities that can be isolated from the rest of your application through a set of interfaces and class dependencies. Identifying these purely by hand can range from rather straightforward for a well designed highly cohesive but loosely coupled application to a nightmare for interlocked source code that you are not familiar with.
Some help can come from tools like JDepend which can show you the coupling of Java packages against other packages/classes in your system. A package with low efferent coupling should be easier to extract into an OSGi bundle than one with high efferent coupling. Even more architectural insight can be had with pro tools like Structure 101.
Purely on a technical level, working daily with an application that consists of 160 OSGi bundles and using Spring DM I can confirm that the transition from "normal" Spring to Spring DM is largely pain free. The extra namespace and the fact that you can (and should) isolate your OSGi specific Spring configuration in separate files makes it even easier to have both with and without OSGi deployment scenarios.
OSGi is a deep and wide component model, documentation I recommend:
Some links:
The Spring DM Google Group is very responsive and friendly in my experienceThe Spring DM Google Group is no longer active and has moved to Eclipse.org as the Gemini Blueprint project which has a forum here.
这个答案是在问题提出近三年后出现的,但是 link 我刚刚发现非常好,特别是对于使用 maven 的初学者来说。 一步一步的解释。
This answer comes nearly 3 years after the question was asked, but the link I just found is really good, especially for starters using maven. A step-by-step explanation.
当学习新技术时,丰富的工具可以让你轻松入门。
此时,ops4j.org 的社区提供了一个名为“PAX”的丰富工具集,它包括:
然后有许多 OSGi 概要服务的实现:
..并且有一个有用的、独立框架的社区,-但这就是现在的广告;-)
When learning a new technology rich tooling gets you into things without big headaches.
At this point the community at ops4j.org provides a rich toolset called "PAX" which includes:
Then there are many implementations of OSGi compendium services:
.. and there is a helpful, framework independend community, - but thats now advertisement ;-)