01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
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-16 17:55:27 -0600 (Sun, 16 Sep 2007) $
29: */
30: public class VmPipeAddress extends SocketAddress implements
31: Comparable<VmPipeAddress> {
32: private static final long serialVersionUID = 3257844376976830515L;
33:
34: private final int port;
35:
36: /**
37: * Creates a new instance with the specifid port number.
38: */
39: public VmPipeAddress(int port) {
40: this .port = port;
41: }
42:
43: /**
44: * Returns the port number.
45: */
46: public int getPort() {
47: return port;
48: }
49:
50: @Override
51: public int hashCode() {
52: return port;
53: }
54:
55: @Override
56: public boolean equals(Object o) {
57: if (o == null) {
58: return false;
59: }
60: if (this == o) {
61: return true;
62: }
63: if (o instanceof VmPipeAddress) {
64: VmPipeAddress that = (VmPipeAddress) o;
65: return this .port == that.port;
66: }
67:
68: return false;
69: }
70:
71: public int compareTo(VmPipeAddress o) {
72: return this .port - o.port;
73: }
74:
75: @Override
76: public String toString() {
77: if (port >= 0) {
78: return "vm:server:" + port;
79: } else {
80: return "vm:client:" + -port;
81: }
82: }
83: }
|