• 沒有找到結果。

D. E XAMPLE P ROGRAM

II. Subscribe Client

try {

peer.leave();

} catch (PeerLeaveException ex) {

//peer may not leave network correctly, //stabilization will handle the error ex.printStackTrace();

} } } else {

// join failed, exit program System.exit(1);

} } }

II. Subscribe Client

package pubsub.app;

import dcslab.p2p.IdFactory;

import dcslab.p2p.Peer;

import dcslab.p2p.PeerFactory;

import dcslab.p2p.PeerJoinException;

import dcslab.p2p.PeerLeaveException;

import dcslab.p2p.boot.BootstrapService;

import dcslab.p2p.boot.impl.LocalBootstrapService;

import dcslab.p2p.environment.Environment;

import dcslab.p2p.pubsub.PubSubException;

import dcslab.p2p.pubsub.PubSubService;

import dcslab.p2p.pubsub.Subscriber;

import dcslab.p2p.pubsub.Topic;

import dcslab.p2p.pubsub.event.Event;

import dcslab.p2p.pubsub.event.EventHandler;

import dcslab.p2p.pubsub.event.TextEvent;

import dcslab.p2p.pubsub.impl.SimplePubSubService;

import dcslab.p2p.transport.CommunicationManager;

import dcslab.p2p.transport.impl.TCPCommunicationManager;

import dcslab.p2p.impl.RingIdFactory;

import dcslab.p2p.impl.RingPeerFactory;

import java.io.File;

import java.io.IOException;

public class SubscribeClient {

public static void main(String[] args) {

//determine underlying transportation mechanism

Environment env = new Environment(new File(“example.cfg”));

CommunicationManager mgr = new TCPCommunicationManager(env);

//determine p2p network type and id type

IdFactory idFactory = new ViceroyIdFactory(env);

PeerFactory factory = new ViceroyPeerFactory(idFactory, mgr);

//peer initialization

Peer peer = factory.createPeer();

PubSubService service = new SimplePubSubService();

peer.register(service);

//connect to http boot server

BootstrapService bootService = new HttpBootstrapService(env);

try { //perform join operation

NodeHandle localhandle = peer.getLocalHandle();

NodeHandle booter=bootService.getBootstrapper(localhandle);

peer.join(booter);

} catch (PeerJoinException ex) {//if join failed on exception ex.printStackTrace();

}

if (peer.isJoined()) {

//create subscriber associated with specific topic and peer Topic topic = new Topic(idFactory, "hello topic");

Subscriber subscriber = null;

try {

subscriber = new Subscriber(service, topic);

//set message listener to catch message event subscriber.setEventHandler(new EventHandler() { public void onEvent(Topic topic, Event event) { if (event instanceof TextEvent) {

System.out.println(

topic.getTopicName() +

((TextEvent) event).getText());

} } });

try { //wait until user input ‘q’

for (int c = 0; c != 'q'; c = System.in.read()){}

} catch (IOException ex) {}

} catch (PubSubException ex) { //subscribe fail ex.printStackTrace();

} finally { //clean up subscriber and peer try {

if (subscriber != null) { subscriber.unsubscribe();}

} catch (PubSubException ex) {}

try { peer.leave(); } catch (PeerLeaveException ex) {}

} } else {

// join failed, exit program System.exit(1);

} } }

8. References

[1] K. Aberer, L. O. Alima, A. Ghodsi, S. Girdzijauskas, S. Haridi and M.

Hauswirth, "The Essence of P2P: A Reference Architecture for Overlay Networks," P2P, vol. 0, pp. 11-20, 2005.

[2] J. Aspnes and G. Shah, "Skip graphs," ACM Trans. Algorithms, vol. 3, pp. 37, 2007.

[3] M. Bender, S. Michel, S. Parkitny and G. Weikum, "A Comparative Study of Pub/Sub Methods in Structured P2P Networks," Databases, Information Systems, and Peer-to-Peer Computing, pp. 385-396, 2007.

[4] M. Castro, P. Druschel, A. -M. Kermarrec and A. I. T. Rowstron, "Scribe: a large-scale and decentralized application-level multicast infrastructure," Selected Areas in Communications, IEEE Journal on, vol. 20, pp. 1489-1499, 2002.

[5] G. Ciaccio, "A Pretty Flexible API for Generic Peer-to-Peer Programming,"

Parallel and Distributed Processing Symposium, 2007. IPDPS 2007. IEEE International, pp. 1-8, 26-30 March 2007.

[6] F. Dabek, M. F. Kaashoek, D. Karger, R. Morris and I. Stoica, "Wide-area cooperative storage with CFS," SIGOPS Oper. Syst. Rev., vol. 35, pp. 202-215, 2001.

[7] F. Dabek, B. Zhao, P. Druschel, J. Kubiatowicz and I. Stoica, "Towards a Common API for Structured Peer-to-Peer Overlays," Peer-to-Peer Systems II, pp. 33-44, 2003.

[8] F. Delmastro, M. Conti and E. Gregori, "P2P common API for structured overlay networks: A cross-layer extension," in WOWMOM '06: Proceedings of the 2006 International Symposium on on World of Wireless, Mobile and

Multimedia Networks, 2006, pp. 593-597.

[9] P. Fraigniaud and P. Gauron, "D2B: A de Bruijn based content-addressable network," Theoretical Computer Science, vol. 355, pp. 65-79, 4/6. 2006.

[10] D. Haussheer, "Decentralized auction-based pricing with PeerMart," Integrated Network Management, 2005. IM 2005. 2005 9th IFIP/IEEE International Symposium on, pp. 381-394, 2005.

[11] M. O. Junginger, "A self-organizing publish/subscribe middleware for dynamic peer-to-peer networks," Network, IEEE, vol. 18, pp. 38-43, 2004.

[12] M. Kaashoek and D. Karger, "Koorde: A Simple Degree-Optimal Distributed Hash Table," Peer-to-Peer Systems II, pp. 98-107, 2003.

[13] Y. Kulbak and D. Bickson, "The emule protocol specification," 2005.

[14] A. Loo, “The future of peer-to-peer computing,” Communications of the ACM, vol. 46, issue 9, pp. 57, 2003.

[15] E. K. Lua, J. Crowcroft, M. Pias, R. Sharma and S. Lim, "A Survey and Comparison of Peer-to-Peer Overlay Network Schemes," Communications Surveys & Tutorials, IEEE, vol. 7, pp. 72-93, 2005.

[16] D. Malkhi, M. Naor and D. Ratajczak, "Viceroy: a scalable and dynamic emulation of the butterfly," pp. 183-192, 2002.

[17] P. Manish, J. Nanyan, S. Cristina and M. Vincent. (2007, Feb. 21). Meteor. 2.4.1 Available: https://jxta-meteor.dev.java.net/

[18] J. Márk, M. Alberto, P. Gian Jesi and V. Spyros. (2007, Dec. 23). PeerSim: A peer-to-peer simulator. 1.0.3

Available: http://peersim.sourceforge.net/

[19] P. Maymounkov and D. Mazieres, "Kademlia: A Peer-to-peer Information System Based on the XOR Metric," 2002.

Available: http://tw.nuweb.cc/

[21] OSGi Alliance, "OSGi Service Platform Core Specification Release 4.1,"

October. 2007.

[22] D. Peter, E. Eric, G. Romer, H. Andreas, H. Jeff, C. Y. Hu, I. Sitaram, L. Andrew, M. Alan, N. Animesh, P. Ansley, R. Charlie, S. Dan, S. Jim, S. Atul and Z.

RongMei. (2007, Nov. 2). FreePastry. 2.0_03 Available: http://freepastry.rice.edu/FreePastry/

[23] P. Pietzuch, D. Eyers, S. Kounev and B. Shand, "Towards a common API for Publish/Subscribe," in DEBS '07: Proceedings of the 2007 Inaugural International Conference on Distributed Event-Based Systems, 2007, pp.

152-157.

[24] C. G. Plaxton, R. Rajaraman and A. W. Richa, "Accessing Nearby Copies of Replicated Objects in a Distributed Environment," Theory of Computing Systems, vol. 32, pp. 241-280, 02/24. 1999.

[25] J. Pouwelse, P. Garbacki, D. Epema and H. Sips, "The Bittorrent P2P File-Sharing System: Measurements and Analysis," Peer-to-Peer Systems IV, pp.

205-216, 2005.

[26] W. Pugh, "Skip lists: a probabilistic alternative to balanced trees," Commun ACM, vol. 33, pp. 668-676, 1990.

[27] S. Ratnasamy, P. Francis, M. Handley, R. Karp and S. Schenker, "A scalable content-addressable network," in SIGCOMM '01: Proceedings of the 2001 Conference on Applications, Technologies, Architectures, and Protocols for Computer Communications, 2001, pp. 161-172.

[28] J. Risson and T. Moors, "Survey of Research Towards Robust Peer-to-Peer Networks: Search Methods," Computer Networks, vol. 50, pp. 3485-3521, 12/5.

2006.

[29] B. Roberto, Q. Leonardo and V. Antonino, “Distributed event routing in Publish/Subscribe communication systems: A survey,” In: Technical Report TR-1/06, rnDipartimento di Informatica e Sistemistica, nUniversitá di Roma ‘La Sapienza’ (2005).

[30] R. Rodrigues, B. Liskov and L. Shrira, "The design of a robust peer-to-peer system," in EW10: Proceedings of the 10th Workshop on ACM SIGOPS European Workshop, 2002, pp. 117-124.

[31] A. I. T. Rowstron and P. Druschel, "Pastry: Scalable, decentralized object location, and routing for large-scale peer-to-peer systems," in Middleware '01:

Proceedings of the IFIP/ACM International Conference on Distributed Systems Platforms Heidelberg, 2001, pp. 329-350.

[32] I. Stoica, D. Adkins, S. Zhuang, S. Shenker and S. Surana, "Internet indirection infrastructure," in SIGCOMM '02: Proceedings of the 2002 Conference on Applications, Technologies, Architectures, and Protocols for Computer Communications, 2002, pp. 73-86.

[33] I. Stoica, R. Morris, D. Karger, M. F. Kaashoek and H. Balakrishnan, "Chord: A scalable peer-to-peer lookup service for internet applications," SIGCOMM Comput. Commun. Rev., vol. 31, pp. 149-160, 2001.

[34] Sun Microsystems Inc. (2007, Oct 16th). JXTA v2.0 protocols specification.

Available: https://jxta-spec.dev.java.net/nonav/JXTAProtocols.html [35] Sun Microsystems Inc. (2003, Dec 2nd). Java message service API.

Available: http://www.jcp.org/en/jsr/detail?id=914

[36] B. Zhao, J. Kubiatowicz and A. Joseph, "Tapestry: An infrastructure for fault-tolerant wide-area location and routing," Computer Science Division, U. C.

Berkeley, apr, 2001.

相關文件