Skip to content

Commit f76e3ae

Browse files
committed
Updated site documentation and examples
Signed-off-by: Rafael Luis Ibasco <[email protected]>
1 parent 7d9880a commit f76e3ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2617
-881
lines changed

.github/workflows/site.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,11 @@ jobs:
3232
cache: maven
3333

3434
- name: Build Project Site
35-
run: mvn site site:stage
35+
run: mvn site site:stage
36+
37+
- name: Deploy Site
38+
if: github.ref == 'refs/heads/master' && matrix.java == 8
39+
uses: peaceiris/actions-gh-pages@v3
40+
with:
41+
github_token: ${{ secrets.GITHUB_TOKEN }}
42+
publish_dir: ./target/staging

assembly/pom.xml

+1-9
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,11 @@
8080
<artifactId>maven-javadoc-plugin</artifactId>
8181
<executions>
8282
<execution>
83-
<id>aggregate-javadocs</id>
83+
<id>aggregate</id>
8484
<phase>package</phase>
8585
<goals>
8686
<goal>aggregate-jar</goal>
8787
</goals>
88-
<configuration>
89-
<includeDependencySources>true</includeDependencySources>
90-
<!--<source>8</source>-->
91-
<dependencySourceExcludes>
92-
<dependencySourceExclude>com.ibasco.agql:agql-lib-examples</dependencySourceExclude>
93-
<dependencySourceExclude>org.slf4j:*</dependencySourceExclude>
94-
</dependencySourceExcludes>
95-
</configuration>
9688
</execution>
9789
</executions>
9890
</plugin>

core/src/main/java/com/ibasco/agql/core/AbstractWebApiInterface.java

-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ abstract public class AbstractWebApiInterface<C extends AbstractRestClient, R ex
5454
/**
5555
* Used by the underlying concrete classes for api versioning
5656
*/
57-
/** Constant <code>VERSION_2=2</code> */
58-
/** Constant <code>VERSION_3=3</code> */
5957
public static final int VERSION_1 = 1, VERSION_2 = 2, VERSION_3 = 3;
6058

6159
/**

core/src/main/java/com/ibasco/agql/core/Client.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@
2929
public interface Client extends Closeable {
3030

3131
/**
32-
* <p>id.</p>
32+
* <p>The unique-id of this instance</p>
3333
*
34-
* @return a {@link com.ibasco.agql.core.util.UUID} object
34+
* @return A {@link com.ibasco.agql.core.util.UUID} object
3535
*/
3636
UUID id();
3737

3838
/**
39-
* <p>getExecutor.</p>
39+
* <p>The underlying {@link Executor} used by this instance</p>
4040
*
41-
* @return a {@link java.util.concurrent.Executor} object
41+
* @return The {@link java.util.concurrent.Executor} object
4242
*/
4343
Executor getExecutor();
4444
}

core/src/main/java/com/ibasco/agql/core/CredentialsStore.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public interface CredentialsStore {
3434
*
3535
* @param address
3636
* The {@link java.net.InetSocketAddress} to be used for lookup
37+
*
3738
* @return The {@link com.ibasco.agql.core.Credentials} associated with the {@link java.net.InetSocketAddress}. {@code null} if no {@link com.ibasco.agql.core.Credentials} is present.
3839
*/
3940
Credentials get(InetSocketAddress address);
@@ -45,8 +46,10 @@ public interface CredentialsStore {
4546
* The {@link java.net.InetSocketAddress} to register
4647
* @param passphrase
4748
* The byte array containing the passphrase to be used for authentication
49+
*
50+
* @return The new {@link Credentials} registered for the specified address
4851
*/
49-
void add(InetSocketAddress address, byte[] passphrase);
52+
Credentials add(InetSocketAddress address, byte[] passphrase);
5053

5154
/**
5255
* Clear {@link com.ibasco.agql.core.Credentials} for a specific address
@@ -66,6 +69,7 @@ public interface CredentialsStore {
6669
*
6770
* @param address
6871
* The {@link java.net.InetSocketAddress} to check
72+
*
6973
* @return {@code true} if a {@link com.ibasco.agql.core.Credentials} is registered for the specified address.
7074
*/
7175
boolean exists(InetSocketAddress address);

core/src/main/java/com/ibasco/agql/core/HttpMessenger.java

+17-9
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public final class HttpMessenger implements Messenger<AbstractWebRequest, Abstra
4747

4848
private final HttpOptions options;
4949

50+
private ExecutorService executorService;
51+
5052
private final EventLoopGroup eventLoopGroup;
5153

5254
/**
@@ -79,31 +81,37 @@ public HttpMessenger(Function<Response, AbstractWebResponse> responseFactory, Ht
7981
}
8082

8183
private EventLoopGroup initializeEventLoopGroup() {
82-
ExecutorService executorService = options.get(GeneralOptions.THREAD_EXECUTOR_SERVICE);
83-
if (executorService == null)
84-
executorService = Platform.getDefaultExecutor();
84+
ExecutorService executor = options.get(GeneralOptions.THREAD_EXECUTOR_SERVICE);
85+
if (executor == null) {
86+
executor = Platform.getDefaultExecutor();
87+
}
8588
Integer nThreads = getOptions().get(GeneralOptions.THREAD_CORE_SIZE);
8689
//Attempt to determine the number of threads supported by the executor service
8790
if (nThreads == null) {
88-
if (executorService instanceof AgqlManagedExecutorService)
89-
executorService = ((AgqlManagedExecutorService) executorService).getResource();
90-
if (executorService instanceof ThreadPoolExecutor) {
91-
ThreadPoolExecutor tpe = (ThreadPoolExecutor) executorService;
91+
ExecutorService tmp = executor;
92+
if (tmp instanceof AgqlManagedExecutorService)
93+
tmp = ((AgqlManagedExecutorService) executor).getResource();
94+
if (tmp instanceof ThreadPoolExecutor) {
95+
ThreadPoolExecutor tpe = (ThreadPoolExecutor) tmp;
9296
nThreads = tpe.getCorePoolSize();
9397
} else {
9498
throw new IllegalStateException("Please specify a core pool size in the options (See GeneralOptions.THREAD_CORE_SIZE)");
9599
}
96100
}
97-
EventLoopGroup group = Platform.isDefaultExecutor(executorService) ? Platform.getDefaultEventLoopGroup() : Platform.createEventLoopGroup(executorService, nThreads, Properties.useNativeTransport());
98-
log.debug("HTTP_MESSENGER (INIT) => Executor Service: '{}'", executorService);
101+
EventLoopGroup group = Platform.isDefaultExecutor(executor) ? Platform.getDefaultEventLoopGroup() : Platform.createEventLoopGroup(executor, nThreads, Properties.useNativeTransport());
102+
log.debug("HTTP_MESSENGER (INIT) => Executor Service: '{}'", executor);
99103
log.debug("HTTP_MESSENGER (INIT) => Event Loop Group: '{}' (Event Loop Threads: {})", group, nThreads);
104+
this.executorService = executor;
100105
return group;
101106
}
102107

103108
/** {@inheritDoc} */
104109
@Override
105110
public void close() throws IOException {
106111
transport.close();
112+
if (eventLoopGroup != null)
113+
eventLoopGroup.shutdownGracefully();
114+
ManagedResource.release(executorService);
107115
}
108116

109117
/** {@inheritDoc} */

core/src/main/java/com/ibasco/agql/core/NettySocketClient.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
import com.ibasco.agql.core.util.OptionBuilder;
2020
import com.ibasco.agql.core.util.Options;
2121
import com.ibasco.agql.core.util.UUID;
22-
import io.netty.channel.EventLoopGroup;
2322
import org.slf4j.Logger;
2423
import org.slf4j.LoggerFactory;
2524

2625
import java.io.IOException;
2726
import java.util.Objects;
27+
import java.util.concurrent.ScheduledExecutorService;
2828

2929
/**
3030
* A netty based socket client.
@@ -73,8 +73,8 @@ protected NettyMessenger<R, S> getMessenger() {
7373

7474
/** {@inheritDoc} */
7575
@Override
76-
public EventLoopGroup getExecutor() {
77-
return (EventLoopGroup) super.getExecutor();
76+
public ScheduledExecutorService getExecutor() {
77+
return (ScheduledExecutorService) super.getExecutor();
7878
}
7979

8080
/** {@inheritDoc} */

core/src/main/java/com/ibasco/agql/core/NettyTransport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class NettyTransport implements Transport<NettyChannelContext, NettyChann
5353
try {
5454
assert context.channel().id().equals(channel.id());
5555
if (future.isSuccess()) {
56-
log.debug("{} TRANSPORT => Request has been sent and processed through the channel's pipeline", context.id());
56+
log.debug("{} TRANSPORT => Request has been sent and processed through the channel's pipeline (Request: {})", context.id(), context.properties().request());
5757
context.properties().endWrite();
5858
} else {
5959
log.debug("{} TRANSPORT => An error occured while sending request through the channel's pipeline", context.id(), future.cause());

core/src/main/java/com/ibasco/agql/core/exceptions/InvalidPacketException.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class InvalidPacketException extends AgqlRuntimeException {
3131
* @param message
3232
* a {@link java.lang.String} object
3333
* @param data
34-
* an array of {@link byte} objects
34+
* The packet in raw byte array form
3535
*/
3636
public InvalidPacketException(String message, byte[] data) {
3737
super(message);

core/src/main/java/com/ibasco/agql/core/util/Console.java

+94-21
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* @author Rafael Luis Ibasco
2323
*/
24-
public class Console {
24+
public final class Console {
2525

2626
/** Constant <code>RESET="\u001B[0m"</code> */
2727
public static final String RESET = "\u001B[0m";
@@ -158,52 +158,113 @@ public static Colorize colorize() {
158158
return new Colorize();
159159
}
160160

161+
public static Colorize colorize(boolean allowPrinting) {
162+
return new Colorize(allowPrinting);
163+
}
164+
161165
public static class Colorize {
162166

163167
private final StringBuilder builder;
164168

169+
private final boolean allowPrinting;
170+
171+
private boolean allowColors;
172+
165173
private Colorize() {
166-
builder = new StringBuilder();
174+
this(Properties.isVerbose());
167175
}
168176

169-
public Colorize red() {
170-
builder.append(RED);
177+
private Colorize(boolean allowPrinting) {
178+
this.builder = new StringBuilder();
179+
this.allowPrinting = allowPrinting;
180+
this.allowColors = true;
181+
}
182+
183+
public Colorize enableColors() {
184+
this.allowColors = true;
171185
return this;
172186
}
173187

174-
public Colorize yellow() {
175-
builder.append(YELLOW);
188+
public Colorize disableColors() {
189+
this.allowColors = false;
176190
return this;
177191
}
178192

193+
public Colorize red() {
194+
return append(RED);
195+
}
196+
197+
public Colorize red(String format, Object... args) {
198+
return append(RED, format, args);
199+
}
200+
201+
public Colorize yellow() {
202+
return append(YELLOW);
203+
}
204+
205+
public Colorize yellow(String format, Object... args) {
206+
return append(YELLOW, format, args);
207+
}
208+
209+
public Colorize purple() {
210+
return append(PURPLE);
211+
}
212+
213+
public Colorize purple(String format, Object... args) {
214+
return append(PURPLE, format, args);
215+
}
216+
179217
public Colorize cyan() {
180-
builder.append(CYAN);
218+
return append(CYAN);
219+
}
220+
221+
public Colorize cyan(String format, Object... args) {
222+
return append(CYAN, format, args);
223+
}
224+
225+
public Colorize line() {
226+
builder.append(System.lineSeparator());
181227
return this;
182228
}
183229

184230
public Colorize reset() {
185-
builder.append(RESET);
186-
return this;
231+
return append(RESET);
232+
}
233+
234+
public Colorize reset(String format, Object... args) {
235+
return append(RESET, format, args);
187236
}
188237

189238
public Colorize black() {
190-
builder.append(BLACK);
191-
return this;
239+
return append(BLACK);
240+
}
241+
242+
public Colorize black(String format, Object... args) {
243+
return append(BLACK, format, args);
192244
}
193245

194246
public Colorize white() {
195-
builder.append(WHITE);
196-
return this;
247+
return append(WHITE);
248+
}
249+
250+
public Colorize white(String format, Object... args) {
251+
return append(WHITE, format, args);
197252
}
198253

199254
public Colorize blue() {
200-
builder.append(BLUE);
201-
return this;
255+
return append(BLUE);
256+
}
257+
258+
public Colorize blue(String format, Object... args) {
259+
return append(BLUE, format, args);
202260
}
203261

204262
public Colorize green() {
205-
builder.append(GREEN);
206-
return this;
263+
return append(GREEN);
264+
}
265+
266+
public Colorize green(String format, Object... args) {
267+
return append(GREEN, format, args);
207268
}
208269

209270
public Colorize text(String text) {
@@ -232,28 +293,40 @@ public Colorize clear() {
232293
}
233294

234295
public void print() {
235-
if (Properties.isVerbose())
296+
if (allowPrinting)
236297
System.out.print(builder);
237298
}
238299

239300
public void println() {
240-
if (Properties.isVerbose())
301+
if (allowPrinting)
241302
System.out.println(builder);
242303
}
243304

244305
public void printErr() {
245-
if (Properties.isVerbose())
306+
if (allowPrinting)
246307
System.err.print(builder);
247308
}
248309

249310
public void printErrln() {
250-
if (Properties.isVerbose())
311+
if (allowPrinting)
251312
System.err.println(builder);
252313
}
253314

254315
@Override
255316
public String toString() {
256317
return builder.toString();
257318
}
319+
320+
private Colorize append(String color) {
321+
return append(color, null);
322+
}
323+
324+
private Colorize append(String color, String format, Object... args) {
325+
if (allowColors)
326+
builder.append(color);
327+
if (!Strings.isBlank(format))
328+
builder.append(String.format(format, args));
329+
return this;
330+
}
258331
}
259332
}

core/src/main/java/com/ibasco/agql/core/util/FailsafeOptions.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
@Shared
2828
public class FailsafeOptions extends AbstractOptions {
2929

30-
protected FailsafeOptions() {}
30+
private FailsafeOptions() {}
3131

3232
//<editor-fold desc="Failsafe - General Options">
3333

core/src/main/java/com/ibasco/agql/core/util/GeneralOptions.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private GeneralOptions() {}
8181
/**
8282
* The maximum number of milliseconds to wait before timing out on close channel operation
8383
*/
84-
public static final Option<Integer> CLOSE_TIMEOUT = Option.create("globalCloseTimeout", 3000);
84+
public static final Option<Integer> CLOSE_TIMEOUT = Option.create("globalCloseTimeout", 10000);
8585
//</editor-fold>
8686

8787
//<editor-fold desc="Connection Pooling">

0 commit comments

Comments
 (0)