KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jrobin > mrtg > client > RpcClient


1 /* ============================================================
2  * JRobin : Pure java implementation of RRDTool's functionality
3  * ============================================================
4  *
5  * Project Info: http://www.jrobin.org
6  * Project Lead: Sasa Markovic (saxon@jrobin.org);
7  *
8  * (C) Copyright 2003, by Sasa Markovic.
9  *
10  * Developers: Sasa Markovic (saxon@jrobin.org)
11  * Arne Vandamme (cobralord@jrobin.org)
12  *
13  * This library is free software; you can redistribute it and/or modify it under the terms
14  * of the GNU Lesser General Public License as published by the Free Software Foundation;
15  * either version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19  * See the GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License along with this
22  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23  * Boston, MA 02111-1307, USA.
24  */

25 package org.jrobin.mrtg.client;
26
27 import org.apache.xmlrpc.XmlRpcClient;
28 import org.apache.xmlrpc.XmlRpcException;
29 import org.jrobin.mrtg.MrtgConstants;
30
31 import java.io.IOException JavaDoc;
32 import java.util.Date JavaDoc;
33 import java.util.Hashtable JavaDoc;
34 import java.util.Vector JavaDoc;
35
36 class RpcClient implements MrtgConstants {
37
38     private XmlRpcClient webClient;
39
40     RpcClient(String JavaDoc host) throws IOException JavaDoc {
41         webClient = new XmlRpcClient(host, SERVER_PORT);
42     }
43
44     Hashtable JavaDoc getMrtgInfo() throws IOException JavaDoc, XmlRpcException {
45         Vector JavaDoc params = new Vector JavaDoc();
46         return (Hashtable JavaDoc) webClient.execute("mrtg.getMrtgInfo", params);
47     }
48
49     byte[] getPngGraph(RouterInfo routerInfo, LinkInfo linkInfo, Date JavaDoc start, Date JavaDoc stop)
50         throws IOException JavaDoc, XmlRpcException {
51         Vector JavaDoc params = new Vector JavaDoc();
52         params.add(routerInfo.getHost());
53         params.add(linkInfo.getIfDescr());
54         params.add(start);
55         params.add(stop);
56         return (byte[]) webClient.execute("mrtg.getPngGraph", params);
57     }
58
59     int addRouter(RouterInfo routerInfo)
60         throws IOException JavaDoc, XmlRpcException {
61         Vector JavaDoc params = new Vector JavaDoc();
62         params.add(routerInfo.getHost());
63         params.add(routerInfo.getCommunity());
64         params.add(routerInfo.getDescr());
65         params.add(new Boolean JavaDoc(routerInfo.isActive()));
66         return ((Integer JavaDoc) webClient.execute("mrtg.addRouter", params)).intValue();
67     }
68
69     int updateRouter(RouterInfo routerInfo)
70         throws IOException JavaDoc, XmlRpcException {
71         Vector JavaDoc params = new Vector JavaDoc();
72         params.add(routerInfo.getHost());
73         params.add(routerInfo.getCommunity());
74         params.add(routerInfo.getDescr());
75         params.add(new Boolean JavaDoc(routerInfo.isActive()));
76         return ((Integer JavaDoc) webClient.execute("mrtg.updateRouter", params)).intValue();
77     }
78
79     int deleteRouter(RouterInfo routerInfo) throws IOException JavaDoc, XmlRpcException {
80         Vector JavaDoc params = new Vector JavaDoc();
81         params.add(routerInfo.getHost());
82         return ((Integer JavaDoc) webClient.execute("mrtg.removeRouter", params)).intValue();
83     }
84
85     Vector JavaDoc getAvailableLinks(RouterInfo routerInfo)
86         throws IOException JavaDoc, XmlRpcException {
87         Vector JavaDoc params = new Vector JavaDoc();
88         params.add(routerInfo.getHost());
89         Vector JavaDoc result = (Vector JavaDoc) webClient.execute("mrtg.getAvailableLinks", params);
90         return result;
91     }
92
93     int addLink(RouterInfo routerInfo, LinkInfo linkInfo) throws XmlRpcException, IOException JavaDoc {
94         Vector JavaDoc params = new Vector JavaDoc();
95         params.add(routerInfo.getHost());
96         params.add(linkInfo.getIfDescr());
97         params.add(linkInfo.getDescr());
98         params.add(new Integer JavaDoc(linkInfo.getSamplingInterval()));
99         params.add(new Boolean JavaDoc(linkInfo.isActive()));
100         return ((Integer JavaDoc) webClient.execute("mrtg.addLink", params)).intValue();
101     }
102
103     int updateLink(RouterInfo routerInfo, LinkInfo linkInfo)
104         throws XmlRpcException, IOException JavaDoc {
105         Vector JavaDoc params = new Vector JavaDoc();
106         params.add(routerInfo.getHost());
107         params.add(linkInfo.getIfDescr());
108         params.add(linkInfo.getDescr());
109         params.add(new Integer JavaDoc(linkInfo.getSamplingInterval()));
110         params.add(new Boolean JavaDoc(linkInfo.isActive()));
111         return ((Integer JavaDoc) webClient.execute("mrtg.updateLink", params)).intValue();
112     }
113
114     int removeLink(RouterInfo routerInfo, LinkInfo linkInfo)
115         throws XmlRpcException, IOException JavaDoc {
116         Vector JavaDoc params = new Vector JavaDoc();
117         params.add(routerInfo.getHost());
118         params.add(linkInfo.getIfDescr());
119         return ((Integer JavaDoc) webClient.execute("mrtg.removeLink", params)).intValue();
120     }
121 }
122
Popular Tags