[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r3122 - in freeway: . doc etc/support/clib native src/org/g
From: |
mdonoughe |
Subject: |
[GNUnet-SVN] r3122 - in freeway: . doc etc/support/clib native src/org/gnu/freeway src/org/gnu/freeway/protocol/afs/swing src/org/gnu/freeway/protocol/stats src/org/gnu/freeway/server src/org/gnu/freeway/services src/org/gnu/freeway/services/java src/org/gnu/freeway/util src/org/gnu/freeway/util/net |
Date: |
Sun, 16 Jul 2006 10:05:00 -0700 (PDT) |
Author: mdonoughe
Date: 2006-07-16 10:04:30 -0700 (Sun, 16 Jul 2006)
New Revision: 3122
Added:
freeway/src/org/gnu/freeway/protocol/stats/NativeStatsProtocol.java
freeway/src/org/gnu/freeway/services/java/
freeway/src/org/gnu/freeway/services/java/StatsService.java
freeway/src/org/gnu/freeway/util/AbstractNativeService.java
Removed:
freeway/doc/todo
freeway/doc/using eclipse
freeway/readme.html
freeway/src/org/gnu/freeway/server/CSStatistics.java
Modified:
freeway/
freeway/README
freeway/build.sh
freeway/configure.ac
freeway/doc/packaging
freeway/etc/support/clib/Makefile.am
freeway/etc/support/clib/freeway-clib.c
freeway/etc/support/clib/freeway-clib.h
freeway/native/Makefile.am
freeway/native/org_gnu_freeway_server_CPluginLoader.c
freeway/native/org_gnu_freeway_server_CPluginLoader.h
freeway/native/switch-table.c
freeway/protocols.xml
freeway/src/org/gnu/freeway/AbstractApplication.java
freeway/src/org/gnu/freeway/GNUNetDaemon.java
freeway/src/org/gnu/freeway/GNUNetStats.java
freeway/src/org/gnu/freeway/GNUNetTransportCheck.java
freeway/src/org/gnu/freeway/protocol/afs/swing/StatsWindow.java
freeway/src/org/gnu/freeway/protocol/stats/StatsProtocol.java
freeway/src/org/gnu/freeway/server/CPluginLoader.java
freeway/src/org/gnu/freeway/server/Core.java
freeway/src/org/gnu/freeway/server/CoreAPI.java
freeway/src/org/gnu/freeway/server/CoreService.java
freeway/src/org/gnu/freeway/util/DynamicLibrary.java
freeway/src/org/gnu/freeway/util/OSAccess.java
freeway/src/org/gnu/freeway/util/ServiceManager.java
freeway/src/org/gnu/freeway/util/Stat.java
freeway/src/org/gnu/freeway/util/Statistics.java
freeway/src/org/gnu/freeway/util/StatusCallsService.java
freeway/src/org/gnu/freeway/util/net/PersistentHelper.java
Log:
updated some documentation
improved building on Mac OS X
can now be built without GNUnet
OSAccess now uses the File class to find symlinks
registerThread now ensures that only one entry is created per thread
a list of types may be supplied when requesting a service
CPluginLoader will load a C service if the C library is already loaded
new protocol jars now specify a C-Class and Java-Class
DynamicLibrary supports calling an initializer function and will fall back on
other implementations as specified by FREEWAY-SERVICES
updated Stat and Statistics to use StatsService
removed some old documentation
implemented sending stats in Java
Property changes on: freeway
___________________________________________________________________
Name: svk:merge
+ ca0d4bff-9018-0410-8ce9-c5d843b21c37:/local/freeway:64
Modified: freeway/README
===================================================================
--- freeway/README 2006-07-16 08:50:44 UTC (rev 3121)
+++ freeway/README 2006-07-16 17:04:30 UTC (rev 3122)
@@ -3,7 +3,7 @@
Freeway is a Java port of the secure peer-to-peer GNUnet framework.
For a longer description of the GNUnet system, please see GNUnet's
webpages (http://www.gnu.org/projects/GNUnet/ and
-http://www.ovmj.org/GNUnet/).
+http://gnunet.org/).
Goals
-----
@@ -31,22 +31,22 @@
How to build it ?
-----------------
-You need Jikes to compile Freeway.
-An ant build file has been provided. To build needed jars, type:
-> cd $PROJECT_HOME
-> ant build
+You need AutoTools, Make, Jikes, and Sh to compile Freeway.
+To build Freeway, type:
+> sh bootstrap
+> sh configure
+> sh build.sh
How to use it ?
---------------
The default configuration should be okay for most of the systems
-($PROJECT_HOME/res/gnunet.root and $PROJECT_HOME/res/gnunet.user). For
+(Freeway will use your GNUnet configuration). For
more information on available options and their meanings, please see
-pages on http://www.ovmj.org/GNUnet/.
+pages on http://gnunet.org/.
-To start daemon, use gnunetd.sh script in $PROJECT_HOME/etc:
-> cd $PROJECT_HOME
+To start the daemon, use gnunetd.sh script in the Freeway folder:
> ./etc/gnunetd.sh -L INFO
Don't forget to set logging level to appropriate value since a lot of
@@ -57,16 +57,16 @@
---------------------
Any contribution will be greatly appreciated. Please submit bugs to
-http://www.ovmj.org/~mantis/ and patches via E-Mail to
address@hidden
+http://gnunet.org/mantis/ and patches via E-Mail to
address@hidden
Stay tuned
----------
-http://www.ovmj.org/GNUnet/freeway/
-http://mail.gnu.org/mailman/listinfo/freeway-developers
+http://gnunet.org/freeway/
+http://mail.gnu.org/mailman/listinfo/gnunet-developers
-Want to freely travel from peer to peer? Take the freeway!
+Want to freely travel from peer to peer? Take the freeway!
The Freeway team.
Modified: freeway/build.sh
===================================================================
--- freeway/build.sh 2006-07-16 08:50:44 UTC (rev 3121)
+++ freeway/build.sh 2006-07-16 17:04:30 UTC (rev 3122)
@@ -3,4 +3,8 @@
# Build Freeway and it's C libraries.
#
-ant && javah -classpath build/classes -d native
org.gnu.freeway.server.CPluginLoader && make && cp native/.libs/lib*.so* build/
&& cp etc/support/clib/.libs/lib*.so* build/
+ant && javah -classpath build/classes -d native
org.gnu.freeway.server.CPluginLoader && make || exit 1
+cp native/.libs/lib*.so* etc/support/clib/.libs/*.so* native/.libs/lib*.dylib
etc/support/clib/.libs/lib*.dylib build/ > /dev/null 2>&1
+mv build/libfreeway-clib.dylib build/libfreeway-clib.jnilib > /dev/null 2>&1
+mv build/liborg_gnu_freeway_server_cpluginloader.dylib
build/liborg_gnu_freeway_server_cpluginloader.jnilib > /dev/null 2>&1
+exit 0
Modified: freeway/configure.ac
===================================================================
--- freeway/configure.ac 2006-07-16 08:50:44 UTC (rev 3121)
+++ freeway/configure.ac 2006-07-16 17:04:30 UTC (rev 3122)
@@ -134,9 +134,11 @@
gnunet=1))])
if test "$gnunet" != 1
then
- AC_MSG_ERROR([Freeway requires GNUnet])
+ AC_MSG_WARN([GNUnet related code will not be compiled])
fi
+AM_CONDITIONAL(HAVE_GNUNET, test g"$gnunet" = "g1")
+
AC_CONFIG_FILES([
po/Makefile.in
Makefile
Modified: freeway/doc/packaging
===================================================================
--- freeway/doc/packaging 2006-07-16 08:50:44 UTC (rev 3121)
+++ freeway/doc/packaging 2006-07-16 17:04:30 UTC (rev 3122)
@@ -4,25 +4,25 @@
core classes (no protocol, no transport)
no resources
-freeway-afs.jar
+protocol-afs.jar
AFS protocol classes only
-freeway-afs-mysql.jar
+protocol-afs-mysql.jar
MySQL access classes only (loaded by AFS protocol)
-freeway-chat.jar
+protocol-chat.jar
Chat protocol classes
-freeway-tracekit.jar
+protocol-tracekit.jar
Trace protocol classes
-freeway-tcp.jar
+transport-tcp.jar
TCP transport classes
-freeway-udp.jar
+transport-udp.jar
UDP transport classes
-freeway-nat.jar
+transport-nat.jar
NAT transport classes
Deleted: freeway/doc/todo
===================================================================
--- freeway/doc/todo 2006-07-16 08:50:44 UTC (rev 3121)
+++ freeway/doc/todo 2006-07-16 17:04:30 UTC (rev 3122)
@@ -1,22 +0,0 @@
-
-
-daemon
-------
-
-
-tools
------
-
-
-ui
---
- . gerer le focus pour les wizards
- . creer des logos pour les joptionpane : logo freeway + un signe
- . setSelectedFile sur file chooser ne semble pas marcher
-
-
- . quand rien de configuré sur les dimensions
- - ouvrir les GFrame centrées à peu près à 1/3 écran
- - ouvrir les GDialog 1/2 de la GFrame owner
- -> important quand une configuration neuve...
-
Deleted: freeway/doc/using eclipse
===================================================================
--- freeway/doc/using eclipse 2006-07-16 08:50:44 UTC (rev 3121)
+++ freeway/doc/using eclipse 2006-07-16 17:04:30 UTC (rev 3122)
@@ -1,27 +0,0 @@
-Using Eclipse to access freeway sources
----------------------------------------
-WARNING: tested on Eclipse 3.0M7/Mac OS X
-
-Set up
- . get a developer cvs account (see [pending])
- . enable SSH2 protocol (diabled by default) in
/Preferences/Team/CVS/SSH2 Connection Method
- . create the repository in CVS perspective
- connection type : extssh
- user : your cvs account user name
- host : ovjm.org
- repository : /home/cvs/GNUnet
- . a SSH2 Client error dialog might appears the first time you log in
- . if you've used a passphrase to protect your keystore, a dialog will
next appear to ask it
-
-Create project
- . expand HEAD
- . use context menu 'Check Out As...' on freeway item
- a lot of problems should have been found
- . open Project Properties dialog
- . in Source tab, open Add Folder dialog and select 'src' subdirectory
- . in Libraries tab, open Add External Jars dialog and select jars found
in 'lib' subdirectory
-
-
-Please note that *all* Java sources are UTF-8 encoded. Be sure you've
configured Eclipse
-to have this encoding as default one when editing sources.
-
Modified: freeway/etc/support/clib/Makefile.am
===================================================================
--- freeway/etc/support/clib/Makefile.am 2006-07-16 08:50:44 UTC (rev
3121)
+++ freeway/etc/support/clib/Makefile.am 2006-07-16 17:04:30 UTC (rev
3122)
@@ -5,8 +5,6 @@
libfreeway_clib_la_LDFLAGS = \
-export-dynamic -version-info 0:0:0
-libfreeway_clib_la_LIBADD = \
- -lgnunetutil
libfreeway_clib_la_SOURCES = \
signals.c signals.h links.c links.h jni.h \
Modified: freeway/etc/support/clib/freeway-clib.c
===================================================================
--- freeway/etc/support/clib/freeway-clib.c 2006-07-16 08:50:44 UTC (rev
3121)
+++ freeway/etc/support/clib/freeway-clib.c 2006-07-16 17:04:30 UTC (rev
3122)
@@ -20,11 +20,13 @@
p=NULL;
ptr=(*env)->GetStringUTFChars(env,str,NULL);
+ fprintf(stderr, "getString1\n");
if (ptr!=NULL) {
len=(*env)->GetStringUTFLength(env,str);
p=(char*) malloc((len+1)*sizeof(char));
memcpy(p,ptr,len);
+ fprintf(stderr, "getString5\n");
p[len]=0;
(*env)->ReleaseStringUTFChars(env,str,ptr);
@@ -67,42 +69,6 @@
kill((pid_t) pid,(int) num);
}
-JNIEXPORT jboolean JNICALL Java_org_gnu_freeway_util_OSAccess__1fileIsLink(
JNIEnv* env, jclass class, jstring path )
-{
- char* fn;
- int ret;
-
- fn=getString(env,path);
- if (fn==NULL) {
- return JNI_FALSE;
- }
- ret=links_is(fn);
- free(fn);
- return (ret ? JNI_TRUE : JNI_FALSE);
-}
-
-JNIEXPORT jstring JNICALL
Java_org_gnu_freeway_util_OSAccess__1fileGetLinkTarget( JNIEnv* env, jclass
class, jstring path )
-{
- jstring str;
- char* fn;
- char* buf;
-
- fn=getString(env,path);
- if (fn==NULL) {
- return NULL;
- }
-
- buf=links_get_target(fn);
- free(fn);
- if (buf==NULL) {
- return NULL;
- }
-
- str=(*env)->NewStringUTF(env,buf);
- free(buf);
- return str;
-}
-
JNIEXPORT jboolean JNICALL
Java_org_gnu_freeway_util_OSAccess__1fileCreateLink( JNIEnv* env, jclass class,
jstring path, jstring target )
{
char* fn;
Modified: freeway/etc/support/clib/freeway-clib.h
===================================================================
--- freeway/etc/support/clib/freeway-clib.h 2006-07-16 08:50:44 UTC (rev
3121)
+++ freeway/etc/support/clib/freeway-clib.h 2006-07-16 17:04:30 UTC (rev
3122)
@@ -68,22 +68,6 @@
/*
* Class: org_gnu_freeway_util_OSAccess
- * Method: _fileIsLink
- * Signature: (Ljava/lang/String;)Z
- */
-JNIEXPORT jboolean JNICALL Java_org_gnu_freeway_util_OSAccess__1fileIsLink
- (JNIEnv *, jclass, jstring);
-
-/*
- * Class: org_gnu_freeway_util_OSAccess
- * Method: _fileGetLinkTarget
- * Signature: (Ljava/lang/String;)Ljava/lang/String;
- */
-JNIEXPORT jstring JNICALL
Java_org_gnu_freeway_util_OSAccess__1fileGetLinkTarget
- (JNIEnv *, jclass, jstring);
-
-/*
- * Class: org_gnu_freeway_util_OSAccess
* Method: _fileCreateLink
* Signature: (Ljava/lang/String;Ljava/lang/String;)Z
*/
Modified: freeway/native/Makefile.am
===================================================================
--- freeway/native/Makefile.am 2006-07-16 08:50:44 UTC (rev 3121)
+++ freeway/native/Makefile.am 2006-07-16 17:04:30 UTC (rev 3122)
@@ -1,3 +1,4 @@
+if HAVE_GNUNET
AM_CPPFLAGS = -DLOCALEDIR=\"$(localedir)\"
lib_LTLIBRARIES = \
@@ -11,3 +12,4 @@
liborg_gnu_freeway_server_CPluginLoader_la_SOURCES = \
org_gnu_freeway_server_CPluginLoader.c jni.h \
org_gnu_freeway_server_CPluginLoader.h gettext.h
+endif
Modified: freeway/native/org_gnu_freeway_server_CPluginLoader.c
===================================================================
--- freeway/native/org_gnu_freeway_server_CPluginLoader.c 2006-07-16
08:50:44 UTC (rev 3121)
+++ freeway/native/org_gnu_freeway_server_CPluginLoader.c 2006-07-16
17:04:30 UTC (rev 3122)
@@ -51,13 +51,13 @@
struct ModuleList * next;
} ModuleList;
+/**
+ * Used to identify which env / jcapi to use when called back.
+ */
typedef struct ActiveThreadList {
JNIEnv * env;
jobject jcapi;
-
- /**
- * Used to identify which env / jcapi to use when called back.
- */
+ unsigned int regs;
PTHREAD_T thread;
struct ActiveThreadList * next;
} ActiveThreadList;
@@ -76,6 +76,33 @@
Mutex threadsLock;
/**
+ * checks if the specified module is already loaded
+ * @param the prefix
+ * @param the name of the library
+ * @return YES or NO
+ */
+int hasModule(char * prefix, char * name) {
+ ModuleList * pos;
+ void * temp;
+ MUTEX_LOCK(&modulesLock);
+ pos = modules;
+ while(pos != NULL) {
+ if(pos->prefix == NULL || pos->name == NULL)
+ continue;
+ if(strcmp(prefix, pos->prefix) != 0)
+ continue;
+ if(strcmp(name, pos->name) == 0)
+ break;
+ pos = pos->next;
+ }
+ MUTEX_UNLOCK(&modulesLock);
+ if(pos != NULL)
+ return YES;
+ else
+ return NO;
+}
+
+/**
* get a ModuleList structure. will attempt to load the library if needed
* @param the prefix
* @param the name of the library
@@ -155,6 +182,23 @@
}
/**
+ * find our thread in ActiveThreadList. Does not check for null or unlock the
mutex.
+ * Consider using findThread instead.
+ * @return our thread entry or null.
+ */
+ActiveThreadList * _findThread() {
+ ActiveThreadList * pos;
+ MUTEX_LOCK(&threadsLock);
+ pos = threads;
+ while(pos != NULL) {
+ if(PTHREAD_SELF_TEST(&pos->thread))
+ break;
+ pos = pos->next;
+ }
+ return pos;
+}
+
+/**
* add an entry for this thread in ActiveThreadList
* @param our JNIEnv
* @param our jcapi
@@ -162,13 +206,19 @@
*/
ActiveThreadList * registerThread(JNIEnv *env, jobject jcapi) {
ActiveThreadList * thread;
- thread = MALLOC(sizeof(ActiveThreadList));
- PTHREAD_GET_SELF(&thread->thread);
- thread->env = env;
- thread->jcapi = jcapi;
- //no need to lock here!
- thread->next = threads;
- threads = thread;
+ thread = _findThread();
+ if(thread == NULL) {
+ thread = MALLOC(sizeof(ActiveThreadList));
+ PTHREAD_GET_SELF(&thread->thread);
+ thread->env = env;
+ thread->jcapi = jcapi;
+ thread->regs = 1;
+ thread->next = threads;
+ threads = thread;
+ } else {
+ thread->regs++;
+ }
+ MUTEX_UNLOCK(&threadsLock);
return thread;
}
@@ -178,22 +228,16 @@
* @return our thread entry
*/
ActiveThreadList * findThread() {
- ActiveThreadList * pos;
- MUTEX_LOCK(&threadsLock);
- pos = threads;
- while(pos != NULL) {
- if(PTHREAD_SELF_TEST(&pos->thread))
- break;
- pos = pos->next;
- }
+ ActiveThreadList * t = _findThread();
MUTEX_UNLOCK(&threadsLock);
- if (pos == NULL)
+ if (t == NULL)
errexit(_("Thread creation in C modules not supported by
Freeway.\n"));
- return pos;
+ return t;
}
/**
- * find our thread in ActiveThreadList and return env. expensive
+ * find our thread in ActiveThreadList and return env
+ * don't use this if you also need the api
* WARNING: aborts program if not found!
* @return env
*/
@@ -210,12 +254,17 @@
MUTEX_LOCK(&threadsLock);
pos = threads;
if(PTHREAD_SELF_TEST(&pos->thread)) {
- threads = pos->next;
+ pos->regs--;
+ if(pos->regs < 1) {
+ threads = pos->next;
+ MUTEX_UNLOCK(&threadsLock);
+ PTHREAD_REL_SELF(&pos->thread);
+ pos->env = NULL;
+ pos->jcapi = 0;
+ FREE(pos);
+ return;
+ }
MUTEX_UNLOCK(&threadsLock);
- PTHREAD_REL_SELF(&pos->thread);
- pos->env = NULL;
- pos->jcapi = 0;
- FREE(pos);
return;
}
while(pos->next != NULL) {
@@ -224,14 +273,17 @@
pos = pos->next;
}
if(pos->next != NULL) {
- this = pos->next;
- pos->next = pos->next->next;
- MUTEX_UNLOCK(&threadsLock);
- PTHREAD_REL_SELF(&pos->thread);
- pos->env = NULL;
- pos->jcapi = 0;
- FREE(this);
- return;
+ pos->regs--;
+ if(pos->regs < 1) {
+ this = pos->next;
+ pos->next = pos->next->next;
+ MUTEX_UNLOCK(&threadsLock);
+ PTHREAD_REL_SELF(&pos->thread);
+ pos->env = NULL;
+ pos->jcapi = 0;
+ FREE(this);
+ return;
+ }
}
MUTEX_UNLOCK(&threadsLock);
}
@@ -401,7 +453,7 @@
method = (*env)->GetMethodID(env, classCString, "<init>",
"(Ljava/lang/String;)V");
if(method == NULL)
return NULL;
-fprintf(stderr, "leaving convJStringToCString\n");
+fprintf(stderr, "leaving convJStringToCString\n", env, classCString, method,
input);
return (*env)->NewObject(env, classCString, method, input);
}
@@ -963,6 +1015,22 @@
return (jlong) returnValue;
}
+JNIEXPORT jboolean JNICALL Java_org_gnu_freeway_server_CPluginLoader_cHasModule
+ (JNIEnv *env, jobject cls, jstring libPrefix, jstring dsoName) {
+ registerThread(env, 0);
+ GNUNET_ASSERT(libPrefix != NULL);
+ GNUNET_ASSERT(dsoName != NULL);
+ const char * strLibPrefix = (*env)->GetStringUTFChars(env, libPrefix, NULL);
+ GNUNET_ASSERT(strLibPrefix != NULL);
+ const char * strDsoName = (*env)->GetStringUTFChars(env, dsoName, NULL);
+ GNUNET_ASSERT(strDsoName != NULL);
+ int returnValue = hasModule(strLibPrefix, strDsoName);
+ (*env)->ReleaseStringUTFChars(env, libPrefix, strLibPrefix);
+ (*env)->ReleaseStringUTFChars(env, dsoName, strDsoName);
+ unregisterThread();
+ return (jboolean) (returnValue == YES);
+}
+
JNIEXPORT void JNICALL
Java_org_gnu_freeway_server_CPluginLoader_cUnloadDynamicLibrary
(JNIEnv *env, jobject cls, jlong libHandle) {
registerThread(env, 0);
Modified: freeway/native/org_gnu_freeway_server_CPluginLoader.h
===================================================================
--- freeway/native/org_gnu_freeway_server_CPluginLoader.h 2006-07-16
08:50:44 UTC (rev 3121)
+++ freeway/native/org_gnu_freeway_server_CPluginLoader.h 2006-07-16
17:04:30 UTC (rev 3122)
@@ -57,6 +57,14 @@
/*
* Class: org_gnu_freeway_server_CPluginLoader
+ * Method: cHasModule
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_gnu_freeway_server_CPluginLoader_cHasModule
+ (JNIEnv *, jclass, jstring, jstring);
+
+/*
+ * Class: org_gnu_freeway_server_CPluginLoader
* Method: cLoadDynamicLibrary
* Signature: (Ljava/lang/String;Ljava/lang/String;)J
*/
Modified: freeway/native/switch-table.c
===================================================================
--- freeway/native/switch-table.c 2006-07-16 08:50:44 UTC (rev 3121)
+++ freeway/native/switch-table.c 2006-07-16 17:04:30 UTC (rev 3122)
@@ -11,6 +11,7 @@
switch (functionType) {
case 13: {
PointerObject * carg0 = convObjectToPtr(jargs[0], env);
+fprintf(stderr, "13: %x %d %x\n", m->modulePtr, functionOffset, carg0);
int cret = ((FunctionType13)
((void**)m->moduleFptrStruct)[functionOffset])(carg0->pointer);
updateObjectFromPtr(jargs[0], carg0, env);
oret = convIntToCInt(cret, env);
@@ -19,12 +20,14 @@
case 60: {
int carg0 = convCIntToInt(jargs[0], env);
long long carg1 = convCLongToLong(jargs[1], env);
+fprintf(stderr, "60: %x %d %d %l\n", m->modulePtr, functionOffset, carg0,
carg1);
((FunctionType60) ((void**)m->moduleFptrStruct)[functionOffset])(carg0,
carg1);
break;
}
case 42: {
int carg0 = convCIntToInt(jargs[0], env);
int carg1 = convCIntToInt(jargs[1], env);
+fprintf(stderr, "42: %x %d %d %d\n", m->modulePtr, functionOffset, carg0,
carg1);
((FunctionType42) ((void**)m->moduleFptrStruct)[functionOffset])(carg0,
carg1);
break;
}
Modified: freeway/protocols.xml
===================================================================
--- freeway/protocols.xml 2006-07-16 08:50:44 UTC (rev 3121)
+++ freeway/protocols.xml 2006-07-16 17:04:30 UTC (rev 3122)
@@ -1,6 +1,5 @@
<jar destfile="${project.build}/protocol-afs.jar">
<fileset dir="${project.build}/classes"
includes="org/gnu/freeway/protocol/afs/**"
excludes="org/gnu/freeway/protocol/afs/MySQLHandle*" />
-<!-- <fileset dir="${project.build}/classes"
includes="org/gnu/freeway/protocol/AbstractProtocol*" />-->
<fileset dir="${project.res}/swing" />
<manifest>
<attribute name="Main-Class"
value="org.gnu.freeway.protocol.afs.AFSProtocol" />
@@ -16,7 +15,6 @@
<jar destfile="${project.build}/protocol-chat.jar">
<fileset dir="${project.build}/classes"
includes="org/gnu/freeway/protocol/chat/**" />
-<!-- <fileset dir="${project.build}/classes"
includes="org/gnu/freeway/protocol/AbstractProtocol*" />-->
<manifest>
<attribute name="Main-Class"
value="org.gnu.freeway.protocol.chat.ChatProtocol" />
</manifest>
@@ -24,7 +22,6 @@
<jar destfile="${project.build}/protocol-dht.jar">
<fileset dir="${project.build}/classes"
includes="org/gnu/freeway/protocol/dht/**" />
-<!-- <fileset dir="${project.build}/classes"
includes="org/gnu/freeway/protocol/AbstractProtocol*" />-->
<manifest>
<attribute name="Main-Class"
value="org.gnu.freeway.protocol.dht.DHTProtocol" />
</manifest>
@@ -32,7 +29,6 @@
<jar destfile="${project.build}/protocol-tbench.jar">
<fileset dir="${project.build}/classes"
includes="org/gnu/freeway/protocol/tbench/**" />
-<!-- <fileset dir="${project.build}/classes"
includes="org/gnu/freeway/protocol/AbstractProtocol*" />-->
<manifest>
<attribute name="Main-Class"
value="org.gnu.freeway.protocol.tbench.TBenchProtocol" />
</manifest>
@@ -40,7 +36,6 @@
<jar destfile="${project.build}/protocol-tracekit.jar">
<fileset dir="${project.build}/classes"
includes="org/gnu/freeway/protocol/tracekit/**" />
-<!-- <fileset dir="${project.build}/classes"
includes="org/gnu/freeway/protocol/AbstractProtocol*" />-->
<manifest>
<attribute name="Main-Class"
value="org.gnu.freeway.protocol.tracekit.TraceKitProtocol" />
</manifest>
@@ -48,9 +43,9 @@
<jar destfile="${project.build}/protocol-stats.jar">
<fileset dir="${project.build}/classes"
includes="org/gnu/freeway/protocol/stats/**" />
-<!-- <fileset dir="${project.build}/classes"
includes="org/gnu/freeway/protocol/AbstractProtocol*" />
- <fileset dir="${project.build}/classes"
includes="org/gnu/freeway/protocol/NativeProtocol*" />-->
<manifest>
- <attribute name="Main-Class"
value="org.gnu.freeway.protocol.stats.StatsProtocol" />
+ <attribute name="Freeway-Name" value="Stats" />
+ <attribute name="Freeway-Java-Class"
value="org.gnu.freeway.protocol.stats.StatsProtocol" />
+ <attribute name="Freeway-C-Class"
value="org.gnu.freeway.protocol.stats.NativeStatsProtocol" />
</manifest>
</jar>
Deleted: freeway/readme.html
===================================================================
--- freeway/readme.html 2006-07-16 08:50:44 UTC (rev 3121)
+++ freeway/readme.html 2006-07-16 17:04:30 UTC (rev 3122)
@@ -1,19 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
-<html>
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-<title>readme.html</title>
-<link href="docs/project.css" rel="stylesheet" type="text/css">
-</head>
-<body>
-
-<div>
-This is the readme.html for freeway project.
-</div>
-
-<div>
-See in <a href='docs/index.html'>docs</a> folder for more information.
Available screenshots are in <a
href='docs/screenshots/index.html'>docs/screenshots</a>.
-</div>
-
-</body>
-</html>
Modified: freeway/src/org/gnu/freeway/AbstractApplication.java
===================================================================
--- freeway/src/org/gnu/freeway/AbstractApplication.java 2006-07-16
08:50:44 UTC (rev 3121)
+++ freeway/src/org/gnu/freeway/AbstractApplication.java 2006-07-16
17:04:30 UTC (rev 3122)
@@ -41,8 +41,9 @@
daemon=dm;//todo: encore utile comme distinction ???
services=ServiceManager.getInstance(this);
preferences=new Prefs();
+ preferences.readConfiguration(daemon);
+ statistics=new Statistics();
before=new ArrayList();
- statistics=new Statistics();
addCritical(new AbstractAction("FLUSH-PREFS") {
public void perform()
@@ -73,8 +74,13 @@
public Service service( Class c )
{
- return services.service(c);
+ return service(c, null);
}
+
+ public Service service( Class c, String forcedTypes )
+ {
+ return services.service(c, forcedTypes);
+ }
@@ -125,8 +131,6 @@
int ret;
/* init 1: get options and basic services up */
- preferences.readConfiguration(daemon);
-
resetAction=new AbstractAction() {
public void perform()
{
Modified: freeway/src/org/gnu/freeway/GNUNetDaemon.java
===================================================================
--- freeway/src/org/gnu/freeway/GNUNetDaemon.java 2006-07-16 08:50:44 UTC
(rev 3121)
+++ freeway/src/org/gnu/freeway/GNUNetDaemon.java 2006-07-16 17:04:30 UTC
(rev 3122)
@@ -141,7 +141,7 @@
//service(HelloExchangeService.class);
//service(PingPongService.class);
//service(ConnectionService.class);
- service(StatsService.class);
+ //service(StatsService.class);
((CoreService) service(CoreService.class)).loadProtocols();
if (firstStart || download) {
Modified: freeway/src/org/gnu/freeway/GNUNetStats.java
===================================================================
--- freeway/src/org/gnu/freeway/GNUNetStats.java 2006-07-16 08:50:44 UTC
(rev 3121)
+++ freeway/src/org/gnu/freeway/GNUNetStats.java 2006-07-16 17:04:30 UTC
(rev 3122)
@@ -99,7 +99,7 @@
protected boolean requestAndPrintStatistics( PrintWriter out, CSSession
sock )
{
- Stat[] stats;
+ /*Stat[] stats;
CSStatistics statMsg;
long t;
int totalCounters,count,i;
@@ -140,7 +140,7 @@
}
count+=stats.length;
}
- out.println();
+ out.println();*/
return true;
}
@@ -154,7 +154,7 @@
protected boolean requestAndPrintProtocols( PrintWriter out, CSSession
sock )
{
- CSResult rv;
+/* CSResult rv;
String name;
int i;
@@ -204,13 +204,13 @@
out.println();
}
}
- out.println();
+ out.println();*/
return true;
}
protected boolean printClients( PrintWriter out, CSSession sock )
{
- CSResult rv;
+/* CSResult rv;
out.println("Connected clients :");
@@ -226,7 +226,7 @@
}
out.println(" Count : "+rv.getResult());
- out.println();
+ out.println();*/
return true;
}
@@ -241,6 +241,6 @@
public static void main( String[] args )
{
- launch(GNUNetStats.class,args);
+// launch(GNUNetStats.class,args);
}
}
Modified: freeway/src/org/gnu/freeway/GNUNetTransportCheck.java
===================================================================
--- freeway/src/org/gnu/freeway/GNUNetTransportCheck.java 2006-07-16
08:50:44 UTC (rev 3121)
+++ freeway/src/org/gnu/freeway/GNUNetTransportCheck.java 2006-07-16
17:04:30 UTC (rev 3122)
@@ -81,8 +81,13 @@
public org.gnu.freeway.util.Service service( Class c )
{
- return GNUNetTransportCheck.this.service(c);
+ return service(c, null);
}
+
+ public org.gnu.freeway.util.Service service( Class c,
String forcedType )
+ {
+ return GNUNetTransportCheck.this.service(c,
forcedType);
+ }
public void receive( MessagePack mp )
{
Modified: freeway/src/org/gnu/freeway/protocol/afs/swing/StatsWindow.java
===================================================================
--- freeway/src/org/gnu/freeway/protocol/afs/swing/StatsWindow.java
2006-07-16 08:50:44 UTC (rev 3121)
+++ freeway/src/org/gnu/freeway/protocol/afs/swing/StatsWindow.java
2006-07-16 17:04:30 UTC (rev 3122)
@@ -101,7 +101,7 @@
int[] sel;
CSSession sock;
DefaultListModel sModel;
- CSStatistics statMsg;
+ //CSStatistics statMsg;
long t;
int totalCounters,count,i;
@@ -110,7 +110,7 @@
sModel=(DefaultListModel) statTable.getUnsortedModel();
sModel.clear();
- sock=controller.connect();
+ /*sock=controller.connect();
try {
if (!sock.send(new CSStatisticsRequest())) {
controller.log(Level.WARNING,"Error sending
request for statistics to gnunetd.");
@@ -121,11 +121,11 @@
totalCounters=1;
while (count<totalCounters) {
- statMsg=(CSStatistics)
sock.receive(CSStatistics.class);
- if (statMsg==null) {
- controller.log(Level.WARNING,"Error
receiving reply for statistics from gnunetd.");
- return false;
- }
+ //statMsg=(CSStatistics)
sock.receive(CSStatistics.class);
+ //if (statMsg==null) {
+ // controller.log(Level.WARNING,"Error
receiving reply for statistics from gnunetd.");
+ // return false;
+ // }
if (count==0) {
t=Scheduler.toSeconds(Scheduler.now());
@@ -149,7 +149,7 @@
}
finally {
sock.disconnect();
- }
+ }*/
statTable.setSelectedRows(sel);
return true;
}
Added: freeway/src/org/gnu/freeway/protocol/stats/NativeStatsProtocol.java
===================================================================
--- freeway/src/org/gnu/freeway/protocol/stats/NativeStatsProtocol.java
2006-07-16 08:50:44 UTC (rev 3121)
+++ freeway/src/org/gnu/freeway/protocol/stats/NativeStatsProtocol.java
2006-07-16 17:04:30 UTC (rev 3122)
@@ -0,0 +1,89 @@
+ /*
+ This file is part of Freeway
+
+ Freeway is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ Freeway is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Freeway; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+package org.gnu.freeway.protocol.stats;
+
+import java.util.logging.Level;
+
+import org.gnu.freeway.Server;
+import org.gnu.freeway.protocol.Protocol;
+import org.gnu.freeway.server.CPluginLoader;
+import org.gnu.freeway.server.ClientExitHandler;
+import org.gnu.freeway.server.CoreForProtocol;
+import org.gnu.freeway.util.Prefs;
+import org.gnu.freeway.util.net.CSHandler;
+import org.gnu.freeway.util.net.CSMessage;
+import org.gnu.freeway.util.net.CSSession;
+import org.gnu.freeway.util.net.P2PMessage;
+import org.gnu.freeway.util.net.PersistentDecoder;
+import org.gnu.freeway.protocol.AbstractProtocol;
+import org.gnu.freeway.protocol.chat.CSChatMessage;
+import org.gnu.freeway.server.CoreAPI;
+
+/**
+ * @file NativeStatsProtocol.java
+ * @brief
+ * @author mdonoughe
+ */
+public class NativeStatsProtocol extends AbstractProtocol implements Protocol {
+
+ private CPluginLoader loader;
+
+ public NativeStatsProtocol() {
+ super();
+
+ loader = new CPluginLoader();
+ }
+
+ /* (non-Javadoc)
+ * @see
org.gnu.freeway.protocol.Protocol#init(org.gnu.freeway.server.CoreForProtocol)
+ */
+ public boolean init(CoreForProtocol api) {
+ boolean ok = super.init(api);
+ CoreAPI._.setProtocolCore(api);
+ ok &= CoreAPI.OK.getValue() ==
loader.loadProtocol(CPluginLoader.classToLibraryName(getName()));
+ return ok;
+ }
+
+ /* (non-Javadoc)
+ * @see org.gnu.freeway.protocol.Protocol#done()
+ */
+ public void done() {
+ // TODO Auto-generated method stub
+ super.done();
+ }
+
+ public String toString() {
+ String ret = this.getClass().getSimpleName();
+ if(ret.startsWith("Native"))
+ ret = ret.substring(6);
+ if(ret.endsWith("Protocol"))
+ ret = ret.substring(0, ret.length() - 8);
+ return ret.toLowerCase();
+ }
+
+ /* (non-Javadoc)
+ * @see org.gnu.freeway.protocol.Protocol#createCSDecoder()
+ */
+ public PersistentDecoder createCSDecoder() {
+ // TODO Auto-generated method stub
+ return super.createCSDecoder();
+ }
+
+}
Modified: freeway/src/org/gnu/freeway/protocol/stats/StatsProtocol.java
===================================================================
--- freeway/src/org/gnu/freeway/protocol/stats/StatsProtocol.java
2006-07-16 08:50:44 UTC (rev 3121)
+++ freeway/src/org/gnu/freeway/protocol/stats/StatsProtocol.java
2006-07-16 17:04:30 UTC (rev 3122)
@@ -19,34 +19,53 @@
package org.gnu.freeway.protocol.stats;
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
import java.util.logging.Level;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ArrayList;
import org.gnu.freeway.Server;
import org.gnu.freeway.protocol.Protocol;
import org.gnu.freeway.server.CPluginLoader;
import org.gnu.freeway.server.ClientExitHandler;
import org.gnu.freeway.server.CoreForProtocol;
+import org.gnu.freeway.util.Prefs;
import org.gnu.freeway.util.net.CSHandler;
import org.gnu.freeway.util.net.CSMessage;
import org.gnu.freeway.util.net.CSSession;
+import org.gnu.freeway.util.net.ErrorReporter;
+import org.gnu.freeway.util.net.NativeCSHandler;
import org.gnu.freeway.util.net.P2PMessage;
+import org.gnu.freeway.util.net.Persistent;
import org.gnu.freeway.util.net.PersistentDecoder;
+import org.gnu.freeway.util.net.PersistentHelper;
import org.gnu.freeway.protocol.AbstractProtocol;
import org.gnu.freeway.protocol.chat.CSChatMessage;
+import org.gnu.freeway.protocol.tbench.CSBenchRequest;
import org.gnu.freeway.server.CoreAPI;
+import org.gnu.freeway.services.java.StatsService;
+import org.gnu.freeway.cwrappers.*;
+import org.gnu.freeway.util.Scheduler;
/**
* @file StatsProtocol.java
* @brief
* @author mdonoughe
*/
-public class StatsProtocol extends AbstractProtocol implements Protocol {
-
- private CPluginLoader loader;
+public class StatsProtocol extends AbstractProtocol implements Protocol,
CSHandler {
+ private StatsService service = null;
+
+ private int stat_handle_network_load_up = 0;
+ private int stat_handle_network_load_down = 0;
+ private int stat_handle_cpu_load = 0;
+ private int stat_bytes_noise_received = 0;
+ private int stat_connected = 0;
+
public StatsProtocol() {
super();
- loader = new CPluginLoader();
}
/* (non-Javadoc)
@@ -54,8 +73,13 @@
*/
public boolean init(CoreForProtocol api) {
boolean ok = super.init(api);
- CoreAPI._.setProtocolCore(api);
- ok &= CoreAPI.OK.getValue() ==
loader.loadProtocol(CPluginLoader.classToLibraryName(getName()));
+ service = (StatsService)
api.service(org.gnu.freeway.services.StatsService.class, "java");
+ ok &= service != null;
+ ok &= ((Server)
api.getApplication()).registerCSHandler(CSMessage.CS_PROTO_stats_GET_STATISTICS,
CSMessage.class, this);
+ ok &= ((Server)
api.getApplication()).registerCSHandler(CSMessage.CS_PROTO_stats_STATISTICS,
CSMessage.class, this);
+ ok &= ((Server)
api.getApplication()).registerCSHandler(CSMessage.CS_PROTO_stats_GET_CS_MESSAGE_SUPPORTED,
CSMessage.class, this);
+ ok &= ((Server)
api.getApplication()).registerCSHandler(CSMessage.CS_PROTO_stats_GET_P2P_MESSAGE_SUPPORTED,
CSMessage.class, this);
+ //TODO: add noise
return ok;
}
@@ -69,6 +93,8 @@
public String toString() {
String ret = this.getClass().getSimpleName();
+ if(ret.startsWith("Native"))
+ ret = ret.substring(6);
if(ret.endsWith("Protocol"))
ret = ret.substring(0, ret.length() - 8);
return ret.toLowerCase();
@@ -82,4 +108,225 @@
return super.createCSDecoder();
}
+ public boolean handle(CSSession session, CSMessage message) {
+
+ System.err.println("+++" + message.getType());
+ if(message.getType() ==
CSMessage.CS_PROTO_stats_GET_STATISTICS) {
+ return handleGetStatistics(session, message);
+ } else if(message.getType() ==
CSMessage.CS_PROTO_stats_STATISTICS) {
+ return handleStatistics(session, message);
+ } else if(message.getType() ==
CSMessage.CS_PROTO_stats_GET_CS_MESSAGE_SUPPORTED) {
+ // TODO iirc, all messages are "supported" for now
+ return handleGetCSMessageSupported(session, message);
+ } else if(message.getType() ==
CSMessage.CS_PROTO_stats_GET_P2P_MESSAGE_SUPPORTED) {
+ return handleGetP2PMessageSupported(session, message);
+ }
+ return false;
+ }
+
+ private boolean handleGetP2PMessageSupported(CSSession session,
CSMessage message) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ private boolean handleGetCSMessageSupported(CSSession session,
CSMessage message) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ private boolean handleStatistics(CSSession session, CSMessage message) {
+ // TODO Auto-generated method stub
+ System.err.println("I have recieved some statistics");
+ return false;
+ }
+
+ private boolean handleGetStatistics(CSSession session, CSMessage
message) {
+ //assume that the server is telling the truth and just send a
reply
+ System.err.println("!! Will send statistics to " +
session.getLabel());
+ sendStatistics(session);
+ return true;
+ }
+
+ private void sendStatistics(CSSession session) {
+ List list;
+ CSStatsMessage msg;
+ int total,i;
+ List stats = service.stats;
+
+ list=new ArrayList();
+
+ total = stats.size();
+
+ i=0;
+ while (i < stats.size()) {
+ msg=new
CSStatsMessage(Scheduler.toSeconds(service.startTime));
+ msg.setTotalCounters(total);
+
+ // how many statistic numbers and their descriptions we
can send in one message ?
+ while (i<stats.size() &&
msg.getByteSize()<CSMessage.MAX_MESSAGE_SIZE) {
+ msg.add((StatsService.Entry)
stats.get(i++));
+ }
+
+ if (msg.getByteSize()>=CSMessage.MAX_MESSAGE_SIZE) {
+ msg.removeLast();
+ i--;
+ }
+
+ list.add(msg);
+ }
+ for(Iterator j = list.iterator(); j.hasNext();) {
+ msg = (CSStatsMessage) j.next();
+ session.send(msg);
+ System.err.println(msg.toString() + msg.getByteSize());
+ }
+ }
+
+ public static final class CSStatsMessage extends CSMessage implements
Persistent {
+ private StatsService src;
+ private int size;
+ private long startTime;
+ private int totalCounters;
+ private List stats;
+ private static final int SIZE = 24;
+
+ public CSStatsMessage() {
+ super(CS_PROTO_stats_STATISTICS);
+ size = SIZE;
+ startTime=Scheduler.toSeconds(Scheduler.now());
+ totalCounters = 0;
+ stats = new ArrayList();
+ }
+
+ public CSStatsMessage(long time) {
+ this();
+ this.startTime = time;
+ }
+
+ public String toString() {
+ return "Statistics message [counters=" + stats.size() +
", totalCounters=" + totalCounters + "]";
+ }
+
+ public long getStartTime()
+ {
+ return startTime;
+ }
+
+ public int getTotalCounters()
+ {
+ return totalCounters;
+ }
+
+ public void setTotalCounters( int total )
+ {
+ totalCounters=total;
+ }
+
+ public void add(StatsService.Entry stat) {
+ stats.add(stat);
+ size += stat.getByteSize();
+ }
+
+ public StatsService.Entry removeLast()
+ {
+ StatsService.Entry stat;
+
+ assert(stats.size()>0);
+
+ stat=(StatsService.Entry) stats.remove(stats.size()-1);
+ size-=stat.getByteSize();
+ return stat;
+ }
+
+ public StatsService.Entry[] getStatistics()
+ {
+ return (StatsService.Entry[]) stats.toArray(new
StatsService.Entry[stats.size()]);
+ }
+
+ public int getByteSize()
+ {
+ return size;
+ }
+
+ public void readBytes( ByteBuffer buf, ErrorReporter err )
+ {
+ StatsService.Entry stat;
+ int type,i,n,reserved,statCounters;
+
+ size=buf.getShort() & 0x0000ffff;
+ err.reportIf(size<16,"packet too small");
+
+ type=buf.getShort() & 0x0000ffff;
+ err.reportIf(type != CS_PROTO_stats_STATISTICS, "wrong
packet type");
+
+ reserved=buf.getInt();
+ err.reportIf(reserved!=0,"'reserved' integer not null
!");
+
+ startTime=buf.getLong();
+ err.reportIf(startTime<=0,"Invalid start time !");
+
+ totalCounters=buf.getInt();
+ err.reportIf(totalCounters<0,"Invalid total counter !");
+
+ statCounters=buf.getInt();
+ err.reportIf(statCounters<0,"Negative numbers of
counters");
+
+ n=SIZE;
+ stats.clear();
+
+ ArrayList values = new ArrayList();
+ for (i=0; i<statCounters; i++) {
+ long l = buf.getLong();
+ values.add(new CLong(l));
+ System.err.println("value: " + l);
+ n+=8;
+ }
+
+ for(i = 0; i<statCounters; i++) {
+ int pos=buf.position();
+ int len = 0;
+ for (len=0; buf.get()!=0; len++) {}
+ buf.position(pos);
+ byte[] b=new byte[len];
+ buf.get(b);
+ buf.get(); //null
+ try {
+ stats.add(new StatsService.Entry(new
String(b, "UTF-8"), (ConstCLong) values.get(i)));
+ System.err.println("key: " + new
String(b, "UTF-8"));
+ } catch (UnsupportedEncodingException e) {
+ throw new Error(e);
+ }
+ n+=len+1;
+ }
+
+ err.reportIf(size!=n,"Bad size: "+size+"!="+n);
+ }
+
+ public void writeBytes( ByteBuffer buf )
+ {
+ int i;
+
+ buf.putShort((short) size);
+ buf.putShort((short) CS_PROTO_stats_STATISTICS);
+ buf.putInt(0);
+ buf.putLong(startTime);
+ buf.putInt(totalCounters);
+ buf.putInt(stats.size());
+
+ for(i = 0; i < stats.size(); i++) {
+ buf.putLong(((StatsService.Entry)
stats.get(i)).value.getValue());
+ System.err.println("value: " +
((StatsService.Entry)stats.get(i)).value.getValue());
+ }
+
+ for(i = 0; i < stats.size(); i++) {
+ try {
+ buf.put(((StatsService.Entry)
stats.get(i)).key.getBytes("UTF-8"));
+ } catch(Exception e) {
+ throw new Error(e);
+ }
+ buf.put((byte) 0);
+ System.err.println("key: " +
((StatsService.Entry) stats.get(i)).key);
+ }
+ System.err.println("wrote to buffer");
+ }
+ }
}
Modified: freeway/src/org/gnu/freeway/server/CPluginLoader.java
===================================================================
--- freeway/src/org/gnu/freeway/server/CPluginLoader.java 2006-07-16
08:50:44 UTC (rev 3121)
+++ freeway/src/org/gnu/freeway/server/CPluginLoader.java 2006-07-16
17:04:30 UTC (rev 3122)
@@ -34,9 +34,18 @@
* @author mdonoughe
*/
public class CPluginLoader extends LoggedObject {
+ public static boolean loaded = false;
static {
- System.loadLibrary("org_gnu_freeway_server_CPluginLoader");
+ try {
+
System.loadLibrary("org_gnu_freeway_server_CPluginLoader");
+ loaded = true;
+ } catch(SecurityException e) {
+ System.err.println("Security manager forbids loading
native code.");
+ } catch(UnsatisfiedLinkError e) {
+ e.printStackTrace();
+
System.err.println("org_gnu_freeway_server_CPluginLoader could not be loaded.");
+ }
}
private static native long cLoadService(String serviceName, CoreAPI
capi);
@@ -52,6 +61,8 @@
private static native long cBindDynamicMethod(long libhandle, String
methodprefix, String dsoname);
+ private static native boolean cHasModule(String dsoprefix, String name);
+
private static native long cLoadDynamicLibrary(String dsoprefix, String
name);
private static native void cUnloadDynamicLibrary(long libhandle);
@@ -69,11 +80,15 @@
*/
public Handle loadService(String serviceName) {
assert (serviceName != null);
+ if(!loaded)
+ return Handle.NULL;
return new Handle(cLoadService(serviceName, CoreAPI._));
}
public int loadProtocol(String protocolName) {
assert (protocolName != null);
+ if(!loaded)
+ return CoreAPI.SYSERR.getValue();
return cLoadProtocol(protocolName, CoreAPI._);
}
@@ -84,6 +99,8 @@
public static int initUtil(String[] args) {
assert(args != null);
+ if(!loaded)
+ return CoreAPI.SYSERR.getValue();
return cInitUtil(args);
}
@@ -101,6 +118,8 @@
int offset,
int functionType,
Object[] arguments) {
+ if(!loaded)
+ throw new Error("Native code loading was not
initialized!");
return cCallC(modulePtr._, CoreAPI._, offset, functionType,
arguments);
}
@@ -112,6 +131,8 @@
*/
public void unloadService(Handle modulePtr) {
assert modulePtr != null;
+ if(!loaded)
+ return;
cUnloadService(modulePtr._);
}
@@ -119,33 +140,61 @@
assert libhandle != null;
assert methodprefix != null;
assert dsoname != null;
+ if(!loaded)
+ return Handle.NULL;
return new Handle(cBindDynamicMethod(libhandle._, methodprefix,
dsoname));
}
public static Handle loadDynamicLibrary(String dsoprefix, String name) {
assert dsoprefix != null;
assert name != null;
+ if(!loaded)
+ return Handle.NULL;
return new Handle(cLoadDynamicLibrary(dsoprefix, name));
}
+ public static boolean hasModule(String dsoprefix, String name) {
+ assert dsoprefix != null;
+ assert name != null;
+ if(!loaded)
+ return false;
+ return cHasModule(dsoprefix, name);
+ }
+
public static void unloadDynamicLibrary(Handle libhandle) {
assert libhandle != null;
+ if(!loaded)
+ return;
cUnloadDynamicLibrary(libhandle._);
}
/**
* Converts a class name to a module name. StatsService -> module_stats
* @param className
- * @return
+ * @return a library name
*/
public static String classToLibraryName(String className) {
if(className.endsWith("Service"))
className = className.substring(0, className.length() -
"Service".length());
+ if(className.endsWith("Protocol"))
+ className = className.substring(0, className.length() -
"Protocol".length());
+ if(className.startsWith("Native"))
+ className = className.substring("Native".length());
return "module_" + className.toLowerCase();
}
+
+ /**
+ * Gets a C facade for a Java service.
+ * @param the Java class
+ * @return a Handle to the facade
+ */
+ public static Handle getFacade(Object c) {
+ //TODO: not implemented
+ return Handle.NULL;
+ }
-
public static final class Handle {
+ public static final Handle NULL = new Handle(0);
final long _;
Handle(long value) {
Deleted: freeway/src/org/gnu/freeway/server/CSStatistics.java
===================================================================
--- freeway/src/org/gnu/freeway/server/CSStatistics.java 2006-07-16
08:50:44 UTC (rev 3121)
+++ freeway/src/org/gnu/freeway/server/CSStatistics.java 2006-07-16
17:04:30 UTC (rev 3122)
@@ -1,158 +0,0 @@
-/**
- * @PROJECT_INFO@
- */
-
-package org.gnu.freeway.server;
-
-import org.gnu.freeway.util.*;
-import org.gnu.freeway.util.net.*;
-
-import java.nio.*;
-import java.util.*;
-
-/**
- * Statistics message. Contains the timestamp and an aribtrary
- * (bounded by the maximum CS message size!) number of statistical
- * numbers. If needed, several messages are used.
- * Statistics message. Contains the timestamp and an aribtrary
- * (bounded by the maximum CS message size!) number of statistical
- * numbers. If needed, several messages are used.
- */
-
-public class CSStatistics extends CSMessage
-{
- public static final int SIZE = 20;
-
- /** */
- private int size;
-
- /** Start time of statistics service (in seconds). */
- private int startTime;
-
- /** total number of statistical counters */
- private int totalCounters;
-
- /** statistical counters */
- private List stats;
-
-
- public CSStatistics()
- {
- super(CS_PROTO_stats_STATISTICS);
- size=SIZE;
- startTime=(int) Scheduler.toSeconds(Scheduler.now());
- totalCounters=0;
- stats=new ArrayList();
- }
-
- public CSStatistics( int start )
- {
- this();
- startTime=start;
- }
-
- public String toString()
- {
- return "Statistics message [counters="+stats.size()+",
totalCounters="+totalCounters+"]";
- }
-
-
-
////////////////////////////////////////////////////////////////////////////////////////////////
-
- public int getStartTime()
- {
- return startTime;
- }
-
- public int getTotalCounters()
- {
- return totalCounters;
- }
-
- public void setTotalCounters( int total )
- {
- totalCounters=total;
- }
-
- public void add( Stat stat )
- {
- stats.add(stat);
- size+=stat.getByteSize();
- }
-
- public Stat removeLast()
- {
- Stat stat;
-
- assert(stats.size()>0);
-
- stat=(Stat) stats.remove(stats.size()-1);
- size-=stat.getByteSize();
- return stat;
- }
-
- public Stat[] getStatistics()
- {
- return (Stat[]) stats.toArray(new Stat[stats.size()]);
- }
-
-
-
////////////////////////////////////////////////////////////////////////////////////////////////
-
- public int getByteSize()
- {
- return size;
- }
-
- public void readBytes( ByteBuffer buf, ErrorReporter err )
- {
- Stat stat;
- int type,i,n,reserved,statCounters;
-
- size=buf.getShort() & 0x0000ffff;
- type=buf.getShort() & 0x0000ffff;
-
- reserved=buf.getInt();
- err.reportIf(reserved!=0,"'reserved' integer not null !");
-
- startTime=buf.getInt();
- totalCounters=buf.getInt();
-
- statCounters=buf.getInt();
- err.reportIf(statCounters<0,"Negative numbers of counters");
-
- n=SIZE;
- stats.clear();
- for (i=0; i<statCounters; i++) {
- stat=new Stat("");
- stat.readBytes(buf,err);
- stats.add(stat);
-
- n+=stat.getByteSize();
- }
-
- err.reportIf(type!=CSMessage.CS_PROTO_stats_STATISTICS,"bad
type !");
- err.reportIf(startTime<=0,"Invalid start time !");
- err.reportIf(totalCounters<0,"Invalid total counter !");
- err.reportIf(statCounters<0,"Invalid stat counter !");
- err.reportIf(size!=n,"Bad size: "+size+"!="+n);
- }
-
- public void writeBytes( ByteBuffer buf )
- {
- Stat stat;
- int i;
-
- buf.putShort((short) size);
- buf.putShort((short) CS_PROTO_stats_STATISTICS);
- buf.putInt(0);
- buf.putInt(startTime);
- buf.putInt(totalCounters);
- buf.putInt(stats.size());
-
- for (i=0; i<stats.size(); i++) {
- stat=(Stat) stats.get(i);
- stat.writeBytes(buf);
- }
- }
-}
Modified: freeway/src/org/gnu/freeway/server/Core.java
===================================================================
--- freeway/src/org/gnu/freeway/server/Core.java 2006-07-16 08:50:44 UTC
(rev 3121)
+++ freeway/src/org/gnu/freeway/server/Core.java 2006-07-16 17:04:30 UTC
(rev 3122)
@@ -49,5 +49,6 @@
*/
public Service service( Class c );
+ public Service service( Class c, String forcedTypes );
public Application getApplication();
}
Modified: freeway/src/org/gnu/freeway/server/CoreAPI.java
===================================================================
--- freeway/src/org/gnu/freeway/server/CoreAPI.java 2006-07-16 08:50:44 UTC
(rev 3121)
+++ freeway/src/org/gnu/freeway/server/CoreAPI.java 2006-07-16 17:04:30 UTC
(rev 3122)
@@ -93,7 +93,12 @@
System.err.println(c.getCanonicalName() + " is not a
NativeService");
return new CPluginLoader.Handle(0);
}
- NativeService s = (NativeService)
ServiceManager.manager.service(c);
+ NativeService s = null;
+ if(CPluginLoader.hasModule("libgnunet", "module_" +
iname.getValue())) {
+ s = (NativeService) ServiceManager.manager.service(c,
"c");
+ } else {
+ s = (NativeService) ServiceManager.manager.service(c);
+ }
return s.getHandle();
}
@@ -135,6 +140,7 @@
}
public CInt registerHandler(CInt type, CPluginLoader.Handle callback) {
+ //TODO: this should be P2P
return ((Server)
protocolCore.getApplication()).registerCSHandler(type.getValue(),
CSMessage.class, new NativeCSHandler(callback)) ? CoreAPI.OK : CoreAPI.SYSERR;
}
Modified: freeway/src/org/gnu/freeway/server/CoreService.java
===================================================================
--- freeway/src/org/gnu/freeway/server/CoreService.java 2006-07-16 08:50:44 UTC
(rev 3121)
+++ freeway/src/org/gnu/freeway/server/CoreService.java 2006-07-16 17:04:30 UTC
(rev 3122)
@@ -257,6 +257,11 @@
{
return getManager().service(c);
}
+
+ public org.gnu.freeway.util.Service service( Class c , String type )
+ {
+ return getManager().service(c, type);
+ }
public void preferTrafficFrom( HostIdentity node, double preference )
{
@@ -380,15 +385,11 @@
return false;
}
- p=(Protocol) new
DynamicLibrary("protocol-"+str+".jar").load(Protocol.class);
+ p=(Protocol) new
DynamicLibrary("protocol-"+str+".jar").load(Protocol.class, "init", new
Class[]{CoreForProtocol.class}, new Object[]{this});
if (p==null) {
log(Level.WARNING,"Could not load protocol
'"+str+"' !");
return false;
}
- if (!p.init(this)) {
- log(Level.WARNING,"Could not init protocol
'"+str+"' !");
- return false;
- }
entry=new ProtocolEntry();
entry.libraryName=str;
@@ -441,13 +442,13 @@
PersistentDecoder dec;
dec=new PersistentDecoder();
-
dec.add(CSMessage.CS_PROTO_stats_GET_CS_MESSAGE_SUPPORTED,CSGetCSMessageSupported.class);
+
//dec.add(CSMessage.CS_PROTO_stats_GET_CS_MESSAGE_SUPPORTED,CSGetCSMessageSupported.class);
//dec.add(CSMessage.IS_RESULT,CSResult.class);
- dec.add(CSMessage.CS_PROTO_stats_STATISTICS,CSStatistics.class);
+
//dec.add(CSMessage.CS_PROTO_stats_STATISTICS,CSStatistics.class);
/*dec.add(CSMessage.IS_TRAFFIC_INFO,CSTrafficInfo.class);
dec.add(CSMessage.IS_TRAFFIC_QUERY,CSTrafficRequest.class);*/
-
dec.add(CSMessage.CS_PROTO_stats_GET_CS_MESSAGE_SUPPORTED,CSStatisticsRequest.class);
-
dec.add(CSMessage.CS_PROTO_stats_GET_P2P_MESSAGE_SUPPORTED,CSGetP2PMessageSupported.class);
+
//dec.add(CSMessage.CS_PROTO_stats_GET_CS_MESSAGE_SUPPORTED,CSStatisticsRequest.class);
+
//dec.add(CSMessage.CS_PROTO_stats_GET_P2P_MESSAGE_SUPPORTED,CSGetP2PMessageSupported.class);
/*dec.add(CSMessage.IS_SHUTDOWN,CSShutdownRequest.class);
dec.add(CSMessage.IS_CLIENT_COUNT,CSGetClientCount.class);
dec.add(CSMessage.IS_GET_HOST_INFO,CSGetHostInfo.class);*/
Added: freeway/src/org/gnu/freeway/services/java/StatsService.java
===================================================================
--- freeway/src/org/gnu/freeway/services/java/StatsService.java 2006-07-16
08:50:44 UTC (rev 3121)
+++ freeway/src/org/gnu/freeway/services/java/StatsService.java 2006-07-16
17:04:30 UTC (rev 3122)
@@ -0,0 +1,92 @@
+package org.gnu.freeway.services.java;
+
+import java.util.ArrayList;
+import java.util.Map;
+
+import org.gnu.freeway.util.AbstractService;
+import org.gnu.freeway.util.NativeService;
+import org.gnu.freeway.util.Scheduler;
+import org.gnu.freeway.util.ServiceException;
+import org.gnu.freeway.cwrappers.CInt;
+import org.gnu.freeway.cwrappers.ConstCLong;
+import org.gnu.freeway.cwrappers.CLong;
+import org.gnu.freeway.cwrappers.ConstCInt;
+import org.gnu.freeway.cwrappers.CString;
+import org.gnu.freeway.cwrappers.ConstCString;
+import org.gnu.freeway.server.CPluginLoader;
+
+public class StatsService extends AbstractService implements NativeService,
org.gnu.freeway.services.StatsService {
+
+ // can only be used by classes that depend on java.StatsService
+ public ArrayList stats;
+ public int startTime;
+
+ public synchronized CInt create(ConstCString name) {
+ stats.add(new Entry(name.getValue(), new ConstCLong(0)));
+ return new CInt(stats.size() - 1);
+ }
+
+ public void set(ConstCInt key, ConstCLong value) {
+ ((Entry) stats.get(key.getValue())).value = value;
+ }
+
+ public CLong get(ConstCInt key) {
+ return new CLong(((Entry)
stats.get(key.getValue())).value.getValue());
+ }
+
+ public void change(ConstCInt key, ConstCInt delta) {
+ ((Entry) stats.get(key.getValue())).value = new
ConstCLong(((Entry) stats.get(key.getValue())).value.getValue() +
delta.getValue());
+ }
+
+ public void init() throws ServiceException {
+ super.init();
+ stats = new ArrayList();
+ startTime = (int) Scheduler.toSeconds(Scheduler.now());
+
+ try {
+ System.err.println("Loaded Java stats service.");
+ CInt c = create(new CString("test"));
+ System.err.println("created stat \"test\":" +
c.getValue());
+ set(c, new CLong(12345));
+ c = create(new CString("test2"));
+ System.err.println("created stat \"test2\":" +
c.getValue());
+ set(c, new CLong(54321));
+ c = create(new CString("-1"));
+ System.err.println("created stat \"-1\":" +
c.getValue());
+ set(c, new CLong(-1));
+ c = create(new CString("-2"));
+ System.err.println("created stat \"-2\":" +
c.getValue());
+ set(c, new CLong(-2));
+ } catch(Throwable t) {
+ t.printStackTrace();
+ }
+ }
+
+ public StatsService() {
+ super("stats");
+ }
+
+ public StatsService(CPluginLoader loader) {
+ this();
+ }
+
+ public CPluginLoader.Handle getHandle() {
+ return CPluginLoader.getFacade(this);
+ }
+
+ public static final class Entry {
+ public String key;
+ public ConstCLong value;
+ public Entry(String key, ConstCLong value) {
+ this.key = key;
+ this.value = value;
+ }
+ public int getByteSize() {
+ try {
+ return key.getBytes("UTF-8").length + 9;
+ } catch(Exception e) {
+ throw new Error(e);
+ }
+ }
+ }
+}
Added: freeway/src/org/gnu/freeway/util/AbstractNativeService.java
===================================================================
--- freeway/src/org/gnu/freeway/util/AbstractNativeService.java 2006-07-16
08:50:44 UTC (rev 3121)
+++ freeway/src/org/gnu/freeway/util/AbstractNativeService.java 2006-07-16
17:04:30 UTC (rev 3122)
@@ -0,0 +1,103 @@
+ /*
+ This file is part of Freeway
+
+ Freeway is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ Freeway is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Freeway; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+package org.gnu.freeway.util;
+
+import org.gnu.freeway.server.CPluginLoader;
+
+/**
+ * @file NativeService.java
+ * @brief an abstract class to make org.gnu.freeway.services types fit
+ * @author mdonoughe
+ */
+public abstract class AbstractNativeService extends AbstractService implements
NativeService {
+
+ protected CPluginLoader loader;
+ protected CPluginLoader.Handle handle;
+
+ protected AbstractNativeService(CPluginLoader loader) {
+ super();
+ setDebug(true);
+ this.loader = loader;
+ }
+
+ protected void finalize() throws Throwable {
+ super.finalize();
+ done();
+ }
+
+ /* (non-Javadoc)
+ * @see org.gnu.freeway.util.Service#getName()
+ */
+ public String toString() {
+ String ret = this.getClass().getSimpleName();
+ if(ret.endsWith("Service")) {
+ ret = ret.substring(0, ret.length() - 7);
+ }
+ return ret;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.gnu.freeway.util.Service#attach(org.gnu.freeway.util.ServiceManager)
+ */
+ public void attach(ServiceManager s) {
+ super.attach(s);
+ }
+
+ /* (non-Javadoc)
+ * @see org.gnu.freeway.util.Service#detach()
+ */
+ public void detach() {
+ super.detach();
+ }
+
+ /* (non-Javadoc)
+ * @see org.gnu.freeway.util.Service#init()
+ */
+ public void init() throws ServiceException {
+ super.init();
+ handle =
loader.loadService(CPluginLoader.classToLibraryName(getName()));
+ }
+
+ /* (non-Javadoc)
+ * @see org.gnu.freeway.util.Service#start()
+ */
+ public void start() throws ServiceException {
+ super.start();
+ }
+
+ /* (non-Javadoc)
+ * @see org.gnu.freeway.util.Service#stop()
+ */
+ public void stop() throws ServiceException {
+ super.stop();
+ }
+
+ /* (non-Javadoc)
+ * @see org.gnu.freeway.util.Service#done()
+ */
+ public void done() throws ServiceException {
+ super.done();
+ loader.unloadService(handle);
+ }
+
+ public CPluginLoader.Handle getHandle() {
+ return handle;
+ }
+}
Modified: freeway/src/org/gnu/freeway/util/DynamicLibrary.java
===================================================================
--- freeway/src/org/gnu/freeway/util/DynamicLibrary.java 2006-07-16
08:50:44 UTC (rev 3121)
+++ freeway/src/org/gnu/freeway/util/DynamicLibrary.java 2006-07-16
17:04:30 UTC (rev 3122)
@@ -5,6 +5,7 @@
package org.gnu.freeway.util;
import java.io.*;
+import java.lang.reflect.Method;
import java.net.*;
import java.util.*;
import java.util.jar.*;
@@ -34,69 +35,140 @@
////////////////////////////////////////////////////////////////////////////////////////////////
- public Object load( Class interfaze )
+ public Object load( Class interfaze, String method, Class[] argt,
Object[] argv )
{
- return load(interfaze,getClass().getClassLoader());
+ return load(interfaze,getClass().getClassLoader(), method,
argt, argv);
}
- public Object load( Class interfaze, ClassLoader loader )
+ public Object load( Class interfaze, ClassLoader loader, String method,
Class[] argt, Object[] argv )
{
- Class c;
- Object obj;
-
- obj=null;
- c=null;
+ Map m = null;
+ Class c = null;
+ Object obj = null;
+ String[] prefixes = null;
+ //TODO: prefs aquisition needs improving!
+ Prefs prefs = ServiceManager.manager.app().getPreferences();
try {
- c=getMainClass(library,loader);
+ m=getMainClass(library,loader);
+ if(m == null)
+ return null;
+ if(m.get("name") != null) {
+ prefixes = prefs.getString("FREEWAY-SERVICES",
((String) m.get("name")).toUpperCase(), "java, c").split(",");
+ } else {
+ prefixes = new String[]{"java"};
+ }
+ } catch( IOException x ) {
+ x.printStackTrace();
+ System.err.println("Could not open library
"+library.getName()+" !");
+ } catch( ClassNotFoundException x ) {
+ x.printStackTrace();
+ System.err.println("Could not open library
"+library.getName()+" !");
+ }
+
+ if(prefixes == null)
+ return null;
+
+ for(int i = 0; i < prefixes.length; i++) {
+ System.err.println((i == 0 ? "Attempting to load " :
"Falling back on ") + prefixes[i].trim() + " implementation" + (m.get("name")
!= null ? " of " + (String) m.get("name") : "") + " from " + library.getName());
+ c = (Class) m.get(prefixes[i].trim().toLowerCase());
if (c==null) {
- log(Level.SEVERE,"No main class found in
library "+library.getName()+".");
+ System.err.println("No " + prefixes[i].trim() +
" implementation in " + library.getName());
+ } else if (interfaze.isAssignableFrom(c)) {
+ obj = null;
+ try {
+ obj=c.newInstance();
+ } catch(Throwable e) {
+ e.printStackTrace();
+ System.err.println("Could not
instantiate class "+c.getCanonicalName()+" !");
+ continue;
}
- else if (interfaze.isAssignableFrom(c)) {
- obj=c.newInstance();
+ if(method != null) {
+ Method mid = null;
+ try {
+ mid =
c.getDeclaredMethod(method, argt);
+ } catch (SecurityException e1) {
+ e1.printStackTrace();
+ System.err.println("Access
denied for initializer " + method + " in " + c.getCanonicalName() + " !");
+ continue;
+ } catch (NoSuchMethodException e1) {
+ e1.printStackTrace();
+ System.err.println("No
initializer " + method + " in " + c.getCanonicalName() + " !");
+ continue;
+ }
+ try {
+ mid.invoke(obj, argv);
+ } catch(Throwable e) {
+ e.printStackTrace();
+ System.err.println("Could not
intialize class "+c.getCanonicalName()+" !");
+ continue;
+ }
}
- else {
- log(Level.SEVERE,"Main class for library
"+library.getName()+" does not implement interface "+interfaze.getName()+".");
- }
+ System.err.println("Loaded " +
prefixes[i].trim() + " implementation");
+ return obj;
+ } else {
+ System.err.println(prefixes[i].trim() + "
implementation in " + library.getName() + " does not implement " +
interfaze.getCanonicalName());
}
- catch( IllegalAccessException x ) {
- err("Could not instantiate class "+c.getName()+" !",x);
- }
- catch( InstantiationException x ) {
- err("Could not instantiate class "+c.getName()+" !",x);
- }
- catch( IOException x ) {
- err("Could not open library "+library.getName()+" !",x);
- }
- catch( ClassNotFoundException x ) {
- err("Could not open library "+library.getName()+" !",x);
- }
- return obj;
+ }
+ return null;
}
+
+ public Object load( Class interfaze )
+ {
+ return load(interfaze,getClass().getClassLoader());
+ }
- protected Class getMainClass( File f, ClassLoader loader ) throws
IOException, ClassNotFoundException
+ public Object load( Class interfaze, ClassLoader loader )
{
+ return load(interfaze, loader, null, null, null);
+ }
+
+ protected Map getMainClass( File f, ClassLoader loader ) throws
IOException, ClassNotFoundException
+ {
JarFile jar;
Manifest mf;
- Class c;
- String str;
-
- c=null;
-
+ String stra;
+ String strb;
+ String strc;
+ Map ret = new HashMap();
jar=new JarFile(f,true,ZipFile.OPEN_READ);
try {
mf=jar.getManifest();
if (mf!=null) {
- str=(String)
mf.getMainAttributes().get(Attributes.Name.MAIN_CLASS);
- if (str!=null) {
+ stra=(String)
mf.getMainAttributes().get(Attributes.Name.MAIN_CLASS);
+ if (stra!=null) {
loader=URLClassLoader.newInstance(new
URL[] {f.toURL()},loader);
- c=loader.loadClass(str);
+ ret.put("java", loader.loadClass(stra));
+ } else {
+ stra = (String)
mf.getMainAttributes().getValue("Freeway-Java-Class");
+ strb = (String)
mf.getMainAttributes().getValue("Freeway-C-Class");
+ strc = (String)
mf.getMainAttributes().getValue("Freeway-name");
+ if(strc != null)
+ ret.put("name", strc);
+ if(stra != null || strb != null) {
+
loader=URLClassLoader.newInstance(new URL[] {f.toURL()},loader);
+ if(stra != null) {
+ try {
+ ret.put("java",
loader.loadClass(stra));
+ } catch(Throwable e) {
+
+ }
+ }
+ if(strb != null) {
+ try {
+ ret.put("c",
loader.loadClass(strb));
+ } catch(Throwable e) {
+
+ }
+ }
}
}
}
- finally {
+ } catch(Throwable e) {
+ e.printStackTrace();
+ } finally {
jar.close();
- }
- return c;
+ }
+ return ret;
}
protected ClassLoader createClassLoader( String[] paths, ClassLoader
loader )
Modified: freeway/src/org/gnu/freeway/util/OSAccess.java
===================================================================
--- freeway/src/org/gnu/freeway/util/OSAccess.java 2006-07-16 08:50:44 UTC
(rev 3121)
+++ freeway/src/org/gnu/freeway/util/OSAccess.java 2006-07-16 17:04:30 UTC
(rev 3122)
@@ -5,6 +5,8 @@
package org.gnu.freeway.util;
import java.util.logging.*;
+import java.io.File;
+import java.io.IOException;
/**
*
@@ -115,28 +117,26 @@
protected static native void _signalsSignal( int pid, int num );
+ //why would we need to know this stuff?
public static boolean fileIsLink( String path )
{
- if (loaded) {
- return _fileIsLink(path);
- }
- logger.log(Level.INFO,"Could not determine whether file
\""+path+"\" is a link, library is not loaded.");
- return false;
+ File file = new File(path);
+ try {
+ return
!file.getAbsolutePath().equals(file.getCanonicalPath());
+ } catch(IOException e) {
+ throw new Error(e);
+ }
}
- protected static native boolean _fileIsLink( String path );
-
public static String fileGetLinkTarget( String path )
{
- if (loaded) {
- return _fileGetLinkTarget(path);
- }
- logger.log(Level.INFO,"Could not get target of link
\""+path+"\", library is not loaded.");
- return null;
+ try {
+ return new File(path).getCanonicalPath();
+ } catch(IOException e) {
+ return null;
+ }
}
- protected static native String _fileGetLinkTarget( String path );
-
public static boolean fileCreateLink( String path, String target )
{
if (loaded) {
Modified: freeway/src/org/gnu/freeway/util/ServiceManager.java
===================================================================
--- freeway/src/org/gnu/freeway/util/ServiceManager.java 2006-07-16
08:50:44 UTC (rev 3121)
+++ freeway/src/org/gnu/freeway/util/ServiceManager.java 2006-07-16
17:04:30 UTC (rev 3122)
@@ -55,11 +55,29 @@
}
public Service service( Class c )
{
+ return service(c, null);
+ }
+ public Service service( Class c, String forcedType )
+ {
Service s;
s = (Service) services.get(c);
- if(s!=null)
+ if(s!=null) {
+ if(forcedType != null) {
+ String type;
+ String[] prefixes;
+ prefixes = forcedType.split(",");
+ for(int i = 0; i < prefixes.length; i++) {
+ type = prefixes[i].trim().toLowerCase();
+
if(s.getClass().getCanonicalName().startsWith("org.gnu.freeway.services." +
type)) {
+ return s;
+ }
+ }
+ System.err.println("Unable to load service " +
c.getCanonicalName() + " because an incompatible implementation is already
loaded.");
+ return null;
+ }
return s;
+ }
// find an implementation for a org.gnu.freeway.services
interface
if(c.isInterface() &&
c.getCanonicalName().startsWith("org.gnu.freeway.services")) {
@@ -70,13 +88,16 @@
type = c.getSimpleName();
type = type.substring(0, type.length() -
7).toUpperCase(); // -"Service"
- prefixes =
app.getPreferences().getString("FREEWAY-SERVICES", type, "java, c").split(",");
+ if(forcedType == null)
+ prefixes =
app.getPreferences().getString("FREEWAY-SERVICES", type, "java, c").split(",");
+ else
+ prefixes = forcedType.split(",");
for(int i = 0; i < prefixes.length; i++) {
type = prefixes[i].trim();
className = c.getPackage().getName() + "." +
type.toLowerCase() + "." + c.getSimpleName();
- System.err.println((i == 0 ? "Loading " :
"Falling back on ") + type + " service: " + className);
+ System.err.println((i == 0 ? "Loading " :
"Falling back on ") + type + " service: " + className + (forcedType != null ? "
(forced type)" : ""));
try {
t = Class.forName(className);
} catch(ClassNotFoundException e) {
@@ -134,9 +155,10 @@
s.start();
}
}
- catch( ServiceException x ) {
+ catch( Throwable x ) {
System.err.println("Failed to init/start service
'"+s.getName()+"' !");
err("Failed to init/start service '"+s.getName()+"'
!",x);
+ services.remove(c);
}
return s;
}
Modified: freeway/src/org/gnu/freeway/util/Stat.java
===================================================================
--- freeway/src/org/gnu/freeway/util/Stat.java 2006-07-16 08:50:44 UTC (rev
3121)
+++ freeway/src/org/gnu/freeway/util/Stat.java 2006-07-16 17:04:30 UTC (rev
3122)
@@ -4,94 +4,38 @@
package org.gnu.freeway.util;
-import org.gnu.freeway.util.net.*;
+import org.gnu.freeway.services.StatsService;
+import org.gnu.freeway.cwrappers.*;
-import EDU.oswego.cs.dl.util.concurrent.*;
-
-import java.nio.*;
-
/**
* A statistical value along with its description.
*/
-public class Stat extends Object implements Persistent
+public class Stat extends Object
{
- public static final int VERBOSE = 1;
- public static final int NORMAL = 5;
- private String name;
- private int level;
- private boolean timed;
- private long value;
- private Sync lck;
+ public static final int NORMAL = 0;
+ public static final int VERBOSE = 0;
+ private StatsService service;
+ private CInt handle;
+ private String name;
public Stat( String str )
{
- this(str,NORMAL);
+ service = (StatsService)
ServiceManager.manager.service(StatsService.class);
+ handle = service.create(new CString(str));
+ name = str;
}
- public Stat( String str, int lev )
- {
- super();
- name=str;
- level=lev;
- timed=false;
- value=0;
- lck=new ReentrantLock();
- }
-
public String toString()
{
- return "Statistic [name="+name+", level="+level+",
timed="+timed+", value="+value+"]";
+ return "Statistic [name="+name+",
value="+service.get(handle).getValue()+"]";
}
////////////////////////////////////////////////////////////////////////////////////////////////
- public void lock()
- {
- try {
- lck.acquire();
- }
- catch( InterruptedException x ) {
- }
- }
-
- public void unlock()
- {
- lck.release();
- }
-
- public int getLevel()
- {
- return level;
- }
-
- public void setLevel( int lev )
- {
- lock();
- level=lev;
- unlock();
- }
-
- public boolean isTimed()
- {
- return timed;
- }
-
- public void setTimed( boolean flag )
- {
- lock();
- timed=flag;
- unlock();
- }
-
- public void dump()
- {
- System.out.println(" "+name+"/"+level+" : "+value);
- }
-
public String getName()
{
return name;
@@ -99,21 +43,17 @@
public void reset()
{
- lock();
- value=0;
- unlock();
+ service.set(handle, new CLong(0));
}
public long get()
{
- return value;
+ return service.get(handle).getValue();
}
public void set( long n )
{
- lock();
- value=n;
- unlock();
+ service.set(handle, new CLong(n));
}
/**
@@ -121,62 +61,23 @@
* @param n
*/
- public void add( long n )
+ public void add( int n )
{
- lock();
- value+=n;
- unlock();
+ service.change(handle, new CInt(n));
}
- public void sub( long n )
+ public void sub( int n )
{
- lock();
- value-=n;
- unlock();
+ service.change(handle, new CInt(-n));
}
public void inc()
{
- lock();
- value++;
- unlock();
+ service.change(handle, new CInt(1));
}
public void dec()
{
- lock();
- value--;
- unlock();
+ service.change(handle, new CInt(-1));
}
-
- public int getByteSize()
- {
- return name.getBytes().length+9+2;
- }
-
- public void readBytes( ByteBuffer buf, ErrorReporter err )
- {
- byte[] b;
- int pos,len;
-
- value=buf.getLong();
- level=buf.getShort() & 0x0000ffff;
-
- pos=buf.position();
- for (len=0; buf.get()!=0; len++) {}
- buf.position(pos);
-
- b=new byte[len];
- buf.get(b);
- name=new String(b);
- err.reportIf(buf.get()!=0,"string not null-terminated");
// last 0
- }
-
- public void writeBytes( ByteBuffer buf )
- {
- buf.putLong(value);
- buf.putShort((short) level);
- buf.put(name.getBytes());
- buf.put((byte) 0);
- }
}
Modified: freeway/src/org/gnu/freeway/util/Statistics.java
===================================================================
--- freeway/src/org/gnu/freeway/util/Statistics.java 2006-07-16 08:50:44 UTC
(rev 3121)
+++ freeway/src/org/gnu/freeway/util/Statistics.java 2006-07-16 17:04:30 UTC
(rev 3122)
@@ -4,51 +4,21 @@
package org.gnu.freeway.util;
-import org.gnu.freeway.server.*;
-import org.gnu.freeway.util.net.*;
+import org.gnu.freeway.services.StatsService;
-import EDU.oswego.cs.dl.util.concurrent.*;
-
-import java.util.*;
-
-/**
- * GNUnet statistics module.
- * keeping statistics of GNUnet activities
- *
- * This module keeps a mapping of strings to values.
- * Every entry in the mapping can be accessed with a handle
- * (int) which can be obtained from the string. The module can be used
- * to keep track of certain statistical information, such as the
- * number of bytes received, messages sent, kilobytes stored, and so
- * on.<p>
- *
- * When used within gnunetd, the gnunet-stats tool can be used to
- * print the statistical information stored in this module.
- */
-
public class Statistics extends LoggedObject
{
- /** When did the module start ? */
- private long startTime;
+ private StatsService service;
- /** A description for each of the values. */
- private List stats;
-
- /** */
- private Sync lock;
-
-
public Statistics()
{
super(true);
- startTime=Scheduler.now();
- stats=new ArrayList();
- lock=new ReentrantLock();
+ service = (StatsService)
ServiceManager.manager.service(StatsService.class);
}
public String toString()
{
- return "Statistics [startTime="+startTime+"]";
+ return "Statistics wrapper";
}
@@ -56,45 +26,9 @@
public void done()
{
- lock();
- stats.clear();
- unlock();
+ service.done();
}
-
- public void lock()
- {
- try {
- lock.acquire();
- }
- catch( InterruptedException x ) {
- }
- }
-
- public void unlock()
- {
- lock.release();
- }
-
- public void lockAll()
- {
- int i;
-
- lock();
- for (i=0; i<stats.size(); i++) {
- ((Stat) stats.get(i)).lock();
- }
- }
-
- public void unlockAll()
- {
- int i;
-
- for (i=0; i<stats.size(); i++) {
- ((Stat) stats.get(i)).unlock();
- }
- unlock();
- }
-
+
/**
* Get a handle to a statistical entity.
*
@@ -104,30 +38,12 @@
public Stat getHandle( String name )
{
- return getHandle(name,Stat.NORMAL);
+ return new Stat(name);
}
public Stat getHandle( String name, int level )
{
- Stat stat;
- int i;
-
- assert(name!=null);
-
- lock();
-
- for (i=0; i<stats.size(); i++) {
- stat=(Stat) stats.get(i);
- if (stat.getName().equals(name)) {
- return stat;
- }
- }
-
- stat=new Stat(name,level);
- stats.add(stat);
- unlock();
-
- return stat;
+ return new Stat(name);
}
/**
@@ -137,7 +53,7 @@
* @return
*/
- public CSStatistics[] createMessages( int minLevel )
+ /*public CSStatistics[] createMessages( int minLevel )
{
List list;
CSStatistics msg;
@@ -179,9 +95,9 @@
unlockAll();
return (CSStatistics[]) list.toArray(new
CSStatistics[list.size()]);
- }
+ } */
- public void dump()
+ /*public void dump()
{
int i;
@@ -194,5 +110,5 @@
}
unlockAll();
- }
+ }*/
}
Modified: freeway/src/org/gnu/freeway/util/StatusCallsService.java
===================================================================
--- freeway/src/org/gnu/freeway/util/StatusCallsService.java 2006-07-16
08:50:44 UTC (rev 3121)
+++ freeway/src/org/gnu/freeway/util/StatusCallsService.java 2006-07-16
17:04:30 UTC (rev 3122)
@@ -296,15 +296,9 @@
}
useBasicMethod= prefs.testString("LOAD",
"BASICLIMITING","YES");
- maxNetDownBPS =
prefs.getInt("LOAD","MAXNETDOWNBPSTOTAL",0);
- if (maxNetDownBPS == 0)
- maxNetDownBPS = 50000;
- maxNetUpBPS = prefs.getInt("LOAD","MAXNETUPBPSTOTAL",0);
- if (maxNetUpBPS == 0)
- maxNetUpBPS = 50000;
- maxCPULoad= prefs.getInt("LOAD","MAXCPULOAD",0);
- if (maxCPULoad == 0)
- maxCPULoad = 100;
+ maxNetDownBPS =
prefs.getInt("LOAD","MAXNETDOWNBPSTOTAL",50000);
+ maxNetUpBPS =
prefs.getInt("LOAD","MAXNETUPBPSTOTAL",50000);
+ maxCPULoad= prefs.getInt("LOAD","MAXCPULOAD",100);
}
}
Modified: freeway/src/org/gnu/freeway/util/net/PersistentHelper.java
===================================================================
--- freeway/src/org/gnu/freeway/util/net/PersistentHelper.java 2006-07-16
08:50:44 UTC (rev 3121)
+++ freeway/src/org/gnu/freeway/util/net/PersistentHelper.java 2006-07-16
17:04:30 UTC (rev 3122)
@@ -25,48 +25,57 @@
{
Persistent p;
int pos;
-
+System.err.println("read0 ");
p=null;
if (Persistent.class.isAssignableFrom(c)) {
+ System.err.println("read1 " + p);
pos=buf.position();
try {
+ System.err.println("read2 " +
c.getCanonicalName());
p=(Persistent) c.newInstance();
+ System.err.println("read3 " + p);
p.readBytes(buf,new ErrorReporter());
-
+ System.err.println("read4 " + p);
if (buf.position()!=pos+p.getByteSize()) {
- logger.log(Level.SEVERE,"Advertised
size does not match reality ("+c.getName()+") !");
+ System.err.println("read5 " +
p);logger.log(Level.SEVERE,"Advertised size does not match reality
("+c.getName()+") !");
buf.position(pos);
p=null;
}
}
catch( BufferUnderflowException x ) {
+ System.err.println("read6 " + p);
logger.log(Level.SEVERE,"Buffer underflow
("+c.getName()+") !",x);
buf.position(pos);
p=null;
}
catch( IllegalStateException x ) {
+ System.err.println("read7 " + p);
logger.log(Level.SEVERE,"Corrupted data
("+x.getMessage()+") !",x);
buf.position(pos);
p=null;
}
catch( InstantiationException x ) {
+ System.err.println("read8 " + p);
logger.log(Level.SEVERE,"Could not create
instance of "+c.getName()+".",x);
}
catch( IllegalAccessException x ) {
+ System.err.println("read9 " + p);
logger.log(Level.SEVERE,"Could not create
instance of "+c.getName()+".",x);
}
}
else {
+ System.err.println("reada " + p);
logger.log(Level.SEVERE,"Instances of "+c.getName()+"
are not persistent.");
}
+ System.err.println("readb " + p);
return p;
}
public static Persistent readFully( Class c, ByteBuffer buf )
{
Persistent p;
-
p=read(c,buf);
+ System.err.println("FATAL1 " + p);
if (p!=null && buf.remaining()>0) {
logger.log(Level.SEVERE,"Buffer larger than expected
("+c.getName()+").");
p=null;
@@ -105,6 +114,7 @@
boolean res;
res=write(p,buf);
+
if (res && buf.remaining()>0) {
logger.log(Level.SEVERE,"Buffer larger than expected
("+p.getClass().getName()+").");
res=false;
@@ -123,6 +133,7 @@
if (writeFully(p,buf)) {
buf.flip();
p=readFully(p.getClass(),buf);
+ System.err.println("FATAL " + p);
}
else {
p=null;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r3122 - in freeway: . doc etc/support/clib native src/org/gnu/freeway src/org/gnu/freeway/protocol/afs/swing src/org/gnu/freeway/protocol/stats src/org/gnu/freeway/server src/org/gnu/freeway/services src/org/gnu/freeway/services/java src/org/gnu/freeway/util src/org/gnu/freeway/util/net,
mdonoughe <=