KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > ioc > connector > jrmps > JRMPSConnectorRemote


1 /* JFox, the OpenSource J2EE Application Server
2  *
3  * Distributable under GNU LGPL license by gun.org
4  * more details please visit http://www.huihoo.org/jfox
5  */

6 package org.jfox.ioc.connector.jrmps;
7
8 import java.rmi.RemoteException JavaDoc;
9 import java.rmi.server.UnicastRemoteObject JavaDoc;
10
11 import org.jfox.ioc.connector.ServerNode;
12 import org.jfox.ioc.connector.jrmp.JRMPConnectorRemote;
13 import org.jfox.ioc.ext.ManagableComponent;
14
15 /**
16  * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>
17  */

18
19 public class JRMPSConnectorRemote extends JRMPConnectorRemote implements ManagableComponent {
20
21     private String JavaDoc SSLKeyFile = "jfox.keystore";
22     private String JavaDoc SSLTrustKeyFile = "jfox.truststore";
23     private String JavaDoc password = "jfox.org";
24
25     private JRMPSServerSocketFactory serverFactory = null;
26     private JRMPSClientSocketFactory clientFactory = null;
27
28     protected void doInit() throws Exception JavaDoc {
29         super.doInit();
30         clientFactory = new JRMPSClientSocketFactory(SSLTrustKeyFile, password);
31         serverFactory = new JRMPSServerSocketFactory(SSLKeyFile, password);
32     }
33
34     /**
35      * export this invoker and set container's invoker to this stub
36      *
37      * @throws Exception
38      */

39     protected void doStart() throws Exception JavaDoc {
40         UnicastRemoteObject.exportObject(this, getPort(), clientFactory, serverFactory);
41         // register this Connector
42
ServerNode.THE_NODE.registerConnector(getProtocol(), this);
43
44         // 启动一个线程,用来每隔一段时间 ping 一下,防止 rmi 线程死掉
45
Thread JavaDoc pingThread = new Thread JavaDoc(this, getClass().getName());
46         pingThread.setPriority(Thread.MIN_PRIORITY);
47         pingThread.start();
48     }
49
50     protected void doStop() throws Exception JavaDoc {
51         ServerNode.THE_NODE.removeConnector(getProtocol());
52         UnicastRemoteObject.unexportObject(this, true);
53     }
54
55     protected synchronized void doDestroy() throws Exception JavaDoc {
56         super.doDestroy();
57         serverFactory = null;
58         clientFactory = null;
59     }
60
61     public String JavaDoc getProtocol() throws RemoteException JavaDoc {
62         // jrmp_ssl
63
return "JRMPS";
64     }
65
66     public void setSSLKeyFile(String JavaDoc SSLKeyFile) {
67         this.SSLKeyFile = SSLKeyFile;
68     }
69
70     public void setSSLTrustKeyFile(String JavaDoc SSLTrustKeyFile) {
71         this.SSLTrustKeyFile = SSLTrustKeyFile;
72     }
73
74     public void setPassword(String JavaDoc password) {
75         this.password = password;
76     }
77
78     public String JavaDoc getSSLKeyFile() {
79         return SSLKeyFile;
80     }
81
82     public String JavaDoc getSSLTrustKeyFile() {
83         return SSLTrustKeyFile;
84     }
85
86     public static void main(String JavaDoc[] args) {
87
88     }
89 }
Popular Tags