Initial commit
This commit is contained in:
		
							parent
							
								
									0f20a7dd14
								
							
						
					
					
						commit
						9cbafc45df
					
				
							
								
								
									
										81
									
								
								jcabi/pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								jcabi/pom.xml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,81 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||||
|          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||
|          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||||
| 
 | ||||
|     <modelVersion>4.0.0</modelVersion> | ||||
|     <artifactId>jcabi</artifactId> | ||||
|     <version>0.1.0-SNAPSHOT</version> | ||||
|     <name>jcabi</name> | ||||
|     <packaging>jar</packaging> | ||||
|      | ||||
|     <parent> | ||||
|         <groupId>com.baeldung</groupId> | ||||
|         <artifactId>parent-java</artifactId> | ||||
|         <version>0.0.1-SNAPSHOT</version> | ||||
|         <relativePath>../parent-java</relativePath> | ||||
|     </parent> | ||||
| 
 | ||||
|     <dependencies> | ||||
|         <dependency> | ||||
|             <groupId>org.assertj</groupId> | ||||
|             <artifactId>assertj-core</artifactId> | ||||
|             <version>${assertj.version}</version> | ||||
|             <scope>test</scope> | ||||
|         </dependency> | ||||
|          | ||||
|         <dependency> | ||||
|             <groupId>com.jcabi</groupId> | ||||
|             <artifactId>jcabi-aspects</artifactId> | ||||
|             <version>${jcabi-aspects.version}</version> | ||||
|         </dependency> | ||||
|          | ||||
|         <dependency> | ||||
|             <groupId>org.aspectj</groupId> | ||||
|             <artifactId>aspectjrt</artifactId> | ||||
|             <version>${aspectjrt.version}</version> | ||||
|             <scope>runtime</scope> | ||||
|         </dependency> | ||||
|          | ||||
|     </dependencies> | ||||
| 
 | ||||
|     <build> | ||||
|         <finalName>jcabi</finalName> | ||||
|         <plugins> | ||||
|             <plugin> | ||||
|                 <groupId>com.jcabi</groupId> | ||||
|                 <artifactId>jcabi-maven-plugin</artifactId> | ||||
|                 <version>${jcabi-maven-plugin.version}</version> | ||||
|                 <executions> | ||||
|                     <execution> | ||||
|                         <goals> | ||||
|                             <goal>ajc</goal> | ||||
|                         </goals> | ||||
|                     </execution> | ||||
|                 </executions> | ||||
|                 <dependencies> | ||||
|                     <dependency> | ||||
|                         <groupId>org.aspectj</groupId> | ||||
|                         <artifactId>aspectjtools</artifactId> | ||||
|                         <version>${aspectjtools.version}</version> | ||||
|                     </dependency> | ||||
|                     <dependency> | ||||
|                         <groupId>org.aspectj</groupId> | ||||
|                         <artifactId>aspectjweaver</artifactId> | ||||
|                         <version>${aspectjweaver.version}</version> | ||||
|                     </dependency> | ||||
|                 </dependencies> | ||||
|             </plugin> | ||||
|         </plugins> | ||||
|     </build> | ||||
| 
 | ||||
|     <properties> | ||||
|         <assertj.version>3.14.0</assertj.version> | ||||
|         <jcabi-aspects.version>0.22.6</jcabi-aspects.version> | ||||
|         <aspectjrt.version>1.9.5</aspectjrt.version> | ||||
|         <jcabi-maven-plugin.version>0.14.1</jcabi-maven-plugin.version> | ||||
|         <aspectjtools.version>1.9.1</aspectjtools.version> | ||||
|         <aspectjweaver.version>1.9.1</aspectjweaver.version> | ||||
|     </properties> | ||||
| 
 | ||||
| </project> | ||||
							
								
								
									
										103
									
								
								jcabi/src/main/java/com/baeldung/jcabi_aspectj/Example.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										103
									
								
								jcabi/src/main/java/com/baeldung/jcabi_aspectj/Example.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,103 @@ | ||||
| package com.baeldung.jcabi_aspectj; | ||||
| 
 | ||||
| import java.util.concurrent.CompletableFuture; | ||||
| import java.util.concurrent.Future; | ||||
| import java.util.concurrent.TimeUnit; | ||||
| 
 | ||||
| import com.jcabi.aspects.Async; | ||||
| import com.jcabi.aspects.Cacheable; | ||||
| import com.jcabi.aspects.LogExceptions; | ||||
| import com.jcabi.aspects.Loggable; | ||||
| import com.jcabi.aspects.Parallel; | ||||
| import com.jcabi.aspects.Quietly; | ||||
| import com.jcabi.aspects.RetryOnFailure; | ||||
| import com.jcabi.aspects.UnitedThrow; | ||||
| 
 | ||||
| //@Loggable | ||||
| public class Example { | ||||
| 
 | ||||
|     public static void main(String[] args) { | ||||
|         try { | ||||
|             tryAsync(); | ||||
|             asyncFactorial(10).get(); | ||||
|             System.out.println("calling 2..."); | ||||
|             System.out.println(called2());     | ||||
|             //called3(); | ||||
|             called4(); | ||||
|             System.out.println(called2()); | ||||
|             System.out.println(called2()); | ||||
|             called6(); | ||||
|             //called7(); | ||||
|              | ||||
|              | ||||
|         } catch(Exception e) { | ||||
| 
 | ||||
|         } | ||||
|         called5(); | ||||
|         called8(); | ||||
|     } | ||||
| 
 | ||||
|     @Async | ||||
|     public static void tryAsync() { | ||||
|         long result = factorial(10); | ||||
|         System.out.println(result); | ||||
|     } | ||||
|      | ||||
|     @Async | ||||
|     public static Future<Long> asyncFactorial(int number) { | ||||
|         Future<Long> factorialFuture = CompletableFuture.supplyAsync(() -> factorial(number)); | ||||
|         return factorialFuture; | ||||
|     } | ||||
|      | ||||
|     /** | ||||
|      * Finds factorial of a number | ||||
|      * @param number | ||||
|      * @return | ||||
|      */ | ||||
|     public static long factorial(int number) { | ||||
|         long result = 1;  | ||||
|         for(int i=number;i>0;i--) { | ||||
|             result *= i;  | ||||
|         }  | ||||
|         return result;  | ||||
|     } | ||||
| 
 | ||||
|     @Cacheable(lifetime = 5, unit = TimeUnit.SECONDS) | ||||
|     public static Double called2() { | ||||
|         return Math.random(); | ||||
|     } | ||||
| 
 | ||||
|     @LogExceptions | ||||
|     public static void called3() { | ||||
|         System.out.println(1/0); | ||||
|     } | ||||
| 
 | ||||
|     @Loggable | ||||
|     public static void called4() { | ||||
|         System.out.println("checking loggable"); | ||||
|     } | ||||
| 
 | ||||
|     @Quietly | ||||
|     public static void called5() { | ||||
|         int x = 1/0; | ||||
|     } | ||||
| 
 | ||||
|     @Parallel(threads = 4) | ||||
|     public static void called6() { | ||||
|         System.out.println("called6"); | ||||
|     } | ||||
|      | ||||
|     @RetryOnFailure | ||||
|     //@Quietly | ||||
|     public static void called7() { | ||||
|         System.out.println("called7..."); | ||||
|         int y = 1/0; | ||||
|     } | ||||
|      | ||||
|     @UnitedThrow //(IllegalStateException.class) | ||||
|     public static void called8() { | ||||
|         System.out.println("called8..."); | ||||
|         int y = 1/0; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										5
									
								
								jcabi/src/main/java/com/baeldung/jcabi_aspectj/User.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								jcabi/src/main/java/com/baeldung/jcabi_aspectj/User.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,5 @@ | ||||
| package com.baeldung.jcabi_aspectj; | ||||
| 
 | ||||
| public class User { | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user