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

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

?? nodeimpl.java

?? Chord package into p2psim
?? JAVA
字號:
/***************************************************************************
 *                                                                         *
 *                               NodeImpl.java                             *
 *                            -------------------                          *
 *   date                 : 16.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.service.impl;

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

import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

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.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;

/**
 * Implements all operations which can be invoked remotely by other nodes.
 * 
 * @author Karsten Loesing
 * @version 1.0.5
 */
public final class NodeImpl extends Node {

	/**
	 * Endpoint for incoming communication.
	 */
	private Endpoint myEndpoint = null;

	/**
	 * Reference on local node.
	 */
	private ChordImpl impl;

	/**
	 * Object logger.
	 * The name of the logger is the name of this class with the nodeID appended. 
	 * The length of the nodeID depends on the number of bytes that are displayed 
	 * when the ID is shown in Hex-Representation. See documentation of {@link ID}. 
	 * E.g. de.uniba.wiai.lspi.chord.service.impl.NodeImpl.FF FF FF FF if the number 
	 * of displayed Bytes of an ID is 4. 
	 */
	private Logger logger;

	/**
	 * Routing table (including finger table, successor list, and predecessor
	 * reference)
	 */
	private References references;

	/**
	 * Repository for locally stored entries.
	 */
	private Entries entries;

	/**
	 * Executor that executes insertion and removal of entries on successors of
	 * this node.
	 */
	private Executor asyncExecutor;
	
	private Lock notifyLock; 

	/**
	 * Creates that part of the local node which answers remote requests by
	 * other nodes. Sole constructor, is invoked by ChordImpl only.
	 * 
	 * @param impl
	 *            Reference on ChordImpl instance which created this object.
	 * @param nodeID
	 *            This node's Chord ID.
	 * @param nodeURL
	 *            URL, on which this node accepts connections.
	 * @param references
	 *            Routing table of this node.
	 * @param entries
	 *            Repository for entries of this node.
	 * @throws IllegalArgumentException
	 *             If any of the parameter has value <code>null</code>.
	 */
	NodeImpl(ChordImpl impl, ID nodeID, URL nodeURL, References references,
			Entries entries) {

		if (impl == null || nodeID == null || nodeURL == null
				|| references == null || entries == null) {
			throw new IllegalArgumentException(
					"Parameters of the constructor may not have a null value!");
		}

		this.logger = Logger.getLogger(NodeImpl.class.getName() + "." + nodeID.toString());

		this.impl = impl;
		this.asyncExecutor = impl.getAsyncExecutor();
		this.nodeID = nodeID;
		this.nodeURL = nodeURL;
		this.references = references;
		this.entries = entries;
		this.notifyLock = new ReentrantLock(true); 
		
		// create endpoint for incoming connections
		this.myEndpoint = Endpoint.createEndpoint(this, nodeURL);
		this.myEndpoint.listen();
	}

	/**
	 * Makes this endpoint accept entries by other nodes. Is invoked by
	 * ChordImpl only.
	 */
	final void acceptEntries() {
		this.myEndpoint.acceptEntries();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public final void disconnect() {
		this.myEndpoint.disconnect();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public final Node findSuccessor(ID key) {
		return this.impl.findSuccessor(key);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public final List<Node> notify(Node potentialPredecessor) {
		/*
		 * Mutual exclusion between notify and notifyAndCopyEntries. 17.03.2008. sven.
		 */
		this.notifyLock.lock(); 
		try {
			// the result will contain the list of successors as well as the
			// predecessor of this node
			List<Node> result = new LinkedList<Node>();

			// add reference on predecessor as well as on successors to result
			if (this.references.getPredecessor() != null) {
				result.add(this.references.getPredecessor());
			} else {
				result.add(potentialPredecessor); 
			}
			result.addAll(this.references.getSuccessors());

//			 add potential predecessor to successor list and finger table and
			// set
			// it as predecessor if no better predecessor is available
			this.references.addReferenceAsPredecessor(potentialPredecessor);			
			return result;
		} finally {
			this.notifyLock.unlock(); 
		}
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public final RefsAndEntries notifyAndCopyEntries(Node potentialPredecessor)
			throws CommunicationException {
		/*
		 * Mutual exclusion between notify and notifyAndCopyEntries. 17.03.2008. sven.
		 */
		this.notifyLock.lock(); 
		try {
			// copy all entries which lie between the local node ID and the ID
			// of
			// the potential predecessor, including those equal to potential
			// predecessor
			Set<Entry> copiedEntries = this.entries.getEntriesInInterval(
					this.nodeID, potentialPredecessor.getNodeID());

			return new RefsAndEntries(this.notify(potentialPredecessor),
					copiedEntries);
		} finally {
			this.notifyLock.unlock(); 
		}
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public final void ping() {
		// do nothing---returning of method is proof of live
		return;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public final void insertEntry(Entry toInsert) throws CommunicationException {
		if (this.logger.isEnabledFor(DEBUG)) {
			this.logger.debug("Inserting entry with id " + toInsert.getId()
					+ " at node " + this.nodeID);
		}

		// Possible, but rare situation: a new node has joined which now is
		// responsible for the id!
		if ((this.references.getPredecessor() == null)
				|| !toInsert.getId().isInInterval(
						this.references.getPredecessor().getNodeID(),
						this.nodeID)) {
			this.references.getPredecessor().insertEntry(toInsert); 
			return;
		}

		// add entry to local repository
		this.entries.add(toInsert);

		// create set containing this entry for insertion of replicates at all
		// nodes in successor list
		Set<Entry> newEntries = new HashSet<Entry>();
		newEntries.add(toInsert);

		// invoke insertReplicates method on all nodes in successor list
		final Set<Entry> mustBeFinal = new HashSet<Entry>(newEntries);
		for (final Node successor : this.references.getSuccessors()) {
			this.asyncExecutor.execute(new Runnable() {
				public void run() {
					try {
						successor.insertReplicas(mustBeFinal);
					} catch (CommunicationException e) {
						// do nothing
					}
				}
			});
		}
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public final void insertReplicas(Set<Entry> replicatesToInsert) {
		this.entries.addAll(replicatesToInsert);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public final void removeEntry(Entry entryToRemove)
			throws CommunicationException {

		if (this.logger.isEnabledFor(DEBUG)) {
			this.logger.debug("Removing entry with id " + entryToRemove.getId()
					+ " at node " + this.nodeID);
		}

		// Possible, but rare situation: a new node has joined which now is
		// responsible for the id!
		if (this.references.getPredecessor() != null
				&& !entryToRemove.getId().isInInterval(
						this.references.getPredecessor().getNodeID(),
						this.nodeID)) {
			this.references.getPredecessor().removeEntry(entryToRemove);
			return;
		}

		// remove entry from repository
		this.entries.remove(entryToRemove);

		// create set containing this entry for removal of replicates at all
		// nodes in successor list
		final Set<Entry> entriesToRemove = new HashSet<Entry>();
		entriesToRemove.add(entryToRemove);

		// invoke removeReplicates method on all nodes in successor list
		List<Node> successors = this.references.getSuccessors();
		final ID id = this.nodeID;
		for (final Node successor : successors) {
			this.asyncExecutor.execute(new Runnable() {
				public void run() {
					try {
						// remove only replica of removed entry
						successor.removeReplicas(id, entriesToRemove);
					} catch (CommunicationException e) {
						// do nothing for the moment
					}
				}
			});
		}
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public final void removeReplicas(ID sendingNodeID,
			Set<Entry> replicasToRemove) {
		if (replicasToRemove.size() == 0) {
			// remove all replicas in interval
			boolean debug = this.logger.isEnabledFor(DEBUG);
			if (debug) {
				this.logger.debug("Removing replicas. Current no. of entries: "
						+ this.entries.getNumberOfStoredEntries());
			}
			/*
			 * Determine entries to remove. These entries are located between
			 * the id of the local peer and the argument sendingNodeID
			 */
			Set<Entry> allReplicasToRemove = this.entries.getEntriesInInterval(
					this.nodeID, sendingNodeID);
			if (debug) {
				this.logger.debug("Replicas to remove " + allReplicasToRemove);
				this.logger.debug("Size of replicas to remove "
						+ allReplicasToRemove.size());
			}

			/*
			 * Remove entries
			 */
			this.entries.removeAll(allReplicasToRemove);

			if (debug) {
				this.logger
						.debug("Removed replicas??? Current no. of entries: "
								+ this.entries.getNumberOfStoredEntries());
			}
		} else {
			// remove only replicas of given entry
			this.entries.removeAll(replicasToRemove);
		}
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public final Set<Entry> retrieveEntries(ID id)
			throws CommunicationException {

		// Possible, but rare situation: a new node has joined which now is
		// responsible for the id!
		if (this.references.getPredecessor() != null
				&& !id.isInInterval(this.references.getPredecessor()
						.getNodeID(), this.nodeID)) {
			this.logger.fatal("The rare situation has occured at time "
					+ System.currentTimeMillis() + ", id to look up=" + id
					+ ", id of local node=" + this.nodeID
					+ ", id of predecessor="
					+ this.references.getPredecessor().getNodeID());
			return this.references.getPredecessor().retrieveEntries(id);
		}

		// return entries from local repository
		// for this purpose create a copy of the Set in order to allow the
		// thread retrieving the entries to modify the Set without modifying the
		// internal Set of entries. sven
		return this.entries.getEntries(id);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	final public void leavesNetwork(Node predecessor) {
		if (this.logger.isEnabledFor(INFO)) {
			this.logger.info("Leaves network invoked; " + this.nodeID
					+ ". Updating references.");
			this.logger.info("New predecessor " + predecessor.getNodeID());
		}
		if (this.logger.isEnabledFor(DEBUG)) {
			this.logger.debug("References before update: "
					+ this.references.toString());
		}
		this.references.removeReference(this.references.getPredecessor());
		if (this.logger.isEnabledFor(DEBUG)) {
			this.logger.debug("References after update: "
					+ this.references.toString());
		}
	}

	/**
	 * 
	 * @return
	 */
	final Executor getAsyncExecutor() {
		return this.asyncExecutor;
	}

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲午夜激情av| 在线看国产一区| 国产一区美女在线| 国内精品久久久久影院薰衣草| 婷婷国产在线综合| 午夜精品久久久| 视频一区免费在线观看| 免费观看一级欧美片| 久久爱www久久做| 国产福利一区二区| 不卡的av中国片| 日本精品视频一区二区| 欧美日韩第一区日日骚| 91精品黄色片免费大全| 欧美成人一区二区三区在线观看| 精品盗摄一区二区三区| 久久精品无码一区二区三区| 中文字幕在线视频一区| 亚洲精品日韩一| 丝袜美腿一区二区三区| 久久99精品久久久| 国产成人精品免费一区二区| 99国产精品国产精品毛片| 欧美亚洲综合久久| 欧美电影在线免费观看| 精品奇米国产一区二区三区| 欧美经典三级视频一区二区三区| 国产精品久久久久久久久晋中| 亚洲精品videosex极品| 日韩av中文字幕一区二区| 国产精品996| 在线观看视频一区| 日韩欧美国产一二三区| 中日韩av电影| 亚洲chinese男男1069| 精品影院一区二区久久久| 成人动漫一区二区三区| 欧美视频中文一区二区三区在线观看| 日韩一级大片在线| 国产精品久久久久久久久快鸭| 亚洲电影在线播放| 国产一区二区三区电影在线观看| 色域天天综合网| 精品国产髙清在线看国产毛片 | 免费观看久久久4p| 成人自拍视频在线| 欧美色视频在线观看| 久久蜜桃香蕉精品一区二区三区| 亚洲精品日日夜夜| 国产精品66部| 欧美精品三级日韩久久| 国产精品午夜春色av| 天堂久久久久va久久久久| 成人午夜在线视频| 日韩欧美久久久| 亚洲黄色小视频| 国产乱国产乱300精品| 欧美在线观看禁18| 久久先锋影音av鲁色资源| 一个色妞综合视频在线观看| 久久精品国产99国产| 在线亚洲高清视频| 国产欧美日本一区视频| 日韩av午夜在线观看| 91亚洲午夜精品久久久久久| 欧美精品一区二区三区高清aⅴ| 一区二区三区日韩精品| 成人永久看片免费视频天堂| 欧美一区二区三区在线电影| 亚洲精品国产成人久久av盗摄| 韩国成人福利片在线播放| 欧美美女黄视频| 亚洲人成网站影音先锋播放| 国产成人亚洲综合a∨婷婷 | 日韩成人一区二区| 色综合中文字幕| 国产日韩精品一区二区浪潮av| 日韩av高清在线观看| 91久久一区二区| 亚洲色图都市小说| 国产**成人网毛片九色| 2020日本不卡一区二区视频| 美腿丝袜亚洲一区| 欧美日韩国产高清一区二区三区| 亚洲男同性恋视频| 99视频精品在线| 亚洲国产成人私人影院tom| 国产在线视视频有精品| 精品国产一区二区亚洲人成毛片| 日韩精品一二区| 欧美高清视频www夜色资源网| 亚洲国产精品尤物yw在线观看| 欧美自拍偷拍一区| 亚洲午夜一二三区视频| 欧美怡红院视频| 夜夜爽夜夜爽精品视频| 色久优优欧美色久优优| 亚洲人成影院在线观看| 93久久精品日日躁夜夜躁欧美| 国产精品视频九色porn| 成人午夜激情在线| 中文字幕亚洲一区二区va在线| 成人深夜在线观看| 亚洲丝袜自拍清纯另类| 色综合天天天天做夜夜夜夜做| 国产精品福利av| 色综合天天综合网国产成人综合天 | 国产亚洲一区二区三区在线观看 | 欧美主播一区二区三区| 亚洲国产综合色| 制服丝袜在线91| 美国十次了思思久久精品导航| 欧美一区二区三区人| 国产在线精品一区二区三区不卡 | 国产精品情趣视频| jlzzjlzz欧美大全| 亚洲一区二区影院| 欧美女孩性生活视频| 免费观看一级欧美片| www国产成人免费观看视频 深夜成人网| 国产一区中文字幕| 中文字幕一区二区三区在线不卡| 色综合久久久久久久久久久| 亚洲国产精品久久一线不卡| 欧美喷水一区二区| 韩国精品在线观看| 国产精品视频免费| 欧美日韩午夜在线| 国产自产v一区二区三区c| 欧美韩国日本不卡| 欧美少妇xxx| 国产一区二区三区不卡在线观看 | 欧美极品少妇xxxxⅹ高跟鞋 | 国产色一区二区| 99久久精品久久久久久清纯| 一区二区三区美女| 日韩美女天天操| av资源网一区| 石原莉奈在线亚洲二区| 精品国产免费视频| 一本大道av伊人久久综合| 美国十次综合导航| 亚洲三级电影网站| 日韩三级视频在线观看| 91在线播放网址| 日本不卡一区二区三区高清视频| 国产清纯白嫩初高生在线观看91 | 国产精品三级视频| 欧美日韩国产另类一区| 东方欧美亚洲色图在线| 亚洲第一搞黄网站| 亚洲国产精品成人综合色在线婷婷 | 国内精品不卡在线| 尤物在线观看一区| 精品国产网站在线观看| 91行情网站电视在线观看高清版| 免费国产亚洲视频| 一区二区久久久久| 国产无遮挡一区二区三区毛片日本| 91理论电影在线观看| 韩国v欧美v日本v亚洲v| 亚洲国产成人va在线观看天堂 | 国产成人在线网站| 婷婷国产v国产偷v亚洲高清| 亚洲国产激情av| 欧美成人午夜电影| 欧美性三三影院| av资源网一区| 国产成人综合亚洲网站| 秋霞电影网一区二区| 亚洲综合一区二区精品导航| 欧美经典一区二区| 日韩欧美的一区| 欧美日韩一区在线| 99re6这里只有精品视频在线观看| 美腿丝袜亚洲色图| 欧美xxxx老人做受| 极品少妇xxxx精品少妇偷拍| 午夜精品在线视频一区| 国产精品久久福利| 久久久综合精品| 欧美一区二区三区免费大片| 欧美中文字幕亚洲一区二区va在线| 成人精品一区二区三区中文字幕| 美美哒免费高清在线观看视频一区二区 | 久久99精品久久久久婷婷| 亚洲国产va精品久久久不卡综合 | 91视频国产观看| 国产成人精品在线看| 精品综合免费视频观看| 午夜视黄欧洲亚洲| 国产99精品视频| 国产成人午夜高潮毛片| 国产一区二区三区日韩| 麻豆精品一区二区三区| 三级欧美在线一区| 亚洲1区2区3区视频| 亚洲第一成年网| 午夜伊人狠狠久久| 视频一区欧美精品|