commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Frazer Irving <superf...@clumsyjedi.com>
Subject Thread safety of plain FTP VFS using UserAuthenticator
Date Tue, 25 Sep 2012 12:12:00 GMT
Hi,

I have the following code:

@Autowired
public DeltaBackend(FileSystemManager fsManager, CredentialsRegistry
credentialsRegistry,
                        @Value("${delta.ftp.hostname}") String hostname,
                        @Value("${delta.ftp.port}") long port)  {
        this.fsOptions = new FileSystemOptions();
        this.credentialsRegistry = credentialsRegistry;
        this.hostname = hostname;
        this.port = port;

        FtpFileSystemConfigBuilder.getInstance().setPassiveMode(fsOptions,
true);

FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(fsOptions, false);

        this.fsManager = fsManager;

}


    private FileObject getFileObjectForUri (URI uri) throws IOException {
        try {
            String profile = uri.getHost();
            Credentials creds = credentialsRegistry.get(profile);
            UserAuthenticator auth = new
StaticUserAuthenticator(AUTH_DOMAIN, creds.username, creds.password);

DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(fsOptions,
auth);

            URI ftpUri = new URI(String.format(ftpUriTemplate, hostname,
port, uri.getPath()));
            return fsManager.resolveFile(ftpUri.toString(), fsOptions);
        } catch (URISyntaxException e) {
            throw new IllegalStateException(e);
        }
    }

Which I expect to be run within many concurrent threads. DeltaBackend is a
singleton. fsManager is created by spring by way of VFS.getManager()

The code above works in single threaded mode, but I'm wondering if it's
thread safe. At a glance I would think the whole method may benefit from
being synchronized. Any thoughts?

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message