All Forums Teradata Applications
EricSantAnna 12 posts Joined 04/11
27 Jun 2012
TPT - Load Operator consumes from a named pipe provided by a JNI process

Hi Teradata Masters,

I'm trying to provide data to be consumed by a Load Operator in my TPT script throught a named pipe.
My DATACONNECTOR Producer: (all runs local on Windows)

    DEFINE OPERATOR PIPE_READER()
    DESCRIPTION 'Define opcoes de leitura de arquivos'
    TYPE DATACONNECTOR PRODUCER
    SCHEMA T701S020_SCHEMA
    ATTRIBUTES
    (
          VARCHAR FileName                 = '\\.\pipe\mynamedpipe'
         , VARCHAR AccessModuleName         = 'np_axsmod.dll'
        , VARCHAR AccessModuleInitStr
        , VARCHAR OpenMode              = 'Read'
        , VARCHAR Format                 = 'TEXT'
    );
    
My Java application gets the file (one line tested txt file) and creates the pipe, "mynamedpipe", and write on it.
Java must use the JNI to handle named pipes, it load a C compiled DLL which includes a JNI library.

The Java application creates the named pipe e wait for the other application to connect on it.
Both sides of the pipe connected, then Java write while the other side read.

I have tested this named pipe connection with other Java application and all works fine, but when I run my TPT script, the pipe don't connect.

- If runs Java app first (create and wait to write), then, run TPT (Load operation):
TPT exit with errorcode 12, and viewing the log with tlogview the error are descripted:
    PIPE_READER: TPT19434 pmOpen failed. General failure (34): 'Could not open the requested Pipe, "\\.\pipe\mynamedpipe", because:  Acesso negado.
Obs.: "Acesso negado" = "Access denied"

- If runs TPT first, then Java app: (I waited for TPT reach the pipe read step, to run Java app)
TPT waits forever while Java app returns an error (an unknowable error =\ )

- If runs TPT first, then runs a modified read only of Java app: (I waited for TPT reach the pipe read step, to run Java app non-pipe-creation version)
TPT waits forever while Java app return an error: "Access denied"

On my C code which I had compile my DLL to Java, have nulls to security required parameters, as I have seen between C, JNI and pipe forums...

In my Google searchs, on over internet, seems which anyone had tried to do this...

Someone help me? (and forgive my horrible grammar...)

EricSantAnna 12 posts Joined 04/11
19 Oct 2012

It's simple!
My concept of pipes were wrong!

You don't need to create the pipe, the TPT creates it for you.
I tried to Read too, but I tried with the wrong Reader class (RandomAccessFile).
My working PipeLoader constructor:
private FileOutputStream pipe;
 
public PipeLoader() {
while(true) {
try {
getLogger().info("Trying to connect to " + getConnectionUrl());
pipe = new FileOutputStream(getConnectionUrl());
} catch (FileNotFoundException e) {
getLogger().debug(e.getMessage());
}
}
 
try {
Thread.sleep(6000);
} catch (InterruptedException iExc) {
iExc.printStackTrace();
}
continue;
}
 
getLogger().info(getConnectionUrl() + " conectado.");
break;
}
 My class PipeLoader implements Runnable, and in my run() method I put all my logics and writes:
 
String line = "";
BufferedReader br = ...
while((line = br.readLine()) != null) {
pipe.write(line.getBytes());
pipe.write("\n".getBytes());
}
 
Obs.: I can create the pipe from Java using JNI, but maybe, I never will use this.
 
Is this.

You must sign in to leave a comment.