View Javadoc
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      public VmPipeAddress(int port) {
38          this.port = port;
39      }
40  
41      /**
42       * Returns the port number.
43       */
44      public int getPort() {
45          return port;
46      }
47  
48      @Override
49      public int hashCode() {
50          return port;
51      }
52  
53      @Override
54      public boolean equals(Object o) {
55          if (o == null) {
56              return false;
57          }
58          if (this == o) {
59              return true;
60          }
61          if (o instanceof VmPipeAddress) {
62              VmPipeAddress that = (VmPipeAddress) o;
63              return this.port == that.port;
64          }
65  
66          return false;
67      }
68  
69      public int compareTo(VmPipeAddress o) {
70          return this.port - o.port;
71      }
72  
73      @Override
74      public String toString() {
75          if (port >= 0) {
76              return "vm:server:" + port;
77          }
78  
79          return "vm:client:" + -port;
80      }
81  }