简体   繁体   English

WAR文件中的BlazeDS和Java类

[英]BlazeDS and Java class in WAR file

Hi I have a java class which has been deployed as WAR web application in a BlazeDS/Spring server sitting on JBOSS. 嗨,我有一个Java类,它已经作为WAR Web应用程序部署在JBOSS上的BlazeDS / Spring服务器中。

Apart from the Flex application which will access the WAR file, I also need to start some server side process's which will initiate BlazeDS "pushes" to the Flex client via AMF messaging. 除了将访问WAR文件的Flex应用程序之外,我还需要启动一些服务器端进程,该进程将通过AMF消息传递将BlazeDS“推送”到Flex客户端。

What is the best way to implement this server side process? 实施此服务器端过程的最佳方法是什么? - Should it just be a class with a main() method in the WAR file which gets called from the command line? -它应该只是在命令行中调用WAR文件中具有main()方法的类吗? Can this be done - not sure you can run a class in a WAR file from command line? 可以这样做-不确定您可以从命令行在WAR文件中运行类吗? - Should it just be a class with a main() method in a JAR file which gets called from the command line? -它是否应该是从命令行调用的JAR文件中具有main()方法的类?

Not sure what the standard practise here is. 不知道这里的标准做法是什么。 The key is that the process needs to be started on the BlazeDS server to push data out (not on the Flex client). 关键是需要在BlazeDS服务器上启动该过程以将数据推出(而不是在Flex客户端上)。

Any help would he appreacited Mike 他会给麦克的任何帮助

First off, are you using the latest Spring/BlazeDS integration? 首先,您是否正在使用最新的Spring / BlazeDS集成? If not, I highly recommend checking it out here . 如果没有,我强烈建议在这里检查一下 It can greatly simplify setting up message destinations for push messaging. 它可以大大简化为推送消息传递设置消息目的地的过程。 It also will allow you to use JMS and Spring Integration message destinations as well as integrate Spring Security if you so choose. 它还允许您使用JMS和Spring Integration消息目标,以及根据需要集成Spring Security。

Now to answer your question. 现在回答您的问题。 What are the life-cycle requirements for your data push service? 您的数据推送服务的生命周期要求是什么? Do you want to be able to control the parameters of this data push (ie, starting and stopping it, frequency, etc.) from other classes? 您是否希望能够从其他类控制此数据推送的参数(即,启动和停止它,频率等)? Creating this service using Spring will allow you to inject it into other beans for control as you so desire. 使用Spring创建此服务将使您可以根据需要将其注入到其他bean中进行控制。

I currently have a similar use case in which I use a BlazeDS message destination to "push" telemetry data to a client browser. 我目前有一个类似的用例,其中我使用BlazeDS消息目标将遥测数据“推送”到客户端浏览器。 I setup a "service" class that is instantiated by Spring as a singleton instance. 我设置了一个“服务”类,该类由Spring实例化为一个单例实例。

If you do not need external control of this singleton, I then suggest you use an annotated @PostConstruct or "init" method for creating a Thread and starting it with an anonymous Runnable representing your main loop. 如果不需要此单例的外部控制,则建议您使用带批注的@PostConstruct或“ init”方法来创建线程,并使用代表您的主循环的匿名Runnable来启动它。 If your service needs to push data at a predefined frequency, you might consider a java.util.concurrent.ScheduledExecutorService. 如果您的服务需要以预定义的频率推送数据,则可以考虑使用java.util.concurrent.ScheduledExecutorService。

Either way, you will also need to setup an annotated @PreDestory or "destroy" method that will execute just before the singleton instance is destroyed. 无论哪种方式,您都将需要设置一个带注释的@PreDestory或“ destroy”方法,该方法将在销毁单例实例之前执行。 This will allow you to insert code to safely stop the loop Thread or ScheduledFuture and clean up any necessary resources before the Spring container is shut down. 这将允许您插入代码,以在Spring容器关闭之前安全地停止循环Thread或ScheduledFuture并清理所有必要的资源。

If you want further interaction with your service, you can manipulate it from other classes (such as Web controllers, etc.) using a service interface. 如果您想与服务进行进一步的交互,则可以使用服务接口从其他类(例如Web控制器等)操纵它。 Have your class implement this interface and inject your class into other classes using this interface. 让您的类实现此接口,然后使用此接口将您的类注入其他类。 For a more daring solution, you might consider using dm Server or another OSGi container and create an OSGi service. 对于更大胆的解决方案,您可以考虑使用dm Server或其他OSGi容器并创建OSGi服务。

Please let me know if you need further help regarding this process or if there are specific details that I can illuminate further. 如果您需要有关此过程的进一步帮助,或者是否有我可以进一步阐明的具体细节,请告诉我。

Marshall your a star - thanks for that! 马歇尔你的明星-谢谢!

I am using the Spring @PostConstruct and this is working a treat. 我正在使用Spring @PostConstruct,并且正在工作。 It appears that the Monitoring class is getting instantiated by Spring automatically and then the @PostConstruct method is being called. 看来Spring会自动实例化Monitoring类,然后调用@PostConstruct方法。

I also had to include the following in the Spring config file to get this to work: 我还必须在Spring配置文件中包含以下内容才能使其正常工作:

xmlns:context=springframework.org/schema/context springframework.org/schema/context springframework.org/schema/context/spring-context-2.5.xsd xmlns:context = springframework.org / schema / context springframework.org/schema/context springframework.org/schema/context/spring-context-2.5.xsd

Within the @PostConstruct method I have implemented a simple java.util.Timer which pushes data to the Flex client are regular intervals. 在@PostConstruct方法中,我实现了一个简单的java.util.Timer,它定期将数据推送到Flex客户端。 (I still need to set it up as a singleton via Spring - im a bit of Spring newbie!) (我仍然需要通过Spring将其设置为单例-有点像Spring新手!)

Does the ScheduledExecutorService offer any benefits above the Timer class for my purposes? 为了我的目的,ScheduledExecutorService是否可以提供Timer类之外的任何好处?

Once again thanks Regards Michael 再次感谢Michael

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

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