Skip to content

Commit

Permalink
Add javadoc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubenicos committed Jan 7, 2024
1 parent 0f25c56 commit c40b7a5
Show file tree
Hide file tree
Showing 6 changed files with 443 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
* Sql integration for data delivery using Hikari library.
*
* @author Rubenicos
*/
public class HikariDelivery extends DeliveryClient {

private final HikariDataSource hikari;
Expand All @@ -20,6 +25,15 @@ public class HikariDelivery extends DeliveryClient {
private Runnable getTask = null;
private Runnable cleanTask = null;

/**
* Create a HikariDelivery client with provided parameters.
*
* @param url the URL to connect with.
* @param username the username to validate authentication.
* @param password the password to validate authentication.
* @param tablePrefix the table prefix.
* @return new HikariDelivery instance.
*/
@NotNull
public static HikariDelivery of(@NotNull String url, @NotNull String username, @NotNull String password, @NotNull String tablePrefix) {
final HikariConfig config = new HikariConfig();
Expand All @@ -29,6 +43,12 @@ public static HikariDelivery of(@NotNull String url, @NotNull String username, @
return new HikariDelivery(new HikariDataSource(config), tablePrefix);
}

/**
* Constructs a HikariDelivery with provided parameters.
*
* @param hikari the hikari instance to make database connections.
* @param tablePrefix the used table prefix.
*/
public HikariDelivery(@NotNull HikariDataSource hikari, @NotNull String tablePrefix) {
this.hikari = hikari;
this.tablePrefix = tablePrefix;
Expand Down Expand Up @@ -100,11 +120,19 @@ public void onSend(@NotNull String channel, byte[] data) {
lock.readLock().unlock();
}

/**
* Get the current hikari instance.
*
* @return a hikari instance.
*/
@NotNull
public HikariDataSource getHikari() {
return hikari;
}

/**
* Get all unread messages from database.
*/
public void getMessages() {
if (!enabled || !hikari.isRunning()) {
return;
Expand Down Expand Up @@ -133,6 +161,9 @@ public void getMessages() {
lock.readLock().unlock();
}

/**
* Clean old messages from database.
*/
public void cleanMessages() {
if (!enabled || !hikari.isRunning()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import java.net.URI;
import java.util.concurrent.TimeUnit;

/**
* RabbitMQ integration for data delivery.
*
* @author Rubenicos
*/
public class RabbitMQDelivery extends DeliveryClient {

private final Connection connection;
Expand All @@ -19,6 +24,13 @@ public class RabbitMQDelivery extends DeliveryClient {
private Runnable aliveTask = null;
private boolean reconnected = false;

/**
* Create a RabbitMQDelivery client with provided parameters.
*
* @param url the URL to connect with.
* @param exchange the pre-channel to use.
* @return new RabbitMQDelivery instance.
*/
@NotNull
public static RabbitMQDelivery of(@NotNull String url, @NotNull String exchange) {
try {
Expand All @@ -28,6 +40,13 @@ public static RabbitMQDelivery of(@NotNull String url, @NotNull String exchange)
}
}

/**
* Create a RabbitMQDelivery client with provided parameters.
*
* @param uri the URL object to connect with.
* @param exchange the pre-channel to use.
* @return new RabbitMQDelivery instance.
*/
@NotNull
public static RabbitMQDelivery of(@NotNull URI uri, @NotNull String exchange) {
final ConnectionFactory factory = new ConnectionFactory();
Expand All @@ -39,6 +58,17 @@ public static RabbitMQDelivery of(@NotNull URI uri, @NotNull String exchange) {
}
}

/**
* Create a RabbitMQDelivery client with provided parameters.
*
* @param host the host to connect.
* @param port the port host.
* @param username the username to validate authentication.
* @param password the password to validate authentication.
* @param virtualHost the virtual host.
* @param exchange the pre-channel to use.
* @return new RabbitMQDelivery instance.
*/
@NotNull
public static RabbitMQDelivery of(@NotNull String host, int port, @NotNull String username, @NotNull String password, @NotNull String virtualHost, @NotNull String exchange) {
final ConnectionFactory factory = new ConnectionFactory();
Expand All @@ -54,6 +84,12 @@ public static RabbitMQDelivery of(@NotNull String host, int port, @NotNull Strin
}
}

/**
* Constructs a RabbitMQDelivery with provided parameters.
*
* @param connection the connection to interact with.
* @param exchange the pre-channel to use.
*/
public RabbitMQDelivery(@NotNull Connection connection, @NotNull String exchange) {
this.connection = connection;
this.exchange = exchange;
Expand Down Expand Up @@ -147,6 +183,11 @@ public void onSend(@NotNull String channel, byte[] data) {
}
}

/**
* The current connection.
*
* @return a RabbitMQ connection object.
*/
@NotNull
public Connection getConnection() {
return connection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

import java.net.URI;

/**
* Redis integration for data delivery.
*
* @author Rubenicos
*/
public class RedisDelivery extends DeliveryClient {

private final JedisPool pool;
Expand All @@ -15,6 +20,12 @@ public class RedisDelivery extends DeliveryClient {

private Runnable aliveTask = null;

/**
* Create a RedisDelivery client with provided parameters.
*
* @param url the URL to connect with.
* @return new RedisDelivery instance.
*/
@NotNull
public static RedisDelivery of(@NotNull String url) {
String password = "";
Expand All @@ -31,22 +42,52 @@ public static RedisDelivery of(@NotNull String url) {
}
}

/**
* Create a RedisDelivery client with provided parameters.
*
* @param uri the URL object to connect with.
* @param password the password to validate authentication.
* @return new RedisDelivery instance.
*/
@NotNull
public static RedisDelivery of(@NotNull URI uri, @NotNull String password) {
return new RedisDelivery(new JedisPool(uri), password);
}

/**
* Create a RedisDelivery client with provided parameters.
*
* @param host the host to connect.
* @param port the port host.
* @param password the password to validate authentication.
* @param database the database number.
* @param ssl true to use SSL.
* @return new RedisDelivery instance.
*/
@NotNull
public static RedisDelivery of(@NotNull String host, int port, @NotNull String password, int database, boolean ssl) {
return new RedisDelivery(new JedisPool(new JedisPoolConfig(), host, port, Protocol.DEFAULT_TIMEOUT, password, database, ssl), password);
}

/**
* Constructs a RedisDelivery with provided parameters.
*
* @param pool the pool to connect with.
* @param password the used redis password.
*/
public RedisDelivery(@NotNull JedisPool pool, @NotNull String password) {
this.pool = pool;
this.password = password;
this.bridge = new Bridge();
}

/**
* Constructs a RedisDelivery with provided parameters.
*
* @param pool the pool to connect with.
* @param password the used redis password.
* @param bridge the bridge to receive messages from redis.
*/
public RedisDelivery(@NotNull JedisPool pool, @NotNull String password, @NotNull Bridge bridge) {
this.pool = pool;
this.password = password;
Expand Down Expand Up @@ -114,16 +155,31 @@ public void onSend(@NotNull String channel, byte[] data) {
}
}

/**
* The current pool.
*
* @return a jedis pool object.
*/
@NotNull
public JedisPool getPool() {
return pool;
}

/**
* The current password for authentication.
*
* @return a String password.
*/
@NotNull
public String getPassword() {
return password;
}

/**
* Get the current bridge to receive messages.
*
* @return a bridge instance.
*/
@NotNull
public Bridge getBridge() {
return bridge;
Expand Down Expand Up @@ -166,6 +222,9 @@ private void alive() {
}
}

/**
* Bridge class to detect received messages from Redis database.
*/
public class Bridge extends JedisPubSub {

@Override
Expand Down
Loading

0 comments on commit c40b7a5

Please sign in to comment.