Skip to content

Commit 2e51fe0

Browse files
committed
Remove Warnings, add documentations
1 parent 29cbb6a commit 2e51fe0

3 files changed

Lines changed: 102 additions & 23 deletions

File tree

‎src/io/socket/IOCallback.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,24 @@ public interface IOCallback {
2929
* On message. Called when the server sends String data.
3030
*
3131
* @param data the data.
32+
* @param ack an {@link IOAcknowledge} instance, may be <code>null</code> if there's none
3233
*/
3334
void onMessage(String data, IOAcknowledge ack);
3435

3536
/**
3637
* On message. Called when the server sends JSON data.
3738
*
3839
* @param json JSON object sent by server.
40+
* @param ack an {@link IOAcknowledge} instance, may be <code>null</code> if there's none
3941
*/
4042
void onMessage(JSONObject json, IOAcknowledge ack);
4143

4244
/**
4345
* On [Event]. Called when server emits an event.
4446
*
4547
* @param event Name of the event
46-
* @param args arguments of the event
48+
* @param ack an {@link IOAcknowledge} instance, may be <code>null</code> if there's none
49+
* @param args Arguments of the event
4750
*/
4851
void on(String event, IOAcknowledge ack, Object... args);
4952

‎src/io/socket/IOConnection.java‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.net.URLConnection;
1919
import java.util.Arrays;
2020
import java.util.HashMap;
21-
import java.util.LinkedList;
2221
import java.util.List;
2322
import java.util.Scanner;
2423
import java.util.Timer;
@@ -49,9 +48,6 @@ public class IOConnection {
4948
/** The Constant STATE_INTERRUPTED. */
5049
private static final int STATE_INTERRUPTED = 4;
5150

52-
/** The Constant STATE_DISCONNECTING. */
53-
private static final int STATE_DISCONNECTING = 5;
54-
5551
/** The Constant STATE_INVALID. */
5652
private static final int STATE_INVALID = 6;
5753

@@ -274,7 +270,7 @@ else if (protocols.contains(XhrTransport.TRANSPORT_NAME))
274270
*
275271
* @param message
276272
* the message
277-
* @return a ne {@link IOAcknowledge} instance
273+
* @return an {@link IOAcknowledge} instance, may be <code>null</code> if server doesn't request one.
278274
*/
279275
private IOAcknowledge remoteAcknowledge(IOMessage message) {
280276
if (message.getId().endsWith("+") == false)
@@ -587,7 +583,7 @@ public void transportMessage(String text) {
587583
String eventName = event.getString("name");
588584
try {
589585
findCallback(message).on(eventName,
590-
remoteAcknowledge(message), argsArray);
586+
remoteAcknowledge(message), (Object[])argsArray);
591587
} catch (Exception e) {
592588
error(new SocketIOException(
593589
"Exception was thrown in on(String, JSONObject[])"

‎src/io/socket/transports/XhrTransport.java‎

Lines changed: 96 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*
2+
* socket.io-java-client XhrTransport.java
3+
*
4+
* Copyright (c) 2012, Enno Boland
5+
* PROJECT DESCRIPTION
6+
*
7+
* See LICENSE file for more information
8+
*/
19
package io.socket.transports;
210

311
import java.io.BufferedReader;
@@ -13,22 +21,47 @@
1321
import io.socket.IOConnection;
1422
import io.socket.IOTransport;
1523

24+
/**
25+
* The Class XhrTransport.
26+
*/
1627
public class XhrTransport implements IOTransport {
17-
/** The String to identify this Transport */
28+
29+
/** The String to identify this Transport. */
1830
public static final String TRANSPORT_NAME = "xhr-polling";
31+
32+
/** The connection. */
1933
private IOConnection connection;
34+
35+
/** The url. */
2036
private URL url;
37+
38+
/** The queue holding elements to send. */
2139
ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<String>();
2240

23-
ReceiverThread receiver = null;
41+
/** background thread for managing the server connection. */
42+
PollThread pollThread = null;
43+
44+
/** Indicates whether the {@link IOConnection} wants us to be connected. */
2445
private boolean connect;
46+
47+
/** Indicates whether {@link PollThread} is blocked. */
2548
private boolean blocked;
2649

27-
private class ReceiverThread extends Thread {
28-
public ReceiverThread() {
50+
/**
51+
* The Class ReceiverThread.
52+
*/
53+
private class PollThread extends Thread {
54+
55+
/**
56+
* Instantiates a new receiver thread.
57+
*/
58+
public PollThread() {
2959
super(TRANSPORT_NAME);
3060
}
3161

62+
/* (non-Javadoc)
63+
* @see java.lang.Thread#run()
64+
*/
3265
@Override
3366
public void run() {
3467
connection.transportConnected();
@@ -69,6 +102,13 @@ public void run() {
69102
}
70103
}
71104

105+
/**
106+
* Creates a new Transport for the given url an {@link IOConnection}.
107+
*
108+
* @param url the url
109+
* @param connection the connection
110+
* @return the iO transport
111+
*/
72112
public static IOTransport create(URL url, IOConnection connection) {
73113
try {
74114
URL xhrUrl = new URL(url.toString() + IOConnection.SOCKET_IO_1
@@ -82,65 +122,105 @@ public static IOTransport create(URL url, IOConnection connection) {
82122

83123
}
84124

125+
/**
126+
* Instantiates a new xhr transport.
127+
*
128+
* @param url the url
129+
* @param connection the connection
130+
*/
85131
public XhrTransport(URL url, IOConnection connection) {
86132
this.connection = connection;
87133
this.url = url;
88134
}
89135

136+
/* (non-Javadoc)
137+
* @see io.socket.IOTransport#connect()
138+
*/
90139
@Override
91140
public void connect() {
92141
this.setConnect(true);
93-
if (receiver == null) {
94-
receiver = new ReceiverThread();
95-
receiver.start();
96-
} else
97-
new RuntimeException(
98-
"connecting on an allready connected transport");
142+
pollThread = new PollThread();
143+
pollThread.start();
99144
}
100145

146+
/* (non-Javadoc)
147+
* @see io.socket.IOTransport#disconnect()
148+
*/
101149
@Override
102150
public void disconnect() {
103151
this.setConnect(false);
104-
receiver.interrupt();
152+
pollThread.interrupt();
105153
}
106154

155+
/* (non-Javadoc)
156+
* @see io.socket.IOTransport#send(java.lang.String)
157+
*/
107158
@Override
108159
public void send(String text) throws IOException {
109160
sendBulk(new String[] { text });
110161
}
111162

163+
/* (non-Javadoc)
164+
* @see io.socket.IOTransport#canSendBulk()
165+
*/
112166
@Override
113167
public boolean canSendBulk() {
114168
return true;
115169
}
116170

171+
/* (non-Javadoc)
172+
* @see io.socket.IOTransport#sendBulk(java.lang.String[])
173+
*/
117174
@Override
118175
public void sendBulk(String[] texts) throws IOException {
119176
for (String text : texts) {
120177
queue.add(text);
121178
}
122179
if(isBlocked())
123-
receiver.interrupt();
180+
pollThread.interrupt();
124181
}
125182

183+
/* (non-Javadoc)
184+
* @see io.socket.IOTransport#invalidate()
185+
*/
126186
@Override
127187
public void invalidate() {
128188
this.connection = null;
129189
}
130190

131-
public synchronized boolean isConnect() {
191+
/**
192+
* Checks if is connect.
193+
*
194+
* @return true, if is connect
195+
*/
196+
private synchronized boolean isConnect() {
132197
return connect;
133198
}
134199

135-
public synchronized void setConnect(boolean connect) {
200+
/**
201+
* Sets the connect.
202+
*
203+
* @param connect the new connect
204+
*/
205+
private synchronized void setConnect(boolean connect) {
136206
this.connect = connect;
137207
}
138208

139-
public synchronized boolean isBlocked() {
209+
/**
210+
* Checks if is blocked.
211+
*
212+
* @return true, if is blocked
213+
*/
214+
private synchronized boolean isBlocked() {
140215
return blocked;
141216
}
142217

143-
public synchronized void setBlocked(boolean blocked) {
218+
/**
219+
* Sets the blocked.
220+
*
221+
* @param blocked the new blocked
222+
*/
223+
private synchronized void setBlocked(boolean blocked) {
144224
this.blocked = blocked;
145225
}
146226
}

0 commit comments

Comments
 (0)