com.telenordigital.sms.smpp.OutboundPduHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sms-smpp Show documentation
Show all versions of sms-smpp Show documentation
A smpp client library implementing SMPP specification from https://smpp.org.
package com.telenordigital.sms.smpp;
/*-
* #%L
* sms-smpp
* %%
* Copyright (C) 2022 Telenor Digital
* %%
* 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.
* #L%
*/
import com.telenordigital.sms.smpp.pdu.ResponsePdu;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageCodec;
import java.lang.invoke.MethodHandles;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
class OutboundPduHandler extends MessageToMessageCodec> {
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private final int windowSize;
private final int timeoutSeconds;
private final Map> window = new LinkedHashMap<>();
private CompletableFuture drainingFuture;
OutboundPduHandler(final int windowSize, final int timeoutSeconds) {
if (windowSize < 1) {
throw new IllegalArgumentException("Window size must be > 0");
}
this.windowSize = windowSize;
this.timeoutSeconds = timeoutSeconds;
}
private void removeExpired(final ChannelHandlerContext ctx) {
window
.entrySet()
.removeIf(
entry -> {
final var rr = entry.getValue();
final var age = System.currentTimeMillis() - rr.startedTimeMillis();
if (age > timeoutSeconds * 1_000L) {
LOG.warn("Entry expired: {}", entry);
rr.completeExceptionally(
ctx, "Request expired. No response received in " + timeoutSeconds + "s");
return true;
}
return false;
});
}
int getOpenWindowSlots() {
// this method will be called on a different thread. it is used only for monitoring purpose
return windowSize - window.size();
}
@Override
protected void encode(
final ChannelHandlerContext ctx,
final RequestResponse msg,
final List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy