简体   繁体   English

在同一JVM上使用JavaEE应用程序共享对象(使用JNDI)

[英]Share object between JavaEE applications on the same JVM (using JNDI)

I'm running a JBoss AS 7.1.3.Final installation with a lot of applications. 我正在运行JBoss AS 7.1.3.Final安装,有很多应用程序。 One of those applications provides common resources and functionallities used by all applications (let's call it framework ). 其中一个应用程序提供了所有应用程序使用的公共资源和功能(让我们称之为框架 )。 I'm also planning to move to WildFly 8, if this is an useful information for your answer. 我还打算转到WildFly 8,如果这是一个有用的信息,你的答案。

All applications should only be accessible, if the framework is available (up and running). 如果框架可用(启动并运行),则只能访问所有应用程序。 My current implementation to achive this dependency is not that nice** and as I'm currently re-designing some parts of the environment, I'm looking for a much neater solution for it. 我目前实现这种依赖性的实现并不是那么好**而且我正在重新设计环境的某些部分,我正在寻找一种更简洁的解决方案。 My first idea was to create some kind of a manager which will be instantiated by the application server and is available to all applications. 我的第一个想法是创建一种管理器,它将由应用程序服务器实例化,并可供所有应用程序使用。 So after an application is started, it could register itself on the manager and as soon as the framework is up, the applications will be notified. 因此,在应用程序启动后,它可以在管理器上注册自己,并且一旦框架启动,将通知应用程序。

Is this possible using the JNDI of the JVM where all applications + framework are running? 这是否可以使用JVM的JNDI,其中所有应用程序+框架都在运行? How must this be implemented? 如何实施? It's really hard to find useful information about how the JNDI works and what is possible with it. 很难找到关于JNDI如何工作以及它可能带来什么的有用信息。 Do you have any other, simplier ideas, how to share a class instance between applications? 您是否有任何其他更简单的想法,如何在应用程序之间共享类实例?

Thank you. 谢谢。

** Currently I'm using a EJB-timer in the applications and a singleton EJB in the framework. **目前我在应用程序中使用EJB计时器,在框架中使用单例EJB。 The framework is available as soon as the EJB lookup succeeds. 一旦EJB查找成功,该框架就可用。

-- -

Edit #1 Some more informations as requested by Nikos Paraskevopoulos 编辑#1根据Nikos Paraskevopoulos的要求提供更多信息

  • One functionionality that is provided by the framework is the maintenance mode . 框架提供的一个功能是维护模式 The applications will check, right after startup, if it is blocked for normal users. 如果正常用户被阻止,应用程序将在启动后立即检查。 It will also receive notifications about planned maintenances. 它还将收到有关计划维护的通知。 (central DB, the application has no rights on it) (中央DB,应用程序没有权利)
  • Common stylesheets or layouts are deployed with the framework. 使用框架部署常见样式表或布局。
  • The user informations are provided by the framework. 用户信息由框架提供。 (central DB, the application has no rights on it) (中央DB,应用程序没有权利)

The main problem is: How could I avoid any timers? 主要问题是:我怎么能避免任何计时器? I have no idea, how I could ensure, that the framework is up before everything else. 我不知道,我怎么能确保框架在其他一切之前完成。

A few thoughts: 一些想法:

  • JBoss has the capability of ordering deployments according to their dependencies. JBoss能够根据其依赖性对部署进行排序。 See here and here . 看到这里这里 So, if all the "applications" depend explicitly on the "framework", your problem may be solved. 因此,如果所有“应用程序”明确依赖于“框架”,那么您的问题可能会得到解决。

  • It seems you have a quite strongly coupled configuration. 看来你的配置非常强大。 Would it be possible to decouple them, eg provide the service through web services (SOAP/REST)? 是否可以将它们分离,例如通过Web服务(SOAP / REST)提供服务? Of course this introduces extra overhead for the communication and the refactoring... 当然这会为通信和重构带来额外的开销......

  • JNDI can be seen (very roughly) as a name to object map shared across the applications. JNDI可以(非常粗略地)看作跨应用程序共享的对象映射的名称。 As such, you may share stuff through it. 因此,您可以通过它分享内容。 But I do not see how will you solve the timing problem, ie wait for a service to be available before using it from the "applications". 但我不知道你将如何解决时间问题,即在“应用程序”中使用服务之前等待服务可用。 The manager component you mention can be placed in JNDI. 您提到的管理器组件可以放在JNDI中。

This is not a complete answer, but it would not fit as a comment either. 这不是一个完整的答案,但它也不适合作为评论。 Maybe if you presented more details on the nature of the applications, the frameworks used etc, you could get more specific answers. 也许如果您提供有关应用程序性质,使用的框架等的更多详细信息,您可以获得更具体的答案。

Good luck anyway 祝你好运


Edit #1: 编辑#1:

  • Maintenance mode : This may be nice for using with JNDI. 维护模式 :这可能适合与JNDI一起使用。 A servlet filter that intercepts every (applicable) request will check a global JNDI name; 拦截每个(适用的)请求的servlet过滤器将检查全局JNDI名称; if it is not found (ie framework not started) or it is false , it will short-circuit the processing of the request, sending back the "maintenance mode" page. 如果没有找到(即框架未启动)或者它是false ,它将使请求的处理短路,发回“维护模式”页面。 The framework will have to set a Boolean in the global JNDI name as soon as it has started and maintain its value, ie set it to false if maintenance mode is active. 一旦启动并保持其值,框架就必须在全局JNDI名称中设置一个Boolean值,即如果维护模式处于活动状态,则将其设置为false

  • Common stylesheets : This is really covered by the maintenance mode flag, I believe. 常见样式表 :我相信维护模式标志确实涵盖了这一点。 Layouts : It depends on the view technology/layouts technology. 布局 :这取决于视图技术/布局技术。

  • User information : This is a good candidate for SOAP/REST implementation. 用户信息 :这是SOAP / REST实现的良好候选者。 It is not expected to be called frequently, so I assume overhead will not matter. 它不会被频繁调用,所以我认为开销无关紧要。

I think OSGi is the technology you should consider. 我认为OSGi是你应该考虑的技术。 Basically you have an OSGi container with applications (called bundles) which provide or consume services. 基本上,您有一个OSGi容器,其中包含提供或使用服务的应用程序(称为bundle)。 So you would have a framework service which is consumed by all applications. 因此,您将拥有一个由所有应用程序使用的框架服务。 JBoss is an OSGi container, as far as I know. 据我所知,JBoss是一个OSGi容器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM