KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xsocket > datagram > Endpoint


1 // $Id: Endpoint.java 1546 2007-07-23 06:07:56Z grro $
2
/*
3  * Copyright (c) xsocket.org, 2006 - 2007. All rights reserved.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Please refer to the LGPL license at: http://www.gnu.org/copyleft/lesser.txt
20  * The latest copy of this software may be found on http://www.xsocket.org/
21  */

22 package org.xsocket.datagram;
23
24 import java.io.IOException JavaDoc;
25 import java.net.InetAddress JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.concurrent.Executor JavaDoc;
29
30
31
32
33 /**
34  * Endpoint implementation
35  *
36  * @author grro@xsocket.org
37  */

38 public final class Endpoint extends AbstractChannelBasedEndpoint implements IEndpoint {
39     
40
41     /**
42      * Constructs a datagram socket and binds it to any
43      * available port on the local host machine. The socket
44      * will be bound to the wildcard address, an IP address
45      * chosen by the kernel.
46      *
47      * @throws IOException If some I/O error occurs
48      */

49     public Endpoint() throws IOException JavaDoc {
50         this(0);
51     }
52     
53     
54
55     /**
56      * Constructs a datagram socket and binds it to any
57      * available port on the local host machine. The socket
58      * will be bound to the wildcard address, an IP address
59      * chosen by the kernel.
60      *
61      * @param receivePacketSize the receive packet size
62      * @throws IOException If some I/O error occurs
63      */

64     public Endpoint(int receivePacketSize) throws IOException JavaDoc {
65         this(receivePacketSize, null);
66     }
67
68     
69
70     /**
71      * @deprecated
72      */

73     public Endpoint(DatagramSocketConfiguration socketConfiguration, int receivePacketSize) throws IOException JavaDoc {
74         this(socketConfiguration, receivePacketSize, null, InetAddress.getLocalHost(), 0);
75     }
76
77
78     
79     /**
80      * Constructs a datagram socket and binds it to any
81      * available port on the local host machine. The socket
82      * will be bound to the wildcard address, an IP address
83      * chosen by the kernel.
84      *
85      * @param receivePacketSize the receive packet size
86      * @param datagramHandler the datagram handler
87      * @throws IOException If some I/O error occurs
88      */

89     public Endpoint(int receivePacketSize, IDatagramHandler datagramHandler) throws IOException JavaDoc {
90         this(new DatagramSocketConfiguration(), receivePacketSize, datagramHandler, InetAddress.getLocalHost(), 0);
91     }
92     
93     /**
94      * Constructs a datagram socket and binds it to any
95      * available port on the local host machine. The socket
96      * will be bound to the wildcard address, an IP address
97      * chosen by the kernel.
98      *
99      * @param receivePacketSize the receive packet size
100      * @param datagramHandler the datagram handler
101      * @param workerPool the workerPool
102      * @throws IOException If some I/O error occurs
103      */

104     public Endpoint(int receivePacketSize, IDatagramHandler datagramHandler, Executor JavaDoc workerPool) throws IOException JavaDoc {
105         this(new HashMap JavaDoc<String JavaDoc, Object JavaDoc>(), receivePacketSize, datagramHandler, workerPool, InetAddress.getLocalHost(), 0);
106     }
107     
108     
109     /**
110      * @deprecated
111      */

112     public Endpoint(DatagramSocketConfiguration socketConfiguration, int receivePacketSize, IDatagramHandler datagramHandler) throws IOException JavaDoc {
113         this(socketConfiguration, receivePacketSize, datagramHandler, InetAddress.getLocalHost(), 0);
114     }
115     
116     
117     
118     
119     /**
120      * Constructs a datagram socket and binds it to the given
121      * port on the local host machine. The socket
122      * will be bound to the wildcard address, an IP address
123      * chosen by the kernel.
124      *
125      * @param receivePacketSize the receive packet size
126      * @param datagramHandler the datagram handler
127      * @param address the local address
128      * @param port the local port which must be between 0 and 65535 inclusive.
129      * @throws IOException If some I/O error occurs
130      */

131     public Endpoint(int receivePacketSize, IDatagramHandler datagramHandler, InetAddress JavaDoc address, int port) throws IOException JavaDoc {
132         this(null, receivePacketSize, datagramHandler, address, port);
133     }
134
135     
136     /**
137      * @deprecated
138      */

139     public Endpoint(DatagramSocketConfiguration socketConfiguration, int receivePacketSize, IDatagramHandler datagramHandler, InetAddress JavaDoc address, int port) throws IOException JavaDoc {
140         this(socketConfiguration, receivePacketSize, datagramHandler, getGlobalWorkerPool(), address, port);
141     }
142
143     
144     
145     /**
146      * @deprecated
147      */

148     public Endpoint(DatagramSocketConfiguration socketConfiguration, int receivePacketSize, IDatagramHandler datagramHandler, Executor JavaDoc workerPool, InetAddress JavaDoc address, int port) throws IOException JavaDoc {
149         this(socketConfiguration.toOptions(), receivePacketSize, datagramHandler, workerPool, address, port);
150     }
151     
152     /**
153      * Constructs a datagram socket and binds it to the given
154      * port on the local host machine. The socket
155      * will be bound to the wildcard address, an IP address
156      * chosen by the kernel.
157      *
158      * @param options the socket options
159      * @param receivePacketSize the receive packet size
160      * @param datagramHandler the datagram handler
161      * @param address the local address
162      * @param port the local port which must be between 0 and 65535 inclusive.
163      * @param workerPool the workerPool
164      * @throws IOException If some I/O error occurs
165      */

166     public Endpoint(Map JavaDoc<String JavaDoc, Object JavaDoc> options, int receivePacketSize, IDatagramHandler datagramHandler, Executor JavaDoc workerPool, InetAddress JavaDoc address, int port) throws IOException JavaDoc {
167         super(address, port, options, datagramHandler, receivePacketSize, workerPool);
168     }
169
170     
171     /**
172      * Constructs a datagram socket and binds it to the given
173      * port on the local host machine. The socket
174      * will be bound to the wildcard address, an IP address
175      * chosen by the kernel.
176      *
177      * @param receivePacketSize the receive packet size
178      * @param datagramHandler the datagram handler
179      * @param address the local address
180      * @param port the local port which must be between 0 and 65535 inclusive.
181      * @param workerPool the workerPool
182      * @throws IOException If some I/O error occurs
183      */

184     public Endpoint(int receivePacketSize, IDatagramHandler datagramHandler, Executor JavaDoc workerPool, InetAddress JavaDoc address, int port) throws IOException JavaDoc {
185         super(address, port, new HashMap JavaDoc<String JavaDoc, Object JavaDoc>(), datagramHandler, receivePacketSize, workerPool);
186     }
187     
188     /**
189      * {@inheritDoc}
190      */

191     protected Endpoint setOption(String JavaDoc name, Object JavaDoc value) throws IOException JavaDoc {
192         return (Endpoint) super.setOption(name, value);
193     }
194 }
195
Popular Tags