1 /*
2 * @(#)RMILinkServerService.java
3 *
4 * JFoxMQ the open source JMS MOM.
5 *
6 * Corpyright 2002-2003 Huihoo Power, Inc. All Rights Reserved. This software
7 * is licensed under LGPL license.
8 *
9 * For more information, please visit: http://www.huihoo.org
10 */
11
12 package org.huihoo.jfox.ms.crb.rmi;
13
14 import java.io.File;
15 import java.io.FileInputStream;
16 import java.io.FileNotFoundException;
17 import java.io.FileOutputStream;
18 import java.io.IOException;
19 import java.rmi.server.UnicastRemoteObject;
20 import java.util.Properties;
21
22 import org.huihoo.jfox.ms.crb.LinkServer;
23 import org.huihoo.jfox.ms.crb.LinkServerService;
24 import org.huihoo.jfox.ms.crb.TestInterceptor;
25
26 /***
27 * Defines the service on server for transforming messages with client
28 *
29 * @author Liang.Zhao (zlushangnwpu@sina.com)
30 * @version
31 * @created July 24th 2003
32 */
33
34 public class RMILinkServerService extends LinkServerService {
35 private RMILinkServer rmiLinkServer = null;
36 private int RMIPort;
37
38 public RMILinkServerService() {
39 super();
40 initialize();
41 }
42
43 public void initialize() {
44 FileInputStream in = null;
45 try {
46 Properties prop = new Properties();
47 try {
48 in = new FileInputStream(new File("jfoxmq.pro"));
49 } catch (FileNotFoundException e) {
50 System.out.println(e.toString());
51 System.out.println("can not read config file,exit");
52 System.exit(1);
53 }
54 prop.load(in);
55 RMIPort = Integer.parseInt(prop.getProperty("RMIPort"));
56 } catch (Exception e) {
57 System.out.println(e.toString());
58 System.out.println("can not get config correctly,exit");
59 System.exit(1);
60 }
61 try {
62 in.close();
63 } catch (IOException e) {
64 System.out.println(e.toString());
65 System.out.println("can not close input stream ");
66 }
67
68 }
69
70
71 /***
72 * return a concrete type of LinkServer
73 * @return The LinkServer object
74 */
75 public LinkServer getLinkServer() {
76 try {
77 if (rmiLinkServer == null) {
78 rmiLinkServer = new RMILinkServer(firstInterceptor, RMIPort);
79 }
80 } catch (Exception e) {
81 System.out.println(e.toString());
82 System.exit(1);
83 }
84 return (LinkServer) rmiLinkServer;
85 }
86
87 public void startServer() {
88
89 }
90
91 public void endServer() {
92 try {
93 UnicastRemoteObject.unexportObject(rmiLinkServer, false);
94 } catch (Exception e) {
95 System.out.println(e.toString());
96 System.exit(1);
97 }
98 }
99
100 /***
101 * for test
102 */
103 public static void main(String args[]) {
104 FileOutputStream fos = null;
105 Properties prop = new Properties();
106 try {
107 fos = new FileOutputStream(new File("jfoxmq.pro"));
108 prop.setProperty("RMIPort", Integer.toString(1000));
109 prop.store(fos, null);
110 } catch (Exception e) {
111 System.out.println(e.toString());
112 System.out.println("can not set properties,exit");
113 System.exit(1);
114 }
115 try {
116 fos.close();
117 } catch (Exception e) {
118 System.out.println(e.toString());
119 }
120
121 RMILinkServerService server = new RMILinkServerService();
122 server.setConnectionFactoryJNDIRef("ConnectionFactory");
123 TestInterceptor test = new TestInterceptor();
124 server.firstInterceptor = test;
125 server.start();
126 }
127
128 }
This page was automatically generated by Maven