21 | * The {@link de.zib.chordsharp.ChordSharp} class provides simple access methods for the most common use cases. 22 | * It provides static methods for reading, writing, publishing, subscribing and getting a list of subscribers with 23 | * normal Java types. 24 | *
25 | * 26 | *
28 | * try {
29 | * String value = ChordSharp.readString("key");
30 | * } catch (ConnectionException e) {
31 | * System.err.println("read failed: " + e.getMessage());
32 | * } catch (TimeoutException e) {
33 | * System.err.println("read failed with timeout: " + e.getMessage());
34 | * } catch (UnknownException e) {
35 | * System.err.println("read failed with unknown: " + e.getMessage());
36 | * } catch (NotFoundException e) {
37 | * System.err.println("read failed with not found: " + e.getMessage());
38 | * }
39 | *
40 | *
41 | * See the {@link de.zib.chordsharp.ChordSharp} class documentation for more details.
42 | * 43 | *45 | * The {@link de.zib.chordsharp.ChordSharpConnection} class provides more sophisticated access methods: 46 | * It provides methods for reading, writing, publishing, subscribing and getting a list of subscribers with 47 | * normal Java types and OtpErlang-types. There are static methods which operate on a single static connection to the chordsharp ring and there are also non-static methods which use instance-specific connections. 48 | *
49 | * 50 | *
52 | * try {
53 | * ChordSharpConnection cs = new ChordSharpConnection();
54 | * String value = cs.singleReadString("key");
55 | * } catch (ConnectionException e) {
56 | * System.err.println("read failed: " + e.getMessage());
57 | * } catch (TimeoutException e) {
58 | * System.err.println("read failed with timeout: " + e.getMessage());
59 | * } catch (UnknownException e) {
60 | * System.err.println("read failed with unknown: " + e.getMessage());
61 | * } catch (NotFoundException e) {
62 | * System.err.println("read failed with not found: " + e.getMessage());
63 | * }
64 | *
65 | *
66 | * See the {@link de.zib.chordsharp.ChordSharpConnection} class documentation for more details.
67 | * 68 | *70 | * The {@link de.zib.chordsharp.Transaction} class provides means to realise a chordsharp transaction 71 | * from Java. After starting a transaction, there are methods to read and write values. The transaction 72 | * can then be committed or aborted. 73 | *
74 | * 75 | *
77 | * try {
78 | * Transaction transaction = new Transaction();
79 | * transaction.start();
80 | * String value = transaction.readString("key");
81 | * transaction.write("key", "value");
82 | * transaction.commit();
83 | * } catch (ConnectionException e) {
84 | * System.err.println("read failed: " + e.getMessage());
85 | * } catch (TimeoutException e) {
86 | * System.err.println("read failed with timeout: " + e.getMessage());
87 | * } catch (UnknownException e) {
88 | * System.err.println("read failed with unknown: " + e.getMessage());
89 | * } catch (NotFoundException e) {
90 | * System.err.println("read failed with not found: " + e.getMessage());
91 | * } catch (TransactionNotFinishedException e) {
92 | * System.out.println("failed: " + e.getMessage());
93 | * return;
94 | * }
95 | *
96 | *
97 | * See the {@link de.zib.chordsharp.Transaction} class documentation for more details.
98 | */ 99 | package de.zib.chordsharp; 100 | 101 | -------------------------------------------------------------------------------- /src/de/zib/scalaris/ConnectionException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2007-2008 Konrad-Zuse-Zentrum für Informationstechnik Berlin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package de.zib.scalaris; 17 | 18 | import com.ericsson.otp.erlang.OtpErlangException; 19 | import com.ericsson.otp.erlang.OtpErlangObject; 20 | 21 | /** 22 | * Exception that is thrown when a read operation on a scalaris ring fails 23 | * because the connection is not active or a communication error occurred or an 24 | * exit signal was received or the remote node sent a message containing an 25 | * invalid cookie. 26 | * 27 | * @author Nico Kruber, kruber@zib.de 28 | * @version 2.2 29 | * @since 2.0 30 | */ 31 | public class ConnectionException extends OtpErlangException { 32 | /** 33 | * class version for serialisation 34 | */ 35 | private static final long serialVersionUID = 1L; 36 | 37 | /** 38 | * Creates the exception with no message. 39 | */ 40 | public ConnectionException() { 41 | } 42 | 43 | /** 44 | * Creates the exception with the given message. 45 | * 46 | * @param msg 47 | * message of the exception 48 | */ 49 | public ConnectionException(String msg) { 50 | super(msg); 51 | } 52 | 53 | /** 54 | * Creates an exception taking the message of the given throwable. 55 | * 56 | * @param e the exception to "re-throw" 57 | */ 58 | public ConnectionException(Throwable e) { 59 | super(e.getMessage()); 60 | } 61 | 62 | /** 63 | * Creates an exception including the message of the given erlang object. 64 | * 65 | * @param erlValue 66 | * the erlang message to include 67 | * 68 | * @since 2.2 69 | */ 70 | public ConnectionException(OtpErlangObject erlValue) { 71 | super("Erlang message: " + erlValue.toString()); 72 | } 73 | 74 | /** 75 | * Creates an exception taking the message of the given throwable. 76 | * 77 | * @param e 78 | * the exception to "re-throw" 79 | * @param erlValue 80 | * the string representation of this erlang value is included 81 | * into the message 82 | * 83 | * @since 2.2 84 | */ 85 | public ConnectionException(Throwable e, OtpErlangObject erlValue) { 86 | super(e.getMessage() + ",\n Erlang message: " + erlValue.toString()); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/de/zib/scalaris/CustomOtpObject.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2007-2008 Konrad-Zuse-Zentrum für Informationstechnik Berlin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package de.zib.scalaris; 17 | 18 | import com.ericsson.otp.erlang.OtpErlangObject; 19 | 20 | /** 21 | * Wrapper class that allows to write custom objects to scalaris. 22 | * 23 | * Provides methods to convert a given Java type to another erlang type. 24 | * 25 | * @param31 | * Uses {@link OtpErlangBinary} objects that store the array of bytes a 32 | * {@link String} consists of and writes this binary to scalaris wrapped into a 33 | * {@link OtpErlangTuple}. Trying to read strings will convert a returned 34 | * {@link OtpErlangBinary} to a {@link String} or return the value of a 35 | * {@link OtpErlangString} result. 36 | *
37 | * 38 | *
39 | * Run with java -cp scalaris-examples.jar de.zib.scalaris.examples.FastStringBenchmark
40 | *
read
method of the
30 | * {@link Transaction} class.
31 | *
32 | * @author Nico Kruber, kruber@zib.de
33 | * @version 2.0
34 | * @since 2.0
35 | */
36 | public class TransactionReadExample {
37 | /**
38 | * Reads all keys given on the command line (given as "key1 key2 ...") with
39 | * the {@link Transaction#read(String)} and
40 | * {@link Transaction#readObject(OtpErlangString)} methods in a single
41 | * transaction."key1"
, "key2"
,
43 | * "key3"
are used.
44 | *
45 | * @param args
46 | * command line arguments (optional keys to look up)
47 | */
48 | public static void main(String[] args) {
49 | String[] keys;
50 | String value;
51 |
52 | if (args.length == 0) {
53 | keys = new String[] { "key1", "key2", "key3" };
54 | } else {
55 | keys = args;
56 | }
57 |
58 | OtpErlangString[] otpKeys_temp = new OtpErlangString[keys.length];
59 | for (int i = 0; i < keys.length; ++i) {
60 | otpKeys_temp[i] = new OtpErlangString(keys[i]);
61 | }
62 | OtpErlangList otpKeys = (new OtpErlangList(otpKeys_temp));
63 | OtpErlangString otpValue;
64 |
65 | System.out.println("Reading values with the class `Transaction`:");
66 |
67 | System.out.print(" Initialising Transaction object... ");
68 | try {
69 | Transaction transaction = new Transaction();
70 | System.out.println("done");
71 |
72 | System.out.print(" Starting transaction... ");
73 | transaction.start();
74 | System.out.println("done");
75 |
76 | System.out
77 | .println(" `OtpErlangObject readObject(OtpErlangString)`...");
78 | for (int i = 0; i < otpKeys.arity(); ++i) {
79 | OtpErlangString otpKey = (OtpErlangString) otpKeys.elementAt(i);
80 | try {
81 | otpValue = (OtpErlangString) transaction.readObject(otpKey);
82 | System.out.println(" read(" + otpKey.stringValue()
83 | + ") == " + otpValue.stringValue());
84 | } catch (ConnectionException e) {
85 | System.out.println(" read(" + otpKey.stringValue()
86 | + ") failed: " + e.getMessage());
87 | } catch (TimeoutException e) {
88 | System.out.println(" read(" + otpKey.stringValue()
89 | + ") failed with timeout: " + e.getMessage());
90 | } catch (UnknownException e) {
91 | System.out.println(" read(" + otpKey.stringValue()
92 | + ") failed with unknown: " + e.getMessage());
93 | } catch (NotFoundException e) {
94 | System.out.println(" read(" + otpKey.stringValue()
95 | + ") failed with not found: " + e.getMessage());
96 | } catch (ClassCastException e) {
97 | System.out.println(" read(" + otpKey.stringValue()
98 | + ") failed with unknown return type: " + e.getMessage());
99 | }
100 | }
101 |
102 | System.out.println(" `String read(String)`...");
103 | for (int i = 0; i < keys.length; ++i) {
104 | String key = keys[i];
105 | try {
106 | value = transaction.read(key);
107 | System.out.println(" read(" + key + ") == " + value);
108 | } catch (ConnectionException e) {
109 | System.out.println(" read(" + key + ") failed: "
110 | + e.getMessage());
111 | } catch (TimeoutException e) {
112 | System.out.println(" read(" + key
113 | + ") failed with timeout: " + e.getMessage());
114 | } catch (UnknownException e) {
115 | System.out.println(" read(" + key
116 | + ") failed with unknown: " + e.getMessage());
117 | } catch (NotFoundException e) {
118 | System.out.println(" read(" + key
119 | + ") failed with not found: " + e.getMessage());
120 | }
121 | }
122 |
123 | System.out.print(" Committing transaction... ");
124 | transaction.commit();
125 | System.out.println("done");
126 | } catch (ConnectionException e) {
127 | System.out.println("failed: " + e.getMessage());
128 | return;
129 | } catch (TransactionNotFinishedException e) {
130 | System.out.println("failed: " + e.getMessage());
131 | return;
132 | } catch (UnknownException e) {
133 | System.out.println("failed: " + e.getMessage());
134 | return;
135 | }
136 | }
137 |
138 | }
139 |
--------------------------------------------------------------------------------
/src/de/zib/scalaris/examples/TransactionWriteExample.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2007-2008 Konrad-Zuse-Zentrum für Informationstechnik Berlin
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package de.zib.scalaris.examples;
17 |
18 | import com.ericsson.otp.erlang.OtpErlangList;
19 | import com.ericsson.otp.erlang.OtpErlangObject;
20 | import com.ericsson.otp.erlang.OtpErlangString;
21 |
22 | import de.zib.scalaris.ConnectionException;
23 | import de.zib.scalaris.TimeoutException;
24 | import de.zib.scalaris.Transaction;
25 | import de.zib.scalaris.TransactionNotFinishedException;
26 | import de.zib.scalaris.UnknownException;
27 |
28 | /**
29 | * Provides an example for using the write
method of the
30 | * {@link Transaction} class.
31 | *
32 | * @author Nico Kruber, kruber@zib.de
33 | * @version 2.0
34 | * @since 2.0
35 | */
36 | public class TransactionWriteExample {
37 | /**
38 | * Writes all key/value pairs given on the command line (given as "key1
39 | * value1 key2 value2 ...") with the
40 | * {@link Transaction#write(String, String)} and
41 | * {@link Transaction#writeObject(OtpErlangString, OtpErlangObject)} methods
42 | * in a single transaction.(key1, value1)
,
44 | * (key2, value2)
and (key3, value3)
are used.
45 | *
46 | * @param args
47 | * command line arguments (optional key/value pairs to store)
48 | */
49 | public static void main(String[] args) {
50 | String[] keys;
51 | String[] values;
52 |
53 | if (args.length < 2 || args.length % 2 != 0) {
54 | keys = new String[] { "key1", "key2", "key3" };
55 | values = new String[] { "value1", "value2", "value3" };
56 | } else {
57 | keys = new String[args.length / 2];
58 | values = new String[args.length / 2];
59 | for (int i = 0; i < args.length;) {
60 | keys[i] = args[i++];
61 | values[i] = args[i++];
62 | }
63 | }
64 |
65 | OtpErlangString[] otpKeys_temp = new OtpErlangString[keys.length];
66 | for (int i = 0; i < keys.length; ++i) {
67 | otpKeys_temp[i] = new OtpErlangString(keys[i]);
68 | }
69 | OtpErlangList otpKeys = (new OtpErlangList(otpKeys_temp));
70 |
71 | OtpErlangString[] otpValues_temp = new OtpErlangString[values.length];
72 | for (int i = 0; i < values.length; ++i) {
73 | otpValues_temp[i] = new OtpErlangString(values[i]);
74 | }
75 | OtpErlangList otpValues = (new OtpErlangList(otpValues_temp));
76 |
77 | System.out.println("Writing values with the class `Transaction`:");
78 |
79 | System.out.print(" Initialising Transaction object... ");
80 | try {
81 | Transaction transaction = new Transaction();
82 | System.out.println("done");
83 |
84 | System.out.print(" Starting transaction... ");
85 | transaction.start();
86 | System.out.println("done");
87 |
88 | System.out
89 | .println(" `writeObject(OtpErlangString, OtpErlangObject)`...");
90 | for (int i = 0; i < otpKeys.arity(); ++i) {
91 | OtpErlangString otpKey = (OtpErlangString) otpKeys.elementAt(i);
92 | OtpErlangString otpValue = (OtpErlangString) otpValues
93 | .elementAt(i);
94 | try {
95 | transaction.writeObject(otpKey, otpValue);
96 | System.out.println(" write(" + otpKey.stringValue()
97 | + ", " + otpValue.stringValue() + ") succeeded");
98 | } catch (ConnectionException e) {
99 | System.out.println(" write(" + otpKey.stringValue()
100 | + ", " + otpValue.stringValue() + ") failed: "
101 | + e.getMessage());
102 | } catch (TimeoutException e) {
103 | System.out.println(" write(" + otpKey.stringValue()
104 | + ", " + otpValue.stringValue()
105 | + ") failed with timeout: " + e.getMessage());
106 | } catch (UnknownException e) {
107 | System.out.println(" write(" + otpKey.stringValue()
108 | + ", " + otpValue.stringValue()
109 | + ") failed with unknown: " + e.getMessage());
110 | }
111 | }
112 |
113 | System.out.println(" `write(String, String)`...");
114 | for (int i = 0; i < keys.length; ++i) {
115 | String key = keys[i];
116 | String value = values[i];
117 | try {
118 | transaction.write(key, value);
119 | System.out.println(" write(" + key + ", " + value
120 | + ") succeeded");
121 | } catch (ConnectionException e) {
122 | System.out.println(" write(" + key + ", " + value
123 | + ") failed: " + e.getMessage());
124 | } catch (TimeoutException e) {
125 | System.out.println(" write(" + key + ", " + value
126 | + ") failed with timeout: " + e.getMessage());
127 | } catch (UnknownException e) {
128 | System.out.println(" write(" + key + ", " + value
129 | + ") failed with unknown: " + e.getMessage());
130 | }
131 | }
132 |
133 | System.out.print(" Committing transaction... ");
134 | transaction.commit();
135 | System.out.println("done");
136 | } catch (ConnectionException e) {
137 | System.out.println("failed: " + e.getMessage());
138 | return;
139 | } catch (TransactionNotFinishedException e) {
140 | System.out.println("failed: " + e.getMessage());
141 | return;
142 | } catch (UnknownException e) {
143 | System.out.println("failed: " + e.getMessage());
144 | return;
145 | }
146 | }
147 |
148 | }
149 |
--------------------------------------------------------------------------------
/src/de/zib/scalaris/examples/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2007-2008 Konrad-Zuse-Zentrum für Informationstechnik Berlin
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /**
17 | * This package contains examples how to use the classes of the {@link de.zib.scalaris} package.
18 | *
19 | * @author Nico Kruber, kruber@zib.de
20 | * @version 2.0
21 | * @since 2.0
22 | */
23 | package de.zib.scalaris.examples;
24 |
25 |
--------------------------------------------------------------------------------
/src/de/zib/scalaris/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2007-2008 Konrad-Zuse-Zentrum für Informationstechnik Berlin
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /**
17 | * This package contains means to communicate with the erlang scalaris ring from Java.
18 | *
19 | * 21 | * The {@link de.zib.scalaris.Scalaris} class provides methods for reading and writing values, 22 | * publishing topics, subscribing to urls and getting a list of subscribers with both erlang 23 | * objects ({@link com.ericsson.otp.erlang.OtpErlangObject}) and Java {@link java.lang.String} 24 | * objects. 25 | *
26 | * 27 | *
29 | *
30 | * try {
31 | * Scalaris sc = new Scalaris();
32 | * String value = sc.read("key");
33 | * } catch (ConnectionException e) {
34 | * System.err.println("read failed: " + e.getMessage());
35 | * } catch (TimeoutException e) {
36 | * System.err.println("read failed with timeout: " + e.getMessage());
37 | * } catch (UnknownException e) {
38 | * System.err.println("read failed with unknown: " + e.getMessage());
39 | * } catch (NotFoundException e) {
40 | * System.err.println("read failed with not found: " + e.getMessage());
41 | * }
42 | *
43 | *
44 | *
45 | * See the {@link de.zib.scalaris.Scalaris} class documentation for more details.
46 | * 47 | *49 | * The {@link de.zib.scalaris.Transaction} class provides means to realise a scalaris transaction 50 | * from Java. After starting a transaction, there are methods to read and write values with both 51 | * erlang objects ({@link com.ericsson.otp.erlang.OtpErlangObject}) and Java {@link java.lang.String} 52 | * objects. The transaction can then be committed, aborted or reset. 53 | *
54 | * 55 | *
57 | *
58 | * try {
59 | * Transaction transaction = new Transaction();
60 | * transaction.start();
61 | * String value = transaction.read("key");
62 | * transaction.write("key", "value");
63 | * transaction.commit();
64 | * } catch (ConnectionException e) {
65 | * System.err.println("read failed: " + e.getMessage());
66 | * } catch (TimeoutException e) {
67 | * System.err.println("read failed with timeout: " + e.getMessage());
68 | * } catch (UnknownException e) {
69 | * System.err.println("read failed with unknown: " + e.getMessage());
70 | * } catch (NotFoundException e) {
71 | * System.err.println("read failed with not found: " + e.getMessage());
72 | * } catch (TransactionNotFinishedException e) {
73 | * System.out.println("failed: " + e.getMessage());
74 | * return;
75 | * }
76 | *
77 | *
78 | *
79 | * See the {@link de.zib.scalaris.Transaction} class documentation for more details.
80 | * 81 | * @author Nico Kruber, kruber@zib.de 82 | * @version 2.0 83 | * @since 2.0 84 | */ 85 | package de.zib.scalaris; 86 | -------------------------------------------------------------------------------- /src/de/zib/tools/PropertyLoader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2007-2008 Konrad-Zuse-Zentrum für Informationstechnik Berlin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package de.zib.tools; 17 | 18 | import java.io.FileInputStream; 19 | import java.io.FileNotFoundException; 20 | import java.io.IOException; 21 | import java.net.URL; 22 | import java.util.Properties; 23 | 24 | /** 25 | * Provides methods to load property files with default look up mechanisms. 26 | * 27 | *
29 | * Properties properties = new Properties();
30 | * PropertyLoader.loadProperties(properties, "PropertiesFile.properties"); // {@link #loadProperties(java.util.Properties, String)}
31 | *
32 | *
33 | * @author Nico Kruber, kruber@zib.de
34 | * @version 1.0
35 | */
36 | public class PropertyLoader {
37 | /**
38 | * Tries to locate the file given by {@code filename} and loads it into the
39 | * given properties parameter.
40 | *
41 | * @param properties
42 | * the {@link Properties} object to load the file into
43 | * @param filename
44 | * the filename of the file containing the properties
45 | *
46 | * @return indicates whether the properties have been successfully loaded
47 | */
48 | public static boolean loadProperties(Properties properties, String filename) {
49 | FileInputStream fis = null;
50 | try {
51 | ClassLoader classLoader = PropertyLoader.class
52 | .getClassLoader();
53 | if (classLoader != null) {
54 | URL url = classLoader.getResource(filename);
55 | if (url != null) {
56 | String path = url.getFile();
57 | fis = new FileInputStream(path);
58 | properties.load(fis);
59 | fis.close();
60 | return true;
61 | }
62 | }
63 | // try default path if the file was not found
64 | fis = new FileInputStream(filename);
65 | properties.load(fis);
66 | fis.close();
67 | return true;
68 | } catch (FileNotFoundException e) {
69 | // TODO add logging
70 | // e.printStackTrace();
71 | } catch (IOException e) {
72 | // TODO add logging
73 | // e.printStackTrace();
74 | } finally {
75 | if (fis != null) {
76 | try {
77 | fis.close();
78 | } catch (IOException e) {
79 | }
80 | }
81 | }
82 | return false;
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/de/zib/tools/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2007-2008 Konrad-Zuse-Zentrum für Informationstechnik Berlin
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | /**
17 | * This package contains some generic tools useful for most implementations.
18 | *
19 | * 21 | * The {@link de.zib.tools.PropertyLoader} class provides methods to load property 22 | * files with look-up mechanisms to find a file given only by its name. 23 | *
24 | * 25 | *
27 | * Properties properties = new Properties();
28 | * PropertyLoader.loadProperties(properties, "PropertiesFile.properties");
29 | *
30 | *
31 | * See the {@link de.zib.tools.PropertyLoader} class documentation for more details.
32 | */ 33 | package de.zib.tools; 34 | -------------------------------------------------------------------------------- /src/implementations/cassandraDB.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2011 Thibault Dory 3 | * Licensed under the GPL Version 3 license 4 | */ 5 | 6 | /** 7 | * Use the following commands with cassandra-cli to create the needed keyspace and column families 8 | * 9 | * create keyspace Keyspace1 with replication_factor = 3 and placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy'; 10 | * use Keyspace1; 11 | * create column family Standard1 with column_type = 'Standard' and comparator = 'UTF8Type'; 12 | * create column family output_phase1 with column_type = 'Standard' and comparator = 'UTF8Type'; 13 | * create column family output_phase2 with column_type = 'Standard' and comparator = 'UTF8Type'; 14 | */ 15 | 16 | package implementations; 17 | 18 | import java.util.List; 19 | 20 | import org.apache.cassandra.thrift.Column; 21 | import org.apache.cassandra.thrift.ConsistencyLevel; 22 | import org.scale7.cassandra.pelops.Cluster; 23 | import org.scale7.cassandra.pelops.Mutator; 24 | import org.scale7.cassandra.pelops.Pelops; 25 | import org.scale7.cassandra.pelops.Selector; 26 | 27 | import cassandra_mapreduce.MapReduceCassandraDB; 28 | 29 | import core.BenchDB; 30 | 31 | 32 | public class cassandraDB extends BenchDB{ 33 | final String UTF8 = "UTF8"; 34 | String pool = "pool"; 35 | String keyspace = "Keyspace1"; 36 | String colFamily = "Standard1"; 37 | 38 | @Override 39 | public int connectNode(String nodeAddress) { 40 | int ret; 41 | try{ 42 | Cluster cluster = new Cluster(nodeAddress, 9160); 43 | Pelops.addPool(pool, cluster, keyspace); 44 | ret = 1; 45 | }catch(Exception e){ 46 | ret = 0; 47 | } 48 | return ret; 49 | } 50 | 51 | @Override 52 | public String readDB(String ID) { 53 | try { 54 | Selector selector = Pelops.createSelector(pool); 55 | List{ 43 | * Method: "POST" (for example), 44 | * "Request-URI": "/" (for example), 45 | * "HTTP-Version": "HTTP/1.1" (for example) 46 | * }47 | * A response header will contain 48 | *
{ 49 | * "HTTP-Version": "HTTP/1.1" (for example), 50 | * "Status-Code": "200" (for example), 51 | * "Reason-Phrase": "OK" (for example) 52 | * }53 | * In addition, the other parameters in the header will be captured, using 54 | * the HTTP field names as JSON names, so that
55 | * Date: Sun, 26 May 2002 18:06:04 GMT 56 | * Cookie: Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s 57 | * Cache-Control: no-cache58 | * become 59 | *
{... 60 | * Date: "Sun, 26 May 2002 18:06:04 GMT", 61 | * Cookie: "Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s", 62 | * "Cache-Control": "no-cache", 63 | * ...}64 | * It does no further checking or conversion. It does not parse dates. 65 | * It does not do '%' transforms on URLs. 66 | * @param string An HTTP header string. 67 | * @return A JSONObject containing the elements and attributes 68 | * of the XML string. 69 | * @throws JSONException 70 | */ 71 | public static JSONObject toJSONObject(String string) throws JSONException { 72 | JSONObject o = new JSONObject(); 73 | HTTPTokener x = new HTTPTokener(string); 74 | String t; 75 | 76 | t = x.nextToken(); 77 | if (t.toUpperCase().startsWith("HTTP")) { 78 | 79 | // Response 80 | 81 | o.put("HTTP-Version", t); 82 | o.put("Status-Code", x.nextToken()); 83 | o.put("Reason-Phrase", x.nextTo('\0')); 84 | x.next(); 85 | 86 | } else { 87 | 88 | // Request 89 | 90 | o.put("Method", t); 91 | o.put("Request-URI", x.nextToken()); 92 | o.put("HTTP-Version", x.nextToken()); 93 | } 94 | 95 | // Fields 96 | 97 | while (x.more()) { 98 | String name = x.nextTo(':'); 99 | x.next(':'); 100 | o.put(name, x.nextTo('\0')); 101 | x.next(); 102 | } 103 | return o; 104 | } 105 | 106 | 107 | /** 108 | * Convert a JSONObject into an HTTP header. A request header must contain 109 | *
{ 110 | * Method: "POST" (for example), 111 | * "Request-URI": "/" (for example), 112 | * "HTTP-Version": "HTTP/1.1" (for example) 113 | * }114 | * A response header must contain 115 | *
{ 116 | * "HTTP-Version": "HTTP/1.1" (for example), 117 | * "Status-Code": "200" (for example), 118 | * "Reason-Phrase": "OK" (for example) 119 | * }120 | * Any other members of the JSONObject will be output as HTTP fields. 121 | * The result will end with two CRLF pairs. 122 | * @param o A JSONObject 123 | * @return An HTTP header string. 124 | * @throws JSONException if the object does not contain enough 125 | * information. 126 | */ 127 | public static String toString(JSONObject o) throws JSONException { 128 | Iterator keys = o.keys(); 129 | String s; 130 | StringBuffer sb = new StringBuffer(); 131 | if (o.has("Status-Code") && o.has("Reason-Phrase")) { 132 | sb.append(o.getString("HTTP-Version")); 133 | sb.append(' '); 134 | sb.append(o.getString("Status-Code")); 135 | sb.append(' '); 136 | sb.append(o.getString("Reason-Phrase")); 137 | } else if (o.has("Method") && o.has("Request-URI")) { 138 | sb.append(o.getString("Method")); 139 | sb.append(' '); 140 | sb.append('"'); 141 | sb.append(o.getString("Request-URI")); 142 | sb.append('"'); 143 | sb.append(' '); 144 | sb.append(o.getString("HTTP-Version")); 145 | } else { 146 | throw new JSONException("Not enough material for an HTTP header."); 147 | } 148 | sb.append(CRLF); 149 | while (keys.hasNext()) { 150 | s = keys.next().toString(); 151 | if (!s.equals("HTTP-Version") && !s.equals("Status-Code") && 152 | !s.equals("Reason-Phrase") && !s.equals("Method") && 153 | !s.equals("Request-URI") && !o.isNull(s)) { 154 | sb.append(s); 155 | sb.append(": "); 156 | sb.append(o.getString(s)); 157 | sb.append(CRLF); 158 | } 159 | } 160 | sb.append(CRLF); 161 | return sb.toString(); 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /src/org/json/HTTPTokener.java: -------------------------------------------------------------------------------- 1 | package org.json; 2 | 3 | /* 4 | Copyright (c) 2002 JSON.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | The Software shall be used for Good, not Evil. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | */ 26 | 27 | /** 28 | * The HTTPTokener extends the JSONTokener to provide additional methods 29 | * for the parsing of HTTP headers. 30 | * @author JSON.org 31 | * @version 2008-09-18 32 | */ 33 | public class HTTPTokener extends JSONTokener { 34 | 35 | /** 36 | * Construct an HTTPTokener from a string. 37 | * @param s A source string. 38 | */ 39 | public HTTPTokener(String s) { 40 | super(s); 41 | } 42 | 43 | 44 | /** 45 | * Get the next token or string. This is used in parsing HTTP headers. 46 | * @throws JSONException 47 | * @return A String. 48 | */ 49 | public String nextToken() throws JSONException { 50 | char c; 51 | char q; 52 | StringBuffer sb = new StringBuffer(); 53 | do { 54 | c = next(); 55 | } while (Character.isWhitespace(c)); 56 | if (c == '"' || c == '\'') { 57 | q = c; 58 | for (;;) { 59 | c = next(); 60 | if (c < ' ') { 61 | throw syntaxError("Unterminated string."); 62 | } 63 | if (c == q) { 64 | return sb.toString(); 65 | } 66 | sb.append(c); 67 | } 68 | } 69 | for (;;) { 70 | if (c == 0 || Character.isWhitespace(c)) { 71 | return sb.toString(); 72 | } 73 | sb.append(c); 74 | c = next(); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/org/json/JSONException.java: -------------------------------------------------------------------------------- 1 | package org.json; 2 | 3 | /** 4 | * The JSONException is thrown by the JSON.org classes when things are amiss. 5 | * @author JSON.org 6 | * @version 2008-09-18 7 | */ 8 | public class JSONException extends Exception { 9 | /** 10 | * 11 | */ 12 | private static final long serialVersionUID = 0; 13 | private Throwable cause; 14 | 15 | /** 16 | * Constructs a JSONException with an explanatory message. 17 | * @param message Detail about the reason for the exception. 18 | */ 19 | public JSONException(String message) { 20 | super(message); 21 | } 22 | 23 | public JSONException(Throwable t) { 24 | super(t.getMessage()); 25 | this.cause = t; 26 | } 27 | 28 | public Throwable getCause() { 29 | return this.cause; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/org/json/JSONString.java: -------------------------------------------------------------------------------- 1 | package org.json; 2 | /** 3 | * The
JSONString
interface allows a toJSONString()
4 | * method so that a class can change the behavior of
5 | * JSONObject.toString()
, JSONArray.toString()
,
6 | * and JSONWriter.value(
Object)
. The
7 | * toJSONString
method will be used instead of the default behavior
8 | * of using the Object's toString()
method and quoting the result.
9 | */
10 | public interface JSONString {
11 | /**
12 | * The toJSONString
method allows a class to produce its own JSON
13 | * serialization.
14 | *
15 | * @return A strictly syntactically correct JSON text.
16 | */
17 | public String toJSONString();
18 | }
19 |
--------------------------------------------------------------------------------
/src/org/json/JSONStringer.java:
--------------------------------------------------------------------------------
1 | package org.json;
2 |
3 | /*
4 | Copyright (c) 2006 JSON.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | The Software shall be used for Good, not Evil.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 | SOFTWARE.
25 | */
26 |
27 | import java.io.StringWriter;
28 |
29 | /**
30 | * JSONStringer provides a quick and convenient way of producing JSON text.
31 | * The texts produced strictly conform to JSON syntax rules. No whitespace is
32 | * added, so the results are ready for transmission or storage. Each instance of
33 | * JSONStringer can produce one JSON text.
34 | *
35 | * A JSONStringer instance provides a value
method for appending
36 | * values to the
37 | * text, and a key
38 | * method for adding keys before values in objects. There are array
39 | * and endArray
methods that make and bound array values, and
40 | * object
and endObject
methods which make and bound
41 | * object values. All of these methods return the JSONWriter instance,
42 | * permitting cascade style. For example,
43 | * myString = new JSONStringer() 44 | * .object() 45 | * .key("JSON") 46 | * .value("Hello, World!") 47 | * .endObject() 48 | * .toString();which produces the string
49 | * {"JSON":"Hello, World!"}50 | *
51 | * The first method called must be array
or object
.
52 | * There are no methods for adding commas or colons. JSONStringer adds them for
53 | * you. Objects and arrays can be nested up to 20 levels deep.
54 | *
55 | * This can sometimes be easier than using a JSONObject to build a string.
56 | * @author JSON.org
57 | * @version 2008-09-18
58 | */
59 | public class JSONStringer extends JSONWriter {
60 | /**
61 | * Make a fresh JSONStringer. It can be used to build one JSON text.
62 | */
63 | public JSONStringer() {
64 | super(new StringWriter());
65 | }
66 |
67 | /**
68 | * Return the JSON text. This method is used to obtain the product of the
69 | * JSONStringer instance. It will return null
if there was a
70 | * problem in the construction of the JSON text (such as the calls to
71 | * array
were not properly balanced with calls to
72 | * endArray
).
73 | * @return The JSON text.
74 | */
75 | public String toString() {
76 | return this.mode == 'd' ? this.writer.toString() : null;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/resources/hadoop-site.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |