@@ -570,6 +570,10 @@ public WriteFuture write(Object message, SocketAddress destination) {
570
570
}
571
571
572
572
/* End wrapped IoSession methods */
573
+ /**
574
+ * Reset the session state. It will remove the 'rename-from' and 'file-offset'
575
+ * attributes from the session
576
+ */
573
577
public void resetState () {
574
578
removeAttribute (ATTRIBUTE_RENAME_FROM );
575
579
removeAttribute (ATTRIBUTE_FILE_OFFSET );
@@ -588,10 +592,20 @@ public synchronized ServerDataConnectionFactory getDataConnection() {
588
592
}
589
593
}
590
594
595
+ /**
596
+ * Get the 'file-system' attribute
597
+ *
598
+ * @return The 'file-system' attribute value
599
+ */
591
600
public FileSystemView getFileSystemView () {
592
601
return (FileSystemView ) getAttribute (ATTRIBUTE_FILE_SYSTEM );
593
602
}
594
603
604
+ /**
605
+ * Get the 'user' attribute
606
+ *
607
+ * @return The 'user' attribute value
608
+ */
595
609
public User getUser () {
596
610
return (User ) getAttribute (ATTRIBUTE_USER );
597
611
}
@@ -605,45 +619,95 @@ public boolean isLoggedIn() {
605
619
return containsAttribute (ATTRIBUTE_USER );
606
620
}
607
621
622
+ /**
623
+ * Get the session listener
624
+ *
625
+ * @return The session listener
626
+ */
608
627
public Listener getListener () {
609
628
return (Listener ) getAttribute (ATTRIBUTE_LISTENER );
610
629
}
611
630
631
+ /**
632
+ * Set the listener attribute
633
+ *
634
+ * @param listener The listener to set
635
+ */
612
636
public void setListener (Listener listener ) {
613
637
setAttribute (ATTRIBUTE_LISTENER , listener );
614
638
}
615
639
640
+ /**
641
+ * Get a Ftp session
642
+ *
643
+ * @return a new Ftp session instance
644
+ */
616
645
public FtpSession getFtpletSession () {
617
646
return new DefaultFtpSession (this );
618
647
}
619
648
649
+ /**
650
+ * Get the session's language
651
+ *-
652
+ * @return The session language
653
+ */
620
654
public String getLanguage () {
621
655
return (String ) getAttribute (ATTRIBUTE_LANGUAGE );
622
656
}
623
657
658
+ /**
659
+ * Set the session language
660
+ *
661
+ * @param language The language to set
662
+ */
624
663
public void setLanguage (String language ) {
625
664
setAttribute (ATTRIBUTE_LANGUAGE , language );
626
665
627
666
}
628
667
629
- public String getUserArgument () {
630
- return (String ) getAttribute (ATTRIBUTE_USER_ARGUMENT );
631
- }
632
-
668
+ /**
669
+ * Set the 'user' attribute
670
+ *
671
+ * @param user The user for this session
672
+ */
633
673
public void setUser (User user ) {
634
674
setAttribute (ATTRIBUTE_USER , user );
635
675
636
676
}
637
677
678
+ /**
679
+ * Get the user argument
680
+ *
681
+ * @return The user argument to set
682
+ */
683
+ public String getUserArgument () {
684
+ return (String ) getAttribute (ATTRIBUTE_USER_ARGUMENT );
685
+ }
686
+
687
+ /**
688
+ * Set the user argument
689
+ *
690
+ * @param userArgument The user argument to set
691
+ */
638
692
public void setUserArgument (String userArgument ) {
639
693
setAttribute (ATTRIBUTE_USER_ARGUMENT , userArgument );
640
694
641
695
}
642
696
697
+ /**
698
+ * Get the max idle time
699
+ *
700
+ * @return The configured max idle time
701
+ */
643
702
public int getMaxIdleTime () {
644
703
return (Integer ) getAttribute (ATTRIBUTE_MAX_IDLE_TIME , 0 );
645
704
}
646
705
706
+ /**
707
+ * Set the max idle time for a session
708
+ *
709
+ * @param maxIdleTime Maximum time a session can idle
710
+ */
647
711
public void setMaxIdleTime (int maxIdleTime ) {
648
712
setAttribute (ATTRIBUTE_MAX_IDLE_TIME , maxIdleTime );
649
713
@@ -659,21 +723,40 @@ public void setMaxIdleTime(int maxIdleTime) {
659
723
}
660
724
}
661
725
726
+ /**
727
+ * Increment the number of failed logins
728
+ */
662
729
public synchronized void increaseFailedLogins () {
663
730
int failedLogins = (Integer ) getAttribute (ATTRIBUTE_FAILED_LOGINS , 0 );
664
731
failedLogins ++;
665
732
setAttribute (ATTRIBUTE_FAILED_LOGINS , failedLogins );
666
733
}
667
734
735
+ /**
736
+ * Get the 'failed-logins' attribute. It contains the number
737
+ * of failed logins during this session
738
+ *
739
+ * @return The number of failed logins
740
+ */
668
741
public int getFailedLogins () {
669
742
return (Integer ) getAttribute (ATTRIBUTE_FAILED_LOGINS , 0 );
670
743
}
671
744
745
+ /**
746
+ * Set the login attributes: 'login-time' and 'file-system'
747
+ *
748
+ * @param fsview The file system view
749
+ */
672
750
public void setLogin (FileSystemView fsview ) {
673
751
setAttribute (ATTRIBUTE_LOGIN_TIME , new Date ());
674
752
setAttribute (ATTRIBUTE_FILE_SYSTEM , fsview );
675
753
}
676
754
755
+ /**
756
+ * Reinitialize the session. It will disconnect the user,
757
+ * and clear the 'user', 'user-argument', 'login-time', 'file-system',
758
+ * 'rename-from' and 'file-offset' session attributes
759
+ */
677
760
public void reinitialize () {
678
761
logoutUser ();
679
762
removeAttribute (ATTRIBUTE_USER );
@@ -684,6 +767,9 @@ public void reinitialize() {
684
767
removeAttribute (ATTRIBUTE_FILE_OFFSET );
685
768
}
686
769
770
+ /**
771
+ * Logout the connected user
772
+ */
687
773
public void logoutUser () {
688
774
ServerFtpStatistics stats = ((ServerFtpStatistics ) context .getFtpStatistics ());
689
775
if (stats != null ) {
@@ -695,63 +781,96 @@ public void logoutUser() {
695
781
}
696
782
}
697
783
784
+ /**
785
+ * Get the 'file-offset' attribute value. Default to 0 if none is set
786
+ *
787
+ * @return The 'file-offset' attribute value
788
+ */
789
+ public long getFileOffset () {
790
+ return (Long ) getAttribute (ATTRIBUTE_FILE_OFFSET , 0L );
791
+ }
792
+
793
+ /**
794
+ * Set the 'file-offset' attribute value.
795
+ *
796
+ * @param fileOffset The 'file-offset' attribute value
797
+ */
698
798
public void setFileOffset (long fileOffset ) {
699
799
setAttribute (ATTRIBUTE_FILE_OFFSET , fileOffset );
700
800
701
801
}
702
802
803
+ /**
804
+ * Get the 'rename-from' attribute
805
+ *
806
+ * @return The 'rename-from' attribute value
807
+ */
808
+ public FtpFile getRenameFrom () {
809
+ return (FtpFile ) getAttribute (ATTRIBUTE_RENAME_FROM );
810
+ }
811
+
812
+ /**
813
+ * Set the 'rename-from' attribute
814
+ *
815
+ * @param renFr The 'rename-from' attribute value
816
+ */
703
817
public void setRenameFrom (FtpFile renFr ) {
704
818
setAttribute (ATTRIBUTE_RENAME_FROM , renFr );
705
819
706
820
}
707
821
708
- public FtpFile getRenameFrom () {
709
- return (FtpFile ) getAttribute (ATTRIBUTE_RENAME_FROM );
710
- }
711
-
712
- public long getFileOffset () {
713
- return (Long ) getAttribute (ATTRIBUTE_FILE_OFFSET , 0L );
822
+ /**
823
+ * Get the structure attribute. We support only <code>FILE</code>
824
+ *
825
+ * @return The structure attribute
826
+ */
827
+ public Structure getStructure () {
828
+ return (Structure ) getAttribute (ATTRIBUTE_STRUCTURE , Structure .FILE );
714
829
}
715
830
831
+ /**
832
+ * Set the transfert structure
833
+ *
834
+ * @param structure The structure (only FILE is currently supported)
835
+ */
716
836
public void setStructure (Structure structure ) {
717
837
setAttribute (ATTRIBUTE_STRUCTURE , structure );
718
838
}
719
839
840
+ /**
841
+ * Get the data type (ascii or binary)
842
+ *
843
+ * @return The data type
844
+ */
845
+ public DataType getDataType () {
846
+ return (DataType ) getAttribute (ATTRIBUTE_DATA_TYPE , DataType .ASCII );
847
+ }
848
+
849
+ /**
850
+ * Set the data type
851
+ *
852
+ * @param dataType The data type to use (ASCII or BINARY)
853
+ */
720
854
public void setDataType (DataType dataType ) {
721
855
setAttribute (ATTRIBUTE_DATA_TYPE , dataType );
722
856
723
857
}
724
858
725
859
/**
726
- * {@inheritDoc}
860
+ * Get the 'session-id' attribute. If none is set, and RandomUUID is created.
861
+ *
862
+ * @return The 'session-id' attribute value
727
863
*/
728
864
public UUID getSessionId () {
729
865
synchronized (wrappedSession ) {
730
866
if (!wrappedSession .containsAttribute (ATTRIBUTE_SESSION_ID )) {
731
867
wrappedSession .setAttribute (ATTRIBUTE_SESSION_ID , UUID .randomUUID ());
732
868
}
869
+
733
870
return (UUID ) wrappedSession .getAttribute (ATTRIBUTE_SESSION_ID );
734
871
}
735
872
}
736
873
737
- /**
738
- * Get the structure attribute. We support only <code>FILE</code>
739
- *
740
- * @return The structure attribute
741
- */
742
- public Structure getStructure () {
743
- return (Structure ) getAttribute (ATTRIBUTE_STRUCTURE , Structure .FILE );
744
- }
745
-
746
- /**
747
- * Get the data type (ascii or binary)
748
- *
749
- * @return The data type
750
- */
751
- public DataType getDataType () {
752
- return (DataType ) getAttribute (ATTRIBUTE_DATA_TYPE , DataType .ASCII );
753
- }
754
-
755
874
/**
756
875
* Get the login time
757
876
*
0 commit comments