1 29 30 package com.caucho.server.http; 31 32 import com.caucho.util.CharBuffer; 33 34 37 public class InvocationKey { 38 private boolean _isSecure; 39 40 private CharSequence _host; 41 private int _port; 42 43 private byte []_uri; 44 private int _uriLength; 45 46 49 public InvocationKey() 50 { 51 } 52 53 62 InvocationKey(boolean isSecure, 63 CharSequence host, int port, 64 byte []uri, int uriLength) 65 { 66 _isSecure = isSecure; 67 68 if (host != null) { 69 CharBuffer cb = new CharBuffer(); 70 cb.append(host); 71 _host = cb; 72 } 73 _port = port; 74 75 _uri = new byte[uriLength]; 76 System.arraycopy(uri, 0, _uri, 0, uriLength); 77 _uriLength = uriLength; 78 } 79 80 88 public void init(boolean isSecure, 89 CharSequence host, int port, 90 byte []uri, int uriLength) 91 { 92 _isSecure = isSecure; 93 94 _host = host; 95 _port = port; 96 97 _uri = uri; 98 _uriLength = uriLength; 99 } 100 101 public boolean isSecure() 102 { 103 return _isSecure; 104 } 105 106 109 public CharSequence getHost() 110 { 111 return _host; 112 } 113 114 117 public void setHost(CharSequence host) 118 { 119 _host = host; 120 } 121 122 125 public int getPort() 126 { 127 return _port; 128 } 129 130 133 public void setPort(int port) 134 { 135 _port = port; 136 } 137 138 141 public byte []getUriBuffer() 142 { 143 return _uri; 144 } 145 146 149 public int getUriLength() 150 { 151 return _uriLength; 152 } 153 154 157 public int hashCode() 158 { 159 int hash = _port + (_isSecure ? 65521 : 31); 160 byte []uri = _uri; 161 int length = _uriLength; 162 163 for (int i = length - 1; i >= 0; i--) 164 hash = 65521 * hash + uri[i]; 165 166 if (_host != null) 167 hash = 65521 * hash + _host.hashCode(); 168 169 return hash; 170 } 171 172 175 public boolean equals(Object b) 176 { 177 if (! (b instanceof InvocationKey)) 178 return false; 179 180 InvocationKey test = (InvocationKey) b; 181 182 if (_isSecure != test._isSecure) 183 return false; 184 185 if (_port != test._port) 186 return false; 187 188 int length = _uriLength; 189 190 if (length != test._uriLength) 191 return false; 192 193 byte []uriA = _uri; 194 byte []uriB = test._uri; 195 196 for (int i = length - 1; i >= 0; i--) 197 if (uriA[i] != uriB[i]) 198 return false; 199 200 if (_host == null) 201 return test._host == null; 202 else 203 return _host.equals(test._host); 204 } 205 206 public Object clone() 207 { 208 return new InvocationKey(_isSecure, _host, _port, _uri, _uriLength); 209 } 210 211 214 public String toString() 215 { 216 if (_host == null) 217 return "InvocationKey[" + new String (_uri, 0, _uriLength) + "]"; 218 else 219 return ("InvocationKey[host=" + _host + ",port=" + _port + 220 ",uri=" + new String (_uri, 0, _uriLength) + "]"); 221 } 222 } 223 | Popular Tags |