亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? jxtapeer.java

?? javaP2P技術內幕課程19-20的源代碼
?? JAVA
字號:
/*
 * We customized our SOAP-over-P2P implementation 
 * by using different examples provided at JXTA.org. 
 * That's the reason for copying the license information here.
 *
 * Copyright (c) 2001 Sun Microsystems, Inc.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *       Sun Microsystems, Inc. for Project JXTA."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact Project JXTA at http://www.jxta.org.
 *
 * 5. Products derived from this software may not be called "JXTA",
 *    nor may "JXTA" appear in their name, without prior written
 *    permission of Sun.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of Project JXTA.  For more
 * information on Project JXTA, please see
 * <http://www.jxta.org/>.
 *
 * This license is based on the BSD license adopted by the Apache Foundation.
 *
 */


package ch20.peer;


import java.io.FileInputStream;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Enumeration;
import java.net.URL;

import java.net.MalformedURLException;
import net.jxta.pipe.PipeID;
import net.jxta.document.TextElement;
import net.jxta.platform.Application;
import net.jxta.document.Advertisement;
import net.jxta.document.AdvertisementFactory;
import net.jxta.document.StructuredDocumentFactory;
import net.jxta.document.StructuredTextDocument;
import net.jxta.document.StructuredDocument;
import net.jxta.document.MimeMediaType;
import net.jxta.document.Element;
import net.jxta.document.StructuredDocumentUtils;
import net.jxta.endpoint.Message;
import net.jxta.pipe.PipeService;
import net.jxta.id.IDFactory;
import net.jxta.pipe.OutputPipe;
import net.jxta.pipe.InputPipe;
import net.jxta.id.ID;
import net.jxta.platform.ModuleClassID;
import net.jxta.pipe.InputPipe;
import net.jxta.peergroup.PeerGroup;
import net.jxta.peergroup.PeerGroupID;
import net.jxta.peergroup.PeerGroupFactory;
import net.jxta.protocol.PeerGroupAdvertisement;
import net.jxta.protocol.ModuleSpecAdvertisement;
import net.jxta.protocol.ModuleClassAdvertisement;
import net.jxta.protocol.PipeAdvertisement;
import net.jxta.discovery.DiscoveryService;
import net.jxta.exception.PeerGroupException;
import net.jxta.impl.peergroup.Platform;
import net.jxta.impl.peergroup.GenericPeerGroup;

import net.jxta.pipe.PipeMsgListener;
import net.jxta.pipe.PipeMsgEvent;

import javax.swing.*;


public class JXTAPeer implements PipeMsgListener{

	protected static PeerGroup group = null;
	protected PeerGroupAdvertisement groupAdvertisement = null;
	protected DiscoveryService disco;
	protected PipeService pipes;
	protected Message msg;      

	private static int objectCount = 0;

	private PipeMsgListener listener;

	protected JTextArea receiver;


	public JXTAPeer(){
		if (group==null)
		{
			try {
				// Create the default NetPeerGroup.
				group = PeerGroupFactory.newNetPeerGroup();
			} catch (Exception e) {
				System.out.println("fatal error : group creation failure");
				e.printStackTrace();
			}//catch
			objectCount++;
		}//if (!objectCount)
		startJXTA();
	}//constructor


	protected void startJXTA() {
		
		// Obtain the group advertisement
		groupAdvertisement = group.getPeerGroupAdvertisement();

		// get the discovery, and pipe service
		disco = group.getDiscoveryService();
		pipes = group.getPipeService();
	}//startJXTA()


	public InputPipe publishServiceOverJXTAPipe(
			String ServiceName,//Name of service being published.
			String ServiceVersion,//Version of the service.
			String ServiceDescription,//Description of the service.
			String ServiceCreator,//Creator of the service.
			String SpecURI,//URI of the service apecification.
			String PipeAdvFile//Name of service XML advertisement.
	){

		receiver.setText(receiver.getText()+
			"Starting to create input pipe service to receive messages:\n");
		
		try {
			// Shortform class advertisement.
			ModuleClassAdvertisement mcadv = (ModuleClassAdvertisement)
			AdvertisementFactory.newAdvertisement(
			ModuleClassAdvertisement.getAdvertisementType());
			mcadv.setName("JXTAMOD:"+ServiceName);
			mcadv.setDescription(ServiceDescription);
			ModuleClassID mcID = IDFactory.newModuleClassID();
			mcadv.setModuleClassID(mcID);
	
			// Publsih the shortform class advertisement.
			disco.publish(mcadv, DiscoveryService.ADV);
			disco.remotePublish(mcadv, DiscoveryService.ADV);

			// Now create the detailed module advertisement.
			ModuleSpecAdvertisement mdadv = 
		     	(ModuleSpecAdvertisement)AdvertisementFactory.newAdvertisement(
			ModuleSpecAdvertisement.getAdvertisementType());
			mdadv.setName("JXTASPEC:"+ServiceName);
			mdadv.setVersion(ServiceVersion);
			mdadv.setCreator(ServiceCreator);
			mdadv.setDescription(ServiceDescription);
			mdadv.setModuleSpecID(IDFactory.newModuleSpecID(mcID));
			mdadv.setSpecURI(SpecURI);

			// Now create the pipe advertismeent.
			// We will later copy the pipe advert
			// into the module spec advert.
			PipeAdvertisement pipeadv = null;
			try {
				FileInputStream is = 
					new FileInputStream(PipeAdvFile);
				pipeadv = (PipeAdvertisement)
					AdvertisementFactory.newAdvertisement(
					new MimeMediaType("text/xml"), is);
				is.close();
			} catch (Exception e) {
				receiver.setText(receiver.getText()+"\n"+
				"Error reading advert file "+ PipeAdvFile);
				return null;
			}//catch

			// Now copy the pipe advert
			// into the module spec advert.
			StructuredTextDocument paramDoc =
				(StructuredTextDocument) 
				StructuredDocumentFactory.newStructuredDocument
				(new MimeMediaType("text/xml"),"Parm");

			StructuredDocumentUtils.copyElements(
				paramDoc, 
				paramDoc, 
				(Element)pipeadv.getDocument(
					new MimeMediaType("text/xml"))
				);
			mdadv.setParam((StructuredDocument) paramDoc);

			// Publish the module spec advert.
			disco.publish(mdadv, DiscoveryService.ADV);
			disco.remotePublish(mdadv, DiscoveryService.ADV);

			// We are now all set to create our input pipe.
			InputPipe ip = pipes.createInputPipe(pipeadv, 
				((listener==null)?this:listener));

			receiver.setText(receiver.getText()+
				"Input Pipe service created.\n");
		
			return ip;
		} catch (Exception ex) {
			receiver.setText(receiver.getText()+
				"Error in publishing.\n");
			return null;

		}//catch
	}//publishServiceOverJXTAPipe()


	public void createOutputPipeAndSendMessage(
			String ServiceName,//Name of output pipe service.
			String resBody//Message to be sent.
								){
		

		OutputPipe myOutPipe;
		Message msg = null;      // pipe message received
	
		Enumeration enum = null;

		// Find the module spec advertisement.
		while (true) {
			try {
				receiver.setText(receiver.getText()+
					"\nLooking for the pipe advertisement: "+
					ServiceName+" .........\n");
				enum = disco.getLocalAdvertisements(DiscoveryService.ADV
						     , "Name"
						     , "JXTASPEC:"+ServiceName);
				if ((enum != null) && enum.hasMoreElements()) break;

				disco.getRemoteAdvertisements(null, 
								DiscoveryService.ADV,
								"Name",
								"JXTASPEC:"+ServiceName,											1, 
								null);
	
				try { Thread.sleep(2000);} catch (Exception e){}
	    		} catch (Exception e){   }
		} // while (true)
   
		// Now extract the pipe advert from module spec advert.
		ModuleSpecAdvertisement mdsadv = 
			(ModuleSpecAdvertisement) enum.nextElement();
		try {
			StructuredTextDocument paramDoc = 
				(StructuredTextDocument)  mdsadv.getParam();

			String pID = null;
			String pType = null;

		    	Enumeration elements = paramDoc.getChildren("jxta:PipeAdvertisement");

			elements = ((TextElement) elements.nextElement()).getChildren();

			while (elements.hasMoreElements()) {
				TextElement elem = (TextElement) elements.nextElement();
				String nm = elem.getName();

				if(nm.equals("Id")) {
			    		pID = elem.getTextValue();
					continue;
			 	}

			 	if(nm.equals("Type")) {
			    		pType = elem.getTextValue();
			    		continue;
			 	}
			} // while

		    	PipeAdvertisement pipeadv = (PipeAdvertisement) 
				AdvertisementFactory.newAdvertisement(
				PipeAdvertisement.getAdvertisementType());
	    
			try {
	            	URL pipeID = new URL(pID );
	            	pipeadv.setPipeID( (PipeID) IDFactory.fromURL( pipeID ) );
				pipeadv.setType(pType);
			} catch ( MalformedURLException badID ) {
		   		badID.printStackTrace();
	            	throw new IllegalArgumentException( 
					"Bad pipe ID in advertisement" );
			}//catch
	    
			myOutPipe = pipes.createOutputPipe(pipeadv, 11000);
	    	
			// Create a new message.
			msg = pipes.createMessage();

			msg.setString("ServiceName", ServiceName);
 			msg.setString("SOAPResponse", resBody);

			myOutPipe.send (msg);

		}catch (Exception ex) {
			receiver.setText(receiver.getText()+
				"Error in sending the message.\n");
		}//catch
	} // getNewAdvmtAndSendResponse(String resBody)


	public void setInputPipeMessageListener(PipeMsgListener msgListener)
	{
		listener = msgListener;

	}//private setInputPipeMessageListener()




	public void pipeMsgEvent ( PipeMsgEvent event ){
		receiver.setText(receiver.getText()+
			"Message received.\n");
	}//pipeMsgEvent

	public void setMessageReceiver(JTextArea msgReceiver){
		receiver = msgReceiver;
	}//setMessageReceiver

}//JXTAPeer

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
2021久久国产精品不只是精品| 精品粉嫩aⅴ一区二区三区四区| 日韩高清欧美激情| 久久色成人在线| 欧美色爱综合网| 国内精品写真在线观看| 亚洲欧美国产三级| 精品国产乱码久久| 欧美三级日韩三级| 91麻豆精品一区二区三区| 久久精品国内一区二区三区| 亚洲精品免费在线| 国产精品免费观看视频| 精品国产伦一区二区三区观看方式| 在线观看日韩毛片| 99久久久久久| jlzzjlzz欧美大全| 国产乱码精品一区二区三| 日本aⅴ亚洲精品中文乱码| 亚洲免费在线观看视频| 国产精品国产三级国产aⅴ无密码| 日韩一级成人av| 91精品国产综合久久久久久久| 色偷偷88欧美精品久久久| 成人免费va视频| 成人一区二区三区视频在线观看 | 亚洲精品国产一区二区精华液| 久久夜色精品国产噜噜av| 欧美一激情一区二区三区| 日本久久一区二区三区| 99在线精品视频| 成人av在线资源网站| 国产成人精品影院| 国产成人午夜高潮毛片| 国产美女视频一区| 国产一区二区三区四| 韩国午夜理伦三级不卡影院| 极品少妇xxxx偷拍精品少妇| 免费观看久久久4p| 久久精品国内一区二区三区| 免费看精品久久片| 久久99国产精品麻豆| 久久99国产精品久久99果冻传媒| 国模大尺度一区二区三区| 国产精品自拍网站| 懂色av噜噜一区二区三区av| 成人福利视频在线看| 成人国产精品视频| 色偷偷一区二区三区| 欧美自拍偷拍一区| 欧美日韩大陆在线| 日韩一级大片在线| 久久九九全国免费| 国产精品少妇自拍| 一区二区在线观看视频| 亚洲高清免费在线| 麻豆高清免费国产一区| 免费在线观看日韩欧美| 国内一区二区视频| 国产69精品一区二区亚洲孕妇| 北条麻妃国产九九精品视频| 在线视频你懂得一区二区三区| 欧美色视频一区| 欧美一级欧美三级在线观看| 久久久精品日韩欧美| 亚洲欧洲三级电影| 午夜精品久久久久久久久久久| 男女男精品视频网| jlzzjlzz国产精品久久| 欧美日韩情趣电影| 2023国产精品自拍| 亚洲乱码国产乱码精品精的特点| 日韩制服丝袜先锋影音| 国产电影精品久久禁18| 色94色欧美sute亚洲线路二| 成人激情校园春色| 欧美三级三级三级| 久久久国产午夜精品| 一区二区国产视频| 极品少妇xxxx偷拍精品少妇| 91蜜桃视频在线| 欧美大尺度电影在线| 国产精品久久久久久久久免费桃花| 一区二区三区视频在线观看| 国产一区二区电影| 在线免费观看日本一区| 精品1区2区在线观看| 亚洲激情校园春色| 国产精品一区二区久久不卡 | 国产丝袜欧美中文另类| 亚洲久草在线视频| 国产在线一区观看| 欧美三级韩国三级日本一级| 久久久久成人黄色影片| 日韩福利视频网| 97久久久精品综合88久久| 欧美挠脚心视频网站| 国产欧美一区二区三区鸳鸯浴| 亚洲午夜精品在线| 成人黄色软件下载| 日韩欧美高清在线| 亚洲一级二级三级| 成人性生交大片免费看在线播放| 91精品国产手机| 一区二区三区四区乱视频| 国产乱色国产精品免费视频| 欧美情侣在线播放| 亚洲精品免费在线播放| 成人免费高清在线| 精品少妇一区二区三区免费观看| 亚洲综合色视频| 91小视频免费观看| 欧美国产综合色视频| 久久精品国产成人一区二区三区 | 色婷婷久久久综合中文字幕| 国产欧美一区视频| 看电影不卡的网站| 欧美人狂配大交3d怪物一区| 亚洲欧美日韩一区二区三区在线观看| 国产美女视频91| 精品欧美一区二区在线观看| 亚洲成人免费在线观看| 日本电影亚洲天堂一区| 亚洲欧洲一区二区三区| 成人av资源网站| 欧美韩日一区二区三区四区| 麻豆精品在线看| 精品日韩欧美在线| 久久99国产精品久久| 日韩精品一区二区三区在线| 青娱乐精品在线视频| 69堂成人精品免费视频| 亚洲国产成人精品视频| 精品视频一区 二区 三区| 夜夜揉揉日日人人青青一国产精品| 97久久超碰国产精品| 亚洲欧洲另类国产综合| 成人的网站免费观看| 中文字幕不卡在线观看| 成人黄色综合网站| 中文字幕一区二区三区在线观看| 成人免费视频免费观看| 欧美国产精品一区| 成人动漫在线一区| 亚洲蜜桃精久久久久久久| 欧美影视一区二区三区| 日韩av中文字幕一区二区三区| 7777精品伊人久久久大香线蕉最新版| 日本在线不卡一区| 日韩精品一区二区三区四区| 韩国一区二区在线观看| 国产视频一区二区三区在线观看 | 欧美日韩国产首页| 日本va欧美va精品发布| 久久综合久久久久88| 高清beeg欧美| 亚洲欧美在线另类| 欧美在线不卡视频| 久色婷婷小香蕉久久| 国产午夜精品一区二区三区四区| 不卡的av网站| 一区二区在线免费| 日韩一级片网站| 国产99久久久久久免费看农村| 专区另类欧美日韩| 欧美三级电影精品| 久久99精品久久久久婷婷| 日本一区二区久久| 欧美视频在线一区二区三区| 日韩精品一区第一页| 久久久亚洲午夜电影| 91在线观看一区二区| 亚洲一区在线看| 久久亚洲捆绑美女| 91碰在线视频| 久久精品国产99国产精品| 中文字幕在线不卡一区| 欧美日韩国产综合一区二区三区| 蜜桃久久av一区| 国产精品视频第一区| 91精品国产高清一区二区三区蜜臀| 国产精品99久久久久久宅男| 亚洲精品中文在线观看| 宅男在线国产精品| 波多野结衣91| 免费日韩伦理电影| 亚洲人成影院在线观看| 欧美一级日韩一级| av影院午夜一区| 捆绑变态av一区二区三区| 亚洲人成网站精品片在线观看| 日韩免费看的电影| 91在线精品一区二区| 狠狠色丁香九九婷婷综合五月| 亚洲女性喷水在线观看一区| 久久亚洲欧美国产精品乐播| 欧美日本一区二区在线观看| 91在线你懂得| 国产精品一区二区三区乱码| 青青草97国产精品免费观看无弹窗版|