org.backsource.adaptor.ftp
Class FTPConnectionFactory

java.lang.Object
  extended byjavax.management.NotificationBroadcasterSupport
      extended byorg.jboss.system.ServiceMBeanSupport
          extended byorg.backsource.jmx.ServiceMBeanSupport
              extended byorg.backsource.adaptor.ftp.FTPConnectionFactory
All Implemented Interfaces:
org.backsource.adaptor.ftp.FTPConnectionFactoryMBean, javax.management.MBeanRegistration, javax.management.NotificationBroadcaster, org.jboss.system.Service, org.backsource.jmx.ServiceMBean, org.jboss.system.ServiceMBean

public class FTPConnectionFactory
extends org.backsource.jmx.ServiceMBeanSupport
implements org.backsource.adaptor.ftp.FTPConnectionFactoryMBean

First scetch of a J2ee/jdbc like ftp adaptor.

This factory is currently hardwired to use the NetFTPConnection.

The typical usage scenarion is much like usage of JDBC. Either you have a preconfigured factory that you lookup through JDBC, or it is configured manually. It is however not serializable.

 
      FTPConnectionFactory  connectionFactory = new FTPConnectionFactory();
      connectionFactory.setHostName( "localhost" );
      connectionFactory.setUser( "pra@tim.se" );
      connectionFactory.setPassword( anonymous );

      FTPConnection ftp = null;
      try {
        // Transfer a file
        ftp.put("topfile.xml", new FileInputStream( new File(dir,"topfile.xml") ) );
        // Create subdir an populate
        ftp.mkdir("mysub");
        ftp.put("mysub/subfile1.xml", new FileInputStream( new File(dir,"subfile1.xml") ) );

        // Remove stuff
        ftp.deleteFile("topfile.xml");
        ftp.deleteFile("mysub/subfile1.xml");
        // delete dir
        ftp.deleteFile("mysub");
      } catch (FTPException e) {
         // throw some own exception
      } finally {
        if ( ftp != null) {
          ftp.close();
        } // end of if ()      

      } // end of finally

      connectionFactory.stop();

Version:
$Revision: 1.1.1.1 $
Author:
Peter Antman

Field Summary
protected  EDU.oswego.cs.dl.util.concurrent.LinkedQueue connections
           
static int DEFAULT_TIMEOUT
           
protected  javax.management.ObjectName name
           
static javax.management.ObjectName OBJECT_NAME
           
protected  javax.management.MBeanServer server
           
protected  org.backsource.utils.io.CachedStream stream
           
protected  org.backsource.utils.io.CachedStreamFactory streamFactory
           
 
Fields inherited from class org.jboss.system.ServiceMBeanSupport
log, serviceName
 
Fields inherited from interface org.jboss.system.ServiceMBean
CREATE_EVENT, CREATED, DESTROY_EVENT, DESTROYED, FAILED, STARTED, STARTING, states, STOPPED, STOPPING
 
Constructor Summary
FTPConnectionFactory()
           
 
Method Summary
 org.backsource.utils.io.CachedStream getCachedStream()
          Get the cached stream (not the factory).
 FTPConnection getConnection()
          Get a new FTPConnection, may have been cached/pooled.
 java.lang.String getHostName()
          Name of the ftp server.
protected  javax.management.ObjectName getObjectName(javax.management.MBeanServer server, javax.management.ObjectName name)
           
 java.lang.String getPassword()
          Password.
 int getTimeout()
          Timeout.
 java.lang.String getUser()
          Name of the user.
protected  void releaseConnection(FTPConnection ftp)
          Hook from the connection to return the connection to the pool.
 void setCachedStreamFactory(org.backsource.utils.io.CachedStreamFactory streamFactory)
          The a CachedStreamFactory to use for stream handling; if not supplied the default one according the default configuration rules are used.
 void setHostName(java.lang.String hostName)
          Name of the ftp server.
 void setPassword(java.lang.String pwd)
          Password.
 void setTimeout(int timeout)
          Timeout.
 void setUser(java.lang.String user)
          Name of the user.
 void stop()
           
 
Methods inherited from class org.jboss.system.ServiceMBeanSupport
create, createService, destroy, destroyService, getLog, getName, getNextNotificationSequenceNumber, getServer, getServiceName, getState, getStateString, postDeregister, postRegister, preDeregister, preRegister, start, startService, stopService
 
Methods inherited from class javax.management.NotificationBroadcasterSupport
addNotificationListener, getNotificationInfo, removeNotificationListener, sendNotification
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jboss.system.ServiceMBean
getName, getState, getStateString
 
Methods inherited from interface org.jboss.system.Service
create, destroy, start
 

Field Detail

OBJECT_NAME

public static final javax.management.ObjectName OBJECT_NAME

DEFAULT_TIMEOUT

public static final int DEFAULT_TIMEOUT
See Also:
Constant Field Values

name

protected javax.management.ObjectName name

server

protected javax.management.MBeanServer server

connections

protected EDU.oswego.cs.dl.util.concurrent.LinkedQueue connections

streamFactory

protected org.backsource.utils.io.CachedStreamFactory streamFactory

stream

protected org.backsource.utils.io.CachedStream stream
Constructor Detail

FTPConnectionFactory

public FTPConnectionFactory()
Method Detail

getObjectName

protected javax.management.ObjectName getObjectName(javax.management.MBeanServer server,
                                                    javax.management.ObjectName name)
                                             throws javax.management.MalformedObjectNameException
Throws:
javax.management.MalformedObjectNameException

setHostName

public void setHostName(java.lang.String hostName)
Name of the ftp server.

Specified by:
setHostName in interface org.backsource.adaptor.ftp.FTPConnectionFactoryMBean

getHostName

public java.lang.String getHostName()
Name of the ftp server.

Specified by:
getHostName in interface org.backsource.adaptor.ftp.FTPConnectionFactoryMBean

setUser

public void setUser(java.lang.String user)
Name of the user.

Specified by:
setUser in interface org.backsource.adaptor.ftp.FTPConnectionFactoryMBean

getUser

public java.lang.String getUser()
Name of the user.

Specified by:
getUser in interface org.backsource.adaptor.ftp.FTPConnectionFactoryMBean

setPassword

public void setPassword(java.lang.String pwd)
Password.

Specified by:
setPassword in interface org.backsource.adaptor.ftp.FTPConnectionFactoryMBean

getPassword

public java.lang.String getPassword()
Password.

Specified by:
getPassword in interface org.backsource.adaptor.ftp.FTPConnectionFactoryMBean

setTimeout

public void setTimeout(int timeout)
Timeout.

Specified by:
setTimeout in interface org.backsource.adaptor.ftp.FTPConnectionFactoryMBean

setCachedStreamFactory

public void setCachedStreamFactory(org.backsource.utils.io.CachedStreamFactory streamFactory)
The a CachedStreamFactory to use for stream handling; if not supplied the default one according the default configuration rules are used.


getCachedStream

public org.backsource.utils.io.CachedStream getCachedStream()
                                                     throws FTPException
Get the cached stream (not the factory).

Throws:
FTPException

getTimeout

public int getTimeout()
Timeout.

Specified by:
getTimeout in interface org.backsource.adaptor.ftp.FTPConnectionFactoryMBean

stop

public void stop()
Specified by:
stop in interface org.jboss.system.Service

getConnection

public FTPConnection getConnection()
                            throws FTPException
Get a new FTPConnection, may have been cached/pooled.

The connection MUST be close after usage, use it much like you would use a JDBC connection.

Throws:
FTPException

releaseConnection

protected void releaseConnection(FTPConnection ftp)
Hook from the connection to return the connection to the pool.



Copyright © 2003-2004 Backsource. All Rights Reserved.