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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? socketproxy.java

?? Chord package into p2psim
?? JAVA
?? 第 1 頁 / 共 3 頁
字號:
/***************************************************************************
 *                                                                         *
 *                             SocketProxy.java                            *
 *                            -------------------                          *
 *   date                 : 12.08.2004                                     *
 *   copyright            : (C) 2004-2008 Distributed and                  *
 *                              Mobile Systems Group                       *
 *                              Lehrstuhl fuer Praktische Informatik       *
 *                              Universitaet Bamberg                       *
 *                              http://www.uni-bamberg.de/pi/              *
 *   email                : sven.kaffille@uni-bamberg.de                   *
 *                          karsten.loesing@uni-bamberg.de                 *
 *                                                                         *
 *                                                                         *
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   A copy of the license can be found in the license.txt file supplied   *
 *   with this software or at: http://www.gnu.org/copyleft/gpl.html        *
 *                                                                         *
 ***************************************************************************/
package de.uniba.wiai.lspi.chord.com.socket;

import static de.uniba.wiai.lspi.util.logging.Logger.LogLevel.DEBUG;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import de.uniba.wiai.lspi.chord.com.CommunicationException;
import de.uniba.wiai.lspi.chord.com.Endpoint;
import de.uniba.wiai.lspi.chord.com.Entry;
import de.uniba.wiai.lspi.chord.com.Node;
import de.uniba.wiai.lspi.chord.com.Proxy;
import de.uniba.wiai.lspi.chord.com.RefsAndEntries;
import de.uniba.wiai.lspi.chord.data.ID;
import de.uniba.wiai.lspi.chord.data.URL;
import de.uniba.wiai.lspi.util.logging.Logger;

/**
 * This is the implementation of {@link Proxy} for the socket protocol. This
 * connects to the {@link SocketEndpoint endpoint} of the node it represents by
 * means of <code>Sockets</code>.
 * 
 * @author sven
 * @version 1.0.5
 */
public final class SocketProxy extends Proxy implements Runnable {

	/**
	 * The logger for instances of this class.
	 */
	private final static Logger logger = Logger.getLogger(SocketProxy.class);

	/**
	 * Map of existing proxies. Key: {@link String}, Value: {@link SocketProxy}.
	 * changed on 21.03.2006 by sven. See documentation of method
	 * {@link #createProxyKey(URL, URL)}
	 * 
	 */
	private static Map<String, SocketProxy> proxies = new HashMap<String, SocketProxy>();

	/**
	 * The {@link URL}of the node that uses this proxy to connect to the node,
	 * which is represented by this proxy.
	 * 
	 */
	private URL urlOfLocalNode = null;

	/**
	 * Counter for requests that have been made by this proxy. Also required to
	 * create unique identifiers for {@link Request requests}.
	 */
	private long requestCounter = -1;

	/**
	 * The socket that provides the connection to the node that this is the
	 * Proxy for. This is transient as a proxy can be transferred over the
	 * network. After transfer this socket has to be restored by reconnecting to
	 * the node.
	 */
	private transient Socket mySocket;

	/**
	 * The {@link ObjectOutputStream}this Proxy writes objects to. This is
	 * transient as a proxy can be transferred over the network. After transfer
	 * this stream has to be restored.
	 */
	private transient ObjectOutputStream out;

	/**
	 * The {@link ObjectInputStream}this Proxy reads objects from. This is
	 * transient as a proxy can be transferred over the network. After transfer
	 * this stream has to be restored.
	 */
	private transient ObjectInputStream in;

	/**
	 * The {@link ObjectInputStream} this Proxy reads objects from. This is
	 * transient as a proxy can be transferred over the network. After transfer
	 * this stream has to be restored.
	 */
	private transient Map<String, Response> responses;

	/**
	 * {@link Map} where threads are put in that are waiting for a repsonse.
	 * Key: identifier of the request (same as for the response). Value: The
	 * Thread itself.
	 */
	private transient Map<String, WaitingThread> waitingThreads;

	/**
	 * This indicates that an exception occured while waiting for responses and
	 * that the connection to the {@link Node node}, that this is the proxy
	 * for, could not be reestablished.
	 */
	private volatile boolean disconnected = false;

	/**
	 * Establishes a connection from <code>urlOfLocalNode</code> to
	 * <code>url</code>. The connection is represented by the returned
	 * <code>SocketProxy</code>.
	 * 
	 * @param url
	 *            The {@link URL} to connect to.
	 * @param urlOfLocalNode
	 *            {@link URL} of local node that establishes the connection.
	 * @return <code>SocketProxy</code> representing the established
	 *         connection.
	 * @throws CommunicationException
	 *             Thrown if establishment of connection to <code>url</code>
	 *             failed.
	 */
	public static SocketProxy create(URL urlOfLocalNode, URL url)
			throws CommunicationException {
		synchronized (proxies) {
			/*
			 * added on 21.03.2006 by sven. See documentation of method
			 * createProxyKey(URL, URL);
			 */
			String proxyKey = SocketProxy.createProxyKey(urlOfLocalNode, url);
			logger.debug("Known proxies " + SocketProxy.proxies.keySet());
			if (proxies.containsKey(proxyKey)) {
				logger.debug("Returning existing proxy for " + url);
				return proxies.get(proxyKey);
			} else {
				logger.debug("Creating new proxy for " + url);
				SocketProxy newProxy = new SocketProxy(url, urlOfLocalNode);
				proxies.put(proxyKey, newProxy);
				return newProxy;
			}
		}
	}

	/**
	 * Closes all outgoing connections to other peers. Allows the local peer to
	 * shutdown cleanly.
	 * 
	 */
	static void shutDownAll() {
		Set<String> keys = proxies.keySet();
		for (String key : keys) {
			proxies.get(key).disconnect();
		}
		proxies.clear();
	}

	/**
	 * Creates a <code>SocketProxy</code> representing the connection from
	 * <code>urlOfLocalNode</code> to <code>url</code>. The connection is
	 * established when the first (remote) invocation with help of the
	 * <code>SocketProxy</code> occurs.
	 * 
	 * @param url
	 *            The {@link URL} of the remote node.
	 * @param urlOfLocalNode
	 *            The {@link URL} of local node.
	 * @param nodeID
	 *            The {@link ID} of the remote node.
	 * @return SocketProxy
	 */
	protected static SocketProxy create(URL url, URL urlOfLocalNode, ID nodeID) {
		synchronized (proxies) {
			/*
			 * added on 21.03.2006 by sven. See documentation of method
			 * createProxyKey(String, String);
			 */
			String proxyKey = SocketProxy.createProxyKey(urlOfLocalNode, url);
			logger.debug("Known proxies " + SocketProxy.proxies.keySet());
			if (proxies.containsKey(proxyKey)) {
				logger.debug("Returning existing proxy for " + url);
				return proxies.get(proxyKey);
			} else {
				logger.debug("Creating new proxy for " + url);
				SocketProxy proxy = new SocketProxy(url, urlOfLocalNode, nodeID);
				proxies.put(proxyKey, proxy);
				return proxy;
			}
		}
	}

	/**
	 * Method that creates a unique key for a SocketProxy to be stored in
	 * {@link #proxies}.
	 * 
	 * This is important for the methods {@link #create(URL, URL)},
	 * {@link #create(URL, URL, ID)}, and {@link #disconnect()}, so that
	 * socket communication also works when it is used within one JVM.
	 * 
	 * Added by sven 21.03.2006, as before SocketProxy were stored in
	 * {@link #proxies} with help of their remote URL as key, so that they were
	 * a kind of singleton for that URL. But the key has to consist of the URL
	 * of the local peer, that uses the proxy, and the remote URL as
	 * SocketProxies must only be (kind of) a singleton per local and remote
	 * URL.
	 * 
	 * @param localURL
	 * @param remoteURL
	 * @return The key to store the SocketProxy
	 */
	private static String createProxyKey(URL localURL, URL remoteURL) {
		return localURL.toString() + "->" + remoteURL.toString();
	}

	/**
	 * Corresponding constructor to factory method {@link #create(URL, URL, ID)}.
	 * 
	 * @see #create(URL, URL, ID)
	 * @param url
	 * @param urlOfLocalNode1
	 * @param nodeID1
	 */
	protected SocketProxy(URL url, URL urlOfLocalNode1, ID nodeID1) {
		super(url);
		if (url == null || urlOfLocalNode1 == null || nodeID1 == null) {
			throw new IllegalArgumentException("null");
		}
		this.urlOfLocalNode = urlOfLocalNode1;
		this.nodeID = nodeID1;
	}

	/**
	 * Corresponding constructor to factory method {@link #create(URL, URL)}.
	 * 
	 * @see #create(URL, URL)
	 * @param url
	 * @param urlOfLocalNode1
	 * @throws CommunicationException
	 */
	private SocketProxy(URL url, URL urlOfLocalNode1)
			throws CommunicationException {
		super(url);
		if (url == null || urlOfLocalNode1 == null) {
			throw new IllegalArgumentException(
					"URLs must not be null!");
		}
		this.urlOfLocalNode = urlOfLocalNode1;
		this.initializeNodeID();
		logger.info("SocketProxy for " + url + " has been created.");
	}

	/**
	 * Private method to send requests over the socket. This method is
	 * synchronized to ensure that no other thread concurrently accesses the
	 * {@link ObjectOutputStream output stream}<code>out</code> while sending
	 * {@link Request request}.
	 * 
	 * @param request
	 *            The {@link Request}to be sent.
	 * @throws CommunicationException
	 *             while writing to {@link ObjectOutputStream output stream}.
	 */
	private synchronized void send(Request request)
			throws CommunicationException {
		try {
			logger.debug("Sending request " + request.getReplyWith());
			this.out.writeObject(request);
			this.out.flush();
			this.out.reset();
		} catch (IOException e) {
			throw new CommunicationException("Could not connect to node "
					+ this.nodeURL, e);
		}
	}

	/**
	 * Private method to create an identifier that enables this to associate a
	 * {@link Response response}with a {@link Request request}made before.
	 * This method is synchronized to protect {@link #requestCounter}from race
	 * conditions.
	 * 
	 * @param methodIdentifier
	 *            Integer identifying the method this method is called from.
	 * @return Unique Identifier for the request.
	 */
	private synchronized String createIdentifier(int methodIdentifier) {
		/* Create unique identifier from */
		StringBuilder uid = new StringBuilder();
		/* Time stamp */
		uid.append(System.currentTimeMillis());
		uid.append("-");
		/* counter and */
		uid.append(this.requestCounter++);
		/* methodIdentifier */
		uid.append("-");
		uid.append(methodIdentifier);
		return uid.toString();
	}

	/**
	 * Called in a method that is delegated to the {@link Node node}, that this
	 * is the proxy for. This method blocks the thread that calls the particular
	 * method until a {@link Response response} is received.
	 * 
	 * @param request
	 * @return The {@link Response} for <code>request</code>.
	 * @throws CommunicationException
	 */
	private Response waitForResponse(Request request)
			throws CommunicationException {

		String responseIdentifier = request.getReplyWith();
		Response response = null;
		logger.debug("Trying to wait for response with identifier "
				+ responseIdentifier + " for method "
				+ MethodConstants.getMethodName(request.getRequestType()));

		synchronized (this.responses) {
			logger.debug("No of responses " + this.responses.size());
			/* Test if we got disconnected while waiting for lock on object */
			if (this.disconnected) {
				throw new CommunicationException("Connection to remote host "
						+ " is broken down. ");
			}
			/*
			 * Test if response is already available (Maybe response arrived
			 * before we reached this point).
			 */
			response = this.responses.remove(responseIdentifier);
			if (response != null) {
				return response;
			}

			/* WAIT FOR RESPONSE */
			/* add current thread to map of threads waiting for a response */
			WaitingThread wt = new WaitingThread(Thread.currentThread());
			this.waitingThreads.put(responseIdentifier, wt);
			while (!wt.hasBeenWokenUp()) {
				try {
					/*
					 * Wait until notified or time out is reached.
					 */
					logger.debug("Waiting for response to arrive.");
					this.responses.wait();
				} catch (InterruptedException e) {
					/*
					 * does not matter as this is intended Thread is interrupted
					 * if response arrives
					 */
				}
			}
			logger.debug("Have been woken up from waiting for response.");

			/* remove thread from map of threads waiting for a response */
			this.waitingThreads.remove(responseIdentifier);
			/* try to get the response if available */
			response = this.responses.remove(responseIdentifier);
			logger.debug("Response for request with identifier "
					+ responseIdentifier + " for method "
					+ MethodConstants.getMethodName(request.getRequestType())
					+ " received.");
			/* if no response availabe */
			if (response == null) {
				logger.debug("No response received.");
				/* we have been disconnected */
				if (this.disconnected) {
					logger.info("Connection to remote host lost.");
					throw new CommunicationException(
							"Connection to remote host " + " is broken down. ");
				}
				/* or time out has elapsed */

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
在线观看www91| 国产成人精品午夜视频免费| 欧美在线观看18| 一区二区三区产品免费精品久久75| 成人综合在线观看| 国产精品萝li| 色天天综合色天天久久| 亚洲综合成人在线| 欧美一区二区在线不卡| 久久国产婷婷国产香蕉| 久久久久久久久久电影| 成人免费视频播放| 一区二区三区在线播放| 欧美高清dvd| 激情综合亚洲精品| 国产精品麻豆网站| 欧美日韩一区二区三区四区 | 午夜精品一区二区三区三上悠亚 | 欧美一区二区三区白人| 久久99精品国产麻豆婷婷| 精品伦理精品一区| 成人夜色视频网站在线观看| 亚洲综合免费观看高清在线观看| 337p亚洲精品色噜噜噜| 国产精品一区二区在线播放| 免费在线看成人av| 国产精品女主播av| 欧美精品久久一区二区三区| 国产精品一级在线| 一区二区高清免费观看影视大全| 日韩西西人体444www| 国产a级毛片一区| 亚洲图片欧美综合| 久久久久久久久久久99999| 在线观看亚洲成人| 床上的激情91.| 美女视频黄a大片欧美| 亚洲视频图片小说| 精品国产亚洲在线| 欧美综合色免费| 成人国产精品免费| 日本欧美一区二区三区乱码| 亚洲欧美一区二区视频| 日韩欧美你懂的| 91久久精品一区二区二区| 精品一区二区在线播放| 一区二区理论电影在线观看| 国产丝袜在线精品| 91精品国产91久久久久久最新毛片| www.综合网.com| 韩国毛片一区二区三区| 亚洲一区二区在线免费看| 国产日产欧美一区二区视频| 欧美精品第1页| 色婷婷av一区二区| 99久久婷婷国产综合精品电影| 黄色资源网久久资源365| 亚洲国产精品一区二区www| 中文字幕中文在线不卡住| 日韩精品在线网站| 欧美乱妇15p| 日本道色综合久久| 91网站在线观看视频| 国产精品99久久久久久久女警| 男男gaygay亚洲| 丝瓜av网站精品一区二区| 一区二区三区四区不卡在线| 国产精品亲子伦对白| 国产亚洲欧美色| 久久久久久免费网| 久久先锋影音av鲁色资源| 日韩午夜av电影| 91精品国产高清一区二区三区| 欧美三级日韩在线| 欧美在线观看一区| 欧洲精品视频在线观看| 在线视频一区二区免费| 在线免费亚洲电影| 欧美亚洲一区二区在线观看| 色94色欧美sute亚洲线路一久 | 日韩欧美国产一区二区在线播放| 欧洲精品一区二区| 欧美剧在线免费观看网站| 欧美日韩一区二区三区高清 | 丰满少妇久久久久久久| 国产精品一区三区| 欧美一区二区三区在线观看视频| 欧美性生交片4| 678五月天丁香亚洲综合网| 91精品国产品国语在线不卡| 日韩一级完整毛片| 久久综合九色综合97婷婷| 久久久精品一品道一区| 国产婷婷色一区二区三区四区 | 亚洲欧洲日韩av| 亚洲精品美国一| 亚洲国产日韩a在线播放性色| 亚洲国产精品一区二区www | 亚洲人成网站精品片在线观看| 中文一区二区完整视频在线观看| 国产精品国产三级国产专播品爱网 | 亚洲综合区在线| 免费一级欧美片在线观看| 精品一区二区三区影院在线午夜| 国产一区二区三区高清播放| 成人一区在线看| 91丨porny丨蝌蚪视频| 欧美日本一区二区在线观看| 欧美变态凌虐bdsm| 最好看的中文字幕久久| 五月天激情小说综合| 经典三级一区二区| 91免费视频观看| 91精品国产色综合久久ai换脸 | 成人一区在线观看| 成人欧美一区二区三区黑人麻豆| 亚洲午夜久久久久久久久久久| 毛片一区二区三区| 成人av网址在线观看| 制服丝袜在线91| 中文字幕+乱码+中文字幕一区| 午夜激情一区二区三区| 国产成人精品免费网站| 欧美精品久久久久久久多人混战| 久久久久久久综合| 亚洲一区二区三区影院| 韩国午夜理伦三级不卡影院| 色女孩综合影院| 久久久久久免费| 日韩av网站免费在线| www.色综合.com| 日韩写真欧美这视频| 亚洲精品美腿丝袜| 粉嫩在线一区二区三区视频| 欧美一区二区三区四区久久| 亚洲欧洲日韩一区二区三区| 狠狠狠色丁香婷婷综合久久五月| 91官网在线观看| 国产精品伦理在线| 久久电影网电视剧免费观看| 欧美性猛片xxxx免费看久爱| 欧美激情中文不卡| 麻豆国产精品777777在线| 日本韩国视频一区二区| 欧美激情中文字幕一区二区| 久久99久久精品| 91精品国产入口在线| 亚洲一区中文日韩| av在线综合网| 欧美国产综合一区二区| 毛片不卡一区二区| 欧美精品久久天天躁| 亚洲午夜免费视频| 91麻豆免费看片| 中文字幕一区二区三区视频| 国产伦精品一区二区三区视频青涩 | 免费看日韩a级影片| 欧美无乱码久久久免费午夜一区 | 久久综合中文字幕| 日韩av中文在线观看| 欧美精品xxxxbbbb| 首页亚洲欧美制服丝腿| 91国偷自产一区二区三区成为亚洲经典 | 欧美猛男男办公室激情| 亚洲天堂福利av| www.视频一区| 亚洲三级电影网站| 91丨porny丨国产| 亚洲伦理在线精品| 色婷婷精品大在线视频 | 久久综合网色—综合色88| 蜜桃久久久久久| 欧美成人一区二区| 精品在线一区二区三区| 欧美tk—视频vk| 国产酒店精品激情| 国产午夜亚洲精品不卡| 国产精品亚洲一区二区三区妖精| 久久先锋影音av鲁色资源| 国产精品996| 国产精品二三区| 97久久精品人人澡人人爽| 亚洲卡通动漫在线| 欧美日韩一级二级三级| 日韩av成人高清| 26uuu久久综合| 成人免费黄色大片| 亚洲免费电影在线| 欧美日韩一区在线观看| 青椒成人免费视频| www久久久久| 99麻豆久久久国产精品免费 | 日本一区二区三区在线观看| 成人精品免费视频| 一区二区三区日韩欧美精品| 337p亚洲精品色噜噜狠狠| 国产精品综合av一区二区国产馆| 国产精品动漫网站| 欧美另类变人与禽xxxxx| 国产精品综合一区二区三区|