Skip to content

Commit

Permalink
Remove @localhost and add it as and option to @pop method annotations.
Browse files Browse the repository at this point in the history
Also solve #1, ATM we don't change the semantic if we don't find a local match.
  • Loading branch information
MDosky committed Sep 25, 2017
1 parent d59a635 commit 4c51f59
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 94 deletions.
17 changes: 0 additions & 17 deletions workspace/popjava/src/popjava/annotation/Localhost.java

This file was deleted.

1 change: 1 addition & 0 deletions workspace/popjava/src/popjava/annotation/POPAsyncConc.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
@Target(ElementType.METHOD)
public @interface POPAsyncConc {
int id() default -1;
boolean localhost() default false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
@Target(ElementType.METHOD)
public @interface POPAsyncMutex {
int id() default -1;
boolean localhost() default false;
}
1 change: 1 addition & 0 deletions workspace/popjava/src/popjava/annotation/POPAsyncSeq.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
@Target(ElementType.METHOD)
public @interface POPAsyncSeq {
int id() default -1;
boolean localhost() default false;
}
2 changes: 1 addition & 1 deletion workspace/popjava/src/popjava/annotation/POPSyncConc.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
@Target(ElementType.METHOD)
public @interface POPSyncConc {
int id() default -1;
boolean localhost() default false;
}
1 change: 1 addition & 0 deletions workspace/popjava/src/popjava/annotation/POPSyncMutex.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
@Target(ElementType.METHOD)
public @interface POPSyncMutex {
int id() default -1;
boolean localhost() default false;
}
1 change: 1 addition & 0 deletions workspace/popjava/src/popjava/annotation/POPSyncSeq.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
@Target(ElementType.METHOD)
public @interface POPSyncSeq {
int id() default -1;
boolean localhost() default false;
}
1 change: 1 addition & 0 deletions workspace/popjava/src/popjava/base/Semantic.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public class Semantic {
public static final int CONCURRENT = 8;
public static final int MUTEX = 16;
public static final int SEQUENCE = 0;
public static final int LOCALHOST = 256;
}
48 changes: 33 additions & 15 deletions workspace/popjava/src/popjava/broker/Broker.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.nio.file.Paths;
import java.security.cert.Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -30,7 +31,6 @@
import popjava.PopJava;
import popjava.annotation.POPClass;
import popjava.annotation.POPParameter;
import popjava.annotation.Localhost;
import popjava.annotation.POPAsyncConc;
import popjava.annotation.POPAsyncMutex;
import popjava.annotation.POPAsyncSeq;
Expand Down Expand Up @@ -366,40 +366,58 @@ public void finalizeRequest(Request request) {

// use previously set semantics if possible
if(methodSemanticsCache.containsKey(method)){
//request.setSenmatics(methodSemanticsCache.get(method));
request.setSenmatics(methodSemanticsCache.get(method));
return;
}

Annotation[] annotations = method.getDeclaredAnnotations();
/*int semantics = 0;
Annotation[] annotations = method.getAnnotations();
int semantics = 0;
boolean isLocalhost = false;

POPSyncConc syncConc;
POPSyncSeq syncSeq;
POPSyncMutex syncMutex;
POPAsyncConc asyncConc;
POPAsyncSeq asyncSeq;
POPAsyncMutex asyncMutex;

// local semantics
if (MethodUtil.hasAnnotation(annotations, POPSyncConc.class)) {
if ((syncConc = MethodUtil.getAnnotation(annotations, POPSyncConc.class)) != null) {
semantics = Semantic.SYNCHRONOUS | Semantic.CONCURRENT;
isLocalhost = syncConc.localhost();
}
else if (MethodUtil.hasAnnotation(annotations, POPSyncSeq.class)) {
else if ((syncSeq = MethodUtil.getAnnotation(annotations, POPSyncSeq.class)) != null) {
semantics = Semantic.SYNCHRONOUS | Semantic.SEQUENCE;
isLocalhost = syncSeq.localhost();
}
else if (MethodUtil.hasAnnotation(annotations, POPSyncMutex.class)) {
else if ((syncMutex = MethodUtil.getAnnotation(annotations, POPSyncMutex.class)) != null) {
semantics = Semantic.SYNCHRONOUS | Semantic.MUTEX;
isLocalhost = syncMutex.localhost();
}
else if (MethodUtil.hasAnnotation(annotations, POPAsyncConc.class)) {
else if ((asyncConc = MethodUtil.getAnnotation(annotations, POPAsyncConc.class)) != null) {
semantics = Semantic.ASYNCHRONOUS | Semantic.CONCURRENT;
isLocalhost = asyncConc.localhost();
}
else if (MethodUtil.hasAnnotation(annotations, POPAsyncSeq.class)) {
else if ((asyncSeq = MethodUtil.getAnnotation(annotations, POPAsyncSeq.class)) != null) {
semantics = Semantic.ASYNCHRONOUS | Semantic.SEQUENCE;
isLocalhost = asyncSeq.localhost();
}
else if (MethodUtil.hasAnnotation(annotations, POPAsyncMutex.class)) {
else if ((asyncMutex = MethodUtil.getAnnotation(annotations, POPAsyncMutex.class)) != null) {
semantics = Semantic.ASYNCHRONOUS | Semantic.MUTEX;
}*/
isLocalhost = asyncMutex.localhost();
} else {
// not a semantic match, we keep what we received
// XXX this happen when we get the annotation from a superclass
semantics = request.getSenmatics();
}

// localhost only call
if (MethodUtil.hasAnnotation(annotations, Localhost.class)) {
request.setLocalhost(true);
if (isLocalhost) {
semantics |= Semantic.LOCALHOST;
}

//request.setSenmatics(semantics);
//methodSemanticsCache.put(method, semantics);
request.setSenmatics(semantics);
methodSemanticsCache.put(method, semantics);
} catch (NoSuchMethodException e) {
}

Expand Down
7 changes: 1 addition & 6 deletions workspace/popjava/src/popjava/broker/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class Request {
protected int status;

protected POPRemoteCaller remoteCaller;
private boolean localhost;

/**
* Creating a new pending request
Expand Down Expand Up @@ -225,11 +224,7 @@ public void setRemoteCaller(POPRemoteCaller callSource) {
}

boolean isLocalhost() {
return localhost;
}

public void setLocalhost(boolean localhost) {
this.localhost = localhost;
return (getSenmatics() & Semantic.LOCALHOST) != 0;
}

public RequestQueue getRequestQueue() {
Expand Down
Loading

0 comments on commit 4c51f59

Please sign in to comment.