|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
DatagramSocketSynchChannelFactory.java | 0% | 0% | 0% | 0% |
|
1 |
/**
|
|
2 |
*
|
|
3 |
* Copyright 2004 Hiram Chirino
|
|
4 |
*
|
|
5 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6 |
* you may not use this file except in compliance with the License.
|
|
7 |
* You may obtain a copy of the License at
|
|
8 |
*
|
|
9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10 |
*
|
|
11 |
* Unless required by applicable law or agreed to in writing, software
|
|
12 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14 |
* See the License for the specific language governing permissions and
|
|
15 |
* limitations under the License.
|
|
16 |
*
|
|
17 |
**/
|
|
18 |
package org.activeio.net;
|
|
19 |
|
|
20 |
import java.io.IOException;
|
|
21 |
import java.net.DatagramSocket;
|
|
22 |
import java.net.InetAddress;
|
|
23 |
import java.net.URI;
|
|
24 |
|
|
25 |
import org.activeio.SynchChannel;
|
|
26 |
import org.activeio.SynchChannelFactory;
|
|
27 |
import org.activeio.SynchChannelServer;
|
|
28 |
|
|
29 |
/**
|
|
30 |
* A TcpSynchChannelFactory creates {@see org.activeio.net.TcpSynchChannel}
|
|
31 |
* and {@see org.activeio.net.TcpSynchChannelServer} objects.
|
|
32 |
*
|
|
33 |
* @version $Revision$
|
|
34 |
*/
|
|
35 |
public class DatagramSocketSynchChannelFactory implements SynchChannelFactory { |
|
36 |
|
|
37 |
/**
|
|
38 |
* Uses the {@param location}'s host and port to create a tcp connection to a remote host.
|
|
39 |
*
|
|
40 |
* @see org.activeio.SynchChannelFactory#openSynchChannel(java.net.URI)
|
|
41 |
*/
|
|
42 | 0 |
public SynchChannel openSynchChannel(URI location) throws IOException { |
43 | 0 |
DatagramSocket socket=null;
|
44 | 0 |
socket = new DatagramSocket();
|
45 | 0 |
if( location != null ) { |
46 | 0 |
InetAddress address = InetAddress.getByName(location.getHost()); |
47 | 0 |
socket.connect(address, location.getPort()); |
48 |
} |
|
49 | 0 |
return createSynchChannel(socket);
|
50 |
} |
|
51 |
|
|
52 |
/**
|
|
53 |
* Uses the {@param location}'s host and port to create a tcp connection to a remote host.
|
|
54 |
*
|
|
55 |
*/
|
|
56 | 0 |
public SynchChannel openSynchChannel(URI location, URI localLocation) throws IOException { |
57 | 0 |
DatagramSocket socket=null;
|
58 | 0 |
InetAddress address = InetAddress.getByName(localLocation.getHost()); |
59 | 0 |
socket = new DatagramSocket(localLocation.getPort(), address);
|
60 |
|
|
61 | 0 |
if( location != null ) { |
62 | 0 |
address = InetAddress.getByName(location.getHost()); |
63 | 0 |
socket.connect(address, location.getPort()); |
64 |
} |
|
65 | 0 |
return createSynchChannel(socket);
|
66 |
} |
|
67 |
|
|
68 |
/**
|
|
69 |
* @param socket
|
|
70 |
* @return
|
|
71 |
* @throws IOException
|
|
72 |
*/
|
|
73 | 0 |
protected SynchChannel createSynchChannel(DatagramSocket socket) throws IOException { |
74 | 0 |
return new DatagramSocketSynchChannel(socket); |
75 |
} |
|
76 |
|
|
77 |
/**
|
|
78 |
* @throws IOException allways thrown.
|
|
79 |
* @see org.activeio.SynchChannelFactory#bindSynchChannel(java.net.URI)
|
|
80 |
*/
|
|
81 | 0 |
public SynchChannelServer bindSynchChannel(URI location) throws IOException { |
82 | 0 |
throw new IOException("A SynchChannelServer is not available for this channel."); |
83 |
} |
|
84 |
|
|
85 |
} |
|
86 |
|
|