[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r32614 - in gnunet-java/src/main/java/org/gnunet: requests
From: |
gnunet |
Subject: |
[GNUnet-SVN] r32614 - in gnunet-java/src/main/java/org/gnunet: requests statistics |
Date: |
Tue, 11 Mar 2014 02:25:03 +0100 |
Author: dold
Date: 2014-03-11 02:25:03 +0100 (Tue, 11 Mar 2014)
New Revision: 32614
Added:
gnunet-java/src/main/java/org/gnunet/requests/FixedMessageRequest.java
gnunet-java/src/main/java/org/gnunet/requests/Request.java
gnunet-java/src/main/java/org/gnunet/requests/RequestIdentifier.java
gnunet-java/src/main/java/org/gnunet/requests/SimpleRequestIdentifier.java
gnunet-java/src/main/java/org/gnunet/requests/TimeoutHandler.java
gnunet-java/src/main/java/org/gnunet/statistics/StatisticsTool.java
Log:
- missing files
Added: gnunet-java/src/main/java/org/gnunet/requests/FixedMessageRequest.java
===================================================================
--- gnunet-java/src/main/java/org/gnunet/requests/FixedMessageRequest.java
(rev 0)
+++ gnunet-java/src/main/java/org/gnunet/requests/FixedMessageRequest.java
2014-03-11 01:25:03 UTC (rev 32614)
@@ -0,0 +1,49 @@
+/*
+ This file is part of GNUnet.
+ (C) 2014 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+
+package org.gnunet.requests;
+
+import org.gnunet.mq.Envelope;
+import org.gnunet.util.GnunetMessage;
+
+/**
+ * Very simple getRequestIdentifier that sends a pre-determined message
+ * to the server and has a context. When this getRequestIdentifier is
restarted,
+ * the message is simply sent again.
+ */
+public class FixedMessageRequest<Ctx> extends Request {
+ private final GnunetMessage.Body message;
+ private final Ctx ctx;
+
+ public FixedMessageRequest(GnunetMessage.Body message, Ctx ctx) {
+ this.message = message;
+ this.ctx = ctx;
+ }
+
+ @Override
+ public Envelope assembleRequest() {
+ return new Envelope(message);
+ }
+
+ public Ctx getContext() {
+ return ctx;
+ }
+}
Added: gnunet-java/src/main/java/org/gnunet/requests/Request.java
===================================================================
--- gnunet-java/src/main/java/org/gnunet/requests/Request.java
(rev 0)
+++ gnunet-java/src/main/java/org/gnunet/requests/Request.java 2014-03-11
01:25:03 UTC (rev 32614)
@@ -0,0 +1,106 @@
+/*
+ This file is part of GNUnet.
+ (C) 2014 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+/*
+ This file is part of GNUnet.
+ (C) 2014 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+/*
+ This file is part of GNUnet.
+ (C) 2014 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+/*
+ This file is part of GNUnet.
+ (C) 2011, 2012 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+package org.gnunet.requests;
+
+import org.gnunet.mq.Envelope;
+import org.gnunet.util.Cancelable;
+
+/**
+ * A getRequestIdentifier that can be put in a getRequestIdentifier container.
+ */
+public abstract class Request implements Cancelable {
+ /**
+ * Create an envelope for executing the getRequestIdentifier.
+ *
+ * @return Envelope to be sent to the service with the
getRequestIdentifier message.
+ */
+ public abstract Envelope assembleRequest();
+
+ /**
+ * Implement cancellation logic for requests.
+ * Only called when the getRequestIdentifier has already been sent to the
service.
+ *
+ * By default, canceling a getRequestIdentifier throws an exception.
+ */
+ public void cancel() {
+ throw new AssertionError("getRequestIdentifier of type " +
this.getClass() + " can not be canceled (not implemented)");
+ }
+}
Added: gnunet-java/src/main/java/org/gnunet/requests/RequestIdentifier.java
===================================================================
--- gnunet-java/src/main/java/org/gnunet/requests/RequestIdentifier.java
(rev 0)
+++ gnunet-java/src/main/java/org/gnunet/requests/RequestIdentifier.java
2014-03-11 01:25:03 UTC (rev 32614)
@@ -0,0 +1,47 @@
+/*
+ This file is part of GNUnet.
+ (C) 2014 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+package org.gnunet.requests;
+
+import org.gnunet.util.Cancelable;
+import org.gnunet.util.RelativeTime;
+
+/**
+ * Identifies a queued getRequestIdentifier.
+ */
+public interface RequestIdentifier<T extends Request> extends Cancelable {
+
+ /**
+ * Cease being an active getRequestIdentifier. Effectively removes the
+ * getRequestIdentifier from its queue.
+ * In contrast to 'cancel', this does not invoke the the cancel
+ * action of the underlying request.
+ */
+ void retire();
+
+ void setTimeout(RelativeTime timeout, TimeoutHandler timeoutHandler);
+
+ T getRequest();
+
+ /**
+ * Actively cancel the request.
+ */
+ void cancel();
+}
Added:
gnunet-java/src/main/java/org/gnunet/requests/SimpleRequestIdentifier.java
===================================================================
--- gnunet-java/src/main/java/org/gnunet/requests/SimpleRequestIdentifier.java
(rev 0)
+++ gnunet-java/src/main/java/org/gnunet/requests/SimpleRequestIdentifier.java
2014-03-11 01:25:03 UTC (rev 32614)
@@ -0,0 +1,109 @@
+/*
+ This file is part of GNUnet.
+ (C) 2014 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+
+package org.gnunet.requests;
+
+
+import org.gnunet.mq.Envelope;
+import org.gnunet.mq.MessageQueue;
+import org.gnunet.mq.NotifySentHandler;
+import org.gnunet.util.Cancelable;
+import org.gnunet.util.RelativeTime;
+import org.gnunet.util.Scheduler;
+
+
+abstract class SimpleRequestIdentifier<T extends Request> implements
RequestIdentifier<T> {
+ private final T request;
+ /**
+ * Has the message been queued for sending?
+ */
+ boolean queued;
+ /**
+ * Cancel sending the message via the message queue.
+ */
+ private Cancelable sendCancel;
+ /**
+ * Has the request been irrevocably sent?
+ */
+ private boolean sent;
+ private boolean canceled;
+ private Scheduler.TaskIdentifier timeoutTask;
+
+ public SimpleRequestIdentifier(T request) {
+ this.request = request;
+ }
+
+ @Override
+ public void retire() {
+ if (null != timeoutTask) {
+ timeoutTask.cancel();
+ timeoutTask = null;
+ }
+ }
+
+ @Override
+ public void setTimeout(final RelativeTime timeout, final TimeoutHandler
timeoutHandler) {
+ if (null != timeoutTask)
+ throw new AssertionError("timeout already set");
+ timeoutTask = Scheduler.addDelayed(timeout, new Scheduler.Task() {
+ @Override
+ public void run(Scheduler.RunContext ctx) {
+ if (ctx.reasons.contains(Scheduler.Reason.SHUTDOWN))
+ return;
+ timeoutHandler.onTimeout();
+ }
+ });
+ }
+
+ @Override
+ public T getRequest() {
+ return request;
+ }
+
+ @Override
+ public void cancel() {
+ if (canceled) {
+ throw new AssertionError("canceled twice");
+ }
+ canceled = true;
+ if (sent) {
+ request.cancel();
+ } else if (null != sendCancel) {
+ sendCancel.cancel();
+ sendCancel = null;
+ }
+ retire();
+ }
+
+ public void send(MessageQueue mq) {
+ queued = true;
+ Envelope ev = request.assembleRequest();
+ ev.notifySent(new NotifySentHandler() {
+ @Override
+ public void onSent() {
+ sendCancel = null;
+ sent = true;
+ }
+ });
+ mq.send(ev);
+ sendCancel = ev;
+ }
+}
Added: gnunet-java/src/main/java/org/gnunet/requests/TimeoutHandler.java
===================================================================
--- gnunet-java/src/main/java/org/gnunet/requests/TimeoutHandler.java
(rev 0)
+++ gnunet-java/src/main/java/org/gnunet/requests/TimeoutHandler.java
2014-03-11 01:25:03 UTC (rev 32614)
@@ -0,0 +1,28 @@
+/*
+ This file is part of GNUnet.
+ (C) 2014 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+package org.gnunet.requests;
+
+/**
+ * Callback object for handling getRequestIdentifier timeouts.
+ */
+public interface TimeoutHandler {
+ void onTimeout();
+}
Added: gnunet-java/src/main/java/org/gnunet/statistics/StatisticsTool.java
===================================================================
--- gnunet-java/src/main/java/org/gnunet/statistics/StatisticsTool.java
(rev 0)
+++ gnunet-java/src/main/java/org/gnunet/statistics/StatisticsTool.java
2014-03-11 01:25:03 UTC (rev 32614)
@@ -0,0 +1,148 @@
+package org.gnunet.statistics;
+
+import org.gnunet.util.Program;
+import org.gnunet.util.RelativeTime;
+import org.gnunet.util.Scheduler;
+import org.gnunet.util.getopt.Argument;
+import org.gnunet.util.getopt.ArgumentAction;
+
+
+/**
+ * Entry point for and implementation of the gnunet-statistics-java tool.
+ */
+public class StatisticsTool extends Program {
+ @Argument(
+ shortname = "x",
+ longname = "set",
+ action = ArgumentAction.SET,
+ description = "watch a value")
+ boolean set;
+ @Argument(
+ shortname = "w",
+ longname = "watch",
+ action = ArgumentAction.SET,
+ description = "set a value")
+ boolean watch;
+ @Argument(
+ shortname = "n",
+ longname = "name",
+ action = ArgumentAction.STORE_STRING,
+ argumentName = "NAME",
+ description = "statistics name")
+ String statisticsName = "";
+ @Argument(
+ shortname = "s",
+ longname = "subsystem",
+ argumentName = "SUBSYS",
+ action = ArgumentAction.STORE_STRING,
+ description = "subsystem name")
+ String subsystemName = "";
+ @Argument(
+ shortname = "p",
+ longname = "persistent",
+ action = ArgumentAction.SET,
+ description = "set value persistently (used with -x)")
+ boolean persistent = false;
+ @Argument(
+ shortname = "r",
+ longname = "relative",
+ action = ArgumentAction.SET,
+ description = "set value relative to old value (used with -x)")
+ boolean relative = false;
+
+ /**
+ * The handle to the statistics service.
+ */
+ Statistics statistics;
+
+ /**
+ * Statistics command line utility entry point
+ *
+ * @param args command line arguments
+ */
+ public static void main(String[] args) {
+ StatisticsTool statisticsTool = new StatisticsTool();
+ int ret = statisticsTool.start(args);
+ System.exit(ret);
+ }
+
+
+ @Override
+ protected String makeHelpText() {
+ return "Get, set and watch GNUnet's statistics.";
+ }
+
+ public void run() {
+ if (set && watch) {
+ System.err.println("--watch/-w and --set/-s cannot be used
together");
+ return;
+ }
+
+ if (set) {
+ if (subsystemName.isEmpty() || statisticsName.isEmpty()) {
+ System.err.println("both subsystem and name must be given for
--set/-x");
+ return;
+ }
+ if (unprocessedArgs.length != 1) {
+ System.err.println("must specify exactly one value to set");
+ return;
+ }
+ long value;
+ try {
+ value = Long.parseLong(unprocessedArgs[0]);
+ } catch (NumberFormatException e) {
+ System.err.println("invalid value (not a long)");
+ return;
+ }
+ statistics = new Statistics(cfg);
+ if (relative)
+ statistics.update(subsystemName, statisticsName, value,
persistent);
+ else
+ statistics.set(subsystemName, statisticsName, value,
persistent);
+ statistics.destroy();
+ return;
+ }
+
+ if (unprocessedArgs.length != 0) {
+ System.err.println("watching or reading statistics does not take
any positional parameters");
+ return;
+ }
+
+ if (watch) {
+ if (subsystemName.isEmpty() || statisticsName.isEmpty()) {
+ System.err.println("both subsystem and name must be given for
--watch/-w");
+ return;
+ }
+ statistics = new Statistics(cfg);
+ statistics.watch(subsystemName, statisticsName,
+ new StatisticsWatcher() {
+ @Override
+ public void onReceive(String subsystem, String name,
long value) {
+ System.out.println(subsystem + "(" + name + ") = "
+ value);
+ }
+ }
+ );
+ } else {
+ statistics = new Statistics(cfg);
+ statistics.get(RelativeTime.fromSeconds(5), subsystemName,
statisticsName,
+ new StatisticsReceiver() {
+ @Override
+ public void onReceive(String subsystem, String name,
long value) {
+ System.out.println(subsystem + "(" + name + ") = "
+ value);
+ }
+
+ @Override
+ public void onTimeout() {
+ System.err.println("Statistics 'get' request timed
out.");
+ statistics.destroy();
+ }
+
+ @Override
+ public void onDone() {
+ statistics.destroy();
+ }
+ }
+ );
+ }
+ }
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r32614 - in gnunet-java/src/main/java/org/gnunet: requests statistics,
gnunet <=