The basic RMI implementation in Java
来源:互联网 发布:什么叫java参数传递 编辑:程序博客网 时间:2024/05/02 01:54
package com.my.study.rmi;import java.io.Serializable;/* * Entity must implements Serializable interface */public class Person implements Serializable {private static final long serialVersionUID = 1L;private int id;private String name;public int getId() {return id;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}}
package com.my.study.rmi;import java.rmi.Remote;import java.rmi.RemoteException;/* * 1, Interface must extend Remote, * 2, All functions must throw RemoteException */public interface IPersonService extends Remote {Person findPersonById(int id) throws RemoteException;}
package com.my.study.rmi;import java.rmi.RemoteException;import java.rmi.server.UnicastRemoteObject;/* * Implementation must extends UnicastRemoteObject */public class PersonServiceImpl extends UnicastRemoteObject implementsIPersonService {private static final long serialVersionUID = 1L;public PersonServiceImpl() throws RemoteException {}public Person findPersonById(int id) throws RemoteException {Person p = new Person();p.setId(id);p.setName("XiaoMing");return p;}}
package com.my.study.rmi;import java.rmi.Naming;import java.rmi.registry.LocateRegistry;public class Server {public static void main(String[] args) {try {IPersonService personService = new PersonServiceImpl();// Listen 8888 portLocateRegistry.createRegistry(8888);// Rebind a object to a path, path format: rmi://127.0.0.1:<PORT>/<serviceName>Naming.rebind("rmi://127.0.0.1:8888/personService", personService);System.out.println("Service startup successfully.");} catch (Exception e) {e.printStackTrace();}}}
package com.my.study.rmi;import java.rmi.Naming;public class Client {public static void main(String[] args) {try {// Use Naming.lookup() to get binded object.IPersonService person = (IPersonService) Naming.lookup("rmi://localhost:8888/personService");System.out.println("Name: " + person.findPersonById(2).getName());} catch (Exception e) {e.printStackTrace();}}}
0 0
- The basic RMI implementation in Java
- md5 implementation in java
- The String class is provided in the Java library. Provide your own implementation for the following
- RMI Plug-in for Eclipse version 2.0 -- Java RMI - The Print Server Tutorial
- RMI-IIOP in the enterprise
- Dynamic Array Implementation in Java
- interface & implementation demo in Java
- the implementation of system call in linux
- The Implementation of RFCOMM in Android
- 【学习笔记】Thinking in java (第三版)第五章 隐藏实现(Hiding the implementation)
- Modern Compiler Implementation in Java: the MiniJava Project http://www.cambridge.org/resources/052182060X/
- The basic of Java
- Implementation of SOAP protocol in Java
- Mozilla Rhino: implementation of JavaScript in Java
- Spring RMI java.rmi.NoSuchObjectException: no such object in table
- The implementation of anonymous methods in C# and its consequences
- Notes on the implementation of encryption in Android 3.0
- How to configure the JSF implementation in WAS
- Sins of a Solar Empire P8
- C语言新标准C11
- 小女子竺霞有礼了
- 使用 jQuery.i18n.properties 实现Web 前端的国际化
- Using FileUpload(Apache文件上传组件)
- The basic RMI implementation in Java
- 判断系统是否安装了flash
- 第十二周项目3(2)
- android 2048游戏实现
- 12周。。。银行系统加强版
- HDU 4745 Two Rabbits
- [LeetCode]Min Stack
- 软件工程作业2---小游戏
- 索隆的难题