Removing doc subdir which resides now in sonews-doc repository.
3 * see AUTHORS for the list of contributors
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package org.sonews.daemon.command;
21 import java.io.IOException;
22 import java.net.InetSocketAddress;
23 import java.util.List;
24 import org.sonews.config.Config;
25 import org.sonews.daemon.NNTPConnection;
26 import org.sonews.storage.StorageBackendException;
27 import org.sonews.storage.StorageManager;
28 import org.sonews.feed.FeedManager;
29 import org.sonews.feed.Subscription;
30 import org.sonews.storage.Group;
31 import org.sonews.util.Stats;
34 * The XDAEMON command allows a client to get/set properties of the
35 * running server daemon. Only locally connected clients are allowed to
37 * The restriction to localhost connection can be suppressed by overriding
38 * the sonews.xdaemon.host bootstrap config property.
39 * @author Christian Lins
42 public class XDaemonCommand implements Command
46 public String[] getSupportedCommandStrings()
48 return new String[]{"XDAEMON"};
52 public boolean hasFinished()
58 public boolean isStateful()
63 // TODO: Refactor this method to reduce complexity!
65 public void processLine(NNTPConnection conn, String line, byte[] raw)
66 throws IOException, StorageBackendException
68 InetSocketAddress addr = (InetSocketAddress)conn.getSocketChannel().socket()
69 .getRemoteSocketAddress();
70 if(addr.getHostName().equals(
71 Config.inst().get(Config.XDAEMON_HOST, "localhost")))
73 String[] commands = line.split(" ", 4);
74 if(commands.length == 3 && commands[1].equalsIgnoreCase("LIST"))
76 if(commands[2].equalsIgnoreCase("CONFIGKEYS"))
78 conn.println("100 list of available config keys follows");
79 for(String key : Config.AVAILABLE_KEYS)
85 else if(commands[2].equalsIgnoreCase("PEERINGRULES"))
87 List<Subscription> pull =
88 StorageManager.current().getSubscriptions(FeedManager.TYPE_PULL);
89 List<Subscription> push =
90 StorageManager.current().getSubscriptions(FeedManager.TYPE_PUSH);
91 conn.println("100 list of peering rules follows");
92 for(Subscription sub : pull)
94 conn.println("PULL " + sub.getHost() + ":" + sub.getPort()
95 + " " + sub.getGroup());
97 for(Subscription sub : push)
99 conn.println("PUSH " + sub.getHost() + ":" + sub.getPort()
100 + " " + sub.getGroup());
106 conn.println("401 unknown sub command");
109 else if(commands.length == 3 && commands[1].equalsIgnoreCase("DELETE"))
111 StorageManager.current().delete(commands[2]);
112 conn.println("200 article " + commands[2] + " deleted");
114 else if(commands.length == 4 && commands[1].equalsIgnoreCase("GROUPADD"))
116 StorageManager.current().addGroup(commands[2], Integer.parseInt(commands[3]));
117 conn.println("200 group " + commands[2] + " created");
119 else if(commands.length == 3 && commands[1].equalsIgnoreCase("GROUPDEL"))
121 Group group = StorageManager.current().getGroup(commands[2]);
124 conn.println("400 group not found");
128 group.setFlag(Group.DELETED);
130 conn.println("200 group " + commands[2] + " marked as deleted");
133 else if(commands.length == 4 && commands[1].equalsIgnoreCase("SET"))
135 String key = commands[2];
136 String val = commands[3];
137 Config.inst().set(key, val);
138 conn.println("200 new config value set");
140 else if(commands.length == 3 && commands[1].equalsIgnoreCase("GET"))
142 String key = commands[2];
143 String val = Config.inst().get(key, null);
146 conn.println("100 config value for " + key + " follows");
152 conn.println("400 config value not set");
155 else if(commands.length >= 3 && commands[1].equalsIgnoreCase("LOG"))
158 if(commands.length > 3)
160 group = Group.getByName(commands[3]);
163 if(commands[2].equalsIgnoreCase("CONNECTED_CLIENTS"))
165 conn.println("100 number of connections follow");
166 conn.println(Integer.toString(Stats.getInstance().connectedClients()));
169 else if(commands[2].equalsIgnoreCase("POSTED_NEWS"))
171 conn.println("100 hourly numbers of posted news yesterday");
172 for(int n = 0; n < 24; n++)
174 conn.println(n + " " + Stats.getInstance()
175 .getYesterdaysEvents(Stats.POSTED_NEWS, n, group));
179 else if(commands[2].equalsIgnoreCase("GATEWAYED_NEWS"))
181 conn.println("100 hourly numbers of gatewayed news yesterday");
182 for(int n = 0; n < 24; n++)
184 conn.println(n + " " + Stats.getInstance()
185 .getYesterdaysEvents(Stats.GATEWAYED_NEWS, n, group));
189 else if(commands[2].equalsIgnoreCase("TRANSMITTED_NEWS"))
191 conn.println("100 hourly numbers of news transmitted to peers yesterday");
192 for(int n = 0; n < 24; n++)
194 conn.println(n + " " + Stats.getInstance()
195 .getYesterdaysEvents(Stats.FEEDED_NEWS, n, group));
199 else if(commands[2].equalsIgnoreCase("HOSTED_NEWS"))
201 conn.println("100 number of overall hosted news");
202 conn.println(Integer.toString(Stats.getInstance().getNumberOfNews()));
205 else if(commands[2].equalsIgnoreCase("HOSTED_GROUPS"))
207 conn.println("100 number of hosted groups");
208 conn.println(Integer.toString(Stats.getInstance().getNumberOfGroups()));
211 else if(commands[2].equalsIgnoreCase("POSTED_NEWS_PER_HOUR"))
213 conn.println("100 posted news per hour");
214 conn.println(Double.toString(Stats.getInstance().postedPerHour(-1)));
217 else if(commands[2].equalsIgnoreCase("FEEDED_NEWS_PER_HOUR"))
219 conn.println("100 feeded news per hour");
220 conn.println(Double.toString(Stats.getInstance().feededPerHour(-1)));
223 else if(commands[2].equalsIgnoreCase("GATEWAYED_NEWS_PER_HOUR"))
225 conn.println("100 gatewayed news per hour");
226 conn.println(Double.toString(Stats.getInstance().gatewayedPerHour(-1)));
231 conn.println("401 unknown sub command");
236 conn.println("400 invalid command usage");
241 conn.println("501 not allowed");