--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementatio\r
+ *******************************************************************************/\r
+package org.simantics.db.server.internal;\r
+\r
+import java.net.InetSocketAddress;\r
+\r
+/**\r
+ * @author J-P Laine\r
+ */\r
+public class ServerAddress {\r
+ private InetSocketAddress socketAddress;\r
+ private String dbid;\r
+\r
+ public ServerAddress(String hostAndPort, String dbid) {\r
+ this(hostAndPort);\r
+ this.dbid = dbid;\r
+ }\r
+\r
+ public ServerAddress(String hostAndPort) {\r
+ assert (hostAndPort != null);\r
+\r
+ String[] split = hostAndPort.split(":");\r
+ if (split.length != 2)\r
+ throw new IllegalArgumentException("address does not contain a port, missing ':' character");\r
+ this.socketAddress = InetSocketAddress.createUnresolved(split[0], Integer.parseInt(split[1]));\r
+ this.dbid = null;\r
+ }\r
+\r
+ public ServerAddress(String host, int port) {\r
+ assert (host != null);\r
+ this.socketAddress = new InetSocketAddress(host, port);\r
+ this.dbid = null;\r
+ }\r
+\r
+ public ServerAddress(String host, int port, String dbid) {\r
+ assert (host != null);\r
+ this.socketAddress = InetSocketAddress.createUnresolved(host, port);\r
+ this.dbid = dbid;\r
+ }\r
+\r
+ public ServerAddress(InetSocketAddress socketAddress) {\r
+ assert (socketAddress != null);\r
+ this.socketAddress = socketAddress;\r
+ this.dbid = null;\r
+ }\r
+\r
+ public ServerAddress(InetSocketAddress socketAddress, String dbid) {\r
+ assert (socketAddress != null);\r
+ this.socketAddress = socketAddress;\r
+ this.dbid = dbid;\r
+ }\r
+\r
+ public InetSocketAddress getAddress() {\r
+ return socketAddress;\r
+ }\r
+\r
+ public String getDbid() {\r
+ return dbid;\r
+ }\r
+\r
+ @Override\r
+ public int hashCode() {\r
+ return socketAddress.hashCode();\r
+ }\r
+\r
+ @Override\r
+ public boolean equals(Object other) {\r
+ if (this == other) return true;\r
+ if (other == null || !(getClass().equals(other.getClass()))) return false;\r
+ ServerAddress r = (ServerAddress) other;\r
+ return r.socketAddress.equals(socketAddress) && (r.dbid != null && r.dbid.equals(dbid) || r.dbid == null && dbid == null);\r
+ }\r
+\r
+ @Override\r
+ public String toString() {\r
+ if(dbid != null) {\r
+ return socketAddress.toString()+" / "+dbid;\r
+ } else {\r
+ return socketAddress.toString();\r
+ }\r
+ }\r
+}\r