`
kylinsoong
  • 浏览: 239629 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

JDK Source Code & java.rmi.server.RMISocketFactory

阅读更多

Today's Source code analysing series I will dive into java.rmi.server.RMISocketFactory, First the UML Diagram:


 This Diagram containing 1 abstract Class: RMISocketFactory, and 3 Interface: RMIClientSocketFactory, RMIServerSocketFactory, RMIFailureHandler.

 

RMIServerSocketFactory only has one method createServerSocket(int port), through this method we can create a server socket on the specified port. RMIServerSocketFactory instance is used by the RMI runtime in order to obtain server sockets for RMI calls. Usually RMIServerSocketFactory associated with a remote object is used to obtain the ServerSocket which accept incoming calls from clients. The Sorce Code:

import java.io.*;
import java.net.*;

public interface RMIServerSocketFactory {

    public ServerSocket createServerSocket(int port)throws IOException;
}

 

 

RMIClientSocketFactory also has one method createSocket(String host, int port), through this method we can create a client socket connected to the specified host and port. Like the RMIServerSocketFactory, RMIClientSocketFactory instance is also used by the RMI runtime in order to obtain client sockets for RMI calls. The Socket RMIClientSocketFactory create can establish a connection with the ServerSoket, This connection use to transmit info between Client and Server. Also the Source Code:

 

import java.io.*;
import java.net.*;

public interface RMIClientSocketFactory {

    public Socket createSocket(String host, int port)throws IOException;
}

 

RMIFailureHandler defined a method failure(Exception ex), While the RMI Runtime is unable to create a ServerSocket via the RMISocketFactory, the failure callback will be invoked. There are no any implemetaion in JDK, if you wanna use this handler mechenism you must impementing yourseves handler. If no failure handler is installed, the default behavior is to attempt to re-create the ServerSocket. the handler can be installed through RMISocketFacotry.setFailureHandler, we will see later. The failure method returns a boolean indicating whether the runtime should attempt to re-create the ServerSocket. The Source Code:

 

public interface RMIFailureHandler {

    public boolean failure(Exception ex);
}

 

RMISocketFactory is an abstract Class, has 3 private stataic atrributes, implementing both RMIClientSocketFactory and RMIClientSocketFactory interface,  RMISocketFactory make this 2 interfaces method abstract, the user implement by themself. RMISocketFactory instance is used by the RMI runtime in order to obtain client and server sockets for RMI calls. An application may use the setSocketFactory method to request that the RMI runtime use its socket factory instance instead of the default implementation. The Source Code:

import java.io.*;
import java.net.*;

public abstract class RMISocketFactory implements RMIClientSocketFactory, RMIServerSocketFactory{

    private static RMISocketFactory factory = null;
    private static RMISocketFactory defaultSocketFactory;
    private static RMIFailureHandler handler = null;

    public RMISocketFactory() {
		super();
    }
    
    public abstract Socket createSocket(String host, int port) throws IOException;

    public abstract ServerSocket createServerSocket(int port) throws IOException;

    public synchronized static void setSocketFactory(RMISocketFactory fac) throws IOException {
    	if (factory != null) {
			throw new SocketException("factory already defined");
		}
		SecurityManager security = System.getSecurityManager();
		if (security != null) {
			security.checkSetFactory();
		}
		factory = fac;
    }

    public synchronized static RMISocketFactory getSocketFactory() {
		return factory;
    }

    public synchronized static RMISocketFactory getDefaultSocketFactory() {
		if (defaultSocketFactory == null) {
			defaultSocketFactory = new sun.rmi.transport.proxy.RMIMasterSocketFactory();
		}
		return defaultSocketFactory;
    }

    public synchronized static void setFailureHandler(RMIFailureHandler fh) {
		SecurityManager security = System.getSecurityManager();
		if (security != null) {
			security.checkSetFactory();
		}
		handler = fh;
    }

    public synchronized static RMIFailureHandler getFailureHandler() {
		return handler;
    }
}

  

Inspiration From this Code:

--will be put later

 

  

  • 大小: 19.3 KB
0
0
分享到:
评论
1 楼 di1984HIT 2013-11-22  
鞋的不错。

相关推荐

    RMI.rar_Java RMI_java.rmi_java.rmi.Remot_remote

    Java RMI(远程方法调用)是Java编程语言中的一项核心技术,自JDK 1.1版本起就被引入,用于构建分布式系统。RMI允许Java对象在不同的Java虚拟机(JVMs)之间进行交互,仿佛这些对象是在同一台机器上一样。这种技术的...

    bcprov-jdk15on-1.54.jar bcprov-ext-jdk15on-1.54.jar下载

    2.将下载的两个JAR文件复制到:JDK安装目录\jre\lib\ext下,例如我的就是D:\Program Files (x86)\java\JDK1.6\jre\lib\ext 3.打开java.security文件:在JDK安装目录\jre\lib\security下的java.security文件。

    JDK1.8下载 : jdk_8.0.1310.11_64.zip

    JDK是 Java 语言的软件开发工具包,主要用于移动设备、嵌入式设备上的java应用程序。JDK是整个java开发的核心,它包含了JAVA的运行环境(JVM+Java系统类库)和JAVA工具. JDK是学好Java的第一步。不管是你要学习java...

    bcprov-ext-jdk15on-1.54.jar,bcprov-jdk15on-1.54.jar

    在Java开发过程中,有时会遇到一个异常:“java.lang.RuntimeException: Could not generate DH keypair”。这个异常通常是由于Java加密库的问题导致的,特别是在进行安全通信,如使用SSL/TLS协议时,系统尝试生成...

    bcprov-ext-jdk15on-1.54.jar、bcprov-jdk15on-1.54.jar和ssl-provider-jvm16-0.2.jar

    标题中的"bcprov-ext-jdk15on-1.54.jar"和"bcprov-jdk15on-1.54.jar"是Bouncy Castle提供的Java加密库,用于增强Java平台的安全性。Bouncy Castle是一个开源项目,提供强大的加密算法实现,包括SSL/TLS协议支持,...

    jdk.tools-1.7.jar

    `jdk.tools-1.7.jar` 是Java Development Kit(JDK)1.7版本的一部分,它包含了用于开发、编译、调试和管理Java应用程序的工具类库。这个特定的JAR文件尤其重要,因为它提供了许多核心的命令行工具,如`javac`(Java...

    bcprov-ext-jdk15on-1.54.jar和bcprov-jdk15on-1.54.jar压缩文件

    《深入解析bcprov-jdk15on与bcprov-ext-jdk15on:Java加密库的秘密武器》 在Java开发中,加密技术是至关重要的,它保障了数据的安全传输和存储。bcprov-jdk15on和bcprov-ext-jdk15on是Bouncy Castle项目提供的两个...

    bcprov-ext-jdk15on-154.jar和bcprov-jdk15on-154.jar

    "bcprov-ext-jdk15on-154.jar" 和 "bcprov-jdk15on-154.jar" 是两个非常重要的工具jar包,它们属于Bouncy Castle加密库,专门用于解决Java中的加密和安全问题,尤其是当系统遇到"javax.net.ssl.SSLException: java....

    bcprov-jdk15on-1.54.jarr和bcprov-ext-jdk15on-1.54.jar和教程.rar

    bcprov-jdk15on-1.54.jarr和bcprov-ext-jdk15on-1.54.jar和教程 win10 64位 java1.8连接SQL Server2008报错 驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接

    jdk 1.8 linux 32&64 .zip

    Java开发工具包(Java Development Kit,简称JDK)是Oracle公司提供的用于开发和运行Java应用程序的软件包。在本压缩包文件"jdk 1.8 linux 32&64 .zip"中,包含了适用于Linux操作系统的JDK 1.8的32位和64位版本。JDK...

    bcmail-jdk15on-1.49.jar/bcpkix-jdk15on-1.49.jar/bcprov-jdk15on-1.49.jar打包下载

    这些文件是Bouncy Castle库的不同组件,用于Java平台上的加密和数字签名操作。Bouncy Castle是一个广泛使用的开源Java安全API,提供了对加密算法、PKI(公钥基础设施)、CMS(内容完整性服务)以及SSL/TLS的支持。这...

    jdk_8.0.1310.11_64.exe -64位

    jdk_8.0.1310.11_64.exe -64位 可用! !!!!!!!

    jdk11.src.zip

    "java.rmi"支持远程方法调用,使得Java对象可以在网络上进行交互。"jdk.crypto.cryptoki"涉及到加密和安全相关,它是PKCS#11的接口,用于与硬件安全模块(HSM)通信。 "jdk.jdeps"是一个依赖性分析工具,可以帮助...

    JDK1.8_Linux_x32&64.zip

    **Java JDK 1.8 for Linux (x32 & x64) 安装详解** 在IT领域,Java是一种广泛使用的编程语言,尤其在企业级应用开发中占据主导地位。JDK(Java Development Kit)是Java开发的核心工具,它包含了编译器、调试器、...

    JDK1.8.0.221 .zip

    JDK(Java Development Kit)是Java编程语言的核心组件,它包含了Java运行环境(JRE)、编译器(javac)、Java工具集以及其他必要的工具,使得开发者能够编写、测试和部署Java应用程序。JDK 1.8.0.221是Oracle公司...

    jdk_8.0.1310.11_32bit.rar

    oracle jdk_8.0.1310.11_32bit.rar JDK是Java语言的软件开发工具包,主要用于移动...JDK是整个Java的核心,包括了Java运行环境、Java工具和Java基础的类库,不管是做Java开发还是做安卓开发,都必须在电脑上安装JDK。

    JDK_8.0.1310.11_32bit

    根据提供的标题、描述、标签及部分内容,我们可以了解到本主题主要关注的是Java Development Kit(Java开发工具包)版本为8.0.1310.11的32位版本(简称JDK 8 32位)。下面将详细介绍与该版本相关的知识点。 ### 一...

    JDK 开发工具包 17.0.7

    新增和增强的 API:JDK 17.0.7 包含了许多新的和增强的 Java API,例如 Java 媒体框架、Java 加密框架、Java 容器平台等,为开发人员提供了更多的工具和功能。 更好的安全性:JDK 17.0.7 包括许多安全改进,例如增强...

    bcprov-jdk15on-1.65.jar

    最新版的JAVA加密算法包。 The Bouncy Castle Crypto package is a Java implementation of... This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5 to JDK 1.8.

    bcprov-ext-jdk15on-154.jar和bcprov-jdk15on-154.jar (2)

    在Java编程环境中,有时会遇到SSL(Secure Socket Layer)连接问题,其中最常见的一种是`javax.net.ssl.SSLException: java.lang.RuntimeException: Could not generate DH keypair`异常。这个异常通常表明在建立...

Global site tag (gtag.js) - Google Analytics