Open keyhan opened 8 years ago
I have written a thread safe version that is not fully tested but I think could work. I could send it to you if you are interested.
Thank you, @Keyhan, send it please. BTW Channel.writeAndFlush is thread-safe so why should we synchronize externally?
I guess it does not have any timeout handling?
I was thinking something in line with:
private synchronized void send(IsoMessage isoMessage) throws InterruptedException {
sendAsync(isoMessage).sync().await();
}
public void orderSend(IsoMessage isoMessage, int timeoutperiod) throws InterruptedException, TimeoutException{
Runnable orderTask = new Runnable() {
@Override
public void run() {
try {
send(isoMessage);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
Thread orderThread = new Thread(orderTask);
orderThread.start();
Thread.sleep(timeoutperiod);
if(orderThread.isAlive()) {
orderThread.interrupt();
throw new TimeoutException("Thread " + orderThread.getName() + " has timed out.");
}
}
don't use this netty based library with blocking thread timeout handling. For multithread use
suspend fun suspendSendMsg(request: String): String {
return suspendCoroutine { continuation ->
try {
sendMsg(request) { response ->
//continuation.resumeWith(Result.failure(InternalTimeoutException( "Таймаут ответа ${request!!::class.java.canonicalName} со временем ожидания ${finalTimeout.toMillis()} миллисекунд" ) ))
continuation.resumeWith(Result.success(response))
}
} catch (e: Exception) {
LOGGER.error("что то сломалось при отправке iso сообщения", e)
throw RuntimeException("что то сломалось при отправке iso сообщения")
}
}
}
`
Hi, just a comment, it would make sense to make some methods like "send()" in client class synchronized. This would make them threadsafe, allowing multiple threads using the same client.