use of ca.uhn.hl7v2.protocol.impl.ServerSocketStreamSource in project pentaho-kettle by pentaho.
the class MLLPSocketCache method getServerSocketStreamSource.
public MLLPSocketCacheEntry getServerSocketStreamSource(String server, int port) throws Exception {
final String key = createKey(server, port);
MLLPSocketCacheEntry s = map.get(key);
if (s != null) {
return s;
}
// Open the socket for this server/port combination.
//
ServerSocket serverSocket = new ServerSocket(port);
StreamSource streamSource = new ServerSocketStreamSource(serverSocket, server);
MLLPTransport transport = new MLLPTransport(streamSource);
transport.connect();
final MLLPSocketCacheEntry entry = new MLLPSocketCacheEntry(serverSocket, streamSource, transport);
entry.setJobListener(new JobAdapter() {
@Override
public void jobFinished(Job job) throws KettleException {
KettleException exception = null;
try {
entry.getTransport().disconnect();
} catch (Exception e) {
exception = new KettleException(e);
}
try {
entry.getStreamSource().disconnect();
} catch (Exception e) {
exception = new KettleException(e);
}
try {
entry.getServerSocket().close();
} catch (Exception e) {
exception = new KettleException(e);
}
map.remove(key);
if (exception != null) {
throw exception;
}
}
});
// Store a copy in our map to make sure that only the first return value contains the job listener.
//
map.put(key, new MLLPSocketCacheEntry(serverSocket, streamSource, transport));
return entry;
}
Aggregations