Commit Graph

17 Commits

Author SHA1 Message Date
Peter Johnson
5ac68f74d4 Support client round robin to multiple server addresses.
Change-Id: If87dc64a485b1c8a340c5f6fa39ca09d40133e30
2016-04-08 22:02:52 -07:00
Peter Johnson
fef8f933d9 Add SafeThread to fix thread JNI shutdown races.
During JVM shutdown, some JNI calls may not return, so it's not possible to
reliably perform a join() during static variable destruction (which occurs
as the JVM unloads the JNI module).

Also, due to static variable destruction, it's not safe to use any members
of a static class instance from a separate thread of execution.

SafeThread is a templated thread class and a related owner class that's
designed for safe operation and shutdown of threads in the presence of
callbacks that may not return.  It also passes ownership of variables from
the static instance to the thread, so the thread can safely operate until
it exits (the last operation of the thread being to destroy its instance).

Notifiers, RpcServer, and Logger now use SafeThread to ensure race-free
destruction in both C++ and Java.

All Java callback threads are now marked as Java daemon threads so they
don't keep the JVM running after main() terminates.

All Java callback threads are now named so their purpose is more easily
identified in a debugger.

Add SetRpcServerOnStart and SetRpcServerOnExit (similar to Listener).
2015-12-28 17:51:56 -08:00
Peter Johnson
32001427d4 Java: call JNI AttachCurrentThread less frequently.
Each call to AttachCurrentThread results in a new Java thread object being
created.  This is inefficient and also causes debugging issues with Eclipse
due to constant creation and removal of threads.  Now AttachCurrentThread is
only called once for (all) listeners and once for logging (if used).
2015-12-20 20:42:09 -08:00
Thad House
a142cc48d3 Adds StopNotifier and StopRpcServer functions
Workaround for #30.  Allows libraries to shut down the secondary
threads.
2015-11-11 20:50:30 -08:00
Peter Johnson
90959defd9 Provide more extensive listener features.
This enables listeners to be notified of not only value updates, but also flag
changes and deletions by using a bitmask to specify what notifications are
desired.  The old API (which only provided a new/not new) flag is still
supported.  This also subsumes the feature to listen to local changes (that's
one of the bitmask options).
2015-09-27 01:55:32 -07:00
Peter Johnson
424bf51a7b Implement local notification.
The default behavior is to only notify remote changes, but for some
applications (e.g. GUI's) it's advantageous to know about local
changes as well.

This is (slightly) optimized in that local changes only result in
additional resources being consumed if (any) local listeners have been
created.
2015-09-23 00:56:08 -07:00
Peter Johnson
51eb96903c Java: Improve robustness against JVM crashes on exit.
The JVM doesn't always do a good job of telling JNI modules that the JVM
is going away, which results in a crash in the JavaGlobal and/or
JavaWeakGlobal destructors as they try to delete the associated references
after the JVM has already gone away.

To protect against this, the Notifier now has a static variable that's set
when the Notifier instance (a singleton) is destroyed.  This is used by
JavaGlobal and JavaWeakGlobal to detect when a process exit is in process.
2015-09-14 22:00:22 -07:00
Peter Johnson
b488cdd6ff Support immediate notify of connection listener.
Also only perform immediate notification to the callback actually
requesting the notification, not all existing callbacks.

Offset returned uids by 1 so uid=0 can be used to indicate immediate
notification.
2015-08-28 00:13:56 -07:00
Peter Johnson
302cc064c6 ConnectionListener: Use bool instead of int for connected parameter. 2015-08-27 23:48:40 -07:00
Peter Johnson
8d7cdeabbf Implement remote procedure calls. 2015-08-13 21:32:16 -07:00
Peter Johnson
4356e313ec Add logging framework.
DEBUG messages are completely optimized out if NDEBUG is defined.
2015-07-31 22:41:26 -07:00
Peter Johnson
6f940bcaaf Add immediate_notify and is_new to entry listener.
On the callback function, is_new indicates the value is newly added.

On adding a callback function, immediate_notify indicates the callback
should be called once (with is_new=true) for each matching entry that
already exists.
2015-07-23 01:02:53 -07:00
Peter Johnson
4c14f7823a ntcore_cpp.h: Comment cleanup. 2015-07-22 21:41:25 -07:00
Peter Johnson
98d45777c6 Remove unnecessary llvm qualifier. 2015-07-20 00:19:20 -07:00
Peter Johnson
1cc148848b StartServer: Take persist_filename as a StringRef. 2015-07-19 16:11:56 -07:00
Peter Johnson
c4a7f6ec9b SavePersistent: Safely save through temp file.
Also change SavePersistent and LoadPersistent to take StringRef.
2015-07-18 00:39:08 -07:00
Peter Johnson
fcbd2751ba Provide C++ API. Move all classes to "nt" namespace.
The C API is now just simple wrappers around the C++ API.
2015-07-17 07:21:07 -07:00