1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementatio
\r
11 *******************************************************************************/
\r
12 package org.simantics.db.server.internal;
\r
14 import java.net.InetSocketAddress;
\r
19 public class ServerAddress {
\r
20 private InetSocketAddress socketAddress;
\r
21 private String dbid;
\r
23 public ServerAddress(String hostAndPort, String dbid) {
\r
28 public ServerAddress(String hostAndPort) {
\r
29 assert (hostAndPort != null);
\r
31 String[] split = hostAndPort.split(":");
\r
32 if (split.length != 2)
\r
33 throw new IllegalArgumentException("address does not contain a port, missing ':' character");
\r
34 this.socketAddress = InetSocketAddress.createUnresolved(split[0], Integer.parseInt(split[1]));
\r
38 public ServerAddress(String host, int port) {
\r
39 assert (host != null);
\r
40 this.socketAddress = new InetSocketAddress(host, port);
\r
44 public ServerAddress(String host, int port, String dbid) {
\r
45 assert (host != null);
\r
46 this.socketAddress = InetSocketAddress.createUnresolved(host, port);
\r
50 public ServerAddress(InetSocketAddress socketAddress) {
\r
51 assert (socketAddress != null);
\r
52 this.socketAddress = socketAddress;
\r
56 public ServerAddress(InetSocketAddress socketAddress, String dbid) {
\r
57 assert (socketAddress != null);
\r
58 this.socketAddress = socketAddress;
\r
62 public InetSocketAddress getAddress() {
\r
63 return socketAddress;
\r
66 public String getDbid() {
\r
71 public int hashCode() {
\r
72 return socketAddress.hashCode();
\r
76 public boolean equals(Object other) {
\r
77 if (this == other) return true;
\r
78 if (other == null || !(getClass().equals(other.getClass()))) return false;
\r
79 ServerAddress r = (ServerAddress) other;
\r
80 return r.socketAddress.equals(socketAddress) && (r.dbid != null && r.dbid.equals(dbid) || r.dbid == null && dbid == null);
\r
84 public String toString() {
\r
86 return socketAddress.toString()+" / "+dbid;
\r
88 return socketAddress.toString();
\r