001: /*
002: * JacORB - a free Java ORB
003: *
004: * Copyright (C) 1999-2004 Gerald Brose
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Library General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Library General Public License for more details.
015: *
016: * You should have received a copy of the GNU Library General Public
017: * License along with this library; if not, write to the Free
018: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
019: *
020: */
021:
022: package org.jacorb.imr;
023:
024: import org.jacorb.imr.RegistrationPackage.*;
025:
026: /**
027: * This class stores information about a POA. It also provides methods
028: * for reactivation, conversion, and for waiting for reactivation.
029: *
030: * @author Nicolas Noffke
031: *
032: * @version $Id: ImRPOAInfo.java,v 1.11 2006/06/27 12:54:33 alphonse.bendt Exp $
033: */
034:
035: public class ImRPOAInfo implements java.io.Serializable {
036: public static final long serialVersionUID = 1l;
037:
038: protected int port;
039: protected ImRServerInfo server;
040: protected String host;
041: protected String name;
042: protected boolean active;
043: protected long timeout; // 2 min.
044:
045: /**
046: * The constructor of this class.
047: *
048: * @param name the POAs name.
049: * @param host the POAs host.
050: * @param port the port the POA listens on.
051: * @param server the server the POA is associated with.
052: * @exception IllegalPOAName thrown when <code>name</code> is
053: * <code>null</code> or of length zero.
054: */
055:
056: public ImRPOAInfo(String name, String host, int port,
057: ImRServerInfo server, long timeout) throws IllegalPOAName {
058: if (name == null || name.length() == 0) {
059: throw new IllegalPOAName(name);
060: }
061:
062: this .name = name;
063: this .host = host;
064: this .port = port;
065: this .server = server;
066: this .active = true;
067: this .timeout = timeout;
068: }
069:
070: /**
071: * "Converts" this Object to an instance of the POAInfo class.
072: *
073: * @return a POAInfo object.
074: */
075:
076: public POAInfo toPOAInfo() {
077: return new POAInfo(name, host, port, server.name, active);
078: }
079:
080: /**
081: * Reactivates this POA, i.e. sets it to active and unblocks any
082: * waiting threads.
083: *
084: * @param host the POAs new host.
085: * @param port the POAs new port.
086: */
087:
088: public synchronized void reactivate(String host, int port) {
089: this .host = host;
090: this .port = port;
091: active = true;
092: server.active = true;
093: server.restarting = false;
094: notifyAll();
095: }
096:
097: /**
098: * This method blocks until the POA is reactivated, or the
099: * timeout is exceeded.
100: *
101: * @return false, if the timeout has been exceeded, true otherwise.
102: */
103:
104: public synchronized boolean awaitActivation() {
105: while (!active) {
106: try {
107: long _sleep_begin = System.currentTimeMillis();
108: wait(timeout);
109: if (!active
110: && (System.currentTimeMillis() - _sleep_begin) > timeout) {
111: return false;
112: }
113: } catch (java.lang.Exception e) {
114: //o.k., not nice but since this class is Serializable, we
115: //can't keep a Logger member
116: e.printStackTrace();
117: }
118: }
119:
120: return true;
121: }
122: } // ImRPOAInfo
|