Skip to content

Commit 3e95f1e

Browse files
committed
Add some docs and bump version.
1 parent 897f8b2 commit 3e95f1e

File tree

10 files changed

+74
-42
lines changed

10 files changed

+74
-42
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<packaging>jar</packaging>
88

99
<name>js-collider</name>
10-
<version>0.2.1</version>
10+
<version>0.2.2</version>
1111
<description>Java NIO framework</description>
1212
<url>https://github.com/js-labs/js-collider</url>
1313

src/main/java/org/jsl/collider/Acceptor.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121

2222
import java.net.InetSocketAddress;
2323

24+
/**
25+
* {@code Acceptor} is used to accepot inbound socket connections.
26+
* See {@link Collider} for details.
27+
*/
28+
2429
public abstract class Acceptor extends SessionEmitter
2530
{
2631
public Acceptor()
@@ -35,10 +40,10 @@ public Acceptor(InetSocketAddress addr)
3540

3641
/**
3742
* Called by the framework to create <tt>Session.Listener</tt> instance
38-
* to be linked with the session. METHOD IS NOT [MT] SAFE,
43+
* to be linked with the session and underlying socket. METHOD IS NOT [MT] SAFE,
3944
* can be executed concurrently in a number of threads.
4045
* Connection and underlying socket will be closed if returns <tt>null</tt>,
41-
* but any data scheduled with <tt>sendData</tt> call before return will be sent.
46+
* but any data scheduled with <tt>sendData</tt> still will be sent.
4247
*/
4348
public abstract Session.Listener createSessionListener(Session session);
4449

src/main/java/org/jsl/collider/Collider.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,27 +103,34 @@ public final Config getConfig()
103103
public abstract void stop();
104104

105105
/**
106-
* Adds an <tt>Acceptor</tt> to the collider.
106+
* Adds an <tt>Acceptor</tt> to the collider. User supposed to extend {@link Acceptor}
107+
* class with handlers to be called by the collider when it will be ready to accept
108+
* inbound socket connections and when new inbound socket connection appears.
107109
* Additionally to the server socket exceptions
108110
* throws an IOException in a case if collider already stopped.
111+
* @param acceptor The acceptor instance to add
112+
* @throws IOException if collider failed to create accepting socket or collider already stopped
109113
*/
110-
public abstract void addAcceptor( Acceptor acceptor ) throws IOException;
114+
public abstract void addAcceptor(Acceptor acceptor) throws IOException;
111115

112116
/**
113117
* Removes the <tt>Acceptor</tt> from the collider.
114-
* On return guarantees that no one thread runs
118+
* On return guarantees no one thread runs
115119
* <tt>Acceptor.onAcceptorStarted</tt> or <tt>Acceptor.createSessionListener</tt>.
120+
* @param acceptor The acceptor instance to remove
121+
* @throws InterruptedException if thread was interrupted on wait
116122
*/
117-
public abstract void removeAcceptor( Acceptor acceptor ) throws InterruptedException;
123+
public abstract void removeAcceptor(Acceptor acceptor) throws InterruptedException;
118124

119125
/**
120126
* Adds <tt>Connector</tt> to the collider.
121127
* Operation is asynchronous, socket operations can throw an exception,
122128
* Connector.onException will be called in this case in the collider thread pool,
123129
* better to handle it properly.
130+
* @param connector The connector instance to add
124131
*/
125-
public abstract void addConnector( Connector connector );
126-
public abstract void removeConnector( Connector connector ) throws InterruptedException;
132+
public abstract void addConnector(Connector connector);
133+
public abstract void removeConnector(Connector connector) throws InterruptedException;
127134

128135
public abstract void addDatagramListener(
129136
DatagramListener datagramListener ) throws IOException;
@@ -139,14 +146,16 @@ public abstract void removeDatagramListener(
139146

140147
/**
141148
* Create a Collider instance with default configuration.
149+
* @return a new collider instance
150+
* @throws IOException if selector I/O error occurs
142151
*/
143152
public static Collider create() throws IOException
144153
{
145-
return create( new Config() );
154+
return create(new Config());
146155
}
147156

148-
public static Collider create( Config config ) throws IOException
157+
public static Collider create(Config config) throws IOException
149158
{
150-
return new ColliderImpl( config );
159+
return new ColliderImpl(config);
151160
}
152161
}

src/main/java/org/jsl/collider/Connector.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
public abstract class Connector extends SessionEmitter
2626
{
27-
public Connector( InetSocketAddress addr )
27+
public Connector(InetSocketAddress addr)
2828
{
29-
super( addr );
29+
super(addr);
3030
}
3131

3232
/**
@@ -35,11 +35,12 @@ public Connector( InetSocketAddress addr )
3535
* Connection will be closed if returns <tt>null</tt>, but any data
3636
* scheduled with <tt>sendData</tt> call before return will be sent.
3737
*/
38-
public abstract Session.Listener createSessionListener( Session session );
38+
public abstract Session.Listener createSessionListener(Session session);
3939

4040
/**
4141
* Called by framework in a case if asynchronous operation
4242
* with underlying socket channel throws some exception.
43+
* @param ex An exception thrown by asynchronous I/O operation
4344
*/
44-
public abstract void onException( IOException ex );
45+
public abstract void onException(IOException ex);
4546
}

src/main/java/org/jsl/collider/DataBlock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import java.nio.ByteBuffer;
2323

24-
public class DataBlock
24+
class DataBlock
2525
{
2626
public DataBlock next;
2727
public final ByteBuffer wr;

src/main/java/org/jsl/collider/DataBlockCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import java.util.logging.Level;
2525
import java.util.logging.Logger;
2626

27-
public class DataBlockCache
27+
class DataBlockCache
2828
{
2929
private final boolean m_useDirectBuffers;
3030
private final int m_blockSize;

src/main/java/org/jsl/collider/MessageQueue.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,9 @@ public MessageQueue( DataBlockCache dataBlockCache )
218218
}
219219

220220
/**
221+
* @param msg the buffer to append
221222
* @return ByteBuffer instance to be processed (queue was empty),
222-
* or <null> if queue was not empty.
223+
* or {@code null} if queue was not empty.
223224
*/
224225
public final ByteBuffer putAndGet( ByteBuffer msg )
225226
{
@@ -265,7 +266,7 @@ public final ByteBuffer putAndGet( ByteBuffer msg )
265266

266267
/**
267268
* @return next data block to be processed,
268-
* or <null> if queue become empty.
269+
* or {@code null} if queue become empty.
269270
*/
270271
public final ByteBuffer getNext()
271272
{

src/main/java/org/jsl/collider/Session.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ public interface Listener
3131
* Executed serially in a one thread, but not necessary always the same.
3232
* Position in the byte buffer can be greater than 0,
3333
* limit can be less than capacity.
34+
* @param data the data received from the related socket
3435
*/
35-
public abstract void onDataReceived( RetainableByteBuffer data );
36+
public abstract void onDataReceived(RetainableByteBuffer data);
3637

3738
/**
3839
* Called by framework when underlying socket channel
@@ -42,17 +43,17 @@ public interface Listener
4243
}
4344

4445
/**
45-
* Returns Collider instance the session is linked with.
46+
* @return Collider instance the session is linked with.
4647
*/
4748
public Collider getCollider();
4849

4950
/**
50-
* Returns local socket address of the session.
51+
* @return local socket address of the session.
5152
*/
5253
public SocketAddress getLocalAddress();
5354

5455
/**
55-
* Returns remote socket address of the session.
56+
* @return remote socket address of the session.
5657
*/
5758
public SocketAddress getRemoteAddress();
5859

@@ -62,8 +63,9 @@ public interface Listener
6263
* (even it's attributes like a position, limit etc)
6364
* so the buffer can be reused to send the same data
6465
* to the different sessions.
65-
* @return >=0 - byte buffer is retained by the framework, will be sent as soon as possible
66-
* -1 - the session is closed
66+
* @param data byte buffer with data to send
67+
* @return value greater than 0 if byte buffer is retained by the framework,
68+
* (data will be sent as soon as possible), or less than 0 if the session is closed.
6769
*/
6870
public int sendData( ByteBuffer data );
6971
public int sendData( RetainableByteBuffer data );
@@ -72,9 +74,10 @@ public interface Listener
7274
* Method makes an attempt to write data synchronously to the underlying socket channel.
7375
* It can happen if it is the single thread calling the <em>sendData</em> or <em>sendDataSync</em>.
7476
* Otherwise data will sent as <em>sendData</em> would be called.
75-
* @return 0 - data written to socket, byte buffer can be reused
76-
* >0 - byte buffer is retained by the framework, will be sent as soon as possible
77-
* -1 - the session is closed
77+
* @param data byte buffer with data to send
78+
* @return 0 if data has been written to the socket and byte buffer can be reused,
79+
* greater than 0 if byte buffer is retained by the framework, will be sent as soon as possible,
80+
* less than 0 if session is closed.
7881
*/
7982
public int sendDataSync( ByteBuffer data );
8083

@@ -87,8 +90,8 @@ public interface Listener
8790
* will be called after all received data will be processed.
8891
* All further <em>sendData</em>, <em>sendDataAsync</em> and
8992
* <em>closeConnection</em> calls will return -1.
90-
* @return >0 - amount of data waiting to be sent
91-
* <0 - session already closed and has no data to be sent
93+
* @return less than 0 if session already has been closed,
94+
* otherwise amount of data waiting to be sent.
9295
*/
9396
public int closeConnection();
9497

@@ -97,8 +100,10 @@ public interface Listener
97100
* Supposed to be called only from the <tt>onDataReceived()</tt> callback.
98101
* Calling it not from the <tt>onDataReceived</tt> callback will result
99102
* in undefined behaviour.
103+
* @param newListener the new listener to be used for the session
104+
* @return the previous listener was used to the session
100105
*/
101-
public Listener replaceListener( Listener newListener );
106+
public Listener replaceListener(Listener newListener);
102107

103-
public int accelerate( ShMem shMem, ByteBuffer message );
108+
public int accelerate(ShMem shMem, ByteBuffer message);
104109
}

src/main/java/org/jsl/collider/SessionEmitter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.net.InetSocketAddress;
2323
import java.nio.ByteOrder;
2424

25-
2625
public abstract class SessionEmitter
2726
{
2827
private final InetSocketAddress m_addr;
@@ -75,6 +74,8 @@ public InetSocketAddress getAddr()
7574
* Called by framework to create session listener instance.
7675
* See <tt>Acceptor.createSessionListener</tt> and
7776
* <tt>Connector.createSessionListener</tt> for detailed description.
77+
* @param session session the listener will be used for
78+
* @return A listener object for the given session
7879
*/
79-
public abstract Session.Listener createSessionListener( Session session );
80+
public abstract Session.Listener createSessionListener(Session session);
8081
}

src/main/java/org/jsl/collider/TimerQueue.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,9 @@ private void removeTimerLocked( TimerInfo timerInfo )
250250

251251
/**
252252
* Public methods
253+
* @param threadPool the thread pool to execute timer tasks in.
253254
*/
254-
public TimerQueue( ThreadPool threadPool )
255+
public TimerQueue(ThreadPool threadPool)
255256
{
256257
m_threadPool = threadPool;
257258
m_lock = new ReentrantLock();
@@ -262,8 +263,12 @@ public TimerQueue( ThreadPool threadPool )
262263

263264
/**
264265
* Schedules the specified task for execution after the specified delay.
266+
* @param task the task to be executed
267+
* @param delay the time to wait
268+
* @param unit the time unot of the {@code delay} argument
269+
* @return less than 0 if task already registered, 0 if task scheduled
265270
*/
266-
public int schedule( Task task, long delay, TimeUnit unit )
271+
public int schedule(Task task, long delay, TimeUnit unit)
267272
{
268273
m_lock.lock();
269274
try
@@ -322,8 +327,12 @@ public int schedule( Task task, long delay, TimeUnit unit )
322327
* Cancel timer,
323328
* waits if timer is being firing at the moment,
324329
* so it guarantees that timer handler is not executed on return.
330+
* @param task the task to cancel
331+
* @return less than 0 if timer task was not registered or timer already fired,
332+
* greater than 0 if task removed before the timer fired.
333+
* @throws InterruptedException if thread interrupted on wait
325334
*/
326-
public int cancel( Task task ) throws InterruptedException
335+
public int cancel(Task task) throws InterruptedException
327336
{
328337
m_lock.lock();
329338
try
@@ -384,11 +393,12 @@ else if (timerInfo.threadID == -2)
384393
}
385394

386395
/**
387-
* Cancel timer,
388-
* do not wait if the task is being executed at that moment,
389-
* return > 0 in this case.
396+
* Cancel timer, do not wait if the task is being executed at that moment.
397+
* @param task the task to cancel
398+
* @return less than 0 if task not registered, 0 if timer task canceled,
399+
* greater than 0 if timer task was executed at the call.
390400
*/
391-
public int cancelNoWait( Task task )
401+
public int cancelNoWait(Task task)
392402
{
393403
m_lock.lock();
394404
try

0 commit comments

Comments
 (0)