- 浏览: 267164 次
- 性别:
- 来自: 天津
文章分类
最新评论
-
1260533105:
uncaught invalidstateerror:Fail ...
WebSocket -
sh747665463:
压力好大啊
【转】如果你不知道接下去学什么,就看这个
JavaRMI
RMI(Remote Method Invocation,远程方法调用)是用Java在JDK1.1中实现的,它大大增强了Java开发分布式应用的能力。Java作为一种风靡一时的网络开发语言,其巨大的威力就体现在它强大的开发分布式网络应用的能力上,而RMI就是开发百分之百纯Java的网络分布式应用系统的核心解决方案之一。其实它可以被看作是RPC的Java版本。但是传统RPC并不能很好地应用于分布式对象系统。而Java RMI 则支持存储于不同地址空间的程序级对象之间彼此进行通信,实现远程对象之间的无缝远程调用。 RMI目前使用Java远程消息交换协议JRMP(Java Remote Messaging Protocol)进行通信。JRMP是专为Java的远程对象制定的协议。因此,Java RMI具有Java的"Write Once,Run Anywhere"的优点,是分布式应用系统的百分之百纯Java解决方案。用Java RMI开发的应用系统可以部署在任何支持JRE(Java Run Environment Java,运行环境)的平台上。但由于JRMP是专为Java对象制定的,因此,RMI对于用非Java语言开发的应用系统的支持不足。不能与用非Java语言书写的对象进行通信。 Java Remote Method Invocation ( RMI -- Java远程方法调用)允许您使用Java编写分布式对象。本文将介绍RMI的优点以及如何将其连接到现有的和原有的系统中,以及与用Java 编写的组件的连接。 RMI为采用Java对象的分布式计算提供了简单而直接的途径。这些对象可以是新的Java对象,也可以是围绕现有API的简单的Java包装程序。Java体现了“编写一次就能在任何地方运行的模式。而RMI可将Java模式进行扩展,使之可在任何地方运行”。 因为RMI是以Java为核心的,所以,它将Java的安全性和可移植性等强大功能带给了分布式计算。您可将代理和业务逻辑等属性移动到网络中最合适的地方。如果您要扩展Java在系统中的使用,RMI将使您充分利用其强大功能。 RMI可利用标准Java本机方法接口JNI与现有的和原有的系统相连接。RMI还可利用标准JDBC包与现有的关系数据库连接。RMI/JNI和RMI/JDBC相结合,可帮助您利用RMI与目前使用非Java语言的现有服务器进行通信,而且在您需要时可扩展Java在这些服务器上的使用。RMI可帮助您在扩展使用时充分利用Java的强大功能。
附件例子,留作以后查看。
1.定义远程接口;
2.定义服务器类;
3.实现server(服务器端程序入口);
4.实现client(客户端程序入口);
5.启动RMI注册表工具(windows: start rmiregistry);
6.启动server(eclipse下点击‘运行’);
7.启动client(eclipse下点击‘运行’);
1.sever不能和远程接口(product)处于同一个package下,否则会报找不到远程接口(product)的错误,default包除外。
2.执行第五步(启动RMI注册表工具(windows: start rmiregistry))过程时,“start rmiregistry”命令必须要在server(服务器端程序入口)类所在文件路径下执行。
3.注意不要将server(服务器端程序入口)中“NamingEnumeration<NameClassPair> e = namingContext.list("rmi:");”写成““NamingEnumeration<NameClassPair> e = namingContext.list("rmi");”。
4.如果没有重新启动RMI注册表工具而直接重新启动server(服务器端程序入口)会提示相关服务器对象已经注册,解决方法有两个:第一是在重启server(服务器端程序入口)时,首先重启RMI注册表工具;第二种方法是将server(服务器端程序入口)中“namingContext.bind("rmi:toaster", p1);
namingContext.bind("rmi:microwave", p2);”
改为“
namingContext.rebind("rmi:toaster", p1);
namingContext.rebind("rmi:microwave", p2);”。
具体原因可参考bind和rebind的相关API。
====================================================================++++
A Note About Security
The server and client programs run with a security manager installed. When you run either program, you need to specify a security policy file so that the code is granted the security permissions it needs to run. Here is an example policy file to use with the server program:grant codeBase "file:/home/ann/src/" { permission java.security.AllPermission; };Here is an example policy file to use with the client program:
grant codeBase "file:/home/jones/src/" { permission java.security.AllPermission; };For both example policy files, all permissions are granted to the classes in the program's local class path, because the local application code is trusted, but no permissions are granted to code downloaded from other locations. Therefore, the compute engine server restricts the tasks that it executes (whose code is not known to be trusted and might be hostile) from performing any operations that require security permissions. The example client's
Pi
task does not require any permissions to execute.In this example, the policy file for the server program is named
server.policy
, and the policy file for the client program is namedclient.policy
.
Starting the Server
Before starting the compute engine, you need to start the RMI registry. The RMI registry is a simple server-side bootstrap naming facility that enables remote clients to obtain a reference to an initial remote object. It can be started with thermiregistry
command. Before you executermiregistry
, you must make sure that the shell or window in which you will runrmiregistry
either has noCLASSPATH
environment variable set or has aCLASSPATH
environment variable that does not include the path to any classes that you want downloaded to clients of your remote objects.To start the registry on the server, execute the
rmiregistry
command. This command produces no output and is typically run in the background. For this example, the registry is started on the hostzaphod
.
Microsoft Windows (use start rmiregistryjavaw
ifstart
is not available):
Solaris OS or Linux: rmiregistry &
By default, the registry runs on port 1099. To start the registry on a different port, specify the port number on the command line. Do not forget to unset your
CLASSPATH
environment variable.
Microsoft Windows: start rmiregistry 2001
Solaris OS or Linux: rmiregistry 2001 &
Once the registry is started, you can start the server. You need to make sure that both the
compute.jar
file and the remote object implementation class are in your class path. When you start the compute engine, you need to specify, using thejava.rmi.server.codebase
property, where the server's classes are network accessible. In this example, the server-side classes to be made available for downloading are theCompute
andTask
interfaces, which are available in thecompute.jar
file in thepublic_html\classes
directory of userann
. The compute engine server is started on the hostzaphod
, the same host on which the registry was started.
Microsoft Windows: java -cp c:\home\ann\src;c:\home\ann\public_html\classes\compute.jar -Djava.rmi.server.codebase=file:/c:/home/ann/public_html/classes/compute.jar -Djava.rmi.server.hostname=zaphod.east.sun.com -Djava.security.policy=server.policy engine.ComputeEngine
Solaris OS or Linux: java -cp /home/ann/src:/home/ann/public_html/classes/compute.jar -Djava.rmi.server.codebase=http://zaphod/~ann/classes/compute.jar -Djava.rmi.server.hostname=zaphod.east.sun.com -Djava.security.policy=server.policy engine.ComputeEngine
The above
java
command defines the following system properties:
- The
java.rmi.server.codebase
property specifies the location, a codebase URL, from which the definitions for classes originating from this server can be downloaded. If the codebase specifies a directory hierarchy (as opposed to a JAR file), you must include a trailing slash at the end of the codebase URL.- The
java.rmi.server.hostname
property specifies the host name or address to put in the stubs for remote objects exported in this Java virtual machine. This value is the host name or address used by clients when they attempt to communicate remote method invocations. By default, the RMI implementation uses the server's IP address as indicated by thejava.net.InetAddress.getLocalHost
API. However, sometimes, this address is not appropriate for all clients and a fully qualified host name would be more effective. To ensure that RMI uses a host name (or IP address) for the server that is routable from all potential clients, set thejava.rmi.server.hostname
property.- The
java.security.policy
property is used to specify the policy file that contains the permissions you intend to grant.
Starting the Client
Once the registry and the compute engine are running, you can start the client, specifying the following:
- The location where the client serves its classes (the
Pi
class) by using thejava.rmi.server.codebase
property- The
java.security.policy
property, which is used to specify the security policy file that contains the permissions you intend to grant to various pieces of code- As command-line arguments, the host name of the server (so that the client knows where to locate the
Compute
remote object) and the number of decimal places to use in the calculationStart the client on another host (a host named
ford
, for example) as follows:
Microsoft Windows: java -cp c:\home\jones\src;c:\home\jones\public_html\classes\compute.jar -Djava.rmi.server.codebase=file:/c:/home/jones/public_html/classes/ -Djava.security.policy=client.policy client.ComputePi zaphod.east.sun.com 45
Solaris OS or Linux: java -cp /home/jones/src:/home/jones/public_html/classes/compute.jar -Djava.rmi.server.codebase=http://ford/~jones/classes/ -Djava.security.policy=client.policy client.ComputePi zaphod.east.sun.com 45
Note that the class path is set on the command line so that the interpreter can find the client classes and the JAR file containing the interfaces. Also note that the value of the
java.rmi.server.codebase
property, which specifies a directory hierarchy, ends with a trailing slash.After you start the client, the following output is displayed:
3.141592653589793238462643383279502884197169399The following figure illustrates where the
rmiregistry
, theComputeEngine
server, and theComputePi
client obtain classes during program execution.
When the
ComputeEngine
server binds its remote object reference in the registry, the registry downloads theCompute
andTask
interfaces on which the stub class depends. These classes are downloaded from either theComputeEngine
server's web server or file system, depending on the type of codebase URL used when starting the server.Because the
ComputePi
client has both theCompute
and theTask
interfaces available in its class path, it loads their definitions from its class path, not from the server's codebase.Finally, the
Pi
class is loaded into theComputeEngine
server's Java virtual machine when thePi
object is passed in theexecuteTask
remote call to theComputeEngine
object. ThePi
class is loaded by the server from either the client's web server or file system, depending on the type of codebase URL used when starting the client.
- RMITest.rar (10.2 KB)
- 下载次数: 1
- RMITest--LocateRegistry.rar (12.4 KB)
- 下载次数: 1
发表评论
-
jvm回顾
2018-11-29 09:10 0一、运行时数据区域 1、程序计数器(program co ... -
转一篇泛型介绍不错的文章
2018-08-02 19:10 643泛型,一个孤独的守门者。 大家可能会有疑问,我为什么叫做泛 ... -
jstat
2018-02-04 11:36 433jps(Java Virtual Machine Proce ... -
转:ant 入门
2017-12-09 17:58 6821)什么是Ant ant是构建工具 2)什么是构 ... -
廉颇老矣?n年没写ant,发现生疏了,这不是我想要的
2017-12-09 11:37 619毕业10年,差不多6年没有碰ant了,昨天解决一个siga ... -
jdk 9 hellomodules
2017-10-03 20:45 4741、准备 lib mods src/cn.gbase ... -
转:Java 9,OSGi以及模块化的未来
2017-10-03 19:19 0ava 9,OSGi以及模块化的 ... -
转:Java 9,OSGi以及模块化的未来
2017-10-03 19:12 0<div class="iteye-blog- ... -
转:Java 8 中的 Streams API 详解
2017-10-02 21:39 434Java 8 中的 Streams API 详 ... -
转:装饰模式
2017-01-01 10:46 501一个有意思的装饰模式样例。 Java与模式:装饰(D ... -
转:Java中多态性的实现
2016-08-25 11:10 534Java中多态性的实现 什么是多态 面向对象的三大 ... -
深入理解Java 8 Lambda(语言篇——lambda,方法引用,目标类型和默认方法)
2016-01-22 14:35 2661作者:Lucida 微博:@peng_gong 豆瓣 ... -
转:permGen space out of memory
2013-11-21 12:53 1018PermGen space的全称是Permanent Gen ... -
trove high performance collections for java
2013-06-02 10:31 718trove high performance collec ... -
kettle Could not find the main class. Program will exit err
2013-06-01 15:44 0I am new in KETTLE. I am tryi ... -
jvm参数集合
2013-05-26 15:42 686一、内存分配 -xms java heap初始化时的大小 ... -
jvm优化配置
2013-05-26 15:16 921server 和 client两种模 ... -
http 错误代码
2013-04-25 09:00 678HTTP 400 – 请求无效HTTP 401.1 – 未授 ... -
JDBC 规范4.1 翻译 (一)
2012-12-28 14:41 23从今天开始希望每天抽出来一点时间把JDBC规范4. ... -
jconsole配置远程监控
2012-11-29 16:59 1643java -Djava.rmi.server. ...
相关推荐
**基于JAVA RMI的聊天室** Java Remote Method Invocation(RMI)是Java平台提供的一种用于在分布式环境中调用远程对象的方法。在这个“基于JAVA RMI的聊天室”项目中,开发者利用RMI技术构建了一个简单的多用户...
Java RMI(Remote Method Invocation)技术是Java平台中用于分布式计算的一种机制,它允许一个Java对象调用远程计算机上的另一个Java对象的方法。在本案例中,“java RMI技术实现的网络聊天室”是一个使用RMI构建的...
Java RMI(Remote Method Invocation,远程方法调用)是一种Java技术,允许在分布式环境中执行远程对象的方法。这个技术的核心是序列化和反序列化过程,它使得对象可以在网络上进行传输。然而,这个特性也可能引入...
根据提供的文件信息,我们可以深入探讨Java RMI(Java Remote Method Invocation)的相关知识点,包括其概念、原理、体系结构以及一个具体的示例。 ### RMI的概念 RMI是一种Java技术,它允许开发者创建分布式应用...
Java RMI(Remote Method Invocation,远程方法调用)是Java平台提供的一种分布式计算技术,它允许在不同的Java虚拟机之间进行远程对象的调用。RMI使得开发者可以像调用本地对象一样调用网络上的对象,极大地简化了...
Java Remote Method Invocation(Java RMI)是Java编程语言中用于在网络间进行远程对象调用的技术。它是Java平台的标准部分,允许程序员在分布式环境中调用对象的方法,就像它们在同一台计算机上一样。Java RMI对于...
### Java RMI (Remote Method Invocation) 概念与实践 #### 一、Java RMI简介 Java RMI(Remote Method Invocation)是一种允许调用不同Java虚拟机(JVM)上方法的机制。这些JVM可能位于不同的机器上,也可能在同一...
Java RMI(Remote Method Invocation,远程方法调用)是Java平台提供的一种分布式计算技术,它允许在不同网络节点上的Java对象之间进行透明的交互。在Java RMI中,一个对象可以调用另一个位于不同JVM(Java虚拟机)...
Java RMI(Remote Method Invocation,远程方法调用)是Java平台提供的一种用于分布式计算的技术,它允许一个Java对象调用另一个在不同 JVM(Java虚拟机)上的对象的方法。这个简单的示例展示了如何创建一个基本的...
Java RMI(Remote Method Invocation,远程方法调用)是Java平台中用于构建分布式对象系统的关键技术。它允许Java应用程序在不同Java虚拟机(JVM)之间进行远程方法调用,这些虚拟机可能位于同一台计算机或网络上的...
Java RMI(Remote Method Invocation)是Java编程语言中用于实现远程过程调用的一种技术。它允许运行在客户机上的程序调用位于远程服务器上的对象的方法,从而实现分布式计算。RMI的核心思想是通过接口隐藏底层网络...
Java RMI (Remote Method Invocation) 是一种用于在Java应用程序之间进行远程通信的技术。为了提高RMI通信的安全性,我们可以使用SSL (Secure Sockets Layer) 或其后继者TLS (Transport Layer Security) 进行加密。...
Java RMI(Remote Method Invocation,远程方法调用)是Java平台提供的一种分布式计算技术,它允许Java对象在不同的网络环境中进行交互,就像调用本地方法一样。RMI是构建分布式应用的重要工具,尤其适用于需要跨...
Java RMI,全称为Remote Method Invocation,是Java平台上的一个标准API,用于实现分布式计算,使得在不同Java虚拟机(JVM)上的对象能够互相调用方法。这个"java rmi HelloWorld版(源码)"的压缩包文件提供了一个...
Java RMI(Remote Method Invocation,远程方法调用)是Java平台提供的一种用于分布式计算的技术,它允许一个Java对象调用另一个在不同JVM上的对象的方法。这个简单的例子将引导我们了解如何利用Java RMI实现远程...
**JAVA RMI(远程方法调用)详解** Java RMI(Remote Method Invocation)是Java平台上的一个核心特性,它允许Java程序在不同的JVM(Java虚拟机)之间进行分布式计算,实现了对象间的远程调用。RMI使得开发者可以像...
Java Remote Method Invocation (RMI) 是Java平台提供的一种强大的分布式计算技术,允许在不同网络环境中的Java对象之间进行远程方法调用。这个可运行实例是一个实际应用RMI概念的示例,它展示了如何构建和运行一个...
Java RMI(Remote Method Invocation,远程方法调用)是Java平台提供的一种分布式计算技术,它允许在不同的Java虚拟机之间进行方法调用,仿佛这些方法都在本地对象上执行一样。这个"JAVA RMI简单例子"旨在帮助我们...
### Java RMI 分布式编程心得详解 #### 一、Java RMI 分布式编程概述 Java远程方法调用(Remote Method Invocation, RMI)是一种让位于不同Java虚拟机(Java Virtual Machine, JVM)上的对象能够互相调用彼此方法...
Java RMI 完整版 Java Remote Method Invocation(RMI)是一种分布式对象技术,允许使用 Java 编写分布式对象,不同的 Java 虚拟机(JVM)之间进行对象间的通讯。这使得应用程序(Application)可以远程调用方法,...