Skip to content

Commit

Permalink
Spotless apply (#109)
Browse files Browse the repository at this point in the history
* initial spotless

* add license

* change pom indentation to 2 from 4

* mvn spotless:apply
  • Loading branch information
kortemik authored Apr 2, 2024
1 parent af4efbd commit 47efd37
Show file tree
Hide file tree
Showing 101 changed files with 1,081 additions and 908 deletions.
733 changes: 362 additions & 371 deletions pom.xml

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/main/java/com/teragrep/rlp_03/EncryptionInfo.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Java Reliable Event Logging Protocol Library Server Implementation RLP-03
* Copyright (C) 2021 Suomen Kanuuna Oy
* Copyright (C) 2021-2024 Suomen Kanuuna Oy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
Expand Down Expand Up @@ -43,7 +43,6 @@
* Teragrep, the applicable Commercial License may apply to this file if you as
* a licensee so wish it.
*/

package com.teragrep.rlp_03;

import javax.net.ssl.SSLPeerUnverifiedException;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/teragrep/rlp_03/EncryptionInfoStub.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Java Reliable Event Logging Protocol Library Server Implementation RLP-03
* Copyright (C) 2021 Suomen Kanuuna Oy
* Copyright (C) 2021-2024 Suomen Kanuuna Oy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
Expand Down Expand Up @@ -43,7 +43,6 @@
* Teragrep, the applicable Commercial License may apply to this file if you as
* a licensee so wish it.
*/

package com.teragrep.rlp_03;

import javax.net.ssl.SSLPeerUnverifiedException;
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/com/teragrep/rlp_03/EncryptionInfoTLS.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Java Reliable Event Logging Protocol Library Server Implementation RLP-03
* Copyright (C) 2021 Suomen Kanuuna Oy
* Copyright (C) 2021-2024 Suomen Kanuuna Oy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
Expand Down Expand Up @@ -43,7 +43,6 @@
* Teragrep, the applicable Commercial License may apply to this file if you as
* a licensee so wish it.
*/

package com.teragrep.rlp_03;

import tlschannel.TlsChannel;
Expand All @@ -65,22 +64,22 @@ public EncryptionInfoTLS(TlsChannel tlsChannel) {
public boolean isEncrypted() {
return true;
}

@Override
public String getSessionCipherSuite() {
return tlsChannel.getSslEngine().getSession().getCipherSuite();
}

@Override
public Certificate[] getLocalCertificates() {
return tlsChannel.getSslEngine().getSession().getLocalCertificates();
}

@Override
public Principal getLocalPrincipal() {
return tlsChannel.getSslEngine().getSession().getLocalPrincipal();
}

@Override
public X509Certificate[] getPeerCertificateChain() throws SSLPeerUnverifiedException {
return tlsChannel.getSslEngine().getSession().getPeerCertificateChain();
Expand All @@ -90,7 +89,7 @@ public X509Certificate[] getPeerCertificateChain() throws SSLPeerUnverifiedExcep
public Certificate[] getPeerCertificates() throws SSLPeerUnverifiedException {
return tlsChannel.getSslEngine().getSession().getPeerCertificates();
}

@Override
public Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
return tlsChannel.getSslEngine().getSession().getPeerPrincipal();
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/teragrep/rlp_03/FrameContext.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Java Reliable Event Logging Protocol Library Server Implementation RLP-03
* Copyright (C) 2021 Suomen Kanuuna Oy
* Copyright (C) 2021-2024 Suomen Kanuuna Oy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
Expand Down Expand Up @@ -43,13 +43,13 @@
* Teragrep, the applicable Commercial License may apply to this file if you as
* a licensee so wish it.
*/

package com.teragrep.rlp_03;

import com.teragrep.rlp_03.context.ConnectionContext;
import com.teragrep.rlp_03.context.frame.RelpFrame;

public class FrameContext {

private final ConnectionContext connectionContext;
private final RelpFrame relpFrame;

Expand All @@ -66,5 +66,4 @@ public RelpFrame relpFrame() {
return relpFrame;
}


}
17 changes: 12 additions & 5 deletions src/main/java/com/teragrep/rlp_03/Server.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Java Reliable Event Logging Protocol Library Server Implementation RLP-03
* Copyright (C) 2021 Suomen Kanuuna Oy
* Copyright (C) 2021-2024 Suomen Kanuuna Oy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
Expand Down Expand Up @@ -43,7 +43,6 @@
* Teragrep, the applicable Commercial License may apply to this file if you as
* a licensee so wish it.
*/

package com.teragrep.rlp_03;

import com.teragrep.rlp_03.context.channel.SocketFactory;
Expand All @@ -60,6 +59,7 @@
import java.util.function.Supplier;

public class Server implements Runnable {

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

public final ThreadPoolExecutor executorService;
Expand All @@ -74,7 +74,6 @@ public class Server implements Runnable {

public final Status startup;


public Server(
ThreadPoolExecutor threadPoolExecutor,
Supplier<FrameDelegate> frameDelegateSupplier,
Expand Down Expand Up @@ -106,7 +105,15 @@ public void stop() {

@Override
public void run() {
try (SocketPoll socketPoll = new SocketPoll(executorService,socketFactory, selector, serverSocketChannel, frameDelegateSupplier)) {
try (
SocketPoll socketPoll = new SocketPoll(
executorService,
socketFactory,
selector,
serverSocketChannel,
frameDelegateSupplier
)
) {
startup.complete(); // indicate successful startup
LOGGER.debug("Started");
while (!stop.get()) {
Expand Down Expand Up @@ -138,4 +145,4 @@ public void run() {
}
LOGGER.debug("Stopped");
}
}
}
19 changes: 9 additions & 10 deletions src/main/java/com/teragrep/rlp_03/ServerFactory.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Java Reliable Event Logging Protocol Library Server Implementation RLP-03
* Copyright (C) 2021 Suomen Kanuuna Oy
* Copyright (C) 2021-2024 Suomen Kanuuna Oy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
Expand Down Expand Up @@ -43,7 +43,6 @@
* Teragrep, the applicable Commercial License may apply to this file if you as
* a licensee so wish it.
*/

package com.teragrep.rlp_03;

import com.teragrep.rlp_03.config.Config;
Expand Down Expand Up @@ -75,23 +74,23 @@ public class ServerFactory {
final ConnectionContextStub connectionContextStub;
final InetSocketAddress listenSocketAddress;


public ServerFactory(Config config, Supplier<FrameDelegate> frameDelegateSupplier) {
this(config, new TLSConfig(), frameDelegateSupplier);
}


public ServerFactory(
Config config,
TLSConfig tlsConfig,
Supplier<FrameDelegate> frameDelegateSupplier
) {
public ServerFactory(Config config, TLSConfig tlsConfig, Supplier<FrameDelegate> frameDelegateSupplier) {

this.config = config;
this.tlsConfig = tlsConfig;
this.frameDelegateSupplier = frameDelegateSupplier;

this.executorService = new ThreadPoolExecutor(config.numberOfThreads, config.numberOfThreads, Long.MAX_VALUE, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
this.executorService = new ThreadPoolExecutor(
config.numberOfThreads,
config.numberOfThreads,
Long.MAX_VALUE,
TimeUnit.SECONDS,
new LinkedBlockingQueue<>()
);
this.connectionContextStub = new ConnectionContextStub();
this.listenSocketAddress = new InetSocketAddress(config.port);
}
Expand Down
49 changes: 21 additions & 28 deletions src/main/java/com/teragrep/rlp_03/SocketPoll.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Java Reliable Event Logging Protocol Library Server Implementation RLP-03
* Copyright (C) 2021 Suomen Kanuuna Oy
* Copyright (C) 2021-2024 Suomen Kanuuna Oy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
Expand Down Expand Up @@ -43,7 +43,6 @@
* Teragrep, the applicable Commercial License may apply to this file if you as
* a licensee so wish it.
*/

package com.teragrep.rlp_03;

import com.teragrep.rlp_03.context.*;
Expand All @@ -62,6 +61,7 @@
import java.util.function.Supplier;

public class SocketPoll implements Closeable {

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

private final ExecutorService executorService;
Expand All @@ -75,7 +75,6 @@ public class SocketPoll implements Closeable {

private final ConnectionContextStub connectionContextStub;


public SocketPoll(
ExecutorService executorService,
SocketFactory socketFactory,
Expand All @@ -94,31 +93,25 @@ public SocketPoll(
public void poll() throws IOException {
int readyKeys = selector.select();

LOGGER.debug("readyKeys <{}>",readyKeys);
LOGGER.debug("readyKeys <{}>", readyKeys);

Set<SelectionKey> selectionKeys = selector.selectedKeys();
LOGGER.debug("selectionKeys <{}> ", selectionKeys);
for (SelectionKey selectionKey : selectionKeys) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
"selectionKey <{}>: " +
"isValid <{}>, " +
"isConnectable <{}>, " +
"isAcceptable <{}>, " +
"isReadable <{}>, " +
"isWritable <{}>",
selectionKey,
selectionKey.isValid(),
selectionKey.isConnectable(),
selectionKey.isAcceptable(),
selectionKey.isReadable(),
selectionKey.isWritable()
);
LOGGER
.debug(
"selectionKey <{}>: " + "isValid <{}>, " + "isConnectable <{}>, "
+ "isAcceptable <{}>, " + "isReadable <{}>, " + "isWritable <{}>",
selectionKey, selectionKey.isValid(), selectionKey.isConnectable(),
selectionKey.isAcceptable(), selectionKey.isReadable(), selectionKey.isWritable()
);
}
try {
if (selectionKey.isAcceptable()) {
processAccept(serverSocketChannel, selectionKey);
} else {
}
else {
// submit readTask/writeTask based on clientContext states
ConnectionContext connectionContext = (ConnectionContext) selectionKey.attachment();
try {
Expand All @@ -129,7 +122,8 @@ public void poll() throws IOException {
connectionContext.close();
}
}
} catch (CancelledKeyException cke) { // TODO is this proper to catch here?
}
catch (CancelledKeyException cke) { // TODO is this proper to catch here?
LOGGER.warn("SocketPoll.poll CancelledKeyException caught: {}", cke.getMessage());
selectionKey.channel().close();
}
Expand All @@ -155,24 +149,23 @@ private void processAccept(ServerSocketChannel serverSocketChannel, SelectionKey
SocketAddress localAddress = serverSocketChannel.getLocalAddress();
SocketAddress remoteAddress = clientSocketChannel.getRemoteAddress();
LOGGER.debug("ServerSocket <{}> accepting ClientSocket <{}> ", localAddress, remoteAddress);
} catch (IOException ioException) {
}
catch (IOException ioException) {
LOGGER.warn("Exception while getAddress", ioException);
}
}

// tls/plain wrapper
Socket socket = socketFactory.create(clientSocketChannel);



// non-blocking
clientSocketChannel.configureBlocking(false);

SelectionKey clientSelectionKey = clientSocketChannel.register(
selector,
0, // interestOps: none at this point
connectionContextStub
);
SelectionKey clientSelectionKey = clientSocketChannel
.register(
selector, 0, // interestOps: none at this point
connectionContextStub
);

InterestOps interestOps = new InterestOpsImpl(clientSelectionKey);

Expand Down
8 changes: 3 additions & 5 deletions src/main/java/com/teragrep/rlp_03/Status.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Java Reliable Event Logging Protocol Library Server Implementation RLP-03
* Copyright (C) 2021 Suomen Kanuuna Oy
* Copyright (C) 2021-2024 Suomen Kanuuna Oy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
Expand Down Expand Up @@ -43,7 +43,6 @@
* Teragrep, the applicable Commercial License may apply to this file if you as
* a licensee so wish it.
*/

package com.teragrep.rlp_03;

import java.util.concurrent.atomic.AtomicBoolean;
Expand All @@ -57,8 +56,6 @@ public class Status {
private final Condition pending;
private final AtomicBoolean done;



Status() {
this.lock = new ReentrantLock();
this.pending = lock.newCondition();
Expand All @@ -70,7 +67,8 @@ void complete() {
try {
done.set(true);
pending.signal();
} finally {
}
finally {
lock.unlock();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/teragrep/rlp_03/TransportInfo.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Java Reliable Event Logging Protocol Library Server Implementation RLP-03
* Copyright (C) 2021 Suomen Kanuuna Oy
* Copyright (C) 2021-2024 Suomen Kanuuna Oy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
Expand Down Expand Up @@ -43,10 +43,10 @@
* Teragrep, the applicable Commercial License may apply to this file if you as
* a licensee so wish it.
*/

package com.teragrep.rlp_03;

public interface TransportInfo {

String getLocalAddress();

int getLocalPort();
Expand Down
Loading

0 comments on commit 47efd37

Please sign in to comment.