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

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

?? distributionalgorithm.java

?? 簡單的分布式算法
?? JAVA
字號:
/***************************************************************************** * $Id: DistributionAlgorithm.java,v 1.2 2003/05/06 15:32:47 jheiss Exp $ ***************************************************************************** * Base class for distribution algorithms:  algorithms for distributing * connections to the backend servers. ***************************************************************************** * Copyright 2003 Jason Heiss *  * This file is part of Distributor. *  * Distributor 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. *  * Distributor is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. *  * You should have received a copy of the GNU General Public License * along with Distributor; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA ***************************************************************************** */package oss.distributor;import java.util.List;import java.util.LinkedList;import java.util.Map;import java.util.Map.Entry;import java.util.HashMap;import java.util.Set;import java.util.Iterator;import java.util.logging.Logger;import java.io.IOException;import java.nio.ByteBuffer;import java.nio.channels.Selector;import java.nio.channels.SelectionKey;import java.nio.channels.SocketChannel;import java.net.InetSocketAddress;public abstract class DistributionAlgorithm{	Distributor distributor;	Logger logger;	int connectionTimeout;	TargetSelector targetSelector;	Selector selector;	Map connections;  // Map client SocketChannel -> Connection	Map connectStartTime;  // Map client SocketChannel -> Long	List failedConnections;	public DistributionAlgorithm(Distributor distributor)	{		this.distributor = distributor;		// We can safely do this now instead of waiting for		// finishInitialization() because we know it's one of the first		// things Distributor does.  Some of our child constructors may		// want to log things so we don't want to wait.		logger = distributor.getLogger();		//logger = Logger.getLogger(getClass().getName());		connections = new HashMap();		connectStartTime = new HashMap();		failedConnections = new LinkedList();		try		{			selector = Selector.open();		}		catch (IOException e)		{			logger.severe("Error creating selector: " + e.getMessage());			System.exit(1);		}	}	public abstract void startThread();	public void finishInitialization()	{		connectionTimeout = distributor.getConnectionTimeout();		targetSelector = distributor.getTargetSelector();	}	/*	 * TargetSelector uses this method to give us a client.	 */	public abstract void tryToConnect(SocketChannel client);	/*	 * Once an algorithm has picked a possible Target for a client, it	 * uses this method to initiate a connection to that target.	 */	public void initiateConnection(SocketChannel client, Target target)	{		try		{			SocketChannel server = SocketChannel.open();			server.configureBlocking(false);			// Initiate connection			server.connect(				new InetSocketAddress(					target.getInetAddress(),					target.getPort()));			synchronized(connections)			{				connections.put(					client,					new Connection(client, server, target));			}			// Record the time that the connection was initiated for later			// use in determining if it has timed out.			synchronized(connectStartTime)			{				connectStartTime.put(					client,					new Long(System.currentTimeMillis()));			}			// Register with selector			// This action is sychronized because if the selector is			// blocked in a select, the register call will hang until			// that ceases to be the case.  We wakeup the selector			// before calling register so it won't block us, but without			// the synchronization there is no guarantee that the			// selector won't get back to the next select call before we			// get a chance to register.  So after select is woken up,			// it synchronizes on 'this' in order to give us a chance to			// complete the register call.			synchronized(this)			{				// Wakeup the select so that it doesn't block us from				// registering the channels				selector.wakeup();				// Use the client as the attachment since all of our				// HashMaps use the client as the key and we'll need that				// later to lookup this connection.				server.register(selector, SelectionKey.OP_CONNECT, client);			}		}		catch (IOException e)		{			logger.warning(				"Error initiating connection to target: " +				e.getMessage());			synchronized(failedConnections)			{				failedConnections.add(client);			}		}	}	/*	 * Deal with any connections which have completed, and return a list	 * of those that have.	 */	public List checkForCompletedConnections()	{		int r;		Set readyKeys;		Iterator keyIter;		SelectionKey key;		SocketChannel client;		SocketChannel server;		List completed = new LinkedList();		// Select for a limited amount of time so that users of this		// method also get a chance to detect failed and timed out		// connections.  (The run methods in individual various children		// of this class generally loop calling this method followed by		// the checkForFailedConnections() method.)		r = 0;		try		{			r = selector.select(connectionTimeout/2);		}		catch (IOException e)		{			// What's it mean to get an I/O exception from select?			// Is it bad enough that we should return or exit?			logger.warning(				"Error when selecting for ready channel: " +				e.getMessage());		}		// If someone is in the process of adding a new channel to our		// selector, wait for them to finish.  See the comments in		// initiateConnection for a more complete explanation.		synchronized (this)		{			// Do we need anything in here to keep the compiler from			// optimizing this block away?			//logger.finest("checkForCompletedConnections has monitor");		}		if (r > 0)		{			logger.finest(				"select reports " + r + " channels ready to connect");			// Work through the list of channels that are ready			readyKeys = selector.selectedKeys();			keyIter = readyKeys.iterator();			while (keyIter.hasNext())			{				key = (SelectionKey) keyIter.next();				keyIter.remove();				server = (SocketChannel) key.channel();				client = (SocketChannel) key.attachment();				try				{					server.finishConnect();					logger.fine(						"Connection from " + client +						" to " + server + " complete");					synchronized(connections)					{						completed.add(connections.get(client));						connections.remove(client);					}					synchronized(connectStartTime)					{						connectStartTime.remove(client);					}					key.cancel();				}				catch (IOException e)				{					logger.warning("Error finishing connection");					key.cancel();					try					{						server.close();					}					catch (IOException ioe)					{						logger.warning(							"Error closing channel: " + ioe.getMessage());					}					synchronized(connections)					{						connections.remove(client);					}					synchronized(connectStartTime)					{						connectStartTime.remove(client);					}					synchronized(failedConnections)					{						failedConnections.add(client);					}				}			}		}		return completed;	}	/*	 * Return a list of connections which have timed out or otherwise	 * failed.	 */	public List checkForFailedConnections()	{		// Add connections which have timed out to the list of		// connections that have failed for other reasons.		Iterator iter = connectStartTime.entrySet().iterator();		while(iter.hasNext())		{			Entry timeEntry = (Entry) iter.next();			SocketChannel client = (SocketChannel) timeEntry.getKey();			long startTime = ((Long) timeEntry.getValue()).longValue();			if (startTime + connectionTimeout < System.currentTimeMillis())			{				synchronized(connections)				{					connections.remove(client);				}				synchronized(connectStartTime)				{					connectStartTime.remove(client);				}				synchronized(failedConnections)				{					failedConnections.add(client);				}			}		}		// To be consistent with checkForCompletedConnections(), return		// a list that the caller doesn't have to worry about		// synchronizing or emptying when done.		List returnList = failedConnections;		failedConnections = new LinkedList();		return returnList;	}	/*	 * Provide a default no-op implementation for this method since	 * most algorithms don't care	 */	public void connectionNotify(Connection conn)	{		// no-op	}	/*	 * Provide default no-op implementations for these methods since	 * most algorithms won't need to do anything with the data	 */	public ByteBuffer reviewClientToServerData(		SocketChannel client, SocketChannel server, ByteBuffer buffer)	{		return buffer;	}	public ByteBuffer reviewServerToClientData(		SocketChannel server, SocketChannel client, ByteBuffer buffer)	{		return buffer;	}	public String toString()	{		return(			getClass().getName() +			" with " + connections.size() + " pending connections");	}}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
色欲综合视频天天天| 一区二区三区四区在线免费观看 | 久久久亚洲欧洲日产国码αv| 国产精品久久久久久亚洲伦| 美女一区二区久久| 91猫先生在线| 国产欧美日韩不卡| 久久福利资源站| 91精品国产综合久久香蕉麻豆| 国产精品人人做人人爽人人添| 激情亚洲综合在线| 91麻豆精品国产91久久久久久久久 | 91在线观看污| 久久嫩草精品久久久精品| 日韩成人伦理电影在线观看| 色综合久久中文字幕| 亚洲国产高清不卡| 国产精华液一区二区三区| 日韩欧美电影在线| 三级影片在线观看欧美日韩一区二区 | 亚洲美女在线一区| av一二三不卡影片| 亚洲欧洲精品成人久久奇米网 | 久久国产综合精品| 欧美一区二区三区性视频| 亚洲大片免费看| 欧美性色黄大片手机版| 亚洲综合成人网| 欧洲精品在线观看| 亚洲午夜在线观看视频在线| 一本久道中文字幕精品亚洲嫩| ...xxx性欧美| 色悠悠久久综合| 亚洲永久免费视频| 欧美色男人天堂| 日韩国产高清在线| 一本大道av一区二区在线播放| 日韩制服丝袜av| 国产一区二区三区不卡在线观看 | 亚洲午夜日本在线观看| 色综合久久久久久久久久久| 亚洲免费观看在线观看| 色综合久久久久综合体桃花网| 亚洲欧美激情小说另类| 欧美视频自拍偷拍| 青青草91视频| 国产亚洲自拍一区| 99天天综合性| 亚洲二区视频在线| 欧美精品一区二区在线观看| 成人美女视频在线观看18| 亚洲乱码国产乱码精品精可以看 | 国产精品天干天干在线综合| eeuss国产一区二区三区| 夜色激情一区二区| 日韩一区二区视频| 成人性色生活片| 国产欧美一区二区三区网站| 成人美女在线视频| 午夜影院久久久| 精品国产乱码久久久久久蜜臀| 成人综合在线观看| 夜夜亚洲天天久久| 精品人在线二区三区| 成人国产亚洲欧美成人综合网| 亚洲成人精品一区二区| 欧美成人a视频| 色综合久久天天综合网| 青青青伊人色综合久久| 国产精品久久毛片| 91精品国产一区二区三区| 国产suv一区二区三区88区| 亚洲国产精品视频| 国产精品久久久久久亚洲毛片| 欧美日产国产精品| 成人av电影免费观看| 日本午夜一本久久久综合| 中文字幕在线观看一区| 91精品国产综合久久久久| a在线欧美一区| 久久不见久久见免费视频7| 一区二区三区中文字幕精品精品| 精品国产青草久久久久福利| 91久久精品日日躁夜夜躁欧美| 国产麻豆精品在线| 日本人妖一区二区| 悠悠色在线精品| 国产精品久久久久影院老司| 欧美videofree性高清杂交| 欧美性大战久久久| caoporn国产一区二区| 国产乱子伦一区二区三区国色天香| 亚洲一级二级三级| 亚洲精品中文在线影院| 中文成人综合网| 日本一区二区免费在线观看视频| 日韩精品中文字幕在线一区| 91精品久久久久久久91蜜桃| 欧美性大战久久久久久久蜜臀| 99精品1区2区| 色综合天天做天天爱| 成人av午夜影院| 丁香天五香天堂综合| 国产一区二区不卡老阿姨| 久久精品国产一区二区三区免费看| 午夜久久久久久久久久一区二区| 亚洲欧美视频在线观看| 亚洲人午夜精品天堂一二香蕉| 国产亚洲一本大道中文在线| 亚洲精品在线电影| 久久伊人中文字幕| 国产午夜精品一区二区三区四区| 欧美精品一区二区三区很污很色的| 欧美一区国产二区| 欧美一级日韩一级| 精品少妇一区二区| 久久久亚洲国产美女国产盗摄| 久久蜜桃av一区二区天堂| 亚洲国产成人午夜在线一区| 国产精品欧美精品| 亚洲欧美日韩国产成人精品影院 | 欧美精品在欧美一区二区少妇| 92精品国产成人观看免费| 色哟哟国产精品| 在线精品视频一区二区| 欧美精品123区| 日韩欧美不卡在线观看视频| 久久久国产精品午夜一区ai换脸| 国产精品美日韩| 亚洲精品久久7777| 首页国产丝袜综合| 九九**精品视频免费播放| 国产美女久久久久| 91丝袜美女网| 777午夜精品视频在线播放| 欧美va在线播放| 日韩一区有码在线| 亚洲一级二级三级| 精品亚洲aⅴ乱码一区二区三区| 国产成人精品亚洲日本在线桃色 | 亚洲欧美一区二区在线观看| 亚洲综合在线电影| 精品一区二区免费| 91免费在线播放| 欧美一级日韩不卡播放免费| 国产精品水嫩水嫩| 亚洲v日本v欧美v久久精品| 韩国精品久久久| 99精品久久只有精品| 91精品欧美久久久久久动漫| 国产欧美日本一区二区三区| 午夜久久电影网| 成人激情电影免费在线观看| 69p69国产精品| 亚洲欧美中日韩| 久久99热这里只有精品| 91香蕉视频mp4| 精品1区2区在线观看| 亚洲va国产va欧美va观看| 粉嫩aⅴ一区二区三区四区| 欧美日韩国产在线观看| 中文字幕国产一区| 蜜乳av一区二区三区| 91视视频在线观看入口直接观看www | 一区二区三区av电影| 国产精品系列在线播放| 欧美亚洲禁片免费| 国产精品网站在线| 国产又粗又猛又爽又黄91精品| 欧美四级电影在线观看| 国产精品乱码妇女bbbb| 精品在线亚洲视频| 欧美精品第一页| 亚洲黄色片在线观看| 成人av电影在线网| 久久精品在这里| 蜜臀精品久久久久久蜜臀| 欧美三级电影在线看| 1024成人网色www| 国产精品1区2区| 日韩欧美高清在线| 喷水一区二区三区| 91精品国产综合久久久久久久久久 | 国产一区二区三区免费播放| 欧美日韩的一区二区| 夜夜揉揉日日人人青青一国产精品| 处破女av一区二区| 久久久av毛片精品| 国产精品原创巨作av| 欧美电视剧在线观看完整版| 性欧美疯狂xxxxbbbb| 在线视频国内一区二区| 亚洲日本青草视频在线怡红院| 成人永久看片免费视频天堂| 欧美成人高清电影在线| 久久成人麻豆午夜电影| 亚洲精品一区二区三区在线观看 | 欧美日韩综合色| 亚洲一区二区三区在线看| 欧美综合在线视频|