Mercurial > java-rrd-hg
changeset 29:3bda723525f2
* two more contrib/test/demo classes
- they really do not serve any real purpose....
author | Peter Stamfest <peter@stamfest.at> |
---|---|
date | Mon, 28 Jan 2013 21:44:02 +0100 |
parents | 05bb7389ffa0 |
children | b072a0e69dc5 |
files | src/contrib/java/net/stamfest/rrd/tests/HelloPool.java src/contrib/java/net/stamfest/rrd/tests/PoolTest.java |
diffstat | 2 files changed, 106 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/contrib/java/net/stamfest/rrd/tests/HelloPool.java Mon Jan 28 21:44:02 2013 +0100 @@ -0,0 +1,33 @@ +package net.stamfest.rrd.tests; + +import java.util.HashMap; +import java.util.Map.Entry; + +import net.stamfest.rrd.CommandResult; +import net.stamfest.rrd.RRDCommandPool; +import net.stamfest.rrd.TCPRRDCommandFactory; + +public class HelloPool { + public static void main(String[] args) throws Exception { + String rrdFileName = args[2]; + RRDCommandPool pool = new RRDCommandPool(10, new TCPRRDCommandFactory(Integer.parseInt(args[0]), args[1])); + + for (int i = 0 ; i < 60 ; i++) { + System.out.println("start " + i); + + CommandResult result = pool.command(new String[] { "info", rrdFileName }); + System.out.println(result); + + HashMap<String, String> hm = result.getInfo(); + + if (hm != null) { + for (Entry<String,String> e : hm.entrySet()) { + System.out.printf("%s:\t%s\n", e.getKey(), e.getValue()); + } + } + System.out.println("done " + i); + + Thread.sleep(10000); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/contrib/java/net/stamfest/rrd/tests/PoolTest.java Mon Jan 28 21:44:02 2013 +0100 @@ -0,0 +1,73 @@ +/* + + Copyright (c) 2010 by Peter Stamfest <peter@stamfest.at> + + This file is part of java-rrd. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + Except as contained in this notice, the name of Peter Stamfest shall not + be used in advertising or otherwise to promote the sale, use or other + dealings in this Software without prior written authorization from + Peter Stamfest. + +*/ + + +package net.stamfest.rrd.tests; + +import java.util.ArrayList; + +import net.stamfest.rrd.CommandResult; +import net.stamfest.rrd.RRDCommandPool; +import net.stamfest.rrd.RRDToolService; + +public class PoolTest { + public static void main(String argv[]) throws Exception { + RRDCommandPool pool = new RRDCommandPool("/", null); + final RRDToolService rrd = new RRDToolService(pool); + + ArrayList<String> cmd = new ArrayList<String>(); + cmd.add("DEF:in=/tmp/D3.rrd:in:AVERAGE"); + cmd.add("LINE1:in#ff0000:in"); + + final String cmdarray[] = cmd.toArray(new String[0]); + + for (int j = 0 ; j < 5 ; j++) { + Thread t = new Thread() { + @Override + public void run() { + for (int i = 0 ; i < 100 ; i++) { + CommandResult r; + try { + r = rrd.graphv(cmdarray); + System.out.println(r); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + }; + + t.start(); + } + + } +}