Skip to content

Commit

Permalink
add more javadoc (#144)
Browse files Browse the repository at this point in the history
* add more javadoc

* apply spotless

* pr comment fixes

* pr comment fixes
  • Loading branch information
kortemik authored Apr 18, 2024
1 parent 5ebf722 commit ac0ba54
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 3 deletions.
22 changes: 21 additions & 1 deletion src/main/java/com/teragrep/rlp_03/EventLoop.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,28 @@
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;

/**
* {@link EventLoop} is used to {@link Selector#select()} events from network connections which are registered with it
*/
public class EventLoop implements AutoCloseable {

private static final Logger LOGGER = LoggerFactory.getLogger(EventLoop.class);

private final Selector selector;
private final ConcurrentLinkedQueue<Context> pendingContextRegistrations;

public EventLoop(Selector selector) {
EventLoop(Selector selector) {
this.selector = selector;

this.pendingContextRegistrations = new ConcurrentLinkedQueue<>();
}

/**
* Register network connection with this {@link EventLoop}. Forces the {@link EventLoop} to run once after
* registration.
*
* @param context to register
*/
public void register(Context context) {
pendingContextRegistrations.add(context);
wakeup();
Expand All @@ -97,6 +106,11 @@ private void registerPendingRegistrations() {
}
}

/**
* Polls events from network connections via {@link Selector#select()}
*
* @throws IOException
*/
public void poll() throws IOException {
int readyKeys = selector.select();

Expand Down Expand Up @@ -140,6 +154,9 @@ else if (selectionKey.isConnectable()) {
selectionKeys.clear();
}

/**
* Terminates the {@link EventLoop}
*/
@Override
public void close() {
for (SelectionKey selectionKey : selector.keys()) {
Expand All @@ -154,6 +171,9 @@ public void close() {
}
}

/**
* Forces the {@link EventLoop} to execute one cycle
*/
public void wakeup() {
selector.wakeup();
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/teragrep/rlp_03/EventLoopFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
import java.io.IOException;
import java.nio.channels.Selector;

/**
* Creates new {@link EventLoop}s
*/
public class EventLoopFactory {

public EventLoop create() throws IOException {
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/com/teragrep/rlp_03/channel/socket/Socket.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,47 @@
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

/**
* {@link Socket} provides network connectivity methods
*/
public interface Socket {

/**
* Read data from a network connection.
*
* @param dsts {@link ByteBuffer}s which are read to from the connection
* @return amount of bytes read
* @throws IOException if read fails
*/
long read(ByteBuffer[] dsts) throws IOException;

/**
* Write data through a network connection.
*
* @param dsts {@link ByteBuffer}s which are written to the connection
* @return amount of bytes written
* @throws IOException if write fails
*/
long write(ByteBuffer[] dsts) throws IOException;

/**
* Provides information about a network connection
*
* @return {@link TransportInfo} describing the connection
*/
TransportInfo getTransportInfo();

/**
* Closes the connection
*
* @throws IOException if close attempt fails
*/
void close() throws IOException;

/**
* Provides the underlying {@link SocketChannel}
*
* @return {@link SocketChannel}
*/
SocketChannel socketChannel();
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@

import java.nio.channels.SocketChannel;

/**
* {@link SocketFactory} is used to create {@link Socket}s
*/
public abstract class SocketFactory {

abstract public Socket create(SocketChannel socketChannel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
import java.nio.channels.SocketChannel;
import java.util.function.Function;

/**
* {@link TLSFactory} is used to create {@link TLSSocket}s
*/
public final class TLSFactory extends SocketFactory {

private final SSLContext sslContext;
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/teragrep/rlp_03/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@
import java.io.UncheckedIOException;
import java.util.concurrent.atomic.AtomicBoolean;

public class Server implements Runnable {
/**
* Simple server with integrated EventLoop which is executed by the {@link Runnable}
*/
class Server implements Runnable {

private static final Logger LOGGER = LoggerFactory.getLogger(Server.class);

Expand All @@ -63,7 +66,7 @@ public class Server implements Runnable {

private final EventLoop eventLoop;

public Server(EventLoop eventLoop) {
Server(EventLoop eventLoop) {
this.eventLoop = eventLoop;
this.stop = new AtomicBoolean();
this.startup = new Status();
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/teragrep/rlp_03/server/ServerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,22 @@
import java.util.concurrent.ExecutorService;
import java.util.function.Supplier;

/**
* Factory for creating {@link Server}s
*/
public class ServerFactory {

private final ExecutorService executorService;
private final SocketFactory socketFactory;
private final Supplier<FrameDelegate> frameDelegateSupplier;

/**
* Primary constructor
*
* @param executorService which {@link Server}s use to run received network connection events with
* @param socketFactory which is used to create {@link Server}'s connections
* @param frameDelegateSupplier is used to create {@link FrameDelegate}s for the {@link Server}'s connections
*/
public ServerFactory(
ExecutorService executorService,
SocketFactory socketFactory,
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/teragrep/rlp_03/server/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
* {@link Status} provides information about {@link Server}'s startup
*/
public class Status {

private final Lock lock;
Expand Down

0 comments on commit ac0ba54

Please sign in to comment.