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