📄 gnurequest.java
字号:
/* gnuRequest.java -- Copyright (C) 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package gnu.CORBA;import gnu.CORBA.CDR.BufferredCdrInput;import gnu.CORBA.CDR.BufferedCdrOutput;import gnu.CORBA.GIOP.MessageHeader;import gnu.CORBA.GIOP.ReplyHeader;import gnu.CORBA.GIOP.RequestHeader;import gnu.CORBA.GIOP.CodeSetServiceContext;import gnu.CORBA.Interceptor.gnuClientRequestInfo;import gnu.CORBA.Poa.ORB_1_4;import org.omg.CORBA.ARG_IN;import org.omg.CORBA.ARG_INOUT;import org.omg.CORBA.ARG_OUT;import org.omg.CORBA.Any;import org.omg.CORBA.BAD_INV_ORDER;import org.omg.CORBA.BAD_PARAM;import org.omg.CORBA.Bounds;import org.omg.CORBA.COMM_FAILURE;import org.omg.CORBA.CompletionStatus;import org.omg.CORBA.Context;import org.omg.CORBA.ContextList;import org.omg.CORBA.Environment;import org.omg.CORBA.ExceptionList;import org.omg.CORBA.INV_POLICY;import org.omg.CORBA.MARSHAL;import org.omg.CORBA.NO_IMPLEMENT;import org.omg.CORBA.NO_RESOURCES;import org.omg.CORBA.NVList;import org.omg.CORBA.NamedValue;import org.omg.CORBA.ORB;import org.omg.CORBA.Policy;import org.omg.CORBA.Request;import org.omg.CORBA.SystemException;import org.omg.CORBA.TypeCode;import org.omg.CORBA.UnknownUserException;import org.omg.CORBA.portable.ObjectImpl;import org.omg.IOP.ServiceContext;import org.omg.IOP.TAG_CODE_SETS;import org.omg.IOP.TAG_INTERNET_IOP;import org.omg.IOP.TaggedComponent;import org.omg.IOP.TaggedProfile;import org.omg.PortableInterceptor.ClientRequestInfo;import org.omg.PortableInterceptor.ClientRequestInterceptorOperations;import org.omg.PortableInterceptor.ForwardRequest;import org.omg.PortableInterceptor.InvalidSlot;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.net.BindException;import java.net.Socket;import java.util.ArrayList;/** * The implementation of the CORBA request. * * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) */public class gnuRequest extends Request implements Cloneable{ /** * The maximal supported GIOP version. */ public static Version MAX_SUPPORTED = new Version(1, 2); /** * The initial pause that the Request makes when the required port is not * available. */ public static int PAUSE_INITIAL = 50; /** * The number of repretetive attempts to get a required port, if it is not * immediately available. */ public static int PAUSE_STEPS = 12; /** * The maximal pausing interval between two repetetive attempts. The interval * doubles after each unsuccessful attempt, but will not exceed this value. */ public static int PAUSE_MAX = 1000; /** * The interceptor, listening the major request submission points. */ ClientRequestInterceptorOperations m_interceptor; /** * The request info, used by interceptor. */ ClientRequestInfo m_info = new gnuClientRequestInfo(this); /** * The empty byte array. */ private static final RawReply EMPTY = new RawReply(null, new MessageHeader(), new byte[ 0 ]); /** * The context holder for methods ctx(Context) and ctx(). */ protected Context m_context; /** * The context list for method contexts(). */ protected ContextList m_context_list; /** * The request environment for holding the exception the has possibly been * thrown by the method being invoked. */ protected Environment m_environment = new gnuEnvironment(); /** * The list of all exceptions that can be thrown by the method being invoked. */ protected ExceptionList m_exceptions = new gnuExceptionList(); /** * The result, returned by the invoked method (function). */ protected NamedValue m_result = new gnuNamedValue(); /** * The exception id, received from the server, null if none. */ protected String m_exception_id; /** * The thrown system exception. */ protected SystemException m_sys_ex; /** * The invocation target. */ protected org.omg.CORBA.Object m_target; /** * The name of the method being invoked. */ protected String m_operation; /** * This field temporary remembers the value of the forwarded ior reference. If * it is not null, the request was forwarded and the effective target is not * the same as the default target. */ public IOR m_forward_ior; /** * Is set when object, and not IOR is directly available. */ public org.omg.CORBA.Object m_forwarding_target; /** * The flag, indicating that the request has been sent and the result is * already received. */ protected boolean complete; /** * The flag, indicating that the response to this request must be ignored * (used with {@link #send_oneway()}). */ protected boolean oneWay; /** * The flag, indicating that the request has been sent and no result is yet * received. */ protected boolean running; /** * The request arguments. */ protected gnuNVList m_args = new gnuNVList(); /** * The request arguments in the case when they are directly written into the * parameter buffer. */ protected StreamBasedRequest m_parameter_buffer; /** * The array of slots. */ protected Any[] m_slots; /** * The request header currently in use. */ protected RequestHeader m_rqh; /** * The reply header currently in use. */ protected ReplyHeader m_rph; /** * The IOR of the target. */ private IOR ior; /** * The ORB of the target. */ private ORB orb; /** * The encoding, used to send the message. * * The default encoding is inherited from the set IOR (that string reference * can be encoded in either Big or Little endian). If the IOR encoding is not * known (for example, by obtaining the reference from the naming service), * the Big Endian is used. */ private boolean Big_endian = true; /** * Set the IOR data, sufficient to find the invocation target. This also sets * default endian encoding for invocations. * * @see IOR.parse(String) */ public void setIor(IOR an_ior) { ior = an_ior; setBigEndian(ior.Big_Endian); } /** * Used when redirecting request to another target. */ gnuRequest redirected; /** * Get the IOR data, sufficient to find the invocation target. * * @return the IOR data. */ public IOR getIor() { return ior; } /** * Set the ORB, related to the invocation target. */ public void setORB(ORB an_orb) { orb = an_orb; // Take the interceptor from the ORB. if (orb instanceof OrbRestricted) m_interceptor = ((OrbRestricted) orb).iClient; if (m_interceptor != null && orb instanceof ORB_1_4) { m_slots = ((ORB_1_4) orb).ic_current.clone_slots(); } } /** * Set the encoding that will be used to send the message. The default * encoding is inherited from the set IOR (that string reference can be * encoded in either Big or Little endian). If the IOR encoding is not known * (for example, by obtaining the reference from the naming service), the Big * Endian is used. * * @param use_big_endian true to use the Big Endian, false to use the Little * Endian encoding. */ public void setBigEndian(boolean use_big_endian) { Big_endian = use_big_endian; } /** * The the method name to invoke. * * @param operation the method name. */ public void setOperation(String operation) { m_operation = operation; } /** * Get the parameter stream, where the invocation arguments should be written * if they are written into the stream directly. */ public StreamBasedRequest getParameterStream() { m_parameter_buffer = new StreamBasedRequest(); m_parameter_buffer.request = this; m_parameter_buffer.setVersion(ior.Internet.version); m_parameter_buffer.setCodeSet(CodeSetServiceContext.negotiate(ior.Internet.CodeSets)); m_parameter_buffer.setOrb(orb); m_parameter_buffer.setBigEndian(Big_endian); // For the old iiop versions, it is important to set the size // correctly. if (ior.Internet.version.until_inclusive(1, 1)) { BufferedCdrOutput measure = new BufferedCdrOutput(); measure.setOffset(12); if (m_rqh == null) m_rqh = new gnu.CORBA.GIOP.v1_0.RequestHeader(); m_rqh.operation = m_operation; m_rqh.object_key = ior.key; m_rqh.write(measure); m_parameter_buffer.setOffset(12 + measure.buffer.size()); } return m_parameter_buffer; } /** * Creates a shallow copy of this request. */ public gnuRequest Clone() { try { return (gnuRequest) clone(); } catch (CloneNotSupportedException ex) { throw new Unexpected(ex); } } /** {@inheritDoc} */ public Any add_in_arg() { gnuNamedValue v = new gnuNamedValue(); v.setFlags(ARG_IN.value); m_args.add(v); return v.value(); } /** {@inheritDoc} */ public Any add_inout_arg() { gnuNamedValue v = new gnuNamedValue(); v.setFlags(ARG_INOUT.value); m_args.add(v); return v.value(); } /** {@inheritDoc} */ public Any add_named_in_arg(String name) { gnuNamedValue v = new gnuNamedValue(); v.setFlags(ARG_IN.value); v.setName(name); m_args.add(v); return v.value(); } /** {@inheritDoc} */ public Any add_named_inout_arg(String name) { gnuNamedValue v = new gnuNamedValue(); v.setFlags(ARG_INOUT.value); v.setName(name); m_args.add(v); return v.value(); } /** {@inheritDoc} */ public Any add_named_out_arg(String name) { gnuNamedValue v = new gnuNamedValue(); v.setFlags(ARG_OUT.value); v.setName(name); m_args.add(v); return v.value(); } /** {@inheritDoc} */ public Any add_out_arg() { gnuNamedValue v = new gnuNamedValue(); v.setFlags(ARG_OUT.value); m_args.add(v); return v.value(); } /** {@inheritDoc} */ public NVList arguments() { return m_args; } /** {@inheritDoc} */ public ContextList contexts() { return m_context_list; } /** {@inheritDoc} */ public Context ctx() { return m_context; } /** {@inheritDoc} */ public void ctx(Context a_context) { m_context = a_context; } /** {@inheritDoc} */ public Environment env() { return m_environment; } /** {@inheritDoc} */ public ExceptionList exceptions() { return m_exceptions; } /** {@inheritDoc} */ public void get_response() throws org.omg.CORBA.WrongTransaction { /** * The response is ready after it is received. FIXME implement context
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -