Skip to content

Commit

Permalink
Minor synchronization changes
Browse files Browse the repository at this point in the history
Synchronization of invoked methods
  • Loading branch information
neocoretechs committed Jan 8, 2022
1 parent a2e0f74 commit b259e75
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 44 deletions.
32 changes: 16 additions & 16 deletions src/com/neocoretechs/relatrix/client/RelatrixKVStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ public RelatrixKVStatement(String tmeth, Object ... o1) {
* @see com.neocoretechs.relatrix.client.RemoteRequestInterface#getClassName()
*/
@Override
public String getClassName() { return className; }
public synchronized String getClassName() { return className; }

/* (non-Javadoc)
* @see com.neocoretechs.relatrix.client.RemoteRequestInterface#getSession()
*/
@Override
public String getSession() {
public synchronized String getSession() {
if( session == null ) {
session = UUID.randomUUID().toString();
if( DEBUG )
Expand All @@ -57,24 +57,24 @@ public String getSession() {
return session;
}

protected void setSession(String session) { this.session = session; }
protected synchronized void setSession(String session) { this.session = session; }

/* (non-Javadoc)
* @see com.neocoretechs.relatrix.client.RemoteRequestInterface#getMethodName()
*/
@Override
public String getMethodName() { return methodName; }
public synchronized String getMethodName() { return methodName; }
/* (non-Javadoc)
* @see com.neocoretechs.relatrix.client.RemoteRequestInterface#getParamArray()
*/
@Override
public Object[] getParamArray() { return paramArray; }
public synchronized Object[] getParamArray() { return paramArray; }

/* (non-Javadoc)
* @see com.neocoretechs.relatrix.client.RemoteRequestInterface#getParams()
*/
@Override
public Class<?>[] getParams() {
public synchronized Class<?>[] getParams() {
//System.out.println("params:"+paramArray.length);
//for(int i = 0; i < paramArray.length; i++)
//System.out.println("paramArray "+i+"="+paramArray[i]);
Expand All @@ -84,42 +84,42 @@ public Class<?>[] getParams() {
return c;
}
@Override
public String toString() { return String.format("%s for Session:%s Class:%s Method:%s Arg:%s%n",
public synchronized String toString() { return String.format("%s for Session:%s Class:%s Method:%s Arg:%s%n",
this.getClass().getName(),session,className,methodName,
(paramArray == null || paramArray.length == 0 ? "nil" : (paramArray[0] == null ? "NULL PARAM!" : paramArray[0]))); }

@Override
public CountDownLatch getCountDownLatch() {
public synchronized CountDownLatch getCountDownLatch() {
return latch;
}
@Override
public void setCountDownLatch(CountDownLatch cdl) {
public synchronized void setCountDownLatch(CountDownLatch cdl) {
latch = cdl;
}
@Override
public CyclicBarrier getCyclicBarrier() {
public synchronized CyclicBarrier getCyclicBarrier() {
return barrier;
}
@Override
public void setCyclicBarrier(CyclicBarrier cb) {
public synchronized void setCyclicBarrier(CyclicBarrier cb) {
barrier = cb;
}
@Override
public void setLongReturn(long val) {
public synchronized void setLongReturn(long val) {
retLong = val;
}
@Override
public void setObjectReturn(Object o) {
public synchronized void setObjectReturn(Object o) {
retObj = o;
}

@Override
public long getLongReturn() {
public synchronized long getLongReturn() {
return retLong;
}

@Override
public Object getObjectReturn() {
public synchronized Object getObjectReturn() {
return retObj;
}
/**
Expand All @@ -133,7 +133,7 @@ public Object getObjectReturn() {
* because the functionality is available in whole, and we dont have to add the morphism processing aspect.
*/
@Override
public void process() throws Exception {
public synchronized void process() throws Exception {
Object result = RelatrixKVServer.relatrixMethods.invokeMethod(this);
// See if we are dealing with an object that must be remotely maintained, e.g. iterator
// which does not serialize so we front it
Expand Down
32 changes: 16 additions & 16 deletions src/com/neocoretechs/relatrix/client/RelatrixStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public RelatrixStatement(String tmeth, Object ... o1) {
* @see com.neocoretechs.relatrix.client.RemoteRequestInterface#getClassName()
*/
@Override
public String getClassName() { return className; }
public synchronized String getClassName() { return className; }
/* (non-Javadoc)
* @see com.neocoretechs.relatrix.client.RemoteRequestInterface#getSession()
*/
@Override
public String getSession() {
public synchronized String getSession() {
if( session == null ) {
session = UUID.randomUUID().toString();
if( DEBUG )
Expand All @@ -56,24 +56,24 @@ public String getSession() {
return session;
}

protected void setSession(String session) { this.session = session; }
protected synchronized void setSession(String session) { this.session = session; }

/* (non-Javadoc)
* @see com.neocoretechs.relatrix.client.RemoteRequestInterface#getMethodName()
*/
@Override
public String getMethodName() { return methodName; }
public synchronized String getMethodName() { return methodName; }
/* (non-Javadoc)
* @see com.neocoretechs.relatrix.client.RemoteRequestInterface#getParamArray()
*/
@Override
public Object[] getParamArray() { return paramArray; }
public synchronized Object[] getParamArray() { return paramArray; }

/* (non-Javadoc)
* @see com.neocoretechs.relatrix.client.RemoteRequestInterface#getParams()
*/
@Override
public Class<?>[] getParams() {
public synchronized Class<?>[] getParams() {
//System.out.println("params:"+paramArray.length);
//for(int i = 0; i < paramArray.length; i++)
//System.out.println("paramArray "+i+"="+paramArray[i]);
Expand All @@ -83,50 +83,50 @@ public Class<?>[] getParams() {
return c;
}
@Override
public String toString() { return String.format("%s for Session:%s Class:%s Method:%s Arg:%s%n",
public synchronized String toString() { return String.format("%s for Session:%s Class:%s Method:%s Arg:%s%n",
this.getClass().getName(),session,className,methodName,
(paramArray == null || paramArray.length == 0 ? "nil" : (paramArray[0] == null ? "NULL PARAM!" : paramArray[0]))); }

@Override
public CountDownLatch getCountDownLatch() {
public synchronized CountDownLatch getCountDownLatch() {
return latch;
}
@Override
public void setCountDownLatch(CountDownLatch cdl) {
public synchronized void setCountDownLatch(CountDownLatch cdl) {
latch = cdl;
}
@Override
public CyclicBarrier getCyclicBarrier() {
public synchronized CyclicBarrier getCyclicBarrier() {
return barrier;
}
@Override
public void setCyclicBarrier(CyclicBarrier cb) {
public synchronized void setCyclicBarrier(CyclicBarrier cb) {
barrier = cb;
}
@Override
public void setLongReturn(long val) {
public synchronized void setLongReturn(long val) {
retLong = val;
}
@Override
public void setObjectReturn(Object o) {
public synchronized void setObjectReturn(Object o) {
retObj = o;
}

@Override
public long getLongReturn() {
public synchronized long getLongReturn() {
return retLong;
}

@Override
public Object getObjectReturn() {
public synchronized Object getObjectReturn() {
return retObj;
}
/**
* Call methods of the main Relatrix class, which will return an instance or an object that is not Serializable
* in which case we save it server side and link it to the session for later retrieval
*/
@Override
public void process() throws Exception {
public synchronized void process() throws Exception {
Object result = RelatrixServer.relatrixMethods.invokeMethod(this);
// See if we are dealing with an object that must be remotely maintained, e.g. iterator
// which does not serialize so we front it
Expand Down
2 changes: 1 addition & 1 deletion src/com/neocoretechs/relatrix/key/IndexInstanceTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
*/
public final class IndexInstanceTable implements IndexInstanceTableInterface {
public static boolean DEBUG = true;
public static boolean DEBUG = false;
LinkedHashSet<Class> classCommits = new LinkedHashSet<Class>();
DBKey lastKey;
DBKey lastGoodKey;
Expand Down
6 changes: 3 additions & 3 deletions src/com/neocoretechs/relatrix/server/ServerInvokeMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class ServerInvokeMethod {
*/
public ServerInvokeMethod(String tclass, int tskipArgs) throws ClassNotFoundException {
//pkmnap.classClass = Class.forName(tclass);
// if we cant load it with handlerclassloader, it cant be loded. period.
// Use custom classloader?
pkmnap.classClass = hcl.loadClass(tclass, true);
pkmnap.className = pkmnap.classClass.getName();
skipArgs = tskipArgs;
Expand Down Expand Up @@ -84,7 +84,7 @@ public ServerInvokeMethod(String tclass, int tskipArgs) throws ClassNotFoundExce
* @return
* @throws Exception
*/
public Object invokeMethod(RemoteRequestInterface tmc) throws Exception {
public synchronized Object invokeMethod(RemoteRequestInterface tmc) throws Exception {
return invokeMethod(tmc, null);
}
/**
Expand All @@ -93,7 +93,7 @@ public Object invokeMethod(RemoteRequestInterface tmc) throws Exception {
* it has been used to locate this object.
* @return Object of result of method invocation
*/
public Object invokeMethod(RemoteRequestInterface tmc, Object localObject) throws Exception {
public synchronized Object invokeMethod(RemoteRequestInterface tmc, Object localObject) throws Exception {
//NoSuchMethodException, InvocationTargetException, IllegalAccessException, PowerSpaceException {
String targetMethod = tmc.getMethodName();
int methodIndex = pkmnap.methodNames.indexOf(targetMethod);
Expand Down
17 changes: 9 additions & 8 deletions src/com/neocoretechs/relatrix/test/EmbeddedRetrievalBattery.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,26 @@ public static void battery1(String[] argv) throws Exception {
rkvc = new RelatrixClient(argv[0], argv[1], Integer.parseInt(argv[2]) );
RemoteTailSetIterator it = null;
System.out.println("Wildcard queries:");

System.out.println("1.) Findset(*,*,*)...");
it = rkvc.findSet("*", "*", "*");

System.out.println("2.) Findset(*,*,?)...");
it = rkvc.findSet("*", "*", "?");
//ar = new ArrayList<Comparable>();
while(rkvc.hasNext(it)) {
Object o = rkvc.next(it);
Comparable[] c = (Comparable[])o;
System.out.println(++recs+"="+c[0]);
//ar.add(c[0]);
if(ar.size() == 0 ) ar.add(c[0]);
}

System.out.println("2.) Findset(*,*,?)...");
it = rkvc.findSet("*", "*", "?");
//ar = new ArrayList<Comparable>();
System.out.println("1.) Findset(*,*,*)...");
it = rkvc.findSet("*", "*", "*");
while(rkvc.hasNext(it)) {
Object o = rkvc.next(it);
Comparable[] c = (Comparable[])o;
System.out.println(++recs+"="+c[0]);
if(ar.size() == 0 ) ar.add(c[0]);
//ar.add(c[0]);
}

System.out.println("3.) Findset(*,?,*)...");
it = rkvc.findSet("*", "?", "*");
//ar = new ArrayList<Comparable>();
Expand Down

0 comments on commit b259e75

Please sign in to comment.