OAInvocationInfo.java revision 608:7e06bf1dcb09
1/*
2 * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25package com.sun.corba.se.spi.oa;
26
27import javax.rmi.CORBA.Tie ;
28
29import org.omg.CORBA.portable.ServantObject;
30
31import org.omg.PortableServer.Servant;
32
33import org.omg.PortableServer.ServantLocatorPackage.CookieHolder;
34
35import com.sun.corba.se.spi.oa.ObjectAdapter ;
36import com.sun.corba.se.spi.copyobject.ObjectCopierFactory ;
37
38/** This class is a holder for the information required to implement POACurrent.
39* It is also used for the ServantObject that is returned by _servant_preinvoke calls.
40* This allows us to avoid allocating an extra object on each collocated invocation.
41*/
42public class OAInvocationInfo extends ServantObject {
43    // This is the container object for the servant.
44    // In the RMI-IIOP case, it is the RMI-IIOP Tie, and the servant is the
45    // target of the Tie.
46    // In all other cases, it is the same as the Servant.
47    private java.lang.Object    servantContainer ;
48
49    // These fields are to support standard OMG APIs.
50    private ObjectAdapter       oa;
51    private byte[]              oid;
52
53    // These fields are to support the Object adapter implementation.
54    private CookieHolder        cookieHolder;
55    private String              operation;
56
57    // This is the copier to be used by javax.rmi.CORBA.Util.copyObject(s)
58    // For the current request.
59    private ObjectCopierFactory factory ;
60
61    public OAInvocationInfo(ObjectAdapter oa, byte[] id )
62    {
63        this.oa = oa;
64        this.oid  = id;
65    }
66
67    // Copy constructor of sorts; used in local optimization path
68    public OAInvocationInfo( OAInvocationInfo info, String operation )
69    {
70        this.servant            = info.servant ;
71        this.servantContainer   = info.servantContainer ;
72        this.cookieHolder       = info.cookieHolder ;
73        this.oa                 = info.oa;
74        this.oid                = info.oid;
75        this.factory            = info.factory ;
76
77        this.operation          = operation;
78    }
79
80    //getters
81    public ObjectAdapter    oa()                    { return oa ; }
82    public byte[]           id()                    { return oid ; }
83    public Object           getServantContainer()   { return servantContainer ; }
84
85    // Create CookieHolder on demand.  This is only called by a single
86    // thread, so no synchronization is needed.
87    public CookieHolder     getCookieHolder()
88    {
89        if (cookieHolder == null)
90            cookieHolder = new CookieHolder() ;
91
92        return cookieHolder;
93    }
94
95    public String           getOperation()      { return operation; }
96    public ObjectCopierFactory  getCopierFactory()      { return factory; }
97
98    //setters
99    public void setOperation( String operation )    { this.operation = operation ; }
100    public void setCopierFactory( ObjectCopierFactory factory )    { this.factory = factory ; }
101
102    public void setServant(Object servant)
103    {
104        servantContainer = servant ;
105        if (servant instanceof Tie)
106            this.servant = ((Tie)servant).getTarget() ;
107        else
108            this.servant = servant;
109    }
110}
111