| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package net.sf.arestc.configuration; |
| 21 |
|
|
| 22 |
|
import java.io.IOException; |
| 23 |
|
import java.io.ObjectInputStream; |
| 24 |
|
import java.io.ObjectOutputStream; |
| 25 |
|
import java.io.Serializable; |
| 26 |
|
|
| 27 |
|
import org.apache.commons.configuration.ConfigurationException; |
| 28 |
|
import org.apache.commons.httpclient.HttpClient; |
| 29 |
|
import org.apache.commons.httpclient.HttpConnectionManager; |
| 30 |
|
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; |
| 31 |
|
import org.apache.commons.httpclient.SimpleHttpConnectionManager; |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
@author |
| 38 |
|
|
|
|
|
| 60% |
Uncovered Elements: 24 (60) |
Complexity: 16 |
Complexity Density: 0.43 |
|
| 39 |
|
public final class CommunicationFactory implements Serializable { |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
private static final long serialVersionUID = 1L; |
| 43 |
|
|
| 44 |
|
|
| 45 |
|
private static final CommunicationFactory FACTORY = new CommunicationFactory(); |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
@return |
| 51 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 52 |
20
|
public static CommunicationFactory getInstance() {... |
| 53 |
20
|
return FACTORY; |
| 54 |
|
} |
| 55 |
|
|
| 56 |
|
|
| 57 |
|
private transient boolean configured = false; |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
private transient HttpClient client; |
| 61 |
|
|
| 62 |
|
|
| 63 |
|
private transient HttpConnectionManager manager; |
| 64 |
|
|
| 65 |
|
|
| 66 |
|
private boolean multithreaded; |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 71 |
1
|
private CommunicationFactory() {... |
| 72 |
1
|
configured = false; |
| 73 |
1
|
client = null; |
| 74 |
1
|
multithreaded = false; |
| 75 |
|
} |
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
@param |
| 81 |
|
|
| 82 |
|
@return |
| 83 |
|
@throws |
| 84 |
|
|
| 85 |
|
|
|
|
|
| 77.8% |
Uncovered Elements: 4 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
|
| 86 |
13
|
public HttpClient configureClient(final boolean localThreadSceme)... |
| 87 |
|
throws ConfigurationException { |
| 88 |
13
|
if (null == client) { |
| 89 |
2
|
multithreaded = localThreadSceme; |
| 90 |
2
|
if (multithreaded) { |
| 91 |
2
|
manager = new MultiThreadedHttpConnectionManager(); |
| 92 |
|
} else { |
| 93 |
0
|
manager = new SimpleHttpConnectionManager(); |
| 94 |
|
} |
| 95 |
2
|
client = new HttpClient(manager); |
| 96 |
2
|
synchronized (this) { |
| 97 |
|
|
| 98 |
|
|
| 99 |
2
|
ClientConfigurationFactory.getInstance().configure(client); |
| 100 |
|
} |
| 101 |
|
|
| 102 |
2
|
configured = true; |
| 103 |
|
} else { |
| 104 |
|
|
| 105 |
|
|
| 106 |
|
|
| 107 |
11
|
if (localThreadSceme != multithreaded) { |
| 108 |
0
|
throw new ConfigurationException(); |
| 109 |
|
} |
| 110 |
|
} |
| 111 |
13
|
return client; |
| 112 |
|
} |
| 113 |
|
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
|
| 114 |
0
|
public HttpClient configureClient(final boolean localThreadSceme,... |
| 115 |
|
final String configFileName) throws ConfigurationException { |
| 116 |
0
|
if (null == client) { |
| 117 |
0
|
multithreaded = localThreadSceme; |
| 118 |
0
|
if (multithreaded) { |
| 119 |
0
|
manager = new MultiThreadedHttpConnectionManager(); |
| 120 |
|
} else { |
| 121 |
0
|
manager = new SimpleHttpConnectionManager(); |
| 122 |
|
} |
| 123 |
0
|
client = new HttpClient(manager); |
| 124 |
0
|
synchronized (this) { |
| 125 |
|
|
| 126 |
|
|
| 127 |
0
|
ClientConfigurationFactory.getInstance().configure(client, |
| 128 |
|
configFileName); |
| 129 |
|
} |
| 130 |
|
|
| 131 |
0
|
configured = true; |
| 132 |
|
} else { |
| 133 |
|
|
| 134 |
|
|
| 135 |
|
|
| 136 |
0
|
if (localThreadSceme != multithreaded) { |
| 137 |
0
|
throw new ConfigurationException(); |
| 138 |
|
} |
| 139 |
|
} |
| 140 |
0
|
return client; |
| 141 |
|
} |
| 142 |
|
|
| 143 |
|
|
| 144 |
|
|
| 145 |
|
|
| 146 |
|
@return |
| 147 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 148 |
1
|
public boolean isConfigured() {... |
| 149 |
1
|
return configured; |
| 150 |
|
} |
| 151 |
|
|
| 152 |
|
|
| 153 |
|
|
| 154 |
|
|
| 155 |
|
@return |
| 156 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 157 |
3
|
public boolean isMultiThreaded() {... |
| 158 |
3
|
return multithreaded; |
| 159 |
|
} |
| 160 |
|
|
| 161 |
|
|
| 162 |
|
|
| 163 |
|
|
| 164 |
|
@param |
| 165 |
|
|
| 166 |
|
@throws |
| 167 |
|
|
| 168 |
|
@throws |
| 169 |
|
|
| 170 |
|
@throws |
| 171 |
|
|
| 172 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 173 |
1
|
private void readObject(final ObjectInputStream aInputStream)... |
| 174 |
|
throws ClassNotFoundException, IOException, ConfigurationException { |
| 175 |
|
|
| 176 |
1
|
aInputStream.defaultReadObject(); |
| 177 |
|
|
| 178 |
|
|
| 179 |
1
|
configureClient(multithreaded); |
| 180 |
|
} |
| 181 |
|
|
| 182 |
|
|
| 183 |
|
|
| 184 |
|
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 185 |
4
|
public void shutdown() {... |
| 186 |
4
|
synchronized (this) { |
| 187 |
4
|
if (multithreaded) { |
| 188 |
4
|
MultiThreadedHttpConnectionManager.shutdownAll(); |
| 189 |
|
} |
| 190 |
4
|
client = null; |
| 191 |
|
} |
| 192 |
|
} |
| 193 |
|
|
| 194 |
|
|
| 195 |
|
|
| 196 |
|
|
| 197 |
|
@param |
| 198 |
|
|
| 199 |
|
@throws |
| 200 |
|
|
| 201 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 202 |
1
|
private void writeObject(final ObjectOutputStream aOutputStream)... |
| 203 |
|
throws IOException { |
| 204 |
|
|
| 205 |
|
|
| 206 |
1
|
aOutputStream.defaultWriteObject(); |
| 207 |
|
} |
| 208 |
|
|
| 209 |
|
} |