001/* 002 * This file is part of the Kompics component model runtime. 003 * 004 * Copyright (C) 2009 Swedish Institute of Computer Science (SICS) 005 * Copyright (C) 2009 Royal Institute of Technology (KTH) 006 * 007 * This program is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU General Public License 009 * as published by the Free Software Foundation; either version 2 010 * of the License, or (at your option) any later version. 011 * 012 * This program is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 015 * GNU General Public License for more details. 016 * 017 * You should have received a copy of the GNU General Public License 018 * along with this program; if not, write to the Free Software 019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 020 */ 021package se.sics.kompics.network; 022 023import java.net.InetAddress; 024import java.net.InetSocketAddress; 025 026/** 027 * 028 * @author Lars Kroll {@literal <[email protected]>} 029 */ 030public interface Address { 031 /** 032 * 033 * @return the IP address part of this object 034 */ 035 public InetAddress getIp(); 036 037 /** 038 * 039 * @return the port part of this object 040 */ 041 public int getPort(); 042 043 /** 044 * Get this address as InetSocketAddress. 045 * 046 * This is used for lookups within network implementation, so it better be fast. Preferably no new object creation 047 * should happen as part of this call. 048 * 049 * @return ip+port of this address. 050 */ 051 public InetSocketAddress asSocket(); 052 053 /** 054 * Compares only the ip+port part of the address for equality. 055 * 056 * This is used to decide whether or not to reflect messages back up without serialising. 057 * 058 * Most likely the same as "this.asSocket().equals(other.asSocket())". 059 * 060 * @param other 061 * the addess to compare to 062 * @return {@literal true}, if {@code other} is on the same port as {@code this} 063 */ 064 public boolean sameHostAs(Address other); 065}