@@ -70,68 +70,97 @@ public void handleCommand(ChannelUID channelUID, Command command) {
7070 @ Override
7171 public void initialize () {
7272 config = getConfigAs (AzureBlobWatcherConfiguration .class );
73+ logger .debug (
74+ "Initializing Azure Blob Watcher handler for {} with account: {}, container: {}, anonymous: {}, poll interval: {}s" ,
75+ thing .getUID (), config .azureAccountName , config .azureContainerName , config .azureAnonymous ,
76+ config .pollIntervalAzure );
7377 if (config .azureAccountName .isBlank () || config .azureContainerName .isBlank ()) {
78+ logger .debug ("Azure configuration invalid: account={}, container={}" , config .azureAccountName ,
79+ config .azureContainerName );
7480 updateStatus (ThingStatus .OFFLINE , ThingStatusDetail .CONFIGURATION_ERROR ,
7581 "Account name or container configuration is invalid" );
7682 return ;
77- } else if (config .pollIntervalAzure == 0 ) {
83+ } else if (config .pollIntervalAzure <= 0 ) {
84+ logger .debug ("Polling interval is zero or negative" );
7885 updateStatus (ThingStatus .OFFLINE , ThingStatusDetail .CONFIGURATION_ERROR ,
7986 "Polling interval must be greater than 0 seconds" );
8087 return ;
8188 }
8289
8390 if (config .azureAnonymous ) {
91+ logger .debug ("Creating Azure connection with anonymous access" );
8492 azure = new AzureActions (httpClientFactory , config .azureAccountName , config .azureContainerName );
8593 } else {
94+ logger .debug ("Creating Azure connection with access key" );
8695 azure = new AzureActions (httpClientFactory , config .azureAccountName , config .azureContainerName ,
8796 config .azureAccessKey );
8897 }
98+ logger .debug ("Starting Azure blob refresh with {} second interval" , config .pollIntervalAzure );
8999 updateStatus (ThingStatus .UNKNOWN );
90100 executionJob = scheduler .scheduleWithFixedDelay (this ::refreshAzureBlobInformation , 0 , config .pollIntervalAzure ,
91101 TimeUnit .SECONDS );
92102 }
93103
94104 private boolean refreshAzureBlobInformation () {
105+ logger .debug ("Refreshing Azure blob container information for {}/{}" , config .azureAccountName ,
106+ config .azureContainerName );
95107 if (previousBlobListing .isEmpty ()) {
96108 try {
109+ logger .debug ("Initializing Azure listing file for account: {}, container: {}" , config .azureAccountName ,
110+ config .azureContainerName );
97111 previousBlobListing = WatcherCommon .initStorage (currentBlobListingFile ,
98112 config .azureAccountName + "-" + config .azureContainerName );
113+ logger .debug ("Loaded {} previous Azure files from storage" , previousBlobListing .size ());
99114 } catch (Exception e ) {
115+ logger .debug ("Exception initializing Azure listing file: {}" , e .getMessage ());
100116 updateStatus (ThingStatus .OFFLINE , ThingStatusDetail .COMMUNICATION_ERROR ,
101117 "Local storage initialization error: " + e .getMessage ());
102118 logger .debug ("Can't write file {}: {}" , currentBlobListingFile , e .getMessage ());
103- executionJob .cancel (false );
119+ ScheduledFuture <?> executionJob = this .executionJob ;
120+ if (executionJob != null ) {
121+ executionJob .cancel (false );
122+ }
104123 return false ;
105124 }
106125 }
107126
108127 List <String > currentBlobListing = new ArrayList <>();
109128 try {
110129 currentBlobListing = azure .listContainer (config .containerPath );
130+ logger .debug ("Azure container scan found {} total files" , currentBlobListing .size ());
111131 updateStatus (ThingStatus .ONLINE );
112132 List <String > difBlobListing = new ArrayList <>(currentBlobListing );
113133 difBlobListing .removeAll (previousBlobListing );
114- difBlobListing .forEach (file -> triggerChannel (CHANNEL_NEWFILE , file ));
134+ logger .debug ("Detected {} new Azure files since last refresh" , difBlobListing .size ());
135+ difBlobListing .forEach (file -> {
136+ logger .trace ("Triggering CHANNEL_NEWFILE with: {}" , file );
137+ triggerChannel (CHANNEL_NEWFILE , file );
138+ });
115139
116140 if (!difBlobListing .isEmpty ()) {
141+ logger .debug ("Saving {} new files to listing file" , difBlobListing .size ());
117142 WatcherCommon .saveNewListing (difBlobListing , currentBlobListingFile );
118143 }
144+ logger .debug ("Azure refresh completed, updated previous listing from {} to {} files" ,
145+ previousBlobListing .size (), currentBlobListing .size ());
119146 previousBlobListing = new ArrayList <>(currentBlobListing );
120147 } catch (Exception e ) {
148+ logger .debug ("Exception connecting to Azure container: {}" , e .getMessage (), e );
121149 updateStatus (ThingStatus .OFFLINE , ThingStatusDetail .COMMUNICATION_ERROR ,
122- "Can't connect to the contaner: " + e .getMessage ());
123- logger .debug ("Can't connect to the contaner: {}" , e .getMessage ());
150+ "Can't connect to the container: " + e .getMessage ());
124151 return false ;
125152 }
126153 return true ;
127154 }
128155
129156 @ Override
130157 public void dispose () {
158+ logger .debug ("Disposing Azure Blob Watcher handler for {}" , thing .getUID ());
131159 ScheduledFuture <?> executionJob = this .executionJob ;
132160 if (executionJob != null ) {
133161 executionJob .cancel (true );
134162 this .executionJob = null ;
163+ logger .debug ("Cancelled execution job" );
135164 }
136165 }
137166}
0 commit comments