KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > interceptors > PICurrent


1 /*
2  * @(#)PICurrent.java 1.14 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.interceptors;
9
10 import com.sun.corba.se.spi.orb.ORB;
11 import org.omg.PortableInterceptor.Current JavaDoc;
12 import org.omg.PortableInterceptor.InvalidSlot JavaDoc;
13 import org.omg.CORBA.Any JavaDoc;
14 import org.omg.CORBA.BAD_INV_ORDER JavaDoc;
15 import org.omg.CORBA.CompletionStatus JavaDoc;
16
17 import com.sun.corba.se.spi.logging.CORBALogDomains ;
18 import com.sun.corba.se.impl.logging.OMGSystemException ;
19
20 /**
21  * PICurrent is the implementation of Current as specified in the Portable
22  * Interceptors Spec orbos/99-12-02.
23  * IMPORTANT: PICurrent is implemented with the assumption that get_slot()
24  * or set_slot() will not be called in ORBInitializer.pre_init() and
25  * post_init().
26  */

27 public class PICurrent extends org.omg.CORBA.LocalObject JavaDoc
28     implements Current JavaDoc
29 {
30     // slotCounter is used to keep track of ORBInitInfo.allocate_slot_id()
31
private int slotCounter;
32
33     // The ORB associated with this PICurrent object.
34
private ORB myORB;
35
36     private OMGSystemException wrapper ;
37
38     // True if the orb is still initialzing and get_slot and set_slot are not
39
// to be called.
40
private boolean orbInitializing;
41
42     // ThreadLocal contains a stack of SlotTable which are used
43
// for resolve_initial_references( "PICurrent" );
44
private ThreadLocal JavaDoc threadLocalSlotTable
45         = new ThreadLocal JavaDoc( ) {
46             protected Object JavaDoc initialValue( ) {
47                 SlotTable table = new SlotTable( myORB, slotCounter );
48                 return new SlotTableStack( myORB, table );
49             }
50         };
51
52     /**
53      * PICurrent constructor which will be called for every ORB
54      * initialization.
55      */

56     PICurrent( ORB myORB ) {
57     this.myORB = myORB;
58     wrapper = OMGSystemException.get( myORB,
59         CORBALogDomains.RPC_PROTOCOL ) ;
60     this.orbInitializing = true;
61         slotCounter = 0;
62     }
63
64
65     /**
66      * This method will be called from ORBInitInfo.allocate_slot_id( ).
67      * simply returns a slot id by incrementing slotCounter.
68      */

69     int allocateSlotId( ) {
70         int slotId = slotCounter;
71         slotCounter = slotCounter + 1;
72         return slotId;
73     }
74
75
76     /**
77      * This method gets the SlotTable which is on the top of the
78      * ThreadLocalStack.
79      */

80     SlotTable getSlotTable( ) {
81         SlotTable table = (SlotTable)
82                 ((SlotTableStack)threadLocalSlotTable.get()).peekSlotTable();
83         return table;
84     }
85
86     /**
87      * This method pushes a SlotTable on the SlotTableStack. When there is
88      * a resolve_initial_references("PICurrent") after this call. The new
89      * PICurrent will be returned.
90      */

91     void pushSlotTable( ) {
92         SlotTableStack st = (SlotTableStack)threadLocalSlotTable.get();
93         st.pushSlotTable( );
94     }
95
96
97     /**
98      * This method pops a SlotTable on the SlotTableStack.
99      */

100     void popSlotTable( ) {
101         SlotTableStack st = (SlotTableStack)threadLocalSlotTable.get();
102         st.popSlotTable( );
103     }
104
105     /**
106      * This method sets the slot data at the given slot id (index) in the
107      * Slot Table which is on the top of the SlotTableStack.
108      */

109     public void set_slot( int id, Any JavaDoc data ) throws InvalidSlot JavaDoc
110     {
111     if( orbInitializing ) {
112         // As per ptc/00-08-06 if the ORB is still initializing, disallow
113
// calls to get_slot and set_slot. If an attempt is made to call,
114
// throw a BAD_INV_ORDER.
115
throw wrapper.invalidPiCall3() ;
116     }
117
118         getSlotTable().set_slot( id, data );
119     }
120
121     /**
122      * This method gets the slot data at the given slot id (index) from the
123      * Slot Table which is on the top of the SlotTableStack.
124      */

125     public Any JavaDoc get_slot( int id ) throws InvalidSlot JavaDoc
126     {
127     if( orbInitializing ) {
128         // As per ptc/00-08-06 if the ORB is still initializing, disallow
129
// calls to get_slot and set_slot. If an attempt is made to call,
130
// throw a BAD_INV_ORDER.
131
throw wrapper.invalidPiCall4() ;
132     }
133
134         return getSlotTable().get_slot( id );
135     }
136
137     /**
138      * This method resets all the slot data to null in the
139      * Slot Table which is on the top of SlotTableStack.
140      */

141     void resetSlotTable( ) {
142         getSlotTable().resetSlots();
143     }
144
145     /**
146      * Called from ORB when the ORBInitializers are about to start
147      * initializing.
148      */

149     void setORBInitializing( boolean init ) {
150     this.orbInitializing = init;
151     }
152 }
153
154
155     
156
Popular Tags