⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 checkpredecessortask.java

📁 一个对等计算发生器
💻 JAVA
字号:
/***************************************************************************
 *                                                                         *
 *                          CheckPredecessorTask.java                      *
 *                            -------------------                          *
 *   date                 : 16.08.2004                                     *
 *   copyright            : (C) 2004/2005 Distributed and                  *
 *								Mobile Systems Group                       *
 *                              Lehrstuhl fuer Praktische Informatik       *
 *                              Universitaet Bamberg                       *
 *                              http://www.lspi.wiai.uni-bamberg.de/       *
 *   email                : sven.kaffille@wiai.uni-bamberg.de              *
 *   						karsten.loesing@wiai.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 de.uniba.wiai.lspi.chord.com.CommunicationException;
import de.uniba.wiai.lspi.chord.com.Node;
import de.uniba.wiai.lspi.util.logging.Logger;

/**
 * Checks if the predecessor of the local node is still alive.
 * 
 * @author Karsten Loesing
 * @version 1.0.1
 */
final class CheckPredecessorTask implements Runnable {

	/**
	 * Object logger.
	 */
	private Logger logger = Logger.getLogger(CheckPredecessorTask.class);

	/**
	 * Reference on routing table.
	 */
	private References references;

	/**
	 * Creates a new instance, but without starting a thread running it.
	 * 
	 * @param references
	 *            Reference on routing table.
	 * @throws NullPointerException
	 *             If parameter value is <code>null</code>.
	 */
	CheckPredecessorTask(References references) {

		if (references == null) {
			throw new NullPointerException(
					"Parameter references may not be null!");
		}

		this.logger = Logger.getLogger(CheckPredecessorTask.class);
		this.logger.debug("Logger initialized.");

		this.references = references;
	}

	public void run() {

		try {

			// start of method
			this.logger.info("Check predecessor method has been invoked.");

			// check if local node has a valid predecessor reference
			Node predecessor = this.references.getPredecessor();
			if (predecessor == null) {
				// I have no predecessor
				this.logger.info("Nothing to check, as predecessor is null");
				return;
			} else {

				// try to reach predecessor
				try {
					predecessor.ping();
					// My predecessor responded
					this.logger.info("Predecessor reached!");
				} catch (CommunicationException e) {
					this.logger.warn(
							"Checking predecessor was NOT successful due "
									+ "to a communication failure! Removing "
									+ "predecessor reference.", e);

					// My predecessor did not respond
					this.references.removeReference(predecessor);
					return;
				}

				this.logger.info("Invocation of check predecessor on node "
						+ predecessor.nodeID + " was successful");
			}
		} catch (Exception e) {
			this.logger.error(
					"Exception caught in StabilizeTask! From now on, "
							+ "periodic maintenance tasks are not executed "
							+ "any more!", e);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -