Commit a27529a3 authored by claes's avatar claes

Subscription of arrays

parent 2d8ffd26
...@@ -250,6 +250,120 @@ JNIEXPORT jstring JNICALL Java_jpwr_rt_Gdh_getObjectRefInfoString ...@@ -250,6 +250,120 @@ JNIEXPORT jstring JNICALL Java_jpwr_rt_Gdh_getObjectRefInfoString
} }
} }
JNIEXPORT jfloatArray JNICALL Java_jpwr_rt_Gdh_getObjectRefInfoFloatArray
(JNIEnv *env, jclass obj, jint id, jint size)
{
jfloatArray jfloatArr = (*env)->NewFloatArray(env, size);
if(jfloatArr == NULL || ((float *)id == NULL) )
{
//something very weird has happen
return (jfloatArray)NULL;
}
(*env)->SetFloatArrayRegion(env, jfloatArr, 0, size, (jfloat *)id);
return jfloatArr;
}
JNIEXPORT jbooleanArray JNICALL Java_jpwr_rt_Gdh_getObjectRefInfoBooleanArray
(JNIEnv *env, jclass obj, jint id, jint size)
{
jbooleanArray jbooleanArr = (*env)->NewBooleanArray(env, size);
if(jbooleanArr == NULL || ((pwr_tBoolean *)id == NULL) )
{
//something very weird has happen
return (jbooleanArray)NULL;
}
(*env)->SetBooleanArrayRegion(env, jbooleanArr, 0, size, (jboolean *)id);
return jbooleanArr;
}
JNIEXPORT jintArray JNICALL Java_jpwr_rt_Gdh_getObjectRefInfoIntArray
(JNIEnv *env, jclass obj, jint id, jint size)
{
jintArray jintArr = (*env)->NewIntArray(env, size);
if(jintArr == NULL || ((pwr_tInt32 *)id == NULL) )
{
//something very weird has happen
return (jintArray)NULL;
}
(*env)->SetIntArrayRegion(env, jintArr, 0, size, (jint *)id);
return jintArr;
}
JNIEXPORT jobjectArray JNICALL Java_jpwr_rt_Gdh_getObjectRefInfoStringArray
(JNIEnv *env, jclass obj, jint id, jint jtypeid, jint size, jint elements)
{
pwr_tTypeId typeid;
jobjectArray jobjectArr;
int i = 0;
//find the class for String[]
jclass strArrCls = (*env)->FindClass(env, "java/lang/String");
if(strArrCls == NULL)
{
return (jobjectArray)NULL;
}
//create a new String[]
jobjectArr = (*env)->NewObjectArray(env, elements, strArrCls, NULL);
printf("size=%d\n", size);
typeid = (pwr_tTypeId) jtypeid;
if ( typeid == 0 || typeid == pwr_eType_String)
{
// String is default
//put the result in an objectarray of Strings
for(i=0;i<elements;i++)
{
(*env)->SetObjectArrayElement(env, jobjectArr, i, (*env)->NewStringUTF( env, (char *)id));
id += size;
}
}
else
{
char buffer[256];
int len;
/*
switch( typeid) {
case pwr_eType_Objid:
size = sizeof(pwr_tObjid);
break;
case pwr_eType_AttrRef:
size = sizeof(pwr_tAttrRef);
break;
case pwr_eType_Time:
size = sizeof(pwr_tTime);
break;
case pwr_eType_DeltaTime:
size = sizeof(pwr_tDeltaTime);
break;
default:
size = 4;
}
*/
//put the result in an objectarray of Strings
for(i=0;i<elements;i++)
{
gdh_AttrToString( typeid, (void *)id, buffer, sizeof(buffer),
&len, NULL);
(*env)->SetObjectArrayElement(env, jobjectArr, i, (*env)->NewStringUTF( env, (char *)buffer));
id += size;
}
}
return jobjectArr;
}
JNIEXPORT jobject JNICALL Java_jpwr_rt_Gdh_refObjectInfo JNIEXPORT jobject JNICALL Java_jpwr_rt_Gdh_refObjectInfo
(JNIEnv *env, jclass obj, jstring name) (JNIEnv *env, jclass obj, jstring name)
...@@ -282,8 +396,8 @@ JNIEXPORT jobject JNICALL Java_jpwr_rt_Gdh_refObjectInfo ...@@ -282,8 +396,8 @@ JNIEXPORT jobject JNICALL Java_jpwr_rt_Gdh_refObjectInfo
if(gdhrRefObjectInfo_cid == NULL) if(gdhrRefObjectInfo_cid == NULL)
{ {
gdhrRefObjectInfo_cid = (*env)->GetMethodID( env, gdhrRefObjectInfo_id, gdhrRefObjectInfo_cid = (*env)->GetMethodID( env, gdhrRefObjectInfo_id,
"<init>", "(Ljpwr/rt/PwrtRefId;III)V"); "<init>", "(Ljpwr/rt/PwrtRefId;IIIII)V");
//printf("gdhrRefObjectInfo_cid initierad\n");
if(gdhrRefObjectInfo_cid == NULL) if(gdhrRefObjectInfo_cid == NULL)
{ {
printf("fel vid init av gdhrRefObjectInfo_cid\n"); printf("fel vid init av gdhrRefObjectInfo_cid\n");
...@@ -315,6 +429,7 @@ JNIEXPORT jobject JNICALL Java_jpwr_rt_Gdh_refObjectInfo ...@@ -315,6 +429,7 @@ JNIEXPORT jobject JNICALL Java_jpwr_rt_Gdh_refObjectInfo
{ {
typeid = pwr_eType_Boolean; typeid = pwr_eType_Boolean;
size = sizeof(pwr_tBoolean); size = sizeof(pwr_tBoolean);
elements = 1;
} }
sts = gdh_RefObjectInfo( cstr, &attr_p, &subid, size); sts = gdh_RefObjectInfo( cstr, &attr_p, &subid, size);
...@@ -332,8 +447,11 @@ JNIEXPORT jobject JNICALL Java_jpwr_rt_Gdh_refObjectInfo ...@@ -332,8 +447,11 @@ JNIEXPORT jobject JNICALL Java_jpwr_rt_Gdh_refObjectInfo
id = 0; id = 0;
jsts = (jint) sts; jsts = (jint) sts;
//we want the size of each element not the hole object
if(elements > 0)
size = size/elements;
return_obj = (*env)->NewObject( env, gdhrRefObjectInfo_id, return_obj = (*env)->NewObject( env, gdhrRefObjectInfo_id,
gdhrRefObjectInfo_cid, refid_obj, id, jsts, (jint)typeid); gdhrRefObjectInfo_cid, refid_obj, id, jsts, (jint)typeid, (jint)elements, (jint)size);
return return_obj; return return_obj;
} }
...@@ -472,7 +590,6 @@ JNIEXPORT jobject JNICALL Java_jpwr_rt_Gdh_objidToName ...@@ -472,7 +590,6 @@ JNIEXPORT jobject JNICALL Java_jpwr_rt_Gdh_objidToName
{ {
cdhrString_cid = (*env)->GetMethodID( env, cdhrString_id, cdhrString_cid = (*env)->GetMethodID( env, cdhrString_id,
"<init>", "(Ljava/lang/String;I)V"); "<init>", "(Ljava/lang/String;I)V");
//printf("cdhrString_cid initierad\n");
} }
PwrtObjid_id = (*env)->FindClass( env, "jpwr/rt/PwrtObjid"); PwrtObjid_id = (*env)->FindClass( env, "jpwr/rt/PwrtObjid");
...@@ -480,7 +597,6 @@ JNIEXPORT jobject JNICALL Java_jpwr_rt_Gdh_objidToName ...@@ -480,7 +597,6 @@ JNIEXPORT jobject JNICALL Java_jpwr_rt_Gdh_objidToName
{ {
PwrtObjid_getOix = (*env)->GetMethodID( env, PwrtObjid_id, "getOix", "()I"); PwrtObjid_getOix = (*env)->GetMethodID( env, PwrtObjid_id, "getOix", "()I");
PwrtObjid_getVid = (*env)->GetMethodID( env, PwrtObjid_id, "getVid", "()I"); PwrtObjid_getVid = (*env)->GetMethodID( env, PwrtObjid_id, "getVid", "()I");
//printf("PwrtObjid_xxx initierad\n");
} }
objid.oix = (*env)->CallIntMethod( env, objid_obj, PwrtObjid_getOix); objid.oix = (*env)->CallIntMethod( env, objid_obj, PwrtObjid_getOix);
...@@ -556,7 +672,6 @@ JNIEXPORT jobject JNICALL Java_jpwr_rt_Gdh_getChild ...@@ -556,7 +672,6 @@ JNIEXPORT jobject JNICALL Java_jpwr_rt_Gdh_getChild
{ {
cdhrObjid_cid = (*env)->GetMethodID( env, cdhrObjid_id, cdhrObjid_cid = (*env)->GetMethodID( env, cdhrObjid_id,
"<init>", "(Ljpwr/rt/PwrtObjid;I)V"); "<init>", "(Ljpwr/rt/PwrtObjid;I)V");
//printf("cdhrObjid initierad\n");
} }
PwrtObjid_id = (*env)->FindClass( env, "jpwr/rt/PwrtObjid"); PwrtObjid_id = (*env)->FindClass( env, "jpwr/rt/PwrtObjid");
...@@ -567,7 +682,6 @@ JNIEXPORT jobject JNICALL Java_jpwr_rt_Gdh_getChild ...@@ -567,7 +682,6 @@ JNIEXPORT jobject JNICALL Java_jpwr_rt_Gdh_getChild
"<init>", "(II)V"); "<init>", "(II)V");
PwrtObjid_getOix = (*env)->GetMethodID( env, PwrtObjid_id, "getOix", "()I"); PwrtObjid_getOix = (*env)->GetMethodID( env, PwrtObjid_id, "getOix", "()I");
PwrtObjid_getVid = (*env)->GetMethodID( env, PwrtObjid_id, "getVid", "()I"); PwrtObjid_getVid = (*env)->GetMethodID( env, PwrtObjid_id, "getVid", "()I");
//printf("PwrtObjid_xxx initierade\n");
} }
objid.oix = (*env)->CallIntMethod( env, objid_obj, PwrtObjid_getOix); objid.oix = (*env)->CallIntMethod( env, objid_obj, PwrtObjid_getOix);
......
...@@ -140,6 +140,38 @@ JNIEXPORT jint JNICALL Java_jpwr_rt_Gdh_getObjectRefInfoInt ...@@ -140,6 +140,38 @@ JNIEXPORT jint JNICALL Java_jpwr_rt_Gdh_getObjectRefInfoInt
JNIEXPORT jstring JNICALL Java_jpwr_rt_Gdh_getObjectRefInfoString JNIEXPORT jstring JNICALL Java_jpwr_rt_Gdh_getObjectRefInfoString
(JNIEnv *, jobject, jint, jint); (JNIEnv *, jobject, jint, jint);
/*
* Class: jpwr_rt_Gdh
* Method: getObjectRefInfoFloatArray
* Signature: (II)[F
*/
JNIEXPORT jfloatArray JNICALL Java_jpwr_rt_Gdh_getObjectRefInfoFloatArray
(JNIEnv *, jobject, jint, jint);
/*
* Class: jpwr_rt_Gdh
* Method: getObjectRefInfoBooleanArray
* Signature: (II)[Z
*/
JNIEXPORT jbooleanArray JNICALL Java_jpwr_rt_Gdh_getObjectRefInfoBooleanArray
(JNIEnv *, jobject, jint, jint);
/*
* Class: jpwr_rt_Gdh
* Method: getObjectRefInfoIntArray
* Signature: (II)[I
*/
JNIEXPORT jintArray JNICALL Java_jpwr_rt_Gdh_getObjectRefInfoIntArray
(JNIEnv *, jobject, jint, jint);
/*
* Class: jpwr_rt_Gdh
* Method: getObjectRefInfoStringArray
* Signature: (IIII)[Ljava/lang/String;
*/
JNIEXPORT jobjectArray JNICALL Java_jpwr_rt_Gdh_getObjectRefInfoStringArray
(JNIEnv *, jobject, jint, jint, jint, jint);
/* /*
* Class: jpwr_rt_Gdh * Class: jpwr_rt_Gdh
* Method: unrefObjectInfo * Method: unrefObjectInfo
......
...@@ -14,6 +14,8 @@ public class GeDynTable extends GeDynElem { ...@@ -14,6 +14,8 @@ public class GeDynTable extends GeDynElem {
public boolean[] selAttrFound; public boolean[] selAttrFound;
PwrtRefId[] subid; PwrtRefId[] subid;
int[] p; int[] p;
public int[] elements;
public int[] size;
public int[] typeId; public int[] typeId;
public boolean[][] oldValueB; public boolean[][] oldValueB;
public float[][] oldValueF; public float[][] oldValueF;
...@@ -35,6 +37,8 @@ public class GeDynTable extends GeDynElem { ...@@ -35,6 +37,8 @@ public class GeDynTable extends GeDynElem {
p = new int[columns]; p = new int[columns];
subid = new PwrtRefId[columns]; subid = new PwrtRefId[columns];
typeId = new int[columns]; typeId = new int[columns];
elements = new int[columns];
size = new int[columns];
attrFound = new boolean[columns]; attrFound = new boolean[columns];
selAttrFound = new boolean[columns]; selAttrFound = new boolean[columns];
oldValueB = new boolean[columns][]; oldValueB = new boolean[columns][];
...@@ -57,6 +61,10 @@ public class GeDynTable extends GeDynElem { ...@@ -57,6 +61,10 @@ public class GeDynTable extends GeDynElem {
p[i] = ret.id; p[i] = ret.id;
subid[i] = ret.refid; subid[i] = ret.refid;
typeId[i] = ret.typeId; typeId[i] = ret.typeId;
elements[i] = ret.getElements();
size[i] = ret.getSize();
if ( elements[i] > rows)
elements[i] = rows;
if ( typeId[i] == Pwr.eType_Float32) { if ( typeId[i] == Pwr.eType_Float32) {
oldValueF[i] = new float[rows]; oldValueF[i] = new float[rows];
} }
...@@ -92,26 +100,26 @@ public class GeDynTable extends GeDynElem { ...@@ -92,26 +100,26 @@ public class GeDynTable extends GeDynElem {
continue; continue;
if ( typeId[i] == Pwr.eType_Float32) { if ( typeId[i] == Pwr.eType_Float32) {
float value0 = dyn.en.gdh.getObjectRefInfoFloat( p[i]); float[] value0 = dyn.en.gdh.getObjectRefInfoFloatArray( p[i], elements[i]);
for ( int j = 0; j < 1; j++) { // Just the first row... for ( int j = 0; j < value0.length; j++) {
if ( value0 != oldValueF[i][j] || firstScan) { if ( value0[j] != oldValueF[i][j] || firstScan) {
sb = cFormat[i].format( value0, sb); sb = cFormat[i].format( value0[j], sb);
((GeTable)dyn.comp).setValueAt(new String(sb), j, i); ((GeTable)dyn.comp).setValueAt(new String(sb), j, i);
// dyn.repaintNow = true; // dyn.repaintNow = true;
oldValueF[i][j] = value0; oldValueF[i][j] = value0[j];
} }
} }
} }
else if ( typeId[i] == Pwr.eType_Boolean) { else if ( typeId[i] == Pwr.eType_Boolean) {
boolean value0 = dyn.en.gdh.getObjectRefInfoBoolean( p[i]); boolean[] value0 = dyn.en.gdh.getObjectRefInfoBooleanArray( p[i], elements[i]);
for ( int j = 0; j < 1; j++) { // Just the first row... for ( int j = 0; j < value0.length; j++) {
if ( value0 != oldValueB[i][j] || firstScan) { if ( value0[j] != oldValueB[i][j] || firstScan) {
if ( value0) if ( value0[j])
((GeTable)dyn.comp).setValueAt("1", j, i); ((GeTable)dyn.comp).setValueAt("1", j, i);
else else
((GeTable)dyn.comp).setValueAt("0", j, i); ((GeTable)dyn.comp).setValueAt("0", j, i);
// dyn.repaintNow = true; // dyn.repaintNow = true;
oldValueB[i][j] = value0; oldValueB[i][j] = value0[j];
} }
} }
} }
...@@ -121,26 +129,26 @@ public class GeDynTable extends GeDynElem { ...@@ -121,26 +129,26 @@ public class GeDynTable extends GeDynElem {
typeId[i] == Pwr.eType_UInt16 || typeId[i] == Pwr.eType_UInt16 ||
typeId[i] == Pwr.eType_Int8 || typeId[i] == Pwr.eType_Int8 ||
typeId[i] == Pwr.eType_UInt8) { typeId[i] == Pwr.eType_UInt8) {
int value0 = dyn.en.gdh.getObjectRefInfoInt( p[i]); int value0[] = dyn.en.gdh.getObjectRefInfoIntArray( p[i], elements[i]);
for ( int j = 0; j < 1; j++) { // Just the first row... for ( int j = 0; j < value0.length; j++) {
if ( value0 != oldValueI[i][j] || firstScan) { if ( value0[j] != oldValueI[i][j] || firstScan) {
sb = cFormat[i].format( value0, sb); sb = cFormat[i].format( value0[j], sb);
((GeTable)dyn.comp).setValueAt(new String(sb), j, i); ((GeTable)dyn.comp).setValueAt(new String(sb), j, i);
// dyn.repaintNow = true; // dyn.repaintNow = true;
oldValueI[i][j] = value0; oldValueI[i][j] = value0[j];
} }
} }
} }
else if ( typeId[i] == Pwr.eType_String || else if ( typeId[i] == Pwr.eType_String ||
typeId[i] == Pwr.eType_Objid) { typeId[i] == Pwr.eType_Objid) {
String value0 = dyn.en.gdh.getObjectRefInfoString( p[i], typeId[i]); String[] value0 = dyn.en.gdh.getObjectRefInfoStringArray( p[i], typeId[i], size[i], elements[i]);
for ( int j = 0; j < 1; j++) { // Just the first row... for ( int j = 0; j < value0.length; j++) {
if ( firstScan || value0.compareTo( oldValueS[i][j]) != 0) { if ( firstScan || value0[j].compareTo( oldValueS[i][j]) != 0) {
sb = cFormat[i].format( value0, sb); sb = cFormat[i].format( value0[j], sb);
((GeTable)dyn.comp).setValueAt(new String(sb), j, i); ((GeTable)dyn.comp).setValueAt(new String(sb), j, i);
// dyn.repaintNow = true; // dyn.repaintNow = true;
oldValueS[i][j] = value0; oldValueS[i][j] = value0[j];
} }
} }
} }
......
...@@ -274,10 +274,17 @@ public class Gdh { ...@@ -274,10 +274,17 @@ public class Gdh {
public native CdhrObjid getObjectInfoObjid( String attributeName); public native CdhrObjid getObjectInfoObjid( String attributeName);
public native PwrtStatus toggleObjectInfo( String attributeName); public native PwrtStatus toggleObjectInfo( String attributeName);
public native GdhrRefObjectInfo refObjectInfo( String attributeName); public native GdhrRefObjectInfo refObjectInfo( String attributeName);
public native float getObjectRefInfoFloat( int id); public native float getObjectRefInfoFloat( int id);
public native boolean getObjectRefInfoBoolean( int id); public native boolean getObjectRefInfoBoolean( int id);
public native int getObjectRefInfoInt( int id); public native int getObjectRefInfoInt( int id);
public native String getObjectRefInfoString( int id, int typeid); public native String getObjectRefInfoString( int id, int typeid);
public native float[] getObjectRefInfoFloatArray( int id, int elements);
public native boolean[] getObjectRefInfoBooleanArray( int id, int elements);
public native int[] getObjectRefInfoIntArray( int id, int elements);
public native String[] getObjectRefInfoStringArray( int id, int typeid, int size, int elements);
public native PwrtStatus unrefObjectInfo( PwrtRefId refid); public native PwrtStatus unrefObjectInfo( PwrtRefId refid);
public native CdhrObjid nameToObjid( String objectName); public native CdhrObjid nameToObjid( String objectName);
public native CdhrString objidToName( PwrtObjid objid, int nameType); public native CdhrString objidToName( PwrtObjid objid, int nameType);
......
...@@ -62,13 +62,19 @@ public class GdhServer ...@@ -62,13 +62,19 @@ public class GdhServer
public final static int CRR_OBJECT = 43; public final static int CRR_OBJECT = 43;
public final static int GET_PARENT = 44; public final static int GET_PARENT = 44;
public final static int GET_OBJECT_INFO_OBJID = 45; public final static int GET_OBJECT_INFO_OBJID = 45;
public final static int GET_OBJECT_REF_INFO_BOOLEAN_ARRAY = 46;
public final static int GET_OBJECT_REF_INFO_FLOAT_ARRAY = 47;
public final static int GET_OBJECT_REF_INFO_INT_ARRAY = 48;
public final static int GET_OBJECT_REF_INFO_STRING_ARRAY = 49;
public final static int PORT = 4445; public final static int PORT = 4445;
public final static int __IO_EXCEPTION = 2000; public final static int __IO_EXCEPTION = 2000;
public final static int __UNREFED = 0; public final static int __UNREFED = 0;
static ArrayList subscriptions = new ArrayList(); static ArrayList subscriptions = new ArrayList();
// static Vector nrOfSubscriptionClients = new Vector();
static int subscriptionCount = 0; static int subscriptionCount = 0;
static int threadCount = 0; static int threadCount = 0;
...@@ -277,14 +283,14 @@ public class GdhServer ...@@ -277,14 +283,14 @@ public class GdhServer
*/ */
public GdhThread(Socket clientSocket, int threadNumber, int maxConnections) public GdhThread(Socket clientSocket, int threadNumber, int maxConnections)
{ {
/* /************ In case of debugging this might be useful
System.out.println("threadnumber : " + threadNumber + "maxconn " + maxConnections); System.out.println("threadnumber : " + threadNumber + "maxconn " + maxConnections);
try{ try{
System.out.println("HostName :" + clientSocket.getInetAddress().getHostName() + System.out.println("HostName :" + clientSocket.getInetAddress().getHostName() +
"Delay : " + clientSocket.getTcpNoDelay()); "Delay : " + clientSocket.getTcpNoDelay());
} }
catch(SocketException exc){} catch(SocketException exc){}
*/ *************************************/
this.threadNumber = threadNumber; this.threadNumber = threadNumber;
this.clientSocket = clientSocket; this.clientSocket = clientSocket;
this.maxConnections = maxConnections; this.maxConnections = maxConnections;
...@@ -315,9 +321,6 @@ public class GdhServer ...@@ -315,9 +321,6 @@ public class GdhServer
out.flush(); out.flush();
in = new ObjectInputStream(new BufferedInputStream(clientSocket.getInputStream())); in = new ObjectInputStream(new BufferedInputStream(clientSocket.getInputStream()));
//buff = new BufferedOutputStream(clientSocket.getOutputStream());
//outbuff = new ObjectOutputStream(buff);
} }
catch(IOException e) catch(IOException e)
{ {
...@@ -330,7 +333,6 @@ public class GdhServer ...@@ -330,7 +333,6 @@ public class GdhServer
try try
{ {
// out.writeLong(9998);
int function = in.readInt(); int function = in.readInt();
while(function != 9999) while(function != 9999)
{ {
...@@ -516,6 +518,8 @@ public class GdhServer ...@@ -516,6 +518,8 @@ public class GdhServer
out.writeInt(ret.refid.nid); out.writeInt(ret.refid.nid);
out.writeInt(thSub.size() - 1); out.writeInt(thSub.size() - 1);
out.writeInt(ret.typeId); out.writeInt(ret.typeId);
out.writeInt(ret.size);
out.writeInt(ret.elements);
} }
out.flush(); out.flush();
} }
...@@ -544,7 +548,8 @@ public class GdhServer ...@@ -544,7 +548,8 @@ public class GdhServer
out.writeInt(ret.refid.nid); out.writeInt(ret.refid.nid);
out.writeInt(thSub.size() - 1); out.writeInt(thSub.size() - 1);
out.writeInt(ret.typeId); out.writeInt(ret.typeId);
out.writeInt(ret.size);
out.writeInt(ret.elements);
} }
} }
out.flush(); out.flush();
...@@ -559,8 +564,6 @@ public class GdhServer ...@@ -559,8 +564,6 @@ public class GdhServer
case REF_OBJECT_INFO_VECTOR: case REF_OBJECT_INFO_VECTOR:
try try
{ {
//System.out.println("Start p refobjinfvec" + (new Timestamp(new Date().getTime())).toString());
//Vector retVec = new Vector();
Vector vec = (Vector)in.readObject(); Vector vec = (Vector)in.readObject();
if(vec == null) if(vec == null)
{ {
...@@ -569,7 +572,6 @@ public class GdhServer ...@@ -569,7 +572,6 @@ public class GdhServer
out.flush(); out.flush();
break; break;
} }
//Sub gdhRet;
String attrName; String attrName;
Vector gdhRet = new Vector(vec.size()); Vector gdhRet = new Vector(vec.size());
for(int j = 0; j < vec.size(); j++) for(int j = 0; j < vec.size(); j++)
...@@ -583,7 +585,9 @@ public class GdhServer ...@@ -583,7 +585,9 @@ public class GdhServer
new PwrtRefId(thSub.size() - 1, ret.refid.nid), new PwrtRefId(thSub.size() - 1, ret.refid.nid),
ret.id, ret.id,
ret.typeId, ret.typeId,
ret.subscriptionsIndex); ret.subscriptionsIndex,
ret.elements,
ret.size );
retToCli.sts = ret.sts; retToCli.sts = ret.sts;
gdhRet.add(retToCli); gdhRet.add(retToCli);
} }
...@@ -596,8 +600,6 @@ public class GdhServer ...@@ -596,8 +600,6 @@ public class GdhServer
out.writeObject(gdhRet); out.writeObject(gdhRet);
out.flush(); out.flush();
//out.reset();
//System.out.println("Stop p refobjinfvec " + (new Timestamp(new Date().getTime())).toString());
} }
catch(NotSerializableException e) catch(NotSerializableException e)
{ {
...@@ -621,38 +623,17 @@ public class GdhServer ...@@ -621,38 +623,17 @@ public class GdhServer
System.out.println("Start GET_OBJECT_REF_INFO_ALL" + (new Timestamp(new Date().getTime())).toString()); System.out.println("Start GET_OBJECT_REF_INFO_ALL" + (new Timestamp(new Date().getTime())).toString());
} }
Sub subElement; Sub subElement;
//Object cli[] = new Object[thSub.size()];
for(i = 0; i < thSub.size(); i++) for(i = 0; i < thSub.size(); i++)
{ {
subElement = ((Sub)thSub.elementAt(i)); subElement = ((Sub)thSub.elementAt(i));
int index = subElement.getIndex(); int index = subElement.getIndex();
//int id = (int)((SubElement)subCopy.elementAt(index)).sub.id;
//int typeId = (int)((SubElement)subCopy.elementAt(index)).sub.typeId;
int id = subElement.id; int id = subElement.id;
int typeId = subElement.typeId; int typeId = subElement.typeId;
/* if(sub.sts == __UNREFED) int elements = subElement.elements;
{ int size = subElement.size;
continue;
}
boolean found = false;
for(int j = 0; j < ((SubElement)subCopy.elementAt(i)).reffedByThread.length; j++)
{
if(((SubElement)subCopy.elementAt(i)).reffedByThread[j][0] == threadNumber)
{
found = true;
break;
}
}
if(!found)
{
continue;
}
*/
//System.out.println(id + " typeId " + typeId);
//System.out.println("refinfoall");
switch (typeId) switch (typeId)
{ {
case Pwr.eType_Int32: case Pwr.eType_Int32:
...@@ -661,49 +642,49 @@ public class GdhServer ...@@ -661,49 +642,49 @@ public class GdhServer
case Pwr.eType_UInt16: case Pwr.eType_UInt16:
case Pwr.eType_Int8: case Pwr.eType_Int8:
case Pwr.eType_UInt8: case Pwr.eType_UInt8:
//cli[i] = new Integer(gdh.getObjectRefInfoInt(id)); if(elements > 1)
{
//its an array
out.writeObject(gdh.getObjectRefInfoIntArray(id, elements));
}
else
out.writeInt(gdh.getObjectRefInfoInt(id)); out.writeInt(gdh.getObjectRefInfoInt(id));
break; break;
case Pwr.eType_Float32: case Pwr.eType_Float32:
//cli[i] = new Float(gdh.getObjectRefInfoFloat(id)); if(elements > 1)
{
//its an array
out.writeObject(gdh.getObjectRefInfoFloatArray(id, elements));
}
else
out.writeFloat(gdh.getObjectRefInfoFloat(id)); out.writeFloat(gdh.getObjectRefInfoFloat(id));
break; break;
case 0: case 0:
case Pwr.eType_Boolean: case Pwr.eType_Boolean:
//cli[i] = new Boolean(gdh.getObjectRefInfoBoolean(id)); if(elements > 1)
{
//its an array
out.writeObject(gdh.getObjectRefInfoBooleanArray(id, elements));
}
else
out.writeBoolean(gdh.getObjectRefInfoBoolean(id)); out.writeBoolean(gdh.getObjectRefInfoBoolean(id));
break; break;
default: default:
//cli[i] = gdh.getObjectRefInfoString(id, typeId); if(elements > 1)
{
//its an array
out.writeObject(gdh.getObjectRefInfoStringArray(id, typeId, size, elements));
}
else
out.writeObject(gdh.getObjectRefInfoString(id, typeId)); out.writeObject(gdh.getObjectRefInfoString(id, typeId));
break; break;
} }
//index = null;
//id = null;
//typeId = null;
} }
try try
{ {
//out.writeObject(cli);
out.flush(); out.flush();
/* //must be done if we dont want memory leaks...
long K = 1024;
long freeMem = Runtime.getRuntime().freeMemory() / K;
long totalMem = Runtime.getRuntime().totalMemory() / K;
System.out.println("Storlek p thSub: " + thSub.size() +
"storlek p sub: " + subscriptions.size() +
"Tillgngligt minne: " + freeMem + " KB" +
"Totalt minne: " + totalMem + " KB");
//ej behvligt
subCopy = null;
cli = null;
subElement = null;
*/
//mste gras annars tar minnet slut...
out.reset(); out.reset();
//System.gc();
//System.runFinalization();
if(logRefInfoAll) if(logRefInfoAll)
{ {
System.out.println("Slut GET_OBJECT_REF_INFO_ALL" + (new Timestamp(new Date().getTime())).toString()); System.out.println("Slut GET_OBJECT_REF_INFO_ALL" + (new Timestamp(new Date().getTime())).toString());
...@@ -724,7 +705,6 @@ public class GdhServer ...@@ -724,7 +705,6 @@ public class GdhServer
{ {
System.out.println("getObjectRefInfoAll: IO exception"); System.out.println("getObjectRefInfoAll: IO exception");
} }
//System.out.println("efter GET_OBJECT_REF_INFO_ALL");
break; break;
case GET_OBJECT_REF_INFO_FLOAT: case GET_OBJECT_REF_INFO_FLOAT:
try try
...@@ -779,6 +759,84 @@ public class GdhServer ...@@ -779,6 +759,84 @@ public class GdhServer
System.out.println("getObjectRefInfoString: IO exception"); System.out.println("getObjectRefInfoString: IO exception");
} }
break; break;
case GET_OBJECT_REF_INFO_FLOAT_ARRAY:
try
{
int id = in.readInt();
int index = ((Sub)thSub.elementAt(id)).getIndex();
int elements = ((Sub)thSub.elementAt(id)).getElements();
out.writeObject(gdh.getObjectRefInfoFloatArray(index, elements));
out.flush();
}
catch(IOException e)
{
System.out.println("getObjectRefInfoFloatArray: IO exception");
}
break;
case GET_OBJECT_REF_INFO_BOOLEAN_ARRAY:
try
{
int id = in.readInt();
int index = ((Sub)thSub.elementAt(id)).getIndex();
int elements = ((Sub)thSub.elementAt(id)).getElements();
out.writeObject(gdh.getObjectRefInfoBooleanArray(index, elements));
out.flush();
}
catch(IOException e)
{
System.out.println("getObjectRefInfoBooleanArray: IO exception");
}
break;
case GET_OBJECT_REF_INFO_INT_ARRAY:
try
{
int id = in.readInt();
int index = ((Sub)thSub.elementAt(id)).getIndex();
int elements = ((Sub)thSub.elementAt(id)).getElements();
out.writeObject(gdh.getObjectRefInfoIntArray(index, elements));
out.flush();
}
catch(IOException e)
{
System.out.println("getObjectRefInfoIntArray: IO exception");
}
break;
case GET_OBJECT_REF_INFO_STRING_ARRAY:
try
{
int id = in.readInt();
int typeid = in.readInt();
int index = ((Sub)thSub.elementAt(id)).getIndex();
int elements = ((Sub)thSub.elementAt(id)).getElements();
int size = ((Sub)thSub.elementAt(id)).getSize();
out.writeObject(gdh.getObjectRefInfoStringArray(index, typeid, size, elements));
out.flush();
}
catch(IOException e)
{
System.out.println("getObjectRefInfoStringArray: IO exception");
}
break;
case UNREF_OBJECT_INFO: case UNREF_OBJECT_INFO:
try try
{ {
...@@ -1425,10 +1483,9 @@ public class GdhServer ...@@ -1425,10 +1483,9 @@ public class GdhServer
ThreadNumbersConnected[ii] += j + ", "; ThreadNumbersConnected[ii] += j + ", ";
NumberOfPrenumerations[ii] += subEl.reffedByThread[j] + ", "; NumberOfPrenumerations[ii] += subEl.reffedByThread[j] + ", ";
} }
//ObjectAttributeNames[ii] = ((SubElement)subcp.get(ii)).sub.attrName;
} }
} }
//Object obj[][] = {ObjectAttributeNames, ThreadNumbersConnected, NumberOfPrenumerations};
out.writeInt(subcp.size()); out.writeInt(subcp.size());
out.writeInt(nrOfSub); out.writeInt(nrOfSub);
...@@ -1441,11 +1498,9 @@ public class GdhServer ...@@ -1441,11 +1498,9 @@ public class GdhServer
out.writeLong(Runtime.getRuntime().totalMemory()); out.writeLong(Runtime.getRuntime().totalMemory());
out.flush(); out.flush();
//mste gras annars tar minnet slut... //must be done if we dont want memory leaks...
out.reset(); out.reset();
//System.gc();
} }
catch(OutOfMemoryError e) catch(OutOfMemoryError e)
{ {
...@@ -1492,17 +1547,17 @@ public class GdhServer ...@@ -1492,17 +1547,17 @@ public class GdhServer
{ {
System.err.println("Close failed"); System.err.println("Close failed");
} }
//loopa igenom och kontrollera att alla prenumerationer har stoppats //check that all subscriptions has stopped
for(i = 0; i < thSub.size(); i++) for(i = 0; i < thSub.size(); i++)
{ {
try try
{ {
sub = ((Sub)thSub.elementAt(i)); sub = ((Sub)thSub.elementAt(i));
int index = ((Sub)thSub.elementAt(i)).getIndex(); int index = ((Sub)thSub.elementAt(i)).getIndex();
//PwrtRefId refid = (PwrtRefId)((SubElement)subCopy.elementAt(index)).sub.refid;
PwrtStatus sts = this.unrefObjectInfo(new PwrtRefId(index, sub.refid.nid), PwrtStatus sts = this.unrefObjectInfo(new PwrtRefId(index, sub.refid.nid),
threadNumber); threadNumber);
// System.out.println("unrefall :" + index + refid.nid);
} }
catch(ArrayIndexOutOfBoundsException exc) catch(ArrayIndexOutOfBoundsException exc)
{ {
...@@ -1529,7 +1584,7 @@ public class GdhServer ...@@ -1529,7 +1584,7 @@ public class GdhServer
*@param threadNumber Description of the Parameter *@param threadNumber Description of the Parameter
*@return Description of the Return Value *@return Description of the Return Value
*/ */
public synchronized Sub refObjectInfo(String attrName, int threadNumber /*, boolean putNextSubAtSubVecEnd*/) public synchronized Sub refObjectInfo(String attrName, int threadNumber)
{ {
SubElement sub; SubElement sub;
int firstUnreffedIndex = subscriptionCount; int firstUnreffedIndex = subscriptionCount;
...@@ -1562,8 +1617,6 @@ public class GdhServer ...@@ -1562,8 +1617,6 @@ public class GdhServer
if(ret.oddSts()) if(ret.oddSts())
{ {
sub = new SubElement(maxConnections, threadNumber); sub = new SubElement(maxConnections, threadNumber);
//sub.refObjectInfo = ret;
//sub.attrName = attrName;
if(notFoundUnreffed) if(notFoundUnreffed)
{ {
//System.out.println("this.refObjectInfo ej reffad ej lucka i subsc.. " + attrName + " " + subscriptionCount); //System.out.println("this.refObjectInfo ej reffad ej lucka i subsc.. " + attrName + " " + subscriptionCount);
...@@ -1582,7 +1635,6 @@ public class GdhServer ...@@ -1582,7 +1635,6 @@ public class GdhServer
subscriptions.add(firstUnreffedIndex, sub); subscriptions.add(firstUnreffedIndex, sub);
sub.reffedByThreadBitSet.set(threadNumber); sub.reffedByThreadBitSet.set(threadNumber);
sub.reffedByThread[threadNumber]++; sub.reffedByThread[threadNumber]++;
//lastIndexReffed = firstUnreffedIndex;
} }
} }
else else
......
...@@ -16,14 +16,31 @@ public class GdhrRefObjectInfo implements Serializable ...@@ -16,14 +16,31 @@ public class GdhrRefObjectInfo implements Serializable
public int sts; public int sts;
public int typeId; public int typeId;
public int subId; public int subId;
public int elements;
public int size;
public GdhrRefObjectInfo( PwrtRefId refid, int id, int sts, int typeId) { public GdhrRefObjectInfo( PwrtRefId refid, int id, int sts, int typeId) {
this.refid = refid; this.refid = refid;
this.id = id; this.id = id;
this.sts = sts; this.sts = sts;
this.typeId = typeId; this.typeId = typeId;
//default values in case we have forgotten to use the new constructor
this.elements = 1;
this.size = 4;
} }
public GdhrRefObjectInfo( PwrtRefId refid, int id, int sts, int typeId, int elements, int size) {
this.refid = refid;
this.id = id;
this.sts = sts;
this.typeId = typeId;
this.elements = elements;
this.size = size;
}
public boolean evenSts() { return (sts % 2 == 0);} public boolean evenSts() { return (sts % 2 == 0);}
public boolean oddSts() { return (sts % 2 == 1);} public boolean oddSts() { return (sts % 2 == 1);}
public int getSts() { return sts;} public int getSts() { return sts;}
public int getElements(){ return elements;}
public int getSize(){ return size;}
} }
...@@ -14,22 +14,16 @@ ...@@ -14,22 +14,16 @@
public float valueFloat; public float valueFloat;
public boolean valueBoolean; public boolean valueBoolean;
public String valueString; public String valueString;
/*
public PwrtRefId refid; public int[] valueIntArray;
public int id; public float[] valueFloatArray;
public int sts; public boolean[] valueBooleanArray;
public int typeId; public String[] valueStringArray;
public int subId;
*/
public Sub(String attrName, PwrtRefId refid, int id, int typeId, int public Sub(String attrName, PwrtRefId refid, int id, int typeId, int
subscriptionsIndex, int valueInt, float valueFloat, boolean valueBoolean, String valueString) subscriptionsIndex, int valueInt, float valueFloat, boolean valueBoolean, String valueString)
{ {
/*
this.refid = refid;
this.id = id;
this.sts = 0;
this.typeId = typeId;
*/
super(refid, id, 0, typeId); super(refid, id, 0, typeId);
this.subscriptionsIndex = subscriptionsIndex; this.subscriptionsIndex = subscriptionsIndex;
this.valueInt = valueInt; this.valueInt = valueInt;
...@@ -69,25 +63,20 @@ ...@@ -69,25 +63,20 @@
public Sub(String attrName, PwrtRefId refid, int id, int typeId, int subscriptionsIndex) public Sub(String attrName, PwrtRefId refid, int id, int typeId, int subscriptionsIndex, int elements, int size)
{ {
/* super(refid, id, 0, typeId, elements, size);
this.refid = refid;
this.id = id;
this.sts = sts;
this.typeId = typeId;
*/
super(refid, id, 0, typeId);
this.attrName = attrName; this.attrName = attrName;
this.subscriptionsIndex = subscriptionsIndex; this.subscriptionsIndex = subscriptionsIndex;
} }
//public boolean evenSts() { return (sts % 2 == 0);}
//public boolean oddSts() { return (sts % 2 == 1);}
//public int getSts() { return sts;}
int getIndex() int getIndex()
{ {
return subscriptionsIndex; return subscriptionsIndex;
} }
} }
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
{ {
public int[] reffedByThread; public int[] reffedByThread;
public BitSet reffedByThreadBitSet; public BitSet reffedByThreadBitSet;
Sub sub = new Sub(" ", new PwrtRefId(0, 0), 0, 0, 0); Sub sub = new Sub(" ", new PwrtRefId(0, 0), 0, 0, 0,0,0);
public SubElement(int maxConnections, int threadNumber) public SubElement(int maxConnections, int threadNumber)
...@@ -40,6 +40,8 @@ ...@@ -40,6 +40,8 @@
this.sub.id = obj.id; this.sub.id = obj.id;
this.sub.sts = obj.sts; this.sub.sts = obj.sts;
this.sub.typeId = obj.typeId; this.sub.typeId = obj.typeId;
this.sub.size = obj.size;
this.sub.elements = obj.elements;
this.sub.subscriptionsIndex = subscriptionsIndex; this.sub.subscriptionsIndex = subscriptionsIndex;
} }
...@@ -48,3 +50,4 @@ ...@@ -48,3 +50,4 @@
return (this.sub.attrName.equalsIgnoreCase(((SubElement)o).sub.attrName) && (((SubElement)o).sub.sts != 0)); return (this.sub.attrName.equalsIgnoreCase(((SubElement)o).sub.attrName) && (((SubElement)o).sub.sts != 0));
} }
} }
...@@ -52,6 +52,13 @@ public class Gdh ...@@ -52,6 +52,13 @@ public class Gdh
public final static int GET_PARENT = 44; public final static int GET_PARENT = 44;
public final static int GET_OBJECT_INFO_OBJID = 45; public final static int GET_OBJECT_INFO_OBJID = 45;
public final static int GET_OBJECT_REF_INFO_BOOLEAN_ARRAY = 46;
public final static int GET_OBJECT_REF_INFO_FLOAT_ARRAY = 47;
public final static int GET_OBJECT_REF_INFO_INT_ARRAY = 48;
public final static int GET_OBJECT_REF_INFO_STRING_ARRAY = 49;
public final static int __IO_EXCEPTION = 2000; public final static int __IO_EXCEPTION = 2000;
public final static int __BUSY = 2002; public final static int __BUSY = 2002;
public final static int __UNREFED = 0; public final static int __UNREFED = 0;
...@@ -367,7 +374,7 @@ public class Gdh ...@@ -367,7 +374,7 @@ public class Gdh
return new GdhrRefObjectInfo(null, 0, 0, 0); return new GdhrRefObjectInfo(null, 0, 0, 0);
} }
//qqq //qqq
Sub sub = new Sub(attributeName, null, 0, typeId, subscriptionCount); Sub sub = new Sub(attributeName, null, 0, typeId, subscriptionCount, 0, 0);
subscriptions.insertElementAt(sub, subscriptionCount); subscriptions.insertElementAt(sub, subscriptionCount);
subscriptionCount++; subscriptionCount++;
return new GdhrRefObjectInfo(refid, id, 1, typeId); return new GdhrRefObjectInfo(refid, id, 1, typeId);
...@@ -395,13 +402,15 @@ public class Gdh ...@@ -395,13 +402,15 @@ public class Gdh
PwrtRefId refid = new PwrtRefId(rix, nid); PwrtRefId refid = new PwrtRefId(rix, nid);
int id = in.readInt(); int id = in.readInt();
int typeId = in.readInt(); int typeId = in.readInt();
Sub sub = new Sub(attributeName, refid, id, typeId,subscriptionCount); int size = in.readInt();
int elements = in.readInt();
Sub sub = new Sub(attributeName, refid, id, typeId,subscriptionCount, size, elements);
sub.sts = 1; sub.sts = 1;
subscriptions.insertElementAt(sub, id); subscriptions.insertElementAt(sub, id);
subscriptionCount++; subscriptionCount++;
refid = new PwrtRefId(id, 0); refid = new PwrtRefId(id, 0);
subLate++; subLate++;
return new GdhrRefObjectInfo(refid, id, sts, typeId); return new GdhrRefObjectInfo(refid, id, sts, typeId, size, elements);
} }
catch(IOException e) catch(IOException e)
{ {
...@@ -420,6 +429,7 @@ public class Gdh ...@@ -420,6 +429,7 @@ public class Gdh
int nid; int nid;
int id; int id;
int typeId; int typeId;
PwrtRefId refid; PwrtRefId refid;
if(listSent) if(listSent)
...@@ -472,6 +482,8 @@ public class Gdh ...@@ -472,6 +482,8 @@ public class Gdh
sub.refid = new PwrtRefId(rix, nid); sub.refid = new PwrtRefId(rix, nid);
id = in.readInt(); id = in.readInt();
typeId = in.readInt(); typeId = in.readInt();
sub.size = in.readInt();
sub.elements = in.readInt();
} }
locked = false; locked = false;
notify(); notify();
...@@ -540,8 +552,7 @@ public class Gdh ...@@ -540,8 +552,7 @@ public class Gdh
} }
ret.id = ret.refid.rix; ret.id = ret.refid.rix;
subscriptions.add(ret); subscriptions.add(ret);
//((Sub)retVec.get(i)).refid.rix = ((Sub)retVec.get(i)).id;
//System.out.println("Status " + ((Sub)retVec.get(i)).getSts());
} }
subscriptionCount += retVec.size(); subscriptionCount += retVec.size();
...@@ -591,17 +602,24 @@ public class Gdh ...@@ -591,17 +602,24 @@ public class Gdh
//System.out.println("ArrayIndexOutOfBounds getObjectRefInfoFloat"); //System.out.println("ArrayIndexOutOfBounds getObjectRefInfoFloat");
return 0F; return 0F;
} }
/*
try {
out.writeInt( GET_OBJECT_REF_INFO_FLOAT);
out.writeInt( id);
return in.readFloat();
} catch (IOException e) {
return 0F;
}
*/
} }
public float[] getObjectRefInfoFloatArray(int id, int elements)
{
try{
Sub sub = (Sub)subscriptions.elementAt(id);
if(sub.oddSts())
{
return sub.valueFloatArray;
}
return null;
}
catch(ArrayIndexOutOfBoundsException e)
{
//System.out.println("ArrayIndexOutOfBounds getObjectRefInfoFloat");
return null;
}
}
public boolean getObjectRefInfoBoolean(int id) public boolean getObjectRefInfoBoolean(int id)
{ {
...@@ -619,17 +637,25 @@ public class Gdh ...@@ -619,17 +637,25 @@ public class Gdh
//System.out.println("ArrayIndexOutOfBounds getObjectRefInfoBoolean"); //System.out.println("ArrayIndexOutOfBounds getObjectRefInfoBoolean");
return false; return false;
} }
/*
try {
out.writeInt( GET_OBJECT_REF_INFO_BOOLEAN);
out.writeInt( id);
return in.readBoolean();
} catch (IOException e) {
return false;
}
*/
} }
public boolean[] getObjectRefInfoBooleanArray(int id, int elements)
{
try
{
Sub sub = (Sub)subscriptions.elementAt(id);
if(sub.oddSts())
{
return sub.valueBooleanArray;
}
return null;
}
catch(ArrayIndexOutOfBoundsException e)
{
//System.out.println("ArrayIndexOutOfBounds getObjectRefInfoBoolean");
return null;
}
}
public int getObjectRefInfoInt(int id) public int getObjectRefInfoInt(int id)
{ {
...@@ -647,17 +673,25 @@ public class Gdh ...@@ -647,17 +673,25 @@ public class Gdh
//System.out.println("ArrayIndexOutOfBounds getObjectRefInfoInt"); //System.out.println("ArrayIndexOutOfBounds getObjectRefInfoInt");
return 0; return 0;
} }
/*
try {
out.writeInt( GET_OBJECT_REF_INFO_INT);
out.writeInt( id);
return in.readInt();
} catch (IOException e) {
return 0;
}
*/
} }
public int[] getObjectRefInfoIntArray(int id, int elements)
{
try
{
Sub sub = (Sub)subscriptions.elementAt(id);
if(sub.oddSts())
{
return sub.valueIntArray;
}
return null;
}
catch(ArrayIndexOutOfBoundsException e)
{
//System.out.println("ArrayIndexOutOfBounds getObjectRefInfoInt");
return null;
}
}
public String getObjectRefInfoString(int id, int typeid) public String getObjectRefInfoString(int id, int typeid)
{ {
...@@ -677,17 +711,29 @@ public class Gdh ...@@ -677,17 +711,29 @@ public class Gdh
//System.out.println("ArrayIndexOutOfBounds getObjectRefInfoString index " + id); //System.out.println("ArrayIndexOutOfBounds getObjectRefInfoString index " + id);
return " "; return " ";
} }
/*
try {
out.writeInt( GET_OBJECT_REF_INFO_STRING);
out.writeInt( id);
out.writeInt( typeid);
return in.readUTF();
} catch (IOException e) {
return "";
} }
*/
public String[] getObjectRefInfoStringArray(int id, int typeid, int size, int elements)
{
try
{
Sub sub = (Sub)subscriptions.elementAt(id);
if(sub.evenSts() || sub.valueStringArray == null)
{
if(sub.evenSts())
System.out.println("getObjectRefInfoString substs " + sub.getSts() + " id " + id);
return null;
} }
return sub.valueStringArray;
}
catch(ArrayIndexOutOfBoundsException e)
{
//System.out.println("ArrayIndexOutOfBounds getObjectRefInfoString index " + id);
return null;
}
}
public synchronized PwrtStatus unrefObjectInfo(PwrtRefId refid) public synchronized PwrtStatus unrefObjectInfo(PwrtRefId refid)
...@@ -1231,36 +1277,8 @@ public class Gdh ...@@ -1231,36 +1277,8 @@ public class Gdh
out.writeInt(GET_OBJECT_REF_INFO_ALL); out.writeInt(GET_OBJECT_REF_INFO_ALL);
out.flush(); out.flush();
//Object retArray[] = (Object[])in.readObject();
//Object retArray[] = (Object[])inbuff.readObject();
//Object ret[] = (Object[])retArray[0];
//String sVec[] = (String[])retArray[0];
//boolean bVec[] = (boolean[])retArray[1];
//int iVec[] = (int[])retArray[2];
//float fVec[] = (float[])retArray[3];
/*
int thSubSize = in.readInt();
Object ret[] = (Object[])in.readObject();
*/
//subscriptions.clear();
//subscriptions.setSize(ret.length);
/*
String sVec[] = (String[])in.readObject();
boolean bVec[] = (boolean[])in.readObject();
int iVec[] = (int[])in.readObject();
float fVec[] = (float[])in.readObject();
*/
for(int i = 0; i < subscriptions.size();i++) for(int i = 0; i < subscriptions.size();i++)
{ {
//subscriptions.set(i, (jpwr.rt.Sub)ret[i]);
/*
((jpwr.rt.Sub)(subscriptions.get(i))).valueString = sVec[i];
((jpwr.rt.Sub)(subscriptions.get(i))).valueBoolean = bVec[i];
((jpwr.rt.Sub)(subscriptions.get(i))).valueInt = iVec[i];
((jpwr.rt.Sub)(subscriptions.get(i))).valueFloat = fVec[i];
*/
try try
{ {
...@@ -1645,24 +1663,11 @@ public class Gdh ...@@ -1645,24 +1663,11 @@ public class Gdh
return 0; return 0;
} }
/* }
private class Sub extends GdhrRefObjectInfo implements Serializable
{
String attrName;
int subscriptionsIndex;
int valueInt;
float valueFloat;
boolean valueBoolean;
String valueString;
public Sub(String attrName, PwrtRefId refid, int id, int typeId, int subscriptionsIndex)
{
super(refid, id, 0, typeId);
this.attrName = attrName;
this.subscriptionsIndex = subscriptionsIndex;
}
}
*/
}
...@@ -14,6 +14,8 @@ public class GeDynTable extends GeDynElem { ...@@ -14,6 +14,8 @@ public class GeDynTable extends GeDynElem {
public boolean[] selAttrFound; public boolean[] selAttrFound;
PwrtRefId[] subid; PwrtRefId[] subid;
int[] p; int[] p;
public int[] elements;
public int[] size;
public int[] typeId; public int[] typeId;
public boolean[][] oldValueB; public boolean[][] oldValueB;
public float[][] oldValueF; public float[][] oldValueF;
...@@ -35,6 +37,8 @@ public class GeDynTable extends GeDynElem { ...@@ -35,6 +37,8 @@ public class GeDynTable extends GeDynElem {
p = new int[columns]; p = new int[columns];
subid = new PwrtRefId[columns]; subid = new PwrtRefId[columns];
typeId = new int[columns]; typeId = new int[columns];
elements = new int[columns];
size = new int[columns];
attrFound = new boolean[columns]; attrFound = new boolean[columns];
selAttrFound = new boolean[columns]; selAttrFound = new boolean[columns];
oldValueB = new boolean[columns][]; oldValueB = new boolean[columns][];
...@@ -57,6 +61,10 @@ public class GeDynTable extends GeDynElem { ...@@ -57,6 +61,10 @@ public class GeDynTable extends GeDynElem {
p[i] = ret.id; p[i] = ret.id;
subid[i] = ret.refid; subid[i] = ret.refid;
typeId[i] = ret.typeId; typeId[i] = ret.typeId;
elements[i] = ret.getElements();
size[i] = ret.getSize();
if ( elements[i] > rows)
elements[i] = rows;
if ( typeId[i] == Pwr.eType_Float32) { if ( typeId[i] == Pwr.eType_Float32) {
oldValueF[i] = new float[rows]; oldValueF[i] = new float[rows];
} }
...@@ -92,26 +100,26 @@ public class GeDynTable extends GeDynElem { ...@@ -92,26 +100,26 @@ public class GeDynTable extends GeDynElem {
continue; continue;
if ( typeId[i] == Pwr.eType_Float32) { if ( typeId[i] == Pwr.eType_Float32) {
float value0 = dyn.en.gdh.getObjectRefInfoFloat( p[i]); float[] value0 = dyn.en.gdh.getObjectRefInfoFloatArray( p[i], elements[i]);
for ( int j = 0; j < 1; j++) { // Just the first row... for ( int j = 0; j < value0.length; j++) {
if ( value0 != oldValueF[i][j] || firstScan) { if ( value0[j] != oldValueF[i][j] || firstScan) {
sb = cFormat[i].format( value0, sb); sb = cFormat[i].format( value0[j], sb);
((GeTable)dyn.comp).setValueAt(new String(sb), j, i); ((GeTable)dyn.comp).setValueAt(new String(sb), j, i);
// dyn.repaintNow = true; // dyn.repaintNow = true;
oldValueF[i][j] = value0; oldValueF[i][j] = value0[j];
} }
} }
} }
else if ( typeId[i] == Pwr.eType_Boolean) { else if ( typeId[i] == Pwr.eType_Boolean) {
boolean value0 = dyn.en.gdh.getObjectRefInfoBoolean( p[i]); boolean[] value0 = dyn.en.gdh.getObjectRefInfoBooleanArray( p[i], elements[i]);
for ( int j = 0; j < 1; j++) { // Just the first row... for ( int j = 0; j < value0.length; j++) {
if ( value0 != oldValueB[i][j] || firstScan) { if ( value0[j] != oldValueB[i][j] || firstScan) {
if ( value0) if ( value0[j])
((GeTable)dyn.comp).setValueAt("1", j, i); ((GeTable)dyn.comp).setValueAt("1", j, i);
else else
((GeTable)dyn.comp).setValueAt("0", j, i); ((GeTable)dyn.comp).setValueAt("0", j, i);
// dyn.repaintNow = true; // dyn.repaintNow = true;
oldValueB[i][j] = value0; oldValueB[i][j] = value0[j];
} }
} }
} }
...@@ -121,26 +129,26 @@ public class GeDynTable extends GeDynElem { ...@@ -121,26 +129,26 @@ public class GeDynTable extends GeDynElem {
typeId[i] == Pwr.eType_UInt16 || typeId[i] == Pwr.eType_UInt16 ||
typeId[i] == Pwr.eType_Int8 || typeId[i] == Pwr.eType_Int8 ||
typeId[i] == Pwr.eType_UInt8) { typeId[i] == Pwr.eType_UInt8) {
int value0 = dyn.en.gdh.getObjectRefInfoInt( p[i]); int value0[] = dyn.en.gdh.getObjectRefInfoIntArray( p[i], elements[i]);
for ( int j = 0; j < 1; j++) { // Just the first row... for ( int j = 0; j < value0.length; j++) {
if ( value0 != oldValueI[i][j] || firstScan) { if ( value0[j] != oldValueI[i][j] || firstScan) {
sb = cFormat[i].format( value0, sb); sb = cFormat[i].format( value0[j], sb);
((GeTable)dyn.comp).setValueAt(new String(sb), j, i); ((GeTable)dyn.comp).setValueAt(new String(sb), j, i);
// dyn.repaintNow = true; // dyn.repaintNow = true;
oldValueI[i][j] = value0; oldValueI[i][j] = value0[j];
} }
} }
} }
else if ( typeId[i] == Pwr.eType_String || else if ( typeId[i] == Pwr.eType_String ||
typeId[i] == Pwr.eType_Objid) { typeId[i] == Pwr.eType_Objid) {
String value0 = dyn.en.gdh.getObjectRefInfoString( p[i], typeId[i]); String[] value0 = dyn.en.gdh.getObjectRefInfoStringArray( p[i], typeId[i], size[i], elements[i]);
for ( int j = 0; j < 1; j++) { // Just the first row... for ( int j = 0; j < value0.length; j++) {
if ( firstScan || value0.compareTo( oldValueS[i][j]) != 0) { if ( firstScan || value0[j].compareTo( oldValueS[i][j]) != 0) {
sb = cFormat[i].format( value0, sb); sb = cFormat[i].format( value0[j], sb);
((GeTable)dyn.comp).setValueAt(new String(sb), j, i); ((GeTable)dyn.comp).setValueAt(new String(sb), j, i);
// dyn.repaintNow = true; // dyn.repaintNow = true;
oldValueS[i][j] = value0; oldValueS[i][j] = value0[j];
} }
} }
} }
......
...@@ -274,10 +274,17 @@ public class Gdh { ...@@ -274,10 +274,17 @@ public class Gdh {
public native CdhrObjid getObjectInfoObjid( String attributeName); public native CdhrObjid getObjectInfoObjid( String attributeName);
public native PwrtStatus toggleObjectInfo( String attributeName); public native PwrtStatus toggleObjectInfo( String attributeName);
public native GdhrRefObjectInfo refObjectInfo( String attributeName); public native GdhrRefObjectInfo refObjectInfo( String attributeName);
public native float getObjectRefInfoFloat( int id); public native float getObjectRefInfoFloat( int id);
public native boolean getObjectRefInfoBoolean( int id); public native boolean getObjectRefInfoBoolean( int id);
public native int getObjectRefInfoInt( int id); public native int getObjectRefInfoInt( int id);
public native String getObjectRefInfoString( int id, int typeid); public native String getObjectRefInfoString( int id, int typeid);
public native float[] getObjectRefInfoFloatArray( int id, int elements);
public native boolean[] getObjectRefInfoBooleanArray( int id, int elements);
public native int[] getObjectRefInfoIntArray( int id, int elements);
public native String[] getObjectRefInfoStringArray( int id, int typeid, int size, int elements);
public native PwrtStatus unrefObjectInfo( PwrtRefId refid); public native PwrtStatus unrefObjectInfo( PwrtRefId refid);
public native CdhrObjid nameToObjid( String objectName); public native CdhrObjid nameToObjid( String objectName);
public native CdhrString objidToName( PwrtObjid objid, int nameType); public native CdhrString objidToName( PwrtObjid objid, int nameType);
......
...@@ -62,13 +62,19 @@ public class GdhServer ...@@ -62,13 +62,19 @@ public class GdhServer
public final static int CRR_OBJECT = 43; public final static int CRR_OBJECT = 43;
public final static int GET_PARENT = 44; public final static int GET_PARENT = 44;
public final static int GET_OBJECT_INFO_OBJID = 45; public final static int GET_OBJECT_INFO_OBJID = 45;
public final static int GET_OBJECT_REF_INFO_BOOLEAN_ARRAY = 46;
public final static int GET_OBJECT_REF_INFO_FLOAT_ARRAY = 47;
public final static int GET_OBJECT_REF_INFO_INT_ARRAY = 48;
public final static int GET_OBJECT_REF_INFO_STRING_ARRAY = 49;
public final static int PORT = 4445; public final static int PORT = 4445;
public final static int __IO_EXCEPTION = 2000; public final static int __IO_EXCEPTION = 2000;
public final static int __UNREFED = 0; public final static int __UNREFED = 0;
static ArrayList subscriptions = new ArrayList(); static ArrayList subscriptions = new ArrayList();
// static Vector nrOfSubscriptionClients = new Vector();
static int subscriptionCount = 0; static int subscriptionCount = 0;
static int threadCount = 0; static int threadCount = 0;
...@@ -277,14 +283,14 @@ public class GdhServer ...@@ -277,14 +283,14 @@ public class GdhServer
*/ */
public GdhThread(Socket clientSocket, int threadNumber, int maxConnections) public GdhThread(Socket clientSocket, int threadNumber, int maxConnections)
{ {
/* /************ In case of debugging this might be useful
System.out.println("threadnumber : " + threadNumber + "maxconn " + maxConnections); System.out.println("threadnumber : " + threadNumber + "maxconn " + maxConnections);
try{ try{
System.out.println("HostName :" + clientSocket.getInetAddress().getHostName() + System.out.println("HostName :" + clientSocket.getInetAddress().getHostName() +
"Delay : " + clientSocket.getTcpNoDelay()); "Delay : " + clientSocket.getTcpNoDelay());
} }
catch(SocketException exc){} catch(SocketException exc){}
*/ *************************************/
this.threadNumber = threadNumber; this.threadNumber = threadNumber;
this.clientSocket = clientSocket; this.clientSocket = clientSocket;
this.maxConnections = maxConnections; this.maxConnections = maxConnections;
...@@ -315,9 +321,6 @@ public class GdhServer ...@@ -315,9 +321,6 @@ public class GdhServer
out.flush(); out.flush();
in = new ObjectInputStream(new BufferedInputStream(clientSocket.getInputStream())); in = new ObjectInputStream(new BufferedInputStream(clientSocket.getInputStream()));
//buff = new BufferedOutputStream(clientSocket.getOutputStream());
//outbuff = new ObjectOutputStream(buff);
} }
catch(IOException e) catch(IOException e)
{ {
...@@ -330,7 +333,6 @@ public class GdhServer ...@@ -330,7 +333,6 @@ public class GdhServer
try try
{ {
// out.writeLong(9998);
int function = in.readInt(); int function = in.readInt();
while(function != 9999) while(function != 9999)
{ {
...@@ -516,6 +518,8 @@ public class GdhServer ...@@ -516,6 +518,8 @@ public class GdhServer
out.writeInt(ret.refid.nid); out.writeInt(ret.refid.nid);
out.writeInt(thSub.size() - 1); out.writeInt(thSub.size() - 1);
out.writeInt(ret.typeId); out.writeInt(ret.typeId);
out.writeInt(ret.size);
out.writeInt(ret.elements);
} }
out.flush(); out.flush();
} }
...@@ -544,7 +548,8 @@ public class GdhServer ...@@ -544,7 +548,8 @@ public class GdhServer
out.writeInt(ret.refid.nid); out.writeInt(ret.refid.nid);
out.writeInt(thSub.size() - 1); out.writeInt(thSub.size() - 1);
out.writeInt(ret.typeId); out.writeInt(ret.typeId);
out.writeInt(ret.size);
out.writeInt(ret.elements);
} }
} }
out.flush(); out.flush();
...@@ -559,8 +564,6 @@ public class GdhServer ...@@ -559,8 +564,6 @@ public class GdhServer
case REF_OBJECT_INFO_VECTOR: case REF_OBJECT_INFO_VECTOR:
try try
{ {
//System.out.println("Start p refobjinfvec" + (new Timestamp(new Date().getTime())).toString());
//Vector retVec = new Vector();
Vector vec = (Vector)in.readObject(); Vector vec = (Vector)in.readObject();
if(vec == null) if(vec == null)
{ {
...@@ -569,7 +572,6 @@ public class GdhServer ...@@ -569,7 +572,6 @@ public class GdhServer
out.flush(); out.flush();
break; break;
} }
//Sub gdhRet;
String attrName; String attrName;
Vector gdhRet = new Vector(vec.size()); Vector gdhRet = new Vector(vec.size());
for(int j = 0; j < vec.size(); j++) for(int j = 0; j < vec.size(); j++)
...@@ -583,7 +585,9 @@ public class GdhServer ...@@ -583,7 +585,9 @@ public class GdhServer
new PwrtRefId(thSub.size() - 1, ret.refid.nid), new PwrtRefId(thSub.size() - 1, ret.refid.nid),
ret.id, ret.id,
ret.typeId, ret.typeId,
ret.subscriptionsIndex); ret.subscriptionsIndex,
ret.elements,
ret.size );
retToCli.sts = ret.sts; retToCli.sts = ret.sts;
gdhRet.add(retToCli); gdhRet.add(retToCli);
} }
...@@ -596,8 +600,6 @@ public class GdhServer ...@@ -596,8 +600,6 @@ public class GdhServer
out.writeObject(gdhRet); out.writeObject(gdhRet);
out.flush(); out.flush();
//out.reset();
//System.out.println("Stop p refobjinfvec " + (new Timestamp(new Date().getTime())).toString());
} }
catch(NotSerializableException e) catch(NotSerializableException e)
{ {
...@@ -621,38 +623,17 @@ public class GdhServer ...@@ -621,38 +623,17 @@ public class GdhServer
System.out.println("Start GET_OBJECT_REF_INFO_ALL" + (new Timestamp(new Date().getTime())).toString()); System.out.println("Start GET_OBJECT_REF_INFO_ALL" + (new Timestamp(new Date().getTime())).toString());
} }
Sub subElement; Sub subElement;
//Object cli[] = new Object[thSub.size()];
for(i = 0; i < thSub.size(); i++) for(i = 0; i < thSub.size(); i++)
{ {
subElement = ((Sub)thSub.elementAt(i)); subElement = ((Sub)thSub.elementAt(i));
int index = subElement.getIndex(); int index = subElement.getIndex();
//int id = (int)((SubElement)subCopy.elementAt(index)).sub.id;
//int typeId = (int)((SubElement)subCopy.elementAt(index)).sub.typeId;
int id = subElement.id; int id = subElement.id;
int typeId = subElement.typeId; int typeId = subElement.typeId;
/* if(sub.sts == __UNREFED) int elements = subElement.elements;
{ int size = subElement.size;
continue;
}
boolean found = false;
for(int j = 0; j < ((SubElement)subCopy.elementAt(i)).reffedByThread.length; j++)
{
if(((SubElement)subCopy.elementAt(i)).reffedByThread[j][0] == threadNumber)
{
found = true;
break;
}
}
if(!found)
{
continue;
}
*/
//System.out.println(id + " typeId " + typeId);
//System.out.println("refinfoall");
switch (typeId) switch (typeId)
{ {
case Pwr.eType_Int32: case Pwr.eType_Int32:
...@@ -661,49 +642,49 @@ public class GdhServer ...@@ -661,49 +642,49 @@ public class GdhServer
case Pwr.eType_UInt16: case Pwr.eType_UInt16:
case Pwr.eType_Int8: case Pwr.eType_Int8:
case Pwr.eType_UInt8: case Pwr.eType_UInt8:
//cli[i] = new Integer(gdh.getObjectRefInfoInt(id)); if(elements > 1)
{
//its an array
out.writeObject(gdh.getObjectRefInfoIntArray(id, elements));
}
else
out.writeInt(gdh.getObjectRefInfoInt(id)); out.writeInt(gdh.getObjectRefInfoInt(id));
break; break;
case Pwr.eType_Float32: case Pwr.eType_Float32:
//cli[i] = new Float(gdh.getObjectRefInfoFloat(id)); if(elements > 1)
{
//its an array
out.writeObject(gdh.getObjectRefInfoFloatArray(id, elements));
}
else
out.writeFloat(gdh.getObjectRefInfoFloat(id)); out.writeFloat(gdh.getObjectRefInfoFloat(id));
break; break;
case 0: case 0:
case Pwr.eType_Boolean: case Pwr.eType_Boolean:
//cli[i] = new Boolean(gdh.getObjectRefInfoBoolean(id)); if(elements > 1)
{
//its an array
out.writeObject(gdh.getObjectRefInfoBooleanArray(id, elements));
}
else
out.writeBoolean(gdh.getObjectRefInfoBoolean(id)); out.writeBoolean(gdh.getObjectRefInfoBoolean(id));
break; break;
default: default:
//cli[i] = gdh.getObjectRefInfoString(id, typeId); if(elements > 1)
{
//its an array
out.writeObject(gdh.getObjectRefInfoStringArray(id, typeId, size, elements));
}
else
out.writeObject(gdh.getObjectRefInfoString(id, typeId)); out.writeObject(gdh.getObjectRefInfoString(id, typeId));
break; break;
} }
//index = null;
//id = null;
//typeId = null;
} }
try try
{ {
//out.writeObject(cli);
out.flush(); out.flush();
/* //must be done if we dont want memory leaks...
long K = 1024;
long freeMem = Runtime.getRuntime().freeMemory() / K;
long totalMem = Runtime.getRuntime().totalMemory() / K;
System.out.println("Storlek p thSub: " + thSub.size() +
"storlek p sub: " + subscriptions.size() +
"Tillgngligt minne: " + freeMem + " KB" +
"Totalt minne: " + totalMem + " KB");
//ej behvligt
subCopy = null;
cli = null;
subElement = null;
*/
//mste gras annars tar minnet slut...
out.reset(); out.reset();
//System.gc();
//System.runFinalization();
if(logRefInfoAll) if(logRefInfoAll)
{ {
System.out.println("Slut GET_OBJECT_REF_INFO_ALL" + (new Timestamp(new Date().getTime())).toString()); System.out.println("Slut GET_OBJECT_REF_INFO_ALL" + (new Timestamp(new Date().getTime())).toString());
...@@ -724,7 +705,6 @@ public class GdhServer ...@@ -724,7 +705,6 @@ public class GdhServer
{ {
System.out.println("getObjectRefInfoAll: IO exception"); System.out.println("getObjectRefInfoAll: IO exception");
} }
//System.out.println("efter GET_OBJECT_REF_INFO_ALL");
break; break;
case GET_OBJECT_REF_INFO_FLOAT: case GET_OBJECT_REF_INFO_FLOAT:
try try
...@@ -779,6 +759,84 @@ public class GdhServer ...@@ -779,6 +759,84 @@ public class GdhServer
System.out.println("getObjectRefInfoString: IO exception"); System.out.println("getObjectRefInfoString: IO exception");
} }
break; break;
case GET_OBJECT_REF_INFO_FLOAT_ARRAY:
try
{
int id = in.readInt();
int index = ((Sub)thSub.elementAt(id)).getIndex();
int elements = ((Sub)thSub.elementAt(id)).getElements();
out.writeObject(gdh.getObjectRefInfoFloatArray(index, elements));
out.flush();
}
catch(IOException e)
{
System.out.println("getObjectRefInfoFloatArray: IO exception");
}
break;
case GET_OBJECT_REF_INFO_BOOLEAN_ARRAY:
try
{
int id = in.readInt();
int index = ((Sub)thSub.elementAt(id)).getIndex();
int elements = ((Sub)thSub.elementAt(id)).getElements();
out.writeObject(gdh.getObjectRefInfoBooleanArray(index, elements));
out.flush();
}
catch(IOException e)
{
System.out.println("getObjectRefInfoBooleanArray: IO exception");
}
break;
case GET_OBJECT_REF_INFO_INT_ARRAY:
try
{
int id = in.readInt();
int index = ((Sub)thSub.elementAt(id)).getIndex();
int elements = ((Sub)thSub.elementAt(id)).getElements();
out.writeObject(gdh.getObjectRefInfoIntArray(index, elements));
out.flush();
}
catch(IOException e)
{
System.out.println("getObjectRefInfoIntArray: IO exception");
}
break;
case GET_OBJECT_REF_INFO_STRING_ARRAY:
try
{
int id = in.readInt();
int typeid = in.readInt();
int index = ((Sub)thSub.elementAt(id)).getIndex();
int elements = ((Sub)thSub.elementAt(id)).getElements();
int size = ((Sub)thSub.elementAt(id)).getSize();
out.writeObject(gdh.getObjectRefInfoStringArray(index, typeid, size, elements));
out.flush();
}
catch(IOException e)
{
System.out.println("getObjectRefInfoStringArray: IO exception");
}
break;
case UNREF_OBJECT_INFO: case UNREF_OBJECT_INFO:
try try
{ {
...@@ -1425,10 +1483,9 @@ public class GdhServer ...@@ -1425,10 +1483,9 @@ public class GdhServer
ThreadNumbersConnected[ii] += j + ", "; ThreadNumbersConnected[ii] += j + ", ";
NumberOfPrenumerations[ii] += subEl.reffedByThread[j] + ", "; NumberOfPrenumerations[ii] += subEl.reffedByThread[j] + ", ";
} }
//ObjectAttributeNames[ii] = ((SubElement)subcp.get(ii)).sub.attrName;
} }
} }
//Object obj[][] = {ObjectAttributeNames, ThreadNumbersConnected, NumberOfPrenumerations};
out.writeInt(subcp.size()); out.writeInt(subcp.size());
out.writeInt(nrOfSub); out.writeInt(nrOfSub);
...@@ -1441,11 +1498,9 @@ public class GdhServer ...@@ -1441,11 +1498,9 @@ public class GdhServer
out.writeLong(Runtime.getRuntime().totalMemory()); out.writeLong(Runtime.getRuntime().totalMemory());
out.flush(); out.flush();
//mste gras annars tar minnet slut... //must be done if we dont want memory leaks...
out.reset(); out.reset();
//System.gc();
} }
catch(OutOfMemoryError e) catch(OutOfMemoryError e)
{ {
...@@ -1492,17 +1547,17 @@ public class GdhServer ...@@ -1492,17 +1547,17 @@ public class GdhServer
{ {
System.err.println("Close failed"); System.err.println("Close failed");
} }
//loopa igenom och kontrollera att alla prenumerationer har stoppats //check that all subscriptions has stopped
for(i = 0; i < thSub.size(); i++) for(i = 0; i < thSub.size(); i++)
{ {
try try
{ {
sub = ((Sub)thSub.elementAt(i)); sub = ((Sub)thSub.elementAt(i));
int index = ((Sub)thSub.elementAt(i)).getIndex(); int index = ((Sub)thSub.elementAt(i)).getIndex();
//PwrtRefId refid = (PwrtRefId)((SubElement)subCopy.elementAt(index)).sub.refid;
PwrtStatus sts = this.unrefObjectInfo(new PwrtRefId(index, sub.refid.nid), PwrtStatus sts = this.unrefObjectInfo(new PwrtRefId(index, sub.refid.nid),
threadNumber); threadNumber);
// System.out.println("unrefall :" + index + refid.nid);
} }
catch(ArrayIndexOutOfBoundsException exc) catch(ArrayIndexOutOfBoundsException exc)
{ {
...@@ -1529,7 +1584,7 @@ public class GdhServer ...@@ -1529,7 +1584,7 @@ public class GdhServer
*@param threadNumber Description of the Parameter *@param threadNumber Description of the Parameter
*@return Description of the Return Value *@return Description of the Return Value
*/ */
public synchronized Sub refObjectInfo(String attrName, int threadNumber /*, boolean putNextSubAtSubVecEnd*/) public synchronized Sub refObjectInfo(String attrName, int threadNumber)
{ {
SubElement sub; SubElement sub;
int firstUnreffedIndex = subscriptionCount; int firstUnreffedIndex = subscriptionCount;
...@@ -1562,8 +1617,6 @@ public class GdhServer ...@@ -1562,8 +1617,6 @@ public class GdhServer
if(ret.oddSts()) if(ret.oddSts())
{ {
sub = new SubElement(maxConnections, threadNumber); sub = new SubElement(maxConnections, threadNumber);
//sub.refObjectInfo = ret;
//sub.attrName = attrName;
if(notFoundUnreffed) if(notFoundUnreffed)
{ {
//System.out.println("this.refObjectInfo ej reffad ej lucka i subsc.. " + attrName + " " + subscriptionCount); //System.out.println("this.refObjectInfo ej reffad ej lucka i subsc.. " + attrName + " " + subscriptionCount);
...@@ -1582,7 +1635,6 @@ public class GdhServer ...@@ -1582,7 +1635,6 @@ public class GdhServer
subscriptions.add(firstUnreffedIndex, sub); subscriptions.add(firstUnreffedIndex, sub);
sub.reffedByThreadBitSet.set(threadNumber); sub.reffedByThreadBitSet.set(threadNumber);
sub.reffedByThread[threadNumber]++; sub.reffedByThread[threadNumber]++;
//lastIndexReffed = firstUnreffedIndex;
} }
} }
else else
......
...@@ -16,14 +16,31 @@ public class GdhrRefObjectInfo implements Serializable ...@@ -16,14 +16,31 @@ public class GdhrRefObjectInfo implements Serializable
public int sts; public int sts;
public int typeId; public int typeId;
public int subId; public int subId;
public int elements;
public int size;
public GdhrRefObjectInfo( PwrtRefId refid, int id, int sts, int typeId) { public GdhrRefObjectInfo( PwrtRefId refid, int id, int sts, int typeId) {
this.refid = refid; this.refid = refid;
this.id = id; this.id = id;
this.sts = sts; this.sts = sts;
this.typeId = typeId; this.typeId = typeId;
//default values in case we have forgotten to use the new constructor
this.elements = 1;
this.size = 4;
} }
public GdhrRefObjectInfo( PwrtRefId refid, int id, int sts, int typeId, int elements, int size) {
this.refid = refid;
this.id = id;
this.sts = sts;
this.typeId = typeId;
this.elements = elements;
this.size = size;
}
public boolean evenSts() { return (sts % 2 == 0);} public boolean evenSts() { return (sts % 2 == 0);}
public boolean oddSts() { return (sts % 2 == 1);} public boolean oddSts() { return (sts % 2 == 1);}
public int getSts() { return sts;} public int getSts() { return sts;}
public int getElements(){ return elements;}
public int getSize(){ return size;}
} }
...@@ -14,22 +14,16 @@ ...@@ -14,22 +14,16 @@
public float valueFloat; public float valueFloat;
public boolean valueBoolean; public boolean valueBoolean;
public String valueString; public String valueString;
/*
public PwrtRefId refid; public int[] valueIntArray;
public int id; public float[] valueFloatArray;
public int sts; public boolean[] valueBooleanArray;
public int typeId; public String[] valueStringArray;
public int subId;
*/
public Sub(String attrName, PwrtRefId refid, int id, int typeId, int public Sub(String attrName, PwrtRefId refid, int id, int typeId, int
subscriptionsIndex, int valueInt, float valueFloat, boolean valueBoolean, String valueString) subscriptionsIndex, int valueInt, float valueFloat, boolean valueBoolean, String valueString)
{ {
/*
this.refid = refid;
this.id = id;
this.sts = 0;
this.typeId = typeId;
*/
super(refid, id, 0, typeId); super(refid, id, 0, typeId);
this.subscriptionsIndex = subscriptionsIndex; this.subscriptionsIndex = subscriptionsIndex;
this.valueInt = valueInt; this.valueInt = valueInt;
...@@ -69,25 +63,20 @@ ...@@ -69,25 +63,20 @@
public Sub(String attrName, PwrtRefId refid, int id, int typeId, int subscriptionsIndex) public Sub(String attrName, PwrtRefId refid, int id, int typeId, int subscriptionsIndex, int elements, int size)
{ {
/* super(refid, id, 0, typeId, elements, size);
this.refid = refid;
this.id = id;
this.sts = sts;
this.typeId = typeId;
*/
super(refid, id, 0, typeId);
this.attrName = attrName; this.attrName = attrName;
this.subscriptionsIndex = subscriptionsIndex; this.subscriptionsIndex = subscriptionsIndex;
} }
//public boolean evenSts() { return (sts % 2 == 0);}
//public boolean oddSts() { return (sts % 2 == 1);}
//public int getSts() { return sts;}
int getIndex() int getIndex()
{ {
return subscriptionsIndex; return subscriptionsIndex;
} }
} }
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
{ {
public int[] reffedByThread; public int[] reffedByThread;
public BitSet reffedByThreadBitSet; public BitSet reffedByThreadBitSet;
Sub sub = new Sub(" ", new PwrtRefId(0, 0), 0, 0, 0); Sub sub = new Sub(" ", new PwrtRefId(0, 0), 0, 0, 0,0,0);
public SubElement(int maxConnections, int threadNumber) public SubElement(int maxConnections, int threadNumber)
...@@ -40,6 +40,8 @@ ...@@ -40,6 +40,8 @@
this.sub.id = obj.id; this.sub.id = obj.id;
this.sub.sts = obj.sts; this.sub.sts = obj.sts;
this.sub.typeId = obj.typeId; this.sub.typeId = obj.typeId;
this.sub.size = obj.size;
this.sub.elements = obj.elements;
this.sub.subscriptionsIndex = subscriptionsIndex; this.sub.subscriptionsIndex = subscriptionsIndex;
} }
...@@ -48,3 +50,4 @@ ...@@ -48,3 +50,4 @@
return (this.sub.attrName.equalsIgnoreCase(((SubElement)o).sub.attrName) && (((SubElement)o).sub.sts != 0)); return (this.sub.attrName.equalsIgnoreCase(((SubElement)o).sub.attrName) && (((SubElement)o).sub.sts != 0));
} }
} }
...@@ -52,6 +52,13 @@ public class Gdh ...@@ -52,6 +52,13 @@ public class Gdh
public final static int GET_PARENT = 44; public final static int GET_PARENT = 44;
public final static int GET_OBJECT_INFO_OBJID = 45; public final static int GET_OBJECT_INFO_OBJID = 45;
public final static int GET_OBJECT_REF_INFO_BOOLEAN_ARRAY = 46;
public final static int GET_OBJECT_REF_INFO_FLOAT_ARRAY = 47;
public final static int GET_OBJECT_REF_INFO_INT_ARRAY = 48;
public final static int GET_OBJECT_REF_INFO_STRING_ARRAY = 49;
public final static int __IO_EXCEPTION = 2000; public final static int __IO_EXCEPTION = 2000;
public final static int __BUSY = 2002; public final static int __BUSY = 2002;
public final static int __UNREFED = 0; public final static int __UNREFED = 0;
...@@ -367,7 +374,7 @@ public class Gdh ...@@ -367,7 +374,7 @@ public class Gdh
return new GdhrRefObjectInfo(null, 0, 0, 0); return new GdhrRefObjectInfo(null, 0, 0, 0);
} }
//qqq //qqq
Sub sub = new Sub(attributeName, null, 0, typeId, subscriptionCount); Sub sub = new Sub(attributeName, null, 0, typeId, subscriptionCount, 0, 0);
subscriptions.insertElementAt(sub, subscriptionCount); subscriptions.insertElementAt(sub, subscriptionCount);
subscriptionCount++; subscriptionCount++;
return new GdhrRefObjectInfo(refid, id, 1, typeId); return new GdhrRefObjectInfo(refid, id, 1, typeId);
...@@ -395,13 +402,15 @@ public class Gdh ...@@ -395,13 +402,15 @@ public class Gdh
PwrtRefId refid = new PwrtRefId(rix, nid); PwrtRefId refid = new PwrtRefId(rix, nid);
int id = in.readInt(); int id = in.readInt();
int typeId = in.readInt(); int typeId = in.readInt();
Sub sub = new Sub(attributeName, refid, id, typeId,subscriptionCount); int size = in.readInt();
int elements = in.readInt();
Sub sub = new Sub(attributeName, refid, id, typeId,subscriptionCount, size, elements);
sub.sts = 1; sub.sts = 1;
subscriptions.insertElementAt(sub, id); subscriptions.insertElementAt(sub, id);
subscriptionCount++; subscriptionCount++;
refid = new PwrtRefId(id, 0); refid = new PwrtRefId(id, 0);
subLate++; subLate++;
return new GdhrRefObjectInfo(refid, id, sts, typeId); return new GdhrRefObjectInfo(refid, id, sts, typeId, size, elements);
} }
catch(IOException e) catch(IOException e)
{ {
...@@ -420,6 +429,7 @@ public class Gdh ...@@ -420,6 +429,7 @@ public class Gdh
int nid; int nid;
int id; int id;
int typeId; int typeId;
PwrtRefId refid; PwrtRefId refid;
if(listSent) if(listSent)
...@@ -472,6 +482,8 @@ public class Gdh ...@@ -472,6 +482,8 @@ public class Gdh
sub.refid = new PwrtRefId(rix, nid); sub.refid = new PwrtRefId(rix, nid);
id = in.readInt(); id = in.readInt();
typeId = in.readInt(); typeId = in.readInt();
sub.size = in.readInt();
sub.elements = in.readInt();
} }
locked = false; locked = false;
notify(); notify();
...@@ -540,8 +552,7 @@ public class Gdh ...@@ -540,8 +552,7 @@ public class Gdh
} }
ret.id = ret.refid.rix; ret.id = ret.refid.rix;
subscriptions.add(ret); subscriptions.add(ret);
//((Sub)retVec.get(i)).refid.rix = ((Sub)retVec.get(i)).id;
//System.out.println("Status " + ((Sub)retVec.get(i)).getSts());
} }
subscriptionCount += retVec.size(); subscriptionCount += retVec.size();
...@@ -591,17 +602,24 @@ public class Gdh ...@@ -591,17 +602,24 @@ public class Gdh
//System.out.println("ArrayIndexOutOfBounds getObjectRefInfoFloat"); //System.out.println("ArrayIndexOutOfBounds getObjectRefInfoFloat");
return 0F; return 0F;
} }
/*
try {
out.writeInt( GET_OBJECT_REF_INFO_FLOAT);
out.writeInt( id);
return in.readFloat();
} catch (IOException e) {
return 0F;
}
*/
} }
public float[] getObjectRefInfoFloatArray(int id, int elements)
{
try{
Sub sub = (Sub)subscriptions.elementAt(id);
if(sub.oddSts())
{
return sub.valueFloatArray;
}
return null;
}
catch(ArrayIndexOutOfBoundsException e)
{
//System.out.println("ArrayIndexOutOfBounds getObjectRefInfoFloat");
return null;
}
}
public boolean getObjectRefInfoBoolean(int id) public boolean getObjectRefInfoBoolean(int id)
{ {
...@@ -619,17 +637,25 @@ public class Gdh ...@@ -619,17 +637,25 @@ public class Gdh
//System.out.println("ArrayIndexOutOfBounds getObjectRefInfoBoolean"); //System.out.println("ArrayIndexOutOfBounds getObjectRefInfoBoolean");
return false; return false;
} }
/*
try {
out.writeInt( GET_OBJECT_REF_INFO_BOOLEAN);
out.writeInt( id);
return in.readBoolean();
} catch (IOException e) {
return false;
}
*/
} }
public boolean[] getObjectRefInfoBooleanArray(int id, int elements)
{
try
{
Sub sub = (Sub)subscriptions.elementAt(id);
if(sub.oddSts())
{
return sub.valueBooleanArray;
}
return null;
}
catch(ArrayIndexOutOfBoundsException e)
{
//System.out.println("ArrayIndexOutOfBounds getObjectRefInfoBoolean");
return null;
}
}
public int getObjectRefInfoInt(int id) public int getObjectRefInfoInt(int id)
{ {
...@@ -647,17 +673,25 @@ public class Gdh ...@@ -647,17 +673,25 @@ public class Gdh
//System.out.println("ArrayIndexOutOfBounds getObjectRefInfoInt"); //System.out.println("ArrayIndexOutOfBounds getObjectRefInfoInt");
return 0; return 0;
} }
/*
try {
out.writeInt( GET_OBJECT_REF_INFO_INT);
out.writeInt( id);
return in.readInt();
} catch (IOException e) {
return 0;
}
*/
} }
public int[] getObjectRefInfoIntArray(int id, int elements)
{
try
{
Sub sub = (Sub)subscriptions.elementAt(id);
if(sub.oddSts())
{
return sub.valueIntArray;
}
return null;
}
catch(ArrayIndexOutOfBoundsException e)
{
//System.out.println("ArrayIndexOutOfBounds getObjectRefInfoInt");
return null;
}
}
public String getObjectRefInfoString(int id, int typeid) public String getObjectRefInfoString(int id, int typeid)
{ {
...@@ -677,17 +711,29 @@ public class Gdh ...@@ -677,17 +711,29 @@ public class Gdh
//System.out.println("ArrayIndexOutOfBounds getObjectRefInfoString index " + id); //System.out.println("ArrayIndexOutOfBounds getObjectRefInfoString index " + id);
return " "; return " ";
} }
/*
try {
out.writeInt( GET_OBJECT_REF_INFO_STRING);
out.writeInt( id);
out.writeInt( typeid);
return in.readUTF();
} catch (IOException e) {
return "";
} }
*/
public String[] getObjectRefInfoStringArray(int id, int typeid, int size, int elements)
{
try
{
Sub sub = (Sub)subscriptions.elementAt(id);
if(sub.evenSts() || sub.valueStringArray == null)
{
if(sub.evenSts())
System.out.println("getObjectRefInfoString substs " + sub.getSts() + " id " + id);
return null;
} }
return sub.valueStringArray;
}
catch(ArrayIndexOutOfBoundsException e)
{
//System.out.println("ArrayIndexOutOfBounds getObjectRefInfoString index " + id);
return null;
}
}
public synchronized PwrtStatus unrefObjectInfo(PwrtRefId refid) public synchronized PwrtStatus unrefObjectInfo(PwrtRefId refid)
...@@ -1231,36 +1277,8 @@ public class Gdh ...@@ -1231,36 +1277,8 @@ public class Gdh
out.writeInt(GET_OBJECT_REF_INFO_ALL); out.writeInt(GET_OBJECT_REF_INFO_ALL);
out.flush(); out.flush();
//Object retArray[] = (Object[])in.readObject();
//Object retArray[] = (Object[])inbuff.readObject();
//Object ret[] = (Object[])retArray[0];
//String sVec[] = (String[])retArray[0];
//boolean bVec[] = (boolean[])retArray[1];
//int iVec[] = (int[])retArray[2];
//float fVec[] = (float[])retArray[3];
/*
int thSubSize = in.readInt();
Object ret[] = (Object[])in.readObject();
*/
//subscriptions.clear();
//subscriptions.setSize(ret.length);
/*
String sVec[] = (String[])in.readObject();
boolean bVec[] = (boolean[])in.readObject();
int iVec[] = (int[])in.readObject();
float fVec[] = (float[])in.readObject();
*/
for(int i = 0; i < subscriptions.size();i++) for(int i = 0; i < subscriptions.size();i++)
{ {
//subscriptions.set(i, (jpwr.rt.Sub)ret[i]);
/*
((jpwr.rt.Sub)(subscriptions.get(i))).valueString = sVec[i];
((jpwr.rt.Sub)(subscriptions.get(i))).valueBoolean = bVec[i];
((jpwr.rt.Sub)(subscriptions.get(i))).valueInt = iVec[i];
((jpwr.rt.Sub)(subscriptions.get(i))).valueFloat = fVec[i];
*/
try try
{ {
...@@ -1645,24 +1663,11 @@ public class Gdh ...@@ -1645,24 +1663,11 @@ public class Gdh
return 0; return 0;
} }
/* }
private class Sub extends GdhrRefObjectInfo implements Serializable
{
String attrName;
int subscriptionsIndex;
int valueInt;
float valueFloat;
boolean valueBoolean;
String valueString;
public Sub(String attrName, PwrtRefId refid, int id, int typeId, int subscriptionsIndex)
{
super(refid, id, 0, typeId);
this.attrName = attrName;
this.subscriptionsIndex = subscriptionsIndex;
}
}
*/
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment