login about faq

I'm using the Tectia Java API 6.0.8, and I get this error: "Could not get broker fd" error when trying to use it. How to fix this?

asked Jan 17 '11 at 13:35

SSH%20KB's gravatar image

SSH KB ♦
509249246237


If using our Java-API's in multi threaded environment (Like calling the methods ReportService.getReportExcel() and/or FTPService.sFtpFileGet() in multiple threads of the same process.), then you will run into connection this issue in API versions BEFORE 6.0.9.

Please upgrade to 6.0.9 or later.

If you can't upgrade to 6.0.9 or higher, a solution is to share amongst all threads that open the session the SFT object, and synchronize it while opening the session.

Below is a small class which performs a copy using a shared SFT object as an example:

import java.net.URI;
import com.ssh.sft.File;
import com.ssh.sft.Session;
import com.ssh.sft.Sft;
import com.ssh.sft.SftException;

/**
 * This small example shows the way that sessions should be opened in
 * when willing to use JAVA-API in a multi-threaded environment.
 * 
 *  It is important that the SFT object is created by one thread, and 
 *  shared by all other threads, because the opening of the session
 *  must be synchronized among all threads.
 *  
 *  This method opens a new session, and obtains a file, either in
 *  the remote or in the local filesystem and closes the session when
 *  finished.
 */

public class SftExample_Thread implements Runnable {

    String argss;
    Sft sft;

    SftExample_Thread(String pargs)
    {
        this.argss = pargs;
    }

    SftExample_Thread(Sft psft, String pargs)
    {
        this.argss = pargs;
        this.sft = psft;
    }

    public void run() {

      try {

          if (sft == null)
            {
              throw new RuntimeException("Attempted to use Java-API in a thread without sharing Sft object.");
            }

          URI uri = new URI(this.argss);
          Session Sess;
          String dir_dest;

          // Determine destination                  
          if (uri.getRawAuthority() == null) 
            {
              Sess = sft.openLocalSession();
              dir_dest = this.argss;
            }
          else
            {
              URI session_uri = new URI(uri.getScheme(), uri.getAuthority(),
                                        null, null, null);
              synchronized(sft)
                {
                  Sess = sft.openSession(session_uri);
                }
              dir_dest = uri.getPath();
            }

          File f = Sess.getLocation(dir_dest).getFile();

          //Perform the copy, etc...

          Sess.close();
          }
        catch (SftException e)
            {
                System.err.println("Error: " + e);
            }
        catch (Exception e)
            {
                System.err.println("Error: " + e);
            }

    }
}
link

answered Jan 17 '11 at 13:38

SSH%20KB's gravatar image

SSH KB ♦
509249246237

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×7
×1

Asked: Jan 17 '11 at 13:35

Seen: 2,335 times

Last updated: Mar 14 '11 at 15:22

All user contributed content licensed under the cc-by-sa license.
Powered by OSQA.