~ubuntu-branches/ubuntu/precise/jcsp/precise

« back to all changes in this revision

Viewing changes to src/org/jcsp/net2/tcpip/TCPIPNodeAddress.java

  • Committer: Bazaar Package Importer
  • Author(s): Miguel Landaeta
  • Date: 2010-06-20 18:12:26 UTC
  • Revision ID: james.westby@ubuntu.com-20100620181226-8yg8d9rjjjiuy7oz
Tags: upstream-1.1-rc4
ImportĀ upstreamĀ versionĀ 1.1-rc4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.jcsp.net2.tcpip;
 
2
 
 
3
import org.jcsp.net2.JCSPNetworkException;
 
4
import org.jcsp.net2.Link;
 
5
import org.jcsp.net2.LinkServer;
 
6
import org.jcsp.net2.NodeAddress;
 
7
import org.jcsp.net2.ProtocolID;
 
8
 
 
9
/**
 
10
 * A concrete implementation of a NodeAddress that is designed for TCP/IP connections.
 
11
 * 
 
12
 * @see NodeAddress
 
13
 * @author Kevin Chalmers
 
14
 */
 
15
public final class TCPIPNodeAddress
 
16
    extends NodeAddress
 
17
{
 
18
    /**
 
19
     * The SUID for this class
 
20
     */
 
21
    private static final long serialVersionUID = 1L;
 
22
 
 
23
    /**
 
24
     * The IP address part of the address
 
25
     */
 
26
    private String ip;
 
27
 
 
28
    /**
 
29
     * The port part of the address
 
30
     */
 
31
    private int port;
 
32
 
 
33
    /**
 
34
     * Creates a new TCPIPNodeAddress from an IP address and port
 
35
     * 
 
36
     * @param ipAddress
 
37
     *            The IP address part of the NodeAddress
 
38
     * @param portNumber
 
39
     *            The port number part of the NodeAddress
 
40
     */
 
41
    public TCPIPNodeAddress(String ipAddress, int portNumber)
 
42
    {
 
43
        this.ip = ipAddress;
 
44
        this.port = portNumber;
 
45
        this.protocol = "tcpip";
 
46
        this.address = ipAddress + ":" + portNumber;
 
47
    }
 
48
 
 
49
    /**
 
50
     * Creates a new TCPIPNodeAddress using the local IP address and a given port number. Allows a
 
51
     * 
 
52
     * @param portNumber
 
53
     *            The port number to use
 
54
     */
 
55
    public TCPIPNodeAddress(int portNumber)
 
56
    {
 
57
        this.port = portNumber;
 
58
        this.ip = "";
 
59
        this.protocol = "tcpip";
 
60
    }
 
61
 
 
62
    /**
 
63
     * Creates a new TCPIPNodeAddress
 
64
     */
 
65
    public TCPIPNodeAddress()
 
66
    {
 
67
        this.port = 0;
 
68
        this.ip = "";
 
69
        this.protocol = "tcpip";
 
70
    }
 
71
 
 
72
    /**
 
73
     * Gets the port number part of this address
 
74
     * 
 
75
     * @return The port number part of the address
 
76
     */
 
77
    public final int getPort()
 
78
    {
 
79
        return this.port;
 
80
    }
 
81
 
 
82
    /**
 
83
     * Sets the port part of the address. Used internally in JCSP
 
84
     * 
 
85
     * @param portNumber
 
86
     *            The port number to use
 
87
     */
 
88
    void setPort(int portNumber)
 
89
    {
 
90
        this.port = portNumber;
 
91
    }
 
92
 
 
93
    /**
 
94
     * Gets the IP address part of the address
 
95
     * 
 
96
     * @return The IP Address part of the address
 
97
     */
 
98
    public final String getIpAddress()
 
99
    {
 
100
        return this.ip;
 
101
    }
 
102
 
 
103
    /**
 
104
     * Sets the IP address part of the NodeAddress. Used internally in JCSP
 
105
     * 
 
106
     * @param ipAddr
 
107
     *            The IP address to use
 
108
     */
 
109
    void setIpAddress(String ipAddr)
 
110
    {
 
111
        this.ip = ipAddr;
 
112
    }
 
113
 
 
114
    /**
 
115
     * Sets the address String. Used internally within JCSP
 
116
     * 
 
117
     * @param str
 
118
     *            The String to set as the address
 
119
     */
 
120
    void setAddress(String str)
 
121
    {
 
122
        this.address = str;
 
123
    }
 
124
 
 
125
    /**
 
126
     * Creates a new TCPIPLink connected to a Node with this address
 
127
     * 
 
128
     * @return A new TCPIPLink connected to this address
 
129
     * @throws JCSPNetworkException
 
130
     *             Thrown if something goes wrong during the creation of the Link
 
131
     */
 
132
    protected Link createLink()
 
133
        throws JCSPNetworkException
 
134
    {
 
135
        return new TCPIPLink(this);
 
136
    }
 
137
 
 
138
    /**
 
139
     * Creates a new TCPIPLinkServer listening on this address
 
140
     * 
 
141
     * @return A new TCPIPLinkServer listening on this address
 
142
     * @throws JCSPNetworkException
 
143
     *             Thrown if something goes wrong during the creation of the LinkServer
 
144
     */
 
145
    protected LinkServer createLinkServer()
 
146
        throws JCSPNetworkException
 
147
    {
 
148
        return new TCPIPLinkServer(this);
 
149
    }
 
150
 
 
151
    /**
 
152
     * Returns the TCPIPProtocolID
 
153
     * 
 
154
     * @return TCPIPProtocolID
 
155
     */
 
156
    protected ProtocolID getProtocolID()
 
157
    {
 
158
        return TCPIPProtocolID.getInstance();
 
159
    }
 
160
 
 
161
}