001 package com.croftsoft.apps.vaft.core; 002 003 import java.io.*; 004 import java.net.InetAddress; 005 import java.rmi.*; 006 007 /********************************************************************* 008 * <P> 009 * @author 010 * <A HREF="http://www.alumni.caltech.edu/~croft">David W. Croft</A> 011 * @version 012 * 1998-04-26 013 *********************************************************************/ 014 015 public class HostInfo extends ActorRemoteInfo implements Serializable 016 ////////////////////////////////////////////////////////////////////// 017 ////////////////////////////////////////////////////////////////////// 018 { 019 020 ////////////////////////////////////////////////////////////////////// 021 // Static methods 022 ////////////////////////////////////////////////////////////////////// 023 024 public static HostRemote getHostRemote ( String url ) 025 throws java.net.MalformedURLException, 026 NotBoundException, 027 RemoteException 028 ////////////////////////////////////////////////////////////////////// 029 { 030 return ( HostRemote ) Naming.lookup ( url ); 031 } 032 033 public static SwapRemote getSwapRemote ( String url ) 034 throws java.net.MalformedURLException, 035 NotBoundException, 036 RemoteException 037 ////////////////////////////////////////////////////////////////////// 038 { 039 return ( SwapRemote ) Naming.lookup ( url ); 040 } 041 042 ////////////////////////////////////////////////////////////////////// 043 // Constructor method 044 ////////////////////////////////////////////////////////////////////// 045 046 public HostInfo ( 047 String rmi_server_name, 048 int rmi_server_port, 049 String rmi_object_name, 050 String [ ] roles ) 051 ////////////////////////////////////////////////////////////////////// 052 { 053 super ( rmi_server_name, rmi_server_port, rmi_object_name, roles ); 054 } 055 056 ////////////////////////////////////////////////////////////////////// 057 // Access methods 058 ////////////////////////////////////////////////////////////////////// 059 060 public String getRmi_server_name ( ) { return rmi_server_name; } 061 public int getRmi_server_port ( ) { return rmi_server_port; } 062 public String getRmi_object_name ( ) { return rmi_object_name; } 063 public String [ ] getRoles ( ) { return roles; } 064 065 ////////////////////////////////////////////////////////////////////// 066 // Convenience methods 067 ////////////////////////////////////////////////////////////////////// 068 069 public HostRemote getHostRemote ( ) 070 throws java.net.MalformedURLException, 071 NotBoundException, 072 RemoteException 073 ////////////////////////////////////////////////////////////////////// 074 { 075 return getHostRemote ( toURL ( ) ); 076 } 077 078 public SwapRemote getSwapRemote ( ) 079 throws java.net.MalformedURLException, 080 NotBoundException, 081 RemoteException 082 ////////////////////////////////////////////////////////////////////// 083 { 084 return getSwapRemote ( toURL ( ) ); 085 } 086 087 public HostList swap ( HostList hostList ) 088 throws java.net.MalformedURLException, 089 NotBoundException, 090 RemoteException 091 ////////////////////////////////////////////////////////////////////// 092 { 093 return getSwapRemote ( ).swap ( hostList ); 094 } 095 096 public String toURL ( ) 097 ////////////////////////////////////////////////////////////////////// 098 { 099 return "rmi://" + rmi_server_name 100 + ":" + rmi_server_port 101 + "/" + rmi_object_name; 102 } 103 104 public String toString ( ) 105 ////////////////////////////////////////////////////////////////////// 106 { 107 return toURL ( ); 108 } 109 110 /********************************************************************* 111 * Returns true if the host address, rmi_server_port, and 112 * rmi_object_name are all the same. Returns false if hostInfo is 113 * null. 114 *********************************************************************/ 115 public boolean matches ( HostInfo hostInfo ) 116 throws java.net.UnknownHostException 117 ////////////////////////////////////////////////////////////////////// 118 { 119 if ( hostInfo == null ) return false; 120 return ( hostInfo.rmi_server_port == rmi_server_port ) 121 && hostInfo.rmi_object_name.equals ( rmi_object_name ) 122 && hostInfo.getHostAddress ( ).equals ( getHostAddress ( ) ); 123 } 124 125 public String getHostAddress ( ) 126 throws java.net.UnknownHostException 127 ////////////////////////////////////////////////////////////////////// 128 { 129 return InetAddress.getByName ( rmi_server_name ).getHostAddress ( ); 130 } 131 132 /********************************************************************* 133 * If the rmi_server_name is "localhost", converts it to a String 134 * representing the IP address number. 135 *********************************************************************/ 136 public synchronized void convertLocalHostToAddress ( ) 137 throws java.net.UnknownHostException 138 ////////////////////////////////////////////////////////////////////// 139 { 140 if ( rmi_server_name.toLowerCase ( ).equals ( "localhost" ) ) 141 { 142 rmi_server_name = InetAddress.getLocalHost ( ).getHostAddress ( ); 143 } 144 } 145 146 ////////////////////////////////////////////////////////////////////// 147 ////////////////////////////////////////////////////////////////////// 148 }