1 /* gnuPoaCurrent.java --
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package gnu
.CORBA
.Poa
;
41 import org
.omg
.CORBA
.CurrentHelper
;
42 import org
.omg
.CORBA
.portable
.ObjectImpl
;
43 import org
.omg
.PortableServer
.Current
;
44 import org
.omg
.PortableServer
.CurrentOperations
;
45 import org
.omg
.PortableServer
.CurrentPackage
.NoContext
;
46 import org
.omg
.PortableServer
.POA
;
48 import java
.util
.Iterator
;
50 import java
.util
.TreeMap
;
53 * Supports the "Poa current" concept, providing the id and poa of
54 * the object currently being served. There is only one instance
55 * of this class per ORB. It maintains a thread to information map.
57 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
59 public class gnuPoaCurrent
64 * The table, mapping threads to records.
66 private TreeMap threads
= new TreeMap();
69 * Get the array of POA current repository ids.
71 * @return a single member array, containing value, returned
72 * by the {@link CurrentHelper#id}, normally
73 * "IDL:omg.org/PortableServer/Current:2.3".
75 public String
[] _ids()
77 return new String
[] { CurrentHelper
.id() };
81 * Get the object id, associated with the thread currently being served.
83 * @throws NoContext if the current thread is not associated with any
86 public byte[] get_object_id()
90 synchronized (threads
)
92 r
= (CurrentOperations
) threads
.get(Thread
.currentThread().getName());
95 return r
.get_object_id();
97 throw new NoContext(Thread
.currentThread().getName());
101 * Get the object POA, associated with the thread currently being served.
103 * @throws NoContext if the current thread is not associated with any
110 synchronized (threads
)
112 r
= (CurrentOperations
) threads
.get(Thread
.currentThread().getName());
117 throw new NoContext(Thread
.currentThread().getName());
121 * Add the entry to the map.
123 public void put(Thread t
, CurrentOperations record
)
125 synchronized (threads
)
127 threads
.put(t
.getName(), record
);
132 * Check if this Poa has some running threads.
134 public boolean has(POA poa
)
136 synchronized (threads
)
138 Iterator iter
= threads
.entrySet().iterator();
139 while (iter
.hasNext())
141 Map
.Entry item
= (Map
.Entry
) iter
.next();
144 if (((CurrentOperations
) item
.getValue()).get_POA() == poa
)
151 throw new InternalError();
159 * Check if this thread is registered.
161 public boolean has(Thread t
)
163 synchronized (threads
)
165 return threads
.containsKey(t
.getName());
170 * Remove the entry from the map.
172 public void remove(Thread t
)
174 synchronized (threads
)
176 threads
.remove(t
.getName());