rmistack.java

来自「CmisJavaApi」· Java 代码 · 共 316 行

JAVA
316
字号
/* * 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: RMIStack.java,v 1.2 2000/09/05 14:42:57 festor Exp $//  $Source: /local/resedas/CVS-Repository/CmisJavaApi/src/fr/dyade/cmis/rmi/RMIStack.java,v $//---------------------------------------------------------------------------////  Todo//---------------------------------------------------------------------------//package fr.dyade.cmis.rmi;import java.rmi.Naming; import java.rmi.NotBoundException;import java.net.MalformedURLException;import java.rmi.RemoteException; import fr.dyade.cmis.api.CMISException;import fr.dyade.cmis.api.BadStackRoleException;import fr.dyade.cmis.api.AlreadyBoundException;import fr.dyade.cmis.api.operation.*;import fr.dyade.cmis.api.operation.event.*;import fr.dyade.cmis.api.types.*;import fr.dyade.cmis.impl.operation.CMISRequestImpl;import fr.dyade.cmis.impl.CMISEventQueue;import fr.dyade.cmis.util.TraceManager;import fr.dyade.cmis.rmi.operation.RequestToIndicationMapper;import fr.dyade.cmis.rmi.operation.ResponseToConfirmationMapper;/** Implementation of COJ using RMI as transport  * The user, manager side may instanciate as many association  he wants by instanciating as many RMIStack object as he wants.  * On agent side an rmi.Agent object must be instanciated and it listens for incoming  * association establishment request. A RMIStack, agent side, is instanciated on agent host for each new accepted associations.  * <p>  * Afterwards, this RMIStack object will be used to issue CMIS requests.   * To create CMIS requests, 6 factory  methods are available, each one corresponding to a particular CMIS request.  * <menu>  *    <li><a href="#newActionRequest()">newActionRequest()</a>  *    <li><a href="#newCancelGetRequest()">newCancelGetRequest()</a>  *    <li><a href="#newCreateRequest()">newCreateRequest()</a>  *    <li><a href="#newDeleteRequest()">newDeleteRequest()</a>  *    <li><a href="#newGetRequest()">newGetRequest()</a>  *    <li><a href="#newSetRequest()">newSetRequest()</a>  * </menu>  *  * This implementation of CMISStack over RMI is based on CMISStackImp generic implementation.  * It is defined as a <strong>final</strong> class to avoid user missuses.  * @see fr.dyade.cmis.rmi.AgentImpl  * @see fr.dyade.cmis.rmi.AssociationEndPoint  * @see fr.dyade.cmis.impl.CMISStackImpl  * @see fr.dyade.cmis.api.CMISStack  * @version cvs $Id: RMIStack.java,v 1.2 2000/09/05 14:42:57 festor Exp $  */public final class RMIStack  extends fr.dyade.cmis.impl.CMISStackImpl {      /** Constructor of a RMIStack, manager side.	* @param pRemoteAgentName the rmi url-like remote agent's name.	* @param pEventQueue the event queue to use to post indication/confirmation/completion related to this stack.	*                    If null a private queue is created  for this new stack.	* @see fr.dyade.cmis.rmi.RMIStack#bind() actual connection to agent	* @see java.rmi.Naming#lookup object name format	*/      public RMIStack( String pRemoteAgentName, CMISEventQueue pEventQueue ) {	 super(pEventQueue);	 fRemoteAgentName=pRemoteAgentName;	 // First initialize the Session parameters... Object encapsulation sucks !	 try{super.setRole(MANAGERSIDEONLY);}catch(CMISException e){}      }      /** Constructor of a RMIStack, manager side using a default private event queue.	* @param pRemoteAgentName the rmi url-like remote agent's name.	* @see java.rmi.Naming#lookup object name format	*/      public RMIStack( String pRemoteAgentName ) {	 this(pRemoteAgentName, null);      }      /** Constructor for a RMIStack, agents side	* @param  pEventQueue the event queue the listening thread will post the incomming events (ind, conf, completion)	*                     in. If this parameter is null a private queue is created.	* @param pManagerAEP the manager remote association end point	* 	* Remark: this constructor has a package access, as it should only be call for cmis.rmi.Agent class.	* @see fr.dyade.cmis.rmi.Agent	*/      RMIStack(CMISEventQueue pEventQueue, AssociationEndPoint pManagerAEP, AgentImpl pAgentContainer ) { 	 super(pEventQueue);	 fRemoteAssociationEndPoint=pManagerAEP;	 fAgentContainer=pAgentContainer;	 try{super.setRole(AGENTSIDEONLY);}catch(CMISException e){}      }      /** Open an association from manager side.	* @throws BadStackRoleException if the stack is not create as a manager stack	* @throws RMIRemoteException if a RMI remote exception occurred when contacting remote agent.	* @throws AlreadyBoundException if an association has been already 	*         established for the stack by a prevoius bind().		* @throw NotBoundException if the agent name url specified at construction time	*        can not be association of an CMIS agent.	* @thorw MalformedURLException if the the agent name url specified at construction time	*        has a bad format.	*/      public void bind() throws  BadStackRoleException, RMIRemoteException, AlreadyBoundException, NotBoundException, MalformedURLException {	 if (getRole()!=MANAGERSIDEONLY) {	    throw new BadStackRoleException("bind only allowed for manager side");	 }	 if (fRemoteAssociationEndPoint!=null) {	    throw new AlreadyBoundException();	 }  	 try {	 // get ref to REMOTE agent, as we are in manager role.	    fRemoteAgent=(Agent)Naming.lookup(fRemoteAgentName); 	    fRemoteAssociationEndPoint=fRemoteAgent.acceptAssociation(new AssociationEndPointImpl(this));	    // RemoteException OR MalformedURLException	 } catch (RemoteException re) {	    throw new RMIRemoteException(re);	 }      }      /** Close an association.	*	* TODO "rebind"	*/      public void unbind() throws BadStackRoleException, RMIRemoteException {	 if (fRemoteAssociationEndPoint!=null) {	    try {	       fRemoteAssociationEndPoint.close();	       terminate();//	       fRemoteAgent=null;	    } catch (RemoteException re) { throw new RMIRemoteException(re);}	       	 } else {	    TraceManager.println(5, getClass().getName()+".unBind(): not bound");	 }      }      void terminate(){	 stopDispatching();	 if (getRole()!=MANAGERSIDEONLY) {	    fAgentContainer.removeStack(this);	 }	 fRemoteAssociationEndPoint=null;      }// From CMISStack      public final void setRole( short pRole ) {	 System.err.println("RMIStack.java: can not change role once created");      }      public final ActionRequest newActionRequest() {	 return (new fr.dyade.cmis.rmi.operation.ActionRequestImpl(this));      }      /** Creates a new GetRequest	*	* @see fr.dyade.cmis.rmi.operation.GetRequestImpl	*	*/      public final GetRequest newGetRequest() {	 return new fr.dyade.cmis.rmi.operation.GetRequestImpl(this);      }      /** Creates a new SetRequest	*	* @see fr.dyade.cmis.rmi.operation.SetRequestImpl	*	*/      public final SetRequest newSetRequest(){	 return new fr.dyade.cmis.rmi.operation.SetRequestImpl(this);      }      /** Creates a new CreateRequest	*	*  @see fr.dyade.cmis.rmi.operation.CreateRequestImpl	*	*/      public final CreateRequest newCreateRequest() {	 return new fr.dyade.cmis.rmi.operation.CreateRequestImpl(this);      }            /** Creates a new DeleteRequest	*	*  @see fr.dyade.cmis.rmi.operation.DeleteRequestImpl	*	*/      public final DeleteRequest newDeleteRequest() {	 return (new fr.dyade.cmis.rmi.operation.DeleteRequestImpl(this));      }      /** Creates a new CancelGetRequest	*	*  @see fr.dyade.cmis.rmi.operation.CancelGetRequestImpl	*	*/      public final CancelGetRequest newCancelGetRequest() {	 return new fr.dyade.cmis.rmi.operation.CancelGetRequestImpl(this);      }      /** Creates a new EventReportResponse.	* 	* @see fr.dyade.cmis.rmi.operation.EventReportResponseImpl	*/      public final EventReportResponse newEventReportResponse() {	 return new fr.dyade.cmis.rmi.operation.EventReportResponseImpl(this);      }      // agent side stuff       /**	*  Creates a new EventReportRequest	*	*  @see fr.dyade.cmis.rmi.operation.EventReportRequestImpl	*	*/      public final EventReportRequest newEventReportRequest() {	 return new fr.dyade.cmis.rmi.operation.EventReportRequestImpl(this);      }      /**	* Creates a new ActionResponse	*	* @see fr.dyade.cmis.rmi.operation.ActionResponseImpl	*/      public final ActionResponse newActionResponse() {	 return new fr.dyade.cmis.rmi.operation.ActionResponseImpl(this);      }            /**	* Creates a new GetResponse	*	* @see fr.dyade.cmis.rmi.operation.GetResponseImpl	*/      public final GetResponse newGetResponse(){	 return new fr.dyade.cmis.rmi.operation.GetResponseImpl(this);      }	       /** Creates a new SetResponse	*	* @see fr.dyade.cmis.rmi.operation.SetResponseImpl	*/      public final SetResponse newSetResponse(){	 return new fr.dyade.cmis.rmi.operation.SetResponseImpl(this);      }            /** Creates a new CreateResponse	*	* @see fr.dyade.cmis.rmi.operation.CreateResponseImpl	*/      public final CreateResponse newCreateResponse() {	 return new fr.dyade.cmis.rmi.operation.CreateResponseImpl(this);      }      /** Creates a new DeleteResponse	*	* @see fr.dyade.cmis.rmi.operation.DeleteResponseImpl	*/      public final DeleteResponse newDeleteResponse() {	 return new fr.dyade.cmis.rmi.operation.DeleteResponseImpl(this);      }            /** Creates a new CancelGetResponse	*	* @see fr.dyade.cmis.rmi.operation.CancelGetResponseImpl	*/      public final CancelGetResponse newCancelGetResponse() {	 return new fr.dyade.cmis.rmi.operation.CancelGetResponseImpl(this);      }      /** Send any request over association.	* Allocates an invoke id. Updates request accordingly before transport, and then 	* sends it to the remove association end point.	* @param pType the type code for the request (see cmis.rmi.AssociationEndPoint)	* @param req the CMIS request to send 	* @return the allocated invoke id (int format)	* 	* This method is synchronized because of fRequestCount update.	* @see fr.dyade.cmis.rmi.AssociationEndPoint	*/      synchronized public final int sendRequest( RequestToIndicationMapper req ) throws CMISException {	 int lId=fRequestCount;	 fRequestCount++;	 CMISIndication ind=req.mapToIndication();	 ind.setInvokeId(new InvokeId(lId));	 try {	    //REM: fr.dyade.cmis.api.operation.CMISIndication implements java.io.Serializable	    fRemoteAssociationEndPoint.pushIndication(ind);	 } catch (java.rmi.RemoteException e) {	    throw new RMIRemoteException(e);	 }	 return lId;      }      public final void sendResponse( ResponseToConfirmationMapper resp ) throws CMISException {	 try {	    //REM: fr.dyade.cmis.api.operation.CMISIndication implements java.io.Serializable	    fRemoteAssociationEndPoint.pushConfirmation(resp.mapToConfirmation());	  } catch (java.rmi.RemoteException e) {	     throw new RMIRemoteException(e);	  }      }      public String toString() {	 return "RMIStack " +	    ((getRole()==MANAGERSIDEONLY)	     ?("as manager to "+fRemoteAgentName)	     :("as "+ fAgentContainer + " agent"));      }      // manager role      private String fRemoteAgentName;      private Agent fRemoteAgent;      // agent side      private AgentImpl fAgentContainer;      private AssociationEndPoint fRemoteAssociationEndPoint;      private int fRequestCount=Integer.MIN_VALUE;} // RMIStack

⌨️ 快捷键说明

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