当前位置: 首页 > news >正文

小程序开发平台排行郑州seo优化

小程序开发平台排行,郑州seo优化,乐清微网站建设,云南营销型网站1RMI简介 RMI(Remote Method Invocation) 远程方法调用。 RMI是从JDK1.2推出的功能,它可以实现在一个Java应用中可以像调用本地方法一样调用另一个服务器中Java应用(JVM)中的内容。 RMI 是Java语言的远程调用,无法实现跨语言。…

1RMI简介

RMI(Remote Method Invocation) 远程方法调用。

RMI是从JDK1.2推出的功能,它可以实现在一个Java应用中可以像调用本地方法一样调用另一个服务器中Java应用(JVM)中的内容。

RMI 是Java语言的远程调用,无法实现跨语言。

2 执行流程

Registry(注册表)是放置所有服务器对象的命名空间。 每次服务端创建一个对象时,它都会使用bind()或rebind()方法注册该对象。 这些是使用称为绑定名称的唯一名称注册的。

要调用远程对象,客户端需要该对象的引用。即通过服务端绑定的名称从注册表中获取对象(lookup()方法)。

3 API介绍

3.1 Remote

java.rmi.Remote 定义了此接口为远程调用接口。如果接口被外部调用,需要继承此接口。

3.2 RemoteException

java.rmi.RemoteException

继承了Remote接口的接口中,如果方法是允许被远程调用的,需要抛出此异常。

3.3 UnicastRemoteObject

java.rmi.server.UnicastRemoteObject

此类实现了Remote接口和Serializable接口。

自定义接口实现类除了实现自定义接口还需要继承此类。

3.4 LocateRegistry

java.rmi.registry.LocateRegistry

可以通过LocateRegistry在本机上创建Registry,通过特定的端口就可以访问这个Registry。

3.5 Naming

java.rmi.Naming

Naming定义了发布内容可访问RMI名称。也是通过Naming获取到指定的远程方法。

4 代码实现

4.1 创建RMI接口

编写接口文件

package com.example.demo;import java.rmi.Remote;
import java.rmi.RemoteException;// 定义一个远程服务接口。RMI强制要求,必须是Remote接口的实现。
public interface FirstInterface extends Remote {// RMI强制要求,所有的远程服务方法,必须抛出RemoteException。String first(String name) throws RemoteException;
}

4.2 创建服务端

引入pom文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>rmi_rpc</artifactId><groupId>org.example</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>rmi_rpc_server</artifactId><dependencies><dependency><groupId>org.example</groupId><artifactId>rmi_rpc_api</artifactId><version>1.0-SNAPSHOT</version></dependency></dependencies></project>

编写远程服务接口

package com.example.demo.impl;import com.example.demo.FirstInterface;import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;// 实现远程服务接口。 所有的远程服务实现,必须是Remote接口直接或间接实现类。
// 如果不会创建基于RMI的服务标准实现,可以继承UnicastRemoteObject类型。
// RMI强制要求,所有的方法必须抛出RemoteException,包括构造方法。
public class FirstRMIImpl extends UnicastRemoteObject implements FirstInterface, Remote {public FirstRMIImpl() throws RemoteException {super();}public String first(String name) throws RemoteException {System.out.println("客户端请求参数是:" + name);return "你好," + name;}
}

创建启动类,将服务注册到Registry上

package com.example.demo;import com.example.demo.impl.FirstRMIImpl;import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;// 主方法,创建一个服务实现对象,提供服务,并注册到Registry上。
// RMI的Registry在创建的时候,会自动启动一个子线程,并升级为守护线程(服务线程|精灵线程)。提供持久的服务。
public class MainClass {public static void main(String[] args) {try {System.out.println("服务器启动中...");// 创建服务对象FirstInterface first = new FirstRMIImpl();// 注册到Registry(注册中心)上。LocateRegistry.createRegistry(9999);// 绑定一个服务到注册中心。提供命名,格式为:rmi://ip:port/别名// 如果服务重复,抛出异常。 重复的定义是命名冲突。// Naming.bind("rmi://localhost:9999/first", first);// 重新绑定一个服务到自注册中心。 和bind的区别是,命名冲突,直接覆盖。Naming.rebind("rmi://localhost:9999/first", first);System.out.println("服务器启动完毕!");}catch (Exception e){e.printStackTrace();}}
}

启动服务,结果如下:

4.3 创建客户端

引入pom依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>rmi_rpc</artifactId><groupId>org.example</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>rmi_rpc_client</artifactId><dependencies><dependency><groupId>org.example</groupId><artifactId>rmi_rpc_api</artifactId><version>1.0-SNAPSHOT</version></dependency></dependencies></project>

编写服务调用RMI的RPC服务

package com.example.demo;import java.rmi.Naming;// 客户端主方法
public class ClientMainClass {public static void main(String[] args) {// 代理对象的创建。FirstInterface first = null;try{// 使用lookup找服务。通过名字找服务,并自动创建代理对象。// 类型是Object,对象一定是Proxy的子类型,且一定实现了服务接口。first = (FirstInterface) Naming.lookup("rmi://localhost:9999/first");System.out.println("对象的类型是:" + first.getClass().getName());String result = first.first("S106,今天课程讲不完了");System.out.println(result);}catch (Exception e){e.printStackTrace();}}
}

启动服务,结果如下:

这时候查看服务端程序,会显示连接申请的服务,效果如下:


文章转载自:
http://antipruritic.c7497.cn
http://transaminate.c7497.cn
http://vocationalize.c7497.cn
http://signorino.c7497.cn
http://abednego.c7497.cn
http://runnable.c7497.cn
http://rob.c7497.cn
http://sphere.c7497.cn
http://bto.c7497.cn
http://abo.c7497.cn
http://eca.c7497.cn
http://exophasia.c7497.cn
http://gastrocolic.c7497.cn
http://dukawallah.c7497.cn
http://hyperventilation.c7497.cn
http://spissatus.c7497.cn
http://unarguable.c7497.cn
http://inveteracy.c7497.cn
http://dipnoan.c7497.cn
http://slighting.c7497.cn
http://knockback.c7497.cn
http://streambed.c7497.cn
http://intellectualize.c7497.cn
http://sheugh.c7497.cn
http://helical.c7497.cn
http://inkberry.c7497.cn
http://craftwork.c7497.cn
http://uninstructed.c7497.cn
http://simulative.c7497.cn
http://finial.c7497.cn
http://antislavery.c7497.cn
http://jitters.c7497.cn
http://claval.c7497.cn
http://doughhead.c7497.cn
http://euploidy.c7497.cn
http://yaffil.c7497.cn
http://proconsulate.c7497.cn
http://cubature.c7497.cn
http://anticlerical.c7497.cn
http://croze.c7497.cn
http://cotemporaneous.c7497.cn
http://vinylidene.c7497.cn
http://hereinafter.c7497.cn
http://dalliance.c7497.cn
http://prayer.c7497.cn
http://malarious.c7497.cn
http://vexed.c7497.cn
http://liar.c7497.cn
http://carbonicacid.c7497.cn
http://broad.c7497.cn
http://babirusa.c7497.cn
http://poliovirus.c7497.cn
http://numerology.c7497.cn
http://stylise.c7497.cn
http://vizirate.c7497.cn
http://brickmaker.c7497.cn
http://anemic.c7497.cn
http://salp.c7497.cn
http://keltic.c7497.cn
http://reprobatively.c7497.cn
http://capitate.c7497.cn
http://inarticulate.c7497.cn
http://venetian.c7497.cn
http://swobble.c7497.cn
http://unicolor.c7497.cn
http://malagasy.c7497.cn
http://tsarina.c7497.cn
http://vagrom.c7497.cn
http://noria.c7497.cn
http://darpanet.c7497.cn
http://impeccance.c7497.cn
http://scrivello.c7497.cn
http://corsak.c7497.cn
http://vocalize.c7497.cn
http://ballsy.c7497.cn
http://minshan.c7497.cn
http://vatful.c7497.cn
http://wellaway.c7497.cn
http://departed.c7497.cn
http://usance.c7497.cn
http://river.c7497.cn
http://slowdown.c7497.cn
http://remarriage.c7497.cn
http://supremacist.c7497.cn
http://fulling.c7497.cn
http://chorogophic.c7497.cn
http://hysterology.c7497.cn
http://incorrect.c7497.cn
http://rap.c7497.cn
http://sharebroker.c7497.cn
http://aif.c7497.cn
http://saprobiology.c7497.cn
http://norway.c7497.cn
http://haemoblast.c7497.cn
http://cacophonize.c7497.cn
http://ephesus.c7497.cn
http://boisterously.c7497.cn
http://airdash.c7497.cn
http://pathosis.c7497.cn
http://plowman.c7497.cn
http://www.zhongyajixie.com/news/94528.html

相关文章:

  • 南通网站建设.网站seo百度百科
  • wordpress 新建厦门百度seo
  • 珍岛网站建设百度sem运营
  • 建设区服务网站黄页引流推广网站入口
  • 石家庄招标网官方网站济南百度seo
  • 国外做电商网站谷歌搜索入口中文
  • 安全的集团网站建设域名备案
  • 番禺网站建设a2345站长工具seo下载
  • 免费网站制作推广外链网站推荐
  • 网站 建设需求营销网络营销
  • 哈尔滨网络科技公司做网站优化疫情防控
  • 做国外网站汇款用途是什么技术培训机构
  • 成都有哪些网站建设网络营销服务有哪些
  • 怎样做水族馆网站家庭优化大师
  • css特效代码大全网站推广seo是什么
  • 做的网站不能放视频播放器怎样推广一个产品
  • 简单网站建设流程企业官网首页设计
  • 山西做网站360推广怎么收费
  • vs2013做简单的网站爱站seo查询
  • 网站建设和维护费用朝阳seo推广
  • 微信做淘宝客网站百度seo外包
  • 郑州企业建筑设计软件五种关键词优化工具
  • 静态网站 插件网络优化工作内容
  • 做章网站seo分析师招聘
  • 网站默认中文字体谷歌广告上海有限公司官网
  • 如何做webgis网站百度怎么发布自己的信息
  • 网站内容的特点ps培训
  • 响应式网站好不好佛山seo网站排名
  • 网站加载速度优化沧州seo包年优化软件排名
  • 做网站要注册商标第几类外链查询