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

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

?? endpoint.java

?? Chord package into p2psim
?? JAVA
字號:
/***************************************************************************
 *                                                                         *
 *                              Endpoint.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;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import de.uniba.wiai.lspi.chord.com.local.ThreadEndpoint;
import de.uniba.wiai.lspi.chord.com.rmi.RMIEndpoint;
import de.uniba.wiai.lspi.chord.com.socket.SocketEndpoint;
import de.uniba.wiai.lspi.chord.data.URL;
import de.uniba.wiai.lspi.util.logging.Logger;

/**
 * <p>
 * This class represents an endpoint, which wraps a {@link Node}, so that other
 * nodes can connect to the node using a protocol.
 * </p>
 * <p>
 * This class must be extended by endpoints that support a certain protocol as
 * e.g. <code>RMI</code> or a protocol over <code>Sockets</code>.
 * </p>
 * <p>
 * This is the abstract class that has to be implemented by all Endpoints. An
 * Endpoint enables other chord peers to connect to a {@link Node node} with
 * help of a given protocol. Each node in a chord network has to have exactly
 * one endpoint.
 * </p>
 * <p>
 * For each protocol that shall be supported a separate endpoint has to be
 * implemented. To initialise endpoints for a {@link Node} an {@link URL} has to
 * be provided to the {@link #createEndpoint(Node, URL)} endpoint factory
 * method. This methods tries to determine the endpoint with help of the
 * protocol names defined by the url. Supported protocols can be found in the
 * {@link URL} class.
 * </p>
 * An Endpoint can be in three states:
 * <ul>
 * <li><code>STARTED</code>,</li>
 * <li><code>LISTENING</code>, and</li>
 * <li><code>ACCEPT_ENTRIES</code>.</li>
 * </ul>
 * <p>
 * In state <code>STARTED</code> the endpoint has been initialised but does
 * not listen to (possibly) incoming messages from the chord network. An
 * endpoint gets into this state if it is created with help of its constructor.
 * <br/><br/> In state <code>LISTENING</code> the endpoint accepts messages
 * that are received from the chord network to update the finger table or
 * request the predecessor or successor of the node of this endpoint. The
 * transition to this state is made by invocation of {@link #listen()}.
 * 
 * 
 * <br/><br/>In state <code>ACCEPT_ENTRIES</code>. This endpoint accepts
 * messages from the chord network, that request storage or removal of entries
 * from the DHT. The transition to this state is made by invocation of
 * {@link #acceptEntries()}.
 * </p>
 * 
 * @author sven
 * @version 1.0.5
 */
public abstract class Endpoint {

	/**
	 * Logger for this class.
	 */
	private static final Logger logger = Logger.getLogger(Endpoint.class);

	/**
	 * Map containing all endpoints. Key: {@link URL}. Value:
	 * <code>Endpoint</code>.
	 */
	protected static final Map<URL, Endpoint> endpoints = new HashMap<URL, Endpoint>();

	// TODO: Create enum for state.
	/**
	 * Integer representation of state.
	 */
	public static final int STARTED = 0;

	/**
	 * Integer representation of state.
	 */
	public static final int LISTENING = 1;

	/**
	 * Integer representation of state.
	 */
	public static final int ACCEPT_ENTRIES = 2;

	/**
	 * Integer representation of state.
	 */
	public static final int DISCONNECTED = 3;

	/**
	 * Array containing names of methods only allowed to be invoked in state
	 * {@link #ACCEPT_ENTRIES}. Remember to eventually edit this array if you
	 * change the methods in interface {@link Node}. The method names contained
	 * in this array must be sorted!
	 */
	public static final List<String> METHODS_ALLOWED_IN_ACCEPT_ENTRIES;

	static {
		String[] temp = new String[] { "insertEntry", "removeEntry",
				"retrieveEntries" };
		Arrays.sort(temp);
		List<String> list = new ArrayList<String>(Arrays.asList(temp));
		METHODS_ALLOWED_IN_ACCEPT_ENTRIES = Collections.unmodifiableList(list);
	}

	/**
	 * The current state of this endpoint.
	 */
	private int state = -1;

	/**
	 * The {@link URL}that can be used to connect to this endpoint.
	 */
	protected URL url;

	/**
	 * The {@link Node node}on which this endpoint invokes methods.
	 */
	protected Node node;

	/**
	 * {@link EndpointStateListener listeners}interested in state changes of
	 * this endpoint.
	 */
	private Set<EndpointStateListener> listeners = new HashSet<EndpointStateListener>();

	/**
	 * 
	 * @param node1
	 *            The {@link Node} this is the Endpoint for.
	 * @param url1
	 *            The {@link URL} that describes the location of this endpoint.
	 */
	protected Endpoint(Node node1, URL url1) {
		logger.info("Endpoint for " + node1 + " with url " + url1 + "created.");
		this.node = node1;
		this.url = url1;
		this.state = STARTED;
	}

	/**
	 * @return Returns the node.
	 */
	public final Node getNode() {
		return this.node;
	}

	/**
	 * Register a listener that is notified when the state of this endpoint
	 * changes.
	 * 
	 * @param listener
	 *            The listener to register.
	 */
	public final void register(EndpointStateListener listener) {
		this.listeners.add(listener);
	}

	/**
	 * Remove a listener that listened for state changes of this endpoint.
	 * 
	 * @param listener
	 *            The listener instance to be removed.
	 */
	public final void deregister(EndpointStateListener listener) {
		this.listeners.remove(listener);
	}

	// TODO rename!!
	/**
	 * Method to notify listeners about a change in state of this endpoint.
	 * 
	 * @param s
	 *            The integer identifying the state to that the endpoint
	 *            switched. See {@link Endpoint#ACCEPT_ENTRIES},
	 *            {@link Endpoint#DISCONNECTED}, {@link Endpoint#LISTENING},
	 *            and {@link Endpoint#STARTED}.
	 */
	protected void notify(int s) {
		logger.debug("notifying state change.");
		synchronized (this.listeners) {
			logger.debug("Size of listeners = " + this.listeners.size());
			for (EndpointStateListener listener : this.listeners) {
				listener.notify(s);
			}
		}
	}

	/**
	 * Get the {@link URL}of this endpoint.
	 * 
	 * @return The {@link URL}that can be used to connect to this endpoint.
	 */
	public URL getURL() {
		return this.url;
	}

	/**
	 * @return Returns the state.
	 */
	public final int getState() {
		return this.state;
	}

	/**
	 * @param state1
	 *            The state to set.
	 */
	protected final void setState(int state1) {
		this.state = state1;
		this.notify(state1);
	}

	/**
	 * Tell this endpoint that it can listen to incoming messages from other
	 * chord nodes. TODO: This method may throw an exception when starting to
	 * listen for incoming connections.
	 */
	public final void listen() {
		this.state = LISTENING;
		this.notify(this.state);
		this.openConnections();
	}

	/**
	 * To implemented by sub classes. This method is called by {@link #listen()}to
	 * make it possible for other chord nodes to connect to the node on that
	 * this endpoint invocates methods.
	 * 
	 * TODO: This method may throw an exception when starting to listen for
	 * incoming connections.
	 */
	protected abstract void openConnections();

	/**
	 * Tell this endpoint that the node is now able to receive messages that
	 * request the storage and removal of entries.
	 * 
	 */
	public final void acceptEntries() {
		logger.info("acceptEntries() called.");
		this.state = ACCEPT_ENTRIES;
		this.notify(this.state);
		this.entriesAcceptable();
	}

	/**
	 * This method has to be overwritten by subclasses. It is called from
	 * {@link #acceptEntries()}to indicate that entries can now be accepted. So
	 * maybe if an endpoint queues incoming requests for storage or removal of
	 * entries this requests can be answered when endpoint changes it state to
	 * <code>ACCEPT_ENTRIES</code>.
	 */
	protected abstract void entriesAcceptable();

	/**
	 * Tell this endpoint to disconnect and close all connections. If this
	 * method has been invoked the endpoint must be not reused!!!
	 */
	public final void disconnect() {
		this.state = STARTED;
		logger.info("Disconnecting.");
		this.notify(this.state);
		this.closeConnections();
		synchronized (endpoints) {
			endpoints.remove(this.node.nodeURL);
		}
	}

	/**
	 * This method has to be overwritten by sub classes and is invoked by
	 * {@link #disconnect()}to close all connections from the chord network.
	 * 
	 */
	protected abstract void closeConnections();

	/**
	 * Create the endpoints for the protocol given by <code>url</code>. An
	 * URL must have a known protocol. An endpoint for an {@link URL} can only
	 * be create once and then be obtained with help of
	 * {@link Endpoint#getEndpoint(URL)}. An endpoint for an url must again be
	 * created if the {@link Endpoint#disconnect()} has been invoked.
	 * 
	 * @param node
	 *            The node to which this endpoint delegates incoming requests.
	 * @param url
	 *            The URL under which <code>node</code> will be reachable by
	 *            other nodes.
	 * @return The endpoint created for <code>node</code> for the protocol
	 *         specified in <code>url</code>.
	 * @throws RuntimeException
	 *             This can occur if any error that cannot be handled by this
	 *             method occurs during endpoint creation.
	 */
	public static Endpoint createEndpoint(Node node, URL url) {

		synchronized (endpoints) {
			if (endpoints.containsKey(url)) {
				throw new RuntimeException("Endpoint already created!");
			}
			Endpoint endpoint = null;

			// TODO irgendwann 黚er properties l鰏en
			if (url == null) {
				throw new IllegalArgumentException("Url must not be null! ");
			}
			if (url.getProtocol().equals(
					URL.KNOWN_PROTOCOLS.get(URL.SOCKET_PROTOCOL))) {

				endpoint = new SocketEndpoint(node, url);
			} else if (url.getProtocol().equals(
					URL.KNOWN_PROTOCOLS.get(URL.LOCAL_PROTOCOL))) {

				endpoint = new ThreadEndpoint(node, url);
			} else if (url.getProtocol().equals(
					URL.KNOWN_PROTOCOLS.get(URL.RMI_PROTOCOL))) {

				endpoint = new RMIEndpoint(node, url);
			} else {
				// does not happen ??
				throw new IllegalArgumentException("Url does not contain a "
						+ "supported protocol " + "(" + url.getProtocol()
						+ ")!");
			}

			endpoints.put(url, endpoint);

			return endpoint;
		}
	}

	/**
	 * Get the <code>Endpoint</code> for the given <code>url</code>.
	 * 
	 * @param url
	 * @return The endpoint for provided <code>url</code>.
	 */
	public static Endpoint getEndpoint(URL url) {
		synchronized (endpoints) {
			Endpoint ep = endpoints.get(url);
			logger.debug("Endpoint for URL " + url + ": " + ep);
			return ep;
		}
	}

	/**
	 * Overwritten from {@link java.lang.Object}.
	 * 
	 * @return String representation of this endpoint.
	 */
	public String toString() {
		StringBuilder buffer = new StringBuilder();
		buffer.append("[Endpoint for ");
		buffer.append(this.node);
		buffer.append(" with URL ");
		buffer.append(this.url);
		return buffer.toString();
	}

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品久久久久久户外露出 | 国内精品写真在线观看| 久久久综合视频| 欧美性色欧美a在线播放| 国产在线国偷精品免费看| 亚洲一区二区三区四区在线| 欧美国产精品专区| 日韩欧美一区二区视频| 欧美午夜不卡在线观看免费| 国产福利精品一区二区| 美日韩一区二区三区| 一区二区三区在线高清| 中文字幕一区二区三区视频| 26uuu精品一区二区三区四区在线 26uuu精品一区二区在线观看 | 欧美日韩免费不卡视频一区二区三区| 国产精品1区2区| 免费观看一级欧美片| 亚洲一二三级电影| 亚洲欧美色图小说| 国产精品国产三级国产普通话蜜臀| 日韩欧美一区二区在线视频| 欧美日本国产视频| 色综合网色综合| www.99精品| 成人激情小说乱人伦| 国产精品一级片| 国内偷窥港台综合视频在线播放| 日本伊人色综合网| 性欧美疯狂xxxxbbbb| 亚洲一区二区三区在线看| 亚洲欧美激情视频在线观看一区二区三区| 久久精品一区八戒影视| wwwwxxxxx欧美| 精品国产伦理网| 久久综合网色—综合色88| 欧美不卡一区二区三区四区| 日韩一区二区三区电影在线观看| 日韩亚洲欧美综合| 欧美大尺度电影在线| 精品日韩一区二区三区| 久久久午夜电影| 久久精品在线观看| 中文字幕永久在线不卡| 自拍偷拍亚洲综合| 亚洲欧美一区二区三区久本道91 | 国产情人综合久久777777| 精品免费视频一区二区| 久久精品夜夜夜夜久久| 国产喷白浆一区二区三区| 中文字幕欧美国产| 中文字幕一区二区三区在线观看| 亚洲欧洲一区二区在线播放| 亚洲精品乱码久久久久| 亚洲国产日韩在线一区模特| 天天色综合成人网| 精品亚洲成a人在线观看| 国产一区中文字幕| 波多野结衣中文字幕一区 | 国产精品12区| 99热精品国产| 欧美日韩国产小视频| 日韩精品一区二区三区视频播放| 欧美韩国一区二区| 一区二区三区四区不卡在线| 日韩主播视频在线| 精油按摩中文字幕久久| 丁香婷婷深情五月亚洲| 在线观看一区日韩| 精品国产一区二区三区久久久蜜月| 亚洲国产精品激情在线观看| 自拍偷拍亚洲综合| 七七婷婷婷婷精品国产| 国产精品一二三在| 欧美中文一区二区三区| 精品日韩在线一区| 亚洲欧美电影一区二区| 免费高清在线视频一区·| 成人午夜在线播放| 欧美日韩你懂得| 久久九九99视频| 午夜精品久久久久久| 国产成人在线网站| 欧美日韩国产高清一区二区| 国产亚洲综合色| 天天av天天翘天天综合网| 国产成人精品午夜视频免费| 欧美三级一区二区| 欧美激情综合网| 蜜臀久久久久久久| 91蜜桃婷婷狠狠久久综合9色| 日韩欧美一二三| 一区二区三区国产豹纹内裤在线| 精品一区二区三区免费视频| 91久久国产最好的精华液| 久久综合狠狠综合| 午夜视频一区在线观看| 成人av在线观| xf在线a精品一区二区视频网站| 亚洲高清视频中文字幕| 99热国产精品| 久久亚洲影视婷婷| 日韩中文字幕麻豆| 欧美私人免费视频| 国产精品毛片久久久久久| 久久精品国产色蜜蜜麻豆| 欧美人成免费网站| 亚洲欧美色图小说| 成人精品免费视频| 久久新电视剧免费观看| 首页国产欧美久久| 欧美性猛交xxxx黑人交| 中文字幕中文字幕在线一区 | 国产成人h网站| 欧美精品一区二区三区蜜桃视频 | 日本一不卡视频| 欧美日韩精品一区视频| 亚洲宅男天堂在线观看无病毒| 99久免费精品视频在线观看 | 亚洲男同性恋视频| kk眼镜猥琐国模调教系列一区二区| 欧美精品一区二区蜜臀亚洲| 无码av中文一区二区三区桃花岛| 在线看日本不卡| 亚洲主播在线播放| 欧美视频在线一区二区三区| 亚洲蜜臀av乱码久久精品| 91在线视频观看| 亚洲精品国产a| 91黄色激情网站| 亚洲综合偷拍欧美一区色| 91蝌蚪国产九色| 亚洲视频图片小说| 91色乱码一区二区三区| 亚洲欧美欧美一区二区三区| www.亚洲人| 18成人在线观看| 色婷婷亚洲婷婷| 亚洲女同ⅹxx女同tv| 色呦呦一区二区三区| 亚洲美女屁股眼交3| 欧美三级日韩在线| 视频一区二区不卡| 欧美电影免费观看完整版| 国内国产精品久久| 中文字幕精品在线不卡| 99视频精品免费视频| 一区二区三区四区在线| 欧美精品亚洲二区| 久久国产视频网| 中文字幕av一区二区三区免费看 | 精品国产成人系列| 国产精品一二三区| 亚洲免费观看高清| 在线不卡欧美精品一区二区三区| 免费观看久久久4p| 国产精品网站在线| 在线日韩国产精品| 免费看欧美美女黄的网站| 国产无遮挡一区二区三区毛片日本| youjizz久久| 三级影片在线观看欧美日韩一区二区| 日韩一区国产二区欧美三区| 国产一区二区在线观看免费| 亚洲国产精品av| 欧美日韩成人一区| 国产精品系列在线播放| 一区二区在线观看不卡| 9191国产精品| 国产精品资源站在线| 亚洲另类中文字| 日韩欧美精品在线视频| 成人小视频免费观看| 亚洲一区二区精品视频| 精品日韩一区二区三区| 91农村精品一区二区在线| 蜜臀91精品一区二区三区| 国产精品天干天干在观线| 欧美日韩精品专区| 国产99精品视频| 视频在线观看国产精品| 中文字幕高清不卡| 91精品国产一区二区三区蜜臀| 国产传媒久久文化传媒| 亚洲综合小说图片| 国产色产综合色产在线视频| 欧美精品久久99久久在免费线| 国产成人免费视频精品含羞草妖精| 亚洲高清三级视频| 国产精品久久久久久久久搜平片| 欧美日韩视频一区二区| 成人av在线看| 国产美女av一区二区三区| 亚洲亚洲人成综合网络| 国产精品伦理在线| 亚洲精品在线三区| 91精品欧美一区二区三区综合在| 99免费精品视频| 国产99久久久国产精品潘金 | 亚洲欧美视频一区| 国产人成一区二区三区影院|