Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
05/12/08 07:34:55 (4 months ago)
Author:
dkayiwa
Message:

xforms module: upgrading to use 1.2.04 version of the openmrs api

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs-modules/xforms/trunk/src/org/openmrs/module/xforms/bluetooth/XformsBluetoothTask.java

    r3291 r4171  
    44import org.apache.commons.logging.LogFactory; 
    55import org.openmrs.api.APIException; 
    6 import org.openmrs.api.AdministrationService; 
    76import org.openmrs.api.context.Context; 
    8 import org.openmrs.api.context.ContextAuthenticationException; 
    9 import org.openmrs.scheduler.TaskConfig; 
    10 import org.openmrs.scheduler.Schedulable; 
    11 import org.openmrs.module.xforms.bluetooth.XformsBluetoothServer; 
     7import org.openmrs.scheduler.tasks.AbstractTask; 
    128 
    139 
     
    1915 * @version 1.0 
    2016 */ 
    21 public class XformsBluetoothTask implements Schedulable
     17public class XformsBluetoothTask extends AbstractTask
    2218 
    2319//       Logger 
    2420        private static Log log = LogFactory.getLog(XformsBluetoothTask.class); 
    25  
    26         // Task configuration  
    27         private TaskConfig taskConfig; 
    2821         
    2922        private static final String PROPERTY_SERVICE_NAME = "ServiceName"; 
     
    4740         * Process incoming connection. 
    4841         */ 
    49         public void run() { 
     42        public void execute() { 
    5043                Context.openSession(); 
    5144                try { 
     
    5346                                authenticate(); 
    5447                         
    55                         String serviceName = taskConfig.getProperty(PROPERTY_SERVICE_NAME); //"OpenMRS XForms Bluetooth Server" 
    56                         String serverUUID = taskConfig.getProperty(PROPERTY_SERVER_UUID); //"F0E0D0C0B0A000908070605040301111" 
    57                         String serverIP= taskConfig.getProperty(PROPERTY_SERVER_IP); //"localhost" 
     48                        String serviceName = taskDefinition.getProperty(PROPERTY_SERVICE_NAME); //"OpenMRS XForms Bluetooth Server" 
     49                        String serverUUID = taskDefinition.getProperty(PROPERTY_SERVER_UUID); //"F0E0D0C0B0A000908070605040301111" 
     50                        String serverIP= taskDefinition.getProperty(PROPERTY_SERVER_IP); //"localhost" 
    5851                         
    5952                        if(serviceName == null){ 
    6053                                serviceName = "OpenMRS XForms Bluetooth Server"; 
    61                                 taskConfig.setProperty(PROPERTY_SERVICE_NAME, serviceName); 
     54                                taskDefinition.setProperty(PROPERTY_SERVICE_NAME, serviceName); 
    6255                                log.error("Property "+PROPERTY_SERVICE_NAME+" was null. Set to "+serviceName); 
    6356                        } 
     
    6558                        if(serverUUID == null){ 
    6659                                serverUUID = "F0E0D0C0B0A000908070605040301111"; 
    67                                 taskConfig.setProperty(PROPERTY_SERVER_UUID, serverUUID); 
     60                                taskDefinition.setProperty(PROPERTY_SERVER_UUID, serverUUID); 
    6861                                log.error("Property "+PROPERTY_SERVER_UUID+" was null. Set to "+serverUUID); 
    6962                        } 
     
    7164                        if(serverIP == null){ 
    7265                                serverIP = "localhost"; 
    73                                 taskConfig.setProperty(PROPERTY_SERVER_IP, serverIP); 
     66                                taskDefinition.setProperty(PROPERTY_SERVER_IP, serverIP); 
    7467                                log.error("Property "+PROPERTY_SERVER_IP+" was null. Set to "+serverIP); 
    7568                        } 
     
    7770                        server = new XformsBluetoothServer(serviceName,serverUUID,serverIP); 
    7871                        server.start(); 
    79                          
    8072                } catch (APIException e) { 
    8173                        log.error("Error running xforms bluetooth task", e); 
     
    9183         */ 
    9284        public void shutdown() { 
    93                 System.out.println("shutdown called."); 
    94                 server.stop(); 
    95                 System.out.println("bluetoth stopped."); 
    96         } 
    97          
    98         /** 
    99          * Initialize task. 
    100          *  
    101          * @param config 
    102          */ 
    103         public void initialize(TaskConfig config) {  
    104                 this.taskConfig = config; 
    105                 taskConfig.getProperty("name"); //Just to ensure we dont get exceptons on accessing this object else where. 
    106         } 
    107          
    108         private void authenticate() { 
    109                 try { 
    110                         AdministrationService adminService = Context.getAdministrationService(); 
    111                         Context.authenticate(adminService.getGlobalProperty("scheduler.username"), 
    112                                 adminService.getGlobalProperty("scheduler.password")); 
    113                          
    114                 } catch (ContextAuthenticationException e) { 
    115                         log.error("Error authenticating user", e); 
    116                 } 
    117         } 
    118          
    119         //TODO Needs to complete implementing this. 
    120         protected void finalize(){ 
    121                 server.stop(); 
     85                if(server != null) 
     86                        server.stop(); 
     87                server = null; 
     88                super.shutdown(); 
    12289        } 
    12390}