1 21 package org.jacorb.imr; 22 23 import org.jacorb.imr.RegistrationPackage.DuplicatePOAName; 24 import org.jacorb.imr.RegistrationPackage.IllegalPOAName; 25 import org.omg.CORBA.INTERNAL ; 26 27 28 37 38 public class ImRAccessImpl 39 implements org.jacorb.orb.ImRAccess 40 { 41 private Registration reg = null; 42 private ImRInfo info = null; 43 44 47 private ImRAccessImpl () {} 48 49 50 56 public static ImRAccessImpl connect (org.omg.CORBA.ORB orb) 57 { 58 ImRAccessImpl result = new ImRAccessImpl (); 59 try 60 { 61 result.reg = RegistrationHelper.narrow( orb.resolve_initial_references("ImplementationRepository")); 62 } 63 catch( org.omg.CORBA.ORBPackage.InvalidName in ) 64 { 65 } 66 67 boolean non_exist = true; 68 if (result.reg != null) 69 { 70 try 71 { 72 non_exist = result.reg._non_existent(); 73 } 74 catch (org.omg.CORBA.SystemException e) 75 { 76 non_exist = true; 77 } 78 } 79 80 if (non_exist) 81 { 82 throw new INTERNAL ("Unable to resolve reference to ImR"); 83 } 84 return result; 85 } 86 87 public String getImRHost() 88 { 89 if( info == null ) 90 { 91 info = reg.get_imr_info(); 92 } 93 94 return info.host; 95 } 96 97 public int getImRPort() 98 { 99 if( info == null ) 100 { 101 info = reg.get_imr_info(); 102 } 103 104 return info.port; 105 } 106 107 public void registerPOA( String name, 108 String server, 109 String host, 110 int port) 111 throws INTERNAL 112 { 113 try 114 { 115 reg.register_poa(name, server, host, port ); 116 } 117 catch( DuplicatePOAName e ) 118 { 119 throw new INTERNAL ( "A server with the same combination of ImplName/POA-Name (" + 120 name + 121 ") is already registered and listed as active at the imr!" ); 122 } 123 catch( IllegalPOAName e ) 124 { 125 throw new INTERNAL ( "The ImR replied that the POA name >>" + 126 e.name + "<< is illegal!" ); 127 } 128 catch( UnknownServerName e ) 129 { 130 throw new INTERNAL ( "The ImR replied that the server name >>" + 131 e.name + "<< is unknown!" ); 132 } 133 } 134 135 public void setServerDown( String name ) 136 throws INTERNAL 137 { 138 try 139 { 140 reg.set_server_down( name ); 141 } 142 catch(UnknownServerName e) 143 { 144 throw new INTERNAL ( "The ImR replied that a server with name " + 145 name + " is unknown" ); 146 } 147 } 148 } | Popular Tags |