Commits

Sebastian Bub  committed 740af2f

introduced a lockObject, optimized reading speed for readTimeBasedAnalogIn

  • Participants
  • Parent commits b40a9ef

Comments (0)

Files changed (2)

File src/main/java/de/derbub/rpigpio/gpio/GpioSysFsInitializer.java

     static final String SYSFS_GPIO_VALUE_FILE_SUFFIX = "/value";
     static Map<String, ConfiguredGpio> configuredGpioMap = new HashMap<String, ConfiguredGpio>();
     static Map<ConfiguredGpio, String> currentOutputPortState = new HashMap<ConfiguredGpio, String>();
+    final Object lockObject = new Object();
 
     /**
      * return the internal map which must not be changed!
     public boolean setupAllGpioPorts() {
         FileWriter exportFileWriter = null;
         // export gpio pins
-        try {
-            File expFile = FileHandlingFactory.getFile(SYSFS_GPIO_EXPORT_FILE);
-            if (expFile.exists()) {
-                exportFileWriter = FileHandlingFactory.getFileWriter(expFile);
-                for (ConfiguredGpio gpio : configuredGpioMap.values()) {
-                    exportFileWriter.write(gpio.getGpioPin().getNumberAsStringLine());
-                    exportFileWriter.flush();
-                    log.info("Export of " + gpio);
+        synchronized (lockObject) {
+            try {
+                File expFile = FileHandlingFactory.getFile(SYSFS_GPIO_EXPORT_FILE);
+                if (expFile.exists()) {
+                    exportFileWriter = FileHandlingFactory.getFileWriter(expFile);
+                    for (ConfiguredGpio gpio : configuredGpioMap.values()) {
+                        exportFileWriter.write(gpio.getGpioPin().getNumberAsStringLine());
+                        exportFileWriter.flush();
+                        log.info("Export of " + gpio);
+                    }
+                } else {
+                    log.error("File " + SYSFS_GPIO_EXPORT_FILE + " does not exists. Check your OS or hardware.");
+                    return false;
                 }
-            } else {
-                log.error("File " + SYSFS_GPIO_EXPORT_FILE + " does not exists. Check your OS or hardware.");
+            } catch (IOException e) {
+                log.error("Got " + e.getClass().getName() + " with message: " + e.getMessage() + " with file " + SYSFS_GPIO_EXPORT_FILE);
                 return false;
-            }
-        } catch (IOException e) {
-            log.error("Got " + e.getClass().getName() + " with message: " + e.getMessage() + " with file " + SYSFS_GPIO_EXPORT_FILE);
-            return false;
-        } finally {
-            try {
-                if (null != exportFileWriter) {
-                    exportFileWriter.close();
+            } finally {
+                try {
+                    if (null != exportFileWriter) {
+                        exportFileWriter.close();
+                    }
+                } catch (Exception e) {
+                    // catch away
                 }
-            } catch (Exception e) {
-                // catch away
             }
         }
 
         // set direction of pins
         for (ConfiguredGpio gpio : configuredGpioMap.values()) {
             Direction d;
-            if(Direction.TI.equals(gpio.getDirection())){
+            if (Direction.TI.equals(gpio.getDirection())) {
                 d = Direction.IN;
             } else {
                 d = gpio.getDirection();
             }
-            if(!setDirection(gpio, d)){
+            if (!setDirection(gpio, d)) {
                 return false;
             }
         }
         return true;
     }
 
-    /** mehtod sets the direction of a gpio
+    /**
+     * mehtod sets the direction of a gpio
      *
-     * @param gpio ConfiguredGpio to set direction
+     * @param gpio      ConfiguredGpio to set direction
      * @param direction Direction to set (should be read from same gpio before (if TI direction depends on the state)
      * @return true if success, else false
      */
-    boolean setDirection(ConfiguredGpio gpio, Direction direction){
+    boolean setDirection(ConfiguredGpio gpio, Direction direction) {
         FileWriter aGpioFileWriter = null;
         File aGpioFile = null;
-        try {
-            aGpioFile = FileHandlingFactory.getFile(SYSFS_GPIO_FILE_PREFIX + gpio.getGpioPin().getNumber() + SYSFS_GPIO_DIRECTION_FILE_SUFFIX);
-            if (aGpioFile.exists()) {
-                aGpioFileWriter = FileHandlingFactory.getFileWriter(aGpioFile);
-                aGpioFileWriter.write(direction.getDirectionStringLine());
-                aGpioFileWriter.flush();
-                log.info("Set direction for " + gpio + " to " + direction);
-            } else {
-                log.error("File " + aGpioFile + " does not exists. Check previous errors.");
-                return false;
-            }
-        } catch (Exception e) {
-            log.error("Got " + e.getClass().getName() + " with message: " + e.getMessage() + " with file " + aGpioFile);
-            return false;
-        } finally {
+        synchronized (lockObject) {
             try {
-                if (null != aGpioFileWriter) {
-                    aGpioFileWriter.close();
-                }
-            } catch (Exception e) {
-                // catch away
-            } finally {
-                aGpioFileWriter = null;
-            }
-        }
-        return true;
-    }
-
-    /**
-     * methods sets the default state of each configured gpio port
-     *
-     * @return boolean success
-     */
-    public boolean setAllDefaultState() {
-        // set default state of pins
-        FileWriter aGpioFileWriter = null;
-        File aGpioFile = null;
-        for (ConfiguredGpio gpio : configuredGpioMap.values()) {
-            try {
-                currentOutputPortState.put(gpio, Integer.toString(gpio.getDefaultState()));
-                if (!Direction.OUT.equals(gpio.getDirection()) ||  gpio.getDefaultState() == ConfiguredGpio.NO_STATE) {
-                    log.debug("Set no default state for " + gpio);
-                    continue;
-                }
-                aGpioFile = FileHandlingFactory.getFile(SYSFS_GPIO_FILE_PREFIX + gpio.getGpioPin().getNumber() + SYSFS_GPIO_VALUE_FILE_SUFFIX);
+                aGpioFile = FileHandlingFactory.getFile(SYSFS_GPIO_FILE_PREFIX + gpio.getGpioPin().getNumber() + SYSFS_GPIO_DIRECTION_FILE_SUFFIX);
                 if (aGpioFile.exists()) {
                     aGpioFileWriter = FileHandlingFactory.getFileWriter(aGpioFile);
-                    aGpioFileWriter.write(gpio.getDefaultStateAsStringLine());
+                    aGpioFileWriter.write(direction.getDirectionStringLine());
                     aGpioFileWriter.flush();
-                    log.info("Set default state for " + gpio);
+                    log.info("Set direction for " + gpio + " to " + direction);
                 } else {
                     log.error("File " + aGpioFile + " does not exists. Check previous errors.");
                     return false;
     }
 
     /**
+     * methods sets the default state of each configured gpio port
+     *
+     * @return boolean success
+     */
+    public boolean setAllDefaultState() {
+        // set default state of pins
+        FileWriter aGpioFileWriter = null;
+        File aGpioFile = null;
+        synchronized (lockObject) {
+            for (ConfiguredGpio gpio : configuredGpioMap.values()) {
+                try {
+                    currentOutputPortState.put(gpio, Integer.toString(gpio.getDefaultState()));
+                    if (!Direction.OUT.equals(gpio.getDirection()) || gpio.getDefaultState() == ConfiguredGpio.NO_STATE) {
+                        log.debug("Set no default state for " + gpio);
+                        continue;
+                    }
+                    aGpioFile = FileHandlingFactory.getFile(SYSFS_GPIO_FILE_PREFIX + gpio.getGpioPin().getNumber() + SYSFS_GPIO_VALUE_FILE_SUFFIX);
+                    if (aGpioFile.exists()) {
+                        aGpioFileWriter = FileHandlingFactory.getFileWriter(aGpioFile);
+                        aGpioFileWriter.write(gpio.getDefaultStateAsStringLine());
+                        aGpioFileWriter.flush();
+                        log.info("Set default state for " + gpio);
+                    } else {
+                        log.error("File " + aGpioFile + " does not exists. Check previous errors.");
+                        return false;
+                    }
+                } catch (Exception e) {
+                    log.error("Got " + e.getClass().getName() + " with message: " + e.getMessage() + " with file " + aGpioFile);
+                    return false;
+                } finally {
+                    try {
+                        if (null != aGpioFileWriter) {
+                            aGpioFileWriter.close();
+                        }
+                    } catch (Exception e) {
+                        // catch away
+                    } finally {
+                        aGpioFileWriter = null;
+                    }
+                }
+            }
+        }
+        return true;
+    }
+
+    /**
      * methods sets all output pins to 0
      *
      * @return boolean success
         FileWriter aGpioFileWriter = null;
         File aGpioFile = null;
         boolean isSuccessful = true;
-        for (ConfiguredGpio gpio : configuredGpioMap.values()) {
-            if (!gpio.getDirection().isOutput()) {
-                continue;
-            }
-            try {
-                aGpioFile = FileHandlingFactory.getFile(SYSFS_GPIO_FILE_PREFIX + gpio.getGpioPin().getNumber() + SYSFS_GPIO_VALUE_FILE_SUFFIX);
-                if (aGpioFile.exists()) {
-                    aGpioFileWriter = FileHandlingFactory.getFileWriter(aGpioFile);
-                    aGpioFileWriter.write("0" + String.format("%n"));
-                    aGpioFileWriter.flush();
-                    log.info("Set state 0 for " + gpio);
-                } else {
-                    log.error("File " + aGpioFile + " does not exists. Check previous errors.");
-                    isSuccessful = false;
+        synchronized (lockObject) {
+            for (ConfiguredGpio gpio : configuredGpioMap.values()) {
+                if (!gpio.getDirection().isOutput()) {
+                    continue;
                 }
-            } catch (Exception e) {
-                log.error("Got " + e.getClass().getName() + " with message: " + e.getMessage() + " with file " + aGpioFile);
-                isSuccessful = false;
-            } finally {
                 try {
-                    if (null != aGpioFileWriter) {
-                        aGpioFileWriter.close();
+                    aGpioFile = FileHandlingFactory.getFile(SYSFS_GPIO_FILE_PREFIX + gpio.getGpioPin().getNumber() + SYSFS_GPIO_VALUE_FILE_SUFFIX);
+                    if (aGpioFile.exists()) {
+                        aGpioFileWriter = FileHandlingFactory.getFileWriter(aGpioFile);
+                        aGpioFileWriter.write("0" + String.format("%n"));
+                        aGpioFileWriter.flush();
+                        log.info("Set state 0 for " + gpio);
+                    } else {
+                        log.error("File " + aGpioFile + " does not exists. Check previous errors.");
+                        isSuccessful = false;
                     }
                 } catch (Exception e) {
-                    // catch away
+                    log.error("Got " + e.getClass().getName() + " with message: " + e.getMessage() + " with file " + aGpioFile);
+                    isSuccessful = false;
                 } finally {
-                    aGpioFileWriter = null;
+                    try {
+                        if (null != aGpioFileWriter) {
+                            aGpioFileWriter.close();
+                        }
+                    } catch (Exception e) {
+                        // catch away
+                    } finally {
+                        aGpioFileWriter = null;
+                    }
                 }
             }
         }
         FileWriter exportFileWriter = null;
         boolean isSuccessful = true;
         // unexport all gpio pins
-        for (ConfiguredGpio gpio : configuredGpioMap.values()) {
-            try {
-                File unexpFile = FileHandlingFactory.getFile(SYSFS_GPIO_UNEXPORT_FILE);
-                if (unexpFile.exists()) {
-                    exportFileWriter = FileHandlingFactory.getFileWriter(unexpFile);
-                    exportFileWriter.write(gpio.getGpioPin().getNumberAsStringLine());
-                    exportFileWriter.flush();
-                    log.info("Unexport of " + gpio);
-                } else {
-                    log.error("File " + SYSFS_GPIO_UNEXPORT_FILE + " does not exists. Check your OS or hardware.");
+        synchronized (lockObject) {
+            for (ConfiguredGpio gpio : configuredGpioMap.values()) {
+                try {
+                    File unexpFile = FileHandlingFactory.getFile(SYSFS_GPIO_UNEXPORT_FILE);
+                    if (unexpFile.exists()) {
+                        exportFileWriter = FileHandlingFactory.getFileWriter(unexpFile);
+                        exportFileWriter.write(gpio.getGpioPin().getNumberAsStringLine());
+                        exportFileWriter.flush();
+                        log.info("Unexport of " + gpio);
+                    } else {
+                        log.error("File " + SYSFS_GPIO_UNEXPORT_FILE + " does not exists. Check your OS or hardware.");
+                        isSuccessful = false;
+                    }
+                } catch (IOException e) {
+                    log.error("Got " + e.getClass().getName() + " with message: " + e.getMessage() + " with file " + SYSFS_GPIO_UNEXPORT_FILE);
                     isSuccessful = false;
-                }
-            } catch (IOException e) {
-                log.error("Got " + e.getClass().getName() + " with message: " + e.getMessage() + " with file " + SYSFS_GPIO_UNEXPORT_FILE);
-                isSuccessful = false;
-            } finally {
-                try {
-                    if (null != exportFileWriter) {
-                        exportFileWriter.close();
+                } finally {
+                    try {
+                        if (null != exportFileWriter) {
+                            exportFileWriter.close();
+                        }
+                    } catch (Exception e) {
+                        // catch away
                     }
-                } catch (Exception e) {
-                    // catch away
                 }
             }
         }

File src/main/java/de/derbub/rpigpio/gpio/GpioSysFsInterface.java

         return isReset && isUnexport;
     }
 
-    /** method handles timeBasedAnalogIn. See gpio.conf for exact handling
+    /**
+     * method handles timeBasedAnalogIn. See gpio.conf for exact handling
      *
      * @param gpio ConfiguredGpio must be of Direction TI (no checking here any more)
      * @return the value read or blocked state info
         log.debug("readTimeBasedAnalogIn for " + gpio);
 
         // 0. Check that it is not blocked.
-        if(isBlocked(gpio, nowForBlocking)){
+        if (isBlocked(gpio, nowForBlocking)) {
             return Integer.toString(ConfiguredGpio.BLOCKED_STATE);
         }
 
         //  1. It is reconfigured to be an output port.
-        if(!setDirection(gpio, Direction.OUT)){
+        if (!setDirection(gpio, Direction.OUT)) {
             log.error("Could not set output direction on " + gpio);
             return returnValue;
         }
         Map<ConfiguredGpio, String> outMap = new HashMap<ConfiguredGpio, String>(1);
         outMap.put(gpio, Integer.toString(gpio.getDefaultState()));
         Map<String, String> outWrittenMap = writeGpios(outMap, true); // handle as if it is isAutoTogglingThread (blocking is not checked)
-        if(Integer.toString(ConfiguredGpio.NO_STATE).equals(outWrittenMap.get(gpio.getUserdefinedName()))){
+        if (Integer.toString(ConfiguredGpio.NO_STATE).equals(outWrittenMap.get(gpio.getUserdefinedName()))) {
             log.error("Could not write default state value to " + gpio);
             return returnValue;
         }
         // 3. Wait for the time specified in AUTO.TOGGLE
         try {
             Thread.sleep(gpio.getAutoToogleTime());
-        }catch (InterruptedException e){
+        } catch (InterruptedException e) {
             log.error("sleep interrupted (shutdown in progress?).");
             return returnValue;
         }
         // 4. It is reconfigured to be an input port.
-        if(!setDirection(gpio, Direction.IN)){
+        if (!setDirection(gpio, Direction.IN)) {
             log.error("Could not set input direction on " + gpio);
             return returnValue;
         }
         // 5. It is read (in a while loop as fast as possible), until a value of (required) !DEFAULT.STATE is returned.
+        FileReader aGpioFileReader = null;
+        BufferedReader bf = null;
+        File aGpioFile = null;
         String defaultState = Integer.toString(gpio.getDefaultState());
         String currentState;
         long counter = 0L;
-        do {
-            currentState = readGpio(gpio);
-            counter++;
-        } while (defaultState.equals(currentState));
+        synchronized (lockObject) {
+            try {
+                aGpioFile = FileHandlingFactory.getFile(SYSFS_GPIO_FILE_PREFIX + gpio.getGpioPin().getNumber() + SYSFS_GPIO_VALUE_FILE_SUFFIX);
+                if (aGpioFile.exists()) {
+                    aGpioFileReader = FileHandlingFactory.getFileReader(aGpioFile);
+                    bf = new BufferedReader(aGpioFileReader);
+                    long before = System.currentTimeMillis();
+                    do {
+                        currentState =  bf.readLine();
+                        counter++;
+                    } while (defaultState.equals(currentState));
+                    log.info("Setting value to " + counter + " for " + gpio + (FileHandlingFactory.isSimulation() ? " (SIMULATION)" : ""));
+                } else {
+                    log.error("File " + aGpioFile + " does not exist. Check previous errors.");
+                }
+            } catch (Exception e) {
+                log.error("Got " + e.getClass().getName() + " with message: " + e.getMessage() + " with file " + aGpioFile);
+            } finally {
+                try {
+                    if (null != bf) {
+                        bf.close();
+                    }
+                } catch (Exception e) {
+                    // catch away
+                }
+                try {
+                    if (null != aGpioFileReader) {
+                        aGpioFileReader.close();
+                    }
+                } catch (Exception e) {
+                    // catch away
+                }
+            }
+        }
 
         // 6. The counter of the while loop is returned (which can be checked with conditions).
-        log.debug("setting value to " + counter + " for " + gpio);
         returnValue = Long.toString(counter);
         currentOutputPortState.put(gpio, returnValue);
         return returnValue;
     /**
      * methods really reads from SysFs
      *
+     * @param gpio which will be read
      * @return String read value or -1 in case of error
      */
-    private synchronized String readGpio(ConfiguredGpio gpio) {
+    private String readGpio(ConfiguredGpio gpio) {
         String returnValue = Integer.toString(ConfiguredGpio.NO_STATE);
         FileReader aGpioFileReader = null;
         BufferedReader bf = null;
         File aGpioFile = null;
-        try {
-            aGpioFile = FileHandlingFactory.getFile(SYSFS_GPIO_FILE_PREFIX + gpio.getGpioPin().getNumber() + SYSFS_GPIO_VALUE_FILE_SUFFIX);
-            if (aGpioFile.exists()) {
-                aGpioFileReader = FileHandlingFactory.getFileReader(aGpioFile);
-                bf = new BufferedReader(aGpioFileReader);
-                returnValue = bf.readLine();
-                log.info("Read " + returnValue + " for " + gpio + (FileHandlingFactory.isSimulation() ? " (SIMULATION)" : ""));
-            } else {
-                log.error("File " + aGpioFile + " does not exist. Check previous errors.");
-            }
-        } catch (Exception e) {
-            log.error("Got " + e.getClass().getName() + " with message: " + e.getMessage() + " with file " + aGpioFile);
-        } finally {
+        synchronized (lockObject) {
             try {
-                if (null != bf) {
-                    bf.close();
+                aGpioFile = FileHandlingFactory.getFile(SYSFS_GPIO_FILE_PREFIX + gpio.getGpioPin().getNumber() + SYSFS_GPIO_VALUE_FILE_SUFFIX);
+                if (aGpioFile.exists()) {
+                    aGpioFileReader = FileHandlingFactory.getFileReader(aGpioFile);
+                    bf = new BufferedReader(aGpioFileReader);
+                    returnValue = bf.readLine();
+                    log.info("Read " + returnValue + " for " + gpio + (FileHandlingFactory.isSimulation() ? " (SIMULATION)" : ""));
+                } else {
+                    log.error("File " + aGpioFile + " does not exist. Check previous errors.");
                 }
             } catch (Exception e) {
-                // catch away
-            }
-            try {
-                if (null != aGpioFileReader) {
-                    aGpioFileReader.close();
+                log.error("Got " + e.getClass().getName() + " with message: " + e.getMessage() + " with file " + aGpioFile);
+            } finally {
+                try {
+                    if (null != bf) {
+                        bf.close();
+                    }
+                } catch (Exception e) {
+                    // catch away
                 }
-            } catch (Exception e) {
-                // catch away
+                try {
+                    if (null != aGpioFileReader) {
+                        aGpioFileReader.close();
+                    }
+                } catch (Exception e) {
+                    // catch away
+                }
             }
         }
         return returnValue;
      *                             GpioOutAutoToggleThread
      * @return Map name as key and written value or -1 in case of error
      */
-    synchronized Map<String, String> writeGpios(Map<ConfiguredGpio, String> outGpioValueMap, boolean isAutoTogglingThread) {
+    Map<String, String> writeGpios(Map<ConfiguredGpio, String> outGpioValueMap, boolean isAutoTogglingThread) {
         Map<String, String> returnMap = new HashMap<String, String>();
         // set state of pins
         List<ConfiguredGpio> autoToggleList = new ArrayList<ConfiguredGpio>();
             // respect block time if not autoToggling (only on user request)
             // since blocktime > autoToggleTime, a gpio can only be in one GpioOutAutoToggleThread
             if (!isAutoTogglingThread && gpio.getBlockTime() != ConfiguredGpio.NO_DEFAULT_TIME) {
-                if(isBlocked(gpio, nowForBlocking)){
+                if (isBlocked(gpio, nowForBlocking)) {
                     returnMap.put(gpio.getUserdefinedName(), Integer.toString(ConfiguredGpio.BLOCKED_STATE));
                     continue;
                 }
         }
 
         int i = 0; // i may be needed in catch block
-        try {
-            long before = System.currentTimeMillis();
-            for (i = 0; i < perfIndex; i++) {
-                FileWriter aGpioFileWriter = perfFileWriterArray[i];
-                if (null != aGpioFileWriter) {
-                    aGpioFileWriter.write(perfValueArray[i]);
-                    aGpioFileWriter.flush();
-                } else {
-                    log.debug("File handle for file " + aGpioFile + " is null, ignoring.");
+        synchronized (lockObject) {
+            try {
+                long before = System.currentTimeMillis();
+                for (i = 0; i < perfIndex; i++) {
+                    FileWriter aGpioFileWriter = perfFileWriterArray[i];
+                    if (null != aGpioFileWriter) {
+                        aGpioFileWriter.write(perfValueArray[i]);
+                        aGpioFileWriter.flush();
+                    } else {
+                        log.debug("File handle for file " + aGpioFile + " is null, ignoring.");
+                    }
                 }
-            }
-            long after = System.currentTimeMillis();
-            log.info("Writing of gpio ports took " + (after - before) + "ms at " + after + (FileHandlingFactory.isSimulation() ? " (SIMULATION)" : ""));
-        } catch (Exception e) {
-            // if we get here, forget about timing: log and overwrite
-            log.error("Got " + e.getClass().getName() + " with message: " + e.getMessage() + " with file " + aGpioFile);
-            returnMap.put(perfileConfiguredGpioArray[i].getUserdefinedName(), Integer.toString(ConfiguredGpio.NO_STATE));
-        } finally {
-            for (i = 0; i < perfIndex; i++) {
-                FileWriter aGpioFileWriter = perfFileWriterArray[i];
-                try {
-                    if (null != aGpioFileWriter) {
-                        aGpioFileWriter.close();
-                        currentOutputPortState.put(perfileConfiguredGpioArray[i], perfValueArray[i].trim());
+                long after = System.currentTimeMillis();
+                log.info("Writing of gpio ports took " + (after - before) + "ms at " + after + (FileHandlingFactory.isSimulation() ? " (SIMULATION)" : ""));
+            } catch (Exception e) {
+                // if we get here, forget about timing: log and overwrite
+                log.error("Got " + e.getClass().getName() + " with message: " + e.getMessage() + " with file " + aGpioFile);
+                returnMap.put(perfileConfiguredGpioArray[i].getUserdefinedName(), Integer.toString(ConfiguredGpio.NO_STATE));
+            } finally {
+                for (i = 0; i < perfIndex; i++) {
+                    FileWriter aGpioFileWriter = perfFileWriterArray[i];
+                    try {
+                        if (null != aGpioFileWriter) {
+                            aGpioFileWriter.close();
+                            currentOutputPortState.put(perfileConfiguredGpioArray[i], perfValueArray[i].trim());
+                        }
+                    } catch (Exception e) {
+                        log.error("Got a " + e.getClass().getName() + " with message: " + e.getMessage() + " with file " + aGpioFile
+                            + " while closing. You may ignore this error, but the cause of upcoming errors may be here.");
+                    } finally {
+                        aGpioFileWriter = null;
                     }
-                } catch (Exception e) {
-                    log.error("Got a " + e.getClass().getName() + " with message: " + e.getMessage() + " with file " + aGpioFile
-                        + " while closing. You may ignore this error, but the cause of upcoming errors may be here.");
-                } finally {
-                    aGpioFileWriter = null;
                 }
             }
         }
     }
 
 
-    /** method checks if a gpio port is blocked. if blocking is configured must be checked before!
+    /**
+     * method checks if a gpio port is blocked. if blocking is configured must be checked before!
      *
-     * @param gpio ConfiguredGpio to check
+     * @param gpio           ConfiguredGpio to check
      * @param nowForBlocking Long millis
      * @return true if blocked
      */
-    private boolean isBlocked(ConfiguredGpio gpio, Long nowForBlocking){
-        boolean isBlocked=false;
+    private boolean isBlocked(ConfiguredGpio gpio, Long nowForBlocking) {
+        boolean isBlocked = false;
         Long blockedTimestamp = blockedMap.get(gpio);
         if (null == blockedTimestamp) {
             blockedMap.put(gpio, nowForBlocking);