从另一个 java 程序触发函数 [英] Trigger functions from another java program

查看:23
本文介绍了从另一个 java 程序触发函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个服务器应用程序和两个独立的客户端应用程序(两者都具有不同的功能 - 一个用于前台,另一个用于后台).一切都是用 Java 编写的.

We've got a server app and two stand alone client apps (both with different functionality - one for front office and the other for back office). Everything is written in Java.

我们现在需要的是:如果两个应用程序都在运行 - 单击一个应用程序中的按钮 -> 检查另一个应用程序是否打开并触发该应用程序上的某些功能(显示消息、打开框架)

What we need right now: If both apps are running - click on a button in one app -> checks to see if the other app is open and triggers some functionality (display a message, open a frame) on that app

如果另一个应用程序没有打开 -> 它应该显示一条消息说明.

if the other app isn't open -> it should display a message saying so.

谁能指出我正确的方向来实现这一目标.我能给出的最好的现实例子是:如何在 Web 浏览器中单击 iTunes 链接打开 iTunes 应用程序(如果已安装)并打开相关的应用商店页面.

Can anyone point me in the right direction to achieve this. The best real life example I can give is: how clicking on the an itunes link in the web browser opens the iTunes application if installed and to the relevant appstore page.

我们的应用程序根本不处理网站.一切都使用 Swing.

Our applications don't deal with websites at all. Everything uses Swing.

推荐答案

实现应用间通信没有最佳"方式,但有很多方式;最好的将是最适合您的环境的:网络条件、防火墙、调用次数、同步与异步等...

There is no "best" way to achieve inter-app communications but there are many ways; the best one will be the one that fits best your environment: network conditions, firewalls, number of calls, synchronous vs asynchronous, etc...

通常使用以下任一方式进行通信:

Usually communication is achieved using either:

  • 远程过程调用:一个应用程序基本上调用另一个应用程序上的函数/方法并传递参数.RPC 通常是同步的:响应在同一个通信/事务中发送
  • 消息:一个应用程序向另一个应用程序发送消息,另一个应用程序可能会回复其他消息.消息传递通常是异步的.使用某些协议(如 REST)时,两者之间的界限可能非常模糊.

在 Java 世界中,

In the Java world,

  • RPC 通常使用任一方法来实现

  • RPC is usually achieved using either

  • RMI:仅限 Java 的解决方案;易于实施;不太喜欢防火墙.
  • SOAP Web 服务:不是以 Java 为中心;难以实施;充满陷阱;网络友好.
  • RMI: Java only solution; easy to implement; does not like firwalls much.
  • SOAP Web services: not Java centric; hard to implement; full of traps; network friendly.

可以使用

  • JMS:仅限 Java;相当容易实现但异步;在高负载下非常强大
  • JSON/XML HTTP/s 消息传递:这里有许多协议来自最安全的协议,例如 AS2 到 RNIF、纯 XML/Json POST 等...这些与网络和语言无关,但总是需要一些工作才能实现.
  • JMS: Java only; rather easy to implement but asynchronous; extremely powerful on high loads
  • JSON/XML HTTP/s Messaging: there are many protocols here from the most secure like AS2 to RNIF, plain XML/Json POST etc... These are network and language agnostic but always require some work to implement.

一种混合方法是 REST 由于易于实施的优点而变得非常流行和网络友好性,但有不够正式的缺点.它是一种技术而不是一种规范.我会查看有关 JAX-RS 和框架(如 RestletJersey 帮助您入门.

An hybrid approach is REST which has become very popular due to the benefits of an easy implementation and network friendliness but has the drawbacks of not being very formalized. it is a technology rather than a specification. I would look at documentation around JAX-RS and frameworks like Restlet and Jersey to get you started.

(编辑)我故意没有提到用 Java 套接字开发你自己的套接字.根据定义,IO 是不纯的并且通常是多线程的:IO 非常很难做到正确.如果您真的坚持走这条路,至少,请使用合适的框架(例如 Apache Mina 或 Netty)的帮助.

(Edit) I purposely did not mention developing your own with Java sockets. IO is by definition impure and often multithreaded: IO is very hard to get right. If you really insist going down that route, at least, use the help of a proper framework like Apache Mina or Netty.

这篇关于从另一个 java 程序触发函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆