Skip to content
Snippets Groups Projects
Commit 44abbf09 authored by pompert's avatar pompert
Browse files

701

getHistory function added to jParmFacade
parent e59e9411
No related branches found
No related tags found
Loading
......@@ -61,4 +61,11 @@ public class jParmFacade {
double startx, double endx, int nx,
double starty, double endy, int ny) throws Exception;
// Get the parameter values for the given parameters and timeframe.
// The domain is given by the start and end values, while the time is
// given by startSolvTime and endSolveTime.
public native HashMap<String,Vector<Double>> getHistory(String parmNamePattern,
double startx, double endx, double starty,
double endy, double startSolveTime, double endSolveTime) throws Exception;
}
......@@ -86,5 +86,21 @@ public class jParmFacadeAdapter extends UnicastRemoteObject implements jParmFaca
return aM;
}
// Get the parameter values for the given parameters and timeframe.
// The domain is given by the start and end values, while the time is
// given by startSolvTime and endSolveTime.
public HashMap<String,Vector<Double>> getHistory(String parmNamePattern,
double startx, double endx, double starty,
double endy, double startSolveTime, double endSolveTime) throws RemoteException {
HashMap<String,Vector<Double>> aM=null;
try {
aM=adaptee.getHistory(parmNamePattern,startx,endx,starty,endy,startSolveTime,endSolveTime);
} catch (Exception ex) {
RemoteException anEx=new RemoteException("JNI getHistory error caused by: " + ex.getMessage());
//anEx.initCause(ex);
throw anEx;
}
return aM;
}
protected jParmFacade adaptee;
}
......@@ -44,11 +44,17 @@ public interface jParmFacadeInterface extends Remote
// An empty name pattern is the same as * (all parm names).
public Vector<String> getNames(String parmNamePattern) throws RemoteException;
// Get the parameter values for the given parameters and domain.
// The domain is given by the start and end values, while the grid is
// given by nx and ny.
public HashMap<String,Vector<Double>> getValues(String parmNamePattern,
double startx, double endx, int nx,
double starty, double endy, int ny) throws RemoteException;
// Get the parameter values for the given parameters and timeframe.
// The domain is given by the start and end values, while the time is
// given by startSolveTime and endSolveTime.
public HashMap<String,Vector<Double>> getHistory(String parmNamePattern,
double startx, double endx, double starty,
double endy, double startSolveTime, double endSolveTime) throws RemoteException;
}
......@@ -127,8 +127,6 @@ JNIEXPORT jobject JNICALL Java_nl_astron_lofar_java_cep_jparmfacade_jParmFacade_
return nameVector;
}
/*
* Class: nl_astron_lofar_java_cep_jparmfacade_jParmFacade
* Method: getValues
......@@ -209,6 +207,86 @@ JNIEXPORT jobject JNICALL Java_nl_astron_lofar_java_cep_jparmfacade_jParmFacade_
return result;
}
/*
* Class: nl_astron_lofar_java_cep_jparmfacade_jParmFacade
* Method: getHistory
* Signature: (Ljava/lang/String;DDIDDI)Ljava/util/HashMap;
*/
JNIEXPORT jobject JNICALL Java_nl_astron_lofar_java_cep_jparmfacade_jParmFacade_getHistory (JNIEnv *env, jobject obj, jstring parmNamePattern, jdouble startx, jdouble endx, jdouble starty, jdouble endy, jdouble startSolveTime, jdouble endSolveTime) {
jboolean isCopy;
jobject result;
// create the connection with the ParmDB
setParmDBConnection(env,obj);
const char* pattern = env->GetStringUTFChars (parmNamePattern, &isCopy);
map<string,vector<double> > valMap;
try {
valMap = theirPF->getHistory(pattern,startx,endx,starty,endy,startSolveTime,endSolveTime);
env->ReleaseStringUTFChars (parmNamePattern, pattern);
// Construct java Map
jclass mapClass, doubleClass, vectorClass;
jmethodID mapInit, mapPut, vectorAdd, doubleInit, vectorInit;
mapClass = env->FindClass("java/util/HashMap");
mapInit = env->GetMethodID(mapClass, "<init>", "()V");
result = env->NewObject(mapClass, mapInit);
mapPut= env->GetMethodID(mapClass, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
// Construct java Double
jobject jDouble;
doubleClass = env->FindClass ("java/lang/Double");
doubleInit = env->GetMethodID (doubleClass, "<init>", "(D)V");
// Loop through map and convert to HashMap
for (map<string,vector<double> >::const_iterator valIter=valMap.begin();
valIter != valMap.end();
valIter++) {
// Construct java Vector
jobject valVector;
vectorClass = env->FindClass("java/util/Vector");
vectorInit = env->GetMethodID(vectorClass, "<init>", "()V");
valVector = env->NewObject(vectorClass, vectorInit);
vectorAdd = env->GetMethodID(vectorClass, "add", "(Ljava/lang/Object;)Z");
for (vector<double>::const_iterator iter=valIter->second.begin();
iter != valIter->second.end();
iter++) {
jDouble = env->NewObject (doubleClass, doubleInit, *iter);
env->CallObjectMethod(valVector, vectorAdd, jDouble);
}
env->CallObjectMethod(result, mapPut, env->NewStringUTF(valIter->first.c_str()),valVector);
}
} catch (exception &ex) {
cout << "Exception during getHistory("<< pattern << "," << startx << ","
<< endx << "," << starty << "," << endy << "," << startSolveTime << ","
<< endSolveTime << ") : "<< ex.what() << endl;
string aStr= (string)ex.what();
jclass newExcCls = env->FindClass("java/lang/Exception");
if (newExcCls == 0) {
cout << "Unable to find the new exception class, give up." << endl;
// env->ReleaseStringUTFChars (parmNamePattern, pattern);
return result;
}
env->ThrowNew(newExcCls,aStr.c_str());
}
return result;
}
void setParmDBConnection(JNIEnv *env, jobject callerObject) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment