Plotting coordinate data being generated in a separate thread
in
Contributed Library Questions
•
1 year ago
Greetings,
I am trying to display (many) points on a map from a stream of coordinate data. Specifically, I want to display the locations of IP addresses on a world map. I thought I had the hard part out of the way, and I usually figure these things out by myself, but I'm having some trouble finding a way to actually
display the data that I am generating. I hope that this is a general design problem, and not some limitation. Some background:
I am able to capture and print IP addresses and coordinates to the console. However, I cannot find a way to actually USE this data within the Processing draw() method. I think that this is because the jflow library collects (and does whatever else you want) in a separate accounting thread. "
Note that the collector is multithreaded. Calling
start
will start collecting in the background, the call will return immediately." If this is the case, what's the best way to access and draw the incoming data? Some kind of IPC? Somehow make the IP collection thread use the draw() method?
Below is an example IP collection class, with some edits showing how I would like to use it. What can I do with this separate thread?
This might lead to other questions, like, should I somehow run the draw() method at a constant rate and asynchronously update it with incoming data from the IP collection thread? Any advice is welcome. Please let me know if anything is not clear.
- import java.net.InetAddress;
- import java.net.SocketException;
- import java.net.UnknownHostException;
- import nettrack.net.netflow.*;
- import com.maxmind.geoip.*;
- import com.maxmind.geoip.Location;
- public class V5Printer
- {
- static class PrintAccountant
- implements Accountant
- {
- public void account(Flow f)
- {
- //method nest below are not real, just illustrating intent.
- drawMapCoordinatesPoint(getGeoIPCoordinates(f.ipAddress))
- }
- public void destroy()
- {
- }
- }
- public static void main(String[] arg)
- {
- InetAddress source = InetAddress.getByName("10.10.10.10");
- Collector collector = new Collector(2055);
- V5FlowHandler handler = new V5FlowHandler(source, 100);
- handler.addAccountant(new PrintAccountant());
- collector.addFlowHandler(handler);
- collector.start(); //starts the collection thread.
- }
- }
1