• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

moto web application


Commit MetaInfo

修订版dd09028d2ca1c566b67de29c7ab6d6cf0ea074f8 (tree)
时间2014-01-29 15:41:36
作者astoria-d <astoria-d@mail...>
Commiterastoria-d

Log Message

push clean up, jms not to be used.

更改概述

差异

--- a/WEB-INF/classes/motoSample/ChatBean.java
+++ b/WEB-INF/classes/motoSample/ChatBean.java
@@ -27,11 +27,7 @@ import javax.faces.component.html.HtmlCommandLink;
2727 import java.util.Date;
2828 import java.text.SimpleDateFormat;
2929 import java.util.UUID;
30-/*
31-import org.richfaces.application.push.TopicKey;
32-import org.richfaces.application.push.TopicsContext;
33-import org.richfaces.application.push.MessageException;
34-*/
30+
3531 import org.primefaces.push.PushContext;
3632 import org.primefaces.push.PushContextFactory;
3733
@@ -49,9 +45,6 @@ public class ChatBean implements Serializable {
4945 @ManagedProperty("#{userBean}")
5046 private UserBean userBean;
5147
52- @ManagedProperty("#{pushBean}")
53- private PushBean pushBean;
54-
5548 @ManagedProperty("#{loginMemberBean}")
5649 private LoginMemberBean loginMemberBean;
5750
@@ -104,9 +97,6 @@ public class ChatBean implements Serializable {
10497 public void setUserBean(UserBean userBean) {
10598 this.userBean = userBean;
10699 }
107- public void setPushBean(PushBean pushBean) {
108- this.pushBean = pushBean;
109- }
110100 public void setLoginMemberBean(LoginMemberBean loginMemberBean) {
111101 this.loginMemberBean = loginMemberBean;
112102 }
@@ -136,13 +126,6 @@ public class ChatBean implements Serializable {
136126 }
137127 }
138128
139- public class ViewMsgList {
140- public String viewId;
141- public String chatRoom;
142- public ArrayList<ChatMessage> msgList;
143- public MemberList memList;
144- }
145-
146129 private void initMsgList(){
147130 log.info("initMsgList: " + chatRoom + ", msgList: "
148131 + (msgList == null ? "null" : msgList.hashCode()) + ", viewId: " + getViewId());
@@ -179,60 +162,9 @@ public class ChatBean implements Serializable {
179162 catch (SQLException se) {
180163 log.severe("sql err!!!");
181164 }
182-
183- //register viewlist in the session to receive ajax push notification update.
184- HttpSession session = (HttpSession) context.getExternalContext().getSession(true);
185- ArrayList<ViewMsgList> viewList = (ArrayList<ViewMsgList>) session.getAttribute("viewList");
186- if (viewList == null) {
187- viewList = new ArrayList<ViewMsgList>();
188- session.setAttribute("viewList", viewList);
189- }
190- ViewMsgList vml = new ViewMsgList();
191- vml.viewId = viewId;
192- vml.chatRoom = chatRoom;
193- vml.msgList = msgList;
194- putViewList(viewList, vml);
195165 }
196-
197- private static int MAX_VIEW_LIST_CNT = 3;
198- void putViewList(ArrayList<ViewMsgList> viewList, ViewMsgList vml) {
199- int i;
200- for (i = 0; i < viewList.size(); i++ ) {
201- ViewMsgList it_vml = viewList.get(i);
202- if (vml.viewId.equals(it_vml.viewId)) {
203- viewList.set(i, vml);
204- return;
205- }
206- }
207- viewList.add(vml);
208- if (viewList.size() > MAX_VIEW_LIST_CNT) {
209- //view number control.
210- ViewMsgList rm_vml = viewList.remove(0);
211- rm_vml.msgList.clear();
212-
213- ChatMessage m = new ChatMessage();
214- m.uname = "----";
215- m.msg = "too much view is opened. please close this window (or tab).";
216- m.date = "----";
217- rm_vml.msgList.add(m);
218166
219- /*
220- //notify browser.
221- try {
222- TopicKey topicKey = new TopicKey(rm_vml.viewId);
223- TopicsContext topicsContext = TopicsContext.lookup();
224- topicsContext.publish(topicKey, "notify");
225- }
226- catch (MessageException me) {
227- log.severe("message exeption!!");
228- }
229- */
230-
231- log.info("old viewList is removed.");
232- }
233- }
234-
235- public ArrayList<ChatMessage> getMsgList(){
167+ public ArrayList<ChatMessage> getMsgList(){
236168 // log.info("getMsgList");
237169 // try {
238170 //System.out.print("viewId:" + viewId);
@@ -295,8 +227,6 @@ public class ChatBean implements Serializable {
295227 catch (SQLException se) {
296228 log.severe("sql err!!!");
297229 }
298-
299- //pushBean.pushChatMessage(viewId, chatRoom, msg, userBean.getUid(), dt);
300230 }
301231
302232 public void loadOldMsg() {
@@ -347,17 +277,6 @@ public class ChatBean implements Serializable {
347277 memList.setChatRoom(chatRoom);
348278 memList.setLoginMember(loginMemberBean);
349279 memList.initMemList();
350-
351- //register viewlist in the session to receive ajax push notification update.
352- HttpSession session = (HttpSession) context.getExternalContext().getSession(true);
353- ArrayList<ViewMsgList> viewList = (ArrayList<ViewMsgList>) session.getAttribute("viewList");
354- for (ViewMsgList vml : viewList) {
355- if (vml.viewId.equals(viewId)) {
356- vml.memList = memList;
357- break;
358- }
359- }
360-
361280 }
362281 ///chat room menu value changed listener
363282 public void chatRoomChanged(ValueChangeEvent e) {
--- a/WEB-INF/classes/motoSample/PushBean.java
+++ /dev/null
@@ -1,300 +0,0 @@
1-package motoSample;
2-
3-import java.io.Serializable;
4-import javax.faces.bean.ManagedBean;
5-import javax.faces.bean.SessionScoped;
6-import javax.faces.bean.ManagedProperty;
7-import javax.faces.context.FacesContext;
8-import javax.faces.event.ActionEvent;
9-import javax.faces.component.UIComponent;
10-import javax.faces.component.UIInput;
11-
12-import javax.servlet.http.HttpSession;
13-
14-import java.util.logging.Logger;
15-import javax.inject.Inject;
16-import javax.annotation.PostConstruct;
17-import javax.annotation.PreDestroy;
18-
19-/*
20-import org.richfaces.application.push.TopicKey;
21-import org.richfaces.application.push.TopicsContext;
22-import org.richfaces.application.push.MessageException;
23-*/
24-import javax.jms.MessageListener;
25-import javax.jms.Message;
26-import javax.jms.MapMessage;
27-
28-import javax.naming.Context;
29-import javax.naming.InitialContext;
30-import javax.naming.NamingException;
31-
32-import java.util.Properties;
33-
34-import javax.jms.TopicConnectionFactory;
35-import javax.jms.TopicConnection;
36-import javax.jms.Topic;
37-import javax.jms.Session;
38-import javax.jms.TopicSession;
39-import javax.jms.TopicSubscriber;
40-import javax.jms.TopicPublisher;
41-import javax.jms.JMSException;
42-
43-import java.util.ArrayList;
44- import java.util.Vector;
45- import java.util.Iterator;
46- import javax.faces.model.SelectItem;
47-
48-
49-@ManagedBean
50-@SessionScoped
51-public class PushBean implements MessageListener, Serializable {
52-
53- @Inject
54- private Logger log;
55-
56- @Inject
57- private FacesContext context = null;
58-
59- private static final String PUSH_TYPE_MSG_POST = "messagePost";
60- private static final String PUSH_TYPE_LOG_IN = "login";
61- private static final String PUSH_TYPE_LOG_OFF = "logoff";
62-
63- private ArrayList<ChatBean.ViewMsgList> viewList;
64-
65- private static final String PUSH_JMS_TOPIC = "motoTest";
66-
67- private TopicConnectionFactory getTopicConnectionFactory() {
68- try {
69- return (TopicConnectionFactory) InitialContext.doLookup("java:/ConnectionFactory");
70- } catch (NamingException e) {
71- try {
72- return (TopicConnectionFactory) InitialContext.doLookup("ConnectionFactory");
73- } catch (NamingException e2) {
74- throw new IllegalStateException("Can't find registered ConnectionFactory");
75- }
76- }
77- }
78-
79- private TopicConnection connection = null;
80- private TopicSession session = null;
81- private TopicPublisher publisher = null;
82- private TopicSubscriber subscriber = null;
83-
84- public void initPushBean() {
85-
86- log.info("initPushBean");
87-
88- try {
89- if (connection == null) {
90- TopicConnectionFactory tcf = getTopicConnectionFactory();
91- connection = tcf.createTopicConnection();
92- log.info("connection ok.");
93- }
94- if (session == null) {
95- session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
96- log.info("session ok.");
97- }
98-
99- Topic topic = InitialContext.doLookup("topic/" + PUSH_JMS_TOPIC);
100- log.info("topic ok.");
101-
102- if (publisher == null) {
103- publisher = session.createPublisher(topic);
104- log.info("publisher ok.");
105- }
106- if (subscriber== null) {
107- subscriber = session.createSubscriber(topic);
108- log.info("subscriber ok.");
109-
110- // Set a JMS message listener
111- subscriber.setMessageListener(this);
112- log.info("lisntener bind ok.");
113- }
114-
115- // Start the JMS connection; allows messages to be delivered
116- connection.start( );
117- log.info("connection start ok.");
118- }
119- catch (JMSException je) {
120- log.severe("jms exeption!!!");
121- }
122- catch (NamingException ne) {
123- log.severe("naming exeption!!!");
124- }
125-
126- //get list of receiver view of this session....
127- HttpSession req_session = (HttpSession) context.getExternalContext().getSession(true);
128- viewList = (ArrayList<ChatBean.ViewMsgList>) req_session.getAttribute("viewList");
129- if (viewList == null) {
130- viewList = new ArrayList<ChatBean.ViewMsgList>();
131- req_session.setAttribute("viewList", viewList);
132- }
133- }
134-
135- //this method is invoked from the sender side.
136- public void pushChatMessage(String viewId, String chatRoom, String msg, String uid, String date) {
137- log.info("push from view " + viewId + ", msg=" + msg);
138-
139- try {
140- MapMessage message = session.createMapMessage();
141- message.setString("pushType", PUSH_TYPE_MSG_POST);
142- message.setString("viewId", viewId);
143- message.setString("chatRoom", chatRoom);
144- message.setString("msg", msg);
145- message.setString("uid", uid);
146- message.setString("date", date);
147- publisher.publish(message);
148-
149- //deliver jms message
150- log.info("message published by " + this.hashCode());
151- //log.info("context: " + context);
152-
153- /*
154- //notifying ajax is done by the message receiver
155- TopicKey topicKey = new TopicKey(chatRoom);
156- TopicsContext topicsContext = TopicsContext.lookup();
157- topicsContext.publish(topicKey, "notify");
158- */
159- }
160- catch (JMSException je) {
161- log.severe("jms exeption!!");
162- }
163- }
164-
165- //this method is invoked from the sender side.
166- public void pushLogin(String uid, ArrayList<SelectItem> flights, boolean isLogin) {
167- log.info("login: " + uid);
168- try {
169- MapMessage message = session.createMapMessage();
170- message.setString("pushType", PUSH_TYPE_LOG_IN);
171- message.setString("uid", uid);
172- message.setBoolean("isLogin", isLogin);
173- publisher.publish(message);
174-
175- //notify ajax page.
176- for (SelectItem si : flights) {
177- String chatRoom = si.getValue().toString();
178- /*
179- TopicKey topicKey = new TopicKey("login_" + chatRoom);
180- TopicsContext topicsContext = TopicsContext.lookup();
181- topicsContext.publish(topicKey, "notify");
182- */
183- }
184- }
185- catch (JMSException je) {
186- log.severe("jms exeption!!");
187- }
188- /*
189- catch (MessageException je) {
190- log.severe("message exeption!!");
191- }*/
192- }
193-
194- //this method is invoked on the receiver side.
195- public void onMessage(Message message) {
196- //msgCnt++;
197- log.info("message received by " + this.hashCode());
198- //log.info("viewMap size: " + viewMap.size());
199- MapMessage mmsg = (MapMessage)message;
200-
201- try {
202- String msgType = mmsg.getString("pushType");
203- if (msgType.equals(PUSH_TYPE_MSG_POST)) {
204- onPostMsgDelivered(mmsg);
205- }
206- else if (msgType.equals(PUSH_TYPE_LOG_IN)) {
207- onLoginDelivered(mmsg);
208- }
209- }
210- catch (JMSException je) {
211- log.severe("get message error!!");
212- }
213- }
214-
215- public void onPostMsgDelivered(MapMessage message) {
216- for (ChatBean.ViewMsgList vml : viewList) {
217- //update the view only if it has the same chat room
218- try {
219- if (!message.getString("chatRoom").equals(vml.chatRoom))
220- continue;
221-
222- ChatBean.ChatMessage m = new ChatBean.ChatMessage();
223- m.setUname(message.getString("uid"));
224- m.setMsg(message.getString("msg"));
225- m.setDate(message.getString("date"));
226- vml.msgList.add(m);
227-
228- log.info("update msgview list!!: " + vml.viewId + "msg: " + message.getString("msg"));
229-
230- /*
231- TopicKey topicKey = new TopicKey(vml.viewId);
232- TopicsContext topicsContext = TopicsContext.lookup();
233- topicsContext.publish(topicKey, "notify");
234- */
235- }
236- catch (JMSException je) {
237- log.severe("get message error!!");
238- }
239- /*
240- catch (MessageException me) {
241- log.severe("message exeption!!");
242- }*/
243- }
244- }
245-
246- public void onLoginDelivered(MapMessage message) {
247- try {
248- String uid = message.getString("uid");
249- boolean isLogin = message.getBoolean("isLogin");
250-
251-
252- //check if the chat rooms are connected to the current view.
253- for (ChatBean.ViewMsgList vml : viewList) {
254- for (MemberList.ChatMember mc : vml.memList) {
255- if (mc.getUname().equals(uid)) {
256- mc.setIsLogin(isLogin);
257- break;
258- }
259- }
260- }
261- }
262- catch (JMSException je) {
263- log.severe("get message error!!");
264- }
265-
266- }
267-
268- @PreDestroy
269- public void preDestroy() {
270- log.info("preDestroy");
271- if (publisher != null) {
272- try {
273- publisher.close();
274- } catch (JMSException e) {
275- log.severe("unable to close publisher");
276- }
277- }
278- if (subscriber != null) {
279- try {
280- subscriber.close();
281- } catch (JMSException e) {
282- log.severe("unable to close subscriber");
283- }
284- }
285- if (session != null) {
286- try {
287- session.close();
288- } catch (JMSException e) {
289- log.severe("unable to close session");
290- }
291- }
292- if (connection != null) {
293- try {
294- connection.close();
295- } catch (JMSException e) {
296- log.severe("unable to close connection");
297- }
298- }
299- }
300-}
--- a/WEB-INF/classes/motoSample/UserBean.java
+++ b/WEB-INF/classes/motoSample/UserBean.java
@@ -18,6 +18,9 @@ import javax.servlet.http.HttpSession;
1818 import java.util.ArrayList;
1919 import javax.faces.model.SelectItem;
2020
21+import org.primefaces.push.PushContext;
22+import org.primefaces.push.PushContextFactory;
23+
2124 @ManagedBean
2225 @SessionScoped
2326 public class UserBean implements Serializable {
@@ -27,14 +30,9 @@ public class UserBean implements Serializable {
2730 @Inject
2831 private FacesContext context;
2932
30- @ManagedProperty("#{pushBean}")
31- private PushBean pushBean;
3233 @ManagedProperty("#{loginMemberBean}")
3334 private LoginMemberBean loginMemberBean;
3435
35- public void setPushBean(PushBean pushBean) {
36- this.pushBean = pushBean;
37- }
3836 public void setLoginMemberBean(LoginMemberBean loginMemberBean) {
3937 this.loginMemberBean = loginMemberBean;
4038 }
@@ -91,7 +89,15 @@ public class UserBean implements Serializable {
9189 log.severe("sql flight err!!!");
9290 }
9391 }
94-
92+
93+ public static class LoginUser {
94+ String uid;
95+ boolean login;
96+ public void setUid(String uid) { this.uid = uid; }
97+ public void setLogin(boolean login) { this.login = login; }
98+ public String getUid() { return uid; }
99+ public boolean getLogin() { return login; }
100+ }
95101 public String doLogin() {
96102
97103 try {
@@ -122,12 +128,18 @@ public class UserBean implements Serializable {
122128 //add to the app login list.
123129 loginMemberBean.login(uid, true);
124130 //notify log in message
125- pushBean.initPushBean();
126- pushBean.pushLogin(uid, flights, true);
127-
128- HttpSession session = Resources.getSession();
131+ for (SelectItem si : flights) {
132+ String chatRoom = si.getValue().toString();
133+ LoginUser lu = new LoginUser();
134+ lu.setUid(uid);
135+ lu.setLogin(true);
136+
137+ PushContext pushContext = PushContextFactory.getDefault().getPushContext();
138+ pushContext.push("/login_" + chatRoom, lu);
139+ }
129140
130141 ///after login, redirect to the user specified url.
142+ HttpSession session = Resources.getSession();
131143 String request_url = (String) session.getAttribute("request_url");
132144 if (request_url == null)
133145 request_url = "secured/chat.jsf";
@@ -152,7 +164,16 @@ public class UserBean implements Serializable {
152164 }
153165
154166 public String doLogout() {
155- pushBean.pushLogin(uid, flights, false);
167+ //notify log in message
168+ for (SelectItem si : flights) {
169+ String chatRoom = si.getValue().toString();
170+ LoginUser lu = new LoginUser();
171+ lu.setUid(uid);
172+ lu.setLogin(false);
173+
174+ PushContext pushContext = PushContextFactory.getDefault().getPushContext();
175+ pushContext.push("/login_" + chatRoom, lu);
176+ }
156177 loginMemberBean.login(uid, false);
157178 context.getExternalContext().invalidateSession();
158179 return "/login.jsf";
--- a/WEB-INF/faces-config.xml
+++ b/WEB-INF/faces-config.xml
@@ -3,13 +3,6 @@
33 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
44
55 <application>
6- <!-- push topic initializer registration -->
7- <!-- not needed ????
8- system-event-listener>
9- <system-event-listener-class>motoSample.TopicsInitializer</system-event-listener-class>
10- <system-event-class>javax.faces.event.PostConstructApplicationEvent</system-event-class>
11- </system-event-listener -->
126 </application>
137
14-
158 </faces-config>
\ No newline at end of file
--- a/WEB-INF/jboss-deployment-structure.xml
+++ b/WEB-INF/jboss-deployment-structure.xml
@@ -1,9 +1,5 @@
11 <?xml version="1.0" encoding="UTF-8"?>
22 <jboss-deployment-structure>
33 <deployment>
4- <dependencies>
5- <module name="org.w3c.css.sac" />
6- <module name="net.sourceforge.cssparser" />
7- </dependencies>
84 </deployment>
95 </jboss-deployment-structure>
--- a/WEB-INF/web.xml
+++ b/WEB-INF/web.xml
@@ -43,28 +43,6 @@
4343 <auth-constraint>
4444 </auth-constraint>
4545 </security-constraint>
46-
47- <!-- enable richfaces push/jms -->
48- <context-param>
49- <param-name>org.richfaces.push.initializeOnStartup</param-name>
50- <param-value>true</param-value>
51- </context-param>
52- <context-param>
53- <param-name>org.richfaces.push.jms.enabled</param-name>
54- <param-value>false</param-value>
55- </context-param>
56- <context-param>
57- <param-name>org.richfaces.push.jms.connectionUsername</param-name>
58- <param-value>jmsuser</param-value>
59- </context-param>
60- <context-param>
61- <param-name>org.richfaces.push.jms.connectionPassword</param-name>
62- <param-value>jmspassword</param-value>
63- </context-param>
64- <session-config>
65- <session-timeout>15</session-timeout>
66- </session-config>
67-
6846
6947 <!-- primefaces push servlet -->
7048 <servlet>
--- a/build.xml
+++ b/build.xml
@@ -25,7 +25,6 @@
2525 <property name="inject" value="${env.JBOSS_HOME}\modules\javax\inject\api\main\javax.inject-1.jar"/>
2626 <property name="servlet" value="${env.JBOSS_HOME}\modules\javax\servlet\api\main\jboss-servlet-api_3.0_spec-1.0.0.Final.jar"/>
2727 <property name="cdi" value="${env.JBOSS_HOME}\modules\javax\enterprise\api\main\cdi-api-1.0-SP4.jar"/>
28- <property name="jms" value="${env.JBOSS_HOME}\modules\javax\jms\api\main\jboss-jms-api_1.1_spec-1.0.0.Final.jar"/>
2928 <property name="primefaces" value="${lib}\primefaces-4.0.jar"/>
3029 <property name="atmosphere" value="${lib}\atmosphere-runtime-2.0.1.jar"/>
3130 <property name="slf4j" value="${lib}\slf4j-api-1.6.1.jar"/>
@@ -56,7 +55,6 @@
5655 <pathelement path="${inject}" />
5756 <pathelement path="${servlet}" />
5857 <pathelement path="${cdi}" />
59- <pathelement path="${jms}" />
6058 <pathelement path="${primefaces}" />
6159 </classpath>
6260 </javac>
--- a/secured/chat.xhtml
+++ b/secured/chat.xhtml
@@ -25,7 +25,25 @@
2525
2626 var msg = document.getElementById("chatForm:msg");
2727 msg.value = '';
28- }
28+ }
29+
30+ function handleLogin(data) {
31+ var memList = document.getElementById("chatForm:memList");
32+ var uid = data.uid;
33+ var login = data.login
34+ var i;
35+ for (i = 0; i < memList.rows.length; i++) {
36+ if (memList.rows[i].cells[0].innerHTML.trim() == uid) {
37+ if (login)
38+ memList.rows[i].cells[1].innerHTML = "online";
39+ else
40+ memList.rows[i].cells[1].innerHTML = "offline";
41+ break;
42+ }
43+ }
44+
45+ }
46+
2947 //]]>
3048 </script>
3149 </ui:define>
@@ -46,13 +64,7 @@
4664 <h:inputHidden id="viewId" value="#{chatBean.viewId}"/>
4765
4866 <p:socket onMessage="handleChatMsg" channel="/#{chatBean.chatRoom}" />
49-
50- <!-- a4j:push address="login_#{chatBean.chatRoom}">
51- <a4j:ajax event="dataavailable" render="memList" />
52- </a4j:push>
53- <a4j:push address="#{chatBean.viewId}">
54- <a4j:ajax event="dataavailable" render="chatTable" />
55- </a4j:push -->
67+<p:socket onMessage="handleLogin" channel="/login_#{chatBean.chatRoom}" />
5668
5769 chat room :
5870 <h:selectOneMenu id="chatRoom" value="#{chatBean.chatRoom}" onchange="submit()"