Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / gnu / CORBA / Poa / gnuPoaCurrent.java
blob927d02fe3d21f0702431fed50fb9937e2fdade13
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)
9 any later version.
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
19 02110-1301 USA.
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
24 combination.
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;
49 import java.util.Map;
50 import java.util.TreeMap;
52 /**
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
60 extends ObjectImpl
61 implements Current
63 /**
64 * The table, mapping threads to records.
66 private TreeMap threads = new TreeMap();
68 /**
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() };
80 /**
81 * Get the object id, associated with the thread currently being served.
83 * @throws NoContext if the current thread is not associated with any
84 * object.
86 public byte[] get_object_id()
87 throws NoContext
89 CurrentOperations r;
90 synchronized (threads)
92 r = (CurrentOperations) threads.get(Thread.currentThread().getName());
94 if (r != null)
95 return r.get_object_id();
96 else
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
104 * object.
106 public POA get_POA()
107 throws NoContext
109 CurrentOperations r;
110 synchronized (threads)
112 r = (CurrentOperations) threads.get(Thread.currentThread().getName());
114 if (r != null)
115 return r.get_POA();
116 else
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)
146 return true;
149 catch (NoContext ex)
151 throw new InternalError();
155 return false;
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());