KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > imr > ImRPOAInfo


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21 package org.jacorb.imr;
22
23 import org.jacorb.imr.RegistrationPackage.*;
24 import org.jacorb.imr.AdminPackage.*;
25
26 import org.jacorb.util.*;
27
28 /**
29  * This class stores information about a POA. It also provides methods
30  * for reactivation, conversion, and for waiting for reactivation.
31  *
32  * @author Nicolas Noffke
33  *
34  * @version $Id: ImRPOAInfo.java,v 1.10 2004/05/06 16:03:35 nicolas Exp $
35  */

36
37 public class ImRPOAInfo
38     implements java.io.Serializable JavaDoc
39 {
40     protected int port;
41     protected ImRServerInfo server;
42     protected String JavaDoc host;
43     protected String JavaDoc name;
44     protected boolean active;
45     protected long timeout; // 2 min.
46

47     /**
48      * The constructor of this class.
49      *
50      * @param name the POAs name.
51      * @param host the POAs host.
52      * @param port the port the POA listens on.
53      * @param server the server the POA is associated with.
54      * @exception IllegalPOAName thrown when <code>name</code> is
55      * <code>null</code> or of length zero.
56      */

57
58     public ImRPOAInfo(String JavaDoc name,
59                       String JavaDoc host,
60                       int port,
61                       ImRServerInfo server,
62                       long timeout)
63         throws IllegalPOAName
64     {
65         if (name == null || name.length() == 0)
66             throw new IllegalPOAName(name);
67
68         this.name = name;
69         this.host = host;
70         this.port = port;
71         this.server = server;
72         this.active = true;
73         this.timeout = timeout;
74     }
75
76     /**
77      * "Converts" this Object to an instance of the POAInfo class.
78      *
79      * @return a POAInfo object.
80      */

81
82     public POAInfo toPOAInfo()
83     {
84         return new POAInfo(name, host, port,server.name, active);
85     }
86
87     /**
88      * Reactivates this POA, i.e. sets it to active and unblocks any
89      * waiting threads.
90      *
91      * @param host the POAs new host.
92      * @param port the POAs new port.
93      */

94
95     public synchronized void reactivate(String JavaDoc host, int port)
96     {
97         this.host = host;
98         this.port = port;
99         active = true;
100         server.active = true;
101         server.restarting = false;
102         notifyAll();
103     }
104
105     /**
106      * This method blocks until the POA is reactivated, or the
107      * timeout is exceeded.
108      *
109      * @return false, if the timeout has been exceeded, true otherwise.
110      */

111
112     public synchronized boolean awaitActivation()
113     {
114         while(!active)
115         {
116             try
117             {
118                 long _sleep_begin = System.currentTimeMillis();
119                 wait(timeout);
120                 if (!active &&
121                     (System.currentTimeMillis() - _sleep_begin) > timeout)
122                 {
123                     return false;
124                 }
125             }
126             catch (java.lang.Exception JavaDoc e)
127             {
128                 //o.k., not nice but since this class is Serializable, we
129
//can't keep a Logger member
130
e.printStackTrace();
131             }
132         }
133         
134         return true;
135     }
136 } // ImRPOAInfo
137

138
Popular Tags