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 The Apache MINA Project (dev@mina.apache.org)
28   * @version $Rev: 576217 $, $Date: 2007-09-17 01:55:27 +0200 (lun, 17 sep 2007) $
29   */
30  public class VmPipeAddress extends SocketAddress implements Comparable<VmPipeAddress> {
31      private static final long serialVersionUID = 3257844376976830515L;
32  
33      private final int port;
34  
35      /**
36       * Creates a new instance with the specifid port number.
37       */
38      public VmPipeAddress(int port) {
39          this.port = port;
40      }
41  
42      /**
43       * Returns the port number.
44       */
45      public int getPort() {
46          return port;
47      }
48  
49      @Override
50      public int hashCode() {
51          return port;
52      }
53  
54      @Override
55      public boolean equals(Object o) {
56          if (o == null) {
57              return false;
58          }
59          if (this == o) {
60              return true;
61          }
62          if (o instanceof VmPipeAddress) {
63              VmPipeAddress that = (VmPipeAddress) o;
64              return this.port == that.port;
65          }
66  
67          return false;
68      }
69  
70      public int compareTo(VmPipeAddress o) {
71          return this.port - o.port;
72      }
73  
74      @Override
75      public String toString() {
76          if (port >= 0) {
77              return "vm:server:" + port;
78          } else {
79              return "vm:client:" + -port;
80          }
81      }
82  }