版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
1、androidpn 的學(xué)習(xí)(一)androidpn-server 服務(wù)端相關(guān)配置的博客分類:Android 開發(fā)學(xué)習(xí)androidpn 的一些基本:ANDROIDPN_HOME=C:android-pushandroidpn-server-0.5.0啟動 androidpn 服務(wù)端:%ANDROID_HOME%/bin/run.bat androidpn 的數(shù)據(jù)庫日志:%ANDROID_HOME%/bin/db/androidpn.log androidpn 的數(shù)據(jù)庫配置:%ANDROID_HOME%/bin/db/pertiesandroidpn 的數(shù)據(jù)庫表結(jié)構(gòu):%ANDROID_HOME%
2、/bin/db/androidpn.script androidpn 的服務(wù)端應(yīng)用數(shù)據(jù)庫配置:%ANDROID_HOME%/conf/perties androidpn 的服務(wù)端應(yīng)用 xmpp 配置:%ANDROID_HOME%/conf/pertiesandroidpn 的服務(wù)端應(yīng)用應(yīng)用 hibernate 緩存配置:%ANDROID_HOME%/conf/ehcache.xmlandroidpn 的服務(wù)端應(yīng)用日志配置:%ANDROID_HOME%/conf/log4j.xmlandroidpn 的服務(wù)端應(yīng)用 spring 配置:%ANDROID_HOME%/conf/spring-conf
3、ig.xmlandroidpn 的服務(wù)端日志:%ANDROID_HOME%/logs/androidpn.log (發(fā)送消息 xmpp 的格式和調(diào)用順序)如下:DEBUG 2012-07-24 14:40:23,921 : Firing aMESSAGE_RECEIVED event for sesDEBUG 2012-07-24 14:40:23,9212 : Prosing aMESSAGE_RECEIVED for ses2DEBUG 2012-07-24 14:40:23,921 : EventMESSAGE_RECEIVED has been fired for sesDEBUG 2
4、012-07-24 14:40:53,9682 :2Adding event MESSAGE_RECEIVED to sesQueue : MESSAGE_RECEIVED, DEBUG 2012-07-24 14:40:53,968 : Firing aMESSAGE_RECEIVED event for sesDEBUG 2012-07-24 14:40:53,9682 : Prosing aMESSAGE_RECEIVED for ses2DEBUG 2012-07-24 14:40:53,968 : EventMESSAGE_RECEIVED has been fired for se
5、sDEBUG 2012-07-24 14:41:06,4532 :apiKey=1234567890DEBUG 2012-07-24 14:41:06,453 :sendBroadcast().DEBUG 2012-07-24 14:41:06,453 :SENT: fdcbd43b1234567890DokdoIslandDoks a Korean island, the far east of theKorean territory. No doubt! No question!t mention it any more!說的法撒旦法DEBUG 2012-07-24 14:41:06,46
6、8 :Adding event MESSAGE_SENT to sesQueue : MESSAGE_SENT, 2備注:在 hibernate 的配置中 hibernate.cfg.xml 配置中:update在多次重新運行服務(wù)端和客戶端之后,可以發(fā)現(xiàn),服務(wù)端的中存在客戶端 id 標(biāo)志的起始值的已經(jīng)存在的數(shù)據(jù)信息信息:有在 androidpn-server-0.5.0bindbandroidpn.script 中。CREATE SCHEMA PUBLIC AUTHORIZATION DBACREATE MEMORY TABLE APN_USER(ID BIGGENERATED BYDEFAU
7、LT AS IDENTITY(START WITH 1) NOT NULL PRIMARYKEY,CREATED_DATE TIMESTAMP,VARCHAR(64),NAMEVARCHAR(64),PASSWORD VARCHAR(64),UPDATED_DATE TIMESTAMP,USERNAME VARCHAR(64) NOT NULL,CONSTRA SYS_CT_46 UNIQUE(USERNAME)ALTER TABLE APN_USER ALTER COLUMN ID RESTART WITH 3CREATE USER S GRANT DBA TO SA SET WRITE_D
8、ELAY 10SET SCHEMA PUBLICSWORD INSERTO APN_USER VALUES(1,2012-07-2313:07:50.421000000,NULL,NULL,4c9cd95e3d3d4874b507fdae64e38b41,NULL,25a67fa989354bca832513d4a3ad4f3d)INSERTO APN_USER VALUES(2,2012-07-2414:34:38.953000000,NULL,NULL,7b8f51468cb441379d0883e1c4707847,NULL,ea34751c595443c89be在Androidpn 的
9、底層主要采用的mina 和 openfire 兩大框架,其中 mina主要為底層數(shù)據(jù)傳輸?shù)?Socket 框架。下面簡單說明 mina 的框架。Apache Mina Server 是一個網(wǎng)絡(luò)通信應(yīng)用框架,也就是說,它主要是對基于 TCP/IP、UDP/IP 協(xié)議棧的通信框架(然,也可以提供 JAVA 對象的序列化服務(wù)、虛擬機管道通信服務(wù)等),Mina 可以幫助快速開發(fā)高性能、高擴展性的網(wǎng)絡(luò)通信應(yīng)用,Mina 提供了事件驅(qū)動、異步(Mina 的異步 IO 默認(rèn)使用的是 JAVA NIO 作為底層支持)操作的編程模型。Mina 主要有1.x 和2.x 兩個分支,這里講解最新版本2.0,如果你使用
10、的是 Mina 1.x,那么可能會有一些功能并不適用。學(xué)習(xí)本文檔,需要你已掌握 JAVA IO、JAVA NIO、JAVASocket、JAVA 線程及并發(fā)庫(java.util.concurrent.*)的知識。Mina 同時提供了網(wǎng)絡(luò)通信的Server 端、Cnt 端的封裝,無論是哪端,Mina 在整個網(wǎng)通通信結(jié)構(gòu)中都處于如下的位置:可見Mina 的 API將真正的網(wǎng)絡(luò)通信與的應(yīng)用程序開來,你只需要關(guān)心你要發(fā)送、接收的數(shù)據(jù)以及你的業(yè)務(wù)邏輯即可。同樣的,無論是哪端,Mina 的執(zhí)行流程如下所示:(1.) IoService:這個接口在一個線程上負(fù)責(zé)套接字的建立,擁有自己的Selector,是
11、否有連接被建立。(2.) IoProsor:這個接口在另一個線程上負(fù)責(zé)檢查是否有數(shù)據(jù)在通道上讀寫,也就是說它也擁有自己的 Selector,這是與使用 JAVA NIO編碼時的一個不同之處,通常在 JAVA NIO 編碼中,都是使用一個Selector,也就是不區(qū)分 IoService 與IoProsor 兩個功能接口。另外,IoProsor 負(fù)責(zé)調(diào)用在 IoService上的過濾器,并在過濾器鏈之后調(diào)用 IoHandler。(3.) IoFilter:這個接口定義一組器,這些器可以包括日志輸出、過濾、數(shù)據(jù)的編碼(write(read 方向)等功能,方向)與其中數(shù)據(jù)的 encode 與 dec
12、ode 是最為重要的、也是你在使用 Mina 時最主要關(guān)注的地方。(4.) IoHandler:這個接口負(fù)責(zé)編寫業(yè)務(wù)邏輯,也就是接收、發(fā)送數(shù)據(jù)的地方。Mina 自帶的過濾器(部分)由上面的Mina 的執(zhí)行的過程可以知道針對使用Mina 的第來說主要的業(yè)務(wù)主要在 IoHandler 中。androidpn-server 的 spring 配置。 classpath:perties property name=ses = - property name=ses = - !- - !- - 通過 Mina 的原理androidpn 的運行流程不能看出,如下:androidpn-server 執(zhí)行過程
13、如下:1.spring 初始化并啟動過程,調(diào)用NioSocketAcceptor。2。NioSocketAcceptor 開始執(zhí)行調(diào)用 IoProsor.3.IoProsor 開始調(diào)用 FilterChain。FilterChain 調(diào)用相關(guān)的 IoFilter 的。其中ProtocolCodecFilter 的過濾器調(diào)用了.androidpn.server.xmpp.codec.XmppCodecFactory 進行編碼。4.XmppIoHandler 實現(xiàn)自IoHanlder 并調(diào)用通過openfire 的XMLLightweightParser關(guān)的業(yè)務(wù)邏輯。相5.根據(jù)的信息調(diào)用 xmpp
14、 并處理相關(guān)信息。androidpn 的學(xué)習(xí)(三)androidpn-server 服務(wù)端幾個類說明博客分類:Android 開發(fā)學(xué)習(xí)AndroidPn MQTT C2DM 推技術(shù)AndroidPN(Android Push Notification) 是一個基于 XMPP 協(xié)議的 Java 開源推送通知實現(xiàn),它包含了完整的客戶端和服務(wù)端。AndroidPN 基于Openfire 下的一些開源項目構(gòu)建。AndroidPN 服務(wù)器包含兩個部分,一個是偵聽在5222端口上的 XMPP 服務(wù),負(fù)責(zé)與客戶端的XMPPConnection 類進行通信,作用是用戶和認(rèn)證,并發(fā)送推送通知消息。另外一部分是
15、Web 服務(wù)器,采用一個輕量級的 HTTP 服務(wù)器,負(fù)責(zé)接收用戶的 Web 請求。最上層包含四個組成部分,分別是 SesManager,Auth Manager,PresenceManager 以及 Notification Manager。SesManager 負(fù)責(zé)管理客戶端與服務(wù)器之間的會話。Auth Manager 負(fù)責(zé)客戶端用戶認(rèn)證管理。Presence Manager 負(fù)責(zé)管理客戶端用戶的登錄狀態(tài)。NotificationManager 負(fù)責(zé)實現(xiàn)服務(wù)器向客戶端推送消息功能。IQHandler 消息處理器的類:IQHandler:消息處理器抽象類。IQAuthHandler:權(quán)限協(xié)議的
16、消息處理類,消息的類型為:jabber:iq:authIQRegisterHandler:用戶jabber:iq:register的消息處理類,消息類型為:IQRosterHandler:用戶消息交互類,消息類型為:jabber:iq:rosterPresenceUpdateHandler:用戶狀態(tài)展現(xiàn)變化處理類。內(nèi)部調(diào)用,不具有類型。NotificationManager 源代碼:Java 代碼public claotificationManager private sic final String NOTIFICATION_NAMESPACE =androidpn:iq:notificat
17、ion;private final Log log = LogFactory.getLog(getClass();private SesManager sesManager;/* Constructor.*/public NotificationManager() sesManager = SesManager.getInstance();/* Broadcasts a newly created notification message to all connectedusers.* param apiKey the API key* param title the title* param
18、 message the messages* param uri the uri*/public void sendBroadcast(String apiKey, String title, String message,String uri) log.debug(sendBroadcast().);IQ notificationIQ = createNotificationIQ(apiKey, title, message, uri);for (CntSesses: sesManager.getSess() if (ses.getPresence().isAvailable() notif
19、icationIQ.setTo(ses.getAddress();ses.deliver(notificationIQ);/* Sends a newly created notification message to the specific user.* param apiKey the API key* param title the title* param message the messages* param uri the uri*/public void sendNotifcationToUser(String apiKey, String username,String ti
20、tle, String message, String uri) log.debug(sendNotifcationToUser().);IQ notificationIQ = createNotificationIQ(apiKey, title, message, uri);CntSesses= sesManager.getSes(username);if (ses!= null) if (ses.getPresence().isAvailable() notificationIQ.setTo(ses.getAddress();ses.deliver(notificationIQ);/* C
21、reates a new notification IQ and returns it.*/private IQ createNotificationIQ(String apiKey, String title,String message, String uri) Random random = new Random();String id =eger.toHexString(random.next();/ String id = String.valueOf(System.currentTimeMillis();Element notification =Helper.createElem
22、ent(QName.get(notification, NOTIFICATION_NAMESPACE);notification.addElement(id).setText(id);notification.addElement(apiKey).setText(apiKey);notification.addElement(title).setText(title);notification.addElement(message).setText(message);notification.addElement(uri).setText(uri);IQ iq = new IQ();iq.se
23、tType(IQ.Type.set);iq.setChildElement(notification);return iq; 其中:發(fā)布訂閱式的發(fā)送消息調(diào)用方法:/*Broadcasts a newly created notification message to all connected users.*param apiKey the API keyparam title the titleparam message the messageparam uri the uri*/spublic void sendBroadcast(String apiKey, String title,
24、String message,String uri);點對點的發(fā)送消息調(diào)用方法:/*Sends a newly created notification message to the specificuser.*param apiKey the API keyparam title the titleparam message the messageparam uri the uri*/spublic void sendNotifcationToUser(String apiKey, String username,String title, String message, String ur
25、i);創(chuàng)建發(fā)送消息的方法:/* Creates a new notification IQ and returns it.*/private IQ createNotificationIQ(String apiKey, String title,String message, String uri);androidpn 的學(xué)習(xí)(四)androidpn-c博客分類:Android 開發(fā)學(xué)習(xí)AndroidPn MQTT C2DM 推技術(shù)nt 客戶端幾個類說明在 androidpn 的客戶端幾個重要的類:ServiceManager:管理消息服務(wù)和加載相關(guān)的配置。ConnectivityReceiv
26、er:處理網(wǎng)絡(luò)狀態(tài)的廣播。NotificationReceiver:處理服務(wù)端發(fā)送的推送消息。NotificationService:服務(wù)用戶響應(yīng)服務(wù)端的消息。需要在 AndroidManifest.xml.。NotificationSettingivity:推送信息設(shè)置頁面。PersistentConnectionListener連接關(guān)閉和重連事件的。PhoneSeChangeListener:狀態(tài)的事件類。ReconnectionThread:重連的線程類。Notifier:客戶端發(fā)送通知的類。NotificationIQ:消息的數(shù)據(jù)包。ServiceManager 中獲取屬性信息的方法:
27、Java 代碼private Properties loroperties() /InputStream in = null;/Properties props = null;/try /in = getClass().getResourceAsStream(/androidpn/cnt/perties);/if (in != null) /props = new Properties();/props.load(in);/ else /Log.e(LOGTAG, Could not find the properties file.);/ catch (IOException e) /Log
28、.e(LOGTAG, Could not find the properties file., e);/ finally /if (in != null)/try /in.close();/ catch (Throwable ignore) /return props;Properties props = new Properties();try id = context.getResour().getIdentifier(androidpn, raw,context.getPackageName();props.load(context.getResour().openRawResource
29、(id); catch (Exception e) Log.e(LOGTAG, Could not find the properties file., e);/ e.prStackTrace();return props;SharedPreferenJava 代碼的使用: sharedPrefs = context.getSharedPreferen(Constants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); Editor editor = sharedPrefs.edit(); editor.putString(Constants.AP
30、I_KEY, apiKey); editor.putString(Constants.VER, ver);editor.putString(Constants.XMPP_HOST, xmppHost);editor.put(Constants.XMPP_PORT,egarse(xmppPort);editor.putString(Constants.CALLBACK_ACTIVITY_PACKAGE_NAME,callbackActivityPackageName);editor.putString(Constants.CALLBACK_ACTIVITY_CLASS_NAME,callback
31、ActivityClaame);mit();獲取Java 代碼的設(shè)備 id:ephonyManagerephonyManager = (ephonyManager)getSystemService(Context.EPHONY_SERVICE);/ wifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);/ connectivityManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);/ Get deviceIddev
32、iceId =ephonyManager.getDeviceId();Notifier 中發(fā)送通知的方法:Java 代碼 / Notification Notification notification = new Notification(); notification.icon = getNotificationIcon();notification.defaults = Notification.DEFAULT_LIGHTS;if (isNotificationSoundEnabled() notification.defaults |= Notification.DEFAULT_SOU
33、ND;if (isNotificationVibrateEnabled() notification.defaults |= Notification.DEFAULT_VIBRATE;notification.flags |= Notification.FLAG_AUTO_CANCEL;notification.when = System.currentTimeMillis();notification.tickerText = message;/entent;/if (uri != null/& uri.length() 0/& (uri.startsWith(http:) | uri.st
34、artsWith(https:)/| uri.startsWith(:) |uri.startsWith(geo:) /ent = newent(ent.ACTION_VIEW, Uri.parse(uri); / else /String callbackActivityPackageName =sharedPrefs.getString( /Constants.CALLBACK_ACTIVITY_PACKAGE_NAME, ); /String callbackActivityClaame =sharedPrefs.getString( /Constants.CALLBACK_ACTIVI
35、TY_CLASS_NAME,);/ent = newent().setClaame(callbackActivityPackageName,/callbackActivityClaame);/ent.setFlags(ent.FLAG_ACTIVITY_NEW_TASK);/ent.setFlags(ent.FLAG_ACTIVITY_SINGLE_TOP);/entent = newent(context,Notificationivity.class);ent.putExtra(Constants.NOTIFICATION_ID, notificationId);ent.putExtra(
36、Constants.NOTIFICATION_API_KEY, apiKey);ent.putExtra(Constants.NOTIFICATION_TITLE, title);ent.putExtra(Constants.NOTIFICATION_MESSAGE, message);ent.putExtra(Constants.NOTIFICATION_URI, uri);ent.setFlags(ent.FLAG_ACTIVITY_NEW_TASK);ent.setFlags(ent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);ent.setFlags(ent
37、.FLAG_ACTIVITY_NO_HISTORY);ent.setFlags(ent.FLAG_ACTIVITY_SINGLE_TOP);ent.setFlags(ent.FLAG_ACTIVITY_CLEAR_TOP); Pendingent contentent = Pendingent.getActivity(context, 0,ent, Pendingent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, title, message,contentent); notificationManager.no
38、tify(random.next(), notification);androidpn 用戶名和來源:XmppManager 的任務(wù)(RegisterTask)中 run 方法:if (!xmppManager.isRegistered() final String newUsername = newRandomUUID();final String nessword = newRandomUUID();Registration registration = new Registration();PacketFiltacketFilter = new AndFilter(necketIDFil
39、ter(cketTypeFilter(registration.getPacketID(), neIQ.class);androidpn 的學(xué)習(xí)(五)【轉(zhuǎn)】androidpn-c博客分類:Android 開發(fā)學(xué)習(xí)AndroidPn MQTT C2DM 推技術(shù)nt 常見 BUG 解決方法androidpnbugandroidXMPPopenfire原文地址:/forum.?mod=viewthread&tid=6&extra=page%3D1最近有需要做推送方面的項目,本人以前沒做過網(wǎng)絡(luò)編程也沒做過安卓,所以只,發(fā)現(xiàn) Androidpn 用的比較廣泛,但 Androidpn 還不成熟,存在一些
40、BUG。能目前比較困擾大家的BUG 主要有:當(dāng)服務(wù)端連續(xù)發(fā)送多條通知時,客戶端都是顯示同一條通知內(nèi)容。服務(wù)端重啟,客戶端也需要重啟建立連接。服務(wù)器端重啟的時候,客戶端就無法在連接到最后還有一個問題當(dāng)服務(wù)器了,除非把 android的服務(wù)關(guān)掉,然后重啟才行.在 XmmpManager 中加上如下紅色代碼就可:private void addTask(Runnable runnable) Log.d(LOGTAG, addTask(runnable).); taskTracker.increase();synchronized (taskList) if (taskList.isEmpty() &
41、 !running) running = true;futureTask = taskSubmitter.submit(runnable); if (futureTask = null) taskTracker.decrease(); else /解決服務(wù)器端重啟后,客戶端不能成功連接 androidpn 服務(wù)器runTask();taskList.add(runnable);Log.d(LOGTAG, addTask(runnable).e);由于沒有經(jīng)驗,有 BUG 也只能繼續(xù),最終發(fā)現(xiàn)http:/blog/1289383 這個 TOMCAT 版本比較符合項目的需求。在此還是要感謝這位大神
42、,真是造福廣大人民群眾。在這個版本中主要修復(fù)了第二個問題,相信很多朋友都已經(jīng)看過了這篇BLOG ,但是大神在回復(fù)中寫錯了類名 XMPPWriter,所有導(dǎo)致大家并不知道問題是怎么解決的, 其實是修改了t.XmppManager,.jivesoftware.smack.PacketWriter(smack 源碼)這2個類,這個將他2個版本的代碼比較一下就可以看出來了,廢話了那么多,在此說一下大神解決此問題的方法。代碼在/forum.?mod=viewthread&tid=5&extra=page%3D1篇帖子中已經(jīng)貼出來了。在t.XmppManager 的Logask 方法中加了一行代碼 get
43、Connection().startKeepAliveThread(xmppManager);進去發(fā)現(xiàn)是開啟了一個線程發(fā)送心跳,當(dāng)發(fā)送失敗時捕獲異常,客戶端每隔一段時間進行重連。.jivesoftware.smack.PacketWriter 的 run 方法Java 代碼catch (SocketException e) Log.e(PacketReader, e.toString();connection.disconnect();xmppManager.startReconnectionThread(); catch (IOException e) e.prStackTrace();這樣
44、就達到了當(dāng)與服務(wù)端失去連接時,客戶端能夠進行重新連接的效果。后來群里有朋友說在 Logask 方法中加入getConnection().startKeepAliveThread(xmppManager); 編譯就報錯,那是因為他用的是第一個版本 ,所有請先 第二個版本,第二個版本帶大神精簡過 smack 源碼。 其實心跳機制在 的 asmack 中就已經(jīng)存在,并且在建立 XmppConnection 的時候就已經(jīng)啟動,但是遺憾的是 asmack 的開發(fā) 并沒有進行異常之后的重連Java 代碼catch (Exception e) /othing 所有才出現(xiàn)這個困擾大家的問題。然后是第二個問題,
45、剛才的這個版本并沒有處理這個 BUG,其實很簡單,群里的高手經(jīng)解決,就是將t.Notifier 中的notify 方法的 Pendingent contentent = Pendingent.getActivity(context, 0,ent,Pendingent.FLAG_UPDATE_CURRENT);代碼改成 Pending random.nextent content(),ent = Pendingent.getActivity(context,ent, Pendingent.FLAG_UPDATE_CURRENT);代碼好了,這2個問題基本上就解決了,本人也只是在此將前輩們的經(jīng)驗寫
46、一下,方便大家集中修正BUG。其實在碰到框架 BUG 時,看看框架的源碼還是有幫助,可能會有很多不解,但我覺得多多少少還是能看出一點東西來。以后大家碰到什么問題也可以提出來,大家一起,集思廣益,總比一個人瞎想的強,有什么好的想法也可以拿出來。再次各位前輩。在網(wǎng)上 androidpn 上的 BUG 基本都解決了,也多虧牛人們頂力相助,感謝啊。在這里要說的問題是鎖屏后,客戶端心跳包不再發(fā)送了。由于 android 也接觸不是很久,對一些系統(tǒng)的機制不太了解,經(jīng)過多次測試與分析,才發(fā)現(xiàn)了是由于鎖屏后 CPU 處于睡眠狀態(tài),線程都被掛起,所以在服務(wù)器端設(shè)定的閑置時間內(nèi)收不到心跳包,強制移除用戶下線。OK
47、 問題已經(jīng)找到了就好辦多了,既然是被掛起了就只有讓心跳一直在跑了,不啰嗦了。既而在網(wǎng)上有找到兩種方法,第一種是讓系統(tǒng)不睡眠,第二種則是使用AlarmManager 來做的操作,在這里我是用的第二種方案來解決的問題的。但這樣可能有點費電,暫時只能這樣解決了了,不知道大家有木有更好點的解決辦法能說出來大家一起。1).java view plaincopypr?/申請設(shè)備電源鎖public void acquireWakeLock()if (null = mWakeLock)erManagm =(erManager)getSystemService(Context.ER_SERVICE);mWake
48、Lock =pm.newWakeLock(erManagARTIAL_WAKE_LOCK, NotificationService);if (null != mWakeLock)mWakeLock.acquire();/設(shè)備電源鎖public void releaseWakeLock()if (null != mWakeLock)mWakeLock.release();mWakeLock = null;Java 代碼/申請設(shè)備電源鎖public void acquireWakeLock()if (null = mWakeLock)erManagm =(erManager)getSystemSe
49、rvice(Context.ER_SERVICE);mWakeLock =pm.newWakeLock(erManagARTIAL_WAKE_LOCK, NotificationService);if (null != mWakeLock)mWakeLock.acquire();/設(shè)備電源鎖public void releaseWakeLock()if (null != mWakeLock)mWakeLock.release();mWakeLock = null;2).Java 代碼 public void registerAlarmManager()am = (AlarmManager)ge
50、tSystemService(ALARM_SERVICE);pi = Pendingent.getBroadcast(this, 0, newent(this,HeartActionBroadCast.class),ent.FLAG_ACTIVITY_NEW_TASK);long now = System.currentTimeMillis();am.setInexactRepeating(AlarmManager.RTC_WAKEUP, now, 20000, pi); androidpn 的學(xué)習(xí)(六)Androidpn-server 的 Mina 編碼和過程博客分類:Android 開發(fā)學(xué)
51、習(xí)AndroidPn MQTT C2DM 推技術(shù)androidpnminaFilterChainProtocolCodecFactory在許多網(wǎng)絡(luò)應(yīng)用中可能針對傳輸?shù)臄?shù)據(jù)進行加密操作,接收到數(shù)據(jù)之后進行操作。在 mina 中提供許多加密和的方式:1.帶一定前綴的字符串的方式。2.序列化對象的字符串方式。3.分隔符方式的字符串方式。在 mina 中提供相關(guān)的 filterchain 支持相關(guān)的操作。Mina 的源代碼如下:Java 代碼package.apache.mina.filter.codec;import.apache.mina.core.ses.IoSes;/* Provides li
52、nk ProtocolEncoder and link ProtocolDecoder whichtranslates* binary or protocol specific datao message object and vice versa.* * Please refer to* ReversrotocolProvider* example.* author Apache MINA Project*/publicerface ProtocolCodecFactory /* Returns a new (or reusable) instance of link ProtocolEnc
53、oderwhich* encodes message objectso binary or protocol-specific data.*/ProtocolEncoder getEncoder(IoSesses) throws Exception;/* Returns a new (or reusable) instance of link ProtocolDecoderwhich* decodes binary or protocol-specific datao message objects.*/ProtocolDecoder getDecoder(IoSesses) throws E
54、xception; 加理類:Java 代碼package.apache.mina.filter.codec;import.apache.mina.core.buffer.IoBuffer;import.apache.mina.core.ses.IoSes;/* Encodes higher-level message objectso binary or protocol-specificdata.* MINA invokes link #encode(IoSes, Object,ProtocolEncoderOutput)* method with message which is popp
55、ed from the seswrite queue, andthen* the encoder implemenion pucoded messages (typically linkIoBuffers)*o link ProtocolEncoderOutput by calling linkProtocolEncoderOutput#write(Object).* * Please refer to* TextLineEncoder* example.* author Apache MINA Project* see ProtocolEncoderException*/publicerfa
56、ce ProtocolEncoder /* Encodes higher-level message objectso binary orprotocol-specific data.* MINA invokes link #encode(IoSes, Object,ProtocolEncoderOutput)* method with message which is popped from the seswrite queue,and then* the encoder implemenion pucoded messages (typicallylink IoBuffers)*o lin
57、k ProtocolEncoderOutput.* throws Exception if the message violated protocol specification*/void encode(IoSesses, Object message,ProtocolEncoderOutput out)throws Exception;/* Releases all resourrelated with this encoder.* throws Exception iiled to dise all resour*/void dise(IoSesses) throws Exception
58、;類如下:Java 代碼 package.apache.mina.filter.codec; import.apache.mina.core.buffer.IoBuffer; import.apache.mina.core.ses.IoSes; /* Decodes binary or protocol-specific datao higher-level messageobjects.* MINA invokes link #decode(IoSes, IoBuffer,ProtocolDecoderOutput)* method with read data, and then the
59、decoder implemenion putsdecoded* messageso link ProtocolDecoderOutput by calling* link ProtocolDecoderOutput#write(Object).* * Please refer to* TextLineDecoder* example.* author Apache MINA Project* see ProtocolDecoderException*/publicerface ProtocolDecoder /* Decodes binary or protocol-specific con
60、tento higher-levelmessage objects.* MINA invokes link #decode(IoSes, IoBuffer,ProtocolDecoderOutput)* method with read data, and then the decoder implemenion putsdecoded* messageso link ProtocolDecoderOutput.* throws Exception if the read data violated protocol specification*/void decode(IoSesses, I
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 值班的管理制度
- 企業(yè)員工培訓(xùn)與績效提升制度
- 交通設(shè)施施工安全管理制度
- 2026年傳統(tǒng)文化與藝術(shù)文化遺產(chǎn)專家考試題目
- 2026年投資入門指南金融市場基礎(chǔ)知識筆試練習(xí)題
- 2026年國際漢語教師職業(yè)能力測試練習(xí)題
- 2026年網(wǎng)絡(luò)安全攻防技術(shù)考試題庫及答案詳解
- 2026年旅游行業(yè)從業(yè)者心理調(diào)適與應(yīng)對策略題
- 商超節(jié)日堆頭布置合同
- 2026年音樂療法體驗協(xié)議
- 國家中醫(yī)藥管理局《中醫(yī)藥事業(yè)發(fā)展“十五五”規(guī)劃》全文
- 師德師風(fēng)個人總結(jié)課件
- 化學(xué)-江蘇省蘇州市2024-2025學(xué)年第一學(xué)期學(xué)業(yè)質(zhì)量陽光指標(biāo)調(diào)研卷暨高二上學(xué)期期末考試試題和答案
- 精神科疑難病例討論
- 騰訊00后研究報告
- DL∕T 1882-2018 驗電器用工頻高壓發(fā)生器
- 固體廢物 鉛和鎘的測定 石墨爐原子吸收分光光度法(HJ 787-2016)
- DB45-T 2675-2023 木薯米粉加工技術(shù)規(guī)程
- 板材眼鏡生產(chǎn)工藝
- Unit 3 My weekend plan B Let's talk(教案)人教PEP版英語六年級上冊
- 實習(xí)考勤表(完整版)
評論
0/150
提交評論