1 /*
2 * @(#)LinkServerService.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;
13
14 import javax.naming.Context;
15 import javax.naming.InitialContext;
16
17 import org.huihoo.jfox.jndi.JNDIProperties;
18
19 /***
20 * Defines the service on server for transforming messages with client
21 *
22 * @author Liang.Zhao (zlushangnwpu@sina.com)
23 * @version @created July 24th 2003
24 */
25
26 public abstract class LinkServerService {
27 protected String connectionFactoryJNDIRef;
28 protected Interceptor firstInterceptor;
29
30 /***
31 * start service to receive request from client
32 */
33 public void start() {
34 try {
35 bindJNDIRef();
36 startServer();
37 } catch (Exception e) {
38 System.out.println("failtrue to start JMS server");
39 System.out.println(e.toString());
40 System.exit(1);
41 }
42 }
43
44 /***
45 * close service
46 */
47 public void close() {
48 try {
49 unbindJNDIRef();
50 endServer();
51 } catch (Exception e) {
52 System.out.println("failtrue in ending JMS server");
53 System.out.println(e.toString());
54 System.exit(1);
55 }
56 }
57
58 /***
59 * return a concrete type of LinkServer
60 *
61 * @return The LinkServer object
62 */
63 public abstract LinkServer getLinkServer();
64
65 /***
66 * set the first interceptor of the interceptor chain param Interceptor
67 * proxy
68 */
69 public void setInterceptor(Interceptor interceptor) {
70 firstInterceptor = interceptor;
71 }
72
73 /***
74 * Binds the connection factory to JDNI tree
75 *
76 * @throws javax.naming.NamingException
77 */
78 public void bindJNDIRef() throws javax.naming.NamingException {
79 //i recommand to use GenConnectionFactoryImpl instead of two type of
80 // connectiom factory(queue&topic)
81 GenConnectionFactoryImpl gcf =
82 new GenConnectionFactoryImpl(getLinkServer());
83
84 System.setProperty(
85 "java.naming.factory.initial",
86 JNDIProperties.INITIAL_CONTEXT_FACTORY);
87 System.setProperty(
88 "java.naming.factory.url.pkgs",
89 "org.huihoo.jfox.jndi");
90 System.setProperty(
91 "java.naming.provider.url",
92 JNDIProperties.PROVIDER_URL);
93
94 // Get an InitialContext
95 Context ctx = new InitialContext();
96 System.out.println("bind the ConnectionFactory");
97 ctx.bind(connectionFactoryJNDIRef, gcf);
98 }
99
100 /***
101 * Unbinds the connection factory
102 *
103 * @throws javax.naming.NamingException
104 */
105 public void unbindJNDIRef() throws javax.naming.NamingException {
106 // Get an InitialContext
107 InitialContext ctx = new InitialContext();
108 System.out.println("unbind the ConnectionFactory");
109 ctx.unbind(connectionFactoryJNDIRef);
110 }
111
112 public abstract void startServer();
113
114 public abstract void endServer();
115
116 /***
117 * @return String for the JNDI reference
118 *
119 */
120 public java.lang.String getConnectionFactoryJNDIRef() {
121 return connectionFactoryJNDIRef;
122 }
123
124 /***
125 * @param String
126 * newConnectionFactoryJNDIRef
127 */
128 public void setConnectionFactoryJNDIRef(String newConnectionFactoryJNDIRef) {
129 connectionFactoryJNDIRef = newConnectionFactoryJNDIRef;
130 }
131 }
This page was automatically generated by Maven