-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
424 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.crucial</groupId> | ||
<artifactId>dso</artifactId> | ||
<version>2.0</version> | ||
<relativePath>../</relativePath> | ||
</parent> | ||
|
||
<artifactId>dso-aspectj</artifactId> | ||
<name>dso-aspectj</name> | ||
<description>AspectJ support for the DSO datastore.</description> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<version.aspectj>1.9.4</version.aspectj> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>dso-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.aspectj</groupId> | ||
<artifactId>aspectjrt</artifactId> | ||
<version>${version.aspectj}</version> | ||
</dependency> | ||
|
||
<!-- TEST --> | ||
|
||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>dso-server</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>dso-server</artifactId> | ||
<version>${project.version}</version> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>dso-core</artifactId> | ||
<version>${project.version}</version> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.testng</groupId> | ||
<artifactId>testng</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.infinispan</groupId> | ||
<artifactId>infinispan-commons-test</artifactId> | ||
<version>${version.infinispan}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.infinispan</groupId> | ||
<artifactId>infinispan-client-hotrod</artifactId> | ||
<version>${version.infinispan}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.infinispan</groupId> | ||
<artifactId>infinispan-component-annotations</artifactId> | ||
<version>${version.infinispan}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.9</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.nickwongdev</groupId> | ||
<artifactId>aspectj-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
31 changes: 31 additions & 0 deletions
31
aspectj/src/main/aspect/org/crucial/dso/DistributionClass.aj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.crucial.dso; | ||
|
||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.annotation.Pointcut; | ||
|
||
/** | ||
* @author Pierre Sutra | ||
*/ | ||
@Aspect | ||
public class DistributionClass { | ||
|
||
@Pointcut("call((@javax.persistence.Entity *).new(..)) " + | ||
"&& ! within(org.crucial.dso.container.BaseContainer)") | ||
public static void distributeEntity(ProceedingJoinPoint pjp) { | ||
} | ||
|
||
@Around("distributeEntity(pjp)") | ||
public Object distributionAdviceClass(ProceedingJoinPoint pjp) throws Throwable{ | ||
Factory factory = Factory.getSingleton(); | ||
return factory.getInstanceOf( | ||
pjp.getStaticPart().getSignature().getDeclaringType(), | ||
null, | ||
false, | ||
true, | ||
false, | ||
pjp.getArgs()); | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
aspectj/src/main/aspect/org/crucial/dso/DistributionField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.crucial.dso; | ||
|
||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.annotation.Pointcut; | ||
import org.crucial.dso.object.Reference; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Modifier; | ||
|
||
@Aspect | ||
public class DistributionField { | ||
|
||
// FIXME constructor? | ||
@Pointcut("set(@org.crucial.dso.Shared * *)") | ||
public static void distributeField(ProceedingJoinPoint pjp) { | ||
} | ||
|
||
@Around("distributeField(pjp)") | ||
public void distributionAdviceField(ProceedingJoinPoint pjp) throws Throwable{ | ||
Factory factory = Factory.getSingleton(); | ||
String fieldName = pjp.getStaticPart().getSignature().getName(); | ||
Class fieldClass = pjp.getArgs()[0].getClass(); | ||
|
||
// parent class name or key if referencable? | ||
String parentClassOrReference = | ||
Reference.isReferencable(pjp.getThis().getClass()) ? | ||
Reference.of(pjp.getThis()).toString() : pjp.getThis().getClass().getCanonicalName(); | ||
|
||
Field field = pjp.getStaticPart().getSignature().getDeclaringType().getDeclaredField(fieldName); | ||
if (!Modifier.isStatic(field.getModifiers())) { | ||
String key = (!field.getAnnotation(Shared.class).key().equals(Shared.DEFAULT_KEY)) ? | ||
field.getAnnotation(Shared.class).key() | ||
: fieldName + Shared.SEPARATOR + parentClassOrReference; | ||
field.setAccessible(true); | ||
field.set(pjp.getTarget(), factory.getInstanceOf( | ||
fieldClass, | ||
key, | ||
field.getAnnotation(Shared.class).readOptimization(), | ||
field.getAnnotation(Shared.class).isIdempotent(), | ||
field.getAnnotation(Shared.class).forceNew())); | ||
return; | ||
} | ||
throw new IllegalStateException("Field "+fieldName+" should not be static."); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.crucial.dso; | ||
|
||
import java.io.Externalizable; | ||
import java.io.IOException; | ||
import java.io.ObjectInput; | ||
import java.io.ObjectOutput; | ||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Modifier; | ||
|
||
/** | ||
* @author Pierre Sutra | ||
*/ | ||
public aspect Marshalling { | ||
|
||
public interface Marshallable extends Externalizable {} | ||
|
||
public void Marshallable.writeExternal(ObjectOutput objectOutput) throws IOException { | ||
try { | ||
for (Field field : this.getClass().getFields()) { | ||
if (!Modifier.isTransient(field.getModifiers()) && | ||
!Modifier.isStatic(field.getModifiers())) { | ||
Object object = field.get(this); | ||
objectOutput.writeObject(object); | ||
} | ||
} | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public void Marshallable.readExternal(ObjectInput objectInput) throws IOException, ClassNotFoundException { | ||
Factory factory = Factory.getSingleton(); | ||
try { | ||
for (Field field : this.getClass().getFields()) { // same order assumed across nodes | ||
if (!Modifier.isTransient(field.getModifiers()) && | ||
!Modifier.isStatic(field.getModifiers())){ | ||
Object value = objectInput.readObject(); | ||
field.set(this,value); | ||
} | ||
} | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
declare parents: @javax.persistence.Entity * implements Marshallable; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.crucial.dso; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Documented | ||
@Target({ElementType.FIELD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Shared { | ||
String DEFAULT_KEY = "__none"; | ||
String SEPARATOR = "#"; | ||
boolean readOptimization() default false; | ||
boolean forceNew() default false; | ||
boolean isIdempotent() default true; | ||
String key() default DEFAULT_KEY; | ||
} |
49 changes: 49 additions & 0 deletions
49
aspectj/src/test/java/org/crucial/dso/test/BaseAspectJ.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.crucial.dso.test; | ||
|
||
import javassist.util.proxy.Proxy; | ||
import org.crucial.dso.Shared; | ||
import org.crucial.dso.Factory; | ||
import org.testng.annotations.Test; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.Id; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Pierre Sutra | ||
*/ | ||
|
||
@Test(testName = "BaseAspectJ") | ||
public class BaseAspectJ { | ||
|
||
static{ | ||
Factory.forCache(new FakeCache()); | ||
} | ||
|
||
@Shared | ||
private List list; | ||
|
||
@Test | ||
public void sharedAnnotation() { | ||
list = new ArrayList(); | ||
assert list instanceof Proxy; | ||
} | ||
|
||
@Test | ||
public void entityAnnotation(){ | ||
A a = new A(); | ||
assert a instanceof Proxy; | ||
} | ||
|
||
@Entity | ||
public static class A{ | ||
|
||
public A(){} | ||
|
||
@Id | ||
private String f = "a"; | ||
|
||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
aspectj/src/test/java/org/crucial/dso/test/RemoteAspectJ.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.crucial.dso.test; | ||
|
||
import javassist.util.proxy.Proxy; | ||
import org.crucial.dso.Shared; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Test(testName = "RemoteAspectJ") | ||
public class RemoteAspectJ extends RemoteTest{ | ||
|
||
@Test(groups = {"aspectj"}) | ||
public void base() throws Exception { | ||
|
||
// 1 - constructor | ||
SimpleObject object = new SimpleObject("aspectj"); | ||
String field = object.getField(); | ||
assert field.equals("aspectj"); | ||
|
||
// 2 - constructor w. arguments | ||
SimpleObject object1 = new SimpleObject("aspectj2"); | ||
assert object1.getField().equals("aspectj2"); | ||
|
||
// 3 - equals() | ||
ShardedObject object2 = new ShardedObject("aspectj3"); | ||
assert object2.equals(object2); | ||
|
||
} | ||
|
||
@Shared | ||
List<SimpleObject> l1; | ||
|
||
@Test(groups = {"aspectj"}) | ||
public void annotation() throws Exception{ | ||
l1 = new ArrayList<>(); | ||
SimpleObject object1 = new SimpleObject(); | ||
l1.add(object1); | ||
assert l1 instanceof Proxy; | ||
assert l1.size() == 1; | ||
l1.remove(0); | ||
assert l1.size() == 1; | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.