1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 package org.apache.mina.transport.vmpipe; 21 22 import java.net.SocketAddress; 23 24 /** 25 * A {@link SocketAddress} which represents in-VM pipe port number. 26 * 27 * @author <a href="http://mina.apache.org">Apache MINA Project</a> 28 */ 29 public class VmPipeAddress extends SocketAddress implements Comparable<VmPipeAddress> { 30 private static final long serialVersionUID = 3257844376976830515L; 31 32 private final int port; 33 34 /** 35 * Creates a new instance with the specifid port number. 36 * 37 * @param port the port to use 38 */ 39 public VmPipeAddress(int port) { 40 this.port = port; 41 } 42 43 /** 44 * @return the port number. 45 */ 46 public int getPort() { 47 return port; 48 } 49 50 /** 51 * {@inheritDoc} 52 */ 53 @Override 54 public int hashCode() { 55 return port; 56 } 57 58 /** 59 * {@inheritDoc} 60 */ 61 @Override 62 public boolean equals(Object o) { 63 if (this == o) { 64 return true; 65 } 66 67 if (o instanceof VmPipeAddress) { 68 VmPipeAddress/../../../org/apache/mina/transport/vmpipe/VmPipeAddress.html#VmPipeAddress">VmPipeAddress that = (VmPipeAddress) o; 69 return this.port == that.port; 70 } 71 72 return false; 73 } 74 75 /** 76 * {@inheritDoc} 77 */ 78 public int compareTo(VmPipeAddress o) { 79 return this.port - o.port; 80 } 81 82 /** 83 * {@inheritDoc} 84 */ 85 @Override 86 public String toString() { 87 if (port >= 0) { 88 return "vm:server:" + port; 89 } 90 91 return "vm:client:" + -port; 92 } 93 }