package ru.taximaxim.pgsqlblocks.dbcdata;

import org.apache.log4j.Logger;
import ru.taximaxim.pgsqlblocks.utils.Settings;

import java.text.MessageFormat;

public class DbcDataRunner implements Runnable {
    private static final Logger LOG = Logger.getLogger(DbcDataRunner.class);
    private DbcDataListBuilder dbcDataBuilder;
    private DbcData dbcData;
    private Settings settings = Settings.getInstance();

    public DbcDataRunner(DbcData data, DbcDataListBuilder dataBuilder) {
        dbcData = data;
        dbcDataBuilder = dataBuilder;
    }

    @Override
    public void run() {
        try {
            if (!dbcData.isConnected()) {
                LOG.debug(MessageFormat.format("  Connecting \"{0}\"...", dbcData.getName()));
                dbcData.connect();
            }
            if (dbcData.getStatus() == DbcStatus.ERROR) {
                LOG.warn(MessageFormat.format("  Error on DbcData: {0}", dbcData.getName()));
                dbcDataBuilder.removeScheduledUpdater(dbcData);
            } else {
                if (dbcData.isConnected()) {
                    dbcData.setStatus(DbcStatus.UPDATE);
                    LOG.info(MessageFormat.format("  Updating \"{0}\"...", dbcData.getName()));
                    if (settings.isOnlyBlocked()) {
                        dbcData.setProcess(dbcData.getOnlyBlockedProcessTree());
                    } else {
                        dbcData.setProcess(dbcData.getProcessTree());
                    }
                } else {
                    LOG.warn(MessageFormat.format(" DbcData not connected: \"{0}\"", dbcData.getName()));
                }
            }
        } catch (Exception e) {
            LOG.error(MessageFormat.format("  Error on connect or update DbcData: {0}", e.getMessage()));
        }
        LOG.debug(MessageFormat.format("  Finish updating \"{0}\"...", dbcData.getName()));
        dbcData.notifyUpdated();
    }
}

@@ -1014,36 +1014,25 @@
            %7D
- else %7B%0A    
+%0A
             
@@ -1068,36 +1068,32 @@
                 
-    
 dbcData.setStatu
@@ -1125,28 +1125,24 @@
             
-  
-  
 LOG.info(Mes
@@ -1217,28 +1217,24 @@
             
-    
 if (settings
@@ -1265,36 +1265,32 @@
                 
-  
-  
 dbcData.setProce
@@ -1338,36 +1338,32 @@
                 
-    
 %7D else %7B%0A       
@@ -1367,36 +1367,32 @@
                 
-  
-  
 dbcData.setProce
@@ -1433,34 +1433,26 @@
             
-    %7D%0A    
+%7D%0A
             
@@ -1452,36 +1452,32 @@
        %7D else %7B%0A
-    
                 
@@ -1562,34 +1562,16 @@
 me()));%0A
-                %7D%0A
         

fix update canceling and process terminating and canceling