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

📄 agentimp.java

📁 Java Communicating Agents是一个用于开发网络反应式信息agent的框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $Source: /home/data/cvsroot/src/jacomma/platform/engine/AgentImp.java,v $ * $Revision: 1.9 $ * $Date: 2000/10/28 20:09:08 $ * * This file is part of the jacomma framework * Copyright (c) 2000 	Dimitrios Vyzovitis *			mailto:dviz@egnatia.ee.auth.gr *			 * *			 *			 *			 * *	This library is free software; you can redistribute it and/or modify *	it under the terms of the GNU Library General Public License as published by *	the Free Software Foundation; either version 2 of the License, or *	(at your option) any later version. * *	This library 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 Library General Public License for more details. * *	You should have received a copy of the GNU Library General Public License *	along with this library; if not, write to the Free Software *	Foundation, Inc., 59 Temple Place, Suite 330,  *	Boston, MA  02111-1307  USA */package jacomma.platform.engine;import jacomma.platform.core.Agent;import jacomma.platform.core.MessagePattern;import jacomma.platform.core.RequestFailedException;import jacomma.icm.type.Handle;import jacomma.icm.type.Message;import jacomma.icm.type.MessageOptions;import jacomma.icm.type.Request;import jacomma.util.Visitor;import jacomma.util.Collections;import java.util.Iterator;import java.util.Collection;import java.util.List;import java.util.ListIterator;import java.util.ArrayList;import java.util.Set;import java.util.HashSet;import java.util.Map;import java.util.HashMap;import java.util.Hashtable;import java.util.Date;import java.net.InetAddress;/** * TBA **/class AgentImp implements Agent {		Handle handle_;	MessageQueue que_;	MessageBuffer outp_;	ConnectionBuffer cb_;	MessageDispatcher dsp_;	AgentMonitor mon_;	Map prop_;	ThreadGroup tg_;	ArrayList orgcs_;	HashMap rgcs_;	ArrayList oatcs_;	HashMap atcs_;	ArrayList odetcs_;	HashMap detcs_;	HashMap fwds_;	int rcount_; // how many times have we registered?	AgentImp( Handle h, MessageQueue mq, 			  MessageBuffer outp, MessageDispatcher mdsp, 			  ConnectionBuffer cb, AgentMonitor mon ) {		handle_ = h;		que_ = mq;		outp_ = outp;		dsp_ = mdsp;		mon_ = mon;		cb_ = cb;		prop_ = new Hashtable();		rgcs_ = new HashMap();		orgcs_ = new ArrayList();		atcs_ = new HashMap();		oatcs_ = new ArrayList();		detcs_ = new HashMap();		odetcs_ = new ArrayList();		fwds_ = new HashMap();	}	public String toString() { return handle_.toString(); }	public Handle getHandle() { return handle_; }	public Object setProperty( Object key, Object val ) { return prop_.put( key, val ); }	public Object getProperty( Object key ) { return prop_.get( key ); }	public Object clearProperty( Object key ) { return prop_.remove( key ); }	public java.util.Map properties() { return prop_; }	// thess sets are protocted from adding garbage	public synchronized Collection commServers() { return (Collection)orgcs_.clone(); }	public synchronized Collection attachedCommServers() { return (Collection)oatcs_.clone(); }	public synchronized Map forwards() { return (Map)fwds_.clone(); }	public Thread spawnThread( Runnable rb ) {		// security ;-)		Thread t = new Thread( tg_, rb );		t.start();				return t;	}	public synchronized Message sendAndWait( Handle to, Object cnt, MessagePattern ptrn ) 		throws java.io.IOException, InterruptedException {		return sendAndWait( new Message( handle_, to, cnt ), ptrn );	}		public synchronized Message sendAndWait( Message msg, MessagePattern ptrn ) 		throws java.io.IOException, InterruptedException {		// temporarily suspend all message dispatching		synchronized ( dsp_ ) {			Map hdls = clearHandlers();			outp_.put( msg );			Message r = recv( ptrn );						// no new handlers. since access is synchronized at the dispatcher			Map nhdls = setHandlers( hdls );						return r;		}	}		public void register() 		throws RequestFailedException {		Handle id = EngineUtilities.makeIdentifier( handle_ );		Message rq = Request.createRegisterRequest( id, handle_ );		_doRegister( id, rq );	}		public void register( InetAddress at ) 		throws RequestFailedException {		Handle id = EngineUtilities.makeIdentifier( handle_ );		Message rq = Request.createRegisterRequest( id, handle_, at );		_doRegister( id, rq );	}		public synchronized void register( Date lt ) 		throws RequestFailedException {		Handle id = EngineUtilities.makeIdentifier( handle_ );		Message rq = Request.createRegisterRequest( id, handle_, lt );		_doRegister( id, rq );	}		public void register( InetAddress to, Date lt ) 		throws RequestFailedException {		Handle id = EngineUtilities.makeIdentifier( handle_ );		Message rq = Request.createRegisterRequest( id, handle_, to, lt );		_doRegister( id, rq );	}	public void deregister()		throws RequestFailedException {		Handle id = EngineUtilities.makeIdentifier( handle_ );		// note: we deregister in reverse order of registration		// but only from attached servers		List rgcs = null;		synchronized( this ) { rgcs = (List)oatcs_.clone(); }		for ( ListIterator it = rgcs.listIterator( rgcs.size() );			  it.hasPrevious();			  _doDeregister( id, Request.createDeregisterRequest( id, 																  handle_,																  (Handle)it.previous() ) ) );	}	public void deregister( InetAddress at ) 		throws RequestFailedException {		Handle id = EngineUtilities.makeIdentifier( handle_ );		Message rq = Request.createDeregisterRequest( id, handle_, at );		_doDeregister( id, rq );	}	public void detach()		throws RequestFailedException {		Handle id = EngineUtilities.makeIdentifier( handle_ );		// note: we detach in reverse order of attachment		List atcs = null;		synchronized( this ) { atcs = (List)oatcs_.clone(); }		for ( ListIterator it = atcs.listIterator( atcs.size() );			  it.hasPrevious();			  _doDetach( id, Request.createDetachRequest( id, 														  handle_,														  (Handle)it.previous() ) ) );	}	public void detach( InetAddress at ) 		throws RequestFailedException {		Handle id = EngineUtilities.makeIdentifier( handle_ );		Message rq = Request.createDetachRequest( id, handle_, at );		_doDetach( id, rq );	}		public void attach()		throws RequestFailedException {		Handle id = EngineUtilities.makeIdentifier( handle_ );		// note: we attach in reverse order of detachment		List detcs = null;		synchronized( this ) { detcs = (List)odetcs_.clone(); }		for ( ListIterator it = detcs.listIterator( detcs.size() );			  it.hasPrevious();			  _doAttach( id, Request.createAttachRequest( id, 														  handle_,														  (Handle)it.previous() ) ) );	}	public void attach( InetAddress at ) 		throws RequestFailedException {		Handle id = EngineUtilities.makeIdentifier( handle_ );		Message rq = Request.createAttachRequest( id, handle_, at );		_doAttach( id, rq );	}		public void attach( Date lt )		throws RequestFailedException {		Handle id = EngineUtilities.makeIdentifier( handle_ );		for ( Iterator it = ((Map)detcs_.clone()).keySet().iterator();			  it.hasNext();			  _doAttach( id, Request.createAttachRequest( id, 														  handle_,														  (Handle)it.next(),														  lt ) ) );	}		public void attach( InetAddress to, Date lt ) 		throws RequestFailedException {		Handle id = EngineUtilities.makeIdentifier( handle_ );		Message rq = Request.createAttachRequest( id, handle_, to, lt );		_doAttach( id, rq );	}		public void destroy() 		throws RequestFailedException {		mon_.onDestroying( this );		// deregister everything that is left after event dispatching		deregister();		mon_.onDestroyed( this );	}		public void reqFwd( Handle to )		throws RequestFailedException {		Handle id = EngineUtilities.makeIdentifier( handle_ );		Message rq = Request.createForwardRequest( id, handle_, to );		_doFwd( id, to, rq );	}	public void reqFwd( InetAddress at, Handle to )		throws RequestFailedException {		Handle id = EngineUtilities.makeIdentifier( handle_ );		Message rq = Request.createForwardRequest( id, handle_, to, at );		_doFwd( id, to, rq );	}	public void cancelFwd( Handle to )		throws RequestFailedException {		Handle id = EngineUtilities.makeIdentifier( handle_ );		Message rq = Request.createCancelForwardRequest( id, handle_, to );		_doUnFwd( id, to, rq );	}	public void cancelFwd( InetAddress at, Handle to )		throws RequestFailedException {		Handle id = EngineUtilities.makeIdentifier( handle_ );

⌨️ 快捷键说明

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