Skip to content

Commit e8786c2

Browse files
authored
add SocketConfig and BlockedServerTests (#73)
* add SocketConfig and BlockedServerTests * add missing license headers * remove AssertDoesNotThrow from TestServer.close eventLoopThread.join()
1 parent c1d2a4d commit e8786c2

15 files changed

Lines changed: 664 additions & 36 deletions

src/main/java/com/teragrep/rlp_01/client/RelpConfig.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Java Reliable Event Logging Protocol Library RLP-01
3+
Copyright (C) 2021-2024 Suomen Kanuuna Oy
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
117
package com.teragrep.rlp_01.client;
218

319
import java.time.Duration;

src/main/java/com/teragrep/rlp_01/client/RelpConnectionFactory.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,24 @@
2323
public class RelpConnectionFactory implements Supplier<IManagedRelpConnection> {
2424

2525
private final RelpConfig relpConfig;
26+
private final SocketConfig socketConfig;
2627
private final SSLContextSupplier sslContextSupplier;
2728

2829
public RelpConnectionFactory(RelpConfig relpConfig) {
29-
this(relpConfig, new SSLContextSupplierStub());
30+
this(relpConfig, new SocketConfigDefault());
3031
}
32+
33+
public RelpConnectionFactory(RelpConfig relpConfig, SocketConfig socketConfig) {
34+
this(relpConfig, socketConfig, new SSLContextSupplierStub());
35+
}
36+
3137
public RelpConnectionFactory(RelpConfig relpConfig, SSLContextSupplier sslContextSupplier) {
38+
this(relpConfig, new SocketConfigDefault(), sslContextSupplier);
39+
}
40+
41+
public RelpConnectionFactory(RelpConfig relpConfig, SocketConfig socketConfig, SSLContextSupplier sslContextSupplier) {
3242
this.relpConfig = relpConfig;
43+
this.socketConfig = socketConfig;
3344
this.sslContextSupplier = sslContextSupplier;
3445
}
3546

@@ -43,6 +54,11 @@ public IManagedRelpConnection get() {
4354
relpConnection = new RelpConnectionWithConfig(new RelpConnection(() -> sslContextSupplier.get().createSSLEngine()), relpConfig);
4455
}
4556

57+
relpConnection.setReadTimeout(socketConfig.readTimeout());
58+
relpConnection.setWriteTimeout(socketConfig.writeTimeout());
59+
relpConnection.setConnectionTimeout(socketConfig.connectTimeout());
60+
relpConnection.setKeepAlive(socketConfig.keepAlive());
61+
4662
IManagedRelpConnection managedRelpConnection = new ManagedRelpConnection(relpConnection);
4763

4864
if (relpConfig.rebindEnabled) {

src/main/java/com/teragrep/rlp_01/client/RenewableRelpConnection.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Java Reliable Event Logging Protocol Library RLP-01
3+
Copyright (C) 2021-2024 Suomen Kanuuna Oy
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
117
package com.teragrep.rlp_01.client;
218

319
import java.io.IOException;

src/main/java/com/teragrep/rlp_01/client/SSLContextSupplier.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Java Reliable Event Logging Protocol Library RLP-01
3+
Copyright (C) 2021-2024 Suomen Kanuuna Oy
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
117
package com.teragrep.rlp_01.client;
218

319
import com.teragrep.rlp_01.pool.Stubable;

src/main/java/com/teragrep/rlp_01/client/SSLContextSupplierKeystore.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Java Reliable Event Logging Protocol Library RLP-01
3+
Copyright (C) 2021-2024 Suomen Kanuuna Oy
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
117
package com.teragrep.rlp_01.client;
218

319
import com.teragrep.rlp_01.SSLContextFactory;

src/main/java/com/teragrep/rlp_01/client/SSLContextSupplierStub.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Java Reliable Event Logging Protocol Library RLP-01
3+
Copyright (C) 2021-2024 Suomen Kanuuna Oy
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
117
package com.teragrep.rlp_01.client;
218

319
import javax.net.ssl.SSLContext;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
Java Reliable Event Logging Protocol Library RLP-01
3+
Copyright (C) 2021-2024 Suomen Kanuuna Oy
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
package com.teragrep.rlp_01.client;
18+
19+
public interface SocketConfig {
20+
int readTimeout();
21+
int writeTimeout();
22+
int connectTimeout();
23+
boolean keepAlive();
24+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
Java Reliable Event Logging Protocol Library RLP-01
3+
Copyright (C) 2021-2024 Suomen Kanuuna Oy
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
package com.teragrep.rlp_01.client;
18+
19+
public class SocketConfigDefault implements SocketConfig {
20+
@Override
21+
public int readTimeout() {
22+
return 0;
23+
}
24+
25+
@Override
26+
public int writeTimeout() {
27+
return 0;
28+
}
29+
30+
@Override
31+
public int connectTimeout() {
32+
return 0;
33+
}
34+
35+
@Override
36+
public boolean keepAlive() {
37+
return false;
38+
}
39+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Java Reliable Event Logging Protocol Library RLP-01
3+
Copyright (C) 2021-2024 Suomen Kanuuna Oy
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
package com.teragrep.rlp_01.client;
18+
19+
public class SocketConfigImpl implements SocketConfig {
20+
private final int readTimeout;
21+
private final int writeTimeout;
22+
private final int connectTimeout;
23+
private final boolean keepAlive;
24+
25+
public SocketConfigImpl(int readTimeout, int writeTimeout, int connectTimeout, boolean keepAlive) {
26+
this.readTimeout = readTimeout;
27+
this.writeTimeout = writeTimeout;
28+
this.connectTimeout = connectTimeout;
29+
this.keepAlive = keepAlive;
30+
}
31+
32+
@Override
33+
public int readTimeout() {
34+
return readTimeout;
35+
}
36+
37+
@Override
38+
public int writeTimeout() {
39+
return writeTimeout;
40+
}
41+
42+
@Override
43+
public int connectTimeout() {
44+
return connectTimeout;
45+
}
46+
47+
@Override
48+
public boolean keepAlive() {
49+
return keepAlive;
50+
}
51+
}

0 commit comments

Comments
 (0)