All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.resteasy.statistics.StatisticsControllerImpl Maven / Gradle / Ivy

There is a newer version: 4.0.0.Beta5
Show newest version
package org.jboss.resteasy.statistics;

import org.jboss.resteasy.core.ResourceInvoker;
import org.jboss.resteasy.spi.statistics.MethodStatisticsLogger;
import org.jboss.resteasy.spi.statistics.StatisticsController;

import java.util.ArrayList;
import java.util.List;

public class StatisticsControllerImpl implements StatisticsController {

   // When statistics collection is OFF use the no-op's methods.
   public static final MethodStatisticsLogger EMPTY = new MethodStatisticsLogger() {
      // use all no-op methods
   };

   boolean isEnabled = false;
   List registry = new ArrayList<>();

   @Override
   public void register(ResourceInvoker invoker) {
      if(isEnabled) {
         invoker.setMethodStatisticsLogger(new MethodStatisticsLoggerImpl());
      }
      registry.add(invoker);
   }

   @Override
   public void setEnabled(boolean b) {
      if (isEnabled == b)
      {
         return;
      }

      isEnabled = b;
      if (isEnabled) {
         for (ResourceInvoker invoker : registry) {
            invoker.setMethodStatisticsLogger(new MethodStatisticsLoggerImpl());
         }
      } else {
         for (ResourceInvoker invoker : registry) {
            invoker.setMethodStatisticsLogger(EMPTY);
         }
      }
   }

   @Override
   public void reset() {
      for (ResourceInvoker invoker : registry) {
         invoker.getMethodStatisticsLogger().reset();
      }
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy