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.DuplicatePOAName;
025: import org.jacorb.imr.RegistrationPackage.IllegalPOAName;
026: import org.omg.CORBA.INTERNAL;
027: import org.jacorb.orb.iiop.IIOPAddress;
028:
029: /**
030: * @author Nicolas Noffke
031: * @version $Id: ImRAccessImpl.java,v 1.10 2006/06/27 12:54:33 alphonse.bendt Exp $
032: */
033: public class ImRAccessImpl implements org.jacorb.orb.ImRAccess {
034: private Registration reg = null;
035: private ImRInfo info = null;
036:
037: /**
038: * <code>ImRAccessImpl</code> private; use the static connect method.
039: */
040: private ImRAccessImpl() {
041: // use the static connect method
042: }
043:
044: /**
045: * <code>connect</code> resolves the IMR and returns a new ImRAccessImpl.
046: *
047: * @param orb an <code>org.omg.CORBA.ORB</code> value
048: * @return an <code>ImRAccessImpl</code> value
049: */
050: public static ImRAccessImpl connect(org.omg.CORBA.ORB orb) {
051: final ImRAccessImpl result = new ImRAccessImpl();
052:
053: try {
054: result.reg = RegistrationHelper
055: .narrow(orb
056: .resolve_initial_references("ImplementationRepository"));
057: } catch (org.omg.CORBA.ORBPackage.InvalidName e) {
058: throw new INTERNAL(
059: "unable to resolve ImplementationRepository: "
060: + e.toString());
061: }
062:
063: boolean non_exist = true;
064: if (result.reg != null) {
065: try {
066: non_exist = result.reg._non_existent();
067: } catch (org.omg.CORBA.SystemException e) {
068: non_exist = true;
069: }
070: }
071:
072: if (non_exist) {
073: throw new INTERNAL("Unable to resolve reference to ImR");
074: }
075: return result;
076: }
077:
078: public org.jacorb.orb.etf.ProtocolAddressBase getImRAddress() {
079: if (info == null) {
080: info = reg.get_imr_info();
081: }
082: return new IIOPAddress(info.host, info.port);
083: }
084:
085: public String getImRHost() {
086: if (info == null) {
087: info = reg.get_imr_info();
088: }
089:
090: return info.host;
091: }
092:
093: public int getImRPort() {
094: if (info == null) {
095: info = reg.get_imr_info();
096: }
097:
098: return info.port;
099: }
100:
101: public void registerPOA(String name, String server,
102: org.jacorb.orb.etf.ProtocolAddressBase address)
103: throws INTERNAL {
104: if (address instanceof IIOPAddress) {
105: registerPOA(name, server, ((IIOPAddress) address)
106: .getHostname(), ((IIOPAddress) address).getPort());
107: } else {
108: throw new INTERNAL("IMR only supports IIOP based POAs");
109: }
110: }
111:
112: public void registerPOA(String name, String server, String host,
113: int port) throws INTERNAL {
114: try {
115: reg.register_poa(name, server, host, port);
116: } catch (DuplicatePOAName e) {
117: throw new INTERNAL(
118: "A server with the same combination of ImplName/POA-Name ("
119: + name
120: + ") is already registered and listed as active at the imr: "
121: + e.toString());
122: } catch (IllegalPOAName e) {
123: throw new INTERNAL("The ImR replied that the POA name >>"
124: + e.name + "<< is illegal: " + e.toString());
125: } catch (UnknownServerName e) {
126: throw new INTERNAL(
127: "The ImR replied that the server name >>" + e.name
128: + "<< is unknown: " + e.toString());
129: }
130: }
131:
132: public void setServerDown(String name) throws INTERNAL {
133: try {
134: reg.set_server_down(name);
135: } catch (UnknownServerName e) {
136: throw new INTERNAL(
137: "The ImR replied that a server with name " + name
138: + " is unknown: " + e.toString());
139: }
140: }
141: }
|