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

📄 channelrequest.java

📁 sea是一个基于seda模式的实现。这个设计模式将系统分为很多stage。每个stage分布不同的任务(基于线程池)。通过任务流的方式提高系统的效率。
💻 JAVA
字号:
/* * Copyright (c) 2003, The Regents of the University of California, through * Lawrence Berkeley National Laboratory (subject to receipt of any required * approvals from the U.S. Dept. of Energy). All rights reserved. */package gov.lbl.dsd.sea.nio.event;import gov.lbl.dsd.sea.Stage;import gov.lbl.dsd.sea.event.GenericCallbackEvent;import java.nio.ByteBuffer;import java.nio.channels.SelectableChannel;/** * Requests an agent to perform some action on a given channel. *  * @author whoschek@lbl.gov * @author $Author: hoschek3 $ * @version $Revision: 1.18 $, $Date: 2004/07/28 19:49:20 $ */public abstract class ChannelRequest {	private ChannelRequest() {} // not instantiable		/**	 * Requests an agent to register the given	 * {@link java.nio.channels.SelectionKey}interest ops with the given	 * channel; The agent will enqueue future responses to the channel onto the	 * given observer stage; If an attachment is given the agent will attach it to the channel's key.	 */	public static class Register extends GenericCallbackEvent {				protected Object attachment;				protected static final Object NO_ATTACHMENT = new Object(); // indicates agent should not modify current attachment		public Register(Stage observer, SelectableChannel channel, int interestOps) {			this(observer, channel, interestOps, NO_ATTACHMENT);		}		public Register(Stage observer, SelectableChannel channel, int interestOps, Object attachment) {			super(observer, channel, new Integer(interestOps));			this.attachment = attachment;		}		public int getInterestOps() {			return ((Integer) this.getInfo()).intValue();		}		public SelectableChannel getChannel() {			return (SelectableChannel) this.getMessage();		}				/**		 * Returns the attachment the agent should attach to the channel's key.		 * 		 * @throws IllegalStateException if <code>hasAttachment() == false</code>.		 */		public Object getAttachment() {			if (!hasAttachment()) throw new IllegalStateException("no attachment available");			return this.attachment;		}				/**		 * Returns whether or not the request contains an attachment.		 */		public boolean hasAttachment() {			return this.attachment != NO_ATTACHMENT;		}			}			/**	 * Requests an agent to close the given channel.	 */	public static class Close extends GenericCallbackEvent {		public Close(SelectableChannel channel) {			super(null, channel);		}		public SelectableChannel getChannel() {			return (SelectableChannel) this.getMessage();		}	}	/**	 * Requests an agent to completely write ALL of the bytes in the given buffer	 * to the given channel; As usual with NIO, the data is contained between	 * indexes <code>buffer.position()</code> and <code>buffer.limit()</code>,	 * and <code>buffer.remaining()</code> bytes will be written; 	 */	public static class WriteData extends GenericCallbackEvent {		public WriteData(SelectableChannel channel, ByteBuffer buffer) {			super(null, channel, buffer);		}		public SelectableChannel getChannel() {			return (SelectableChannel) this.getMessage();		}		public ByteBuffer getBuffer() {			return (ByteBuffer) this.getInfo();		}	}	//	/**//	 * Requests an agent to add the given {@link java.nio.channels.SelectionKey}//	 * interest ops to the ops registered with the given channel; The agent will//	 * enqueue future responses to the channel onto the given observer stage; If//	 * an attachment is given the agent will attach it to the channel's key.//	 *///	public static class RegisterAdd extends Register {//		//		public RegisterAdd(Stage observer, SelectableChannel channel, int interestOps) {//			this(observer, channel, interestOps, NO_ATTACHMENT);//		}////		public RegisterAdd(Stage observer, SelectableChannel channel, int interestOps, Object attachment) {//			super(observer, channel, interestOps);//			this.attachment = attachment;//		}////	}////	/**//	 * Requests an agent to remove the given {@link java.nio.channels.SelectionKey}//	 * interest ops from the ops registered with the given channel; The agent will//	 * enqueue future responses to the channel onto the given observer stage; If//	 * an attachment is given the agent will attach it to the channel's key.//	 *///	public static class RegisterRemove extends Register {//		//		public RegisterRemove(Stage observer, SelectableChannel channel, int interestOps) {//			this(observer, channel, interestOps, NO_ATTACHMENT);//		}////		public RegisterRemove(Stage observer, SelectableChannel channel, int interestOps, Object attachment) {//			super(observer, channel, interestOps);//			this.attachment = attachment;//		}////	}////	/**//	 * Requests an agent to assign the given {@link java.nio.channels.SelectionKey}//	 * interest ops to the ops registered with the given channel; The agent will//	 * enqueue future responses to the channel onto the given observer stage; If//	 * an attachment is given the agent will attach it to the channel's key.//	 *///	public static class RegisterSet extends Register {//		//		public RegisterSet(Stage observer, SelectableChannel channel, int interestOps) {//			this(observer, channel, interestOps, NO_ATTACHMENT);//		}////		public RegisterSet(Stage observer, SelectableChannel channel, int interestOps, Object attachment) {//			super(observer, channel, interestOps);//			this.attachment = attachment;//		}////	}}

⌨️ 快捷键说明

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