Permalink
Browse files

Merge pull request #5 from miniway/master

FileMQ java implementation
  • Loading branch information...
2 parents d8417bb + 03de104 commit 491aed9828393c7a098dcf5c20c057c5c1ab5810 @hintjens hintjens committed Dec 13, 2012
Showing with 7,053 additions and 441 deletions.
  1. +0 −1 .gitignore
  2. +19 −0 java/README.md
  3. +44 −0 java/gen-filemq-jeromq.sh
  4. +88 −2 java/pom.xml
  5. +111 −0 java/src/main/java/org/filemq/FmqChunk.java
  6. +797 −0 java/src/main/java/org/filemq/FmqClient.java
  7. +435 −0 java/src/main/java/org/filemq/FmqConfig.java
  8. +361 −0 java/src/main/java/org/filemq/FmqDir.java
  9. +328 −0 java/src/main/java/org/filemq/FmqFile.java
  10. +75 −0 java/src/main/java/org/filemq/FmqHash.java
  11. +661 −250 java/src/main/java/org/filemq/FmqMsg.java
  12. +124 −0 java/src/main/java/org/filemq/FmqPatch.java
  13. +85 −0 java/src/main/java/org/filemq/FmqSasl.java
  14. +1,100 −0 java/src/main/java/org/filemq/FmqServer.java
  15. +20 −0 java/src/test/java/org/filemq/TestFmqChunk.java
  16. +51 −0 java/src/test/java/org/filemq/TestFmqClient.java
  17. +58 −0 java/src/test/java/org/filemq/TestFmqConfig.java
  18. +43 −0 java/src/test/java/org/filemq/TestFmqDir.java
  19. +81 −0 java/src/test/java/org/filemq/TestFmqFile.java
  20. +31 −0 java/src/test/java/org/filemq/TestFmqHash.java
  21. +16 −16 java/src/test/java/org/filemq/TestFmqMsg.java
  22. +29 −0 java/src/test/java/org/filemq/TestFmqSasl.java
  23. +139 −0 java/src/test/java/org/filemq/TestFmqServer.java
  24. +5 −0 java/src/test/resources/anonymous.cfg
  25. +16 −0 java/src/test/resources/client_test.cfg
  26. +26 −0 java/src/test/resources/server_test.cfg
  27. +630 −0 model/client_java.gsl
  28. +296 −171 model/codec_java.gsl
  29. +179 −1 model/fmq_client.xml
  30. +34 −0 model/fmq_client_sub.xml
  31. +189 −0 model/fmq_server.xml
  32. +128 −0 model/fmq_server_mount.xml
  33. +37 −0 model/fmq_server_selftest.xml
  34. +71 −0 model/fmq_server_sub.xml
  35. +3 −0 model/generate
  36. +742 −0 model/server_java.gsl
  37. +1 −0 src/.gitignore
View
@@ -24,7 +24,6 @@ src/stamp-h1
*.lo
*.la
*.lst
-filemq
track
core
fmq_selftest
View
@@ -0,0 +1,19 @@
+# FileMQ implementation in Java
+
+## How to use
+
+Add it to your Maven project's `pom.xml`:
+
+ <!-- for the FileMQ using jzmq -->
+ <dependency>
+ <groupId>org.filemq</groupId>
+ <artifactId>filemq</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ </dependency>
+
+ <!-- for the FileMQ using JeroMQ -->
+ <dependency>
+ <groupId>org.filemq</groupId>
+ <artifactId>filemq-jeromq</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ </dependency>
View
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+echo "Generate FileMQ codes use JeroMQ"
+
+TARGET="jeromq"
+JZMQ_VERSION="1.1.0-SNAPSHOT"
+JEROMQ_VERSION="0.2.0"
+
+if [ ! -d $TARGET ]; then
+ mkdir $TARGET
+fi
+
+if [ ! -d $TARGET/src/test/resources ]; then
+ mkdir -p $TARGET/src/test/resources
+fi
+
+cp -f src/test/resources/* $TARGET/src/test/resources
+
+sed -e '
+s/<artifactId>filemq<\/artifactId>/<artifactId>filemq-jeromq<\/artifactId>/
+s/<name>filemq<\/name>/<name>filemq-jeromq<\/name>/
+/<dependency>/,/<\/depencency>/ {
+ /<groupId>org.zeromq<\/groupId>/,/<version>${JZMQ_VERSION}<\/version>/ {
+ s/zeromq/jeromq/
+ s/jzmq/jeromq/
+ s/'"${JZMQ_VERSION}"'/'"${JEROMQ_VERSION}"'/
+ }
+}' pom.xml > $TARGET/pom.xml
+
+for j in `find ./src -name "*.java"`; do
+ BASE=${j:2}
+ FILE=${j##.*/}
+ BASE=$TARGET/${BASE%/$FILE}
+ mkdir -p $BASE
+ sed -e '
+ s/org.zeromq.ZMQ/org.jeromq.ZMQ/g
+ s/org.zeromq.ZContext/org.jeromq.ZContext/g
+ s/org.zeromq.ZFrame/org.jeromq.ZFrame/g
+ s/org.zeromq.ZMsg/org.jeromq.ZMsg/g
+ s/org.zeromq.ZThread/org.jeromq.ZThread/g
+ ' $j > $BASE/$FILE
+done
+
+echo "Done"
View
@@ -4,9 +4,24 @@
<groupId>org.filemq</groupId>
<artifactId>filemq</artifactId>
<packaging>jar</packaging>
- <version>1.0-SNAPSHOT</version>
+ <version>0.1.0-SNAPSHOT</version>
<name>filemq</name>
- <url>http://maven.apache.org</url>
+ <description>publish-subscribe file service based on 0MQ</description>
+ <url>https://github.com/zeromq/filemq</url>
+ <licenses>
+ <license>
+ <name>GNU General Lesser Public License (LGPL) version 3.0</name>
+ <url>http://www.gnu.org/licenses/lgpl-3.0.html</url>
+ </license>
+ </licenses>
+ <scm>
+ <url>git@github.com:zeromq/filemq.git</url>
+ <connection>scm:git:git@github.com:zeromq/filemq.git</connection>
+ <developerConnection>scm:git:git@github.com:zeromq/filemq.git</developerConnection>
+ </scm>
+ <developers>
+ <developer />
+ </developers>
<dependencies>
<dependency>
<groupId>org.zeromq</groupId>
@@ -20,4 +35,75 @@
<scope>test</scope>
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <version>2.2</version>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.8.1</version>
+ <executions>
+ <execution>
+ <id>attach-javadocs</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <profiles>
+ <profile>
+ <id>release-sign-artifacts</id>
+ <activation>
+ <property>
+ <name>performRelease</name>
+ <value>true</value>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-gpg-plugin</artifactId>
+ <version>1.1</version>
+ <executions>
+ <execution>
+ <id>sign-artifacts</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>sign</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+ <distributionManagement>
+ <repository>
+ <id>sonatype-nexus-releases</id>
+ <name>Nexus Release Repository</name>
+ <url>https://oss.sonatype.org/content/repositories/releases/</url>
+ </repository>
+ <snapshotRepository>
+ <id>sonatype-nexus-snapshots</id>
+ <name>Nexus Snapshot Repository</name>
+ <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
+ </snapshotRepository>
+ </distributionManagement>
</project>
@@ -0,0 +1,111 @@
+/* =========================================================================
+ fmq_chunk - work with memory chunks
+
+ -------------------------------------------------------------------------
+ Copyright (c) 1991-2012 iMatix Corporation -- http://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;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
+import java.util.Arrays;
+
+public class FmqChunk
+{
+ private ByteBuffer data; // Data part follows here
+
+ public FmqChunk (final byte[] content, int size)
+ {
+ this.data = ByteBuffer.allocate (size);
+
+ if (content != null) {
+ data.put (content);
+ }
+ }
+
+ public void destroy ()
+ {
+ }
+
+ // --------------------------------------------------------------------------
+ // Fill chunk data from user-supplied octet
+ // Returns actual size of chunk
+ public int fill (byte filler, int size)
+ {
+ if (size > data.capacity ())
+ size = data.capacity ();
+ data.clear ();
+ Arrays.fill (data.array (), 0, size, filler);
+ data.position (size);
+
+ return size;
+ }
+
+ // --------------------------------------------------------------------------
+ // Return chunk cur size
+ public int size ()
+ {
+ return data.position ();
+ }
+
+ // --------------------------------------------------------------------------
+ // Return chunk cur size
+ public int maxSize ()
+ {
+ return data.capacity ();
+ }
+
+
+ // --------------------------------------------------------------------------
+ // Return chunk data
+ public byte [] data ()
+ {
+ return data.array ();
+ }
+
+
+ // --------------------------------------------------------------------------
+ // Read chunk from an open file descriptor
+ public static FmqChunk read (FileChannel handle, int bytes)
+ {
+ FmqChunk chunk = new FmqChunk (null, bytes);
+ try {
+ handle.read (chunk.data);
+ } catch (IOException e) {
+ }
+
+ return chunk;
+ }
+ // --------------------------------------------------------------------------
+ // Write chunk to an open file descriptor
+ public boolean write (FileChannel handle)
+ {
+ try {
+ data.flip ();
+ handle.write (data);
+ return !data.hasRemaining ();
+ } catch (IOException e) {
+ return false;
+ }
+ }
+
+
+}
Oops, something went wrong.

0 comments on commit 491aed9

Please sign in to comment.