Permalink
Browse files

Merge pull request #6 from miniway/master

FileMQ command-line service
  • Loading branch information...
2 parents 491aed9 + 0a059b4 commit bdf3d2d9905ecf07f561e3da8b391a524840f9be @hintjens hintjens committed Dec 13, 2012
@@ -0,0 +1,67 @@
+/* =========================================================================
+ filemq - FileMQ command-line service
+
+ This version works just like the track command. I'll improve filemq to
+ be a more general service over time.
+
+ -------------------------------------------------------------------------
+ Copyright (c) 1991-2012 iMatix Corporation <www.imatix.com>
+ Copyright other contributors as noted in the AUTHORS file.
+
+ This file is part of FILEMQ, see http://filemq.org.
+
+ This is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation; either version 3 of the License, or (at your
+ option) any later version.
+
+ This software is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTA-
+ BILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ =========================================================================
+*/
+
+package org.filemq;
+
+public class Filemq
+{
+ private static final String PRODUCT = "FileMQ service/1.0a1";
+ private static final String COPYRIGHT = "Copyright (c) 2012 iMatix Corporation";
+ private static final String NOWARRANTY =
+ "This is free software; see the source for copying conditions. There is NO\n"
+ + "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" ;
+
+ public static void main (String[] args) throws Exception
+ {
+ System.out.println (PRODUCT);
+ System.out.println (COPYRIGHT);
+ System.out.println (NOWARRANTY);
+
+ if (args.length < 2) {
+ System.out.println ("usage: filemq publish-from subscribe-into");
+ return;
+ }
+ FmqServer server = new FmqServer ();
+ server.configure ("src/test/resources/anonymous.cfg");
+ server.publish (args [0], "/");
+ server.setAnonymous (1);
+ server.bind ("tcp://*:5670");
+
+ FmqClient client = new FmqClient ();
+ client.connect ("tcp://localhost:5670");
+ client.setInbox (args [1]);
+ client.subscribe ("/");
+
+ while (!Thread.currentThread ().isInterrupted ())
+ Thread.sleep (1000);
+ System.out.println ("interrupted");
+
+ server.destroy ();
+ client.destroy ();
+ }
+
+}
@@ -327,8 +327,8 @@ public void dump (int indent)
// Old file was modified or replaced
// Since we don't check file contents, treat as created
// Could better do SHA check on file here
- if (new_.time () != older.time ()
- || new_.size () != older.size ())
+ if (new_.time () != old.time ()
+ || new_.size () != old.size ())
patches.add (new FmqPatch (newer.path, new_, FmqPatch.OP.patch_create, alias));
}
else
@@ -66,8 +66,22 @@ public FmqFile (File path)
in = new BufferedReader (new FileReader (path));
String buffer = in.readLine ();
link = buffer.trim ();
- this.path = new File (link);
- name = name.substring (0, name.length () -3);
+ if (link == null) {
+ // There could be a race condition or corrupted, try once more
+ in.close ();
+ in = new BufferedReader (new FileReader (path));
+ buffer = in.readLine ();
+ link = buffer.trim ();
+ }
+ if (link == null) {
+ // Guess it is corrupted
+ in.close ();
+ in = null;
+ path.delete ();
+ } else {
+ this.path = new File (link);
+ name = name.substring (0, name.length () -3);
+ }
} catch (IOException e) {
} finally {
if (in != null)
@@ -718,6 +718,7 @@ private void getNextPatchForClient (Client client)
// No reliability in this version, assume patch delivered safely
client.patch.destroy ();
+ client.patch = null;
}
else
if (client.patch.op () == FmqPatch.OP.patch_create) {
View
@@ -414,6 +414,7 @@ if (client.patch.op () == FmqPatch.OP.patch_delete) {
// No reliability in this version, assume patch delivered safely
client.patch.destroy ();
+ client.patch = null;
}
else
if (client.patch.op () == FmqPatch.OP.patch_create) {

0 comments on commit bdf3d2d

Please sign in to comment.