Skip to content
Permalink
Browse files

made changes to prep for next version: 1.0.4 and reformatted code

  • Loading branch information...
stevensouza committed Apr 26, 2019
1 parent 69e6254 commit a7ef39a7ab44734632a2d2ff41ed660ca8cba527
Showing with 351 additions and 334 deletions.
  1. +1 −1 automon/src/main/java/org/automon/annotations/Monitor.java
  2. +15 −9 automon/src/main/java/org/automon/aspects/AutomonAspectBase.java
  3. +26 −25 automon/src/main/java/org/automon/aspects/AutomonJmx.java
  4. +0 −3 automon/src/main/java/org/automon/aspects/AutomonMXBean.java
  5. +6 −6 automon/src/main/java/org/automon/aspects/AutomonSpringAspect.java
  6. +7 −8 automon/src/main/java/org/automon/implementations/Micrometer.java
  7. +13 −13 automon/src/main/java/org/automon/pointcuts/Annotations.java
  8. +12 −14 automon/src/main/java/org/automon/pointcuts/Jdk.java
  9. +7 −4 automon/src/main/java/org/automon/pointcuts/Select.java
  10. +5 −3 automon/src/main/java/org/automon/pointcuts/SpringSelect.java
  11. +22 −20 automon/src/main/java/org/automon/utils/AutomonPropertiesLoader.java
  12. +0 −1 automon/src/main/java/org/automon/utils/Expirable.java
  13. +5 −4 automon/src/main/java/org/automon/utils/ExpiringMap.java
  14. +5 −5 automon/src/main/java/org/automon/utils/TimeExpirable.java
  15. +55 −57 automon/src/main/java/org/automon/utils/Utils.java
  16. +7 −6 automon/src/test/java/org/automon/aspects/AspectJBaseTest.java
  17. +5 −5 automon/src/test/java/org/automon/aspects/AutomonAspectBaseTest.java
  18. +7 −6 automon/src/test/java/org/automon/aspects/AutomonAspectTest.java
  19. +10 −10 automon/src/test/java/org/automon/aspects/AutomonSpringAspectTest.java
  20. +26 −25 automon/src/test/java/org/automon/aspects/HelloWorld.java
  21. +1 −1 automon/src/test/java/org/automon/aspects/HiWorld.java
  22. +2 −2 automon/src/test/java/org/automon/implementations/JamonTest.java
  23. +1 −1 automon/src/test/java/org/automon/implementations/JavaSimonTest.java
  24. +3 −2 automon/src/test/java/org/automon/implementations/MetricsTest.java
  25. +3 −4 automon/src/test/java/org/automon/implementations/MicrometerTest.java
  26. +1 −1 automon/src/test/java/org/automon/implementations/OpenMonBaseTest.java
  27. +8 −6 automon/src/test/java/org/automon/implementations/SharedConstants.java
  28. +8 −10 automon/src/test/java/org/automon/implementations/StatsDTest.java
  29. +1 −1 automon/src/test/java/org/automon/pointcuts/AutomonAnnotatedClass.java
  30. +2 −2 automon/src/test/java/org/automon/pointcuts/AutomonAnnotatedMethod.java
  31. +8 −6 automon/src/test/java/org/automon/pointcuts/AutomonAnnotationsTest.java
  32. +2 −1 automon/src/test/java/org/automon/pointcuts/JamonAnnotatedClass.java
  33. +1 −1 automon/src/test/java/org/automon/pointcuts/JamonAnnotatedMethod.java
  34. +8 −6 automon/src/test/java/org/automon/pointcuts/JamonAnnotationsTest.java
  35. +2 −1 automon/src/test/java/org/automon/pointcuts/JavaSimonAnnotatedClass.java
  36. +1 −1 automon/src/test/java/org/automon/pointcuts/JavaSimonAnnotatedMethod.java
  37. +7 −5 automon/src/test/java/org/automon/pointcuts/JavaSimonAnnotationsTest.java
  38. +1 −1 automon/src/test/java/org/automon/pointcuts/MetricsAnnotatedClass.java
  39. +1 −1 automon/src/test/java/org/automon/pointcuts/MetricsAnnotatedMethod.java
  40. +7 −5 automon/src/test/java/org/automon/pointcuts/MetricsAnnotationsTest.java
  41. +9 −9 automon/src/test/java/org/automon/utils/AutomonPropertiesLoaderTest.java
  42. +5 −5 automon/src/test/java/org/automon/utils/ExpiringMapTest.java
  43. +2 −2 automon/src/test/java/org/automon/utils/TimeExpirableTest.java
  44. +8 −9 automon/src/test/java/org/automon/utils/UtilsTest.java
  45. +25 −26 automon/src/test/resources/applicationContext.xml
@@ -15,6 +15,6 @@
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.CONSTRUCTOR, ElementType.METHOD})
public @interface Monitor {
public @interface Monitor {

}
@@ -1,20 +1,20 @@

package org.automon.aspects;

import java.util.Properties;
import org.automon.implementations.NullImp;
import org.automon.implementations.OpenMon;
import org.automon.implementations.OpenMonFactory;
import org.automon.utils.AutomonPropertiesLoader;
import org.automon.utils.Utils;

import java.util.Properties;

/**
* <p>Base class used in all aspects. Contains automon implementations and registers Automon
* with jmx</p>
*/

public class AutomonAspectBase {
public class AutomonAspectBase {

private OpenMonFactory factory = new OpenMonFactory(new NullImp());
private OpenMon openMon = new NullImp();
private AutomonMXBean automonJmx = new AutomonJmx(this);
@@ -41,14 +41,20 @@ public boolean isEnabled() {
return !(openMon instanceof NullImp);
}

/** Retrieve current monitoring implementation
* @return */
/**
* Retrieve current monitoring implementation
*
* @return
*/
public OpenMon getOpenMon() {
return openMon;
}

/** Set monitoring implementation such as JAMon, Metrics, or JavaSimon
* @param openMon */
/**
* Set monitoring implementation such as JAMon, Metrics, or JavaSimon
*
* @param openMon
*/
public void setOpenMon(OpenMon openMon) {
this.openMon = openMon;
}
@@ -62,7 +68,7 @@ public void setOpenMon(OpenMon openMon) {
* @param openMonKey Something like jamon, metrics, javasimon
*/
public void setOpenMon(String openMonKey) {
if (openMonKey==null || openMonKey.trim().equals("")) {
if (openMonKey == null || openMonKey.trim().equals("")) {
this.openMon = factory.getFirstInstance();
} else {
this.openMon = factory.getInstance(openMonKey);
@@ -1,33 +1,34 @@

package org.automon.aspects;

/** Registers Automon aspects with jmx so they can be managed and viewed.
/**
* Registers Automon aspects with jmx so they can be managed and viewed.
*/
public class AutomonJmx implements AutomonMXBean {

// aspect to register with jmx
private AutomonAspectBase automonAspectBase;
public AutomonJmx(AutomonAspectBase automonAspectBase) {
this.automonAspectBase = automonAspectBase;
}
public class AutomonJmx implements AutomonMXBean {

// aspect to register with jmx
private AutomonAspectBase automonAspectBase;

public AutomonJmx(AutomonAspectBase automonAspectBase) {
this.automonAspectBase = automonAspectBase;
}

@Override
public boolean isEnabled() {
return automonAspectBase.isEnabled();
}
@Override
public boolean isEnabled() {
return automonAspectBase.isEnabled();
}

@Override
public void setOpenMon(String openMonKey) {
automonAspectBase.setOpenMon(openMonKey);
}
@Override
public void setOpenMon(String openMonKey) {
automonAspectBase.setOpenMon(openMonKey);
}

@Override
public String getOpenMon() {
return automonAspectBase.getOpenMon().toString();
}
@Override
public String getOpenMon() {
return automonAspectBase.getOpenMon().toString();
}

@Override
public String getValidOpenMons() {
return automonAspectBase.getOpenMonFactory().toString();
}
@Override
public String getValidOpenMons() {
return automonAspectBase.getOpenMonFactory().toString();
}
}
@@ -1,7 +1,6 @@
package org.automon.aspects;



/**
* Jmx bean that allows AutomonAspect to be configured from a jmx console like visualvm, or jconsole
*/
@@ -22,13 +21,11 @@
public void setOpenMon(String openMon);

/**
*
* @return The current {@link org.automon.implementations.OpenMon}.
*/
public String getOpenMon();

/**
*
* @return A list of all registered {@link org.automon.implementations.OpenMon}'s.
* Values here can be used in {@link org.automon.aspects.AutomonMXBean#setOpenMon(String)}
*/
@@ -1,4 +1,3 @@

package org.automon.aspects;

import org.aspectj.lang.JoinPoint;
@@ -7,24 +6,24 @@

/**
* <p>This aspect should contain pointcut language that is compatible with Spring. Use this as your Base class if you use Spring.
* * It will also work with any AspectJ program, but will be more limited in how expressive the pointcuts can be.</p>
* * It will also work with any AspectJ program, but will be more limited in how expressive the pointcuts can be.</p>
*
* <p>Note a developer should implement and provide pointcuts that you want to monitor by implementing {@link #user_monitor()}
* and {@link #user_exceptions()}</p>
*/

@Component
public class AutomonSpringAspect extends AutomonAspectBase {
@Component
public class AutomonSpringAspect extends AutomonAspectBase {

/**
/**
* _monitor() advice - Wraps the given pointcut and calls the appropriate {@link org.automon.implementations.OpenMon} method
* at the beginning and end of the method call.
*
* @param pjp
* @return The advised methods value or void.
* @throws Throwable If the method throws a {@link java.lang.Throwable} the advice will rethrow it.
*/


public Object monitor(ProceedingJoinPoint pjp) throws Throwable {
// Note: context is typically a Timer/Monitor object returned by the monitoring implementation (Jamon, JavaSimon, Metrics,...)
@@ -43,6 +42,7 @@ public Object monitor(ProceedingJoinPoint pjp) throws Throwable {
/**
* exceptions() advice - Takes action on any Exception thrown. It typically Tracks/Counts any exceptions thrown by the pointcut.
* Note arguments are passed on to {@link org.automon.implementations.OpenMon#exception(org.aspectj.lang.JoinPoint, Throwable)}
*
* @param pjp
* @param exception
*/
@@ -12,22 +12,21 @@
/**
* {@link org.automon.implementations.OpenMon} implementation that https://micrometer.io to time methods, and count exceptions.
* Note micrometer is a wrapper for many underlying monitoring api's. It is also the default monitoring api of Spring.
*
* <p>
* To have this object share the same MeterRegistry as spring simply access it MetricRegistry via @Autowired and then call
* this classes Micrometer.setMeterRegistry(springMeterRegistry) with Springs value. Example:
*
* @Autowired
* public MetricsController(MeterRegistry registry) {
* Micrometer.setMeterRegistry(registry);
* }
*
* @Autowired public MetricsController(MeterRegistry registry) {
* Micrometer.setMeterRegistry(registry);
* }
* <p>
* # For spring see see data at http://localhost:8080/actuator/metrics
* # or you can look at an individual metric like this
*
* <p>
* # http://localhost:8080/actuator/metrics/execution(int org.tempuri.AddResponse.getAddResult())
* # or
* # http://localhost:8080/actuator/metrics/execution(int%20org.tempuri.AddResponse.getAddResult())
*
* <p>
* To enable this class for monitoring put the following in automon.properties
* #org.automon=micrometer
*/
@@ -8,7 +8,7 @@
* This model can also be followed to have automon recognize any other annotation.
*
* <p>
* Note @annotation(..) applies to method annotations, and @within(..) or within(@..) apply to class annotations.
* Note @annotation(..) applies to method annotations, and @within(..) or within(@..) apply to class annotations.
* </p>
*/
@Aspect
@@ -40,10 +40,10 @@ public void newrelic() {
}

@Pointcut(
"within(@javax.ejb.Stateless *) || @annotation(javax.ejb.Stateless) || "+
"within(@javax.ejb.Stateful *) || @annotation(javax.ejb.Stateful) || "+
"within(@javax.ejb.MessageDriven *) || @annotation(javax.ejb.MessageDriven) || "+
"within(@javax.ejb.Singleton *) || @annotation(javax.ejb.Singleton)"
"within(@javax.ejb.Stateless *) || @annotation(javax.ejb.Stateless) || " +
"within(@javax.ejb.Stateful *) || @annotation(javax.ejb.Stateful) || " +
"within(@javax.ejb.MessageDriven *) || @annotation(javax.ejb.MessageDriven) || " +
"within(@javax.ejb.Singleton *) || @annotation(javax.ejb.Singleton)"
)
public void ejb() {
}
@@ -60,11 +60,11 @@ public void spring() {
* GET, PUT, POST, DELETE and HEAD specify the HTTP request type of a resource. They are applied to methods.
*/
@Pointcut(
"@annotation(javax.ws.rs.GET) || "+
"@annotation(javax.ws.rs.PUT) || "+
"@annotation(javax.ws.rs.POST) || "+
"@annotation(javax.ws.rs.DELETE) || "+
"@annotation(javax.ws.rs.HEAD)"
"@annotation(javax.ws.rs.GET) || " +
"@annotation(javax.ws.rs.PUT) || " +
"@annotation(javax.ws.rs.POST) || " +
"@annotation(javax.ws.rs.DELETE) || " +
"@annotation(javax.ws.rs.HEAD)"
)
public void jaxrs() {
}
@@ -73,9 +73,9 @@ public void jaxrs() {
* Pointcut for jpa entities
*/
@Pointcut(
"within(@javax.persistence.Entity *) || "+
"within(@javax.persistence.MappedSuperclass *) || "+
"within(@javax.persistence.Embeddable *)"
"within(@javax.persistence.Entity *) || " +
"within(@javax.persistence.MappedSuperclass *) || " +
"within(@javax.persistence.Embeddable *)"
)
public void jpa() {
}
@@ -12,39 +12,37 @@
* the '+' at the end of the classname will also monitor any calls to any class that inherits from this one. See AspectJ documentation
* for more information.
* </p>
*
*
*/

@Aspect
public abstract class Jdk {

@Pointcut(
"call(public * java.sql.Statement+.*(..)) || " +
"call(public * java.sql.Connection+.*(..)) || " +
"call(public * java.sql.Savepoint+.*(..))"
"call(public * java.sql.Connection+.*(..)) || " +
"call(public * java.sql.Savepoint+.*(..))"
)
public void jdbc() {
}

@Pointcut(
"call(public * java.io.Writer+.*(..)) || " +
"call(public * java.io.Reader+.*(..)) || " +
"call(public * java.io.OutputStream+.*(..)) || " +
"call(public * java.io.InputStream+.*(..)) || " +
"call(public * java.io.DataInput+.*(..)) || " +
"call(public * java.io.DataOutput+.*(..))"
"call(public * java.io.Reader+.*(..)) || " +
"call(public * java.io.OutputStream+.*(..)) || " +
"call(public * java.io.InputStream+.*(..)) || " +
"call(public * java.io.DataInput+.*(..)) || " +
"call(public * java.io.DataOutput+.*(..))"
)
public void io() {
}

@Pointcut(
"call(public * java.net.SocketImpl+.*(..)) || " +
"call(public * java.net.ServerSocket+.*(..)) || " +
"call(public * java.net.DatagramSocket+.*(..)) || " +
"call(public * java.net.DatagramSocketImpl+.*(..)) || " +
"call(public * java.net.Socket+.*(..)) || " +
"call(public * java.net.URLConnection+.*(..))"
"call(public * java.net.ServerSocket+.*(..)) || " +
"call(public * java.net.DatagramSocket+.*(..)) || " +
"call(public * java.net.DatagramSocketImpl+.*(..)) || " +
"call(public * java.net.Socket+.*(..)) || " +
"call(public * java.net.URLConnection+.*(..))"
)
public void net() {
}
@@ -10,12 +10,13 @@
*
* <p>Note remember that this interface extends {@link org.automon.pointcuts.SpringSelect} and so also has all of the available
* pointcuts in that interface.</p>
*
*/
@Aspect
public abstract class Select extends SpringSelect {

/** Note this should cover everything. I had problems with jdk 1.8 if I also included preinitialization so I got rid of this one */
/**
* Note this should cover everything. I had problems with jdk 1.8 if I also included preinitialization so I got rid of this one
*/
@Pointcut("!preinitialization(*.new(..))")
public void all() {

@@ -54,7 +55,8 @@ public void packageConstructor() {

}

/** Field set pointcuts
/**
* Field set pointcuts
*/

@Pointcut("set(* *.*)")
@@ -82,7 +84,8 @@ public void packageFieldSet() {

}

/** Field get pointcuts
/**
* Field get pointcuts
*/

@Pointcut("get(* *.*)")
@@ -7,11 +7,11 @@
* Some standard pointcuts defined that are valid in Spring (execution(method)).
* They can be reused in other aspects. See {@link org.automon.pointcuts.Select}
* for more general pointcuts valid in AspectJ as a whole.
*
*/
@Aspect
public abstract class SpringSelect {
/** Method execution pointcuts
/**
* Method execution pointcuts
*/
@Pointcut("execution(* java.lang.Object.*(..))")
public void objectMethod() {
@@ -43,7 +43,9 @@ public void packageMethod() {

}

/** Pointcuts for getter and setter methods */
/**
* Pointcuts for getter and setter methods
*/
@Pointcut("execution(public void *.set*(*))")
public void setter() {
}
Oops, something went wrong.

0 comments on commit a7ef39a

Please sign in to comment.
You can’t perform that action at this time.