├── .classpath ├── .directory ├── .gitignore ├── .project ├── .settings └── org.eclipse.jdt.core.prefs ├── APACHE-LICENSE.txt ├── GPL-LICENSE.txt ├── README ├── README.textile ├── addToLocalRepo.sh ├── bin ├── benchmark_clients ├── benchmark_nodes └── result_new ├── lib ├── hadoop-core-0.20-append-r1056497.jar ├── hbase-0.90.0.jar └── terrastore-javaclient-2.1.jar ├── pom.xml └── src ├── benchmark_clients ├── benchmark_nodes ├── cassandra_mapreduce └── MapReduceCassandraDB.java ├── client ├── benchClient.java └── incomingHandler.java ├── controller ├── benchmarkController.java └── clientThread.java ├── core ├── BenchDB.java ├── Main.java ├── benchThread.java ├── fillDB.java ├── runBenchmark.java └── verifyAndCorrect.java ├── de └── zib │ ├── chordsharp │ ├── ChordSharp.java │ ├── ChordSharpConnection.java │ ├── ConnectionException.java │ ├── Main.java │ ├── NotFoundException.java │ ├── TimeoutException.java │ ├── Transaction.java │ ├── TransactionNotFinishedException.java │ ├── TransactionNotStartedException.java │ ├── UnknownException.java │ ├── examples │ │ ├── ChordSharpConnectionGetSubscribersExample.java │ │ ├── ChordSharpConnectionPublishExample.java │ │ ├── ChordSharpConnectionReadExample.java │ │ ├── ChordSharpConnectionSubscribeExample.java │ │ ├── ChordSharpConnectionWriteExample.java │ │ ├── TransactionParallelReadsExample.java │ │ ├── TransactionReadExample.java │ │ ├── TransactionReadWriteExample.java │ │ ├── TransactionWriteExample.java │ │ └── package-info.java │ └── package-info.java │ ├── scalaris │ ├── Benchmark.java │ ├── ConnectionException.java │ ├── ConnectionFactory.java │ ├── CustomOtpObject.java │ ├── CustomOtpStringObject.java │ ├── DeleteResult.java │ ├── Main.java │ ├── NodeNotFoundException.java │ ├── NotFoundException.java │ ├── Scalaris.java │ ├── TimeoutException.java │ ├── Transaction.java │ ├── TransactionNotFinishedException.java │ ├── TransactionNotStartedException.java │ ├── UnknownException.java │ ├── examples │ │ ├── CustomOtpFastStringObject.java │ │ ├── FastStringBenchmark.java │ │ ├── ScalarisGetSubscribersExample.java │ │ ├── ScalarisPublishExample.java │ │ ├── ScalarisReadExample.java │ │ ├── ScalarisSubscribeExample.java │ │ ├── ScalarisWriteExample.java │ │ ├── TransactionReadExample.java │ │ ├── TransactionReadWriteExample.java │ │ ├── TransactionWriteExample.java │ │ └── package-info.java │ └── package-info.java │ └── tools │ ├── PropertyLoader.java │ └── package-info.java ├── hbase_mapreduce └── MapReduceHbaseDB.java ├── implementations ├── cassandraDB.java ├── hbaseDB.java ├── mongoDB.java ├── riakDB.java ├── scalarisDB.java ├── terrastoreDB.java └── voldermortDB.java ├── org └── json │ ├── CDL.java │ ├── Cookie.java │ ├── CookieList.java │ ├── HTTP.java │ ├── HTTPTokener.java │ ├── JSONArray.java │ ├── JSONException.java │ ├── JSONML.java │ ├── JSONObject.java │ ├── JSONString.java │ ├── JSONStringer.java │ ├── JSONTokener.java │ ├── JSONWriter.java │ ├── Test.java │ ├── XML.java │ └── XMLTokener.java ├── resources ├── hadoop-site.xml ├── hbase-site.xml └── storage-conf.xml ├── result_new ├── test.java └── utils ├── Files.java ├── argsTools.java ├── mathTools.java ├── parse.py └── statTools.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /.directory: -------------------------------------------------------------------------------- 1 | [Dolphin] 2 | Timestamp=2011,2,8,17,24,41 3 | Version=2 4 | 5 | [Settings] 6 | ShowDotFiles=true 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Wikipedia-nosql-benchmark 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | 19 | CASSANDRA_HOME 20 | file:/home/inflames/apache-cassandra-0.7.2 21 | 22 | 23 | HADOOP_HOME 24 | file:/home/inflames/hadoop-0.20.2 25 | 26 | 27 | HBASE_HOME 28 | file:/home/inflames/hbase-0.20.6 29 | 30 | 31 | MONGODB_HOME 32 | file:/home/inflames/Documents/INFO22/M%C3%A9moire/software 33 | 34 | 35 | RIAK_HOME 36 | file:/home/inflames/Documents/INFO22/M%C3%A9moire/software/riak-java-client 37 | 38 | 39 | SCALARIS_HOME 40 | file:/home/inflames/Documents/INFO22/M%C3%A9moire/software/scalaris-0.2.2 41 | 42 | 43 | VOLDEMORT_HOME 44 | file:/home/inflames/Documents/INFO22/M%C3%A9moire/software/voldemort-0.81 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Mon Nov 15 17:17:41 CET 2010 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.5 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.source=1.5 13 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | see README.textile 2 | -------------------------------------------------------------------------------- /README.textile: -------------------------------------------------------------------------------- 1 | Please see http://www.nosqlbenchmarking.com for more informations and benchmark results 2 | 3 | You can now build this project using Maven. As a few dependencies where not available in any maven repository, I have decided to provide them myself in the lib directory. You still have to add those jar to your local maven repository, to do so execute the script addToLocalRepo.sh or execute each of the three lines that it contains. For Cassandra and HBase, there is a little more configuration needed. For Cassandra edit the file storage-conf.xml to reflect your cluster configuration. For HBase edit the file hbase-site.xml to reflect your cluster configuration. 4 | 5 | Then you only have to run "mvn package" to build the jar that contains everything needed. It will be in the folder "target" and it will be called "Wikipedia-nosql-benchmark-1.0-SNAPSHOT.jar". 6 | 7 | You can use the jar as a single client or with a controller and several clients if you need (they are mainly usefull if the client's bandwidth is too small). You can also use this jar to insert the documents in the DBs and to measure elasticity. 8 | 9 | h1. Fill the database 10 | 11 | Call the jar file like this : 12 | 13 | *java -jar jarfile.jar fillDB dbType /path/to/documents/ numberOfDocuments nodeAdress firstID numberOfInsertRun* 14 | 15 | *dbType* can currently take the following values : 16 | * cassandra 17 | * scalaris (please note that the current implementation should be optimized) 18 | * voldemort (no MapReduce implementation so only read/update can be benchmarked) 19 | * terrastore (partial implementation, needs work) 20 | * riak 21 | * mongodb 22 | * hbase 23 | 24 | */path/to/documents/* is the path to a directory that contains files named as increasing integers going from 1 to *numberOfDocuments* 25 | *nodeAdress* is the IP address of a working node in the cluster that can handle writes 26 | *firstID* is the integer that should be used as the starting ID of the inserts, this is usefull is you already have inserted documents and want to increase the data set with the same documents but using new IDs 27 | *numberOfInsertRun* is the number of time you want to insert all the documents 28 | 29 | 30 | h1. Run the benchmark in standalone mode (only one client) 31 | 32 | To *benchmark the read and update performances* call the jarfile like this : 33 | 34 | *java -jar jarfile.jar runBenchmark dbType totalNumberOp readPercentage numberOfDocuments IP1 IP2 IP3 ...* 35 | 36 | *dbType* can currently take the following values : 37 | * cassandra 38 | * scalaris (please note that the current implementation should be optimized) 39 | * voldemort (no MapReduce implementation so only read/update can be benchmarked) 40 | * terrastore (partial implementation, needs work) 41 | * riak 42 | * mongodb 43 | * hbase 44 | 45 | *totalNumberOp* is the total number of operations that will be requested to the cluster. 46 | *readPercentage* is the proportion of requests that will be read-only 47 | *numberOfDocuments* the total number of documents already inserted in the DB 48 | *IP1 IP2 IP3 ...* is a list of IP that can be as long as desired. For the systems without a load balancer, I put in the list the IP of each 49 | active node in the cluster. For systems with a load balancer, I simply put the IP of the load balancer as many time as there are active 50 | nodes in the cluster. 51 | 52 | If you want to *benchmark the MapReduce performances* , call the jar file like this : 53 | 54 | *java -jar jarfile.jar dbType search numberOfRuns IP* 55 | *dbType* can take any value listed just before provided that this database has a MapReduce implementation. 56 | *search* is a constant 57 | *numberOfRuns* is the number of time that the search benchmark will run 58 | *IP* is the IP of one of the nodes of the cluster that accept MapReduce jobs 59 | 60 | *Please note that the elasticity test is only available in controller/client mode* 61 | 62 | 63 | h1. Run the benchmark in controller/client mode 64 | 65 | This mode use configuration files that must be in the same directory than the jar : 66 | * *benchmark_clients* must contain the IP addresses of all the servers running a client, one IP per line without any blank line 67 | * *benchmark_nodes* must contain the IP addresses of all the servers that should be benchmarked 68 | * *elasticityArgs* must contain the following line if you want to use the elasticity test : 69 | - the upper limit acceptable for the standard deviation on 10 runs (use a statistical test at 95% for example) 70 | - the lower limit acceptable for the standard deviation on 10 runs 71 | - the number of milliseconds that must be waited for between runs 72 | - the maximum number of runs 73 | 74 | First you have to start the clients on each server that you specified in *benchmark_clients*, to do so simply run the command 75 | *java -jar jarfile.jar client* on each of them. 76 | 77 | To *benchmark the read and update performances* call the jarfile like this : 78 | *java -jar jarfile.jar controller dbType totalNumberOp readPercentage numberOfDocuments* 79 | 80 | Please note that the arguments are exactly the same than for the standalone client, except for the IP list that is now provided in the file *benchmark_nodes* 81 | 82 | If you want to *benchmark the MapReduce performances* , call the jar file like this : 83 | *java -jar wikipedia.jar controller dbType search numberOfRuns* 84 | The arguments are exactly the same than the ones for the standalone search benchmark, except for the server address that will be used. Note that the IP that will be used is the first one in the file *benchmark_nodes* 85 | 86 | If you want to *start the elasticity test* that will run until it sees 5 consecutive runs whose standard deviations are within the bounds defined by the two first lines of the file *elasticityArgs* or until it reach the maximum number of run defined in the same file. Call the jarfile like this : 87 | *java -jar jarfile.jar controller dbType totalNumberOp readPercentage numberOfDocuments elasticity* 88 | 89 | Finally you can kill all the clients from the controller by running the command : 90 | *java -jar jarfile.jar controller kill* 91 | 92 | 93 | -------------------------------------------------------------------------------- /addToLocalRepo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | mvn install:install-file -Dfile=./lib/hbase-0.90.0.jar -DgroupId=org.apache.hbase -DartifactId=hbase -Dversion=0.90.0 -Dpackaging=jar 3 | mvn install:install-file -Dfile=./lib/terrastore-javaclient-2.1.jar -DgroupId=terrastore-javaclient -DartifactId=terrastore-javaclient -Dversion=2.1 -Dpackaging=jar 4 | mvn install:install-file -Dfile=./lib/hadoop-core-0.20-append-r1056497.jar -DgroupId=org.apache.hadoop -DartifactId=hadoop-core -Dversion=0.20-append-r1056497 -Dpackaging=jar 5 | -------------------------------------------------------------------------------- /bin/benchmark_clients: -------------------------------------------------------------------------------- 1 | 127.0.0.1 -------------------------------------------------------------------------------- /bin/benchmark_nodes: -------------------------------------------------------------------------------- 1 | 192.168.0.34 2 | 192.168.0.35 -------------------------------------------------------------------------------- /lib/hadoop-core-0.20-append-r1056497.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thibaultdory/Wikipedia-noSQL-Benchmark/e5511e611b5f92457c51669e40bcbbaa0b1d060b/lib/hadoop-core-0.20-append-r1056497.jar -------------------------------------------------------------------------------- /lib/hbase-0.90.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thibaultdory/Wikipedia-noSQL-Benchmark/e5511e611b5f92457c51669e40bcbbaa0b1d060b/lib/hbase-0.90.0.jar -------------------------------------------------------------------------------- /lib/terrastore-javaclient-2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thibaultdory/Wikipedia-noSQL-Benchmark/e5511e611b5f92457c51669e40bcbbaa0b1d060b/lib/terrastore-javaclient-2.1.jar -------------------------------------------------------------------------------- /src/benchmark_clients: -------------------------------------------------------------------------------- 1 | 127.0.0.1 -------------------------------------------------------------------------------- /src/benchmark_nodes: -------------------------------------------------------------------------------- 1 | 192.168.0.34 2 | 192.168.0.35 -------------------------------------------------------------------------------- /src/client/benchClient.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2011 Thibault Dory 3 | * Licensed under the GPL Version 3 license 4 | */ 5 | package client; 6 | 7 | import java.io.IOException; 8 | import java.net.ServerSocket; 9 | import java.net.Socket; 10 | 11 | public class benchClient { 12 | 13 | private ServerSocket server; 14 | private int port = 6666; 15 | 16 | public benchClient(){ 17 | try { 18 | server = new ServerSocket(port); 19 | } catch (IOException e) { 20 | e.printStackTrace(); 21 | } 22 | } 23 | 24 | public static void main(String[] args) { 25 | benchClient client = new benchClient(); 26 | client.handleIncoming(); 27 | } 28 | 29 | public void handleIncoming(){ 30 | System.out.println("Waiting for message from the controller"); 31 | try { 32 | Socket socket = server.accept(); 33 | new incomingHandler(socket); 34 | //Restart the thread to wait for the next command 35 | this.handleIncoming(); 36 | } catch (IOException e) { 37 | e.printStackTrace(); 38 | } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/client/incomingHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2011 Thibault Dory 3 | * Licensed under the GPL Version 3 license 4 | */ 5 | 6 | package client; 7 | 8 | import java.io.IOException; 9 | import java.io.ObjectInputStream; 10 | import java.io.ObjectOutputStream; 11 | import java.net.Socket; 12 | import java.util.ArrayList; 13 | import java.util.Arrays; 14 | 15 | import core.runBenchmark; 16 | 17 | public class incomingHandler implements Runnable{ 18 | private Socket socket; 19 | 20 | public incomingHandler(Socket socket) { 21 | this.socket = socket; 22 | Thread t = new Thread(this); 23 | t.start(); 24 | } 25 | 26 | public void run() { 27 | try { 28 | //Get args from the controller 29 | ObjectInputStream ois = new ObjectInputStream(socket.getInputStream()); 30 | ArrayList argList = (ArrayList) ois.readObject(); 31 | 32 | if(!(argList.get(0).equals("kill"))){ 33 | //Run the benchmark and get the results 34 | String dbType = argList.get(0); 35 | String numberOfOperations = argList.get(1); 36 | String readPercentage = argList.get(2); 37 | String numberOfDocuments = argList.get(3); 38 | String [] args = new String [argList.size()]; 39 | args[0] = dbType; 40 | args[1] = numberOfOperations; 41 | args[2] = readPercentage; 42 | args[3] = numberOfDocuments; 43 | for(int i=4;i> results = new ArrayList>(); 19 | 20 | 21 | public static void main(String[] args) { 22 | 23 | //handle arguments 24 | String dbType = args[0]; 25 | int readPercentage; 26 | boolean isSearch = false; 27 | boolean isElasticity = false; 28 | boolean isKill = false; 29 | try{ 30 | readPercentage = Integer.decode(args[2]); 31 | }catch(Exception e){ 32 | readPercentage = 0; 33 | if(dbType.equals("kill")){ 34 | System.out.println("Sending kill signal to all clients"); 35 | isKill = true; 36 | }else{ 37 | e.printStackTrace(); 38 | System.out.println("Bad arguments"); 39 | System.exit(0); 40 | } 41 | } 42 | String numberOfOperations; 43 | if(! isKill){ 44 | numberOfOperations = args[1]; 45 | }else{ 46 | numberOfOperations = "1"; 47 | } 48 | try{ 49 | if(args[4].equals("elasticity")){ 50 | isElasticity = true; 51 | System.out.println("Starting elasticity test"); 52 | } 53 | }catch(Exception e){} 54 | 55 | ArrayList clientList = Files.readFileAsList("benchmark_clients"); 56 | ArrayList nodeList = Files.readFileAsList("benchmark_nodes"); 57 | String numberOfOperationsByThread; 58 | try{ 59 | int temp = Integer.decode(numberOfOperations)/clientList.size(); 60 | numberOfOperationsByThread = String.valueOf(temp); 61 | }catch(Exception e){ 62 | //search 63 | numberOfOperationsByThread = "search"; 64 | isSearch = true; 65 | } 66 | ArrayList> dividedList = argsTools.divideNodeList(nodeList, clientList.size()); 67 | int numberOfDocuments; 68 | if(!isKill && !isSearch){ 69 | numberOfDocuments = Integer.decode(args[3]); 70 | }else{ 71 | numberOfDocuments = 1; 72 | } 73 | 74 | if(! isElasticity){ 75 | startThreads(nodeList, clientList, dbType, numberOfOperationsByThread, readPercentage, numberOfDocuments, dividedList, isSearch); 76 | 77 | //The threads results have been added to "results" by clientThread called by startThreads 78 | statTools stat = new statTools(results); 79 | double average = stat.getAverage(); 80 | double standardDeviation = stat.getStandardDeviation(); 81 | 82 | if(!isKill){ 83 | if(isSearch){ 84 | System.out.println("Average time and standard deviation taken to build the search index"); 85 | System.out.println("Time in seconds \t Standard deviation"); 86 | System.out.println(average + " \t "+standardDeviation); 87 | }else{ 88 | System.out.println("Number of reported errors during tests : "); 89 | System.out.println("Connection error \t Read error \t Update error"); 90 | System.out.println(numberOfConnectErrors+"\t"+numberOfReadErrors+"\t"+numberOfUpdateErrors); 91 | System.out.println("Average time and standard deviation taken to complete "+numberOfOperations+" requests"); 92 | System.out.println("Time in seconds \t Standard deviation"); 93 | System.out.println(average + " \t "+standardDeviation); 94 | } 95 | } 96 | }else{ 97 | //Get the arguments needed for the elasticity test in the file elasticityArgs 98 | ArrayList elastArgs = Files.readFileAsList("elasticityArgs"); 99 | double maxDeltaTime = Double.valueOf(elastArgs.get(0)); 100 | //In milliseconds 101 | int sleepTime = Integer.valueOf(elastArgs.get(1)); 102 | int maxRuns = Integer.valueOf(elastArgs.get(2)); 103 | //Start the elasticity test 104 | int countGlobal = 0; 105 | int countInBounds = 0; 106 | ArrayList intermediateResults = new ArrayList(); 107 | 108 | while( (countInBounds < 6) && (countGlobal < maxRuns)){ 109 | //Reset the results list 110 | results = new ArrayList>(); 111 | startThreads(nodeList, clientList, dbType, numberOfOperationsByThread, readPercentage, numberOfDocuments, dividedList, isSearch); 112 | statTools stat = new statTools(results); 113 | double tempAverage = stat.getAverage(); 114 | intermediateResults.add(tempAverage); 115 | double deltaTime = 0; 116 | int numberOfResults = intermediateResults.size(); 117 | if(numberOfResults > 1){ 118 | deltaTime = Math.abs(intermediateResults.get(numberOfResults-2) - intermediateResults.get(numberOfResults-1)); 119 | } 120 | System.out.println("Run number "+countGlobal+" has an average of "+tempAverage +" and a SD of : "+stat.getStandardDeviation()); 121 | if(deltaTime <= maxDeltaTime){ 122 | countInBounds += 1; 123 | System.out.println("In bounds"); 124 | }else{ 125 | countInBounds = 0; 126 | System.out.println("Out of bounds"); 127 | } 128 | countGlobal += 1; 129 | try { 130 | Thread.sleep(sleepTime); 131 | } catch (InterruptedException e) { 132 | e.printStackTrace(); 133 | } 134 | } 135 | 136 | System.out.println("The DB took "+countGlobal+" runs to stabilize with a sleep time of "+sleepTime+" milliseconds"); 137 | System.out.println("Observed average time : "); 138 | System.out.println(intermediateResults); 139 | } 140 | 141 | 142 | 143 | 144 | 145 | } 146 | 147 | public static void startThreads(ArrayList nodeList, ArrayList clientList, String dbType, 148 | String numberOfOperationsByThread, int readPercentage, int numberOfDocuments, 149 | ArrayList> dividedList, boolean isSearch){ 150 | 151 | clientThread t[] = new clientThread[nodeList.size()]; 152 | //start thread for each client 153 | for(int i=0;i argList = new ArrayList(); 21 | 22 | public clientThread(String host, String dbTypeArg, String numberOfOperationsArg, 23 | int readPercentageArg, int numberOfDocuments, ArrayList nodeListArg){ 24 | clientHost = host; 25 | argList.add(dbTypeArg); 26 | argList.add(numberOfOperationsArg); 27 | argList.add(String.valueOf(readPercentageArg)); 28 | argList.add(String.valueOf(numberOfDocuments)); 29 | for(int i=0;i clientResult = (ArrayList) ois.readObject(); 46 | int connectErrors = (Integer) ois.readObject(); 47 | int readErrors = (Integer) ois.readObject(); 48 | int updateErrors = (Integer) ois.readObject(); 49 | benchmarkController.results.add(clientResult); 50 | benchmarkController.numberOfConnectErrors += connectErrors; 51 | benchmarkController.numberOfReadErrors += readErrors; 52 | benchmarkController.numberOfUpdateErrors += updateErrors; 53 | ois.close(); 54 | oos.close(); 55 | } catch (UnknownHostException e) { 56 | e.printStackTrace(); 57 | } catch (EOFException e){ 58 | System.out.println("Client killed"); 59 | } catch (IOException e) { 60 | e.printStackTrace(); 61 | } catch (ClassNotFoundException e) { 62 | e.printStackTrace(); 63 | } 64 | 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/core/BenchDB.java: -------------------------------------------------------------------------------- 1 | package core; 2 | /** 3 | * Copyright 2011 Thibault Dory 4 | * Licensed under the GPL Version 3 license 5 | */ 6 | 7 | 8 | /** 9 | * Every database client implementation must extends this class and implement its functions 10 | * @author Thibault Dory 11 | * @version 0.1 12 | */ 13 | public abstract class BenchDB { 14 | /** 15 | * This function is used to initialize the connection to the node nodeAddress 16 | * @param nodeAddress contains the hostname to connect to 17 | * @return 1 if everything is ok else return -1 18 | */ 19 | public abstract int connectNode(String nodeAddress); 20 | 21 | /** 22 | * This function is used to get the string corresponding ID from the database 23 | * @param ID the key associated to the wanted value 24 | * @return the string associated to ID or null if an error occurs 25 | */ 26 | public abstract String readDB(String ID); 27 | 28 | /** 29 | * This function is used to update the value corresponding to ID 30 | * @param ID the key 31 | * @param newValue the updated value associated to ID 32 | * @return 1 if everything goes fine else return -1 33 | */ 34 | public abstract int updateDB(String ID, String newValue); 35 | 36 | /** 37 | * This function is used to write a value corresponding to ID 38 | * @param ID the key 39 | * @param Value the value associated to ID 40 | * @return 1 if everything goes fine else return -1 41 | */ 42 | public abstract int writeDB(String ID, String Value); 43 | 44 | /** 45 | * This function is called to launch the MapReduce build of the reverse index 46 | * @param keyword 47 | * @return 48 | */ 49 | public abstract void searchDB(String keyword); 50 | 51 | /** 52 | * This function is called to clise the connection 53 | */ 54 | public abstract void close(); 55 | } 56 | -------------------------------------------------------------------------------- /src/core/Main.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2011 Thibault Dory 3 | * Licensed under the GPL Version 3 license 4 | */ 5 | 6 | package core; 7 | 8 | import client.benchClient; 9 | import controller.benchmarkController; 10 | 11 | /* 12 | * This class is a simple entry point for the other main classes 13 | */ 14 | 15 | public class Main { 16 | 17 | public static void main(String[] args) { 18 | String [] newArgs = new String[args.length -1]; 19 | for(int i=0; i<(args.length -1);i++){ 20 | newArgs[i] = args[i+1]; 21 | } 22 | if(args[0].equals("runBenchmark")){ 23 | runBenchmark.main(newArgs); 24 | }else if(args[0].equals("controller")){ 25 | benchmarkController.main(newArgs); 26 | }else if(args[0].equals("client")){ 27 | benchClient.main(newArgs); 28 | }else if(args[0].equals("fillDB")){ 29 | fillDB.main(newArgs); 30 | }else if(args[0].equals("verifyAndCorrect")){ 31 | verifyAndCorrect.main(newArgs); 32 | } 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/core/benchThread.java: -------------------------------------------------------------------------------- 1 | package core; 2 | /** 3 | * Copyright 2011 Thibault Dory 4 | * Licensed under the GPL Version 3 license 5 | */ 6 | 7 | import java.util.Random; 8 | 9 | 10 | /** 11 | * This class does the actual job of the benchmark 12 | * @author Thibault Dory 13 | * @version 0.1 14 | */ 15 | 16 | public class benchThread extends Thread{ 17 | Random generator = new Random(); 18 | int numberOfOperationsDone = 0; 19 | int numberOfUpdates =0; 20 | BenchDB db; 21 | String nodeAddress; 22 | int readPercentage; 23 | int numberOfOperations; 24 | int numberOfDocuments; 25 | 26 | /** 27 | * Constructor of the class 28 | * @param dbA is a DB object initialized 29 | * @param nodeAddressA is the node address to connect to 30 | * @param readPercentageA is the percentage of requests that will be only reads 31 | * @param numberOfOperationsA is the total number of requests that will be made by this thread 32 | */ 33 | public benchThread(BenchDB dbA, String nodeAddressA, int readPercentageA, int numberOfOperationsA, int numberOfDocumentsA){ 34 | db = dbA; 35 | nodeAddress = nodeAddressA; 36 | readPercentage = readPercentageA; 37 | numberOfOperations = numberOfOperationsA; 38 | numberOfDocuments = numberOfDocumentsA; 39 | } 40 | /** 41 | * This function is called when the thread is started 42 | */ 43 | public void run(){ 44 | int countConnectErrors = 0; 45 | int countReadErrors = 0; 46 | int countUpdateErrors = 0; 47 | while(!connect()){ 48 | countConnectErrors += 1; 49 | System.out.println("This thread cannot connect to : "+nodeAddress+" retrying new attempt : "+countConnectErrors); 50 | try { 51 | Thread.sleep(100); 52 | } catch (InterruptedException e) { 53 | e.printStackTrace(); 54 | } 55 | } 56 | for(int i=0;i<=numberOfOperations;i++){ 57 | //Generate a random ID in the range of the document 58 | int ID = generator.nextInt(numberOfDocuments)+1; 59 | String document = db.readDB(String.valueOf(ID)); 60 | if(document == null){ 61 | System.out.println("Thread cannot read ID : "+ID+"for node : "+nodeAddress); 62 | countReadErrors += 1; 63 | } 64 | //Update if randomUpdate > readPercentage to have ~readPercentage % of read only 65 | int randomUpdate = generator.nextInt(100); 66 | if(randomUpdate > readPercentage){ 67 | String newDocument = modify(document); 68 | int ret = db.updateDB(String.valueOf(ID), newDocument); 69 | numberOfUpdates += 1; 70 | if(ret < 0){ 71 | System.out.println("Thread cannot update for node : "+nodeAddress); 72 | countUpdateErrors += 1; 73 | } 74 | } 75 | numberOfOperationsDone += 1; 76 | } 77 | System.out.println("the thread has done "+numberOfOperationsDone+" operations and "+numberOfUpdates+" updates with "+countConnectErrors+" errors"); 78 | runBenchmark.numberOfConnectErrors += countConnectErrors; 79 | runBenchmark.numberOfReadErrors += countReadErrors; 80 | runBenchmark.numberOfUpdateErrors += countUpdateErrors; 81 | db.close(); 82 | return; 83 | } 84 | 85 | private boolean connect(){ 86 | boolean ret; 87 | try{ 88 | int res = db.connectNode(nodeAddress); 89 | if(res == 1) ret = true; 90 | else ret = false; 91 | }catch(Exception e){ 92 | ret = false; 93 | } 94 | return ret; 95 | } 96 | /** 97 | * Function used to modify the document 98 | * @param document the original document 99 | * @return the modified document 100 | */ 101 | private String modify(String document) { 102 | // String newDocument = document + " Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed adipiscing orci at erat " + 103 | // "consectetur blandit. Suspendisse feugiat eros nec ante scelerisque et gravida tortor ultrices. Nulla diam felis, " + 104 | // "vestibulum nec venenatis id, dapibus vitae enim. Nullam porta volutpat ipsum, sit amet sagittis risus dapibus at. " + 105 | // "Sed diam nibh, eleifend id feugiat vitae, fringilla id odio. Integer est arcu, mattis non vehicula non, dictum sit " + 106 | // "amet neque. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas dapibus " + 107 | // "libero at felis ultricies eleifend. Vivamus luctus blandit libero sed hendrerit. Vestibulum faucibus fermentum turpis, " + 108 | // "quis dictum risus volutpat vel.Nam dolor lacus, facilisis eget placerat id, rhoncus ut diam. Duis pharetra quam et nibh " + 109 | // "fermentum et feugiat nulla tincidunt. Pellentesque molestie ligula eget justo pulvinar ut pellentesque mi placerat. " + 110 | // "Ut at odio vitae nisl pharetra porta ac nec tortor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, " + 111 | // "per inceptos himenaeos. Maecenas lobortis massa at purus venenatis gravida. Pellentesque consequat ultrices ante, quis " + 112 | // "dignissim ligula venenatis placerat. Fusce et diam in velit blandit rhoncus vitae sed nibh. Morbi quis libero eros, " + 113 | // "fermentum vulputate neque. Mauris non felis eget felis ornare porta. In sit amet felis felis. Nunc nisl sapien, " + 114 | // "gravida eu mollis ut, faucibus vel diam. Fusce blandit dui sed massa rutrum lacinia. Duis eleifend posuere sagittis. " + 115 | // "Pellentesque vel tellus ligula. Nullam ac dolor vel nisl molestie dictum at vel erat.Fusce sed massa nisi. Curabitur " + 116 | // "fermentum placerat tortor, a condimentum odio placerat ac. Aenean vitae dolor velit. Vivamus consectetur ante dui, eget " + 117 | // "dapibus tortor. Suspendisse sed turpis eu felis tincidunt accumsan. Mauris tempor massa id purus placerat pulvinar. "; 118 | String newDocument = document + "1"; 119 | return newDocument; 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /src/core/fillDB.java: -------------------------------------------------------------------------------- 1 | package core; 2 | /** 3 | * Copyright 2011 Thibault Dory 4 | * Licensed under the GPL Version 3 license 5 | */ 6 | 7 | 8 | import implementations.cassandraDB; 9 | import implementations.hbaseDB; 10 | import implementations.mongoDB; 11 | import implementations.riakDB; 12 | import implementations.scalarisDB; 13 | import implementations.terrastoreDB; 14 | import implementations.voldermortDB; 15 | 16 | import java.io.IOException; 17 | import utils.Files; 18 | 19 | /** 20 | * Class used to fill in the different databases with the wikipedia data 21 | * @author Thibault Dory 22 | * @version 0.1 23 | */ 24 | 25 | public class fillDB { 26 | 27 | public static void main(String[] args) { 28 | 29 | 30 | String dbType = args[0]; 31 | int dbTypeI; 32 | if(dbType.equals("cassandra")) dbTypeI = 0; 33 | else if(dbType.equals("scalaris")) dbTypeI = 1; 34 | else if(dbType.equals("voldemort")) dbTypeI = 2; 35 | else if(dbType.equals("terrastore")) dbTypeI = 3; 36 | else if(dbType.equals("riak")) dbTypeI = 4; 37 | else if(dbType.equals("mongodb")) dbTypeI = 5; 38 | else if(dbType.equals("hbase")) dbTypeI = 6; 39 | else dbTypeI = -1; 40 | 41 | String basePath = args[1]; 42 | int numberOfInserts = Integer.decode(args[2]); 43 | String nodeAdress = args[3]; 44 | 45 | int firstIDInDB = Integer.valueOf(args[4]); 46 | int numberOfInsertRun = Integer.valueOf(args[5]); 47 | int firstIDOnDisk; 48 | try{ 49 | firstIDOnDisk = Integer.valueOf(args[6]); 50 | }catch(Exception e){ 51 | firstIDOnDisk = 0; 52 | } 53 | 54 | BenchDB db; 55 | switch(dbTypeI){ 56 | case 0: 57 | db = new cassandraDB(); 58 | break; 59 | case 1: 60 | db = new scalarisDB(); 61 | break; 62 | case 2: 63 | db = new voldermortDB(); 64 | break; 65 | case 3: 66 | db = new terrastoreDB(); 67 | break; 68 | case 4: 69 | db = new riakDB(); 70 | break; 71 | case 5: 72 | db = new mongoDB(); 73 | break; 74 | case 6: 75 | db = new hbaseDB(); 76 | break; 77 | default: 78 | db = new cassandraDB(); 79 | break; 80 | } 81 | 82 | int retCon = db.connectNode(nodeAdress); 83 | System.out.println("connection returned value : "+retCon); 84 | if(retCon > 0){ 85 | for(int j=0;j 0){ 67 | for(int i=1+startID;i<=numberOfDocuments;i++){ 68 | String xml=""; 69 | try { 70 | xml = Files.readFileAsString(basePath+String.valueOf(i)); 71 | } catch (IOException e2) { 72 | // TODO Auto-generated catch block 73 | e2.printStackTrace(); 74 | } 75 | try{ 76 | String ret = db.readDB(String.valueOf(i)); 77 | if(ret == null){ 78 | throw new Exception(); 79 | } 80 | db.updateDB(String.valueOf(i), xml); 81 | }catch(Exception e){ 82 | db.writeDB(String.valueOf(i), xml); 83 | System.out.println("Corrected ID : "+i); 84 | } 85 | if(i%200 == 0){ 86 | System.out.println(i+" verifications done"); 87 | } 88 | } 89 | } 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /src/de/zib/chordsharp/ChordSharp.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.chordsharp; 17 | 18 | import java.util.Vector; 19 | 20 | /** 21 | * Public ChordSharp Interface. 22 | * 23 | * @author Nico Kruber, kruber@zib.de 24 | * @version 1.4 25 | * @deprecated use {@link de.zib.scalaris.Scalaris} instead 26 | */ 27 | @Deprecated 28 | public class ChordSharp { 29 | 30 | /** 31 | * Gets the value stored with the given {@code key}. 32 | * 33 | * @param key 34 | * the key to look up 35 | * @return the value stored under the given {@code key} 36 | * @throws ConnectionException 37 | * if the connection is not active or a communication error 38 | * occurs or an exit signal was received or the remote node 39 | * sends a message containing an invalid cookie 40 | * @throws TimeoutException 41 | * if a timeout occurred while trying to fetch the value 42 | * @throws NotFoundException 43 | * if the requested key does not exist 44 | * @throws UnknownException 45 | * if any other error occurs 46 | */ 47 | public static String read(String key) throws ConnectionException, 48 | TimeoutException, UnknownException, NotFoundException { 49 | return ChordSharpConnection.readString(key); 50 | } 51 | 52 | /** 53 | * Stores the given {@code key}/{@code value} pair. 54 | * 55 | * @param key 56 | * the key to store the value for 57 | * @param value 58 | * the value to store 59 | * @throws ConnectionException 60 | * if the connection is not active or a communication error 61 | * occurs or an exit signal was received or the remote node 62 | * sends a message containing an invalid cookie 63 | * @throws TimeoutException 64 | * if a timeout occurred while trying to write the value 65 | * @throws UnknownException 66 | * if any other error occurs 67 | */ 68 | public static void write(String key, String value) 69 | throws ConnectionException, TimeoutException, UnknownException { 70 | ChordSharpConnection.write(key, value); 71 | } 72 | 73 | /** 74 | * Publishes an event under a given {@code topic}. 75 | * 76 | * @param topic 77 | * the topic to publish the content under 78 | * @param content 79 | * the content to publish 80 | * @throws ConnectionException 81 | * if the connection is not active or a communication error 82 | * occurs or an exit signal was received or the remote node 83 | * sends a message containing an invalid cookie 84 | */ 85 | public static void publish(String topic, String content) throws ConnectionException { 86 | ChordSharpConnection.publish(topic, content); 87 | } 88 | 89 | /** 90 | * Subscribes a url for a {@code topic}. 91 | * 92 | * Note: Since version 1.4 erlang's return type is evaluated and additional 93 | * exceptions were added to comply with that change. 94 | * 95 | * @param topic 96 | * the topic to subscribe the url for 97 | * @param url 98 | * the url of the subscriber (this is where the events are send 99 | * to) 100 | * @throws ConnectionException 101 | * if the connection is not active or a communication error 102 | * occurs or an exit signal was received or the remote node 103 | * sends a message containing an invalid cookie 104 | * @throws TimeoutException 105 | * if a timeout occurred while trying to write the value 106 | * @throws UnknownException 107 | * if any other error occurs 108 | */ 109 | public static void subscribe(String topic, String url) 110 | throws ConnectionException, TimeoutException, UnknownException { 111 | ChordSharpConnection.subscribe(topic, url); 112 | } 113 | 114 | /** 115 | * Unsubscribes a url from a {@code topic}. 116 | * 117 | * Note: Since version 1.4 erlang's return type is evaluated and additional 118 | * exceptions were added to comply with that change. 119 | * 120 | * @param topic 121 | * the topic to unsubscribe the url from 122 | * @param url 123 | * the url of the subscriber 124 | * @throws ConnectionException 125 | * if the connection is not active or a communication error 126 | * occurs or an exit signal was received or the remote node 127 | * sends a message containing an invalid cookie 128 | * @throws TimeoutException 129 | * if a timeout occurred while trying to write the value 130 | * @throws NotFoundException 131 | * if the topic does not exist or the given subscriber is not 132 | * subscribed to the given topic 133 | * @throws UnknownException 134 | * if any other error occurs 135 | * 136 | * @since 1.3 137 | */ 138 | public static void unsubscribe(String topic, String url) 139 | throws ConnectionException, TimeoutException, NotFoundException, UnknownException { 140 | ChordSharpConnection.unsubscribe(topic, url); 141 | } 142 | 143 | /** 144 | * Gets a list of subscribers of a {@code topic}. 145 | * 146 | * @param topic 147 | * the topic to get the subscribers for 148 | * @return the subscriber URLs 149 | * @throws ConnectionException 150 | * if the connection is not active or a communication error 151 | * occurs or an exit signal was received or the remote node 152 | * sends a message containing an invalid cookie 153 | * @throws UnknownException 154 | * is thrown if the return type of the erlang method does not 155 | * match the expected one 156 | */ 157 | public static Vector getSubscribers(String topic) 158 | throws ConnectionException, UnknownException { 159 | return ChordSharpConnection.getSubscribers(topic); 160 | } 161 | } -------------------------------------------------------------------------------- /src/de/zib/chordsharp/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.chordsharp; 17 | 18 | import com.ericsson.otp.erlang.OtpErlangException; 19 | 20 | /** 21 | * Exception that is thrown when a read operation on a chordsharp ring fails 22 | * because the connection is not active or a communication error occurred or an 23 | * exit signal was received or the remote node sent a message containing an 24 | * invalid cookie. 25 | * 26 | * @author Nico Kruber, kruber@zib.de 27 | * @version 2.0 28 | */ 29 | @Deprecated 30 | public class ConnectionException extends OtpErlangException { 31 | /** 32 | * class version for serialisation 33 | */ 34 | private static final long serialVersionUID = 1L; 35 | 36 | /** 37 | * Creates the exception with no message. 38 | */ 39 | public ConnectionException() { 40 | } 41 | 42 | /** 43 | * Creates the exception with the given message. 44 | * 45 | * @param msg 46 | * message of the exception 47 | */ 48 | public ConnectionException(String msg) { 49 | super(msg); 50 | } 51 | 52 | /** 53 | * Creates an exception taking the message of the given throwable. 54 | * 55 | * @param e the exception to "re-throw" 56 | */ 57 | public ConnectionException(Throwable e) { 58 | super(e.getMessage()); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/de/zib/chordsharp/NotFoundException.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.chordsharp; 17 | 18 | import com.ericsson.otp.erlang.OtpErlangException; 19 | 20 | /** 21 | * Exception that is thrown when a read operation on a chordsharp ring fails 22 | * because the key did not exist before. 23 | * 24 | * @author Nico Kruber, kruber@zib.de 25 | * @version 2.0 26 | */ 27 | @Deprecated 28 | public class NotFoundException extends OtpErlangException { 29 | /** 30 | * class version for serialisation 31 | */ 32 | private static final long serialVersionUID = 1L; 33 | 34 | /** 35 | * Creates the exception with no message. 36 | */ 37 | public NotFoundException() { 38 | } 39 | 40 | /** 41 | * Creates the exception with the given message. 42 | * 43 | * @param msg 44 | * message of the exception 45 | */ 46 | public NotFoundException(String msg) { 47 | super(msg); 48 | } 49 | 50 | /** 51 | * Creates an exception taking the message of the given throwable. 52 | * 53 | * @param e the exception to "re-throw" 54 | */ 55 | public NotFoundException(Throwable e) { 56 | super(e.getMessage()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/de/zib/chordsharp/TimeoutException.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.chordsharp; 17 | 18 | import com.ericsson.otp.erlang.OtpErlangException; 19 | 20 | /** 21 | * Exception that is thrown when a read or write operation on a chordsharp ring 22 | * fails due to a timeout. 23 | * 24 | * @author Nico Kruber, kruber@zib.de 25 | * @version 2.0 26 | */ 27 | @Deprecated 28 | public class TimeoutException extends OtpErlangException { 29 | /** 30 | * class version for serialisation 31 | */ 32 | private static final long serialVersionUID = 1L; 33 | 34 | /** 35 | * Creates the exception with no message. 36 | */ 37 | public TimeoutException() { 38 | } 39 | 40 | /** 41 | * Creates the exception with the given message. 42 | * 43 | * @param msg 44 | * message of the exception 45 | */ 46 | public TimeoutException(String msg) { 47 | super(msg); 48 | } 49 | 50 | /** 51 | * Creates an exception taking the message of the given throwable. 52 | * 53 | * @param e the exception to "re-throw" 54 | */ 55 | public TimeoutException(Throwable e) { 56 | super(e.getMessage()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/de/zib/chordsharp/TransactionNotFinishedException.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.chordsharp; 17 | 18 | /** 19 | * Exception that is thrown when a new transaction is started although the old 20 | * one has not been committed or aborted. 21 | * 22 | * @author Nico Kruber, kruber@zib.de 23 | * @version 2.0 24 | */ 25 | @Deprecated 26 | public class TransactionNotFinishedException extends Exception { 27 | /** 28 | * class version for serialisation 29 | */ 30 | private static final long serialVersionUID = 1L; 31 | 32 | /** 33 | * Creates the exception with no message. 34 | */ 35 | public TransactionNotFinishedException() { 36 | } 37 | 38 | /** 39 | * Creates the exception with the given message. 40 | * 41 | * @param msg 42 | * message of the exception 43 | */ 44 | public TransactionNotFinishedException(String msg) { 45 | super(msg); 46 | } 47 | 48 | /** 49 | * Creates an exception taking the message of the given throwable. 50 | * 51 | * @param e the exception to "re-throw" 52 | */ 53 | public TransactionNotFinishedException(Throwable e) { 54 | super(e.getMessage()); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/de/zib/chordsharp/TransactionNotStartedException.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.chordsharp; 17 | 18 | /** 19 | * Exception that is thrown when a new transaction is not started but is used 20 | * nevertheless. Since this is a programmer's mistake, a RuntimeException is 21 | * chosen as the base class which eliminates the need to specify the exception 22 | * in a throws clause. 23 | * 24 | * @author Nico Kruber, kruber@zib.de 25 | * @version 2.0 26 | */ 27 | @Deprecated 28 | public class TransactionNotStartedException extends RuntimeException { 29 | /** 30 | * class version for serialisation 31 | */ 32 | private static final long serialVersionUID = 1L; 33 | 34 | /** 35 | * Creates the exception with no message. 36 | */ 37 | public TransactionNotStartedException() { 38 | } 39 | 40 | /** 41 | * Creates the exception with the given message. 42 | * 43 | * @param msg 44 | * message of the exception 45 | */ 46 | public TransactionNotStartedException(String msg) { 47 | super(msg); 48 | } 49 | 50 | /** 51 | * Creates an exception taking the message of the given throwable. 52 | * 53 | * @param e the exception to "re-throw" 54 | */ 55 | public TransactionNotStartedException(Throwable e) { 56 | super(e.getMessage()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/de/zib/chordsharp/UnknownException.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.chordsharp; 17 | 18 | import com.ericsson.otp.erlang.OtpErlangException; 19 | 20 | /** 21 | * Generic exception that is thrown during read or write operations on a 22 | * chordsharp ring. The reason is anything else but a timeout or not_found. They 23 | * are handled in {@link TimeoutException} and {@link NotFoundException}. 24 | * 25 | * @author Nico Kruber, kruber@zib.de 26 | * @version 2.0 27 | */ 28 | @Deprecated 29 | public class UnknownException extends OtpErlangException { 30 | /** 31 | * class version for serialisation 32 | */ 33 | private static final long serialVersionUID = 1L; 34 | 35 | /** 36 | * Creates the exception with no message. 37 | */ 38 | public UnknownException() { 39 | } 40 | 41 | /** 42 | * Creates the exception with the given message. 43 | * 44 | * @param msg 45 | * message of the exception 46 | */ 47 | public UnknownException(String msg) { 48 | super(msg); 49 | } 50 | 51 | /** 52 | * Creates an exception taking the message of the given throwable. 53 | * 54 | * @param e the exception to "re-throw" 55 | */ 56 | public UnknownException(Throwable e) { 57 | super(e.getMessage()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/de/zib/chordsharp/examples/ChordSharpConnectionGetSubscribersExample.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.chordsharp.examples; 17 | 18 | import java.util.Iterator; 19 | import java.util.Vector; 20 | 21 | import com.ericsson.otp.erlang.OtpErlangList; 22 | import com.ericsson.otp.erlang.OtpErlangString; 23 | 24 | import de.zib.chordsharp.ChordSharpConnection; 25 | import de.zib.chordsharp.ConnectionException; 26 | import de.zib.chordsharp.UnknownException; 27 | 28 | /** 29 | * Provides an example for using the {@code getSubscribers} methods of the 30 | * {@link ChordSharpConnection} class. 31 | * 32 | * @author Nico Kruber, kruber@zib.de 33 | * @version 1.1 34 | */ 35 | @Deprecated 36 | public class ChordSharpConnectionGetSubscribersExample { 37 | /** 38 | * Prints a list of all subscribers to a given topic, provided on the 39 | * command line with the {@code getSubscribers} methods of 40 | * {@link ChordSharpConnection}.
41 | * If no topic is given, the default topic {@code "topic"} is used. 42 | * 43 | * @param args 44 | * command line arguments (first argument can be an optional 45 | * topic to get the subscribers for) 46 | */ 47 | public static void main(String[] args) { 48 | String topic; 49 | 50 | if (args.length != 1) { 51 | topic = "topic"; 52 | } else { 53 | topic = args[0]; 54 | } 55 | 56 | OtpErlangString otpTopic = new OtpErlangString(topic); 57 | 58 | OtpErlangList otpSubscribers; 59 | Vector subscribers; 60 | 61 | System.out 62 | .println("Reading values with the class `ChordSharpConnection`:"); 63 | 64 | // static: 65 | try { 66 | System.out 67 | .println(" `static OtpErlangString getSubscribers(OtpErlangString)`..."); 68 | otpSubscribers = ChordSharpConnection.getSubscribers(otpTopic); 69 | System.out.println(" getSubscribers(" + otpTopic.stringValue() 70 | + ") == " + getSubscribers(otpSubscribers)); 71 | } catch (ConnectionException e) { 72 | System.out.println(" getSubscribers(" + otpTopic.stringValue() 73 | + ") failed: " + e.getMessage()); 74 | } catch (UnknownException e) { 75 | System.out.println(" getSubscribers(" + otpTopic.stringValue() 76 | + ") failed: " + e.getMessage()); 77 | } 78 | 79 | try { 80 | System.out.println(" `static String getSubscribers(String)`..."); 81 | subscribers = ChordSharpConnection.getSubscribers(topic); 82 | System.out.println(" getSubscribers(" + topic + ") == " 83 | + getSubscribers(subscribers)); 84 | } catch (ConnectionException e) { 85 | System.out.println(" getSubscribers(" + topic + ") failed: " 86 | + e.getMessage()); 87 | } catch (UnknownException e) { 88 | System.out.println(" getSubscribers(" + topic 89 | + ") failed: " + e.getMessage()); 90 | } 91 | 92 | // non-static: 93 | try { 94 | System.out.println(" creating object..."); 95 | ChordSharpConnection cs = new ChordSharpConnection(); 96 | System.out 97 | .println(" `OtpErlangList singleGetSubscribers(OtpErlangString)`..."); 98 | otpSubscribers = cs.singleGetSubscribers(otpTopic); 99 | System.out.println(" getSubscribers(" + otpTopic.stringValue() 100 | + ") == " + getSubscribers(otpSubscribers)); 101 | } catch (ConnectionException e) { 102 | System.out.println(" getSubscribers(" + otpTopic.stringValue() 103 | + ") failed: " + e.getMessage()); 104 | } catch (UnknownException e) { 105 | System.out.println(" getSubscribers(" + otpTopic.stringValue() 106 | + ") failed: " + e.getMessage()); 107 | } 108 | 109 | try { 110 | System.out.println(" creating object..."); 111 | ChordSharpConnection cs = new ChordSharpConnection(); 112 | System.out.println(" `Vector singleGetSubscribers(String)`..."); 113 | subscribers = cs.singleGetSubscribers(topic); 114 | System.out.println(" getSubscribers(" + topic + ") == " 115 | + getSubscribers(subscribers)); 116 | } catch (ConnectionException e) { 117 | System.out.println(" getSubscribers(" + topic + ") failed: " 118 | + e.getMessage()); 119 | } catch (UnknownException e) { 120 | System.out.println(" getSubscribers(" + topic 121 | + ") failed: " + e.getMessage()); 122 | } 123 | } 124 | 125 | /** 126 | * converts the list of strings to a comma-separated list of strings 127 | * 128 | * @param subscribers 129 | * the list of subscribers to convert 130 | * @return a comma-separated list of subscriber URLs 131 | */ 132 | private static String getSubscribers(Vector subscribers) { 133 | StringBuffer result = new StringBuffer(); 134 | for (Iterator iterator = subscribers.iterator(); iterator 135 | .hasNext();) { 136 | result.append(iterator.next()); 137 | result.append(", "); 138 | } 139 | if (result.length() > 2) { 140 | return "[" + result.substring(0, result.length() - 3) + "]"; 141 | } else { 142 | return "[" + result.toString() + "]"; 143 | } 144 | } 145 | 146 | /** 147 | * converts the list of erlang strings to a comma-separated list of strings 148 | * 149 | * @param subscribers 150 | * the list of subscribers to convert 151 | * @return a comma-separated list of subscriber URLs 152 | */ 153 | private static String getSubscribers(OtpErlangList subscribers) { 154 | StringBuffer result = new StringBuffer(); 155 | for (int i = 0; i < subscribers.arity(); ++i) { 156 | result.append(((OtpErlangString) subscribers.elementAt(i)) 157 | .stringValue()); 158 | result.append(", "); 159 | } 160 | if (result.length() > 2) { 161 | return "[" + result.substring(0, result.length() - 3) + "]"; 162 | } else { 163 | return "[" + result.toString() + "]"; 164 | } 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /src/de/zib/chordsharp/examples/ChordSharpConnectionPublishExample.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.chordsharp.examples; 17 | 18 | import com.ericsson.otp.erlang.OtpErlangString; 19 | 20 | import de.zib.chordsharp.ChordSharpConnection; 21 | import de.zib.chordsharp.ConnectionException; 22 | 23 | /** 24 | * Provides an example for using the {@code publish} methods of the 25 | * {@link ChordSharpConnection} class. 26 | * 27 | * @author Nico Kruber, kruber@zib.de 28 | * @version 1.0 29 | */ 30 | @Deprecated 31 | public class ChordSharpConnectionPublishExample { 32 | /** 33 | * Publishes content under a given topic, both provided on the command line, 34 | * with the {@code publish} methods of {@link ChordSharpConnection}.
35 | * If no content or topic is given, the default key {@code "key"} and the 36 | * default value {@code "value"} is used. 37 | * 38 | * @param args 39 | * command line arguments (first argument can be an optional 40 | * topic and the second an optional content) 41 | */ 42 | public static void main(String[] args) { 43 | String topic; 44 | String content; 45 | 46 | if (args.length == 0) { 47 | topic = "topic"; 48 | content = "content"; 49 | } else if (args.length == 1) { 50 | topic = args[0]; 51 | content = "content"; 52 | } else { 53 | topic = args[0]; 54 | content = args[1]; 55 | } 56 | 57 | OtpErlangString otpTopic = new OtpErlangString(topic); 58 | OtpErlangString otpContent = new OtpErlangString(content); 59 | 60 | System.out.println("Publishing content under a topic with the class `ChordSharpConnection`:"); 61 | 62 | // static: 63 | try { 64 | System.out.println(" `static void publish(OtpErlangString, OtpErlangString)`..."); 65 | ChordSharpConnection.publish(otpTopic, otpContent); 66 | System.out.println(" publish(" + otpTopic.stringValue() + ", " + otpContent.stringValue() + ") succeeded"); 67 | } catch (ConnectionException e) { 68 | System.out.println(" publish(" + otpTopic.stringValue() + ", " + otpContent.stringValue() + ") failed: " + e.getMessage()); 69 | } 70 | 71 | try { 72 | System.out.println(" `static void publish(String, String)`..."); 73 | ChordSharpConnection.publish(topic, content); 74 | System.out.println(" publish(" + topic + ", " + content + ") succeeded"); 75 | } catch (ConnectionException e) { 76 | System.out.println(" publish(" + topic + ", " + content + ") failed: " + e.getMessage()); 77 | } 78 | 79 | // non-static: 80 | try { 81 | System.out.println(" creating object..."); 82 | ChordSharpConnection cs = new ChordSharpConnection(); 83 | System.out.println(" `void singlePublish(OtpErlangString, OtpErlangString)`..."); 84 | cs.singlePublish(otpTopic, otpContent); 85 | System.out.println(" publish(" + otpTopic.stringValue() + ", " + otpContent.stringValue() + ") succeeded"); 86 | } catch (ConnectionException e) { 87 | System.out.println(" publish(" + otpTopic.stringValue() + ", " + otpContent.stringValue() + ") failed: " + e.getMessage()); 88 | } 89 | 90 | try { 91 | System.out.println(" creating object..."); 92 | ChordSharpConnection cs = new ChordSharpConnection(); 93 | System.out.println(" `void singlePublish(String, String)`..."); 94 | cs.singlePublish(topic, content); 95 | System.out.println(" publish(" + topic + ", " + content + ") succeeded"); 96 | } catch (ConnectionException e) { 97 | System.out.println(" publish(" + topic + ", " + content + ") failed: " + e.getMessage()); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/de/zib/chordsharp/examples/ChordSharpConnectionReadExample.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.chordsharp.examples; 17 | 18 | import com.ericsson.otp.erlang.OtpErlangString; 19 | 20 | import de.zib.chordsharp.ChordSharpConnection; 21 | import de.zib.chordsharp.ConnectionException; 22 | import de.zib.chordsharp.NotFoundException; 23 | import de.zib.chordsharp.TimeoutException; 24 | import de.zib.chordsharp.UnknownException; 25 | 26 | /** 27 | * Provides an example for using the {@code read} methods of the 28 | * {@link ChordSharpConnection} class. 29 | * 30 | * @author Nico Kruber, kruber@zib.de 31 | * @version 1.0 32 | */ 33 | @Deprecated 34 | public class ChordSharpConnectionReadExample { 35 | /** 36 | * Reads a key given on the command line with the {@code read} methods of 37 | * {@link ChordSharpConnection}.
38 | * If no key is given, the default key {@code "key"} is used. 39 | * 40 | * @param args 41 | * command line arguments (first argument can be an optional key 42 | * to look up) 43 | */ 44 | public static void main(String[] args) { 45 | String key; 46 | String value; 47 | 48 | if (args.length != 1) { 49 | key = "key"; 50 | } else { 51 | key = args[0]; 52 | } 53 | 54 | OtpErlangString otpKey = new OtpErlangString(key); 55 | OtpErlangString otpValue; 56 | 57 | System.out 58 | .println("Reading values with the class `ChordSharpConnection`:"); 59 | 60 | // static: 61 | try { 62 | System.out 63 | .println(" `static OtpErlangString read(OtpErlangString)`..."); 64 | otpValue = ChordSharpConnection.readString(otpKey); 65 | System.out.println(" read(" + otpKey.stringValue() + ") == " 66 | + otpValue.stringValue()); 67 | } catch (ConnectionException e) { 68 | System.out.println(" read(" + otpKey.stringValue() 69 | + ") failed: " + e.getMessage()); 70 | } catch (TimeoutException e) { 71 | System.out.println(" read(" + otpKey.stringValue() 72 | + ") failed with timeout: " + e.getMessage()); 73 | } catch (UnknownException e) { 74 | System.out.println(" read(" + otpKey.stringValue() 75 | + ") failed with unknown: " + e.getMessage()); 76 | } catch (NotFoundException e) { 77 | System.out.println(" read(" + otpKey.stringValue() 78 | + ") failed with not found: " + e.getMessage()); 79 | } 80 | 81 | try { 82 | System.out.println(" `static String read(String)`..."); 83 | value = ChordSharpConnection.readString(key); 84 | System.out.println(" read(" + key + ") == " + value); 85 | } catch (ConnectionException e) { 86 | System.out.println(" read(" + key + ") failed: " 87 | + e.getMessage()); 88 | } catch (TimeoutException e) { 89 | System.out.println(" read(" + key + ") failed with timeout: " 90 | + e.getMessage()); 91 | } catch (UnknownException e) { 92 | System.out.println(" read(" + key + ") failed with unknown: " 93 | + e.getMessage()); 94 | } catch (NotFoundException e) { 95 | System.out.println(" read(" + key + ") failed with not found: " 96 | + e.getMessage()); 97 | } 98 | 99 | // non-static: 100 | try { 101 | System.out.println(" creating object..."); 102 | ChordSharpConnection cs = new ChordSharpConnection(); 103 | System.out 104 | .println(" `OtpErlangString singleRead(OtpErlangString)`..."); 105 | otpValue = cs.singleReadString(otpKey); 106 | System.out.println(" read(" + otpKey.stringValue() + ") == " 107 | + otpValue.stringValue()); 108 | } catch (ConnectionException e) { 109 | System.out.println(" read(" + otpKey.stringValue() 110 | + ") failed: " + e.getMessage()); 111 | } catch (TimeoutException e) { 112 | System.out.println(" read(" + otpKey.stringValue() 113 | + ") failed with timeout: " + e.getMessage()); 114 | } catch (UnknownException e) { 115 | System.out.println(" read(" + otpKey.stringValue() 116 | + ") failed with unknown: " + e.getMessage()); 117 | } catch (NotFoundException e) { 118 | System.out.println(" read(" + otpKey.stringValue() 119 | + ") failed with not found: " + e.getMessage()); 120 | } 121 | 122 | try { 123 | System.out.println(" creating object..."); 124 | ChordSharpConnection cs = new ChordSharpConnection(); 125 | System.out.println(" `String singleRead(String)`..."); 126 | value = cs.singleReadString(key); 127 | System.out.println(" read(" + key + ") == " + value); 128 | } catch (ConnectionException e) { 129 | System.out.println(" read(" + key + ") failed: " 130 | + e.getMessage()); 131 | } catch (TimeoutException e) { 132 | System.out.println(" read(" + key + ") failed with timeout: " 133 | + e.getMessage()); 134 | } catch (UnknownException e) { 135 | System.out.println(" read(" + key + ") failed with unknown: " 136 | + e.getMessage()); 137 | } catch (NotFoundException e) { 138 | System.out.println(" read(" + key 139 | + ") failed with not found: " + e.getMessage()); 140 | } 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /src/de/zib/chordsharp/examples/ChordSharpConnectionSubscribeExample.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.chordsharp.examples; 17 | 18 | import com.ericsson.otp.erlang.OtpErlangString; 19 | 20 | import de.zib.chordsharp.ChordSharpConnection; 21 | import de.zib.chordsharp.ConnectionException; 22 | import de.zib.chordsharp.TimeoutException; 23 | import de.zib.chordsharp.UnknownException; 24 | 25 | /** 26 | * Provides an example for using the {@code subscribe} methods of the 27 | * {@link ChordSharpConnection} class. 28 | * 29 | * @author Nico Kruber, kruber@zib.de 30 | * @version 1.4 31 | */ 32 | @Deprecated 33 | public class ChordSharpConnectionSubscribeExample { 34 | /** 35 | * Subscribes a given URL to a given topic, both provided on the command 36 | * line, with the {@code subscribe} methods of {@link ChordSharpConnection}.
37 | * If no URL or topic is given, the default URL {@code "url"} and the 38 | * default topic {@code "topic"} is used. 39 | * 40 | * @param args 41 | * command line arguments (first argument can be an optional 42 | * topic and the second an optional URL) 43 | */ 44 | public static void main(String[] args) { 45 | String topic; 46 | String URL; 47 | 48 | if (args.length == 0) { 49 | topic = "topic"; 50 | URL = "url"; 51 | } else if (args.length == 1) { 52 | topic = args[0]; 53 | URL = "url"; 54 | } else { 55 | topic = args[0]; 56 | URL = args[1]; 57 | } 58 | 59 | OtpErlangString otpTopic = new OtpErlangString(topic); 60 | OtpErlangString otpURL = new OtpErlangString(URL); 61 | 62 | System.out 63 | .println("Subscribing a URL to a topic with the class `ChordSharpConnection`:"); 64 | 65 | // static: 66 | try { 67 | System.out 68 | .println(" `static void subscribe(OtpErlangString, OtpErlangString)`..."); 69 | ChordSharpConnection.subscribe(otpTopic, otpURL); 70 | System.out.println(" subscribe(" + otpTopic.stringValue() + ", " 71 | + otpURL.stringValue() + ") succeeded"); 72 | } catch (ConnectionException e) { 73 | System.out.println(" subscribe(" + otpTopic.stringValue() + ", " 74 | + otpURL.stringValue() + ") failed: " + e.getMessage()); 75 | } catch (TimeoutException e) { 76 | System.out.println(" subscribe(" + otpTopic.stringValue() + ", " 77 | + otpURL.stringValue() + ") failed with timeout: " 78 | + e.getMessage()); 79 | } catch (UnknownException e) { 80 | System.out.println(" subscribe(" + otpTopic.stringValue() + ", " 81 | + otpURL.stringValue() + ") failed with unknown: " 82 | + e.getMessage()); 83 | } 84 | 85 | try { 86 | System.out.println(" `static void subscribe(String, String)`..."); 87 | ChordSharpConnection.subscribe(topic, URL); 88 | System.out.println(" subscribe(" + topic + ", " + URL 89 | + ") succeeded"); 90 | } catch (ConnectionException e) { 91 | System.out.println(" subscribe(" + topic + ", " + URL 92 | + ") failed: " + e.getMessage()); 93 | } catch (TimeoutException e) { 94 | System.out.println(" subscribe(" + topic + ", " + URL 95 | + ") failed with timeout: " + e.getMessage()); 96 | } catch (UnknownException e) { 97 | System.out.println(" subscribe(" + topic + ", " + URL 98 | + ") failed with unknown: " + e.getMessage()); 99 | } 100 | 101 | // non-static: 102 | try { 103 | System.out.println(" creating object..."); 104 | ChordSharpConnection cs = new ChordSharpConnection(); 105 | System.out 106 | .println(" `void singleSubscribe(OtpErlangString, OtpErlangString)`..."); 107 | cs.singleSubscribe(otpTopic, otpURL); 108 | System.out.println(" subscribe(" + otpTopic.stringValue() 109 | + ", " + otpURL.stringValue() + ") succeeded"); 110 | } catch (ConnectionException e) { 111 | System.out.println(" subscribe(" + otpTopic.stringValue() 112 | + ", " + otpURL.stringValue() + ") failed: " 113 | + e.getMessage()); 114 | } catch (TimeoutException e) { 115 | System.out.println(" subscribe(" + otpTopic.stringValue() 116 | + ", " + otpURL.stringValue() + ") failed with timeout: " 117 | + e.getMessage()); 118 | } catch (UnknownException e) { 119 | System.out.println(" subscribe(" + otpTopic.stringValue() 120 | + ", " + otpURL.stringValue() + ") failed with unknown: " 121 | + e.getMessage()); 122 | } 123 | 124 | try { 125 | System.out.println(" creating object..."); 126 | ChordSharpConnection cs = new ChordSharpConnection(); 127 | System.out.println(" `void singleSubscribe(String, String)`..."); 128 | cs.singleSubscribe(topic, URL); 129 | System.out.println(" subscribe(" + topic + ", " + URL 130 | + ") succeeded"); 131 | } catch (ConnectionException e) { 132 | System.out.println(" subscribe(" + topic + ", " + URL 133 | + ") failed: " + e.getMessage()); 134 | } catch (TimeoutException e) { 135 | System.out.println(" subscribe(" + topic + ", " + URL 136 | + ") failed with timeout: " + e.getMessage()); 137 | } catch (UnknownException e) { 138 | System.out.println(" subscribe(" + topic + ", " + URL 139 | + ") failed with unknown: " + e.getMessage()); 140 | } 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /src/de/zib/chordsharp/examples/ChordSharpConnectionWriteExample.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.chordsharp.examples; 17 | 18 | import com.ericsson.otp.erlang.OtpErlangString; 19 | 20 | import de.zib.chordsharp.ChordSharpConnection; 21 | import de.zib.chordsharp.ConnectionException; 22 | import de.zib.chordsharp.TimeoutException; 23 | import de.zib.chordsharp.UnknownException; 24 | 25 | /** 26 | * Provides an example for using the {@code write} methods of the 27 | * {@link ChordSharpConnection} class. 28 | * 29 | * @author Nico Kruber, kruber@zib.de 30 | * @version 1.0 31 | */ 32 | @Deprecated 33 | public class ChordSharpConnectionWriteExample { 34 | /** 35 | * Writes a key/value pair given on the command line with the {@code write} 36 | * methods of {@link ChordSharpConnection}.
37 | * If no value or key is given, the default key {@code "key"} and the 38 | * default value {@code "value"} is used. 39 | * 40 | * @param args 41 | * command line arguments (first argument can be an optional key 42 | * and the second an optional value) 43 | */ 44 | public static void main(String[] args) { 45 | String key; 46 | String value; 47 | 48 | if (args.length == 0) { 49 | key = "key"; 50 | value = "value"; 51 | } else if (args.length == 1) { 52 | key = args[0]; 53 | value = "value"; 54 | } else { 55 | key = args[0]; 56 | value = args[1]; 57 | } 58 | 59 | OtpErlangString otpKey = new OtpErlangString(key); 60 | OtpErlangString otpValue = new OtpErlangString(value); 61 | 62 | System.out 63 | .println("Writing values with the class `ChordSharpConnection`:"); 64 | 65 | // static: 66 | try { 67 | System.out.println(" `static void write(OtpErlangString, OtpErlangString)`..."); 68 | ChordSharpConnection.write(otpKey, otpValue); 69 | System.out.println(" write(" + otpKey.stringValue() + ", " 70 | + otpValue.stringValue() + ") succeeded"); 71 | } catch (ConnectionException e) { 72 | System.out.println(" write(" + otpKey.stringValue() + ", " 73 | + otpValue.stringValue() + ") failed: " + e.getMessage()); 74 | } catch (TimeoutException e) { 75 | System.out.println(" write(" + otpKey.stringValue() + ", " 76 | + otpValue.stringValue() + ") failed with timeout: " 77 | + e.getMessage()); 78 | } catch (UnknownException e) { 79 | System.out.println(" write(" + otpKey.stringValue() + ", " 80 | + otpValue.stringValue() + ") failed with unknown: " 81 | + e.getMessage()); 82 | } 83 | 84 | try { 85 | System.out.println(" `static void write(String, String)`..."); 86 | ChordSharpConnection.write(key, value); 87 | System.out.println(" write(" + key + ", " + value 88 | + ") succeeded"); 89 | } catch (ConnectionException e) { 90 | System.out.println(" write(" + key + ", " + value + ") failed: " 91 | + e.getMessage()); 92 | } catch (TimeoutException e) { 93 | System.out.println(" write(" + key + ", " + value 94 | + ") failed with timeout: " + e.getMessage()); 95 | } catch (UnknownException e) { 96 | System.out.println(" write(" + key + ", " + value 97 | + ") failed with unknown: " + e.getMessage()); 98 | } 99 | 100 | // non-static: 101 | try { 102 | System.out.println(" creating object..."); 103 | ChordSharpConnection cs = new ChordSharpConnection(); 104 | System.out 105 | .println(" `void singleWrite(OtpErlangString, OtpErlangString)`..."); 106 | cs.singleWrite(otpKey, otpValue); 107 | System.out.println(" write(" + otpKey.stringValue() + ", " 108 | + otpValue.stringValue() + ") succeeded"); 109 | } catch (ConnectionException e) { 110 | System.out.println(" write(" + otpKey.stringValue() + ", " 111 | + otpValue.stringValue() + ") failed: " + e.getMessage()); 112 | } catch (TimeoutException e) { 113 | System.out.println(" write(" + otpKey.stringValue() + ", " 114 | + otpValue.stringValue() + ") failed with timeout: " 115 | + e.getMessage()); 116 | } catch (UnknownException e) { 117 | System.out.println(" write(" + otpKey.stringValue() + ", " 118 | + otpValue.stringValue() + ") failed with unknown: " 119 | + e.getMessage()); 120 | } 121 | 122 | try { 123 | System.out.println(" creating object..."); 124 | ChordSharpConnection cs = new ChordSharpConnection(); 125 | System.out.println(" `void singleWrite(String, String)`..."); 126 | cs.singleWrite(key, value); 127 | System.out.println(" write(" + key + ", " + value 128 | + ") succeeded"); 129 | } catch (ConnectionException e) { 130 | System.out.println(" write(" + key + ", " + value 131 | + ") failed: " + e.getMessage()); 132 | } catch (TimeoutException e) { 133 | System.out.println(" write(" + key + ", " + value 134 | + ") failed with timeout: " + e.getMessage()); 135 | } catch (UnknownException e) { 136 | System.out.println(" write(" + key + ", " + value 137 | + ") failed with unknown: " + e.getMessage()); 138 | } 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /src/de/zib/chordsharp/examples/TransactionParallelReadsExample.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.chordsharp.examples; 17 | 18 | import java.util.Vector; 19 | 20 | import com.ericsson.otp.erlang.OtpErlangList; 21 | import com.ericsson.otp.erlang.OtpErlangString; 22 | 23 | import de.zib.chordsharp.ConnectionException; 24 | import de.zib.chordsharp.Transaction; 25 | import de.zib.chordsharp.TransactionNotFinishedException; 26 | import de.zib.chordsharp.UnknownException; 27 | 28 | /** 29 | * Provides an example for using the {@code parallelReads} method of the 30 | * {@link Transaction} class. 31 | * 32 | * @author Nico Kruber, kruber@zib.de 33 | * @version 1.0 34 | */ 35 | @Deprecated 36 | public class TransactionParallelReadsExample { 37 | /** 38 | * Reads all keys given on the command line (given as "key1 key2 ...") with 39 | * the {@link Transaction#parallelReads(String[])} and 40 | * {@link Transaction#parallelReads(OtpErlangList)} methods in a single 41 | * transaction.
42 | * If no keys are given, the default keys {@code "key1"}, {@code "key2"}, 43 | * {@code "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 | Vector values; 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 | OtpErlangList otpValues; 64 | 65 | System.out 66 | .println("Reading values with the class `Transaction`:"); 67 | 68 | System.out.print(" Initialising Transaction object... "); 69 | try { 70 | Transaction transaction = new Transaction(); 71 | System.out.println("done"); 72 | 73 | System.out.print(" Starting transaction... "); 74 | transaction.start(); 75 | System.out.println("done"); 76 | 77 | System.out.println(" `OtpErlangList parallelReads(OtpErlangList)`..."); 78 | try { 79 | otpValues = transaction.parallelReads(otpKeys); 80 | System.out.println(" parallelReads(" + otpKeys.toString() 81 | + ") == " + otpValues.toString()); 82 | } catch (ConnectionException e) { 83 | System.out.println(" parallelReads(" + otpKeys.toString() 84 | + ") failed: " + e.getMessage()); 85 | } catch (UnknownException e) { 86 | System.out.println(" parallelReads(" + otpKeys.toString() 87 | + ") failed with unknown: " + e.getMessage()); 88 | } 89 | 90 | System.out.println(" `Vector parallelReads(String[])`..."); 91 | try { 92 | values = transaction.parallelReads(keys); 93 | System.out.println(" parallelReads(" + keys + ") == " + values); 94 | } catch (ConnectionException e) { 95 | System.out.println(" parallelReads(" + keys + ") failed: " 96 | + e.getMessage()); 97 | } catch (UnknownException e) { 98 | System.out.println(" parallelReads(" + keys 99 | + ") failed with unknown: " + e.getMessage()); 100 | } 101 | 102 | System.out.print(" Committing transaction... "); 103 | transaction.commit(); 104 | System.out.println("done"); 105 | } catch (ConnectionException e) { 106 | System.out.println("failed: " + e.getMessage()); 107 | return; 108 | } catch (TransactionNotFinishedException e) { 109 | System.out.println("failed: " + e.getMessage()); 110 | return; 111 | } catch (UnknownException e) { 112 | System.out.println("failed: " + e.getMessage()); 113 | return; 114 | } 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /src/de/zib/chordsharp/examples/TransactionReadExample.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.chordsharp.examples; 17 | 18 | import com.ericsson.otp.erlang.OtpErlangList; 19 | import com.ericsson.otp.erlang.OtpErlangString; 20 | 21 | import de.zib.chordsharp.ConnectionException; 22 | import de.zib.chordsharp.NotFoundException; 23 | import de.zib.chordsharp.TimeoutException; 24 | import de.zib.chordsharp.Transaction; 25 | import de.zib.chordsharp.TransactionNotFinishedException; 26 | import de.zib.chordsharp.UnknownException; 27 | 28 | /** 29 | * Provides an example for using the {@code read} method of the 30 | * {@link Transaction} class. 31 | * 32 | * @author Nico Kruber, kruber@zib.de 33 | * @version 1.0 34 | */ 35 | @Deprecated 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#read(OtpErlangString)} methods in a single 41 | * transaction.
42 | * If no keys are given, the default keys {@code "key1"}, {@code "key2"}, 43 | * {@code "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 66 | .println("Reading values with the class `Transaction`:"); 67 | 68 | System.out.print(" Initialising Transaction object... "); 69 | try { 70 | Transaction transaction = new Transaction(); 71 | System.out.println("done"); 72 | 73 | System.out.print(" Starting transaction... "); 74 | transaction.start(); 75 | System.out.println("done"); 76 | 77 | System.out.println(" `OtpErlangString read(OtpErlangString)`..."); 78 | for (int i = 0; i < otpKeys.arity(); ++i) { 79 | OtpErlangString key = (OtpErlangString) otpKeys.elementAt(i); 80 | try { 81 | otpValue = transaction.readString(key); 82 | System.out.println(" read(" + key.stringValue() 83 | + ") == " + otpValue.stringValue()); 84 | } catch (ConnectionException e) { 85 | System.out.println(" read(" + key.stringValue() 86 | + ") failed: " + e.getMessage()); 87 | } catch (TimeoutException e) { 88 | System.out.println(" read(" + key.stringValue() 89 | + ") failed with timeout: " + e.getMessage()); 90 | } catch (UnknownException e) { 91 | System.out.println(" read(" + key.stringValue() 92 | + ") failed with unknown: " + e.getMessage()); 93 | } catch (NotFoundException e) { 94 | System.out.println(" read(" + key.stringValue() 95 | + ") failed with not found: " + e.getMessage()); 96 | } 97 | } 98 | 99 | System.out.println(" `String read(String)`..."); 100 | for (int i = 0; i < keys.length; ++i) { 101 | String key = keys[i]; 102 | try { 103 | value = transaction.readString(key); 104 | System.out.println(" read(" + key + ") == " + value); 105 | } catch (ConnectionException e) { 106 | System.out.println(" read(" + key + ") failed: " 107 | + e.getMessage()); 108 | } catch (TimeoutException e) { 109 | System.out.println(" read(" + key 110 | + ") failed with timeout: " + e.getMessage()); 111 | } catch (UnknownException e) { 112 | System.out.println(" read(" + key 113 | + ") failed with unknown: " + e.getMessage()); 114 | } catch (NotFoundException e) { 115 | System.out.println(" read(" + key 116 | + ") failed with not found: " + e.getMessage()); 117 | } 118 | } 119 | 120 | System.out.print(" Committing transaction... "); 121 | transaction.commit(); 122 | System.out.println("done"); 123 | } catch (ConnectionException e) { 124 | System.out.println("failed: " + e.getMessage()); 125 | return; 126 | } catch (TransactionNotFinishedException e) { 127 | System.out.println("failed: " + e.getMessage()); 128 | return; 129 | } catch (UnknownException e) { 130 | System.out.println("failed: " + e.getMessage()); 131 | return; 132 | } 133 | } 134 | 135 | } 136 | -------------------------------------------------------------------------------- /src/de/zib/chordsharp/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.chordsharp.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.chordsharp.ConnectionException; 23 | import de.zib.chordsharp.TimeoutException; 24 | import de.zib.chordsharp.Transaction; 25 | import de.zib.chordsharp.TransactionNotFinishedException; 26 | import de.zib.chordsharp.UnknownException; 27 | 28 | /** 29 | * Provides an example for using the {@code write} method of the 30 | * {@link Transaction} class. 31 | * 32 | * @author Nico Kruber, kruber@zib.de 33 | * @version 1.0 34 | */ 35 | @Deprecated 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#write(OtpErlangString, OtpErlangObject)} methods in a 42 | * single transaction.
43 | * If no key/value pair is given, the default pairs {@code (key1, value1)}, 44 | * {@code (key2, value2)} and {@code (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(" `write(OtpErlangString, OtpErlangString)`..."); 90 | for (int i = 0; i < otpKeys.arity(); ++i) { 91 | OtpErlangString key = (OtpErlangString) otpKeys.elementAt(i); 92 | OtpErlangString value = (OtpErlangString) otpValues 93 | .elementAt(i); 94 | try { 95 | transaction.write(key, value); 96 | System.out.println(" write(" + key.stringValue() 97 | + ", " + value.stringValue() + ") succeeded"); 98 | } catch (ConnectionException e) { 99 | System.out.println(" write(" + key.stringValue() 100 | + ", " + value.stringValue() + ") failed: " 101 | + e.getMessage()); 102 | } catch (TimeoutException e) { 103 | System.out.println(" write(" + key.stringValue() 104 | + ", " + value.stringValue() 105 | + ") failed with timeout: " + e.getMessage()); 106 | } catch (UnknownException e) { 107 | System.out.println(" write(" + key.stringValue() 108 | + ", " + value.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/chordsharp/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.chordsharp} package. 18 | */ 19 | package de.zib.chordsharp.examples; 20 | 21 | -------------------------------------------------------------------------------- /src/de/zib/chordsharp/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 chordsharp ring from Java. 18 | * 19 | *

The ChordSharp class

20 | *

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 | *

Example:

27 | * 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 | *

The ChordSharpConnection class

44 | *

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 | *

Example:

51 | * 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 | *

The Transaction class

69 | *

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 | *

Example:

76 | * 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 | * @param 26 | * java type to use 27 | * 28 | * @author Nico Kruber, kruber@zib.de 29 | * @version 2.1 30 | * @since 2.1 31 | */ 32 | public abstract class CustomOtpObject { 33 | /** 34 | * The contained value as a Java type. 35 | */ 36 | protected JavaType value = null; 37 | /** 38 | * The contained value as an erlang type. 39 | */ 40 | protected OtpErlangObject otpValue = null; 41 | 42 | /** 43 | * Creates a new and empty object. 44 | */ 45 | public CustomOtpObject() { 46 | } 47 | 48 | /** 49 | * Creates an object with the given (Java) value. 50 | * 51 | * @param value 52 | * the value to use 53 | */ 54 | public CustomOtpObject(JavaType value) { 55 | this.value = value; 56 | } 57 | 58 | /** 59 | * Creates an object with the given (erlang) value. 60 | * 61 | * @param otpValue 62 | * the value to use 63 | */ 64 | public CustomOtpObject(OtpErlangObject otpValue) { 65 | this.otpValue = otpValue; 66 | } 67 | 68 | /** 69 | * Returns the stored value as a Java type. If the value stored is an erlang 70 | * object it is converted to a java value once. 71 | * 72 | * Future calls will not convert the value. 73 | * 74 | * @return the stored value 75 | * 76 | * @throws ClassCastException 77 | * if the conversion fails 78 | */ 79 | public JavaType getValue() throws ClassCastException { 80 | if (value == null) { 81 | convertFromOtpObject(); 82 | } 83 | return value; 84 | } 85 | 86 | /** 87 | * Returns the stored value as an erlang type. If the value stored is a Java 88 | * object it is converted to an erlang value once. 89 | * 90 | * Future calls will not convert the value. 91 | * 92 | * @return the stored value 93 | */ 94 | public OtpErlangObject getOtpValue() { 95 | if (otpValue == null) { 96 | convertToOtpObject(); 97 | } 98 | return otpValue; 99 | } 100 | 101 | /** 102 | * Converts {@link #value} to an erlang object and saves it to 103 | * {@link #otpValue}. 104 | */ 105 | public abstract void convertToOtpObject(); 106 | 107 | /** 108 | * Converts {@link #otpValue} to a Java object and saves it to 109 | * {@link #value}. 110 | * 111 | * @throws ClassCastException 112 | * if the conversion fails 113 | */ 114 | public abstract void convertFromOtpObject() throws ClassCastException; 115 | 116 | /** 117 | * Sets the stored Java value. 118 | * 119 | * @param value 120 | * the value to set 121 | */ 122 | public void setValue(JavaType value) { 123 | this.value = value; 124 | } 125 | 126 | /** 127 | * Sets the stored erlang value. 128 | * 129 | * @param otpValue 130 | * the otpValue to set 131 | */ 132 | public void setOtpValue(OtpErlangObject otpValue) { 133 | this.otpValue = otpValue; 134 | } 135 | 136 | /** 137 | * 138 | */ 139 | public void clear() { 140 | value = null; 141 | otpValue = null; 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /src/de/zib/scalaris/CustomOtpStringObject.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 | import com.ericsson.otp.erlang.OtpErlangString; 20 | 21 | /** 22 | * Implements a {@link CustomOtpObject} that allows {@link String} objects to be 23 | * written to scalaris. 24 | * 25 | * @author Nico Kruber, kruber@zib.de 26 | * @version 2.1 27 | * @since 2.1 28 | */ 29 | public class CustomOtpStringObject extends CustomOtpObject { 30 | /** 31 | * Creates a new and empty object. 32 | */ 33 | public CustomOtpStringObject() { 34 | super(); 35 | } 36 | 37 | /** 38 | * Creates an object with the given (Java) value. 39 | * 40 | * @param value 41 | * the value to use 42 | */ 43 | public CustomOtpStringObject(String value) { 44 | super(value); 45 | } 46 | 47 | /** 48 | * Creates an object with the given (erlang) value. 49 | * 50 | * @param otpValue 51 | * the value to use 52 | */ 53 | public CustomOtpStringObject(OtpErlangObject otpValue) { 54 | super(otpValue); 55 | } 56 | 57 | /** 58 | * Converts {@link #value} to an erlang object and saves it to 59 | * {@link #otpValue}. 60 | */ 61 | @Override 62 | public void convertToOtpObject() { 63 | otpValue = new OtpErlangString(value); 64 | } 65 | 66 | /** 67 | * Converts {@link #otpValue} to a Java object and saves it to 68 | * {@link #value}. 69 | * 70 | * @throws ClassCastException 71 | * if the conversion fails 72 | */ 73 | @Override 74 | public void convertFromOtpObject() { 75 | value = ((OtpErlangString) otpValue).stringValue(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/de/zib/scalaris/DeleteResult.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package de.zib.scalaris; 5 | 6 | import com.ericsson.otp.erlang.OtpErlangAtom; 7 | import com.ericsson.otp.erlang.OtpErlangList; 8 | 9 | /** 10 | * Stores the result of a delete operation. 11 | * 12 | * @author Nico Kruber, kruber@zib.de 13 | * @version 2.2 14 | * @since 2.2 15 | * 16 | * @see Scalaris#delete(String) 17 | */ 18 | public class DeleteResult { 19 | /** 20 | * Number of successfully deleted replicas. 21 | */ 22 | public int ok = 0; 23 | /** 24 | * Skipped replicas because locks were set. 25 | */ 26 | public int locks_set = 0; 27 | /** 28 | * Skipped replicas because they did not exist. 29 | */ 30 | public int undef = 0; 31 | 32 | /** 33 | * Creates a delete state object by converting the result list returned from 34 | * erlang. 35 | * 36 | * @param list 37 | * the list to convert 38 | * @throws UnknownException 39 | * is thrown if an unknown reason was encountered 40 | */ 41 | public DeleteResult(OtpErlangList list) throws UnknownException { 42 | if (list != null) { 43 | for (int i = 0; i < list.arity(); ++i) { 44 | OtpErlangAtom element = (OtpErlangAtom) list.elementAt(i); 45 | if (element.equals(new OtpErlangAtom("ok"))) { 46 | ++ok; 47 | } else if (element.equals(new OtpErlangAtom("locks_set"))) { 48 | ++locks_set; 49 | } else if (element.equals(new OtpErlangAtom("undef"))) { 50 | ++undef; 51 | } else { 52 | throw new UnknownException("Unknow reason: " 53 | + element.atomValue()); 54 | } 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/de/zib/scalaris/NodeNotFoundException.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 delete operation on a scalaris ring fails 23 | * because no scalaris node was found. 24 | * 25 | * @author Nico Kruber, kruber@zib.de 26 | * @version 2.2 27 | * @since 2.2 28 | */ 29 | public class NodeNotFoundException extends OtpErlangException { 30 | /** 31 | * class version for serialisation 32 | */ 33 | private static final long serialVersionUID = 1L; 34 | 35 | /** 36 | * Creates the exception with no message. 37 | */ 38 | public NodeNotFoundException() { 39 | } 40 | 41 | /** 42 | * Creates the exception with the given message. 43 | * 44 | * @param msg 45 | * message of the exception 46 | */ 47 | public NodeNotFoundException(String msg) { 48 | super(msg); 49 | } 50 | 51 | /** 52 | * Creates an exception taking the message of the given throwable. 53 | * 54 | * @param e the exception to "re-throw" 55 | */ 56 | public NodeNotFoundException(Throwable e) { 57 | super(e.getMessage()); 58 | } 59 | 60 | /** 61 | * Creates an exception including the message of the given erlang object. 62 | * 63 | * @param erlValue 64 | * the erlang message to include 65 | * 66 | * @since 2.2 67 | */ 68 | public NodeNotFoundException(OtpErlangObject erlValue) { 69 | super("Erlang message: " + erlValue.toString()); 70 | } 71 | 72 | /** 73 | * Creates an exception taking the message of the given throwable. 74 | * 75 | * @param e 76 | * the exception to "re-throw" 77 | * @param erlValue 78 | * the string representation of this erlang value is included 79 | * into the message 80 | */ 81 | public NodeNotFoundException(Throwable e, OtpErlangObject erlValue) { 82 | super(e.getMessage() + ",\n Erlang message: " + erlValue.toString()); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/de/zib/scalaris/NotFoundException.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 key did not exist before. 24 | * 25 | * @author Nico Kruber, kruber@zib.de 26 | * @version 2.2 27 | * @since 2.0 28 | */ 29 | public class NotFoundException extends OtpErlangException { 30 | /** 31 | * class version for serialisation 32 | */ 33 | private static final long serialVersionUID = 1L; 34 | 35 | /** 36 | * Creates the exception with no message. 37 | */ 38 | public NotFoundException() { 39 | } 40 | 41 | /** 42 | * Creates the exception with the given message. 43 | * 44 | * @param msg 45 | * message of the exception 46 | */ 47 | public NotFoundException(String msg) { 48 | super(msg); 49 | } 50 | 51 | /** 52 | * Creates an exception taking the message of the given throwable. 53 | * 54 | * @param e the exception to "re-throw" 55 | */ 56 | public NotFoundException(Throwable e) { 57 | super(e.getMessage()); 58 | } 59 | 60 | /** 61 | * Creates an exception including the message of the given erlang object. 62 | * 63 | * @param erlValue 64 | * the erlang message to include 65 | * 66 | * @since 2.2 67 | */ 68 | public NotFoundException(OtpErlangObject erlValue) { 69 | super("Erlang message: " + erlValue.toString()); 70 | } 71 | 72 | /** 73 | * Creates an exception taking the message of the given throwable. 74 | * 75 | * @param e 76 | * the exception to "re-throw" 77 | * @param erlValue 78 | * the string representation of this erlang value is included 79 | * into the message 80 | * 81 | * @since 2.2 82 | */ 83 | public NotFoundException(Throwable e, OtpErlangObject erlValue) { 84 | super(e.getMessage() + ",\n Erlang message: " + erlValue.toString()); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/de/zib/scalaris/TimeoutException.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 or write operation on a scalaris ring 23 | * fails due to a timeout. 24 | * 25 | * @author Nico Kruber, kruber@zib.de 26 | * @version 2.2 27 | * @since 2.0 28 | */ 29 | public class TimeoutException extends OtpErlangException { 30 | /** 31 | * class version for serialisation 32 | */ 33 | private static final long serialVersionUID = 1L; 34 | 35 | /** 36 | * Creates the exception with no message. 37 | */ 38 | public TimeoutException() { 39 | } 40 | 41 | /** 42 | * Creates the exception with the given message. 43 | * 44 | * @param msg 45 | * message of the exception 46 | */ 47 | public TimeoutException(String msg) { 48 | super(msg); 49 | } 50 | 51 | /** 52 | * Creates an exception taking the message of the given throwable. 53 | * 54 | * @param e the exception to "re-throw" 55 | */ 56 | public TimeoutException(Throwable e) { 57 | super(e.getMessage()); 58 | } 59 | 60 | /** 61 | * Creates an exception including the message of the given erlang object. 62 | * 63 | * @param erlValue 64 | * the erlang message to include 65 | * 66 | * @since 2.2 67 | */ 68 | public TimeoutException(OtpErlangObject erlValue) { 69 | super("Erlang message: " + erlValue.toString()); 70 | } 71 | 72 | /** 73 | * Creates an exception taking the message of the given throwable. 74 | * 75 | * @param e 76 | * the exception to "re-throw" 77 | * @param erlValue 78 | * the string representation of this erlang value is included 79 | * into the message 80 | * 81 | * @since 2.2 82 | */ 83 | public TimeoutException(Throwable e, OtpErlangObject erlValue) { 84 | super(e.getMessage() + ",\n Erlang message: " + erlValue.toString()); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/de/zib/scalaris/TransactionNotFinishedException.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 | /** 19 | * Exception that is thrown when a new transaction is started although the old 20 | * one has not been committed or aborted. 21 | * 22 | * @author Nico Kruber, kruber@zib.de 23 | * @version 2.0 24 | * @since 2.0 25 | */ 26 | public class TransactionNotFinishedException extends Exception { 27 | /** 28 | * class version for serialisation 29 | */ 30 | private static final long serialVersionUID = 1L; 31 | 32 | /** 33 | * Creates the exception with no message. 34 | */ 35 | public TransactionNotFinishedException() { 36 | super("Cannot start a new transaction until the old one is not committed or aborted."); 37 | } 38 | 39 | /** 40 | * Creates the exception with the given message. 41 | * 42 | * @param msg 43 | * message of the exception 44 | */ 45 | public TransactionNotFinishedException(String msg) { 46 | super(msg); 47 | } 48 | 49 | /** 50 | * Creates an exception taking the message of the given throwable. 51 | * 52 | * @param e the exception to "re-throw" 53 | */ 54 | public TransactionNotFinishedException(Throwable e) { 55 | super(e.getMessage()); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/de/zib/scalaris/TransactionNotStartedException.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 | /** 19 | * Exception that is thrown when a new transaction is not started but is used 20 | * nevertheless. Since this is a programmer's mistake, a RuntimeException is 21 | * chosen as the base class which eliminates the need to specify the exception 22 | * in a throws clause. 23 | * 24 | * @author Nico Kruber, kruber@zib.de 25 | * @version 2.0 26 | * @since 2.0 27 | */ 28 | public class TransactionNotStartedException extends RuntimeException { 29 | /** 30 | * class version for serialisation 31 | */ 32 | private static final long serialVersionUID = 1L; 33 | 34 | /** 35 | * Creates the exception with no message. 36 | */ 37 | public TransactionNotStartedException() { 38 | super("The transaction needs to be started before it is used."); 39 | } 40 | 41 | /** 42 | * Creates the exception with the given message. 43 | * 44 | * @param msg 45 | * message of the exception 46 | */ 47 | public TransactionNotStartedException(String msg) { 48 | super(msg); 49 | } 50 | 51 | /** 52 | * Creates an exception taking the message of the given throwable. 53 | * 54 | * @param e the exception to "re-throw" 55 | */ 56 | public TransactionNotStartedException(Throwable e) { 57 | super(e.getMessage()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/de/zib/scalaris/UnknownException.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 | * Generic exception that is thrown during read or write operations on a 23 | * scalaris ring. The reason is anything else but a timeout or not_found. They 24 | * are handled in {@link TimeoutException} and {@link NotFoundException}. 25 | * 26 | * @author Nico Kruber, kruber@zib.de 27 | * @version 2.2 28 | * @since 2.0 29 | */ 30 | public class UnknownException extends OtpErlangException { 31 | /** 32 | * class version for serialisation 33 | */ 34 | private static final long serialVersionUID = 1L; 35 | 36 | /** 37 | * Creates the exception with no message. 38 | */ 39 | public UnknownException() { 40 | } 41 | 42 | /** 43 | * Creates the exception with the given message. 44 | * 45 | * @param msg 46 | * message of the exception 47 | */ 48 | public UnknownException(String msg) { 49 | super(msg); 50 | } 51 | 52 | /** 53 | * Creates an exception taking the message of the given throwable. 54 | * 55 | * @param e 56 | * the exception to "re-throw" 57 | */ 58 | public UnknownException(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 UnknownException(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 UnknownException(Throwable e, OtpErlangObject erlValue) { 86 | super(e.getMessage() + ",\n Erlang message: " + erlValue.toString()); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/de/zib/scalaris/examples/CustomOtpFastStringObject.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.OtpErlangAtom; 19 | import com.ericsson.otp.erlang.OtpErlangBinary; 20 | import com.ericsson.otp.erlang.OtpErlangObject; 21 | import com.ericsson.otp.erlang.OtpErlangString; 22 | import com.ericsson.otp.erlang.OtpErlangTuple; 23 | 24 | import de.zib.scalaris.CustomOtpObject; 25 | 26 | /** 27 | * Implements a faster {@link String} storage mechanism if only Java access to 28 | * scalaris is used. 29 | * 30 | *

31 | * 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 | *

41 | * 42 | * @author Nico Kruber, kruber@zib.de 43 | * @version 2.1 44 | * @since 2.1 45 | */ 46 | public class CustomOtpFastStringObject extends CustomOtpObject { 47 | /** 48 | * Identifies the tuple of the stored erlang object. 49 | */ 50 | private OtpErlangAtom identifier = new OtpErlangAtom("custom_fast_string"); 51 | 52 | /** 53 | * Creates an empty object. 54 | */ 55 | public CustomOtpFastStringObject() { 56 | super(); 57 | } 58 | 59 | /** 60 | * Creates an object with the given (Java) value. 61 | * 62 | * @param value 63 | * the value to use 64 | */ 65 | public CustomOtpFastStringObject(String value) { 66 | super(value); 67 | } 68 | 69 | /** 70 | * Creates an object with the given (erlang) value. 71 | * 72 | * @param otpValue 73 | * the value to use 74 | */ 75 | public CustomOtpFastStringObject(OtpErlangObject otpValue) { 76 | super(otpValue); 77 | } 78 | 79 | /** 80 | * Converts {@link #value} to an erlang object and saves it to 81 | * {@link #otpValue}. 82 | */ 83 | @Override 84 | public void convertToOtpObject() { 85 | otpValue = new OtpErlangTuple(new OtpErlangObject[] { identifier, 86 | new OtpErlangBinary(value.getBytes()) }); 87 | } 88 | 89 | /** 90 | * Converts {@link #otpValue} to a Java object and saves it to 91 | * {@link #value}. 92 | * 93 | * {@link #otpValue} is assumed to be either a tuple with its first element 94 | * being {@link #identifier} and its second the binary containing a string 95 | * representation or a {@link OtpErlangString}. 96 | * 97 | * @throws ClassCastException 98 | * if the conversion fails 99 | */ 100 | @Override 101 | public void convertFromOtpObject() { 102 | if (otpValue instanceof OtpErlangTuple) { 103 | OtpErlangTuple otpTuple = (OtpErlangTuple) otpValue; 104 | if (otpTuple.elementAt(0).equals(identifier)) { 105 | value = new String(((OtpErlangBinary) otpTuple.elementAt(0)) 106 | .binaryValue()); 107 | return; 108 | } 109 | } else if (otpValue instanceof OtpErlangString) { 110 | value = ((OtpErlangString) otpValue).stringValue(); 111 | return; 112 | } 113 | 114 | throw new ClassCastException("Unexpected result type: " 115 | + otpValue.getClass()); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/de/zib/scalaris/examples/ScalarisGetSubscribersExample.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 java.util.Iterator; 19 | import java.util.List; 20 | 21 | import com.ericsson.otp.erlang.OtpErlangList; 22 | import com.ericsson.otp.erlang.OtpErlangString; 23 | 24 | import de.zib.scalaris.ConnectionException; 25 | import de.zib.scalaris.Scalaris; 26 | import de.zib.scalaris.UnknownException; 27 | 28 | /** 29 | * Provides an example for using the getSubscribers methods of the 30 | * {@link Scalaris} class. 31 | * 32 | * @author Nico Kruber, kruber@zib.de 33 | * @version 2.0 34 | * @since 2.0 35 | */ 36 | public class ScalarisGetSubscribersExample { 37 | /** 38 | * Prints a list of all subscribers to a given topic, provided on the 39 | * command line with the getSubscribers methods of 40 | * {@link Scalaris}.
41 | * If no topic is given, the default topic "topic" is used. 42 | * 43 | * @param args 44 | * command line arguments (first argument can be an optional 45 | * topic to get the subscribers for) 46 | */ 47 | public static void main(String[] args) { 48 | String topic; 49 | 50 | if (args.length != 1) { 51 | topic = "topic"; 52 | } else { 53 | topic = args[0]; 54 | } 55 | 56 | OtpErlangString otpTopic = new OtpErlangString(topic); 57 | 58 | OtpErlangList otpSubscribers; 59 | List subscribers; 60 | 61 | System.out.println("Reading values with the class `Scalaris`:"); 62 | 63 | try { 64 | System.out.println(" creating object..."); 65 | Scalaris sc = new Scalaris(); 66 | System.out 67 | .println(" `OtpErlangList getSubscribers(OtpErlangString)`..."); 68 | otpSubscribers = sc.getSubscribers(otpTopic); 69 | System.out.println(" getSubscribers(" + otpTopic.stringValue() 70 | + ") == " + getSubscribers(otpSubscribers)); 71 | } catch (ConnectionException e) { 72 | System.out.println(" getSubscribers(" + otpTopic.stringValue() 73 | + ") failed: " + e.getMessage()); 74 | } catch (UnknownException e) { 75 | System.out.println(" getSubscribers(" + otpTopic.stringValue() 76 | + ") failed: " + e.getMessage()); 77 | } 78 | 79 | try { 80 | System.out.println(" creating object..."); 81 | Scalaris sc = new Scalaris(); 82 | System.out 83 | .println(" `Vector getSubscribers(String)`..."); 84 | subscribers = sc.getSubscribers(topic); 85 | System.out.println(" getSubscribers(" + topic + ") == " 86 | + getSubscribers(subscribers)); 87 | } catch (ConnectionException e) { 88 | System.out.println(" getSubscribers(" + topic + ") failed: " 89 | + e.getMessage()); 90 | } catch (UnknownException e) { 91 | System.out.println(" getSubscribers(" + topic + ") failed: " 92 | + e.getMessage()); 93 | } 94 | } 95 | 96 | /** 97 | * converts the list of strings to a comma-separated list of strings 98 | * 99 | * @param subscribers 100 | * the list of subscribers to convert 101 | * @return a comma-separated list of subscriber URLs 102 | */ 103 | private static String getSubscribers(List subscribers) { 104 | StringBuffer result = new StringBuffer(); 105 | for (Iterator iterator = subscribers.iterator(); iterator 106 | .hasNext();) { 107 | result.append(iterator.next()); 108 | result.append(", "); 109 | } 110 | if (result.length() > 2) { 111 | return "[" + result.substring(0, result.length() - 3) + "]"; 112 | } else { 113 | return "[" + result.toString() + "]"; 114 | } 115 | } 116 | 117 | /** 118 | * converts the list of erlang strings to a comma-separated list of strings 119 | * 120 | * @param subscribers 121 | * the list of subscribers to convert 122 | * @return a comma-separated list of subscriber URLs 123 | */ 124 | private static String getSubscribers(OtpErlangList subscribers) { 125 | StringBuffer result = new StringBuffer(); 126 | for (int i = 0; i < subscribers.arity(); ++i) { 127 | result.append(((OtpErlangString) subscribers.elementAt(i)) 128 | .stringValue()); 129 | result.append(", "); 130 | } 131 | if (result.length() > 2) { 132 | return "[" + result.substring(0, result.length() - 3) + "]"; 133 | } else { 134 | return "[" + result.toString() + "]"; 135 | } 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /src/de/zib/scalaris/examples/ScalarisPublishExample.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.OtpErlangString; 19 | 20 | import de.zib.scalaris.ConnectionException; 21 | import de.zib.scalaris.Scalaris; 22 | 23 | /** 24 | * Provides an example for using the publish methods of the 25 | * {@link Scalaris} class. 26 | * 27 | * @author Nico Kruber, kruber@zib.de 28 | * @version 2.0 29 | * @since 2.0 30 | */ 31 | public class ScalarisPublishExample { 32 | /** 33 | * Publishes content under a given topic, both provided on the command line, 34 | * with the publish methods of {@link Scalaris}.
35 | * If no content or topic is given, the default key "key" and the 36 | * default value "value" is used. 37 | * 38 | * @param args 39 | * command line arguments (first argument can be an optional 40 | * topic and the second an optional content) 41 | */ 42 | public static void main(String[] args) { 43 | String topic; 44 | String content; 45 | 46 | if (args.length == 0) { 47 | topic = "topic"; 48 | content = "content"; 49 | } else if (args.length == 1) { 50 | topic = args[0]; 51 | content = "content"; 52 | } else { 53 | topic = args[0]; 54 | content = args[1]; 55 | } 56 | 57 | OtpErlangString otpTopic = new OtpErlangString(topic); 58 | OtpErlangString otpContent = new OtpErlangString(content); 59 | 60 | System.out 61 | .println("Publishing content under a topic with the class `Scalaris`:"); 62 | 63 | try { 64 | System.out.println(" creating object..."); 65 | Scalaris sc = new Scalaris(); 66 | System.out 67 | .println(" `void publish(OtpErlangString, OtpErlangString)`..."); 68 | sc.publish(otpTopic, otpContent); 69 | System.out.println(" publish(" + otpTopic.stringValue() + ", " 70 | + otpContent.stringValue() + ") succeeded"); 71 | } catch (ConnectionException e) { 72 | System.out.println(" publish(" + otpTopic.stringValue() + ", " 73 | + otpContent.stringValue() + ") failed: " + e.getMessage()); 74 | } 75 | 76 | try { 77 | System.out.println(" creating object..."); 78 | Scalaris sc = new Scalaris(); 79 | System.out.println(" `void publish(String, String)`..."); 80 | sc.publish(topic, content); 81 | System.out.println(" publish(" + topic + ", " + content 82 | + ") succeeded"); 83 | } catch (ConnectionException e) { 84 | System.out.println(" publish(" + topic + ", " + content 85 | + ") failed: " + e.getMessage()); 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/de/zib/scalaris/examples/ScalarisReadExample.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.OtpErlangString; 19 | 20 | import de.zib.scalaris.ConnectionException; 21 | import de.zib.scalaris.NotFoundException; 22 | import de.zib.scalaris.Scalaris; 23 | import de.zib.scalaris.TimeoutException; 24 | import de.zib.scalaris.UnknownException; 25 | 26 | /** 27 | * Provides an example for using the read methods of the 28 | * {@link Scalaris} class. 29 | * 30 | * @author Nico Kruber, kruber@zib.de 31 | * @version 2.0 32 | * @since 2.0 33 | */ 34 | public class ScalarisReadExample { 35 | /** 36 | * Reads a key given on the command line with the read methods of 37 | * {@link Scalaris}.
38 | * If no key is given, the default key "key" is used. 39 | * 40 | * @param args 41 | * command line arguments (first argument can be an optional key 42 | * to look up) 43 | */ 44 | public static void main(String[] args) { 45 | String key; 46 | String value; 47 | 48 | if (args.length != 1) { 49 | key = "key"; 50 | } else { 51 | key = args[0]; 52 | } 53 | 54 | OtpErlangString otpKey = new OtpErlangString(key); 55 | OtpErlangString otpValue; 56 | 57 | System.out.println("Reading values with the class `Scalaris`:"); 58 | 59 | try { 60 | System.out.println(" creating object..."); 61 | Scalaris sc = new Scalaris(); 62 | System.out 63 | .println(" `OtpErlangObject readObject(OtpErlangString)`..."); 64 | otpValue = (OtpErlangString) sc.readObject(otpKey); 65 | System.out.println(" read(" + otpKey.stringValue() + ") == " 66 | + otpValue.stringValue()); 67 | } catch (ConnectionException e) { 68 | System.out.println(" read(" + otpKey.stringValue() 69 | + ") failed: " + e.getMessage()); 70 | } catch (TimeoutException e) { 71 | System.out.println(" read(" + otpKey.stringValue() 72 | + ") failed with timeout: " + e.getMessage()); 73 | } catch (UnknownException e) { 74 | System.out.println(" read(" + otpKey.stringValue() 75 | + ") failed with unknown: " + e.getMessage()); 76 | } catch (NotFoundException e) { 77 | System.out.println(" read(" + otpKey.stringValue() 78 | + ") failed with not found: " + e.getMessage()); 79 | } catch (ClassCastException e) { 80 | System.out.println(" read(" + otpKey.stringValue() 81 | + ") failed with unknown return type: " + e.getMessage()); 82 | } 83 | 84 | try { 85 | System.out.println(" creating object..."); 86 | Scalaris sc = new Scalaris(); 87 | System.out.println(" `String read(String)`..."); 88 | value = sc.read(key); 89 | System.out.println(" read(" + key + ") == " + value); 90 | } catch (ConnectionException e) { 91 | System.out.println(" read(" + key + ") failed: " 92 | + e.getMessage()); 93 | } catch (TimeoutException e) { 94 | System.out.println(" read(" + key + ") failed with timeout: " 95 | + e.getMessage()); 96 | } catch (UnknownException e) { 97 | System.out.println(" read(" + key + ") failed with unknown: " 98 | + e.getMessage()); 99 | } catch (NotFoundException e) { 100 | System.out.println(" read(" + key 101 | + ") failed with not found: " + e.getMessage()); 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/de/zib/scalaris/examples/ScalarisSubscribeExample.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.OtpErlangString; 19 | 20 | import de.zib.scalaris.Scalaris; 21 | import de.zib.scalaris.ConnectionException; 22 | import de.zib.scalaris.TimeoutException; 23 | import de.zib.scalaris.UnknownException; 24 | 25 | /** 26 | * Provides an example for using the subscribe methods of the 27 | * {@link Scalaris} class. 28 | * 29 | * @author Nico Kruber, kruber@zib.de 30 | * @version 2.0 31 | * @since 2.0 32 | */ 33 | public class ScalarisSubscribeExample { 34 | /** 35 | * Subscribes a given URL to a given topic, both provided on the command 36 | * line, with the subscribe methods of {@link Scalaris}.
37 | * If no URL or topic is given, the default URL "url" and the 38 | * default topic "topic" is used. 39 | * 40 | * @param args 41 | * command line arguments (first argument can be an optional 42 | * topic and the second an optional URL) 43 | */ 44 | public static void main(String[] args) { 45 | String topic; 46 | String URL; 47 | 48 | if (args.length == 0) { 49 | topic = "topic"; 50 | URL = "url"; 51 | } else if (args.length == 1) { 52 | topic = args[0]; 53 | URL = "url"; 54 | } else { 55 | topic = args[0]; 56 | URL = args[1]; 57 | } 58 | 59 | OtpErlangString otpTopic = new OtpErlangString(topic); 60 | OtpErlangString otpURL = new OtpErlangString(URL); 61 | 62 | System.out 63 | .println("Subscribing a URL to a topic with the class `Scalaris`:"); 64 | 65 | try { 66 | System.out.println(" creating object..."); 67 | Scalaris sc = new Scalaris(); 68 | System.out 69 | .println(" `void subscribe(OtpErlangString, OtpErlangString)`..."); 70 | sc.subscribe(otpTopic, otpURL); 71 | System.out.println(" subscribe(" + otpTopic.stringValue() 72 | + ", " + otpURL.stringValue() + ") succeeded"); 73 | } catch (ConnectionException e) { 74 | System.out.println(" subscribe(" + otpTopic.stringValue() 75 | + ", " + otpURL.stringValue() + ") failed: " 76 | + e.getMessage()); 77 | } catch (TimeoutException e) { 78 | System.out.println(" subscribe(" + otpTopic.stringValue() 79 | + ", " + otpURL.stringValue() + ") failed with timeout: " 80 | + e.getMessage()); 81 | } catch (UnknownException e) { 82 | System.out.println(" subscribe(" + otpTopic.stringValue() 83 | + ", " + otpURL.stringValue() + ") failed with unknown: " 84 | + e.getMessage()); 85 | } 86 | 87 | try { 88 | System.out.println(" creating object..."); 89 | Scalaris sc = new Scalaris(); 90 | System.out.println(" `void subscribe(String, String)`..."); 91 | sc.subscribe(topic, URL); 92 | System.out.println(" subscribe(" + topic + ", " + URL 93 | + ") succeeded"); 94 | } catch (ConnectionException e) { 95 | System.out.println(" subscribe(" + topic + ", " + URL 96 | + ") failed: " + e.getMessage()); 97 | } catch (TimeoutException e) { 98 | System.out.println(" subscribe(" + topic + ", " + URL 99 | + ") failed with timeout: " + e.getMessage()); 100 | } catch (UnknownException e) { 101 | System.out.println(" subscribe(" + topic + ", " + URL 102 | + ") failed with unknown: " + e.getMessage()); 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/de/zib/scalaris/examples/ScalarisWriteExample.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.OtpErlangString; 19 | 20 | import de.zib.scalaris.ConnectionException; 21 | import de.zib.scalaris.Scalaris; 22 | import de.zib.scalaris.TimeoutException; 23 | import de.zib.scalaris.UnknownException; 24 | 25 | /** 26 | * Provides an example for using the write methods of the 27 | * {@link Scalaris} class. 28 | * 29 | * @author Nico Kruber, kruber@zib.de 30 | * @version 2.0 31 | * @since 2.0 32 | */ 33 | public class ScalarisWriteExample { 34 | /** 35 | * Writes a key/value pair given on the command line with the write 36 | * methods of {@link Scalaris}.
37 | * If no value or key is given, the default key "key" and the 38 | * default value "value" is used. 39 | * 40 | * @param args 41 | * command line arguments (first argument can be an optional key 42 | * and the second an optional value) 43 | */ 44 | public static void main(String[] args) { 45 | String key; 46 | String value; 47 | 48 | if (args.length == 0) { 49 | key = "key"; 50 | value = "value"; 51 | } else if (args.length == 1) { 52 | key = args[0]; 53 | value = "value"; 54 | } else { 55 | key = args[0]; 56 | value = args[1]; 57 | } 58 | 59 | OtpErlangString otpKey = new OtpErlangString(key); 60 | OtpErlangString otpValue = new OtpErlangString(value); 61 | 62 | System.out.println("Writing values with the class `Scalaris`:"); 63 | 64 | try { 65 | System.out.println(" creating object..."); 66 | Scalaris sc = new Scalaris(); 67 | System.out 68 | .println(" `void writeObject(OtpErlangString, OtpErlangObject)`..."); 69 | sc.writeObject(otpKey, otpValue); 70 | System.out.println(" write(" + otpKey.stringValue() + ", " 71 | + otpValue.stringValue() + ") succeeded"); 72 | } catch (ConnectionException e) { 73 | System.out.println(" write(" + otpKey.stringValue() + ", " 74 | + otpValue.stringValue() + ") failed: " + e.getMessage()); 75 | } catch (TimeoutException e) { 76 | System.out.println(" write(" + otpKey.stringValue() + ", " 77 | + otpValue.stringValue() + ") failed with timeout: " 78 | + e.getMessage()); 79 | } catch (UnknownException e) { 80 | System.out.println(" write(" + otpKey.stringValue() + ", " 81 | + otpValue.stringValue() + ") failed with unknown: " 82 | + e.getMessage()); 83 | } 84 | 85 | try { 86 | System.out.println(" creating object..."); 87 | Scalaris sc = new Scalaris(); 88 | System.out.println(" `void write(String, String)`..."); 89 | sc.write(key, value); 90 | System.out.println(" write(" + key + ", " + value 91 | + ") succeeded"); 92 | } catch (ConnectionException e) { 93 | System.out.println(" write(" + key + ", " + value 94 | + ") failed: " + e.getMessage()); 95 | } catch (TimeoutException e) { 96 | System.out.println(" write(" + key + ", " + value 97 | + ") failed with timeout: " + e.getMessage()); 98 | } catch (UnknownException e) { 99 | System.out.println(" write(" + key + ", " + value 100 | + ") failed with unknown: " + e.getMessage()); 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/de/zib/scalaris/examples/TransactionReadExample.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.OtpErlangString; 20 | 21 | import de.zib.scalaris.ConnectionException; 22 | import de.zib.scalaris.NotFoundException; 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 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.
42 | * If no keys are given, the default keys "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.
43 | * If no key/value pair is given, the default pairs (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 | *

The Scalaris class

20 | *

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 | *

Example:

28 | *
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 | *

The Transaction class

48 | *

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 | *

Example:

56 | *
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 | *

Example:

28 | * 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 | *

The PropertyLoader class

20 | *

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 | *

Example:

26 | * 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 columns = selector.getColumnsFromRow(colFamily, ID, false, ConsistencyLevel.QUORUM); 56 | return Selector.getColumnStringValue(columns, "value").toString(); 57 | }catch(Exception e){ 58 | e.printStackTrace(); 59 | return null; 60 | } 61 | } 62 | 63 | @Override 64 | public int updateDB(String ID, String newValue) { 65 | int ret; 66 | try{ 67 | Mutator mutator = Pelops.createMutator(pool); 68 | mutator.writeColumns( 69 | colFamily, ID, 70 | mutator.newColumnList( 71 | mutator.newColumn("value", newValue) 72 | ) 73 | ); 74 | mutator.execute(ConsistencyLevel.QUORUM); 75 | ret = 1; 76 | }catch(Exception e){ 77 | e.printStackTrace(); 78 | ret = 0; 79 | } 80 | return ret; 81 | } 82 | 83 | @Override 84 | public int writeDB(String ID, String Value) { 85 | return updateDB(ID, Value); 86 | } 87 | 88 | @Override 89 | public void searchDB(String keyword) { 90 | //Replace this by one your Cassandra node's IP 91 | String[] args = {"10.176.90.119"}; 92 | try { 93 | MapReduceCassandraDB.main(args); 94 | } catch (Exception e) { 95 | e.printStackTrace(); 96 | } 97 | 98 | } 99 | 100 | @Override 101 | public void close() { 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /src/implementations/hbaseDB.java: -------------------------------------------------------------------------------- 1 | package implementations; 2 | /** 3 | * Copyright 2011 Thibault Dory 4 | * Licensed under the GPL Version 3 license 5 | */ 6 | 7 | import hbase_mapreduce.MapReduceHbaseDB; 8 | import java.io.IOException; 9 | 10 | import org.apache.hadoop.hbase.HBaseConfiguration; 11 | import org.apache.hadoop.hbase.client.Get; 12 | import org.apache.hadoop.hbase.client.HTable; 13 | import org.apache.hadoop.hbase.client.Put; 14 | import org.apache.hadoop.hbase.client.Result; 15 | import org.apache.hadoop.hbase.util.Bytes; 16 | 17 | import core.BenchDB; 18 | 19 | /** 20 | * 21 | * @author Thibault Dory 22 | * 23 | * Use the following commands in HBase shell to create the needed tables and column families 24 | * create 'myTable', 'myColumnFamily' 25 | * create 'result', 'resultF' 26 | * create 'result2', 'resultF' 27 | */ 28 | 29 | public class hbaseDB extends BenchDB{ 30 | HTable table; 31 | HBaseConfiguration config; 32 | 33 | @Override 34 | public int connectNode(String nodeAddress) { 35 | int ret; 36 | config = new HBaseConfiguration(); 37 | try { 38 | table = new HTable(config, "myTable"); 39 | ret = 1; 40 | } catch (IOException e) { 41 | e.printStackTrace(); 42 | ret = -1; 43 | } 44 | return ret; 45 | } 46 | @Override 47 | public String readDB(String ID) { 48 | String ret; 49 | Get g = new Get(Bytes.toBytes(ID)); 50 | try { 51 | Result r = table.get(g); 52 | byte [] value = r.getValue(Bytes.toBytes("myColumnFamily"),Bytes.toBytes("value")); 53 | ret = Bytes.toString(value); 54 | } catch (IOException e) { 55 | e.printStackTrace(); 56 | ret = null; 57 | } 58 | return ret; 59 | } 60 | 61 | @Override 62 | public int updateDB(String ID, String newValue) { 63 | return writeDB(ID, newValue); 64 | } 65 | @Override 66 | public int writeDB(String ID, String Value) { 67 | int ret = 0; 68 | Put p = new Put(Bytes.toBytes(ID)); 69 | try{ 70 | p.add(Bytes.toBytes("myColumnFamily"), Bytes.toBytes("value"), Bytes.toBytes(Value)); 71 | table.put(p); 72 | ret = 1; 73 | }catch(Exception e){ 74 | e.printStackTrace(); 75 | ret = -1; 76 | } 77 | return ret; 78 | } 79 | 80 | @Override 81 | public void close(){ 82 | try { 83 | table.close(); 84 | System.out.println("================== Table closed ===================================================="); 85 | config.clear(); 86 | } catch (IOException e) { 87 | e.printStackTrace(); 88 | } 89 | } 90 | 91 | @Override 92 | public void searchDB(String keyword){ 93 | 94 | String[] args = {"master"}; 95 | try { 96 | MapReduceHbaseDB.main(args); 97 | } catch (Exception e) { 98 | e.printStackTrace(); 99 | } 100 | 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/implementations/mongoDB.java: -------------------------------------------------------------------------------- 1 | package implementations; 2 | /** 3 | * Copyright 2011 Thibault Dory 4 | * Licensed under the GPL Version 3 license 5 | */ 6 | 7 | import java.net.UnknownHostException; 8 | import java.util.ArrayList; 9 | 10 | import com.mongodb.BasicDBObject; 11 | import com.mongodb.DB; 12 | import com.mongodb.DBCollection; 13 | import com.mongodb.DBCursor; 14 | import com.mongodb.DBObject; 15 | import com.mongodb.MapReduceOutput; 16 | import com.mongodb.Mongo; 17 | import com.mongodb.MongoException; 18 | import com.mongodb.util.JSON; 19 | 20 | import core.BenchDB; 21 | 22 | /** 23 | * 24 | * @author Thibault Dory 25 | * 26 | */ 27 | 28 | public class mongoDB extends BenchDB{ 29 | DB db; 30 | Mongo mdb; 31 | DBCollection dbCol; 32 | 33 | @Override 34 | public int connectNode(String nodeAddress) { 35 | int ret; 36 | try { 37 | mdb = new Mongo(nodeAddress); 38 | //mdb.slaveOk(); 39 | db = mdb.getDB("test"); 40 | dbCol = db.getCollection("test"); 41 | DBCursor cur = dbCol.find(); 42 | ret = 1; 43 | } catch (UnknownHostException e) { 44 | ret = -1; 45 | e.printStackTrace(); 46 | } catch (MongoException e) { 47 | ret = 1; 48 | e.printStackTrace(); 49 | } 50 | return ret; 51 | } 52 | 53 | @Override 54 | public String readDB(String ID) { 55 | String ret; 56 | try{ 57 | db.requestStart(); 58 | BasicDBObject query = new BasicDBObject(); 59 | query.put("_id", ID); 60 | DBCursor cur = dbCol.find(query); 61 | ret = ""; 62 | while(cur.hasNext()) { 63 | DBObject temp = (DBObject) JSON.parse(cur.next().toString()); 64 | ret = (String) temp.get("artValue"); 65 | 66 | } 67 | db.requestDone(); 68 | }catch(Exception e){ 69 | e.printStackTrace(); 70 | ret = null; 71 | } 72 | return ret; 73 | } 74 | 75 | 76 | public int writeDB(String ID, String newValue) { 77 | int ret; 78 | try{ 79 | db.requestStart(); 80 | BasicDBObject doc = new BasicDBObject(); 81 | doc.put("_id",ID); 82 | doc.put("artValue", newValue); 83 | dbCol.insert(doc); 84 | db.requestDone(); 85 | ret = 1; 86 | }catch(Exception e){ 87 | e.printStackTrace(); 88 | ret = -1; 89 | } 90 | return ret; 91 | } 92 | 93 | @Override 94 | public int updateDB(String ID, String newValue) { 95 | int ret; 96 | try{ 97 | db.requestStart(); 98 | BasicDBObject query = new BasicDBObject(); 99 | query.put("_id", ID); 100 | DBCursor cur = dbCol.find(query); 101 | cur.next(); 102 | BasicDBObject doc = new BasicDBObject(); 103 | doc.put("_id",ID); 104 | doc.put("artValue", newValue); 105 | dbCol.update(cur.curr(), doc); 106 | db.requestDone(); 107 | ret = 1; 108 | }catch(Exception e){ 109 | e.printStackTrace(); 110 | System.out.println("ID = "+ID+" ==============================="); 111 | ret = -1; 112 | } 113 | return ret; 114 | } 115 | 116 | public void searchDB(String keyword){ 117 | ArrayList res= new ArrayList(); 118 | String map_index = "function() {"+ 119 | "var words = this.artValue.split(' ');"+ 120 | "var keyword = \""+keyword+"\";"+ 121 | "for ( var i=0; i client; 22 | StoreClientFactory factory; 23 | @Override 24 | public int connectNode(String nodeAddress) { 25 | int ret; 26 | try{ 27 | String bootstrapUrl = "tcp://"+nodeAddress+":6666"; 28 | factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl)); 29 | client = factory.getStoreClient("test"); 30 | ret = 1; 31 | }catch(Exception e){ 32 | e.printStackTrace(); 33 | ret = -1; 34 | } 35 | return ret; 36 | } 37 | 38 | @Override 39 | public String readDB(String ID) { 40 | String res; 41 | try{ 42 | res = client.get(ID).getValue(); 43 | } catch(VoldemortException e) { 44 | res = null; 45 | } 46 | return res; 47 | } 48 | 49 | @Override 50 | public int updateDB(String ID, String newValue) { 51 | int ret; 52 | try{ 53 | client.put(ID, newValue); 54 | ret = 1; 55 | } catch(VoldemortException e) { 56 | ret = -1; 57 | } 58 | return ret; 59 | } 60 | 61 | @Override 62 | public int writeDB(String ID, String Value) { 63 | return updateDB(ID, Value); 64 | } 65 | 66 | @Override 67 | public void searchDB(String keyword) { 68 | // There is no MapReduce implementation in voldemort 69 | } 70 | 71 | @Override 72 | public void close() { 73 | factory.close(); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/org/json/CookieList.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 | import java.util.Iterator; 28 | 29 | /** 30 | * Convert a web browser cookie list string to a JSONObject and back. 31 | * @author JSON.org 32 | * @version 2008-09-18 33 | */ 34 | public class CookieList { 35 | 36 | /** 37 | * Convert a cookie list into a JSONObject. A cookie list is a sequence 38 | * of name/value pairs. The names are separated from the values by '='. 39 | * The pairs are separated by ';'. The names and the values 40 | * will be unescaped, possibly converting '+' and '%' sequences. 41 | * 42 | * To add a cookie to a cooklist, 43 | * cookielistJSONObject.put(cookieJSONObject.getString("name"), 44 | * cookieJSONObject.getString("value")); 45 | * @param string A cookie list string 46 | * @return A JSONObject 47 | * @throws JSONException 48 | */ 49 | public static JSONObject toJSONObject(String string) throws JSONException { 50 | JSONObject o = new JSONObject(); 51 | JSONTokener x = new JSONTokener(string); 52 | while (x.more()) { 53 | String name = Cookie.unescape(x.nextTo('=')); 54 | x.next('='); 55 | o.put(name, Cookie.unescape(x.nextTo(';'))); 56 | x.next(); 57 | } 58 | return o; 59 | } 60 | 61 | 62 | /** 63 | * Convert a JSONObject into a cookie list. A cookie list is a sequence 64 | * of name/value pairs. The names are separated from the values by '='. 65 | * The pairs are separated by ';'. The characters '%', '+', '=', and ';' 66 | * in the names and values are replaced by "%hh". 67 | * @param o A JSONObject 68 | * @return A cookie list string 69 | * @throws JSONException 70 | */ 71 | public static String toString(JSONObject o) throws JSONException { 72 | boolean b = false; 73 | Iterator keys = o.keys(); 74 | String s; 75 | StringBuffer sb = new StringBuffer(); 76 | while (keys.hasNext()) { 77 | s = keys.next().toString(); 78 | if (!o.isNull(s)) { 79 | if (b) { 80 | sb.append(';'); 81 | } 82 | sb.append(Cookie.escape(s)); 83 | sb.append("="); 84 | sb.append(Cookie.escape(o.getString(s))); 85 | b = true; 86 | } 87 | } 88 | return sb.toString(); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/org/json/HTTP.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 | import java.util.Iterator; 28 | 29 | /** 30 | * Convert an HTTP header to a JSONObject and back. 31 | * @author JSON.org 32 | * @version 2008-09-18 33 | */ 34 | public class HTTP { 35 | 36 | /** Carriage return/line feed. */ 37 | public static final String CRLF = "\r\n"; 38 | 39 | /** 40 | * Convert an HTTP header string into a JSONObject. It can be a request 41 | * header or a response header. A request header will contain 42 | *
{
 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-cache
58 | * 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 | 7 | 8 | fs.default.name 9 | hdfs://master/ 10 | 11 | 12 | mapred.job.tracker 13 | master:8021 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/resources/hbase-site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 24 | 25 | 26 | hbase.rootdir 27 | hdfs://master/hbase 28 | 29 | 30 | dfs.replication 31 | 3 32 | 33 | 34 | hbase.master.hostname 35 | master 36 | 37 | 38 | hbase.cluster.distributed 39 | true 40 | The mode the cluster will be in. Possible values are 41 | false: standalone and pseudo-distributed setups with managed Zookeeper 42 | true: fully-distributed with unmanaged Zookeeper Quorum (see hbase-env.sh) 43 | 44 | 45 | 46 | hbase.zookeeper.quorum 47 | master 48 | Comma separated list of servers in the ZooKeeper Quorum. 49 | For example, "host1.mydomain.com,host2.mydomain.com,host3.mydomain.com". 50 | By default this is set to localhost for local and pseudo-distributed modes 51 | of operation. For a fully-distributed setup, this should be set to a full 52 | list of ZooKeeper quorum servers. If HBASE_MANAGES_ZK is set in hbase-env.sh 53 | this is the list of servers which we will start/stop ZooKeeper on. 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /src/utils/Files.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | import java.io.BufferedInputStream; 3 | import java.io.BufferedReader; 4 | import java.io.DataInputStream; 5 | import java.io.File; 6 | import java.io.FileInputStream; 7 | import java.io.FileNotFoundException; 8 | import java.io.IOException; 9 | import java.io.InputStreamReader; 10 | import java.util.ArrayList; 11 | 12 | public class Files { 13 | 14 | /** 15 | * @param filePath 16 | * @return the content of the file in a string 17 | * @throws java.io.IOException 18 | */ 19 | public static String readFileAsString(String filePath) throws java.io.IOException{ 20 | byte[] buffer = new byte[(int) new File(filePath).length()]; 21 | BufferedInputStream f = null; 22 | try { 23 | f = new BufferedInputStream(new FileInputStream(filePath)); 24 | f.read(buffer); 25 | } finally { 26 | if (f != null) try { f.close(); } catch (IOException ignored) { } 27 | } 28 | return new String(buffer); 29 | } 30 | 31 | static public boolean deleteDirectory(File path) { 32 | if( path.exists() ) { 33 | File[] files = path.listFiles(); 34 | for(int i=0; i readFileAsList(String filePath){ 48 | ArrayList result = new ArrayList(); 49 | 50 | try { 51 | FileInputStream fstream = new FileInputStream(filePath); 52 | DataInputStream in = new DataInputStream(fstream); 53 | BufferedReader br = new BufferedReader(new InputStreamReader(in)); 54 | String strLine; 55 | while ((strLine = br.readLine()) != null) { 56 | result.add(strLine); 57 | } 58 | in.close(); 59 | } catch (Exception e) { 60 | e.printStackTrace(); 61 | } 62 | 63 | return result; 64 | 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/utils/argsTools.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class argsTools { 6 | 7 | public static ArrayList> divideNodeList(ArrayList nodeList, int numberOfClients){ 8 | ArrayList> result = new ArrayList>(); 9 | int numberOfNodes = nodeList.size(); 10 | int low=0; 11 | int up=numberOfNodes/numberOfClients; 12 | 13 | for(int i=0;i local = new ArrayList(); 15 | for(int j=low;j average, ArrayList time){ 9 | double FullIntegral =0; 10 | 11 | for(int i=0;i average, ArrayList time, ArrayList sd, int M, int N){ 21 | double under = (time.get(time.size()-1) - time.get(0)) * average.get(average.size()-1); 22 | double A = numIntegral(average, time); 23 | ArrayList averageSD = new ArrayList(); 24 | for(int i=0;i" in line: 11 | inPage = True 12 | 13 | if "" in line: 14 | inPage = False 15 | temp += line 16 | f = open('articles/'+str(currentArticle),'w') 17 | f.write(temp) 18 | f.close() 19 | temp = "" 20 | currentArticle = currentArticle + 1 21 | count = count + 1 22 | if (count % 100) == 0 : 23 | print count 24 | 25 | if inPage: 26 | temp += line 27 | 28 | -------------------------------------------------------------------------------- /src/utils/statTools.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class statTools { 6 | 7 | ArrayList> results; 8 | int count = 0; 9 | double sum = 0; 10 | double squareSum = 0; 11 | double average; 12 | double standardDeviation; 13 | 14 | public statTools(ArrayList> results){ 15 | this.results = results; 16 | for(ArrayList dArray : results){ 17 | for(Double d : dArray){ 18 | count += 1; 19 | sum += d; 20 | } 21 | } 22 | } 23 | 24 | public int getCount(){ 25 | return count; 26 | } 27 | 28 | public double getAverage(){ 29 | average = sum / (double) count; 30 | return average; 31 | } 32 | 33 | public double getStandardDeviation(){ 34 | getAverage(); 35 | for(ArrayList dArray : results){ 36 | for(Double d : dArray){ 37 | squareSum += Math.pow((d - average),2); 38 | } 39 | } 40 | return standardDeviation = Math.sqrt(squareSum / ( (double) (count -1))); 41 | } 42 | 43 | } 44 | --------------------------------------------------------------------------------