Skip to content

Commit

Permalink
add SocketConfig and BlockedServerTests (#73)
Browse files Browse the repository at this point in the history
* add SocketConfig and BlockedServerTests

* add missing license headers

* remove AssertDoesNotThrow from TestServer.close eventLoopThread.join()
  • Loading branch information
kortemik authored Nov 22, 2024
1 parent c1d2a4d commit e8786c2
Show file tree
Hide file tree
Showing 15 changed files with 664 additions and 36 deletions.
16 changes: 16 additions & 0 deletions src/main/java/com/teragrep/rlp_01/client/RelpConfig.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Java Reliable Event Logging Protocol Library RLP-01
Copyright (C) 2021-2024 Suomen Kanuuna Oy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.teragrep.rlp_01.client;

import java.time.Duration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,24 @@
public class RelpConnectionFactory implements Supplier<IManagedRelpConnection> {

private final RelpConfig relpConfig;
private final SocketConfig socketConfig;
private final SSLContextSupplier sslContextSupplier;

public RelpConnectionFactory(RelpConfig relpConfig) {
this(relpConfig, new SSLContextSupplierStub());
this(relpConfig, new SocketConfigDefault());
}

public RelpConnectionFactory(RelpConfig relpConfig, SocketConfig socketConfig) {
this(relpConfig, socketConfig, new SSLContextSupplierStub());
}

public RelpConnectionFactory(RelpConfig relpConfig, SSLContextSupplier sslContextSupplier) {
this(relpConfig, new SocketConfigDefault(), sslContextSupplier);
}

public RelpConnectionFactory(RelpConfig relpConfig, SocketConfig socketConfig, SSLContextSupplier sslContextSupplier) {
this.relpConfig = relpConfig;
this.socketConfig = socketConfig;
this.sslContextSupplier = sslContextSupplier;
}

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

relpConnection.setReadTimeout(socketConfig.readTimeout());
relpConnection.setWriteTimeout(socketConfig.writeTimeout());
relpConnection.setConnectionTimeout(socketConfig.connectTimeout());
relpConnection.setKeepAlive(socketConfig.keepAlive());

IManagedRelpConnection managedRelpConnection = new ManagedRelpConnection(relpConnection);

if (relpConfig.rebindEnabled) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Java Reliable Event Logging Protocol Library RLP-01
Copyright (C) 2021-2024 Suomen Kanuuna Oy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.teragrep.rlp_01.client;

import java.io.IOException;
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/teragrep/rlp_01/client/SSLContextSupplier.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Java Reliable Event Logging Protocol Library RLP-01
Copyright (C) 2021-2024 Suomen Kanuuna Oy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.teragrep.rlp_01.client;

import com.teragrep.rlp_01.pool.Stubable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Java Reliable Event Logging Protocol Library RLP-01
Copyright (C) 2021-2024 Suomen Kanuuna Oy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.teragrep.rlp_01.client;

import com.teragrep.rlp_01.SSLContextFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Java Reliable Event Logging Protocol Library RLP-01
Copyright (C) 2021-2024 Suomen Kanuuna Oy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.teragrep.rlp_01.client;

import javax.net.ssl.SSLContext;
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/teragrep/rlp_01/client/SocketConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Java Reliable Event Logging Protocol Library RLP-01
Copyright (C) 2021-2024 Suomen Kanuuna Oy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.teragrep.rlp_01.client;

public interface SocketConfig {
int readTimeout();
int writeTimeout();
int connectTimeout();
boolean keepAlive();
}
39 changes: 39 additions & 0 deletions src/main/java/com/teragrep/rlp_01/client/SocketConfigDefault.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Java Reliable Event Logging Protocol Library RLP-01
Copyright (C) 2021-2024 Suomen Kanuuna Oy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.teragrep.rlp_01.client;

public class SocketConfigDefault implements SocketConfig {
@Override
public int readTimeout() {
return 0;
}

@Override
public int writeTimeout() {
return 0;
}

@Override
public int connectTimeout() {
return 0;
}

@Override
public boolean keepAlive() {
return false;
}
}
51 changes: 51 additions & 0 deletions src/main/java/com/teragrep/rlp_01/client/SocketConfigImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Java Reliable Event Logging Protocol Library RLP-01
Copyright (C) 2021-2024 Suomen Kanuuna Oy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.teragrep.rlp_01.client;

public class SocketConfigImpl implements SocketConfig {
private final int readTimeout;
private final int writeTimeout;
private final int connectTimeout;
private final boolean keepAlive;

public SocketConfigImpl(int readTimeout, int writeTimeout, int connectTimeout, boolean keepAlive) {
this.readTimeout = readTimeout;
this.writeTimeout = writeTimeout;
this.connectTimeout = connectTimeout;
this.keepAlive = keepAlive;
}

@Override
public int readTimeout() {
return readTimeout;
}

@Override
public int writeTimeout() {
return writeTimeout;
}

@Override
public int connectTimeout() {
return connectTimeout;
}

@Override
public boolean keepAlive() {
return keepAlive;
}
}
Loading

0 comments on commit e8786c2

Please sign in to comment.