Search in sources :

Example 1 with ServerSocketStreamSource

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;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) MLLPTransport(ca.uhn.hl7v2.protocol.impl.MLLPTransport) ServerSocketStreamSource(ca.uhn.hl7v2.protocol.impl.ServerSocketStreamSource) ServerSocketStreamSource(ca.uhn.hl7v2.protocol.impl.ServerSocketStreamSource) StreamSource(ca.uhn.hl7v2.protocol.StreamSource) ServerSocket(java.net.ServerSocket) Job(org.pentaho.di.job.Job) JobAdapter(org.pentaho.di.job.JobAdapter) KettleException(org.pentaho.di.core.exception.KettleException)

Aggregations

StreamSource (ca.uhn.hl7v2.protocol.StreamSource)1 MLLPTransport (ca.uhn.hl7v2.protocol.impl.MLLPTransport)1 ServerSocketStreamSource (ca.uhn.hl7v2.protocol.impl.ServerSocketStreamSource)1 ServerSocket (java.net.ServerSocket)1 KettleException (org.pentaho.di.core.exception.KettleException)1 Job (org.pentaho.di.job.Job)1 JobAdapter (org.pentaho.di.job.JobAdapter)1