agentimpl.java
来自「CmisJavaApi」· Java 代码 · 共 265 行
JAVA
265 行
/* * The contents of this file are subject to the Dyade Public License, * as defined by the file DYADE_PUBLIC_LICENSE.TXT * * You may not use this file except in compliance with the License. You may * obtain a copy of the License on the Dyade web site (www.dyade.fr). * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific terms governing rights and limitations under the License. * * The Original Code is CmisJava API, including the java package * fr.dyade.cmis, released September 5, 2000. * * The Initial Developer of the Original Code is Dyade. The Original Code and * portions created by Dyade are Copyright Bull and Copyright INRIA. * All Rights Reserved. *//* Copyright 1996-2000 by Institut National de Recherche en Informatique * et en Automatique (INRIA) * All rights reserved. See COPYRIGHT in top-level directory. * * Authors: Laurent Andrey, Eric Dillon, Olivier Festor */// $Id: AgentImpl.java,v 1.2 2000/09/05 14:42:55 festor Exp $// $Source: /local/resedas/CVS-Repository/CmisJavaApi/src/fr/dyade/cmis/rmi/AgentImpl.java,v $//---------------------------------------------------------------------------//// Todo//---------------------------------------------------------------------------//// Add exception case then newRMIStack() fails=association refused.// model's flaw: association set up is synchronous (rmi call==rpc)// Other design flaw: Agent - stack relation is partially implemented Stack -> agent way.// It will suck for agent clean up.package fr.dyade.cmis.rmi;import java.util.*;import java.rmi.Naming;import java.rmi.RemoteException;import java.rmi.RMISecurityManager;import java.rmi.server.UnicastRemoteObject;import fr.dyade.cmis.api.CMISStack;import fr.dyade.cmis.api.ErrorHandler;import fr.dyade.cmis.api.operation.event.ActionListener;import fr.dyade.cmis.api.operation.event.CancelGetListener;import fr.dyade.cmis.api.operation.event.CreateListener;import fr.dyade.cmis.api.operation.event.DeleteListener;import fr.dyade.cmis.api.operation.event.GetListener;import fr.dyade.cmis.api.operation.event.SetListener;import fr.dyade.cmis.api.operation.event.InternalErrorListener;import fr.dyade.cmis.impl.CMISEventQueue;import fr.dyade.cmis.util.TraceManager;/** Implementation for the basic CMIS RMI agent abstraction. * The main task for this class is to: * <menu> * <li> get registred in rmi registry * <li> accept "association" with manager * <li> instanciate CMIS (RMI) Stack for newly accepted association * </menu> * @version cvs $Id: AgentImpl.java,v 1.2 2000/09/05 14:42:55 festor Exp $ */public class AgentImpl extends UnicastRemoteObject implements Agent { public AgentImpl( String pName, CMISEventQueue pEventQueue ) throws RemoteException, java.net.MalformedURLException { super(); fName=pName; if (System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager()); } Naming.rebind(pName, this); fEventQueue= (pEventQueue!=null)?pEventQueue:new CMISEventQueue(); } public AgentImpl( String pName ) throws RemoteException, java.net.MalformedURLException { this(pName, null); } final public AssociationEndPoint acceptAssociation( AssociationEndPoint pManagerAssociationEndPoint ) throws RemoteException { RMIStack s=newRMIStack(pManagerAssociationEndPoint); addStack(s); return new AssociationEndPointImpl(s); } /** Basic list of Listener to initialize any RMIStack ones. * @see #newRMIStack */ public final void addActionListener(ActionListener pListener) { synchronized(fActionListeners) { fActionListeners.addElement(pListener); } } public final void removeActionListener(ActionListener pListener){ synchronized(fActionListeners) { fActionListeners.removeElement(pListener); } } public final void addCancelGetListener(CancelGetListener pListener){ synchronized(fCancelGetListeners) { fCancelGetListeners.addElement(pListener); } } public final void removeCancelGetListener(CancelGetListener pListener){ synchronized(fCancelGetListeners) { fCancelGetListeners.removeElement(pListener); } } public final void addDeleteListener(DeleteListener pListener){ synchronized(fDeleteListeners) { fDeleteListeners.addElement(pListener); } } public final void removeDeleteListener(DeleteListener pListener){ synchronized(fDeleteListeners) { fDeleteListeners.removeElement(pListener); } } public final void addCreateListener(CreateListener pListener){ synchronized(fCreateListeners) { fCreateListeners.addElement(pListener); } } public final void removeCreateListener(CreateListener pListener){ synchronized(fCreateListeners) { fCreateListeners.removeElement(pListener); } } public final void addGetListener(GetListener pListener){ synchronized(fGetListeners) { fGetListeners.addElement(pListener); } } public final void removeGetListener(GetListener pListener){ synchronized(fGetListeners) { fGetListeners.removeElement(pListener); } } public final void addSetListener(SetListener pListener){ synchronized(fSetListeners) { fSetListeners.addElement(pListener); } } public final void removeSetListener(SetListener pListener){ synchronized(fSetListeners) { fSetListeners.removeElement(pListener); } } /** Add an "asynchrounous" listener for internal runtime stack error seen as event. * More one listener can be handled by the agent. * This/these listeners are used by the <code>{@link AgentImpl#newRMIStack}</code> factory method * when initializing a stack for a new association. * @param pListener a new listener to call on error event * @see fr.dyade.cmis.api.operation.event.InternalErrorEvent */ public final void addInternalErrorListener( InternalErrorListener pListener ) { synchronized(fInternalErrorListeners) { fInternalErrorListeners.addElement(pListener); } } /** Remove a listener internal runtime stack error. * @param pListener the listener to remove */ public final void removeInternalErrorListener( InternalErrorListener pListener ){ synchronized(fInternalErrorListeners) { fInternalErrorListeners.removeElement(pListener); } } /** Set the synchronous error handler. * This "last chance" error handler is call when asynchronous error reporting * via <code>{@link InternalErrorListener}</code> is unsafe or not appropriated. * One and only one synchrounous error handler is setable. * This handler is used by the <code>{@link AgentImpl#newRMIStack}</code> factory method * when initializing a stack for a new association. * @param pListener a new listener to call on error event * @param pHandler the handler to use, if null default stack handler will be use * by <code>{@link AgentImpl#newRMIStack}</code> factory method. * @see fr.dyade.cmis.impl.CMISStackImpl#setSynchronousErrorHandler */ public final void setSynchronousErrorHandler( ErrorHandler pHandler ) { fSynchronousErrorHandler=pHandler; } /** Get all "associations", what are also the * currently running <code>RMIStack</code>. * @return an enumeration giving all <code>RMIStack</code> * currently managed by this agent. * <p>NOTE: the user should cast to {@link RMIStack} when calling the * <code>nextElement()</code> of the result. */ public final Enumeration getStacks() { return fStacks.elements(); } /** Stack factory method for acceptAssociation * Default one. Stack is built for agent default ones. * One common EventQueue is shared by all association/instanciated stack. * This is a factory method (107) pattern used by Agent.acceptAssociation * @see fr.dyade.cmis.rmi.AgentImpl#acceptAssociation */ protected RMIStack newRMIStack( AssociationEndPoint pManagerAssociationEndPoint ) { RMIStack lNewStack=new RMIStack(fEventQueue, pManagerAssociationEndPoint, this); for (Enumeration e=fActionListeners.elements(); e.hasMoreElements();) { lNewStack.addActionListener((ActionListener)e.nextElement()); } for (Enumeration e=fCancelGetListeners.elements(); e.hasMoreElements();) { lNewStack.addCancelGetListener((CancelGetListener)e.nextElement()); } for (Enumeration e=fCreateListeners.elements(); e.hasMoreElements();) { lNewStack.addCreateListener((CreateListener)e.nextElement()); } for (Enumeration e=fDeleteListeners.elements(); e.hasMoreElements();) { lNewStack.addDeleteListener((DeleteListener)e.nextElement()); } for (Enumeration e=fGetListeners.elements(); e.hasMoreElements();) { lNewStack.addGetListener((GetListener)e.nextElement()); } for (Enumeration e=fSetListeners.elements(); e.hasMoreElements();) { lNewStack.addSetListener((SetListener)e.nextElement()); } for (Enumeration e=fInternalErrorListeners.elements(); e.hasMoreElements();) { lNewStack.addInternalErrorListener((InternalErrorListener)e.nextElement()); } lNewStack.setSynchronousErrorHandler(fSynchronousErrorHandler); return lNewStack; } /** Add a stack (connection) to this agent. * This method keeps track of a newly instanciated stack. * @param pStack the new stack * Not for public use. * <p>NOTE: Internal container is a Vector: which * is a synchronized container. */ final void addStack( CMISStack pStack ) { fStacks.addElement(pStack); } /** Remove a stack (connection) for this agent. * Remove a stack the agent has previously instancied. * Not for public use. * NOTE: Internal container is a Vector: a syschonized container. * @see fr.dyade.cmis.rmi.RMIStack#unbind() */ final void removeStack( CMISStack pStack ) { TraceManager.debugln(getClass().getName()+".removeStack remove "+ pStack); while (fStacks.removeElement(pStack)) {} } public String toString() { return fName; } private String fName; // Rem: Vector is a synchronized container private Vector fActionListeners = new Vector(); private Vector fCancelGetListeners = new Vector(); private Vector fCreateListeners = new Vector(); private Vector fDeleteListeners = new Vector(); private Vector fEventReportListeners = new Vector(); private Vector fGetListeners = new Vector(); private Vector fSetListeners = new Vector(); private Vector fInternalErrorListeners = new Vector(); private ErrorHandler fSynchronousErrorHandler; private CMISEventQueue fEventQueue; // Note: HashSet is not a synchronyzed container -- jdk 1.2 only... // private HashSet fStacks= new HashSet(); // Vector is a synchronized container. private Vector fStacks=new Vector();}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?