📄 gnuservantobject.java
字号:
*/ public OutputStream _invoke(String method, InputStream input, ResponseHandler r_handler ) throws SystemException { boolean intercept = false; ServerRequestInterceptorOperations interceptor = null; gnuServerRequestInfo info = null; ResponseHandlerImpl i_handler = null; try { if (orb.iServer != null && r_handler instanceof ResponseHandlerImpl ) { interceptor = orb.iServer; i_handler = (ResponseHandlerImpl) r_handler; info = new gnuServerRequestInfo(this, i_handler.request_header, i_handler.reply_header ); intercept = true; interceptor.receive_request_service_contexts(info); } try { CookieHolder cookie = null; AOM.Obj self = poa.aom.get(Id); if (poa.servant_locator != null) { // If the servant locator is in use, it is always responsible // for providing the servant. self.servant = servant = null; cookie = new CookieHolder(); } else if (self != null && self.isDeactiveted()) { if (poa.applies( ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION ) && poa.servant_activator != null ) { // Reset the servant, forcing the subsequent activation. servant = null; } else { throw new OBJECT_NOT_EXIST("Object deactivated", 0x535503ec, CompletionStatus.COMPLETED_NO ); } } InvokeHandler handler = getHandler(method, cookie, true); Delegate d = null; try { d = servant._get_delegate(); orb.currents.put(Thread.currentThread(), this); } catch (Exception ex) { // In some cases exception is thrown if the delegate is not set. } if (d instanceof ServantDelegateImpl) { // If the delegate is already set, check maybe we can // reuse the existing instance. if (((ServantDelegateImpl) d).object != this) { servant._set_delegate(new ServantDelegateImpl(servant, poa, Id)); } } else { servant._set_delegate(new ServantDelegateImpl(servant, poa, Id)); } try { switch (manager.get_state().value()) { case State._ACTIVE : OutputStream rt; try { if (intercept) { interceptor.receive_request(info); } rt = handler._invoke(method, input, r_handler); if (intercept) { // Handler is casted into i_handler. if (i_handler.isExceptionReply()) { info.m_reply_header.reply_status = ReplyHeader.USER_EXCEPTION; // Make Any, holding the user exception. Any a = orb.create_any(); OutputStream buf = i_handler.getBuffer(); InputStream in = buf.create_input_stream(); String uex_idl = "unknown"; try { in.mark(Integer.MAX_VALUE); uex_idl = in.read_string(); in.reset(); } catch (IOException e) { throw new Unexpected(e); } try { UserException exception = ObjectCreator.readUserException(uex_idl, in ); ObjectCreator.insertWithHelper(a, exception ); } catch (Exception e) { // Failed due any reason, insert without // helper. a.insert_Streamable(new StreamHolder( buf.create_input_stream() ) ); RecordTypeCode r = new RecordTypeCode(TCKind.tk_except); r.setId(uex_idl); r.setName(ObjectCreator.getDefaultName( uex_idl ) ); } info.m_usr_exception = a; interceptor.send_exception(info); } else { info.m_reply_header.reply_status = ReplyHeader.NO_EXCEPTION; interceptor.send_reply(info); } } } catch (SystemException sys_ex) { if (intercept) { info.m_reply_header.reply_status = ReplyHeader.SYSTEM_EXCEPTION; info.m_sys_exception = sys_ex; interceptor.send_exception(info); } throw sys_ex; } return rt; case State._HOLDING : // The holding mode is implemented // relying on the holding capabilites of the network // support (if any). // TODO FIXME in more recent CORBA applications, the // client // ORB can free the connection and wait for a server side // notification about the completed request. Implement // this // as soon as JDK specification would allow bidirectional // policy. int sleep = 5; int max = 500; // Wait till the state will be switched into some other // mode. while (manager.get_state().value() == State._HOLDING) { try { Thread.sleep(sleep); if (sleep < max) { sleep = max; } } catch (InterruptedException ex) { } } // Handle another mode. return _invoke(method, input, r_handler); case State._DISCARDING : throw new TRANSIENT("Discarding mode", 0x535503e9, CompletionStatus.COMPLETED_NO ); case State._INACTIVE : throw new OBJ_ADAPTER("POA deactivated", 0x535503ea, CompletionStatus.COMPLETED_NO ); default : throw new InternalError(); // No more states. } } finally { if (poa.servant_locator != null) { poa.servant_locator.postinvoke(Id, poa, method, cookie.value, servant ); servant = null; } } } finally { orb.currents.remove(Thread.currentThread()); } } catch (ForwardRequest fex) { // May be thrown by interceptor. if (intercept) { Forwarding: while (true) { info.m_reply_header.reply_status = ReplyHeader.LOCATION_FORWARD; info.m_forward_reference = fex.forward; try { interceptor.send_other(info); break Forwarding; } catch (ForwardRequest fex2) { info.m_forward_reference = fex2.forward; fex.forward = info.m_forward_reference; } } } throw new gnuForwardRequest(fex.forward); } catch (gnuForwardRequest fex) { // May be thrown during activation. if (intercept) { Forwarding: while (true) { info.m_reply_header.reply_status = ReplyHeader.LOCATION_FORWARD; info.m_forward_reference = fex.forward_reference; try { interceptor.send_other(info); break Forwarding; } catch (ForwardRequest fex2) { info.m_forward_reference = fex2.forward; fex.forward_reference = (ObjectImpl) fex2.forward; } } } throw fex; } } /** * Compare with another object for equality, comparing the object keys. */ public boolean equals(java.lang.Object other) { if (other instanceof gnuServantObject) { gnuServantObject o = (gnuServantObject) other; return Arrays.equals(o.Id, Id); } else { return false; } } /** * Get the hash code, based on the object key. */ public int hashCode() { long s = 0; int v = 1; for (int i = 0; i < Id.length; i++) { s += Id [ i ] * v; if (s > Integer.MAX_VALUE) { s = s % Integer.MAX_VALUE; v = 1; } v = v * 8; } return (int) (s % Integer.MAX_VALUE); } /** * Get the object id. */ public byte[] get_object_id() { return Id; } /** * Get POA. */ public POA get_POA() { return poa; } /** * Returns without action. */ public void _release() { } /** * Returns without action. */ public void _releaseReply(InputStream stream) { } /** * Checks if this object is equivalent to another instance. These objects are * assumed equal if they are connected to the same orb and poa under the same * Id, regardless of they delegates. * * @param another instance to check. * @return */ public boolean _is_equivalent(org.omg.CORBA.Object other) { if (other instanceof gnuServantObject) { gnuServantObject g = (gnuServantObject) other; return orb == g.orb && poa == g.poa && Arrays.equals(Id, g.Id); } else if (other instanceof IorObject) { IorObject ir = ((IorObject) other); try { IorDelegate ird = (IorDelegate) ir._get_delegate(); byte[] ior_id = poa.idFormIor(ird.getIor().key); if (ior_id != null && Arrays.equals(ior_id, Id)) { return true; } else { return false; } } catch (Exception ex) { // Non - typical delegate or very specific subclass of // IOR_constructed_object. return super._is_equivalent(other); } } return super._is_equivalent(other); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -