Skip to content

Commit 593adcd

Browse files
committed
Merge with 7edc0a6f719d64025b6446921e2de87564278f58
2 parents ee0e5f1 + 35032a8 commit 593adcd

File tree

6 files changed

+39
-80
lines changed

6 files changed

+39
-80
lines changed

.classpath

+2-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@
44
<classpathentry kind="src" path="examples"/>
55
<classpathentry kind="src" path="tests"/>
66
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
7-
<classpathentry exported="true" kind="lib" path="lib/json-org.jar">
8-
<attributes>
9-
<attribute name="javadoc_location" value="http://www.json.org/javadoc/"/>
10-
</attributes>
11-
</classpathentry>
127
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
13-
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/weberknecht"/>
8+
<classpathentry kind="lib" path="libs/weberknecht-0.1.1.jar"/>
9+
<classpathentry kind="lib" path="libs/json-org.jar"/>
1410
<classpathentry kind="output" path="bin"/>
1511
</classpath>
File renamed without changes.

libs/weberknecht-0.1.1.jar

10.6 KB
Binary file not shown.

src/io/socket/IOConnection.java

+37-57
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.TimerTask;
2626
import java.util.concurrent.ConcurrentLinkedQueue;
2727
import java.util.logging.Logger;
28-
2928
import javax.net.ssl.HttpsURLConnection;
3029
import javax.net.ssl.SSLSocketFactory;
3130

@@ -39,7 +38,7 @@
3938
class IOConnection implements IOCallback {
4039
/** Debug logger */
4140
static final Logger logger = Logger.getLogger("io.socket");
42-
41+
4342
public static final String FRAME_DELIMITER = "\ufffd";
4443

4544
/** The Constant STATE_INIT. */
@@ -67,8 +66,9 @@ class IOConnection implements IOCallback {
6766
public static final String SOCKET_IO_1 = "/socket.io/1/";
6867

6968
/** The SSL socket factory for HTTPS connections */
70-
private static SSLSocketFactory sslSocketFactory = (SSLSocketFactory)SSLSocketFactory.getDefault();
71-
69+
private static SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory
70+
.getDefault();
71+
7272
/** All available connections. */
7373
private static HashMap<String, List<IOConnection>> connections = new HashMap<String, List<IOConnection>>();
7474

@@ -177,23 +177,6 @@ public void run() {
177177
}
178178
}
179179
}
180-
181-
private IOReconnectScheduler reconnectScheduler = new IOReconnectScheduler() {
182-
183-
@Override
184-
public void scheduleReconnect(Timer timer, TimerTask task) {
185-
timer.schedule(task, 1000);
186-
}
187-
188-
@Override
189-
public void onReconnect() {
190-
}
191-
192-
};
193-
194-
public void setReconnectScheduler(IOReconnectScheduler scheduler) {
195-
reconnectScheduler = scheduler;
196-
}
197180

198181
/**
199182
* The Class ConnectThread. Handles connecting to the server with an
@@ -218,17 +201,17 @@ public void run() {
218201
connectTransport();
219202
}
220203

221-
222204
};
223205

224206
/**
225207
* Set the socket factory used for SSL connections.
208+
*
226209
* @param socketFactory
227210
*/
228211
public static void setDefaultSSLSocketFactory(SSLSocketFactory socketFactory) {
229212
sslSocketFactory = socketFactory;
230213
}
231-
214+
232215
/**
233216
* Creates a new connection or returns the corresponding one.
234217
*
@@ -286,7 +269,7 @@ public void unregister(SocketIO socket) {
286269
sendPlain("0::" + socket.getNamespace());
287270
sockets.remove(socket.getNamespace());
288271
socket.getCallback().onDisconnect();
289-
272+
290273
if (sockets.size() == 0) {
291274
cleanup();
292275
}
@@ -304,18 +287,19 @@ private void handshake() {
304287
setState(STATE_HANDSHAKE);
305288
url = new URL(IOConnection.this.url.toString() + SOCKET_IO_1);
306289
connection = url.openConnection();
307-
if(connection instanceof HttpsURLConnection) {
308-
((HttpsURLConnection)connection).setSSLSocketFactory(sslSocketFactory);
290+
if (connection instanceof HttpsURLConnection) {
291+
((HttpsURLConnection) connection)
292+
.setSSLSocketFactory(sslSocketFactory);
309293
}
310294
connection.setConnectTimeout(connectTimeout);
311295
connection.setReadTimeout(connectTimeout);
312-
296+
313297
/* Setting the request headers */
314298
for (Entry<Object, Object> entry : headers.entrySet()) {
315299
connection.setRequestProperty((String) entry.getKey(),
316300
(String) entry.getValue());
317301
}
318-
302+
319303
InputStream stream = connection.getInputStream();
320304
Scanner in = new Scanner(stream);
321305
response = in.nextLine();
@@ -432,7 +416,7 @@ private void cleanup() {
432416
sockets.clear();
433417
synchronized (connections) {
434418
List<IOConnection> con = connections.get(urlStr);
435-
if (con != null && con.size() > 1)
419+
if (con.size() > 1)
436420
con.remove(this);
437421
else
438422
connections.remove(urlStr);
@@ -504,15 +488,15 @@ private void resetTimeout() {
504488
* @param message
505489
* the message
506490
* @return the iO callback
507-
* @throws SocketIOException
491+
* @throws SocketIOException
508492
*/
509493
private IOCallback findCallback(IOMessage message) throws SocketIOException {
510-
if("".equals(message.getEndpoint()))
494+
if ("".equals(message.getEndpoint()))
511495
return this;
512496
SocketIO socket = sockets.get(message.getEndpoint());
513497
if (socket == null) {
514-
throw new SocketIOException("Cannot find socket for '" + message.getEndpoint()
515-
+ "'");
498+
throw new SocketIOException("Cannot find socket for '"
499+
+ message.getEndpoint() + "'");
516500
}
517501
return socket.getCallback();
518502
}
@@ -524,9 +508,7 @@ private IOCallback findCallback(IOMessage message) throws SocketIOException {
524508
*/
525509
public void transportConnected() {
526510
setState(STATE_READY);
527-
528-
boolean isReconnecting = (reconnectTask != null);
529-
if (isReconnecting) {
511+
if (reconnectTask != null) {
530512
reconnectTask.cancel();
531513
reconnectTask = null;
532514
}
@@ -554,11 +536,7 @@ public void transportConnected() {
554536
while ((text = outputBuffer.poll()) != null)
555537
sendPlain(text);
556538
}
557-
558539
this.keepAliveInQueue = false;
559-
if(isReconnecting) {
560-
reconnectScheduler.onReconnect();
561-
}
562540
}
563541
}
564542

@@ -587,28 +565,31 @@ public void transportError(Exception error) {
587565
}
588566

589567
/**
590-
* {@link IOTransport} should call this function if it does not support framing. If it does, transportMessage should be used
568+
* {@link IOTransport} should call this function if it does not support
569+
* framing. If it does, transportMessage should be used
591570
*
592571
* @param text
593572
* the text
594573
*/
595574
public void transportData(String text) {
596-
if(!text.startsWith(FRAME_DELIMITER)) {
575+
if (!text.startsWith(FRAME_DELIMITER)) {
597576
transportMessage(text);
598577
return;
599578
}
600-
601-
Iterator<String> fragments = Arrays.asList(text.split(FRAME_DELIMITER)).listIterator(1);
579+
580+
Iterator<String> fragments = Arrays.asList(text.split(FRAME_DELIMITER))
581+
.listIterator(1);
602582
while (fragments.hasNext()) {
603583
int length = Integer.parseInt(fragments.next());
604584
String string = (String) fragments.next();
605-
// Potential BUG: it is not defined if length is in bytes or characters. Assuming characters.
606-
607-
if(length != string.length()) {
585+
// Potential BUG: it is not defined if length is in bytes or
586+
// characters. Assuming characters.
587+
588+
if (length != string.length()) {
608589
error(new SocketIOException("Garbage from server: " + text));
609590
return;
610591
}
611-
592+
612593
transportMessage(string);
613594
}
614595
}
@@ -701,8 +682,7 @@ public void transportMessage(String text) {
701682
if (args.isNull(i) == false)
702683
argsArray[i] = args.get(i);
703684
}
704-
}
705-
else
685+
} else
706686
argsArray = new Object[0];
707687
String eventName = event.getString("name");
708688
try {
@@ -776,7 +756,7 @@ public void reconnect() {
776756
reconnectTask.cancel();
777757
}
778758
reconnectTask = new ReconnectTask();
779-
reconnectScheduler.scheduleReconnect(backgroundTimer, reconnectTask);
759+
backgroundTimer.schedule(reconnectTask, 1000);
780760
}
781761
}
782762
}
@@ -892,38 +872,38 @@ public IOTransport getTransport() {
892872
@Override
893873
public void onDisconnect() {
894874
SocketIO socket = sockets.get("");
895-
if(socket != null)
875+
if (socket != null)
896876
socket.getCallback().onConnect();
897877
}
898878

899879
@Override
900880
public void onConnect() {
901881
SocketIO socket = sockets.get("");
902-
if(socket != null)
882+
if (socket != null)
903883
socket.getCallback().onConnect();
904884
}
905885

906886
@Override
907887
public void onMessage(String data, IOAcknowledge ack) {
908-
for(SocketIO socket : sockets.values())
888+
for (SocketIO socket : sockets.values())
909889
socket.getCallback().onMessage(data, ack);
910890
}
911891

912892
@Override
913893
public void onMessage(JSONObject json, IOAcknowledge ack) {
914-
for(SocketIO socket : sockets.values())
894+
for (SocketIO socket : sockets.values())
915895
socket.getCallback().onMessage(json, ack);
916896
}
917897

918898
@Override
919899
public void on(String event, IOAcknowledge ack, Object... args) {
920-
for(SocketIO socket : sockets.values())
900+
for (SocketIO socket : sockets.values())
921901
socket.getCallback().on(event, ack, args);
922902
}
923903

924904
@Override
925905
public void onError(SocketIOException socketIOException) {
926-
for(SocketIO socket : sockets.values())
906+
for (SocketIO socket : sockets.values())
927907
socket.getCallback().onError(socketIOException);
928908
}
929909
}

src/io/socket/IOReconnectScheduler.java

-9
This file was deleted.

src/io/socket/SocketIO.java

-8
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,6 @@ public void reconnect() {
330330
this.connection.reconnect();
331331
}
332332

333-
/**
334-
* Set the reconnect scheduler. By default reconnects are attempted every
335-
* second.
336-
*/
337-
public void setReconnectScheduler(IOReconnectScheduler scheduler) {
338-
this.connection.setReconnectScheduler(scheduler);
339-
}
340-
341333
/**
342334
* Returns, if a connection is established at the moment
343335
*

0 commit comments

Comments
 (0)