Merge branch 'RAMCloud-master' into RAMCloud-new_dynamics
Conflicts:
src/main/java/net/onrc/onos/datagrid/HazelcastDatagrid.java
src/main/java/net/onrc/onos/graph/LocalTopologyEventListener.java
src/main/java/net/onrc/onos/ofcontroller/core/internal/TopoLinkServiceImpl.java
src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowDatabaseOperation.java
src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
diff --git a/.gitignore b/.gitignore
index 88f7bb1..c9e6bc1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,6 +8,5 @@
target
onos-logs
onos.log
-repo
logback.*.xml
diff --git a/blueprints-README.md b/blueprints-README.md
new file mode 100644
index 0000000..787bd36
--- /dev/null
+++ b/blueprints-README.md
@@ -0,0 +1,160 @@
+blueprints-ramcloud-graph
+=========================
+
+A TinkerPop Blueprints implementation for RAMCloud
+
+Setup
+=====
+ - Copy `src/main/java/edu/stanford/ramcloud/JRamCloud.java` and `src/main/cpp/edu_stanford_ramcloud_JRamCloud.cc` to your `ramcloud/bindinds/java/edu/stanford/ramcloud` directory, overwriting what is already there.
+
+ - Generate the C++ header files containing the function signatures for all the native methods in the Java RamCloud library:
+
+```
+javah -cp ../../../ edu.stanford.ramcloud.JRamCloud
+```
+
+ - Compile the ramcloud C++ library (assuming ramcloud is in your ${HOME} directory and you have already compiled ramcloud):
+
+```
+c++ -Wall -O3 -shared -fPIC -std=c++0x -I/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64/include/ -I/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64/include/linux/ -I${HOME}/ramcloud/src/ -I${HOME}/ramcloud/obj.master/ -I${HOME}/ramcloud/logcabin/ -I${HOME}/ramcloud/gtest/include/ -L${HOME}/ramcloud/obj.master -o libedu_stanford_ramcloud_JRamCloud.so edu_stanford_ramcloud_JRamCloud.cc -lramcloud
+```
+
+ - Update `LD_LIBRARY_PATH` (assuming ramcloud is in your ${HOME} directory) to include the library and also any other ramcloud libraries:
+
+```
+export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${HOME}/ramcloud/bindings/java/edu/stanford/ramcloud:${HOME}/ramcloud/obj.master
+```
+
+ - Startup a ramcloud cluster somewhere and modify RamCloudGraph.java to point to the coordinator.
+
+ - Compile this package (blueprints-ramcloud-graph) using maven and run :)
+
+Using Rexster
+=============
+ - git clone the rexster repository:
+
+```
+git clone https://github.com/tinkerpop/rexster.git
+```
+
+ - Compile rexster
+
+```
+cd rexster/
+mvn compile
+```
+
+ - Compile packaged rexster server
+
+```
+cd rexster-server/
+mvn package
+```
+
+ - Edit rexster-server config file
+
+```
+cd target/rexster-server-2.5.0-SNAPSHOT-standalone/
+vim config/rexster.xml
+```
+
+ - Change web-root to be your public web-root directory
+
+ - Add a ramcloud graph to the set of graphs to load up:
+
+```
+<graph>
+ <graph-enabled>true</graph-enabled>
+ <graph-name>ramcloudgraph</graph-name>
+ <graph-type>com.tinkerpop.rexster.config.RamCloudGraphConfiguration</graph-type>
+</graph>
+```
+
+ - Go back to the blueprints-ramcloud-graph directory and compile jar with depdencies:
+
+```
+mvn assembly:assembly -DdescriptorId=jar-with-dependencies
+```
+
+ - Copy resulting jar file into the compiled rexster-server library directory:
+
+```
+cp blueprints-ramcloud-graph-2.0.0-jar-with-depdencies.jar ~/git/rexster/rexster-server/target/rexster-server-2.5.0-SNAPSHOT-standalone/lib
+```
+
+ - Startup a ramcloud cluster (maybe using the cluster.py script):
+
+```
+./cluster.py --verbose --servers=5 --replicas=3 --backups=1 --masterArgs="--totalMasterMemory 80% --masterServiceThreads 4" --clients=1 --client=../obj.master/client --debug
+```
+
+ - Startup the rexster server:
+
+```
+./bin/rexster.sh -start &
+```
+
+ - Connect to rexster server at:
+
+```
+localhost:8182
+```
+
+
+Using Gremlin
+=============
+ - git clone the gremlin repository:
+
+```
+git clone https://github.com/tinkerpop/gremlin.git
+```
+
+ - Compile gremlin
+
+```
+cd rexster/
+mvn package
+```
+
+ - Go back to the blueprints-ramcloud-graph directory and compile jar with depdencies:
+
+```
+mvn assembly:assembly -DdescriptorId=jar-with-dependencies
+```
+
+ - Copy resulting jar file into the compiled gremlin-groovy library directory:
+
+```
+cp blueprints-ramcloud-graph-2.0.0-jar-with-depdencies.jar ~/git/gremlin/gremlin-groovy/target/gremlin-groovy-2.5.0-SNAPSHOT-standalone/lib
+```
+
+ - Startup a ramcloud cluster (maybe using the cluster.py script):
+
+```
+./cluster.py --verbose --servers=5 --replicas=3 --backups=1 --masterArgs="--totalMasterMemory 80% --masterServiceThreads 4" --clients=1 --client=../obj.master/client --debug
+```
+
+ - Startup gremlin shell:
+
+```
+./bin/gremlin.sh
+```
+
+ - Import RamCloudGraph java libraries and create RamCloudGraph:
+
+```
+ \,,,/
+ (o o)
+-----oOOo-(_)-oOOo-----
+gremlin> g = new com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraph()
+```
+
+ - Have fun!
+
+Using Furnace
+=============
+ - See `com.tinkerpop.blueprints.impls.ramcloud.FurnaceExamples` for some examples of using Furnace
+
+Using JUNG
+==========
+ - See `com.tinkerpop.blueprints.impls.ramcloud.JUNGExamples` for some examples of using the JUNG ouplementation (mostly taken from https://github.com/tinkerpop/blueprints/wiki/JUNG-Ouplementation).
diff --git a/cluster-mgmt/template/onsdemo_edge_template.py b/cluster-mgmt/template/onsdemo_edge_template.py
index c3d0287..b5a76f5 100755
--- a/cluster-mgmt/template/onsdemo_edge_template.py
+++ b/cluster-mgmt/template/onsdemo_edge_template.py
@@ -113,7 +113,7 @@
# controllers.append(rc)
#net.controllers=controllers
- net.build()
+ #net.build()
host = []
for i in range (NR_NODES):
diff --git a/conf/ramcloud.conf b/conf/ramcloud.conf
index 84b4ff2..b69fcd2 100644
--- a/conf/ramcloud.conf
+++ b/conf/ramcloud.conf
@@ -1 +1,4 @@
-ramcloud.coordinator=fast+udp:host=10.128.100.36,port=12246
+ramcloud.coordinatorIp=fast+udp:host=192.168.56.11
+ramcloud.coordinatorPort=port=12246
+ramcloud.serverIp=fast+udp:host=192.168.56.11
+ramcloud.serverPort=port=12242
diff --git a/kryo2/.gitignore b/kryo2/.gitignore
deleted file mode 100644
index 916e17c..0000000
--- a/kryo2/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-dependency-reduced-pom.xml
diff --git a/kryo2/pom.xml b/kryo2/pom.xml
deleted file mode 100644
index 788f952..0000000
--- a/kryo2/pom.xml
+++ /dev/null
@@ -1,68 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <groupId>net.onrc.onos</groupId>
- <artifactId>kryo2</artifactId>
- <version>2.22</version>
- <packaging>jar</packaging>
-
- <name>kryo2</name>
- <url>http://maven.apache.org</url>
-
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>com.esotericsoftware.kryo</groupId>
- <artifactId>kryo</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-shade-plugin</artifactId>
- <version>2.1</version>
- <configuration>
- <relocations>
- <relocation>
- <pattern>com.esotericsoftware.kryo</pattern>
- <shadedPattern>com.esotericsoftware.kryo2</shadedPattern>
- <excludes>
- </excludes>
- </relocation>
- </relocations>
- </configuration>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>shade</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>exec-maven-plugin</artifactId>
- <version>1.2.1</version>
- <executions>
- <execution>
- <id>kryo2</id>
- <goals>
- <goal>exec</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <executable>mvn</executable>
- <commandlineArgs>install:install-file -DlocalRepositoryPath=${basedir}/../repo -DcreateChecksum=true -Dpackaging=jar -Dfile=${basedir}/target/${project.build.finalName}.jar -DgroupId=${project.groupId} -DartifactId=${project.artifactId} -Dversion=${project.version}</commandlineArgs>
- </configuration>
- </plugin>
- </plugins>
- </build>
-</project>
diff --git a/logcabin.patch b/logcabin.patch
new file mode 100644
index 0000000..100697c
--- /dev/null
+++ b/logcabin.patch
@@ -0,0 +1,21 @@
+diff --git a/Core/Time.h b/Core/Time.h
+index 1dd2e00..a9deddd 100644
+--- a/Core/Time.h
++++ b/Core/Time.h
+@@ -25,6 +25,7 @@ namespace std {
+ /**
+ * Prints std::time_point values in a way that is useful for unit tests.
+ */
++/*
+ template<typename Clock, typename Duration>
+ std::ostream&
+ operator<<(std::ostream& os,
+@@ -45,7 +46,7 @@ operator<<(std::ostream& os,
+ microsSinceUnixEpoch / 1000000,
+ microsSinceUnixEpoch % 1000000);
+ }
+-
++*/
+ }
+
+ namespace LogCabin {
diff --git a/perf-scripts/flow-sync-perf.py b/perf-scripts/flow-sync-perf.py
index b782333..61a204b 100755
--- a/perf-scripts/flow-sync-perf.py
+++ b/perf-scripts/flow-sync-perf.py
@@ -35,7 +35,9 @@
print "ONOS Log File:", ONOS_LOG
# Verify that tcpkill is installed
-if not Popen( 'which tcpkill', stdout=PIPE, shell=True).communicate():
+tcpkill_check = Popen( 'which tcpkill', stdout=PIPE, shell=True)
+tcpkill_check.communicate()
+if tcpkill_check.returncode != 0:
print '* Installing tcpkill'
call( 'apt-get install -y dsniff', stdout=PIPE, shell=True )
diff --git a/pom.xml b/pom.xml
index c19c56f..b62b934 100644
--- a/pom.xml
+++ b/pom.xml
@@ -195,13 +195,11 @@
<goal>build-classpath</goal>
</goals>
<configuration>
- <!-- configure the plugin here -->
<outputFile>${project.basedir}/.javacp</outputFile>
</configuration>
</execution>
</executions>
</plugin>
-
</plugins>
</build>
<!-- for getting visualization reporting -->
@@ -267,22 +265,11 @@
</plugins>
</reporting>
<dependencies>
- <!-- Commenting out original kryo 2.X
- and using shaded version (net.onrc.onos.kryo2)
- to workaround conflict with kryo 1.X in titan's dependency.(#443)
- -->
- <!--
<dependency>
<groupId>com.esotericsoftware.kryo</groupId>
<artifactId>kryo</artifactId>
<version>2.22</version>
</dependency>
- -->
- <dependency>
- <groupId>net.onrc.onos</groupId>
- <artifactId>kryo2</artifactId>
- <version>2.22</version>
- </dependency>
<!-- ONOS's direct dependencies -->
<dependency>
<groupId>org.apache.cassandra</groupId>
@@ -293,7 +280,7 @@
<dependency>
<groupId>com.thinkaurelius.titan</groupId>
<artifactId>titan-all</artifactId>
- <version>0.2.1</version>
+ <version>0.4.2</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
@@ -304,7 +291,7 @@
<dependency>
<groupId>com.tinkerpop</groupId>
<artifactId>frames</artifactId>
- <version>2.3.1</version>
+ <version>2.4.0</version>
</dependency>
<dependency>
<groupId>com.tinkerpop.blueprints</groupId>
@@ -312,6 +299,21 @@
<version>2.3.0</version>
</dependency>
<dependency>
+ <groupId>com.tinkerpop.rexster</groupId>
+ <artifactId>rexster-core</artifactId>
+ <version>2.4.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.tinkerpop.blueprints</groupId>
+ <artifactId>blueprints-test</artifactId>
+ <version>2.4.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.protobuf</groupId>
+ <artifactId>protobuf-java</artifactId>
+ <version>2.5.0</version>
+ </dependency>
+ <dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>3.0.2</version>
@@ -477,10 +479,5 @@
<version>0.1.0</version>
</dependency>
-->
- <dependency>
- <groupId>com.tinkerpop.blueprints.impls.ramcloud</groupId>
- <artifactId>blueprints-ramcloud-graph</artifactId>
- <version>2.5.0</version>
- </dependency>
</dependencies>
</project>
diff --git a/ramcloud.patch b/ramcloud.patch
new file mode 100644
index 0000000..d3a17e3
--- /dev/null
+++ b/ramcloud.patch
@@ -0,0 +1,13 @@
+diff --git a/src/MasterService.cc b/src/MasterService.cc
+index ba7fdf1..fa041e0 100644
+--- a/src/MasterService.cc
++++ b/src/MasterService.cc
+@@ -606,7 +606,7 @@ MasterService::multiWrite(const WireFormat::MultiOp::Request* reqHdr,
+ reqOffset, currentReq->valueLength);
+ reqOffset += currentReq->valueLength;
+
+- if (stringKey == NULL || value == NULL) {
++ if (stringKey == NULL) {
+ respHdr->common.status = STATUS_REQUEST_FORMAT_ERROR;
+ break;
+ }
diff --git a/rebuild-local-repo.sh b/rebuild-local-repo.sh
index 4ea1fbf..1baa27b 100755
--- a/rebuild-local-repo.sh
+++ b/rebuild-local-repo.sh
@@ -15,11 +15,6 @@
MVN="mvn"
fi
-# Install Kryo2 workaround to local repo
-# - Shaded(rename package name to allow mixing 2 different Kryo version)
-# - Install created sharded jar to local repo
-${MVN} -f kryo2/pom.xml package exec:exec
-
# Install modified curators to local repo
${MVN} install:install-file -Dfile=./curator/curator-framework-1.3.5-SNAPSHOT.jar -DgroupId=com.netflix.curator -DartifactId=curator-framework -Dversion=1.3.5-SNAPSHOT -Dpackaging=jar -DgeneratePom=true -DlocalRepositoryPath=./repo -DcreateChecksum=true
${MVN} install:install-file -Dfile=./curator/curator-client-1.3.5-SNAPSHOT.jar -DgroupId=com.netflix.curator -DartifactId=curator-client -Dversion=1.3.5-SNAPSHOT -Dpackaging=jar -DgeneratePom=true -DlocalRepositoryPath=./repo -DcreateChecksum=true
diff --git a/scripts/all-linkup.sh b/scripts/all-linkup.sh
index 9067012..290a17d 100755
--- a/scripts/all-linkup.sh
+++ b/scripts/all-linkup.sh
@@ -3,11 +3,6 @@
controller=`hostname`
switches=`sudo ovs-vsctl list-br`
-function host2ip (){
- ip=`grep $1 /etc/hosts |grep -v "ip6"| awk '{print $1}'`
- echo $ip
-}
-
for s in $switches; do
ports=`sudo ovs-vsctl --pretty list-ports $s`
for p in $ports; do
diff --git a/scripts/ctrl-local.sh b/scripts/ctrl-local.sh
index 023a9db..1418a2c 100755
--- a/scripts/ctrl-local.sh
+++ b/scripts/ctrl-local.sh
@@ -1,9 +1,8 @@
#! /bin/bash
controller=`hostname`
-switches=`ifconfig -a | grep sw |grep -v eth | awk '{print $1}'`
-
+switches=`sudo ovs-vsctl list-br`
function host2ip (){
- ip=`grep $1 /etc/hosts |grep -v "ip6"| awk '{print $1}'`
+ ip=`getent hosts $1 | awk '{print $1}' | tail -n 1`
echo $ip
}
diff --git a/scripts/ctrl-none.sh b/scripts/ctrl-none.sh
index 74349e3..fb8d2a0 100755
--- a/scripts/ctrl-none.sh
+++ b/scripts/ctrl-none.sh
@@ -1,9 +1,8 @@
#! /bin/bash
controller=""
-switches=`ifconfig -a | grep sw |grep -v eth | awk '{print $1}'`
-
+switches=`sudo ovs-vsctl list-br`
function host2ip (){
- ip=`grep $1 /etc/hosts |grep -v "ip6"| awk '{print $1}'`
+ ip=`getent hosts $1 | awk '{print $1}' | tail -n 1`
echo $ip
}
diff --git a/scripts/ctrl-one.sh b/scripts/ctrl-one.sh
index 207d3f2..9fe8341 100755
--- a/scripts/ctrl-one.sh
+++ b/scripts/ctrl-one.sh
@@ -8,10 +8,9 @@
#controller=`hostname`
controller=$1
-switches=`ifconfig -a | grep sw |grep -v eth | awk '{print $1}'`
-
+switches=`sudo ovs-vsctl list-br`
function host2ip (){
- ip=`grep $1 /etc/hosts |grep -v "ip6"| awk '{print $1}'`
+ ip=`getent hosts $1 | awk '{print $1}' | tail -n 1`
echo $ip
}
diff --git a/scripts/link.sh b/scripts/link.sh
index dc202e7..57323ef 100755
--- a/scripts/link.sh
+++ b/scripts/link.sh
@@ -1,7 +1,7 @@
#! /bin/bash
controller=`hostname`
-switches=`ifconfig -a | grep sw |grep -v eth | awk '{print $1}'`
+switches=`sudo ovs-vsctl list-br`
function host2ip (){
ip=`grep $1 /etc/hosts |grep -v "ip6"| awk '{print $1}'`
@@ -12,14 +12,16 @@
if [ $# != 3 ];then
echo "usage: $0 <dpid> <port> <up|down>"
+ echo " example: $0 00:00:00:00:ba:5e:ba:11 1 up"
+ exit
fi
-src_dpid="dpid:"`echo $1 | sed s'/://g'`
+src_dpid=`echo $1 | sed s'/://g'`
src_port=$2
cmd=$3
for s in $switches; do
- dpid=`sudo ovs-ofctl show $s |grep dpid | awk '{print $4}'`
+ dpid=`sudo ovs-ofctl show $s |grep dpid | awk '{if(match($0,/dpid:[0-9|a-d]*/)){ print substr($0,RSTART+5,RLENGTH)}}'`
if [ "x$dpid" == "x$src_dpid" ]; then
# intf=`sudo ovs-ofctl show $s |grep addr | awk -v p=$src_port 'BEGIN {pat="^ "p"\("}
diff --git a/scripts/showdpid.sh b/scripts/showdpid.sh
index 1dff291..14b6345 100755
--- a/scripts/showdpid.sh
+++ b/scripts/showdpid.sh
@@ -2,17 +2,6 @@
controller=""
#switches=`ifconfig -a | grep sw |grep -v eth | awk '{print $1}'`
switches=`sudo ovs-vsctl list-br`
-
-function host2ip (){
- ip=`grep $1 /etc/hosts |grep -v "ip6"| awk '{print $1}'`
- echo $ip
-}
-
-url=""
-for c in $controller; do
- url="$url tcp:`host2ip $c`:6633"
-done
-echo $url
for s in $switches; do
echo -n "$s : "
sudo ovs-ofctl show $s |grep dpid
diff --git a/scripts/showflow.sh b/scripts/showflow.sh
index 15824d7..63b82b7 100755
--- a/scripts/showflow.sh
+++ b/scripts/showflow.sh
@@ -2,11 +2,6 @@
controller=""
switches=`sudo ovs-vsctl list-br`
-function host2ip (){
- ip=`grep $1 /etc/hosts |grep -v "ip6"| awk '{print $1}'`
- echo $ip
-}
-
dpids=()
for s in $switches; do
i=`sudo ovs-ofctl show $s |grep dpid | awk -F ":" '{print $4}'`
diff --git a/setup-ramcloud.sh b/setup-ramcloud.sh
new file mode 100755
index 0000000..758bb0c
--- /dev/null
+++ b/setup-ramcloud.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+set -x
+
+ONOS_HOME=~/ONOS
+RAMCLOUD_HOME=~/ramcloud
+
+# clone ramcloud
+git clone https://github.com/y-higuchi/ramcloud.git ${RAMCLOUD_HOME}
+cd ${RAMCLOUD_HOME}
+git checkout blueprint-java
+git checkout 64462be50b9b0add25cf16beea75eb40bf89f62c
+
+# install some app
+sudo apt-get -y install build-essential git-core libcppunit-dev libcppunit-doc doxygen libboost-all-dev libpcre3-dev protobuf-compiler libprotobuf-dev libcrypto++-dev libevent-dev scons libssl-dev
+
+# compile ramcloud
+git submodule update --init --recursive
+patch ${RAMCLOUD_HOME}/src/MasterService.cc < ${ONOS_HOME}/ramcloud.patch
+patch ${RAMCLOUD_HOME}/logcabin/Core/Time.h < ${ONOS_HOME}/logcabin.patch
+make logcabin
+make
+
+ln -s ${RAMCLOUD_HOME}/obj obj.blueprint-java
+
+# crate ramcloud lib
+cp ${ONOS_HOME}/src/main/java/edu/stanford/ramcloud/JRamCloud.java ${HOME}/ramcloud/bindings/java/edu/stanford/ramcloud/
+cp ${ONOS_HOME}/src/main/cpp/edu_stanford_ramcloud_JRamCloud.cc ${HOME}/ramcloud/bindings/java/edu/stanford/ramcloud/
+cd ${HOME}/ramcloud/bindings/java/edu/stanford/ramcloud/
+javac JRamCloud.java
+./build_so.sh
+jar cvf ${RAMCLOUD_HOME}/bindings/java/RamCloud.jar ${RAMCLOUD_HOME}/bindings/java/edu/stanford/ramcloud/*.class
diff --git a/src/apps/java/com/tinkerpop/blueprints/impls/ramcloud/FurnaceExamples.java b/src/apps/java/com/tinkerpop/blueprints/impls/ramcloud/FurnaceExamples.java
new file mode 100644
index 0000000..0da987e
--- /dev/null
+++ b/src/apps/java/com/tinkerpop/blueprints/impls/ramcloud/FurnaceExamples.java
@@ -0,0 +1,72 @@
+/* Copyright (c) 2013 Stanford University
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.tinkerpop.blueprints.impls.ramcloud;
+
+import java.util.logging.Level;
+
+import com.tinkerpop.blueprints.Graph;
+import com.tinkerpop.furnace.generators.CommunityGenerator;
+import com.tinkerpop.furnace.generators.DistributionGenerator;
+import com.tinkerpop.furnace.generators.NormalDistribution;
+
+public class FurnaceExamples {
+
+ public FurnaceExamples() {
+ // TODO Auto-generated constructor stub
+ }
+
+ public static int generateCommunityGraph(Graph graph, String label) {
+ CommunityGenerator cg = new CommunityGenerator(label);
+ int numEdges;
+
+ for(int i = 0; i<30; i++) {
+ graph.addVertex(null);
+ }
+
+ cg.setCommunityDistribution(new NormalDistribution(2.0));
+ cg.setDegreeDistribution(new NormalDistribution(2.0));
+ numEdges = cg.generate(graph, 3, 60);
+
+ return numEdges;
+ }
+
+ public static int generateDistributionGraph(Graph graph, String label) {
+ DistributionGenerator dg = new DistributionGenerator(label);
+ int numEdges;
+
+ for(int i = 0; i<10; i++) {
+ graph.addVertex(null);
+ }
+
+ dg.setAllowLoops(true);
+ dg.setInDistribution(new NormalDistribution(2.0));
+ dg.setOutDistribution(new NormalDistribution(2.0));
+ numEdges = dg.generate(graph, 20);
+
+ return numEdges;
+ }
+
+ public static void main(String[] args) {
+ Graph graph = new RamCloudGraph(Level.FINER);
+
+ //generateCommunityGraph(graph, "HippieCommune");
+
+ //generateDistributionGraph(graph, "HippieRefuge");
+
+ graph.shutdown();
+ }
+
+}
diff --git a/src/apps/java/com/tinkerpop/blueprints/impls/ramcloud/JUNGExamples.java b/src/apps/java/com/tinkerpop/blueprints/impls/ramcloud/JUNGExamples.java
new file mode 100644
index 0000000..9645854
--- /dev/null
+++ b/src/apps/java/com/tinkerpop/blueprints/impls/ramcloud/JUNGExamples.java
@@ -0,0 +1,104 @@
+/* Copyright (c) 2013 Stanford University
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.tinkerpop.blueprints.impls.ramcloud;
+
+import java.awt.Dimension;
+import java.util.logging.Level;
+
+import javax.swing.JFrame;
+
+import org.apache.commons.collections15.Transformer;
+
+import com.tinkerpop.blueprints.Edge;
+import com.tinkerpop.blueprints.Graph;
+import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.blueprints.oupls.jung.GraphJung;
+
+import edu.uci.ics.jung.algorithms.layout.BalloonLayout;
+import edu.uci.ics.jung.algorithms.layout.CircleLayout;
+import edu.uci.ics.jung.algorithms.layout.DAGLayout;
+import edu.uci.ics.jung.algorithms.layout.FRLayout;
+import edu.uci.ics.jung.algorithms.layout.FRLayout2;
+import edu.uci.ics.jung.algorithms.layout.ISOMLayout;
+import edu.uci.ics.jung.algorithms.layout.KKLayout;
+import edu.uci.ics.jung.algorithms.layout.Layout;
+import edu.uci.ics.jung.algorithms.scoring.PageRank;
+import edu.uci.ics.jung.visualization.BasicVisualizationServer;
+
+public class JUNGExamples {
+
+ public JUNGExamples() {
+ // TODO Auto-generated constructor stub
+ }
+
+ public static void calculatePageRank(Graph graph) {
+ PageRank<Vertex,Edge> pageRank = new PageRank<Vertex, Edge>(new GraphJung(graph), 0.15d);
+ pageRank.evaluate();
+
+ for (Vertex vertex : graph.getVertices()) {
+ System.out.println("The PageRank score of " + vertex + " is: " + pageRank.getVertexScore(vertex));
+ }
+ }
+
+ public static void displayGraph(Graph graph) {
+ GraphJung gj = new GraphJung(graph);
+
+ Layout<Vertex, Edge> layout = new CircleLayout<Vertex, Edge>(gj);
+ layout.setSize(new Dimension(600, 600));
+ BasicVisualizationServer<Vertex, Edge> viz = new BasicVisualizationServer<Vertex, Edge>(layout);
+ viz.setPreferredSize(new Dimension(650, 650));
+
+ Transformer<Vertex, String> vertexLabelTransformer = new Transformer<Vertex, String>() {
+ public String transform(Vertex vertex) {
+ return (String) vertex.getProperty("name");
+ }
+ };
+
+ Transformer<Edge, String> edgeLabelTransformer = new Transformer<Edge, String>() {
+ public String transform(Edge edge) {
+ return edge.getLabel();
+ }
+ };
+
+ viz.getRenderContext().setEdgeLabelTransformer(edgeLabelTransformer);
+ viz.getRenderContext().setVertexLabelTransformer(vertexLabelTransformer);
+
+ JFrame frame = new JFrame("TinkerPop");
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.getContentPane().add(viz);
+ frame.pack();
+ frame.setVisible(true);
+
+ try {
+ System.in.read();
+ } catch(Exception e) {
+ // poop
+ }
+ }
+
+ public static void main(String[] args) {
+ Graph graph = new RamCloudGraph(Level.FINER);
+
+ FurnaceExamples.generateDistributionGraph(graph, "ex");
+
+ //calculatePageRank(graph);
+
+ displayGraph(graph);
+
+ graph.shutdown();
+ }
+
+}
diff --git a/src/main/cpp/edu_stanford_ramcloud_JRamCloud.cc b/src/main/cpp/edu_stanford_ramcloud_JRamCloud.cc
new file mode 100755
index 0000000..fc93cb4
--- /dev/null
+++ b/src/main/cpp/edu_stanford_ramcloud_JRamCloud.cc
@@ -0,0 +1,766 @@
+/* Copyright (c) 2013 Stanford University
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <RamCloud.h>
+#include <TableEnumerator.h>
+#include <Object.h>
+#include "edu_stanford_ramcloud_JRamCloud.h"
+#include "edu_stanford_ramcloud_JRamCloud_TableEnumerator.h"
+
+using namespace RAMCloud;
+
+/// Our JRamCloud java library is packaged under "edu.stanford.ramcloud".
+/// We will need this when using FindClass, etc.
+#define PACKAGE_PATH "edu/stanford/ramcloud/"
+
+#define check_null(var, msg) \
+ if (var == NULL) { \
+ throw Exception(HERE, "JRamCloud: NULL returned: " msg "\n"); \
+ }
+
+/**
+ * This class provides a simple means of extracting C-style strings
+ * from a jstring and cleans up when the destructor is called. This
+ * avoids having to manually do the annoying GetStringUTFChars /
+ * ReleaseStringUTFChars dance.
+ */
+class JStringGetter {
+ public:
+ JStringGetter(JNIEnv* env, jstring jString)
+ : env(env)
+ , jString(jString)
+ , string(env->GetStringUTFChars(jString, 0))
+ {
+ check_null(string, "GetStringUTFChars failed");
+ }
+
+ ~JStringGetter()
+ {
+ if (string != NULL)
+ env->ReleaseStringUTFChars(jString, string);
+ }
+
+ private:
+ JNIEnv* env;
+ jstring jString;
+
+ public:
+ const char* const string;
+};
+
+/**
+ * This class provides a simple means of accessing jbyteArrays as
+ * C-style void* buffers and cleans up when the destructor is called.
+ * This avoids having to manually do the annoying GetByteArrayElements /
+ * ReleaseByteArrayElements dance.
+ */
+class JByteArrayGetter {
+ public:
+ JByteArrayGetter(JNIEnv* env, jbyteArray jByteArray)
+ : env(env)
+ , jByteArray(jByteArray)
+ , pointer(static_cast<void*>(env->GetByteArrayElements(jByteArray, 0)))
+ , length(env->GetArrayLength(jByteArray))
+ {
+ check_null(pointer, "GetByteArrayElements failed");
+ }
+
+ ~JByteArrayGetter()
+ {
+ if (pointer != NULL) {
+ env->ReleaseByteArrayElements(jByteArray,
+ reinterpret_cast<jbyte*>(pointer),
+ 0);
+ }
+ }
+
+ private:
+ JNIEnv* env;
+ jbyteArray jByteArray;
+
+ public:
+ void* const pointer;
+ const jsize length;
+};
+
+class JByteArrayReference {
+ public:
+ JByteArrayReference(JNIEnv* env, jbyteArray jByteArray)
+ : env(env)
+ , jByteArray(jByteArray)
+ , pointer(static_cast<const void*>(env->GetByteArrayElements(jByteArray, 0)))
+ , length(env->GetArrayLength(jByteArray))
+ {
+ check_null(pointer, "GetByteArrayElements failed");
+ }
+
+ ~JByteArrayReference()
+ {
+ if (pointer != NULL) {
+ env->ReleaseByteArrayElements(jByteArray,
+ (jbyte*)pointer,
+ JNI_ABORT);
+ }
+ }
+
+ private:
+ JNIEnv* env;
+ jbyteArray jByteArray;
+
+ public:
+ const void* const pointer;
+ const jsize length;
+};
+
+static RamCloud*
+getRamCloud(JNIEnv* env, jobject jRamCloud)
+{
+ const static jclass cls = (jclass)env->NewGlobalRef(env->FindClass(PACKAGE_PATH "JRamCloud"));
+ const static jfieldID fieldId = env->GetFieldID(cls, "ramcloudObjectPointer", "J");
+ return reinterpret_cast<RamCloud*>(env->GetLongField(jRamCloud, fieldId));
+}
+
+static TableEnumerator*
+getTableEnumerator(JNIEnv* env, jobject jTableEnumerator)
+{
+ const static jclass cls = (jclass)env->NewGlobalRef(env->FindClass(PACKAGE_PATH "JRamCloud$TableEnumerator"));
+ const static jfieldID fieldId = env->GetFieldID(cls, "tableEnumeratorObjectPointer", "J");
+ return reinterpret_cast<TableEnumerator*>(env->GetLongField(jTableEnumerator, fieldId));
+}
+
+static void
+createException(JNIEnv* env, jobject jRamCloud, const char* name)
+{
+ // Need to specify the full class name, including the package. To make it
+ // slightly more complicated, our exceptions are nested under the JRamCloud
+ // class.
+ string fullName = PACKAGE_PATH;
+ fullName += "JRamCloud$";
+ fullName += name;
+
+ // This would be much easier if we didn't make our Exception classes nested
+ // under JRamCloud since env->ThrowNew() could be used instead. The problem
+ // is that ThrowNew assumes a particular method signature that happens to
+ // be incompatible with the nested classes' signatures.
+ jclass cls = env->FindClass(fullName.c_str());
+ check_null(cls, "FindClass failed");
+
+ jmethodID methodId = env->GetMethodID(cls,
+ "<init>",
+ "(L" PACKAGE_PATH "JRamCloud;Ljava/lang/String;)V");
+ check_null(methodId, "GetMethodID failed");
+
+ jstring jString = env->NewStringUTF("");
+ check_null(jString, "NewStringUTF failed");
+
+ jthrowable exception = reinterpret_cast<jthrowable>(
+ env->NewObject(cls, methodId, jRamCloud, jString));
+ check_null(exception, "NewObject failed");
+
+ env->Throw(exception);
+}
+
+/**
+ * This macro is used to catch C++ exceptions and convert them into Java
+ * exceptions. Be sure to wrap the individual RamCloud:: calls in try blocks,
+ * rather than the entire methods, since doing so with functions that return
+ * non-void is a bad idea with undefined(?) behaviour.
+ *
+ * _returnValue is the value that should be returned from the JNI function
+ * when an exception is caught and generated in Java. As far as I can tell,
+ * the exception fires immediately upon returning from the JNI method. I
+ * don't think anything else would make sense, but the JNI docs kind of
+ * suck.
+ */
+#define EXCEPTION_CATCHER(_returnValue) \
+ catch (TableDoesntExistException& e) { \
+ createException(env, jRamCloud, "TableDoesntExistException"); \
+ return _returnValue; \
+ } catch (ObjectDoesntExistException& e) { \
+ createException(env, jRamCloud, "ObjectDoesntExistException"); \
+ return _returnValue; \
+ } catch (ObjectExistsException& e) { \
+ createException(env, jRamCloud, "ObjectExistsException"); \
+ return _returnValue; \
+ } catch (WrongVersionException& e) { \
+ createException(env, jRamCloud, "WrongVersionException"); \
+ return _returnValue; \
+ } catch (RejectRulesException& e) { \
+ createException(env, jRamCloud, "RejectRulesException"); \
+ return _returnValue; \
+ } catch (InvalidObjectException& e) { \
+ createException(env, jRamCloud, "InvalidObjectException"); \
+ return _returnValue; \
+ }
+
+/*
+ * Class: edu_stanford_ramcloud_JRamCloud
+ * Method: connect
+ * Signature: (Ljava/lang/String;)J
+ */
+JNIEXPORT jlong
+JNICALL Java_edu_stanford_ramcloud_JRamCloud_connect(JNIEnv *env,
+ jclass jRamCloud,
+ jstring coordinatorLocator)
+{
+ JStringGetter locator(env, coordinatorLocator);
+ RamCloud* ramcloud = NULL;
+ try {
+ ramcloud = new RamCloud(locator.string);
+ } EXCEPTION_CATCHER(NULL);
+ return reinterpret_cast<jlong>(ramcloud);
+}
+
+/*
+ * Class: edu_stanford_ramcloud_JRamCloud
+ * Method: disconnect
+ * Signature: (J)V
+ */
+JNIEXPORT void
+JNICALL Java_edu_stanford_ramcloud_JRamCloud_disconnect(JNIEnv *env,
+ jclass jRamCloud,
+ jlong ramcloudObjectPointer)
+{
+ delete reinterpret_cast<RamCloud*>(ramcloudObjectPointer);
+}
+
+/*
+ * Class: edu_stanford_ramcloud_JRamCloud
+ * Method: createTable
+ * Signature: (Ljava/lang/String;)I
+ */
+JNIEXPORT jlong
+JNICALL Java_edu_stanford_ramcloud_JRamCloud_createTable__Ljava_lang_String_2(JNIEnv *env,
+ jobject jRamCloud,
+ jstring jTableName)
+{
+ return Java_edu_stanford_ramcloud_JRamCloud_createTable__Ljava_lang_String_2I(env,
+ jRamCloud,
+ jTableName,
+ 1);
+}
+
+/*
+ * Class: edu_stanford_ramcloud_JRamCloud
+ * Method: createTable
+ * Signature: (Ljava/lang/String;I)I
+ */
+JNIEXPORT jlong
+JNICALL Java_edu_stanford_ramcloud_JRamCloud_createTable__Ljava_lang_String_2I(JNIEnv *env,
+ jobject jRamCloud,
+ jstring jTableName,
+ jint jServerSpan)
+{
+ RamCloud* ramcloud = getRamCloud(env, jRamCloud);
+ JStringGetter tableName(env, jTableName);
+ uint64_t tableId;
+ try {
+ tableId = ramcloud->createTable(tableName.string, jServerSpan);
+ } EXCEPTION_CATCHER(-1);
+ return static_cast<jlong>(tableId);
+}
+
+/*
+ * Class: edu_stanford_ramcloud_JRamCloud
+ * Method: dropTable
+ * Signature: (Ljava/lang/String;)I
+ */
+JNIEXPORT void
+JNICALL Java_edu_stanford_ramcloud_JRamCloud_dropTable(JNIEnv *env,
+ jobject jRamCloud,
+ jstring jTableName)
+{
+ RamCloud* ramcloud = getRamCloud(env, jRamCloud);
+ JStringGetter tableName(env, jTableName);
+ try {
+ ramcloud->dropTable(tableName.string);
+ } EXCEPTION_CATCHER();
+}
+
+/*
+ * Class: edu_stanford_ramcloud_JRamCloud
+ * Method: getTableId
+ * Signature: (Ljava/lang/String;)J
+ */
+JNIEXPORT jlong
+JNICALL Java_edu_stanford_ramcloud_JRamCloud_getTableId(JNIEnv *env,
+ jobject jRamCloud,
+ jstring jTableName)
+{
+ RamCloud* ramcloud = getRamCloud(env, jRamCloud);
+ JStringGetter tableName(env, jTableName);
+ uint64_t tableId;
+ try {
+ tableId = ramcloud->getTableId(tableName.string);
+ } EXCEPTION_CATCHER(-1);
+ return tableId;
+}
+
+/*
+ * Class: edu_stanford_ramcloud_JRamCloud
+ * Method: read
+ * Signature: (J[B)LJRamCloud/Object;
+ */
+JNIEXPORT jobject
+JNICALL Java_edu_stanford_ramcloud_JRamCloud_read__J_3B(JNIEnv *env,
+ jobject jRamCloud,
+ jlong jTableId,
+ jbyteArray jKey)
+{
+ RamCloud* ramcloud = getRamCloud(env, jRamCloud);
+ JByteArrayReference key(env, jKey);
+
+ Buffer buffer;
+ uint64_t version;
+ try {
+ ramcloud->read(jTableId, key.pointer, key.length, &buffer, NULL, &version);
+ } EXCEPTION_CATCHER(NULL);
+
+ jbyteArray jValue = env->NewByteArray(buffer.getTotalLength());
+ check_null(jValue, "NewByteArray failed");
+ JByteArrayGetter value(env, jValue);
+ buffer.copy(0, buffer.getTotalLength(), value.pointer);
+
+ // Note that using 'javap -s' on the class file will print out the method
+ // signatures (the third argument to GetMethodID).
+ const static jclass cls = (jclass)env->NewGlobalRef(env->FindClass(PACKAGE_PATH "JRamCloud$Object"));
+ check_null(cls, "FindClass failed");
+
+ const static jmethodID methodId = env->GetMethodID(cls,
+ "<init>",
+ "(L" PACKAGE_PATH "JRamCloud;[B[BJ)V");
+ check_null(methodId, "GetMethodID failed");
+
+ return env->NewObject(cls,
+ methodId,
+ jRamCloud,
+ jKey,
+ jValue,
+ static_cast<jlong>(version));
+}
+
+/*
+ * Class: edu_stanford_ramcloud_JRamCloud
+ * Method: read
+ * Signature: (J[BLJRamCloud/RejectRules;)LJRamCloud/Object;
+ */
+JNIEXPORT jobject
+JNICALL Java_edu_stanford_ramcloud_JRamCloud_read__J_3BLJRamCloud_RejectRules_2(JNIEnv *env,
+ jobject jRamCloud,
+ jlong jTableId,
+ jbyteArray jKey,
+ jobject jRejectRules)
+{
+ // XXX-- implement me by generalising the other read() method.
+ return NULL;
+}
+
+/*
+ * Class: edu_stanford_ramcloud_JRamCloud
+ * Method: multiRead
+ * Signature: ([Ledu/stanford/ramcloud/JRamCloud$multiReadObject;I)[Ledu/stanford/ramcloud/JRamCloud$Object;
+ */
+JNIEXPORT jobjectArray
+JNICALL Java_edu_stanford_ramcloud_JRamCloud_multiRead(JNIEnv *env,
+ jobject jRamCloud,
+ jobjectArray jmultiReadArray){
+
+ RamCloud* ramcloud = getRamCloud(env, jRamCloud);
+ const jint requestNum = env->GetArrayLength(jmultiReadArray);
+ MultiReadObject objects[requestNum];
+ Tub<Buffer> values[requestNum];
+ jbyteArray jKey[requestNum];
+ MultiReadObject* requests[requestNum];
+
+ const static jclass jc_multiReadObject = (jclass)env->NewGlobalRef(env->FindClass(PACKAGE_PATH "JRamCloud$multiReadObject"));
+ const static jfieldID jf_tableId = env->GetFieldID(jc_multiReadObject, "tableId", "J");
+ const static jfieldID jf_key = env->GetFieldID(jc_multiReadObject, "key", "[B");
+
+ for (int i = 0 ; i < requestNum ; i++){
+ jobject obj = env->GetObjectArrayElement(jmultiReadArray, i);
+ check_null(obj, "GetObjectArrayElement failed");
+ jlong jTableId = env->GetLongField(obj, jf_tableId);
+
+ jKey[i] = (jbyteArray)env->GetObjectField(obj, jf_key);
+
+ jbyte* data = env->GetByteArrayElements(jKey[i], NULL);
+ check_null(data, "GetByteArrayElements failed");
+
+ objects[i].tableId = jTableId;
+ objects[i].key = data;
+ objects[i].keyLength = env->GetArrayLength(jKey[i]);
+ objects[i].value = &values[i];
+ requests[i] = &objects[i];
+ }
+
+ try {
+ ramcloud->multiRead(requests, requestNum);
+ } EXCEPTION_CATCHER(NULL);
+
+ const static jclass jc_RcObject = (jclass)env->NewGlobalRef(env->FindClass(PACKAGE_PATH "JRamCloud$Object"));
+ check_null(jc_RcObject, "FindClass failed");
+ const static jmethodID jm_init = env->GetMethodID(jc_RcObject,
+ "<init>",
+ "(L" PACKAGE_PATH "JRamCloud;[B[BJ)V");
+
+ jobjectArray outJNIArray = env->NewObjectArray(requestNum, jc_RcObject , NULL);
+ check_null(outJNIArray, "NewObjectArray failed");
+
+ for (int i = 0 ; i < requestNum ; i++) {
+ if (objects[i].status == 0) {
+ jbyteArray jValue = env->NewByteArray(values[i].get()->getTotalLength());
+ check_null(jValue, "NewByteArray failed");
+ JByteArrayGetter value(env, jValue);
+ values[i].get()->copy(0, values[i].get()->getTotalLength(), value.pointer);
+ jobject obj = env->NewObject(jc_RcObject, jm_init, jRamCloud, jKey[i], jValue);
+ check_null(obj, "NewObject failed");
+ env->SetObjectArrayElement(outJNIArray, i, obj);
+ }
+ // keys are read only so no need to copy back to Java side: JNI_ABORT
+ env->ReleaseByteArrayElements(jKey[i], (jbyte *) objects[i].key, JNI_ABORT);
+ }
+ return outJNIArray;
+}
+
+
+/*
+ * Class: edu_stanford_ramcloud_JRamCloud
+ * Method: remove
+ * Signature: (J[B)J
+ */
+JNIEXPORT jlong
+JNICALL Java_edu_stanford_ramcloud_JRamCloud_remove__J_3B(JNIEnv *env,
+ jobject jRamCloud,
+ jlong jTableId,
+ jbyteArray jKey)
+{
+ RamCloud* ramcloud = getRamCloud(env, jRamCloud);
+ JByteArrayReference key(env, jKey);
+ uint64_t version;
+ try {
+ ramcloud->remove(jTableId, key.pointer, key.length, NULL, &version);
+ } EXCEPTION_CATCHER(-1);
+ return static_cast<jlong>(version);
+}
+
+/*
+ * Class: edu_stanford_ramcloud_JRamCloud
+ * Method: remove
+ * Signature: (J[BLJRamCloud/RejectRules;)J
+ */
+JNIEXPORT jlong
+JNICALL Java_edu_stanford_ramcloud_JRamCloud_remove__J_3BLJRamCloud_RejectRules_2(JNIEnv *env,
+ jobject jRamCloud,
+ jlong jTableId,
+ jbyteArray jKey,
+ jobject jRejectRules)
+{
+ // XXX- handle RejectRules
+ RamCloud* ramcloud = getRamCloud(env, jRamCloud);
+ JByteArrayReference key(env, jKey);
+ uint64_t version;
+ try {
+ ramcloud->remove(jTableId, key.pointer, key.length, NULL, &version);
+ } EXCEPTION_CATCHER(-1);
+ return static_cast<jlong>(version);
+}
+
+/*
+ * Class: edu_stanford_ramcloud_JRamCloud
+ * Method: write
+ * Signature: (J[B[B)J
+ */
+JNIEXPORT jlong
+JNICALL Java_edu_stanford_ramcloud_JRamCloud_write__J_3B_3B(JNIEnv *env,
+ jobject jRamCloud,
+ jlong jTableId,
+ jbyteArray jKey,
+ jbyteArray jValue)
+{
+ RamCloud* ramcloud = getRamCloud(env, jRamCloud);
+ JByteArrayReference key(env, jKey);
+ JByteArrayGetter value(env, jValue);
+ uint64_t version;
+ try {
+ ramcloud->write(jTableId,
+ key.pointer, key.length,
+ value.pointer, value.length,
+ NULL,
+ &version);
+ } EXCEPTION_CATCHER(-1);
+ return static_cast<jlong>(version);
+}
+
+/*
+ * Class: edu_stanford_ramcloud_JRamCloud
+ * Method: write
+ * Signature: (J[B[BLJRamCloud/RejectRules;)J
+ */
+JNIEXPORT jlong
+JNICALL Java_edu_stanford_ramcloud_JRamCloud_write__J_3B_3BLJRamCloud_RejectRules_2(JNIEnv *env,
+ jobject jRamCloud,
+ jlong jTableId,
+ jbyteArray jKey,
+ jbyteArray jValue,
+ jobject jRejectRules)
+{
+ // XXX- handle RejectRules
+ RamCloud* ramcloud = getRamCloud(env, jRamCloud);
+ JByteArrayReference key(env, jKey);
+ JByteArrayGetter value(env, jValue);
+ RejectRules rules;
+ jclass ruleClass = env->GetObjectClass(jRejectRules);
+ jfieldID fid = env->GetFieldID(ruleClass, "doesntExist", "Z");
+ rules.doesntExist = (uint8_t) env->GetBooleanField(jRejectRules, fid);
+
+ fid = env->GetFieldID(ruleClass, "exists", "Z");
+ rules.exists = (uint8_t) env->GetBooleanField(jRejectRules, fid);
+
+ fid = env->GetFieldID(ruleClass, "givenVersion", "J");
+ rules.givenVersion = env->GetLongField(jRejectRules, fid);
+
+ fid = env->GetFieldID(ruleClass, "versionLeGiven", "Z");
+ rules.versionLeGiven = (uint8_t) env->GetBooleanField(jRejectRules, fid);
+
+ fid = env->GetFieldID(ruleClass, "versionNeGiven", "Z");
+ rules.versionNeGiven = (uint8_t) env->GetBooleanField(jRejectRules, fid);
+
+ uint64_t version;
+ try {
+ ramcloud->write(jTableId,
+ key.pointer, key.length,
+ value.pointer, value.length,
+ &rules,
+ &version);
+ }
+ EXCEPTION_CATCHER(-1);
+ return static_cast<jlong> (version);
+}
+
+JNIEXPORT jlong
+JNICALL Java_edu_stanford_ramcloud_JRamCloud_writeRule(JNIEnv *env,
+ jobject jRamCloud,
+ jlong jTableId,
+ jbyteArray jKey,
+ jbyteArray jValue,
+ jobject jRejectRules) {
+ RamCloud* ramcloud = getRamCloud(env, jRamCloud);
+ JByteArrayReference key(env, jKey);
+ JByteArrayGetter value(env, jValue);
+ uint64_t version;
+ RejectRules rules = {};
+ const static jclass jc_RejectRules = (jclass)env->NewGlobalRef(env->FindClass(PACKAGE_PATH "JRamCloud$RejectRules"));
+
+ const static jfieldID jf_doesntExist = env->GetFieldID(jc_RejectRules, "doesntExist", "Z");
+ check_null(jf_doesntExist, "doesentExist field id is null");
+ jboolean ruleBool;
+ ruleBool = env->GetBooleanField(jRejectRules, jf_doesntExist);
+ rules.doesntExist = ruleBool ? 1 : 0;
+
+ const static jfieldID jf_exists = env->GetFieldID(jc_RejectRules, "exists", "Z");
+ check_null(jf_exists, "exists field id is null");
+ ruleBool = env->GetBooleanField(jRejectRules, jf_exists);
+ rules.exists = ruleBool ? 1 : 0;
+
+ const static jfieldID jf_givenVersion = env->GetFieldID(jc_RejectRules, "givenVersion", "J");
+ check_null(jf_givenVersion, "givenVersion field id is null");
+ rules.givenVersion = env->GetLongField(jRejectRules, jf_givenVersion);
+
+ const static jfieldID jf_versionLeGiven = env->GetFieldID(jc_RejectRules, "versionLeGiven", "Z");
+ check_null(jf_versionLeGiven, "versionLeGiven field id is null");
+ ruleBool = env->GetBooleanField(jRejectRules, jf_versionLeGiven);
+ rules.versionLeGiven = ruleBool ? 1 : 0;
+
+ const static jfieldID jf_versionNeGiven = env->GetFieldID(jc_RejectRules, "versionNeGiven", "Z");
+ check_null(jf_versionNeGiven, "versionNeGiven field id is null");
+ ruleBool = env->GetBooleanField(jRejectRules, jf_versionNeGiven);
+ rules.versionNeGiven = ruleBool ? 1 : 0;
+ try {
+ ramcloud->write(jTableId,
+ key.pointer, key.length,
+ value.pointer, value.length,
+ &rules,
+ &version);
+ }
+ EXCEPTION_CATCHER(-1);
+ return static_cast<jlong> (version);
+}
+
+/*
+ * Class: edu_stanford_ramcloud_JRamCloud_TableEnumerator
+ * Method: init
+ * Signature: (J)V
+ */
+JNIEXPORT jlong JNICALL Java_edu_stanford_ramcloud_JRamCloud_00024TableEnumerator_init(JNIEnv *env,
+ jobject jTableEnumerator,
+ jlong jTableId)
+{
+ const static jclass cls = (jclass)env->NewGlobalRef(env->FindClass(PACKAGE_PATH "JRamCloud$TableEnumerator"));
+ const static jfieldID fieldId = env->GetFieldID(cls, "ramCloudObjectPointer", "J");
+ RamCloud* ramcloud = reinterpret_cast<RamCloud*>(env->GetLongField(jTableEnumerator, fieldId));
+
+ return reinterpret_cast<jlong>(new TableEnumerator(*ramcloud, jTableId));
+}
+
+/*
+ * Class: edu_stanford_ramcloud_JRamCloud_TableEnumerator
+ * Method: hasNext
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_edu_stanford_ramcloud_JRamCloud_00024TableEnumerator_hasNext( JNIEnv *env,
+ jobject jTableEnumerator)
+{
+ TableEnumerator* tableEnum = getTableEnumerator(env, jTableEnumerator);
+ return static_cast<jboolean>(tableEnum->hasNext());
+}
+
+/*
+ * Class: edu_stanford_ramcloud_JRamCloud_TableEnumerator
+ * Method: next
+ * Signature: ()Ledu/stanford/ramcloud/JRamCloud/Object;
+ */
+JNIEXPORT jobject JNICALL Java_edu_stanford_ramcloud_JRamCloud_00024TableEnumerator_next( JNIEnv *env,
+ jobject jTableEnumerator)
+{
+ TableEnumerator* tableEnum = getTableEnumerator(env, jTableEnumerator);
+
+ if(tableEnum->hasNext())
+ {
+ uint32_t size = 0;
+ const void* buffer = 0;
+ uint64_t version = 0;
+
+ tableEnum->next(&size, &buffer);
+ Object object(buffer, size);
+
+ jbyteArray jKey = env->NewByteArray(object.getKeyLength());
+ jbyteArray jValue = env->NewByteArray(object.getDataLength());
+
+ JByteArrayGetter key(env, jKey);
+ JByteArrayGetter value(env, jValue);
+
+ memcpy(key.pointer, object.getKey(), object.getKeyLength());
+ memcpy(value.pointer, object.getData(), object.getDataLength());
+
+ version = object.getVersion();
+
+ const static jclass cls = (jclass)env->NewGlobalRef(env->FindClass(PACKAGE_PATH "JRamCloud$Object"));
+ check_null(cls, "FindClass failed");
+ const static jmethodID methodId = env->GetMethodID(cls,
+ "<init>",
+ "(L" PACKAGE_PATH "JRamCloud;[B[BJ)V");
+ check_null(methodId, "GetMethodID failed");
+ return env->NewObject(cls,
+ methodId,
+ jTableEnumerator,
+ jKey,
+ jValue,
+ static_cast<jlong>(version));
+ } else
+ return NULL;
+}
+
+/*
+ * Class: edu_stanford_ramcloud_JRamCloud
+ * Method: multiWrite
+ * Signature: ([Ledu/stanford/ramcloud/JRamCloud/MultiWriteObject;)[Ledu/stanford/ramcloud/JRamCloud/MultiWriteRspObject;
+ */
+JNIEXPORT jobjectArray JNICALL Java_edu_stanford_ramcloud_JRamCloud_multiWrite(JNIEnv *env, jobject jRamCloud, jobjectArray jmultiWriteArray) {
+ jint requestNum = env->GetArrayLength(jmultiWriteArray);
+ RamCloud* ramcloud = getRamCloud(env, jRamCloud);
+ Tub<MultiWriteObject> objects[requestNum];
+ MultiWriteObject *requests[requestNum];
+ RejectRules rules[requestNum];
+ jbyteArray jKey[requestNum];
+ jbyteArray jValue[requestNum];
+
+ const static jclass jc_multiWriteObject = (jclass)env->NewGlobalRef(env->FindClass(PACKAGE_PATH "JRamCloud$MultiWriteObject"));
+ const static jclass jc_RejectRules = (jclass)env->NewGlobalRef(env->FindClass(PACKAGE_PATH "JRamCloud$RejectRules"));
+ const static jfieldID jf_tableId = env->GetFieldID(jc_multiWriteObject, "tableId", "J");
+ const static jfieldID jf_key = env->GetFieldID(jc_multiWriteObject, "key", "[B");
+ const static jfieldID jf_value = env->GetFieldID(jc_multiWriteObject, "value", "[B");
+ const static jfieldID jf_reject_rules = env->GetFieldID(jc_multiWriteObject, "rules", "L" PACKAGE_PATH "JRamCloud$RejectRules;");
+
+ const static jfieldID jf_doesntExist = env->GetFieldID(jc_RejectRules, "doesntExist", "Z");
+ check_null(jf_doesntExist, "doesentExist field id is null");
+ const static jfieldID jf_exists = env->GetFieldID(jc_RejectRules, "exists", "Z");
+ check_null(jf_exists, "exists field id is null");
+ const static jfieldID jf_givenVersion = env->GetFieldID(jc_RejectRules, "givenVersion", "J");
+ check_null(jf_givenVersion, "givenVersion field id is null");
+ const static jfieldID jf_versionLeGiven = env->GetFieldID(jc_RejectRules, "versionLeGiven", "Z");
+ check_null(jf_versionLeGiven, "versionLeGiven field id is null");
+ const static jfieldID jf_versionNeGiven = env->GetFieldID(jc_RejectRules, "versionNeGiven", "Z");
+ check_null(jf_versionNeGiven, "versionNeGiven field id is null");
+
+ for (int i = 0; i < requestNum; i++) {
+ jobject obj = env->GetObjectArrayElement(jmultiWriteArray, i);
+ check_null(obj, "multi write GetObjectArrayElement failed");
+
+ uint64_t tableId = env->GetLongField(obj, jf_tableId);
+
+ jKey[i] = (jbyteArray)env->GetObjectField(obj, jf_key);
+ jbyte* keyData = env->GetByteArrayElements(jKey[i], NULL);
+ uint16_t keyLength = env->GetArrayLength(jKey[i]);
+
+ jValue[i] = (jbyteArray)env->GetObjectField(obj, jf_value);
+ jbyte* valueData = env->GetByteArrayElements(jValue[i], NULL);
+ uint32_t valueLength = env->GetArrayLength(jValue[i]);
+
+ jobject jRejectRules = env->GetObjectField(obj, jf_reject_rules);
+ rules[i] = {};
+
+ if (jRejectRules != NULL) {
+ jboolean ruleBool;
+
+ ruleBool = env->GetBooleanField(jRejectRules, jf_doesntExist);
+ rules[i].doesntExist = ruleBool ? 1 : 0;
+
+ ruleBool = env->GetBooleanField(jRejectRules, jf_exists);
+ rules[i].exists = ruleBool ? 1 : 0;
+
+ rules[i].givenVersion = env->GetLongField(jRejectRules, jf_givenVersion);
+
+ ruleBool = env->GetBooleanField(jRejectRules, jf_versionLeGiven);
+ rules[i].versionLeGiven = ruleBool ? 1 : 0;
+
+ ruleBool = env->GetBooleanField(jRejectRules, jf_versionNeGiven);
+ rules[i].versionNeGiven = ruleBool ? 1 : 0;
+ }
+ objects[i].construct(tableId, keyData, keyLength, valueData, valueLength, &rules[i]);
+ requests[i] = objects[i].get();
+ }
+ try {
+ ramcloud->multiWrite(requests, requestNum);
+ } EXCEPTION_CATCHER(NULL);
+
+ const static jclass jc_RcObject = (jclass)env->NewGlobalRef(env->FindClass(PACKAGE_PATH "JRamCloud$MultiWriteRspObject"));
+ check_null(jc_RcObject, "FindClass failed");
+ const static jmethodID jm_init = env->GetMethodID(jc_RcObject,
+ "<init>",
+ "(L" PACKAGE_PATH "JRamCloud;IJ)V");
+
+ jobjectArray outJNIArray = env->NewObjectArray(requestNum, jc_RcObject , NULL);
+ check_null(outJNIArray, "NewObjectArray failed");
+
+ for (int i = 0 ; i < requestNum ; i++) {
+ jobject obj = env->NewObject(jc_RcObject, jm_init, jRamCloud, objects[i]->status, objects[i]->version);
+ check_null(obj, "NewObject failed");
+ env->SetObjectArrayElement(outJNIArray, i, obj);
+ env->ReleaseByteArrayElements(jKey[i], (jbyte *)requests[i]->key, JNI_ABORT);
+ env->ReleaseByteArrayElements(jValue[i], (jbyte *)requests[i]->value, JNI_ABORT);
+ objects[i].destroy();
+ }
+ return outJNIArray;
+}
diff --git a/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/PerfMon.java b/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/PerfMon.java
new file mode 100644
index 0000000..158a3c8
--- /dev/null
+++ b/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/PerfMon.java
@@ -0,0 +1,747 @@
+package com.tinkerpop.blueprints.impls.ramcloud;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+// Singleton class
+public final class PerfMon {
+ private static final ThreadLocal<PerfMon> instance = new ThreadLocal<PerfMon>() {
+ @Override
+ protected PerfMon initialValue() {
+ return new PerfMon();
+ }
+ };
+
+ public final long measureAllTimeProp = Long.valueOf(System.getProperty("benchmark.measureAll", "0"));
+ private final static Logger log = LoggerFactory.getLogger(PerfMon.class);
+
+ private static final int debug = 0;
+
+ private long read_latency_sum;
+ private long read_latency_cnt;
+ private int read_flag;
+
+ private long multiread_latency_sum;
+ private long multiread_latency_cnt;
+ private int multiread_flag;
+
+ private long multiwrite_latency_sum;
+ private long multiwrite_latency_cnt;
+ private int multiwrite_flag;
+
+ private long indexread_latency_sum;
+ private long indexread_latency_cnt;
+ private int indexread_flag;
+
+ private long write_latency_sum;
+ private long write_latency_cnt;
+
+ private int write_flag;
+
+ private long indexwrite_latency_sum;
+ private long indexwrite_latency_cnt;
+ private int indexwrite_flag;
+
+ private long serialize_latency_sum;
+ private long serialize_latency_cnt;
+ private int ser_flag;
+
+ private long indexserialize_latency_sum;
+ private long indexserialize_latency_cnt;
+ private int indexser_flag;
+
+ private long proto_serialize_latency_sum;
+ private long proto_serialize_latency_cnt;
+ private int protoser_flag;
+
+ private long deserialize_latency_sum;
+ private long deserialize_latency_cnt;
+ private int deser_flag;
+
+ private long indexdeserialize_latency_sum;
+ private long indexdeserialize_latency_cnt;
+ private int indexdeser_flag;
+
+ private long proto_deserialize_latency_sum;
+ private long proto_deserialize_latency_cnt;
+ private int protodeser_flag;
+
+ private long addsw_time;
+ private long addport_time;
+ private long addlink_time;
+ private long addport_cnt;
+ private long addflowpath_time;
+ private long addflowentry_time;
+ private long addflowentry_cnt;
+
+ private long ser_time;
+ private long indexser_time;
+ private long protoser_time;
+
+ private long deser_time;
+ private long indexdeser_time;
+ private long protodeser_time;
+
+ private long write_time;
+ private long multiwrite_time;
+ private long write_condfails;
+ private long indexwrite_time;
+ private long indexwrite_condfails;
+ private long read_time;
+ private long multiread_time;
+ private long indexread_time;
+ private long read_whole_topology_time;
+
+ public static PerfMon getInstance() {
+ return instance.get();
+ }
+ private PerfMon(){
+ }
+
+ private void clear(){
+ read_latency_sum=0L;
+ read_latency_cnt=0L;
+ multiread_latency_sum=0L;
+ multiread_latency_cnt=0L;
+ multiwrite_latency_sum=0L;
+ multiwrite_latency_cnt=0L;
+ indexread_latency_sum=0L;
+ indexread_latency_cnt=0L;
+ write_latency_sum=0L;
+ write_latency_cnt=0L;
+ indexwrite_latency_sum=0L;
+ indexwrite_latency_cnt=0L;
+ serialize_latency_sum=0L;
+ serialize_latency_cnt=0L;
+ indexserialize_latency_sum=0L;
+ indexserialize_latency_cnt=0L;
+ deserialize_latency_sum=0L;
+ deserialize_latency_cnt=0L;
+ indexdeserialize_latency_sum=0L;
+ indexdeserialize_latency_cnt=0L;
+ read_flag=multiread_flag=indexread_flag=write_flag=indexwrite_flag=deser_flag=indexdeser_flag=ser_flag=indexser_flag=0;
+ addflowpath_time = addflowentry_time = addflowentry_cnt = 0;
+ write_condfails = indexwrite_condfails = 0;
+ read_whole_topology_time = 0;
+ protoser_time = protodeser_time = 0;
+ proto_deserialize_latency_cnt = proto_deserialize_latency_sum = proto_serialize_latency_cnt = proto_serialize_latency_sum = 0;
+ //log.error("flag cleared");
+ }
+
+ private long getSum(){
+ return read_latency_sum + multiread_latency_sum + indexread_latency_sum + write_latency_sum + indexwrite_latency_sum + serialize_latency_sum + indexserialize_latency_sum + deserialize_latency_sum + indexdeserialize_latency_sum;
+ }
+
+ public void addswitch_start(){
+ if(measureAllTimeProp==0)
+ return;
+
+ clear();
+ addsw_time = System.nanoTime();
+ }
+ public void addswitch_end(){
+ if(measureAllTimeProp==0)
+ return;
+
+ long delta;
+ long sum;
+
+ delta = System.nanoTime() - addsw_time;
+ sum = getSum();
+ log.error("Performance add_switch {}"
+ + " read {} ({})"
+ + " multiread {} ({})"
+ + " index_read {} ({})"
+ + " write {} ({})"
+ + " multiwrite {} ({})"
+ + " index_write {} ({})"
+ + " serialize {} ({})"
+ + " indexserialize {} ({})"
+ + " proto_serialize {} ({})"
+ + " deserialize {} ({})"
+ + " indexdeserialize {} ({})"
+ + " proto_deserialize {} ({})"
+ + " rwsd total {} other {} ({})"
+ + " writefail ({}) indexwritefail({})",
+ delta,
+ read_latency_sum, read_latency_cnt,
+ multiread_latency_sum, multiread_latency_cnt,
+ indexread_latency_sum, indexread_latency_cnt,
+ write_latency_sum, write_latency_cnt,
+ multiwrite_latency_sum, multiwrite_latency_cnt,
+ indexwrite_latency_sum, indexwrite_latency_cnt,
+ serialize_latency_sum, serialize_latency_cnt,
+ indexserialize_latency_sum, indexserialize_latency_cnt,
+ proto_serialize_latency_sum, proto_serialize_latency_cnt,
+ deserialize_latency_sum, deserialize_latency_cnt,
+ indexdeserialize_latency_sum, indexdeserialize_latency_cnt,
+ proto_deserialize_latency_sum, proto_deserialize_latency_cnt,
+ sum, delta - sum, (delta - sum) * 100.0 / (delta),
+ write_condfails, indexwrite_condfails);
+ }
+ public void addport_start(){
+ if(measureAllTimeProp==0)
+ return;
+ clear();
+ addport_cnt = 0;
+ addport_time = System.nanoTime();
+ }
+ public void addport_incr(){
+ if(measureAllTimeProp==0)
+ return;
+ addport_cnt ++;
+ }
+ public void addport_end(){
+ if(measureAllTimeProp==0)
+ return;
+ long delta;
+ long sum;
+ delta = System.nanoTime() - addport_time;
+ sum = getSum();
+ log.error("Performance add_port {} ( {} ports )"
+ + " read {} ({})"
+ + " multiread {} ({})"
+ + " index_read {} ({})"
+ + " write {} ({})"
+ + " multiwrite {} ({})"
+ + " index_write {} ({})"
+ + " serialize {} ({})"
+ + " indexserialize {} ({})"
+ + " proto_serialize {} ({})"
+ + " deserialize {} ({})"
+ + " indexdeserialize {} ({})"
+ + " proto_deserialize {} ({})"
+ + " rwsd total {} other {} ({})"
+ + " writefail ({}) indexwritefail({})",
+ delta, addport_cnt,
+ read_latency_sum, read_latency_cnt,
+ multiread_latency_sum, multiread_latency_cnt,
+ indexread_latency_sum, indexread_latency_cnt,
+ write_latency_sum, write_latency_cnt,
+ multiwrite_latency_sum, multiwrite_latency_cnt,
+ indexwrite_latency_sum, indexwrite_latency_cnt,
+ serialize_latency_sum, serialize_latency_cnt,
+ indexserialize_latency_sum, indexserialize_latency_cnt,
+ proto_serialize_latency_sum, proto_serialize_latency_cnt,
+ deserialize_latency_sum, deserialize_latency_cnt,
+ indexdeserialize_latency_sum, indexdeserialize_latency_cnt,
+ proto_deserialize_latency_sum, proto_deserialize_latency_cnt,
+ sum, delta - sum, (delta - sum) * 100.0 / (delta),
+ write_condfails, indexwrite_condfails);
+ }
+ public void addlink_start(){
+ if(measureAllTimeProp==0)
+ return;
+ clear();
+ addlink_time = System.nanoTime();
+ }
+ public void addlink_end(){
+ if(measureAllTimeProp==0)
+ return;
+ long delta;
+ long sum;
+ delta = System.nanoTime() - addlink_time;
+ sum = getSum();
+ log.error("Performance add_link {}"
+ + " read {} ({})"
+ + " multiread {} ({})"
+ + " index_read {} ({})"
+ + " write {} ({})"
+ + " multiwrite {} ({})"
+ + " index_write {} ({})"
+ + " serialize {} ({})"
+ + " indexserialize {} ({})"
+ + " proto_serialize {} ({})"
+ + " deserialize {} ({})"
+ + " indexdeserialize {} ({})"
+ + " proto_deserialize {} ({})"
+ + " rwsd total {} other {} ({})"
+ + " writefail ({}) indexwritefail({})",
+ delta,
+ read_latency_sum, read_latency_cnt,
+ multiread_latency_sum, multiread_latency_cnt,
+ indexread_latency_sum, indexread_latency_cnt,
+ write_latency_sum, write_latency_cnt,
+ multiwrite_latency_sum, multiwrite_latency_cnt,
+ indexwrite_latency_sum, indexwrite_latency_cnt,
+ serialize_latency_sum, serialize_latency_cnt,
+ indexserialize_latency_sum, indexserialize_latency_cnt,
+ proto_serialize_latency_sum, proto_serialize_latency_cnt,
+ deserialize_latency_sum, deserialize_latency_cnt,
+ indexdeserialize_latency_sum, indexdeserialize_latency_cnt,
+ proto_deserialize_latency_sum, proto_deserialize_latency_cnt,
+ sum, delta - sum, (delta - sum) * 100.0 / (delta),
+ write_condfails, indexwrite_condfails);
+ }
+
+ public void addflowpath_start(){
+ if(measureAllTimeProp==0) return;
+ clear();
+ addflowpath_time = System.nanoTime();
+ }
+ public void addflowpath_end(){
+ if(measureAllTimeProp==0) return;
+ long delta;
+ long sum;
+ delta = System.nanoTime() - addflowpath_time;
+ sum = getSum();
+ log.error("Performance add_flowpath {}"
+ + " read {} ({})"
+ + " multiread {} ({})"
+ + " index_read {} ({})"
+ + " write {} ({})"
+ + " multiwrite {} ({})"
+ + " index_write {} ({})"
+ + " serialize {} ({})"
+ + " indexserialize {} ({})"
+ + " proto_serialize {} ({})"
+ + " deserialize {} ({})"
+ + " indexdeserialize {} ({})"
+ + " proto_deserialize {} ({})"
+ + " rwsd total {} other {} ({})"
+ + " writefail ({}) indexwritefail({})",
+ delta,
+ read_latency_sum, read_latency_cnt,
+ multiread_latency_sum, multiread_latency_cnt,
+ indexread_latency_sum, indexread_latency_cnt,
+ write_latency_sum, write_latency_cnt,
+ multiwrite_latency_sum, multiwrite_latency_cnt,
+ indexwrite_latency_sum, indexwrite_latency_cnt,
+ serialize_latency_sum, serialize_latency_cnt,
+ indexserialize_latency_sum, indexserialize_latency_cnt,
+ proto_serialize_latency_sum, proto_serialize_latency_cnt,
+ deserialize_latency_sum, deserialize_latency_cnt,
+ indexdeserialize_latency_sum, indexdeserialize_latency_cnt,
+ proto_deserialize_latency_sum, proto_deserialize_latency_cnt,
+ sum, delta - sum, (delta - sum) * 100.0 / (delta),
+ write_condfails, indexwrite_condfails);
+ }
+
+ public void addflowentry_start(){
+ if(measureAllTimeProp==0) return;
+ clear();
+ if ( debug==1 )
+ log.error("addflowentry_start");
+ addflowentry_time = System.nanoTime();
+ }
+ public void addflowentry_incr(){
+ if(measureAllTimeProp==0) return;
+ addflowentry_cnt++;
+ }
+ public void addflowentry_end(){
+ if(measureAllTimeProp==0) return;
+ long delta;
+ long sum;
+ delta = System.nanoTime() - addflowentry_time;
+ sum = getSum();
+ log.error("Performance add_flowentry {} ( {} flows )"
+ + " read {} ({})"
+ + " multiread {} ({})"
+ + " index_read {} ({})"
+ + " write {} ({})"
+ + " multiwrite {} ({})"
+ + " index_write {} ({})"
+ + " serialize {} ({})"
+ + " indexserialize {} ({})"
+ + " proto_serialize {} ({})"
+ + " deserialize {} ({})"
+ + " indexdeserialize {} ({})"
+ + " proto_deserialize {} ({})"
+ + " rwsd total {} other {} ({})"
+ + " writefail ({}) indexwritefail({})",
+ delta, addflowentry_cnt,
+ read_latency_sum, read_latency_cnt,
+ multiread_latency_sum, multiread_latency_cnt,
+ indexread_latency_sum, indexread_latency_cnt,
+ write_latency_sum, write_latency_cnt,
+ multiwrite_latency_sum, multiwrite_latency_cnt,
+ indexwrite_latency_sum, indexwrite_latency_cnt,
+ serialize_latency_sum, serialize_latency_cnt,
+ indexserialize_latency_sum, indexserialize_latency_cnt,
+ proto_serialize_latency_sum, proto_serialize_latency_cnt,
+ deserialize_latency_sum, deserialize_latency_cnt,
+ indexdeserialize_latency_sum, indexdeserialize_latency_cnt,
+ proto_deserialize_latency_sum, proto_deserialize_latency_cnt,
+ sum, delta - sum, (delta - sum) * 100.0 / (delta),
+ write_condfails, indexwrite_condfails);
+ }
+
+ public void read_whole_topology_start(){
+ if(measureAllTimeProp==0) return;
+ if ( debug==1 )
+ log.error("read_whole_topology_start");
+
+ clear();
+ read_whole_topology_time = System.nanoTime();
+ }
+ public void read_whole_topology_end(){
+ if(measureAllTimeProp==0) return;
+ long delta;
+ long sum;
+ delta = System.nanoTime() - read_whole_topology_time;
+ sum = getSum();
+ log.error("Performance read_whole_topology {}"
+ + " read {} ({})"
+ + " multiread {} ({})"
+ + " index_read {} ({})"
+ + " write {} ({})"
+ + " multiwrite {} ({})"
+ + " index_write {} ({})"
+ + " serialize {} ({})"
+ + " indexserialize {} ({})"
+ + " proto_serialize {} ({})"
+ + " deserialize {} ({})"
+ + " indexdeserialize {} ({})"
+ + " proto_deserialize {} ({})"
+ + " rwsd total {} other {} ({})"
+ + " writefail ({}) indexwritefail({})",
+ delta,
+ read_latency_sum, read_latency_cnt,
+ multiread_latency_sum, multiread_latency_cnt,
+ indexread_latency_sum, indexread_latency_cnt,
+ write_latency_sum, write_latency_cnt,
+ multiwrite_latency_sum, multiwrite_latency_cnt,
+ indexwrite_latency_sum, indexwrite_latency_cnt,
+ serialize_latency_sum, serialize_latency_cnt,
+ indexserialize_latency_sum, indexserialize_latency_cnt,
+ proto_serialize_latency_sum, proto_serialize_latency_cnt,
+ deserialize_latency_sum, deserialize_latency_cnt,
+ indexdeserialize_latency_sum, indexdeserialize_latency_cnt,
+ proto_deserialize_latency_sum, proto_deserialize_latency_cnt,
+ sum, delta - sum, (delta - sum) * 100.0 / (delta),
+ write_condfails, indexwrite_condfails);
+ }
+
+
+ public void read_start(String key){
+ if(measureAllTimeProp==0)
+ return;
+ if ( debug==1 )
+ log.error("read_start {}", key);
+ if ( read_flag != 0){
+ log.error("read_start called twice");
+ }
+ read_flag = 1;
+
+ read_time=System.nanoTime();
+ }
+ public void read_end(String key){
+ if(measureAllTimeProp==0)
+ return;
+ if ( debug==1 )
+ log.error("read_end {}", key);
+
+ read_latency_sum += System.nanoTime() - read_time;
+ read_latency_cnt ++;
+
+ if ( read_flag != 1){
+ log.error("read_end called before read_start");
+ }
+ read_flag = 0;
+ }
+ public void multiread_start(String key){
+ if(measureAllTimeProp==0)
+ return;
+ if ( debug==1 )
+ log.error("multiread_start {}", key);
+ if ( multiread_flag != 0){
+ log.error("multiread_start called twice");
+ }
+ multiread_flag = 1;
+
+ multiread_time=System.nanoTime();
+ }
+ public void multiread_end(String key){
+ if(measureAllTimeProp==0)
+ return;
+
+ multiread_latency_sum += System.nanoTime() - multiread_time;
+ multiread_latency_cnt ++;
+
+ if ( debug==1 )
+ log.error("multiread_end {}", key);
+ if ( multiread_flag != 1){
+ log.error("multiread_end called before multiread_start");
+ }
+ multiread_flag = 0;
+ }
+ public void multiwrite_start(String key){
+ if(measureAllTimeProp==0)
+ return;
+ if ( debug==1 )
+ log.error("multiwrite_start {}", key);
+ if ( multiwrite_flag != 0){
+ log.error("multiwrite_start called twice");
+ }
+ multiwrite_flag = 1;
+
+ multiwrite_time=System.nanoTime();
+ }
+ public void multiwrite_end(String key){
+ if(measureAllTimeProp==0)
+ return;
+
+ multiwrite_latency_sum += System.nanoTime() - multiwrite_time;
+ multiwrite_latency_cnt ++;
+
+ if ( debug==1 )
+ log.error("multiwrite_end {}", key);
+ if ( multiwrite_flag != 1){
+ log.error("multiwrite_end called before multiwrite_start");
+ }
+ multiwrite_flag = 0;
+ }
+ public void indexread_start(String key){
+ if(measureAllTimeProp==0)
+ return;
+ if ( debug==1 )
+ log.error("indexread_start {}", key);
+ if ( indexread_flag != 0){
+ log.error("indexread_start called twice");
+ }
+ indexread_flag = 1;
+
+ indexread_time=System.nanoTime();
+ }
+ public void indexread_end(String key){
+ if(measureAllTimeProp==0)
+ return;
+
+ indexread_latency_sum += System.nanoTime() - indexread_time;
+ indexread_latency_cnt ++;
+
+ if ( debug==1 )
+ log.error("indexread_end {}", key);
+ if ( indexread_flag != 1){
+ log.error("indexread_end called before indexread_start");
+ }
+ indexread_flag = 0;
+ }
+ public void write_start(String key){
+ if(measureAllTimeProp==0)
+ return;
+ if ( debug==1 )
+ log.error("write start_{}", key);
+ if ( write_flag != 0){
+ log.error("write_start called twice");
+ }
+ write_flag = 1;
+
+ write_time = System.nanoTime();
+ }
+ public void write_end(String key){
+ if(measureAllTimeProp==0)
+ return;
+
+ write_latency_sum += System.nanoTime() - write_time;
+ write_latency_cnt ++;
+
+ if ( debug==1 )
+ log.error("write_end {}", key);
+ if ( write_flag != 1){
+ log.error("write_end called before write_start");
+ }
+ write_flag = 0;
+ }
+ public void write_condfail(String key){
+ if(measureAllTimeProp==0)
+ return;
+ write_condfails++;
+ }
+
+ public void indexwrite_start(String key){
+ if(measureAllTimeProp==0)
+ return;
+ if ( debug==1 )
+ log.error("index_write start {}", key);
+ if ( indexwrite_flag != 0){
+ log.error("indexwrite_start called twice");
+ }
+ indexwrite_flag = 1;
+ indexwrite_time = System.nanoTime();
+ }
+ public void indexwrite_end(String key){
+ if(measureAllTimeProp==0)
+ return;
+
+ indexwrite_latency_sum += System.nanoTime() - indexwrite_time;
+ indexwrite_latency_cnt ++;
+
+ if ( debug==1 )
+ log.error("indexwrite_end {}", key);
+ if ( indexwrite_flag != 1){
+ log.error("indexwrite_end called before indexwrite_start");
+ }
+ indexwrite_flag = 0;
+ }
+ public void indexwrite_condfail(String key){
+ if(measureAllTimeProp==0)
+ return;
+ indexwrite_condfails++;
+ }
+
+ public void ser_start(String key){
+ if(measureAllTimeProp==0)
+ return;
+ if ( debug==1 )
+ log.error("ser_start {}", key);
+ if ( ser_flag != 0 ){
+ log.error("ser_start called twice");
+ }
+ ser_flag = 1;
+
+ ser_time = System.nanoTime();
+ }
+ public void ser_end(String key){
+ if(measureAllTimeProp==0)
+ return;
+
+ serialize_latency_sum += System.nanoTime() - ser_time;
+ serialize_latency_cnt ++;
+
+ if ( debug==1 )
+ log.error("ser_end {}", key);
+ if ( ser_flag != 1 ){
+ log.error("ser_end called before ser_start");
+ }
+ ser_flag = 0;
+ }
+
+ public void indexser_start(String key){
+ if(measureAllTimeProp==0)
+ return;
+
+ indexser_time = System.nanoTime();
+
+ if ( debug==1 )
+ log.error("indexser_start {}", key);
+ if ( indexser_flag != 0 ){
+ log.error("indexser_start called twice");
+ }
+ indexser_flag = 1;
+ }
+ public void indexser_end(String key){
+ if(measureAllTimeProp==0)
+ return;
+
+ indexserialize_latency_sum += System.nanoTime() - indexser_time;
+ indexserialize_latency_cnt ++;
+
+ if ( debug==1 )
+ log.error("indexser_end {}", key);
+ if ( indexser_flag != 1 ){
+ log.error("indexser_end called before indexser_start");
+ }
+ indexser_flag = 0;
+
+ }
+
+ public void deser_start(String key){
+ if(measureAllTimeProp==0)
+ return;
+ if ( debug==1 )
+ log.error("deser_start {}", key);
+ if ( deser_flag != 0){
+ log.error("deser_start called twice");
+ }
+ deser_flag = 1;
+
+ deser_time = System.nanoTime();
+ }
+ public void deser_end(String key){
+ if(measureAllTimeProp==0)
+ return;
+
+ deserialize_latency_sum += System.nanoTime() - deser_time;
+ deserialize_latency_cnt ++;
+
+ if ( debug==1 )
+ log.error("deser_end {}", key);
+ if ( deser_flag != 1){
+ log.error("deser_end called before deser_start");
+ }
+ deser_flag = 0;
+ }
+
+ public void indexdeser_start(String key){
+ if(measureAllTimeProp==0)
+ return;
+ if ( debug==1 )
+ log.error("indexdeser_start {}", key);
+ if ( indexdeser_flag != 0){
+ log.error("indexdeser_start called twice");
+ }
+ indexdeser_flag = 1;
+
+ indexdeser_time = System.nanoTime();
+ }
+ public void indexdeser_end(String key){
+ if(measureAllTimeProp==0)
+ return;
+
+ indexdeserialize_latency_sum += System.nanoTime() - indexdeser_time;
+ indexdeserialize_latency_cnt ++;
+
+ if ( debug==1 )
+ log.error("indexdeser_end {}", key);
+ if ( indexdeser_flag != 1){
+ log.error("indexdeser_end called before indexdeser_start");
+ }
+ indexdeser_flag = 0;
+ }
+
+ public void protoser_start(String key){
+ if(measureAllTimeProp==0)
+ return;
+
+ if ( debug==1 )
+ log.error("protoser_start {}", key);
+ if ( protoser_flag != 0){
+ log.error("protoser_start called twice");
+ }
+ protoser_flag = 1;
+
+ protoser_time = System.nanoTime();
+ }
+ public void protoser_end(String key){
+ if(measureAllTimeProp==0)
+ return;
+
+ proto_serialize_latency_sum += System.nanoTime() - protoser_time;
+ proto_serialize_latency_cnt ++;
+
+ if ( debug==1 )
+ log.error("protoser_end {}", key);
+ if ( protoser_flag != 1){
+ log.error("protoser_end called before protoser_start");
+ }
+ protoser_flag = 0;
+ }
+ public void protodeser_start(String key){
+ if(measureAllTimeProp==0)
+ return;
+ if ( debug==1 )
+ log.error("protodeser_start {}", key);
+ if ( protodeser_flag != 0){
+ log.error("protoser_start called twice");
+ }
+ protodeser_flag = 1;
+
+ protodeser_time = System.nanoTime();
+ }
+ public void protodeser_end(String key){
+ if(measureAllTimeProp==0)
+ return;
+
+ proto_deserialize_latency_sum += System.nanoTime() - protodeser_time;
+ proto_deserialize_latency_cnt ++;
+
+ if ( debug==1 )
+ log.error("protodeser_end {}", key);
+ if ( protodeser_flag != 1){
+ log.error("protodeser_end called before protodeser_start");
+ }
+ protodeser_flag = 0;
+ }
+
+}
diff --git a/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/PerfMon.java.hashversion b/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/PerfMon.java.hashversion
new file mode 100644
index 0000000..9847cbd
--- /dev/null
+++ b/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/PerfMon.java.hashversion
@@ -0,0 +1,290 @@
+package com.tinkerpop.blueprints.impls.ramcloud;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import sun.reflect.Reflection;
+
+
+public final class PerfMon {
+ private static final PerfMon instance = new PerfMon();
+ public final long measureAllTimeProp = Long.valueOf(System.getProperty("benchmark.measureAll", "0"));
+ private final static Logger log = LoggerFactory.getLogger(PerfMon.class);
+
+ private static final int debug = 0;
+
+ private static long read_latency_sum;
+ private static long read_latency_cnt;
+ private static int read_flag;
+
+ private static long write_latency_sum;
+ private static long write_latency_cnt;
+ private static int write_flag;
+
+ private static long serialize_latency_sum;
+ private static long serialize_latency_cnt;
+ private static HashMap<String, Long> ser_flag = new HashMap<String, Long>();
+ //private static int ser_flag;
+
+ private static long deserialize_latency_sum;
+ private static long deserialize_latency_cnt;
+ private static int deser_flag;
+
+ private static long addsw_time;
+ private static long addport_time;
+ private static long addlink_time;
+ private static long addport_cnt;
+ private static HashMap<String, Long> ser_time = new HashMap<String, Long>();
+ private static HashMap<String, Long> deser_time = new HashMap<String, Long>();
+ private static HashMap<String, Long> write_time = new HashMap<String, Long>();
+ private static HashMap<String, Long> read_time = new HashMap<String, Long>();
+
+ public static PerfMon getInstance() {
+ return instance;
+ }
+ private PerfMon(){
+ }
+
+ private void clear(){
+ if(! Thread.currentThread().getName().equals("main")){
+ return;
+ }
+ read_latency_sum=0L;
+ read_latency_cnt=0L;
+ write_latency_sum=0L;
+ write_latency_cnt=0L;
+ serialize_latency_sum=0L;
+ serialize_latency_cnt=0L;
+ deserialize_latency_sum=0L;
+ deserialize_latency_cnt=0L;
+ read_flag=write_flag=deser_flag=0;
+ for (Iterator<Map.Entry<String, Long>> it = ser_flag.entrySet().iterator(); it.hasNext(); ) {
+ Map.Entry<String, Long> entry = it.next();
+ entry.setValue(0L);
+ }
+ //log.error("flag cleared");
+ }
+ public void addswitch_start(){
+ if(measureAllTimeProp==0)
+ return;
+
+ if(! Thread.currentThread().getName().equals("main")){
+ return;
+ }
+ clear();
+ addsw_time = System.nanoTime();
+ }
+ public void addswitch_end(){
+ if(measureAllTimeProp==0)
+ return;
+
+ long delta;
+ long sum;
+
+ if(! Thread.currentThread().getName().equals("main")){
+ return;
+ }
+ delta = System.nanoTime() - addsw_time;
+ sum = read_latency_sum + write_latency_sum + serialize_latency_sum + deserialize_latency_sum;
+ log.error("Performance add_switch {} read {} ({}) write {} ({}) serialize {} ({}) deserialize {} ({}) rwsd total {} other {} ({})",
+ delta, read_latency_sum, read_latency_cnt, write_latency_sum, write_latency_cnt, serialize_latency_sum, serialize_latency_cnt, deserialize_latency_sum, deserialize_latency_cnt, sum, delta-sum, ((float)(delta-sum))*100.0/((float) delta));
+ }
+ public void addport_start(){
+ if(measureAllTimeProp==0)
+ return;
+ if(! Thread.currentThread().getName().equals("main")){
+ return;
+ }
+ clear();
+ addport_cnt = 0;
+ addport_time = System.nanoTime();
+ }
+ public void addport_incr(){
+ if(measureAllTimeProp==0)
+ return;
+ if(! Thread.currentThread().getName().equals("main")){
+ return;
+ }
+ clear();
+ addport_cnt ++;
+ }
+ public void addport_end(){
+ if(measureAllTimeProp==0)
+ return;
+ long delta;
+ long sum;
+ if(! Thread.currentThread().getName().equals("main")){
+ return;
+ }
+ delta = System.nanoTime() - addport_time;
+ sum = read_latency_sum + write_latency_sum + serialize_latency_sum + deserialize_latency_sum;
+ log.error("Performance add_port {} ( {} ports ) read {} ({}) write {} ({}) serialize {} ({}) deserialize {} ({}) rwsd total {} other {} ({})",
+ delta, addport_cnt, read_latency_sum, read_latency_cnt, write_latency_sum, write_latency_cnt, serialize_latency_sum, serialize_latency_cnt, deserialize_latency_sum, deserialize_latency_cnt, sum, delta-sum, ((float)(delta-sum))*100.0/((float) delta));
+ }
+ public void addlink_start(){
+ if(measureAllTimeProp==0)
+ return;
+ if(! Thread.currentThread().getName().equals("main")){
+ return;
+ }
+ clear();
+ addlink_time = System.nanoTime();
+ }
+ public void addlink_end(){
+ if(measureAllTimeProp==0)
+ return;
+ long delta;
+ long sum;
+ if(! Thread.currentThread().getName().equals("main")){
+ return;
+ }
+ delta = System.nanoTime() - addlink_time;
+ sum = read_latency_sum + write_latency_sum + serialize_latency_sum + deserialize_latency_sum;
+ log.error("Performance add_link {} read {} ({}) write {} ({}) serialize {} ({}) deserialize {} ({}) rwsd total {} other {} ({})",
+ delta, read_latency_sum, read_latency_cnt, write_latency_sum, write_latency_cnt, serialize_latency_sum, serialize_latency_cnt, deserialize_latency_sum, deserialize_latency_cnt, sum, delta-sum, ((float)(delta-sum))*100.0/((float) delta));
+ }
+
+ public void read_start(String key){
+ if(measureAllTimeProp==0)
+ return;
+ if(! Thread.currentThread().getName().equals("main")){
+ return;
+ }
+ if ( debug==1 )
+ log.error("read start {}", key);
+ read_time.put(key, System.nanoTime());
+ //read_time = System.nanoTime();
+ if ( read_flag != 0){
+ log.error("read is already started");
+ }
+ read_flag = 1;
+ }
+ public void read_end(String key){
+ if(measureAllTimeProp==0)
+ return;
+ long delta;
+ if(! Thread.currentThread().getName().equals("main")){
+ return;
+ }
+ //read_latency_sum += System.nanoTime() - read_time;
+ if ( debug==1 )
+ log.error("read end {}", key);
+ delta = System.nanoTime() - read_time.get(key);
+ read_latency_sum += delta;
+ read_latency_cnt ++;
+ if ( read_flag != 1){
+ log.error("read is not started");
+ }
+ read_flag = 0;
+ }
+ public void write_start(String key){
+ if(measureAllTimeProp==0)
+ return;
+ if(! Thread.currentThread().getName().equals("main")){
+ return;
+ }
+ if ( debug==1 )
+ log.error("write start {}", key);
+ write_time.put(key, System.nanoTime());
+ //write_time = System.nanoTime();
+ if ( write_flag != 0){
+ log.error("write is already started");
+ }
+ write_flag = 1;
+ }
+ public void write_end(String key){
+ if(measureAllTimeProp==0)
+ return;
+ if(! Thread.currentThread().getName().equals("main")){
+ return;
+ }
+ if ( debug==1 )
+ log.error("write end {}", key);
+ write_latency_sum += (System.nanoTime() - write_time.get(key));
+ //write_latency_sum += System.nanoTime() - write_time;
+ write_latency_cnt ++;
+ if ( write_flag != 1){
+ log.error("write is not started");
+ }
+ write_flag = 0;
+ }
+ public void ser_add(long time){
+ if(measureAllTimeProp==0)
+ return;
+ if(! Thread.currentThread().getName().equals("main")){
+ return;
+ }
+ serialize_latency_sum += time;
+ serialize_latency_cnt ++;
+ }
+ public void ser_start(String key){
+ if(measureAllTimeProp==0)
+ return;
+ if(! Thread.currentThread().getName().equals("main")){
+ return;
+ }
+ //ser_time = System.nanoTime();
+ if ( debug==1 )
+ log.error("ser start {}", key);
+ ser_time.put(key, System.nanoTime());
+// log.error("ser {} start at {} flag {}", key, ser_time, ser_flag);
+ if ( ser_flag.containsKey(key) ){
+ if ( ser_flag.get(key) != 0L){
+ log.error("ser {} sarted but has been already started", key);
+ }
+ }
+ ser_flag.put(key, 1L);
+ }
+ public void ser_end(String key){
+ if(measureAllTimeProp==0)
+ return;
+ if(! Thread.currentThread().getName().equals("main")){
+ return;
+ }
+ if ( debug==1 )
+ log.error("ser end {}", key);
+ //serialize_latency_sum += System.nanoTime() - ser_time;
+ serialize_latency_sum += (System.nanoTime() - ser_time.get(key));
+ serialize_latency_cnt ++;
+ // log.error("ser {} end at {} flag {}", key, ser_time, ser_flag);
+ if ( ser_flag.containsKey(key) ){
+ if ( ser_flag.get(key) != 1L){
+ log.error("ser {} ended but hasn't started", key);
+ }
+ }
+ ser_flag.put(key, 0L);
+ }
+ public void deser_start(String key){
+ if(measureAllTimeProp==0)
+ return;
+ if(! Thread.currentThread().getName().equals("main")){
+ return;
+ }
+ if ( debug==1 )
+ log.error("deser start {}", key);
+ deser_time.put(key, System.nanoTime());
+ //deser_time = System.nanoTime();
+ if ( deser_flag != 0){
+ log.error("deser is already started");
+ }
+ deser_flag = 1;
+ }
+ public void deser_end(String key){
+ if(measureAllTimeProp==0)
+ return;
+ if(! Thread.currentThread().getName().equals("main")){
+ return;
+ }
+ if ( debug==1 )
+ log.error("deser end {}", key);
+ //deserialize_latency_sum += System.nanoTime() - deser_time;
+ deserialize_latency_sum += System.nanoTime() - deser_time.get(key);
+ deserialize_latency_cnt ++;
+ if ( deser_flag != 1){
+ log.error("deser is not started");
+ }
+ deser_flag = 0;
+ }
+}
diff --git a/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/RamCloudEdge.java b/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/RamCloudEdge.java
new file mode 100644
index 0000000..c0346c3
--- /dev/null
+++ b/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/RamCloudEdge.java
@@ -0,0 +1,237 @@
+/* Copyright (c) 2013 Stanford University
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.tinkerpop.blueprints.impls.ramcloud;
+
+import java.nio.BufferUnderflowException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.Arrays;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.sun.jersey.core.util.Base64;
+import com.tinkerpop.blueprints.Direction;
+import com.tinkerpop.blueprints.Edge;
+import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.blueprints.util.ExceptionFactory;
+import com.tinkerpop.blueprints.impls.ramcloud.PerfMon;
+import edu.stanford.ramcloud.JRamCloud;
+
+public class RamCloudEdge extends RamCloudElement implements Edge {
+
+ private final static Logger log = LoggerFactory.getLogger(RamCloudGraph.class);
+ private RamCloudVertex outVertex;
+ private RamCloudVertex inVertex;
+ private String label;
+ private byte[] rcKey;
+ private RamCloudGraph graph;
+
+ public RamCloudEdge(RamCloudVertex outVertex, RamCloudVertex inVertex, String label, RamCloudGraph graph) {
+ super(edgeToRcKey(outVertex, inVertex, label), graph.edgePropTableId, graph);
+
+ this.outVertex = outVertex;
+ this.inVertex = inVertex;
+ this.label = label;
+ this.rcKey = edgeToRcKey(outVertex, inVertex, label);
+ this.graph = graph;
+ }
+
+ public RamCloudEdge(byte[] rcKey, RamCloudGraph graph) {
+ super(rcKey, graph.edgePropTableId, graph);
+
+ ByteBuffer edgeId = ByteBuffer.wrap(rcKey).order(ByteOrder.LITTLE_ENDIAN);
+ outVertex = new RamCloudVertex(edgeId.getLong(), graph);
+ inVertex = new RamCloudVertex(edgeId.getLong(), graph);
+ label = new String(rcKey, 16, rcKey.length - 16);
+
+ this.rcKey = rcKey;
+ this.graph = graph;
+ }
+
+ private static byte[] edgeToRcKey(RamCloudVertex outVertex, RamCloudVertex inVertex, String label) {
+ return ByteBuffer.allocate(16 + label.length()).order(ByteOrder.LITTLE_ENDIAN).putLong((Long) outVertex.getId()).putLong((Long) inVertex.getId()).put(label.getBytes()).array();
+ }
+
+ @Override
+ public Vertex getVertex(Direction direction) throws IllegalArgumentException {
+ if (direction.equals(Direction.OUT)) {
+ return outVertex;
+ } else if (direction.equals(Direction.IN)) {
+ return inVertex;
+ } else {
+ throw ExceptionFactory.bothIsNotSupported();
+ }
+ }
+
+ @Override
+ public String getLabel() {
+ return label;
+ }
+
+ public boolean isLoop() {
+ return outVertex.equals(inVertex);
+ }
+
+ public Vertex getNeighbor(Vertex vertex) {
+ if (outVertex.equals(vertex)) {
+ return inVertex;
+ } else if (inVertex.equals(vertex)) {
+ return outVertex;
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public void remove() {
+ if (isLoop()) {
+ outVertex.removeEdgeFromAdjList(this);
+ } else {
+ outVertex.removeEdgeFromAdjList(this);
+ inVertex.removeEdgeFromAdjList(this);
+ }
+
+ super.remove();
+ }
+
+ void removeProperties() {
+ super.remove();
+ }
+
+ @Override
+ public Object getId() {
+ return new String(Base64.encode(rcKey));
+ }
+
+ public boolean exists() {
+ boolean edgePropTableEntryExists;
+ boolean outVertexEntryExists;
+ boolean inVertexEntryExists;
+
+ PerfMon pm = PerfMon.getInstance();
+ try {
+ JRamCloud edgeTable = graph.getRcClient();
+ pm.read_start("RamCloudEdge exists()");
+ edgeTable.read(graph.edgePropTableId, rcKey);
+ pm.read_end("RamCloudEdge exists()");
+ edgePropTableEntryExists = true;
+ } catch (Exception e) {
+ pm.read_end("RamCloudEdge exists()");
+ // Edge property table entry does not exist
+ edgePropTableEntryExists = false;
+ }
+
+ outVertexEntryExists = outVertex.getEdgeSet().contains(this);
+
+ if (!outVertex.equals(inVertex)) {
+ inVertexEntryExists = inVertex.getEdgeSet().contains(this);
+ } else {
+ inVertexEntryExists = outVertexEntryExists;
+ }
+
+ if (edgePropTableEntryExists && outVertexEntryExists && inVertexEntryExists) {
+ return true;
+ } else if (!edgePropTableEntryExists && !outVertexEntryExists && !inVertexEntryExists) {
+ return false;
+ } else {
+ log.warn("{}: Detected RamCloudGraph inconsistency: edgePropTableEntryExists={}, outVertexEntryExists={}, inVertexEntryExists={}.", this, edgePropTableEntryExists, outVertexEntryExists, inVertexEntryExists);
+ return true;
+ }
+ }
+
+ public void create() throws Exception {
+ // TODO: Existence check costs extra (presently 3 reads), could use option to turn on/off
+ if (!exists()) {
+ PerfMon pm = PerfMon.getInstance();
+ // create edge property table
+ JRamCloud edgeTable = graph.getRcClient();
+ pm.write_start("RamCloudEdge create()");
+ edgeTable.write(graph.edgePropTableId, rcKey, ByteBuffer.allocate(0).array());
+ pm.write_end("RamCloudEdge create()");
+
+ boolean addSucc = outVertex.addEdgeToAdjList(this);
+ if ( !addSucc ) {
+ edgeTable.remove(graph.edgePropTableId, rcKey);
+ throw ExceptionFactory.edgeWithIdAlreadyExist(rcKey);
+ }
+ if (!isLoop()) {
+ addSucc = inVertex.addEdgeToAdjList(this);
+ if ( !addSucc ) {
+ edgeTable.remove(graph.edgePropTableId, rcKey);
+ outVertex.removeEdgeFromAdjList(this);
+ throw ExceptionFactory.edgeWithIdAlreadyExist(rcKey);
+ }
+ }
+ } else {
+ throw ExceptionFactory.edgeWithIdAlreadyExist(rcKey);
+ }
+ }
+
+ public static boolean isValidEdgeId(byte[] id) {
+ if (id == null) {
+ return false;
+ }
+ if (id.length == 0) {
+ return false;
+ }
+
+ ByteBuffer edgeId = ByteBuffer.wrap(id);
+ try {
+ edgeId.getLong();
+ } catch (BufferUnderflowException e) {
+ return false;
+ }
+
+ try {
+ edgeId.getLong();
+ } catch (BufferUnderflowException e) {
+ return false;
+ }
+
+ if (edgeId.remaining() == 0) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(rcKey);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ RamCloudEdge other = (RamCloudEdge) obj;
+ return Arrays.equals(rcKey, other.rcKey);
+ }
+
+ @Override
+ public String toString() {
+ return "RamCloudEdge [outVertex=" + outVertex + ", inVertex=" + inVertex
+ + ", label=" + label + "]";
+ }
+}
diff --git a/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/RamCloudElement.java b/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/RamCloudElement.java
new file mode 100644
index 0000000..f1183c5
--- /dev/null
+++ b/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/RamCloudElement.java
@@ -0,0 +1,315 @@
+/* Copyright (c) 2013 Stanford University
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.tinkerpop.blueprints.impls.ramcloud;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
+import java.util.TreeMap;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.io.ByteBufferInput;
+import com.esotericsoftware.kryo.io.Output;
+import com.tinkerpop.blueprints.Edge;
+import com.tinkerpop.blueprints.Element;
+import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.blueprints.util.ExceptionFactory;
+import com.tinkerpop.blueprints.impls.ramcloud.PerfMon;
+
+import edu.stanford.ramcloud.JRamCloud;
+
+public class RamCloudElement implements Element, Serializable {
+
+ private final static Logger log = LoggerFactory.getLogger(RamCloudGraph.class);
+ private byte[] rcPropTableKey;
+ private long rcPropTableId;
+ private RamCloudGraph graph;
+
+ private static final ThreadLocal<Kryo> kryo = new ThreadLocal<Kryo>() {
+ @Override
+ protected Kryo initialValue() {
+ Kryo kryo = new Kryo();
+ kryo.setRegistrationRequired(true);
+ kryo.register(String.class);
+ kryo.register(Long.class);
+ kryo.register(Integer.class);
+ kryo.register(Short.class);
+ kryo.register(Byte.class);
+ kryo.register(TreeMap.class);
+ kryo.register(ArrayList.class);
+ kryo.setReferences(false);
+ return kryo;
+ }
+ };
+
+ public RamCloudElement() {
+ }
+
+ public RamCloudElement(byte[] rcPropTableKey, long rcPropTableId, RamCloudGraph graph) {
+ this.rcPropTableKey = rcPropTableKey;
+ this.rcPropTableId = rcPropTableId;
+ this.graph = graph;
+ }
+
+ protected Map<String, Object> getPropertyMap() {
+ JRamCloud.Object propTableEntry;
+
+ PerfMon pm = PerfMon.getInstance();
+ try {
+ JRamCloud vertTable = graph.getRcClient();
+ pm.read_start("RamCloudElement getPropertyMap()");
+ propTableEntry = vertTable.read(rcPropTableId, rcPropTableKey);
+ pm.read_end("RamCloudElement getPropertyMap()");
+ if (propTableEntry.value.length > 1024 * 1024 * 0.9) {
+ log.warn("Element[id={}] property map size is near 1MB limit!", new String(rcPropTableKey));
+ }
+ } catch (Exception e) {
+ pm.read_end("RamCloudElement getPropertyMap()");
+ log.warn("Element does not have a property table entry!");
+ return null;
+ }
+
+ return convertRcBytesToPropertyMap(propTableEntry.value);
+ }
+
+ public static Map<String, Object> convertRcBytesToPropertyMapEx(byte[] byteArray) {
+ if (byteArray == null) {
+ log.warn("Got a null byteArray argument");
+ return null;
+ } else if (byteArray.length != 0) {
+ PerfMon pm = PerfMon.getInstance();
+ pm.deser_start("RamCloudElement convertRcBytesToPropertyMapEx()");
+ ByteBufferInput input = new ByteBufferInput(byteArray);
+ TreeMap map = kryo.get().readObject(input, TreeMap.class);
+ pm.deser_end("RamCloudElement convertRcBytesToPropertyMapEx()");
+ return map;
+ } else {
+ return new TreeMap<String, Object>();
+ }
+ }
+
+ public Map<String, Object> convertRcBytesToPropertyMap(byte[] byteArray) {
+ if (byteArray == null) {
+ log.warn("Got a null byteArray argument");
+ return null;
+ } else if (byteArray.length != 0) {
+ PerfMon pm = PerfMon.getInstance();
+ long startTime = 0;
+ if(RamCloudGraph.measureSerializeTimeProp == 1) {
+ startTime = System.nanoTime();
+ }
+ pm.deser_start("RamCloudElement convertRcBytesToPropertyMap()");
+ ByteBufferInput input = new ByteBufferInput(byteArray);
+ TreeMap map = kryo.get().readObject(input, TreeMap.class);
+ pm.deser_end("RamCloudElement convertRcBytesToPropertyMap()");
+ if(RamCloudGraph.measureSerializeTimeProp == 1) {
+ long endTime = System.nanoTime();
+ log.error("Performance element kryo deserialization key {} {} size {}", this, endTime - startTime, byteArray.length);
+ }
+ return map;
+ } else {
+ return new TreeMap<String, Object>();
+ }
+ }
+
+ private void setPropertyMap(Map<String, Object> map) {
+ byte[] rcValue;
+ PerfMon pm = PerfMon.getInstance();
+
+ long startKryoTime = 0;
+ if(RamCloudGraph.measureSerializeTimeProp == 1) {
+ startKryoTime = System.nanoTime();
+ }
+ pm.ser_start("RamCloudElement setPropertyMap()");
+ byte[] rcTemp = new byte[1024*1024];
+ Output output = new Output(rcTemp);
+ kryo.get().writeObject(output, map);
+ long midKryoTime = 0;
+ if(RamCloudGraph.measureSerializeTimeProp == 1) {
+ midKryoTime = System.nanoTime();
+ }
+ rcValue = output.toBytes();
+ pm.ser_end("RamCloudElement setPropertyMap()");
+ if(RamCloudGraph.measureSerializeTimeProp == 1) {
+ long endKryoTime = System.nanoTime();
+ log.error("Performance element kryo serialization key {} mid {}, total {}, size {}", this, midKryoTime - startKryoTime, endKryoTime - startKryoTime, rcValue.length);
+ }
+
+ long startTime = 0;
+ JRamCloud vertTable = graph.getRcClient();
+ if (graph.measureRcTimeProp == 1) {
+ startTime = System.nanoTime();
+ }
+ pm.write_start("RamCloudElement setPropertyMap()");
+ vertTable.write(rcPropTableId, rcPropTableKey, rcValue);
+ pm.write_end("RamCloudElement setPropertyMap()");
+ if (graph.measureRcTimeProp == 1) {
+ long endTime = System.nanoTime();
+ log.error("Performance setPropertyMap write time key {} {}", this, endTime - startTime);
+ }
+ }
+
+ @Override
+ public <T> T getProperty(String key) {
+ Map<String, Object> map = getPropertyMap();
+ return (T) map.get(key);
+ }
+
+ @Override
+ public Set<String> getPropertyKeys() {
+ Map<String, Object> map = getPropertyMap();
+ return map.keySet();
+ }
+
+ public Map<String, Object> getProperties() {
+ return getPropertyMap();
+ }
+ public void setProperties(Map<String, Object> properties) {
+ Map<String, Object> map = getPropertyMap();
+ Map<String, Object> oldValueMap = new HashMap<String, Object>(map.size());
+ for (Map.Entry<String, Object> property : properties.entrySet()) {
+ String key = property.getKey();
+ if (key == null) {
+ throw ExceptionFactory.propertyKeyCanNotBeNull();
+ }
+
+ if (key.equals("")) {
+ throw ExceptionFactory.propertyKeyCanNotBeEmpty();
+ }
+
+ if (key.equals("id")) {
+ throw ExceptionFactory.propertyKeyIdIsReserved();
+ }
+
+ if (this instanceof RamCloudEdge && key.equals("label")) {
+ throw ExceptionFactory.propertyKeyLabelIsReservedForEdges();
+ }
+ Object value = property.getValue();
+ if (value == null) {
+ throw ExceptionFactory.propertyValueCanNotBeNull();
+ }
+
+ oldValueMap.put(key, map.put(key, value));
+
+ }
+ setPropertyMap(map);
+
+ // TODO use multi-write
+ for (Map.Entry<String, Object> oldProperty : oldValueMap.entrySet()) {
+ String key = oldProperty.getKey();
+ Object oldValue = oldProperty.getValue();
+ Object value = map.get(key);
+ if (this instanceof RamCloudVertex) {
+ RamCloudKeyIndex keyIndex = new RamCloudKeyIndex(graph.kidxVertTableId, key, value, graph, Vertex.class);
+ keyIndex.autoUpdate(key, value, oldValue, this);
+ } else {
+ RamCloudKeyIndex keyIndex = new RamCloudKeyIndex(graph.kidxVertTableId, key, value, graph, Edge.class);
+ keyIndex.autoUpdate(key, value, oldValue, this);
+ }
+ }
+ }
+
+ @Override
+ public void setProperty(String key, Object value) {
+ Object oldValue;
+ if (value == null) {
+ throw ExceptionFactory.propertyValueCanNotBeNull();
+ }
+
+ if (key == null) {
+ throw ExceptionFactory.propertyKeyCanNotBeNull();
+ }
+
+ if (key.equals("")) {
+ throw ExceptionFactory.propertyKeyCanNotBeEmpty();
+ }
+
+ if (key.equals("id")) {
+ throw ExceptionFactory.propertyKeyIdIsReserved();
+ }
+
+ if (this instanceof RamCloudEdge && key.equals("label")) {
+ throw ExceptionFactory.propertyKeyLabelIsReservedForEdges();
+ }
+
+ long startTime = 0;
+ if (graph.measureBPTimeProp == 1) {
+ startTime = System.nanoTime();
+ }
+
+ Map<String, Object> map = getPropertyMap();
+ oldValue = map.put(key, value);
+ setPropertyMap(map);
+
+ boolean ret = false;
+ if (this instanceof RamCloudVertex) {
+ RamCloudKeyIndex keyIndex = new RamCloudKeyIndex(graph.kidxVertTableId, key, value, graph, Vertex.class);
+ ret = keyIndex.autoUpdate(key, value, oldValue, this);
+ } else {
+ RamCloudKeyIndex keyIndex = new RamCloudKeyIndex(graph.kidxVertTableId, key, value, graph, Edge.class);
+ keyIndex.autoUpdate(key, value, oldValue, this);
+ }
+
+ if (graph.measureBPTimeProp == 1) {
+ long endTime = System.nanoTime();
+ if (ret) {
+ log.error("Performance vertex setProperty(key {}) which is index total time {}", key, endTime - startTime);
+ } else {
+ log.error("Performance vertex setProperty(key {}) does not index time {}", key, endTime - startTime);
+ }
+ }
+
+ }
+
+ @Override
+ public <T> T removeProperty(String key) {
+ Map<String, Object> map = getPropertyMap();
+ T retVal = (T) map.remove(key);
+ setPropertyMap(map);
+ if (this instanceof RamCloudVertex) {
+ RamCloudKeyIndex keyIndex = new RamCloudKeyIndex(graph.kidxVertTableId, key, retVal, graph, Vertex.class);
+ keyIndex.autoRemove(key, retVal.toString(), this);
+ } else {
+ RamCloudKeyIndex keyIndex = new RamCloudKeyIndex(graph.kidxVertTableId, key, retVal, graph, Edge.class);
+ keyIndex.autoRemove(key, retVal.toString(), this);
+ }
+
+ return retVal;
+ }
+
+ @Override
+ public void remove() {
+ graph.getRcClient().remove(rcPropTableId, rcPropTableKey);
+ }
+
+ @Override
+ public Object getId() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String toString() {
+ return "RamCloudElement [rcPropTableKey=" + Arrays.toString(rcPropTableKey)
+ + ", rcPropTableId=" + rcPropTableId + "]";
+ }
+}
diff --git a/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/RamCloudGraph.java b/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/RamCloudGraph.java
new file mode 100644
index 0000000..4843b01
--- /dev/null
+++ b/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/RamCloudGraph.java
@@ -0,0 +1,725 @@
+/* Copyright (c) 2013 Stanford University
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.tinkerpop.blueprints.impls.ramcloud;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.nio.BufferUnderflowException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.sun.jersey.core.util.Base64;
+import com.tinkerpop.blueprints.Direction;
+import com.tinkerpop.blueprints.Edge;
+import com.tinkerpop.blueprints.Element;
+import com.tinkerpop.blueprints.Features;
+import com.tinkerpop.blueprints.GraphQuery;
+import com.tinkerpop.blueprints.Index;
+import com.tinkerpop.blueprints.IndexableGraph;
+import com.tinkerpop.blueprints.KeyIndexableGraph;
+import com.tinkerpop.blueprints.Parameter;
+import com.tinkerpop.blueprints.TransactionalGraph;
+import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.blueprints.util.DefaultGraphQuery;
+import com.tinkerpop.blueprints.util.ExceptionFactory;
+import com.tinkerpop.blueprints.impls.ramcloud.PerfMon;
+
+import edu.stanford.ramcloud.JRamCloud;
+import edu.stanford.ramcloud.JRamCloud.MultiWriteObject;
+
+public class RamCloudGraph implements IndexableGraph, KeyIndexableGraph, TransactionalGraph, Serializable {
+ private final static Logger log = LoggerFactory.getLogger(RamCloudGraph.class);
+
+ private static final ThreadLocal<JRamCloud> RamCloudThreadLocal = new ThreadLocal<JRamCloud>();
+
+ protected long vertTableId; //(vertex_id) --> ( (n,d,ll,l), (n,d,ll,l), ... )
+ protected long vertPropTableId; //(vertex_id) -> ( (kl,k,vl,v), (kl,k,vl,v), ... )
+ protected long edgePropTableId; //(edge_id) -> ( (kl,k,vl,v), (kl,k,vl,v), ... )
+ protected long idxVertTableId;
+ protected long idxEdgeTableId;
+ protected long kidxVertTableId;
+ protected long kidxEdgeTableId;
+ protected long instanceTableId;
+ private String VERT_TABLE_NAME = "verts";
+ private String EDGE_PROP_TABLE_NAME = "edge_props";
+ private String VERT_PROP_TABLE_NAME = "vert_props";
+ private String IDX_VERT_TABLE_NAME = "idx_vert";
+ private String IDX_EDGE_TABLE_NAME = "idx_edge";
+ private String KIDX_VERT_TABLE_NAME = "kidx_vert";
+ private String KIDX_EDGE_TABLE_NAME = "kidx_edge";
+ private final String INSTANCE_TABLE_NAME = "instance";
+ private long instanceId;
+ private AtomicLong nextVertexId;
+ private final long INSTANCE_ID_RANGE = 100000;
+ private String coordinatorLocation;
+ private static final Features FEATURES = new Features();
+ public final long measureBPTimeProp = Long.valueOf(System.getProperty("benchmark.measureBP", "0"));
+ public final long measureRcTimeProp = Long.valueOf(System.getProperty("benchmark.measureRc", "0"));
+ public static final long measureSerializeTimeProp = Long.valueOf(System.getProperty("benchmark.measureSerializeTimeProp", "0"));
+
+
+ public final Set<String> indexedKeys = new HashSet<String>();
+
+ static {
+ FEATURES.supportsSerializableObjectProperty = true;
+ FEATURES.supportsBooleanProperty = true;
+ FEATURES.supportsDoubleProperty = true;
+ FEATURES.supportsFloatProperty = true;
+ FEATURES.supportsIntegerProperty = true;
+ FEATURES.supportsPrimitiveArrayProperty = true;
+ FEATURES.supportsUniformListProperty = true;
+ FEATURES.supportsMixedListProperty = true;
+ FEATURES.supportsLongProperty = true;
+ FEATURES.supportsMapProperty = true;
+ FEATURES.supportsStringProperty = true;
+
+ FEATURES.supportsDuplicateEdges = false;
+ FEATURES.supportsSelfLoops = false;
+ FEATURES.isPersistent = false;
+ FEATURES.isWrapper = false;
+ FEATURES.supportsVertexIteration = true;
+ FEATURES.supportsEdgeIteration = true;
+ FEATURES.supportsVertexIndex = true;
+ FEATURES.supportsEdgeIndex = false;
+ FEATURES.ignoresSuppliedIds = true;
+ FEATURES.supportsTransactions = false;
+ FEATURES.supportsIndices = false;
+ FEATURES.supportsKeyIndices = true;
+ FEATURES.supportsVertexKeyIndex = true;
+ FEATURES.supportsEdgeKeyIndex = false;
+ FEATURES.supportsEdgeRetrieval = true;
+ FEATURES.supportsVertexProperties = true;
+ FEATURES.supportsEdgeProperties = true;
+ FEATURES.supportsThreadedTransactions = false;
+ }
+
+ static {
+ System.loadLibrary("edu_stanford_ramcloud_JRamCloud");
+ }
+
+ private RamCloudGraph() {
+ }
+
+
+ public RamCloudGraph(String coordinatorLocation) {
+ this.coordinatorLocation = coordinatorLocation;
+
+ JRamCloud rcClient = getRcClient();
+
+ vertTableId = rcClient.createTable(VERT_TABLE_NAME);
+ vertPropTableId = rcClient.createTable(VERT_PROP_TABLE_NAME);
+ edgePropTableId = rcClient.createTable(EDGE_PROP_TABLE_NAME);
+ idxVertTableId = rcClient.createTable(IDX_VERT_TABLE_NAME);
+ idxEdgeTableId = rcClient.createTable(IDX_EDGE_TABLE_NAME);
+ kidxVertTableId = rcClient.createTable(KIDX_VERT_TABLE_NAME);
+ kidxEdgeTableId = rcClient.createTable(KIDX_EDGE_TABLE_NAME);
+ instanceTableId = rcClient.createTable(INSTANCE_TABLE_NAME);
+
+ log.info( "Connected to coordinator at {}", coordinatorLocation);
+ log.debug("VERT_TABLE:{}, VERT_PROP_TABLE:{}, EDGE_PROP_TABLE:{}, IDX_VERT_TABLE:{}, IDX_EDGE_TABLE:{}, KIDX_VERT_TABLE:{}, KIDX_EDGE_TABLE:{}", vertTableId, vertPropTableId, edgePropTableId, idxVertTableId, idxEdgeTableId, kidxVertTableId, kidxEdgeTableId);
+ nextVertexId = new AtomicLong(-1);
+ initInstance();
+ }
+
+ public JRamCloud getRcClient() {
+ JRamCloud rcClient = RamCloudThreadLocal.get();
+ if (rcClient == null) {
+ rcClient = new JRamCloud(coordinatorLocation);
+ RamCloudThreadLocal.set(rcClient);
+ }
+ return rcClient;
+ }
+
+ @Override
+ public Features getFeatures() {
+ return FEATURES;
+ }
+
+ private Long parseVertexId(Object id) {
+ Long longId;
+ if (id == null) {
+ longId = nextVertexId.incrementAndGet();
+ } else if (id instanceof Integer) {
+ longId = ((Integer) id).longValue();
+ } else if (id instanceof Long) {
+ longId = (Long) id;
+ } else if (id instanceof String) {
+ try {
+ longId = Long.parseLong((String) id, 10);
+ } catch (NumberFormatException e) {
+ log.warn("ID argument {} of type {} is not a parseable long number: {}", id, id.getClass(), e);
+ return null;
+ }
+ } else if (id instanceof byte[]) {
+ try {
+ longId = ByteBuffer.wrap((byte[]) id).getLong();
+ } catch (BufferUnderflowException e) {
+ log.warn("ID argument {} of type {} is not a parseable long number: {}", id, id.getClass(), e);
+ return null;
+ }
+ } else {
+ log.warn("ID argument {} of type {} is not supported. Returning null.", id, id.getClass());
+ return null;
+ }
+ return longId;
+ }
+
+ @Override
+ public Vertex addVertex(Object id) {
+ long startTime = 0;
+ long Tstamp1 = 0;
+ long Tstamp2 = 0;
+
+ if (measureBPTimeProp == 1) {
+ startTime = System.nanoTime();
+ }
+ Long longId = parseVertexId(id);
+ if (longId == null)
+ return null;
+ if (measureBPTimeProp == 1) {
+ Tstamp1 = System.nanoTime();
+ }
+ RamCloudVertex newVertex = new RamCloudVertex(longId, this);
+ if (measureBPTimeProp == 1) {
+ Tstamp2 = System.nanoTime();
+ log.error("Performance addVertex [id={}] : Calling create at {}", longId, Tstamp2);
+ }
+
+ try {
+ newVertex.create();
+ if (measureBPTimeProp == 1) {
+ long endTime = System.nanoTime();
+ log.error("Performance addVertex [id={}] : genid {} newVerex {} create {} total time {}", longId, Tstamp1 - startTime, Tstamp2 - Tstamp1, endTime - Tstamp2, endTime - startTime);
+ }
+ log.info("Added vertex: [id={}]", longId);
+ return newVertex;
+ } catch (IllegalArgumentException e) {
+ log.error("Tried to create vertex failed {" + newVertex + "}", e);
+ return null;
+ }
+ }
+
+ public List<RamCloudVertex> addVertices(Iterable<Object> ids) {
+ log.info("addVertices start");
+ List<RamCloudVertex> vertices = new LinkedList<RamCloudVertex>();
+
+ for (Object id: ids) {
+ Long longId = parseVertexId(id);
+ if (longId == null)
+ return null;
+ RamCloudVertex v = new RamCloudVertex(longId, this);
+ if (v.exists()) {
+ log.error("ramcloud vertex id: {} already exists", v.getId());
+ throw ExceptionFactory.vertexWithIdAlreadyExists(v.getId());
+ }
+ vertices.add(v);
+ }
+ MultiWriteObject multiWriteObjects[] = new MultiWriteObject[vertices.size() * 2];
+ for (int i=0; i < vertices.size(); i++) {
+ RamCloudVertex v = vertices.get(i);
+ multiWriteObjects[i*2] = new MultiWriteObject(vertTableId, v.rcKey, ByteBuffer.allocate(0).array(), null);
+ multiWriteObjects[i*2+1] = new MultiWriteObject(vertPropTableId, v.rcKey, ByteBuffer.allocate(0).array(), null);
+ }
+ try {
+ PerfMon pm = PerfMon.getInstance();
+ pm.multiwrite_start("RamCloudVertex create()");
+ getRcClient().multiWrite(multiWriteObjects);
+ pm.multiwrite_end("RamCloudVertex create()");
+ log.info("ramcloud vertices are created");
+ } catch (Exception e) {
+ log.error("Tried to create vertices failed {}", e);
+ return null;
+ }
+ log.info("addVertices end (success)");
+ return vertices;
+ }
+
+ private final void initInstance() {
+ //long incrementValue = 1;
+ JRamCloud.Object instanceEntry = null;
+ JRamCloud rcClient = getRcClient();
+ try {
+ instanceEntry = rcClient.read(instanceTableId, "nextInstanceId".getBytes());
+ } catch (Exception e) {
+ if (e instanceof JRamCloud.ObjectDoesntExistException) {
+ instanceId = 0;
+ rcClient.write(instanceTableId, "nextInstanceId".getBytes(), ByteBuffer.allocate(0).array());
+ }
+ }
+ if (instanceEntry != null) {
+ long curInstanceId = 1;
+ for (int i = 0 ; i < 100 ; i++) {
+ Map<String, Long> propMap = null;
+ if (instanceEntry.value == null) {
+ log.warn("Got a null byteArray argument");
+ return;
+ } else if (instanceEntry.value.length != 0) {
+ try {
+ ByteArrayInputStream bais = new ByteArrayInputStream(instanceEntry.value);
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ propMap = (Map<String, Long>) ois.readObject();
+ } catch (IOException e) {
+ log.error("Got an exception while deserializing element's property map: ", e);
+ return;
+ } catch (ClassNotFoundException e) {
+ log.error("Got an exception while deserializing element's property map: ", e);
+ return;
+ }
+ } else {
+ propMap = new HashMap<String, Long>();
+ }
+
+ if (propMap.containsKey(INSTANCE_TABLE_NAME)) {
+ curInstanceId = propMap.get(INSTANCE_TABLE_NAME) + 1;
+ }
+
+ propMap.put(INSTANCE_TABLE_NAME, curInstanceId);
+
+ byte[] rcValue = null;
+ try {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oot = new ObjectOutputStream(baos);
+ oot.writeObject(propMap);
+ rcValue = baos.toByteArray();
+ } catch (IOException e) {
+ log.error("Got an exception while serializing element's property map", e);
+ return;
+ }
+ JRamCloud.RejectRules rules = rcClient.new RejectRules();
+ rules.setNeVersion(instanceEntry.version);
+ try {
+ rcClient.writeRule(instanceTableId, "nextInstanceId".getBytes(), rcValue, rules);
+ instanceId = curInstanceId;
+ break;
+ } catch (Exception ex) {
+ log.debug("Cond. Write increment Vertex property: ", ex);
+ instanceEntry = rcClient.read(instanceTableId, "nextInstanceId".getBytes());
+ continue;
+ }
+ }
+ }
+
+ nextVertexId.compareAndSet(-1, instanceId * INSTANCE_ID_RANGE);
+ }
+
+ @Override
+ public Vertex getVertex(Object id) throws IllegalArgumentException {
+ Long longId;
+
+ if (id == null) {
+ throw ExceptionFactory.vertexIdCanNotBeNull();
+ } else if (id instanceof Integer) {
+ longId = ((Integer) id).longValue();
+ } else if (id instanceof Long) {
+ longId = (Long) id;
+ } else if (id instanceof String) {
+ try {
+ longId = Long.parseLong((String) id, 10);
+ } catch (NumberFormatException e) {
+ log.warn("ID argument {} of type {} is not a parseable long number: {}", id, id.getClass(), e);
+ return null;
+ }
+ } else if (id instanceof byte[]) {
+ try {
+ longId = ByteBuffer.wrap((byte[]) id).getLong();
+ } catch (BufferUnderflowException e) {
+ log.warn("ID argument {} of type {} is not a parseable long number: {}", id, id.getClass(), e);
+ return null;
+ }
+ } else {
+ log.warn("ID argument {} of type {} is not supported. Returning null.", id, id.getClass());
+ return null;
+ }
+
+ RamCloudVertex vertex = new RamCloudVertex(longId, this);
+
+ if (vertex.exists()) {
+ return vertex;
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public void removeVertex(Vertex vertex) {
+ ((RamCloudVertex) vertex).remove();
+ }
+
+ @Override
+ public Iterable<Vertex> getVertices() {
+ JRamCloud.TableEnumerator tableEnum = getRcClient().new TableEnumerator(vertPropTableId);
+ List<Vertex> vertices = new LinkedList<Vertex>();
+
+ while (tableEnum.hasNext()) {
+ vertices.add(new RamCloudVertex(tableEnum.next().key, this));
+ }
+
+ return vertices;
+ }
+
+ @Override
+ public Iterable<Vertex> getVertices(String key, Object value) {
+ long startTime = 0;
+ long Tstamp1 = 0;
+ long Tstamp2 = 0;
+ long Tstamp3 = 0;
+ if (measureBPTimeProp == 1) {
+ startTime = System.nanoTime();
+ log.error("Performance getVertices(key {}) start at {}", key, startTime);
+ }
+
+ List<Vertex> vertices = new ArrayList<Vertex>();
+ List<Object> vertexList = null;
+
+ JRamCloud vertTable = getRcClient();
+ if (measureBPTimeProp == 1) {
+ Tstamp1 = System.nanoTime();
+ log.error("Performance getVertices(key {}) Calling indexedKeys.contains(key) at {}", key, Tstamp1);
+ }
+
+
+ if (indexedKeys.contains(key)) {
+ PerfMon pm = PerfMon.getInstance();
+ if (measureBPTimeProp == 1) {
+ Tstamp2 = System.nanoTime();
+ log.error("Performance getVertices(key {}) Calling new RamCloudKeyIndex at {}", key, Tstamp2);
+ }
+ RamCloudKeyIndex KeyIndex = new RamCloudKeyIndex(kidxVertTableId, key, value, this, Vertex.class);
+ if (measureBPTimeProp == 1) {
+ Tstamp3 = System.nanoTime();
+ log.error("Performance getVertices(key {}) Calling KeyIndex.GetElmIdListForPropValue at {}", key, Tstamp3);
+ }
+ vertexList = KeyIndex.getElmIdListForPropValue(value.toString());
+ if (vertexList == null) {
+ if (measureBPTimeProp == 1) {
+ long endTime = System.nanoTime();
+ log.error("Performance getVertices(key {}) does not exists : getRcClient {} indexedKeys.contains(key) {} new_RamCloudKeyIndex {} KeyIndex.get..Value {} total {} diff {}", key, Tstamp1-startTime, Tstamp2-Tstamp1,Tstamp3-Tstamp2, endTime-Tstamp3, endTime - startTime, (endTime-startTime)- (Tstamp1-startTime)- (Tstamp2-Tstamp1)- (Tstamp3-Tstamp2)-(endTime-Tstamp3));
+ }
+ return vertices;
+ }
+
+ final int mreadMax = 400;
+ final int size = Math.min(mreadMax, vertexList.size());
+ JRamCloud.multiReadObject vertPropTableMread[] = new JRamCloud.multiReadObject[size];
+
+ int vertexNum = 0;
+ for (Object vert : vertexList) {
+ byte[] rckey =
+ ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN).putLong((Long) vert).array();
+ vertPropTableMread[vertexNum] = new JRamCloud.multiReadObject(vertPropTableId, rckey);
+ if (vertexNum >= (mreadMax - 1)) {
+ pm.multiread_start("RamCloudGraph getVertices()");
+ JRamCloud.Object outvertPropTable[] =
+ vertTable.multiRead(vertPropTableMread);
+ pm.multiread_end("RamCloudGraph getVertices()");
+ for (int i = 0; i < outvertPropTable.length; i++) {
+ if (outvertPropTable[i] != null) {
+ vertices.add(new RamCloudVertex(outvertPropTable[i].key, this));
+ }
+ }
+ vertexNum = 0;
+ continue;
+ }
+ vertexNum++;
+ }
+
+ if (vertexNum != 0) {
+ JRamCloud.multiReadObject mread_leftover[] = Arrays.copyOf(vertPropTableMread, vertexNum);
+
+ long startTime2 = 0;
+ if (measureRcTimeProp == 1) {
+ startTime2 = System.nanoTime();
+ }
+ pm.multiread_start("RamCloudGraph getVertices()");
+ JRamCloud.Object outvertPropTable[] = vertTable.multiRead(mread_leftover);
+ pm.multiread_end("RamCloudGraph getVertices()");
+ if (measureRcTimeProp == 1) {
+ long endTime2 = System.nanoTime();
+ log.error("Performance index multiread(key {}, number {}) time {}", key, vertexNum, endTime2 - startTime2);
+ }
+ for (int i = 0; i < outvertPropTable.length; i++) {
+ if (outvertPropTable[i] != null) {
+ vertices.add(new RamCloudVertex(outvertPropTable[i].key, this));
+ }
+ }
+ }
+ } else {
+
+ JRamCloud.TableEnumerator tableEnum = getRcClient().new TableEnumerator(vertPropTableId);
+ JRamCloud.Object tableEntry;
+
+ while (tableEnum.hasNext()) {
+ tableEntry = tableEnum.next();
+ if (tableEntry != null) {
+ //XXX remove temp
+ // RamCloudVertex temp = new RamCloudVertex(tableEntry.key, this);
+ Map<String, Object> propMap = RamCloudElement.convertRcBytesToPropertyMapEx(tableEntry.value);
+ if (propMap.containsKey(key) && propMap.get(key).equals(value)) {
+ vertices.add(new RamCloudVertex(tableEntry.key, this));
+ }
+ }
+ }
+ }
+
+ if (measureBPTimeProp == 1) {
+ long endTime = System.nanoTime();
+ log.error("Performance getVertices exists total time {}.", endTime - startTime);
+ }
+
+ return vertices;
+ }
+
+ @Override
+ public Edge addEdge(Object id, Vertex outVertex, Vertex inVertex, String label) throws IllegalArgumentException {
+ log.info("Adding edge: [id={}, outVertex={}, inVertex={}, label={}]", id, outVertex, inVertex, label);
+
+ if (label == null) {
+ throw ExceptionFactory.edgeLabelCanNotBeNull();
+ }
+
+ RamCloudEdge newEdge = new RamCloudEdge((RamCloudVertex) outVertex, (RamCloudVertex) inVertex, label, this);
+
+ for (int i = 0; i < 5 ;i++) {
+ try {
+ newEdge.create();
+ return newEdge;
+ } catch (Exception e) {
+ log.warn("Tried to create edge failed: {" + newEdge + "}: ", e);
+
+ if (e instanceof NoSuchElementException) {
+ log.error("addEdge RETRYING {}", i);
+ continue;
+ }
+ }
+ }
+ return null;
+ }
+
+ public List<Edge> addEdges(Iterable<Edge> edgeEntities) throws IllegalArgumentException {
+ //TODO WIP: need multi-write
+ log.info("addEdges start");
+ ArrayList<Edge> edges = new ArrayList<Edge>();
+ for (Edge edge: edgeEntities) {
+ edges.add(addEdge(null, edge.getVertex(Direction.OUT), edge.getVertex(Direction.IN), edge.getLabel()));
+ }
+ log.info("addVertices end");
+ return edges;
+ }
+
+ public void setProperties(Map<RamCloudVertex, Map<String, Object>> properties) {
+ // TODO WIP: need multi-write
+ log.info("setProperties start");
+ for (Map.Entry<RamCloudVertex, Map<String, Object>> e: properties.entrySet()) {
+ e.getKey().setProperties(e.getValue());
+ }
+ log.info("setProperties end");
+ }
+
+ @Override
+ public Edge getEdge(Object id) throws IllegalArgumentException {
+ byte[] bytearrayId;
+
+ if (id == null) {
+ throw ExceptionFactory.edgeIdCanNotBeNull();
+ } else if (id instanceof byte[]) {
+ bytearrayId = (byte[]) id;
+ } else if (id instanceof String) {
+ bytearrayId = Base64.decode(((String) id));
+ } else {
+ log.warn("ID argument {} of type {} is not supported. Returning null.", id, id.getClass());
+ return null;
+ }
+
+ if (!RamCloudEdge.isValidEdgeId(bytearrayId)) {
+ log.warn("ID argument {} of type {} is malformed. Returning null.", id, id.getClass());
+ return null;
+ }
+
+ RamCloudEdge edge = new RamCloudEdge(bytearrayId, this);
+
+ if (edge.exists()) {
+ return edge;
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public void removeEdge(Edge edge) {
+ edge.remove();
+ }
+
+ @Override
+ public Iterable<Edge> getEdges() {
+ JRamCloud.TableEnumerator tableEnum = getRcClient().new TableEnumerator(edgePropTableId);
+ List<Edge> edges = new ArrayList<Edge>();
+
+ while (tableEnum.hasNext()) {
+ edges.add(new RamCloudEdge(tableEnum.next().key, this));
+ }
+
+ return edges;
+ }
+
+ @Override
+ public Iterable<Edge> getEdges(String key, Object value) {
+ JRamCloud.TableEnumerator tableEnum = getRcClient().new TableEnumerator(edgePropTableId);
+ List<Edge> edges = new ArrayList<Edge>();
+ JRamCloud.Object tableEntry;
+
+ while (tableEnum.hasNext()) {
+ tableEntry = tableEnum.next();
+ // FIXME temp
+ //RamCloudEdge temp = new RamCloudEdge(tableEntry.key, this);
+ Map<String, Object> propMap = RamCloudElement.convertRcBytesToPropertyMapEx(tableEntry.value);
+ if (propMap.containsKey(key) && propMap.get(key).equals(value)) {
+ edges.add(new RamCloudEdge(tableEntry.key, this));
+ }
+ }
+
+ return edges;
+ }
+
+ @Override
+ public GraphQuery query() {
+ return new DefaultGraphQuery(this);
+ }
+
+ @Override
+ public void shutdown() {
+ JRamCloud rcClient = getRcClient();
+ rcClient.dropTable(VERT_TABLE_NAME);
+ rcClient.dropTable(VERT_PROP_TABLE_NAME);
+ rcClient.dropTable(EDGE_PROP_TABLE_NAME);
+ rcClient.dropTable(IDX_VERT_TABLE_NAME);
+ rcClient.dropTable(IDX_EDGE_TABLE_NAME);
+ rcClient.dropTable(KIDX_VERT_TABLE_NAME);
+ rcClient.dropTable(KIDX_EDGE_TABLE_NAME);
+ rcClient.disconnect();
+ }
+
+ @Override
+ public void stopTransaction(Conclusion conclusion) {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void commit() {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void rollback() {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public <T extends Element> void dropKeyIndex(String key, Class<T> elementClass) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ //FIXME how to dropKeyIndex
+ //new RamCloudKeyIndex(kidxVertTableId, key, this, elementClass);
+ //getIndexedKeys(key, elementClass).removeIndex();
+ }
+
+ @Override
+ public <T extends Element> void createKeyIndex(String key,
+ Class<T> elementClass, Parameter... indexParameters) {
+ if (key == null) {
+ return;
+ }
+ if (this.indexedKeys.contains(key)) {
+ return;
+ }
+ this.indexedKeys.add(key);
+ }
+
+ @Override
+ public <T extends Element> Set< String> getIndexedKeys(Class< T> elementClass) {
+ if (null != this.indexedKeys) {
+ return new HashSet<String>(this.indexedKeys);
+ } else {
+ return Collections.emptySet();
+ }
+ }
+
+ @Override
+ public <T extends Element> Index<T> createIndex(String indexName,
+ Class<T> indexClass, Parameter... indexParameters) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public <T extends Element> Index<T> getIndex(String indexName, Class<T> indexClass) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Iterable<Index<? extends Element>> getIndices() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void dropIndex(String indexName) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName().toLowerCase() + "[vertices:" + ((List<Vertex>)getVertices()).size() + " edges:" + ((List<Edge>)getEdges()).size() + "]";
+ }
+
+ public static void main(String[] args) {
+ RamCloudGraph graph = new RamCloudGraph();
+
+ Vertex a = graph.addVertex(null);
+ Vertex b = graph.addVertex(null);
+ Vertex c = graph.addVertex(null);
+ Vertex d = graph.addVertex(null);
+ Vertex e = graph.addVertex(null);
+ Vertex f = graph.addVertex(null);
+ Vertex g = graph.addVertex(null);
+
+ graph.addEdge(null, a, a, "friend");
+ graph.addEdge(null, a, b, "friend1");
+ graph.addEdge(null, a, b, "friend2");
+ graph.addEdge(null, a, b, "friend3");
+ graph.addEdge(null, a, c, "friend");
+ graph.addEdge(null, a, d, "friend");
+ graph.addEdge(null, a, e, "friend");
+ graph.addEdge(null, a, f, "friend");
+ graph.addEdge(null, a, g, "friend");
+
+ graph.shutdown();
+ }
+}
diff --git a/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/RamCloudGraphProtos.java b/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/RamCloudGraphProtos.java
new file mode 100644
index 0000000..9a126eb
--- /dev/null
+++ b/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/RamCloudGraphProtos.java
@@ -0,0 +1,3861 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: ramcloudgraph.proto
+
+package com.tinkerpop.blueprints.impls.ramcloud;
+
+public final class RamCloudGraphProtos {
+ private RamCloudGraphProtos() {}
+ public static void registerAllExtensions(
+ com.google.protobuf.ExtensionRegistry registry) {
+ }
+ public interface EdgeListProtoBufOrBuilder
+ extends com.google.protobuf.MessageOrBuilder {
+
+ // repeated .RamCloudGraph.EdgeProtoBuf edge = 1;
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ java.util.List<com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf>
+ getEdgeList();
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf getEdge(int index);
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ int getEdgeCount();
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ java.util.List<? extends com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBufOrBuilder>
+ getEdgeOrBuilderList();
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBufOrBuilder getEdgeOrBuilder(
+ int index);
+ }
+ /**
+ * Protobuf type {@code RamCloudGraph.EdgeListProtoBuf}
+ */
+ public static final class EdgeListProtoBuf extends
+ com.google.protobuf.GeneratedMessage
+ implements EdgeListProtoBufOrBuilder {
+ // Use EdgeListProtoBuf.newBuilder() to construct.
+ private EdgeListProtoBuf(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
+ super(builder);
+ this.unknownFields = builder.getUnknownFields();
+ }
+ private EdgeListProtoBuf(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }
+
+ private static final EdgeListProtoBuf defaultInstance;
+ public static EdgeListProtoBuf getDefaultInstance() {
+ return defaultInstance;
+ }
+
+ public EdgeListProtoBuf getDefaultInstanceForType() {
+ return defaultInstance;
+ }
+
+ private final com.google.protobuf.UnknownFieldSet unknownFields;
+ @java.lang.Override
+ public final com.google.protobuf.UnknownFieldSet
+ getUnknownFields() {
+ return this.unknownFields;
+ }
+ private EdgeListProtoBuf(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ initFields();
+ int mutable_bitField0_ = 0;
+ com.google.protobuf.UnknownFieldSet.Builder unknownFields =
+ com.google.protobuf.UnknownFieldSet.newBuilder();
+ try {
+ boolean done = false;
+ while (!done) {
+ int tag = input.readTag();
+ switch (tag) {
+ case 0:
+ done = true;
+ break;
+ default: {
+ if (!parseUnknownField(input, unknownFields,
+ extensionRegistry, tag)) {
+ done = true;
+ }
+ break;
+ }
+ case 10: {
+ if (!((mutable_bitField0_ & 0x00000001) == 0x00000001)) {
+ edge_ = new java.util.ArrayList<com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf>();
+ mutable_bitField0_ |= 0x00000001;
+ }
+ edge_.add(input.readMessage(com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf.PARSER, extensionRegistry));
+ break;
+ }
+ }
+ }
+ } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+ throw e.setUnfinishedMessage(this);
+ } catch (java.io.IOException e) {
+ throw new com.google.protobuf.InvalidProtocolBufferException(
+ e.getMessage()).setUnfinishedMessage(this);
+ } finally {
+ if (((mutable_bitField0_ & 0x00000001) == 0x00000001)) {
+ edge_ = java.util.Collections.unmodifiableList(edge_);
+ }
+ this.unknownFields = unknownFields.build();
+ makeExtensionsImmutable();
+ }
+ }
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.internal_static_RamCloudGraph_EdgeListProtoBuf_descriptor;
+ }
+
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.internal_static_RamCloudGraph_EdgeListProtoBuf_fieldAccessorTable
+ .ensureFieldAccessorsInitialized(
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf.class, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf.Builder.class);
+ }
+
+ public static com.google.protobuf.Parser<EdgeListProtoBuf> PARSER =
+ new com.google.protobuf.AbstractParser<EdgeListProtoBuf>() {
+ public EdgeListProtoBuf parsePartialFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return new EdgeListProtoBuf(input, extensionRegistry);
+ }
+ };
+
+ @java.lang.Override
+ public com.google.protobuf.Parser<EdgeListProtoBuf> getParserForType() {
+ return PARSER;
+ }
+
+ // repeated .RamCloudGraph.EdgeProtoBuf edge = 1;
+ public static final int EDGE_FIELD_NUMBER = 1;
+ private java.util.List<com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf> edge_;
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ public java.util.List<com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf> getEdgeList() {
+ return edge_;
+ }
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ public java.util.List<? extends com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBufOrBuilder>
+ getEdgeOrBuilderList() {
+ return edge_;
+ }
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ public int getEdgeCount() {
+ return edge_.size();
+ }
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf getEdge(int index) {
+ return edge_.get(index);
+ }
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBufOrBuilder getEdgeOrBuilder(
+ int index) {
+ return edge_.get(index);
+ }
+
+ private void initFields() {
+ edge_ = java.util.Collections.emptyList();
+ }
+ private byte memoizedIsInitialized = -1;
+ public final boolean isInitialized() {
+ byte isInitialized = memoizedIsInitialized;
+ if (isInitialized != -1) return isInitialized == 1;
+
+ for (int i = 0; i < getEdgeCount(); i++) {
+ if (!getEdge(i).isInitialized()) {
+ memoizedIsInitialized = 0;
+ return false;
+ }
+ }
+ memoizedIsInitialized = 1;
+ return true;
+ }
+
+ public void writeTo(com.google.protobuf.CodedOutputStream output)
+ throws java.io.IOException {
+ getSerializedSize();
+ for (int i = 0; i < edge_.size(); i++) {
+ output.writeMessage(1, edge_.get(i));
+ }
+ getUnknownFields().writeTo(output);
+ }
+
+ private int memoizedSerializedSize = -1;
+ public int getSerializedSize() {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ for (int i = 0; i < edge_.size(); i++) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeMessageSize(1, edge_.get(i));
+ }
+ size += getUnknownFields().getSerializedSize();
+ memoizedSerializedSize = size;
+ return size;
+ }
+
+ private static final long serialVersionUID = 0L;
+ @java.lang.Override
+ protected java.lang.Object writeReplace()
+ throws java.io.ObjectStreamException {
+ return super.writeReplace();
+ }
+
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf parseFrom(
+ com.google.protobuf.ByteString data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf parseFrom(
+ com.google.protobuf.ByteString data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf parseFrom(byte[] data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf parseFrom(
+ byte[] data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf parseFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf parseFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input, extensionRegistry);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf parseDelimitedFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return PARSER.parseDelimitedFrom(input);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf parseDelimitedFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return PARSER.parseDelimitedFrom(input, extensionRegistry);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf parseFrom(
+ com.google.protobuf.CodedInputStream input)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf parseFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input, extensionRegistry);
+ }
+
+ public static Builder newBuilder() { return Builder.create(); }
+ public Builder newBuilderForType() { return newBuilder(); }
+ public static Builder newBuilder(com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf prototype) {
+ return newBuilder().mergeFrom(prototype);
+ }
+ public Builder toBuilder() { return newBuilder(this); }
+
+ @java.lang.Override
+ protected Builder newBuilderForType(
+ com.google.protobuf.GeneratedMessage.BuilderParent parent) {
+ Builder builder = new Builder(parent);
+ return builder;
+ }
+ /**
+ * Protobuf type {@code RamCloudGraph.EdgeListProtoBuf}
+ */
+ public static final class Builder extends
+ com.google.protobuf.GeneratedMessage.Builder<Builder>
+ implements com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBufOrBuilder {
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.internal_static_RamCloudGraph_EdgeListProtoBuf_descriptor;
+ }
+
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.internal_static_RamCloudGraph_EdgeListProtoBuf_fieldAccessorTable
+ .ensureFieldAccessorsInitialized(
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf.class, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf.Builder.class);
+ }
+
+ // Construct using com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf.newBuilder()
+ private Builder() {
+ maybeForceBuilderInitialization();
+ }
+
+ private Builder(
+ com.google.protobuf.GeneratedMessage.BuilderParent parent) {
+ super(parent);
+ maybeForceBuilderInitialization();
+ }
+ private void maybeForceBuilderInitialization() {
+ if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
+ getEdgeFieldBuilder();
+ }
+ }
+ private static Builder create() {
+ return new Builder();
+ }
+
+ public Builder clear() {
+ super.clear();
+ if (edgeBuilder_ == null) {
+ edge_ = java.util.Collections.emptyList();
+ bitField0_ = (bitField0_ & ~0x00000001);
+ } else {
+ edgeBuilder_.clear();
+ }
+ return this;
+ }
+
+ public Builder clone() {
+ return create().mergeFrom(buildPartial());
+ }
+
+ public com.google.protobuf.Descriptors.Descriptor
+ getDescriptorForType() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.internal_static_RamCloudGraph_EdgeListProtoBuf_descriptor;
+ }
+
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf getDefaultInstanceForType() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf.getDefaultInstance();
+ }
+
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf build() {
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf result = buildPartial();
+ if (!result.isInitialized()) {
+ throw newUninitializedMessageException(result);
+ }
+ return result;
+ }
+
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf buildPartial() {
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf result = new com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf(this);
+ int from_bitField0_ = bitField0_;
+ if (edgeBuilder_ == null) {
+ if (((bitField0_ & 0x00000001) == 0x00000001)) {
+ edge_ = java.util.Collections.unmodifiableList(edge_);
+ bitField0_ = (bitField0_ & ~0x00000001);
+ }
+ result.edge_ = edge_;
+ } else {
+ result.edge_ = edgeBuilder_.build();
+ }
+ onBuilt();
+ return result;
+ }
+
+ public Builder mergeFrom(com.google.protobuf.Message other) {
+ if (other instanceof com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf) {
+ return mergeFrom((com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf)other);
+ } else {
+ super.mergeFrom(other);
+ return this;
+ }
+ }
+
+ public Builder mergeFrom(com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf other) {
+ if (other == com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf.getDefaultInstance()) return this;
+ if (edgeBuilder_ == null) {
+ if (!other.edge_.isEmpty()) {
+ if (edge_.isEmpty()) {
+ edge_ = other.edge_;
+ bitField0_ = (bitField0_ & ~0x00000001);
+ } else {
+ ensureEdgeIsMutable();
+ edge_.addAll(other.edge_);
+ }
+ onChanged();
+ }
+ } else {
+ if (!other.edge_.isEmpty()) {
+ if (edgeBuilder_.isEmpty()) {
+ edgeBuilder_.dispose();
+ edgeBuilder_ = null;
+ edge_ = other.edge_;
+ bitField0_ = (bitField0_ & ~0x00000001);
+ edgeBuilder_ =
+ com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ?
+ getEdgeFieldBuilder() : null;
+ } else {
+ edgeBuilder_.addAllMessages(other.edge_);
+ }
+ }
+ }
+ this.mergeUnknownFields(other.getUnknownFields());
+ return this;
+ }
+
+ public final boolean isInitialized() {
+ for (int i = 0; i < getEdgeCount(); i++) {
+ if (!getEdge(i).isInitialized()) {
+
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public Builder mergeFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf parsedMessage = null;
+ try {
+ parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
+ } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+ parsedMessage = (com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf) e.getUnfinishedMessage();
+ throw e;
+ } finally {
+ if (parsedMessage != null) {
+ mergeFrom(parsedMessage);
+ }
+ }
+ return this;
+ }
+ private int bitField0_;
+
+ // repeated .RamCloudGraph.EdgeProtoBuf edge = 1;
+ private java.util.List<com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf> edge_ =
+ java.util.Collections.emptyList();
+ private void ensureEdgeIsMutable() {
+ if (!((bitField0_ & 0x00000001) == 0x00000001)) {
+ edge_ = new java.util.ArrayList<com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf>(edge_);
+ bitField0_ |= 0x00000001;
+ }
+ }
+
+ private com.google.protobuf.RepeatedFieldBuilder<
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf.Builder, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBufOrBuilder> edgeBuilder_;
+
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ public java.util.List<com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf> getEdgeList() {
+ if (edgeBuilder_ == null) {
+ return java.util.Collections.unmodifiableList(edge_);
+ } else {
+ return edgeBuilder_.getMessageList();
+ }
+ }
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ public int getEdgeCount() {
+ if (edgeBuilder_ == null) {
+ return edge_.size();
+ } else {
+ return edgeBuilder_.getCount();
+ }
+ }
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf getEdge(int index) {
+ if (edgeBuilder_ == null) {
+ return edge_.get(index);
+ } else {
+ return edgeBuilder_.getMessage(index);
+ }
+ }
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ public Builder setEdge(
+ int index, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf value) {
+ if (edgeBuilder_ == null) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ ensureEdgeIsMutable();
+ edge_.set(index, value);
+ onChanged();
+ } else {
+ edgeBuilder_.setMessage(index, value);
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ public Builder setEdge(
+ int index, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf.Builder builderForValue) {
+ if (edgeBuilder_ == null) {
+ ensureEdgeIsMutable();
+ edge_.set(index, builderForValue.build());
+ onChanged();
+ } else {
+ edgeBuilder_.setMessage(index, builderForValue.build());
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ public Builder addEdge(com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf value) {
+ if (edgeBuilder_ == null) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ ensureEdgeIsMutable();
+ edge_.add(value);
+ onChanged();
+ } else {
+ edgeBuilder_.addMessage(value);
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ public Builder addEdge(
+ int index, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf value) {
+ if (edgeBuilder_ == null) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ ensureEdgeIsMutable();
+ edge_.add(index, value);
+ onChanged();
+ } else {
+ edgeBuilder_.addMessage(index, value);
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ public Builder addEdge(
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf.Builder builderForValue) {
+ if (edgeBuilder_ == null) {
+ ensureEdgeIsMutable();
+ edge_.add(builderForValue.build());
+ onChanged();
+ } else {
+ edgeBuilder_.addMessage(builderForValue.build());
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ public Builder addEdge(
+ int index, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf.Builder builderForValue) {
+ if (edgeBuilder_ == null) {
+ ensureEdgeIsMutable();
+ edge_.add(index, builderForValue.build());
+ onChanged();
+ } else {
+ edgeBuilder_.addMessage(index, builderForValue.build());
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ public Builder addAllEdge(
+ java.lang.Iterable<? extends com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf> values) {
+ if (edgeBuilder_ == null) {
+ ensureEdgeIsMutable();
+ super.addAll(values, edge_);
+ onChanged();
+ } else {
+ edgeBuilder_.addAllMessages(values);
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ public Builder clearEdge() {
+ if (edgeBuilder_ == null) {
+ edge_ = java.util.Collections.emptyList();
+ bitField0_ = (bitField0_ & ~0x00000001);
+ onChanged();
+ } else {
+ edgeBuilder_.clear();
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ public Builder removeEdge(int index) {
+ if (edgeBuilder_ == null) {
+ ensureEdgeIsMutable();
+ edge_.remove(index);
+ onChanged();
+ } else {
+ edgeBuilder_.remove(index);
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf.Builder getEdgeBuilder(
+ int index) {
+ return getEdgeFieldBuilder().getBuilder(index);
+ }
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBufOrBuilder getEdgeOrBuilder(
+ int index) {
+ if (edgeBuilder_ == null) {
+ return edge_.get(index); } else {
+ return edgeBuilder_.getMessageOrBuilder(index);
+ }
+ }
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ public java.util.List<? extends com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBufOrBuilder>
+ getEdgeOrBuilderList() {
+ if (edgeBuilder_ != null) {
+ return edgeBuilder_.getMessageOrBuilderList();
+ } else {
+ return java.util.Collections.unmodifiableList(edge_);
+ }
+ }
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf.Builder addEdgeBuilder() {
+ return getEdgeFieldBuilder().addBuilder(
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf.getDefaultInstance());
+ }
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf.Builder addEdgeBuilder(
+ int index) {
+ return getEdgeFieldBuilder().addBuilder(
+ index, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf.getDefaultInstance());
+ }
+ /**
+ * <code>repeated .RamCloudGraph.EdgeProtoBuf edge = 1;</code>
+ */
+ public java.util.List<com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf.Builder>
+ getEdgeBuilderList() {
+ return getEdgeFieldBuilder().getBuilderList();
+ }
+ private com.google.protobuf.RepeatedFieldBuilder<
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf.Builder, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBufOrBuilder>
+ getEdgeFieldBuilder() {
+ if (edgeBuilder_ == null) {
+ edgeBuilder_ = new com.google.protobuf.RepeatedFieldBuilder<
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf.Builder, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBufOrBuilder>(
+ edge_,
+ ((bitField0_ & 0x00000001) == 0x00000001),
+ getParentForChildren(),
+ isClean());
+ edge_ = null;
+ }
+ return edgeBuilder_;
+ }
+
+ // @@protoc_insertion_point(builder_scope:RamCloudGraph.EdgeListProtoBuf)
+ }
+
+ static {
+ defaultInstance = new EdgeListProtoBuf(true);
+ defaultInstance.initFields();
+ }
+
+ // @@protoc_insertion_point(class_scope:RamCloudGraph.EdgeListProtoBuf)
+ }
+
+ public interface EdgeProtoBufOrBuilder
+ extends com.google.protobuf.MessageOrBuilder {
+
+ // required uint64 neighborId = 1;
+ /**
+ * <code>required uint64 neighborId = 1;</code>
+ */
+ boolean hasNeighborId();
+ /**
+ * <code>required uint64 neighborId = 1;</code>
+ */
+ long getNeighborId();
+
+ // required bool outgoing = 2;
+ /**
+ * <code>required bool outgoing = 2;</code>
+ */
+ boolean hasOutgoing();
+ /**
+ * <code>required bool outgoing = 2;</code>
+ */
+ boolean getOutgoing();
+
+ // required string label = 3;
+ /**
+ * <code>required string label = 3;</code>
+ */
+ boolean hasLabel();
+ /**
+ * <code>required string label = 3;</code>
+ */
+ java.lang.String getLabel();
+ /**
+ * <code>required string label = 3;</code>
+ */
+ com.google.protobuf.ByteString
+ getLabelBytes();
+ }
+ /**
+ * Protobuf type {@code RamCloudGraph.EdgeProtoBuf}
+ */
+ public static final class EdgeProtoBuf extends
+ com.google.protobuf.GeneratedMessage
+ implements EdgeProtoBufOrBuilder {
+ // Use EdgeProtoBuf.newBuilder() to construct.
+ private EdgeProtoBuf(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
+ super(builder);
+ this.unknownFields = builder.getUnknownFields();
+ }
+ private EdgeProtoBuf(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }
+
+ private static final EdgeProtoBuf defaultInstance;
+ public static EdgeProtoBuf getDefaultInstance() {
+ return defaultInstance;
+ }
+
+ public EdgeProtoBuf getDefaultInstanceForType() {
+ return defaultInstance;
+ }
+
+ private final com.google.protobuf.UnknownFieldSet unknownFields;
+ @java.lang.Override
+ public final com.google.protobuf.UnknownFieldSet
+ getUnknownFields() {
+ return this.unknownFields;
+ }
+ private EdgeProtoBuf(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ initFields();
+ int mutable_bitField0_ = 0;
+ com.google.protobuf.UnknownFieldSet.Builder unknownFields =
+ com.google.protobuf.UnknownFieldSet.newBuilder();
+ try {
+ boolean done = false;
+ while (!done) {
+ int tag = input.readTag();
+ switch (tag) {
+ case 0:
+ done = true;
+ break;
+ default: {
+ if (!parseUnknownField(input, unknownFields,
+ extensionRegistry, tag)) {
+ done = true;
+ }
+ break;
+ }
+ case 8: {
+ bitField0_ |= 0x00000001;
+ neighborId_ = input.readUInt64();
+ break;
+ }
+ case 16: {
+ bitField0_ |= 0x00000002;
+ outgoing_ = input.readBool();
+ break;
+ }
+ case 26: {
+ bitField0_ |= 0x00000004;
+ label_ = input.readBytes();
+ break;
+ }
+ }
+ }
+ } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+ throw e.setUnfinishedMessage(this);
+ } catch (java.io.IOException e) {
+ throw new com.google.protobuf.InvalidProtocolBufferException(
+ e.getMessage()).setUnfinishedMessage(this);
+ } finally {
+ this.unknownFields = unknownFields.build();
+ makeExtensionsImmutable();
+ }
+ }
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.internal_static_RamCloudGraph_EdgeProtoBuf_descriptor;
+ }
+
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.internal_static_RamCloudGraph_EdgeProtoBuf_fieldAccessorTable
+ .ensureFieldAccessorsInitialized(
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf.class, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf.Builder.class);
+ }
+
+ public static com.google.protobuf.Parser<EdgeProtoBuf> PARSER =
+ new com.google.protobuf.AbstractParser<EdgeProtoBuf>() {
+ public EdgeProtoBuf parsePartialFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return new EdgeProtoBuf(input, extensionRegistry);
+ }
+ };
+
+ @java.lang.Override
+ public com.google.protobuf.Parser<EdgeProtoBuf> getParserForType() {
+ return PARSER;
+ }
+
+ private int bitField0_;
+ // required uint64 neighborId = 1;
+ public static final int NEIGHBORID_FIELD_NUMBER = 1;
+ private long neighborId_;
+ /**
+ * <code>required uint64 neighborId = 1;</code>
+ */
+ public boolean hasNeighborId() {
+ return ((bitField0_ & 0x00000001) == 0x00000001);
+ }
+ /**
+ * <code>required uint64 neighborId = 1;</code>
+ */
+ public long getNeighborId() {
+ return neighborId_;
+ }
+
+ // required bool outgoing = 2;
+ public static final int OUTGOING_FIELD_NUMBER = 2;
+ private boolean outgoing_;
+ /**
+ * <code>required bool outgoing = 2;</code>
+ */
+ public boolean hasOutgoing() {
+ return ((bitField0_ & 0x00000002) == 0x00000002);
+ }
+ /**
+ * <code>required bool outgoing = 2;</code>
+ */
+ public boolean getOutgoing() {
+ return outgoing_;
+ }
+
+ // required string label = 3;
+ public static final int LABEL_FIELD_NUMBER = 3;
+ private java.lang.Object label_;
+ /**
+ * <code>required string label = 3;</code>
+ */
+ public boolean hasLabel() {
+ return ((bitField0_ & 0x00000004) == 0x00000004);
+ }
+ /**
+ * <code>required string label = 3;</code>
+ */
+ public java.lang.String getLabel() {
+ java.lang.Object ref = label_;
+ if (ref instanceof java.lang.String) {
+ return (java.lang.String) ref;
+ } else {
+ com.google.protobuf.ByteString bs =
+ (com.google.protobuf.ByteString) ref;
+ java.lang.String s = bs.toStringUtf8();
+ if (bs.isValidUtf8()) {
+ label_ = s;
+ }
+ return s;
+ }
+ }
+ /**
+ * <code>required string label = 3;</code>
+ */
+ public com.google.protobuf.ByteString
+ getLabelBytes() {
+ java.lang.Object ref = label_;
+ if (ref instanceof java.lang.String) {
+ com.google.protobuf.ByteString b =
+ com.google.protobuf.ByteString.copyFromUtf8(
+ (java.lang.String) ref);
+ label_ = b;
+ return b;
+ } else {
+ return (com.google.protobuf.ByteString) ref;
+ }
+ }
+
+ private void initFields() {
+ neighborId_ = 0L;
+ outgoing_ = false;
+ label_ = "";
+ }
+ private byte memoizedIsInitialized = -1;
+ public final boolean isInitialized() {
+ byte isInitialized = memoizedIsInitialized;
+ if (isInitialized != -1) return isInitialized == 1;
+
+ if (!hasNeighborId()) {
+ memoizedIsInitialized = 0;
+ return false;
+ }
+ if (!hasOutgoing()) {
+ memoizedIsInitialized = 0;
+ return false;
+ }
+ if (!hasLabel()) {
+ memoizedIsInitialized = 0;
+ return false;
+ }
+ memoizedIsInitialized = 1;
+ return true;
+ }
+
+ public void writeTo(com.google.protobuf.CodedOutputStream output)
+ throws java.io.IOException {
+ getSerializedSize();
+ if (((bitField0_ & 0x00000001) == 0x00000001)) {
+ output.writeUInt64(1, neighborId_);
+ }
+ if (((bitField0_ & 0x00000002) == 0x00000002)) {
+ output.writeBool(2, outgoing_);
+ }
+ if (((bitField0_ & 0x00000004) == 0x00000004)) {
+ output.writeBytes(3, getLabelBytes());
+ }
+ getUnknownFields().writeTo(output);
+ }
+
+ private int memoizedSerializedSize = -1;
+ public int getSerializedSize() {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (((bitField0_ & 0x00000001) == 0x00000001)) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeUInt64Size(1, neighborId_);
+ }
+ if (((bitField0_ & 0x00000002) == 0x00000002)) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeBoolSize(2, outgoing_);
+ }
+ if (((bitField0_ & 0x00000004) == 0x00000004)) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeBytesSize(3, getLabelBytes());
+ }
+ size += getUnknownFields().getSerializedSize();
+ memoizedSerializedSize = size;
+ return size;
+ }
+
+ private static final long serialVersionUID = 0L;
+ @java.lang.Override
+ protected java.lang.Object writeReplace()
+ throws java.io.ObjectStreamException {
+ return super.writeReplace();
+ }
+
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf parseFrom(
+ com.google.protobuf.ByteString data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf parseFrom(
+ com.google.protobuf.ByteString data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf parseFrom(byte[] data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf parseFrom(
+ byte[] data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf parseFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf parseFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input, extensionRegistry);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf parseDelimitedFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return PARSER.parseDelimitedFrom(input);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf parseDelimitedFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return PARSER.parseDelimitedFrom(input, extensionRegistry);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf parseFrom(
+ com.google.protobuf.CodedInputStream input)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf parseFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input, extensionRegistry);
+ }
+
+ public static Builder newBuilder() { return Builder.create(); }
+ public Builder newBuilderForType() { return newBuilder(); }
+ public static Builder newBuilder(com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf prototype) {
+ return newBuilder().mergeFrom(prototype);
+ }
+ public Builder toBuilder() { return newBuilder(this); }
+
+ @java.lang.Override
+ protected Builder newBuilderForType(
+ com.google.protobuf.GeneratedMessage.BuilderParent parent) {
+ Builder builder = new Builder(parent);
+ return builder;
+ }
+ /**
+ * Protobuf type {@code RamCloudGraph.EdgeProtoBuf}
+ */
+ public static final class Builder extends
+ com.google.protobuf.GeneratedMessage.Builder<Builder>
+ implements com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBufOrBuilder {
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.internal_static_RamCloudGraph_EdgeProtoBuf_descriptor;
+ }
+
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.internal_static_RamCloudGraph_EdgeProtoBuf_fieldAccessorTable
+ .ensureFieldAccessorsInitialized(
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf.class, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf.Builder.class);
+ }
+
+ // Construct using com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf.newBuilder()
+ private Builder() {
+ maybeForceBuilderInitialization();
+ }
+
+ private Builder(
+ com.google.protobuf.GeneratedMessage.BuilderParent parent) {
+ super(parent);
+ maybeForceBuilderInitialization();
+ }
+ private void maybeForceBuilderInitialization() {
+ if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
+ }
+ }
+ private static Builder create() {
+ return new Builder();
+ }
+
+ public Builder clear() {
+ super.clear();
+ neighborId_ = 0L;
+ bitField0_ = (bitField0_ & ~0x00000001);
+ outgoing_ = false;
+ bitField0_ = (bitField0_ & ~0x00000002);
+ label_ = "";
+ bitField0_ = (bitField0_ & ~0x00000004);
+ return this;
+ }
+
+ public Builder clone() {
+ return create().mergeFrom(buildPartial());
+ }
+
+ public com.google.protobuf.Descriptors.Descriptor
+ getDescriptorForType() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.internal_static_RamCloudGraph_EdgeProtoBuf_descriptor;
+ }
+
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf getDefaultInstanceForType() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf.getDefaultInstance();
+ }
+
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf build() {
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf result = buildPartial();
+ if (!result.isInitialized()) {
+ throw newUninitializedMessageException(result);
+ }
+ return result;
+ }
+
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf buildPartial() {
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf result = new com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf(this);
+ int from_bitField0_ = bitField0_;
+ int to_bitField0_ = 0;
+ if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
+ to_bitField0_ |= 0x00000001;
+ }
+ result.neighborId_ = neighborId_;
+ if (((from_bitField0_ & 0x00000002) == 0x00000002)) {
+ to_bitField0_ |= 0x00000002;
+ }
+ result.outgoing_ = outgoing_;
+ if (((from_bitField0_ & 0x00000004) == 0x00000004)) {
+ to_bitField0_ |= 0x00000004;
+ }
+ result.label_ = label_;
+ result.bitField0_ = to_bitField0_;
+ onBuilt();
+ return result;
+ }
+
+ public Builder mergeFrom(com.google.protobuf.Message other) {
+ if (other instanceof com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf) {
+ return mergeFrom((com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf)other);
+ } else {
+ super.mergeFrom(other);
+ return this;
+ }
+ }
+
+ public Builder mergeFrom(com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf other) {
+ if (other == com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf.getDefaultInstance()) return this;
+ if (other.hasNeighborId()) {
+ setNeighborId(other.getNeighborId());
+ }
+ if (other.hasOutgoing()) {
+ setOutgoing(other.getOutgoing());
+ }
+ if (other.hasLabel()) {
+ bitField0_ |= 0x00000004;
+ label_ = other.label_;
+ onChanged();
+ }
+ this.mergeUnknownFields(other.getUnknownFields());
+ return this;
+ }
+
+ public final boolean isInitialized() {
+ if (!hasNeighborId()) {
+
+ return false;
+ }
+ if (!hasOutgoing()) {
+
+ return false;
+ }
+ if (!hasLabel()) {
+
+ return false;
+ }
+ return true;
+ }
+
+ public Builder mergeFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf parsedMessage = null;
+ try {
+ parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
+ } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+ parsedMessage = (com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf) e.getUnfinishedMessage();
+ throw e;
+ } finally {
+ if (parsedMessage != null) {
+ mergeFrom(parsedMessage);
+ }
+ }
+ return this;
+ }
+ private int bitField0_;
+
+ // required uint64 neighborId = 1;
+ private long neighborId_ ;
+ /**
+ * <code>required uint64 neighborId = 1;</code>
+ */
+ public boolean hasNeighborId() {
+ return ((bitField0_ & 0x00000001) == 0x00000001);
+ }
+ /**
+ * <code>required uint64 neighborId = 1;</code>
+ */
+ public long getNeighborId() {
+ return neighborId_;
+ }
+ /**
+ * <code>required uint64 neighborId = 1;</code>
+ */
+ public Builder setNeighborId(long value) {
+ bitField0_ |= 0x00000001;
+ neighborId_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>required uint64 neighborId = 1;</code>
+ */
+ public Builder clearNeighborId() {
+ bitField0_ = (bitField0_ & ~0x00000001);
+ neighborId_ = 0L;
+ onChanged();
+ return this;
+ }
+
+ // required bool outgoing = 2;
+ private boolean outgoing_ ;
+ /**
+ * <code>required bool outgoing = 2;</code>
+ */
+ public boolean hasOutgoing() {
+ return ((bitField0_ & 0x00000002) == 0x00000002);
+ }
+ /**
+ * <code>required bool outgoing = 2;</code>
+ */
+ public boolean getOutgoing() {
+ return outgoing_;
+ }
+ /**
+ * <code>required bool outgoing = 2;</code>
+ */
+ public Builder setOutgoing(boolean value) {
+ bitField0_ |= 0x00000002;
+ outgoing_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>required bool outgoing = 2;</code>
+ */
+ public Builder clearOutgoing() {
+ bitField0_ = (bitField0_ & ~0x00000002);
+ outgoing_ = false;
+ onChanged();
+ return this;
+ }
+
+ // required string label = 3;
+ private java.lang.Object label_ = "";
+ /**
+ * <code>required string label = 3;</code>
+ */
+ public boolean hasLabel() {
+ return ((bitField0_ & 0x00000004) == 0x00000004);
+ }
+ /**
+ * <code>required string label = 3;</code>
+ */
+ public java.lang.String getLabel() {
+ java.lang.Object ref = label_;
+ if (!(ref instanceof java.lang.String)) {
+ java.lang.String s = ((com.google.protobuf.ByteString) ref)
+ .toStringUtf8();
+ label_ = s;
+ return s;
+ } else {
+ return (java.lang.String) ref;
+ }
+ }
+ /**
+ * <code>required string label = 3;</code>
+ */
+ public com.google.protobuf.ByteString
+ getLabelBytes() {
+ java.lang.Object ref = label_;
+ if (ref instanceof String) {
+ com.google.protobuf.ByteString b =
+ com.google.protobuf.ByteString.copyFromUtf8(
+ (java.lang.String) ref);
+ label_ = b;
+ return b;
+ } else {
+ return (com.google.protobuf.ByteString) ref;
+ }
+ }
+ /**
+ * <code>required string label = 3;</code>
+ */
+ public Builder setLabel(
+ java.lang.String value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ bitField0_ |= 0x00000004;
+ label_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>required string label = 3;</code>
+ */
+ public Builder clearLabel() {
+ bitField0_ = (bitField0_ & ~0x00000004);
+ label_ = getDefaultInstance().getLabel();
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>required string label = 3;</code>
+ */
+ public Builder setLabelBytes(
+ com.google.protobuf.ByteString value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ bitField0_ |= 0x00000004;
+ label_ = value;
+ onChanged();
+ return this;
+ }
+
+ // @@protoc_insertion_point(builder_scope:RamCloudGraph.EdgeProtoBuf)
+ }
+
+ static {
+ defaultInstance = new EdgeProtoBuf(true);
+ defaultInstance.initFields();
+ }
+
+ // @@protoc_insertion_point(class_scope:RamCloudGraph.EdgeProtoBuf)
+ }
+
+ public interface PropertyListProtoBufOrBuilder
+ extends com.google.protobuf.MessageOrBuilder {
+
+ // repeated .RamCloudGraph.PropertyProtoBuf property = 1;
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ java.util.List<com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf>
+ getPropertyList();
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf getProperty(int index);
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ int getPropertyCount();
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ java.util.List<? extends com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBufOrBuilder>
+ getPropertyOrBuilderList();
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBufOrBuilder getPropertyOrBuilder(
+ int index);
+ }
+ /**
+ * Protobuf type {@code RamCloudGraph.PropertyListProtoBuf}
+ */
+ public static final class PropertyListProtoBuf extends
+ com.google.protobuf.GeneratedMessage
+ implements PropertyListProtoBufOrBuilder {
+ // Use PropertyListProtoBuf.newBuilder() to construct.
+ private PropertyListProtoBuf(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
+ super(builder);
+ this.unknownFields = builder.getUnknownFields();
+ }
+ private PropertyListProtoBuf(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }
+
+ private static final PropertyListProtoBuf defaultInstance;
+ public static PropertyListProtoBuf getDefaultInstance() {
+ return defaultInstance;
+ }
+
+ public PropertyListProtoBuf getDefaultInstanceForType() {
+ return defaultInstance;
+ }
+
+ private final com.google.protobuf.UnknownFieldSet unknownFields;
+ @java.lang.Override
+ public final com.google.protobuf.UnknownFieldSet
+ getUnknownFields() {
+ return this.unknownFields;
+ }
+ private PropertyListProtoBuf(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ initFields();
+ int mutable_bitField0_ = 0;
+ com.google.protobuf.UnknownFieldSet.Builder unknownFields =
+ com.google.protobuf.UnknownFieldSet.newBuilder();
+ try {
+ boolean done = false;
+ while (!done) {
+ int tag = input.readTag();
+ switch (tag) {
+ case 0:
+ done = true;
+ break;
+ default: {
+ if (!parseUnknownField(input, unknownFields,
+ extensionRegistry, tag)) {
+ done = true;
+ }
+ break;
+ }
+ case 10: {
+ if (!((mutable_bitField0_ & 0x00000001) == 0x00000001)) {
+ property_ = new java.util.ArrayList<com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf>();
+ mutable_bitField0_ |= 0x00000001;
+ }
+ property_.add(input.readMessage(com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.PARSER, extensionRegistry));
+ break;
+ }
+ }
+ }
+ } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+ throw e.setUnfinishedMessage(this);
+ } catch (java.io.IOException e) {
+ throw new com.google.protobuf.InvalidProtocolBufferException(
+ e.getMessage()).setUnfinishedMessage(this);
+ } finally {
+ if (((mutable_bitField0_ & 0x00000001) == 0x00000001)) {
+ property_ = java.util.Collections.unmodifiableList(property_);
+ }
+ this.unknownFields = unknownFields.build();
+ makeExtensionsImmutable();
+ }
+ }
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.internal_static_RamCloudGraph_PropertyListProtoBuf_descriptor;
+ }
+
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.internal_static_RamCloudGraph_PropertyListProtoBuf_fieldAccessorTable
+ .ensureFieldAccessorsInitialized(
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf.class, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf.Builder.class);
+ }
+
+ public static com.google.protobuf.Parser<PropertyListProtoBuf> PARSER =
+ new com.google.protobuf.AbstractParser<PropertyListProtoBuf>() {
+ public PropertyListProtoBuf parsePartialFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return new PropertyListProtoBuf(input, extensionRegistry);
+ }
+ };
+
+ @java.lang.Override
+ public com.google.protobuf.Parser<PropertyListProtoBuf> getParserForType() {
+ return PARSER;
+ }
+
+ // repeated .RamCloudGraph.PropertyProtoBuf property = 1;
+ public static final int PROPERTY_FIELD_NUMBER = 1;
+ private java.util.List<com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf> property_;
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ public java.util.List<com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf> getPropertyList() {
+ return property_;
+ }
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ public java.util.List<? extends com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBufOrBuilder>
+ getPropertyOrBuilderList() {
+ return property_;
+ }
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ public int getPropertyCount() {
+ return property_.size();
+ }
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf getProperty(int index) {
+ return property_.get(index);
+ }
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBufOrBuilder getPropertyOrBuilder(
+ int index) {
+ return property_.get(index);
+ }
+
+ private void initFields() {
+ property_ = java.util.Collections.emptyList();
+ }
+ private byte memoizedIsInitialized = -1;
+ public final boolean isInitialized() {
+ byte isInitialized = memoizedIsInitialized;
+ if (isInitialized != -1) return isInitialized == 1;
+
+ for (int i = 0; i < getPropertyCount(); i++) {
+ if (!getProperty(i).isInitialized()) {
+ memoizedIsInitialized = 0;
+ return false;
+ }
+ }
+ memoizedIsInitialized = 1;
+ return true;
+ }
+
+ public void writeTo(com.google.protobuf.CodedOutputStream output)
+ throws java.io.IOException {
+ getSerializedSize();
+ for (int i = 0; i < property_.size(); i++) {
+ output.writeMessage(1, property_.get(i));
+ }
+ getUnknownFields().writeTo(output);
+ }
+
+ private int memoizedSerializedSize = -1;
+ public int getSerializedSize() {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ for (int i = 0; i < property_.size(); i++) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeMessageSize(1, property_.get(i));
+ }
+ size += getUnknownFields().getSerializedSize();
+ memoizedSerializedSize = size;
+ return size;
+ }
+
+ private static final long serialVersionUID = 0L;
+ @java.lang.Override
+ protected java.lang.Object writeReplace()
+ throws java.io.ObjectStreamException {
+ return super.writeReplace();
+ }
+
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf parseFrom(
+ com.google.protobuf.ByteString data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf parseFrom(
+ com.google.protobuf.ByteString data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf parseFrom(byte[] data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf parseFrom(
+ byte[] data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf parseFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf parseFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input, extensionRegistry);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf parseDelimitedFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return PARSER.parseDelimitedFrom(input);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf parseDelimitedFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return PARSER.parseDelimitedFrom(input, extensionRegistry);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf parseFrom(
+ com.google.protobuf.CodedInputStream input)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf parseFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input, extensionRegistry);
+ }
+
+ public static Builder newBuilder() { return Builder.create(); }
+ public Builder newBuilderForType() { return newBuilder(); }
+ public static Builder newBuilder(com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf prototype) {
+ return newBuilder().mergeFrom(prototype);
+ }
+ public Builder toBuilder() { return newBuilder(this); }
+
+ @java.lang.Override
+ protected Builder newBuilderForType(
+ com.google.protobuf.GeneratedMessage.BuilderParent parent) {
+ Builder builder = new Builder(parent);
+ return builder;
+ }
+ /**
+ * Protobuf type {@code RamCloudGraph.PropertyListProtoBuf}
+ */
+ public static final class Builder extends
+ com.google.protobuf.GeneratedMessage.Builder<Builder>
+ implements com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBufOrBuilder {
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.internal_static_RamCloudGraph_PropertyListProtoBuf_descriptor;
+ }
+
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.internal_static_RamCloudGraph_PropertyListProtoBuf_fieldAccessorTable
+ .ensureFieldAccessorsInitialized(
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf.class, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf.Builder.class);
+ }
+
+ // Construct using com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf.newBuilder()
+ private Builder() {
+ maybeForceBuilderInitialization();
+ }
+
+ private Builder(
+ com.google.protobuf.GeneratedMessage.BuilderParent parent) {
+ super(parent);
+ maybeForceBuilderInitialization();
+ }
+ private void maybeForceBuilderInitialization() {
+ if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
+ getPropertyFieldBuilder();
+ }
+ }
+ private static Builder create() {
+ return new Builder();
+ }
+
+ public Builder clear() {
+ super.clear();
+ if (propertyBuilder_ == null) {
+ property_ = java.util.Collections.emptyList();
+ bitField0_ = (bitField0_ & ~0x00000001);
+ } else {
+ propertyBuilder_.clear();
+ }
+ return this;
+ }
+
+ public Builder clone() {
+ return create().mergeFrom(buildPartial());
+ }
+
+ public com.google.protobuf.Descriptors.Descriptor
+ getDescriptorForType() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.internal_static_RamCloudGraph_PropertyListProtoBuf_descriptor;
+ }
+
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf getDefaultInstanceForType() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf.getDefaultInstance();
+ }
+
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf build() {
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf result = buildPartial();
+ if (!result.isInitialized()) {
+ throw newUninitializedMessageException(result);
+ }
+ return result;
+ }
+
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf buildPartial() {
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf result = new com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf(this);
+ int from_bitField0_ = bitField0_;
+ if (propertyBuilder_ == null) {
+ if (((bitField0_ & 0x00000001) == 0x00000001)) {
+ property_ = java.util.Collections.unmodifiableList(property_);
+ bitField0_ = (bitField0_ & ~0x00000001);
+ }
+ result.property_ = property_;
+ } else {
+ result.property_ = propertyBuilder_.build();
+ }
+ onBuilt();
+ return result;
+ }
+
+ public Builder mergeFrom(com.google.protobuf.Message other) {
+ if (other instanceof com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf) {
+ return mergeFrom((com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf)other);
+ } else {
+ super.mergeFrom(other);
+ return this;
+ }
+ }
+
+ public Builder mergeFrom(com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf other) {
+ if (other == com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf.getDefaultInstance()) return this;
+ if (propertyBuilder_ == null) {
+ if (!other.property_.isEmpty()) {
+ if (property_.isEmpty()) {
+ property_ = other.property_;
+ bitField0_ = (bitField0_ & ~0x00000001);
+ } else {
+ ensurePropertyIsMutable();
+ property_.addAll(other.property_);
+ }
+ onChanged();
+ }
+ } else {
+ if (!other.property_.isEmpty()) {
+ if (propertyBuilder_.isEmpty()) {
+ propertyBuilder_.dispose();
+ propertyBuilder_ = null;
+ property_ = other.property_;
+ bitField0_ = (bitField0_ & ~0x00000001);
+ propertyBuilder_ =
+ com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ?
+ getPropertyFieldBuilder() : null;
+ } else {
+ propertyBuilder_.addAllMessages(other.property_);
+ }
+ }
+ }
+ this.mergeUnknownFields(other.getUnknownFields());
+ return this;
+ }
+
+ public final boolean isInitialized() {
+ for (int i = 0; i < getPropertyCount(); i++) {
+ if (!getProperty(i).isInitialized()) {
+
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public Builder mergeFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf parsedMessage = null;
+ try {
+ parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
+ } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+ parsedMessage = (com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyListProtoBuf) e.getUnfinishedMessage();
+ throw e;
+ } finally {
+ if (parsedMessage != null) {
+ mergeFrom(parsedMessage);
+ }
+ }
+ return this;
+ }
+ private int bitField0_;
+
+ // repeated .RamCloudGraph.PropertyProtoBuf property = 1;
+ private java.util.List<com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf> property_ =
+ java.util.Collections.emptyList();
+ private void ensurePropertyIsMutable() {
+ if (!((bitField0_ & 0x00000001) == 0x00000001)) {
+ property_ = new java.util.ArrayList<com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf>(property_);
+ bitField0_ |= 0x00000001;
+ }
+ }
+
+ private com.google.protobuf.RepeatedFieldBuilder<
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.Builder, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBufOrBuilder> propertyBuilder_;
+
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ public java.util.List<com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf> getPropertyList() {
+ if (propertyBuilder_ == null) {
+ return java.util.Collections.unmodifiableList(property_);
+ } else {
+ return propertyBuilder_.getMessageList();
+ }
+ }
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ public int getPropertyCount() {
+ if (propertyBuilder_ == null) {
+ return property_.size();
+ } else {
+ return propertyBuilder_.getCount();
+ }
+ }
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf getProperty(int index) {
+ if (propertyBuilder_ == null) {
+ return property_.get(index);
+ } else {
+ return propertyBuilder_.getMessage(index);
+ }
+ }
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ public Builder setProperty(
+ int index, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf value) {
+ if (propertyBuilder_ == null) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ ensurePropertyIsMutable();
+ property_.set(index, value);
+ onChanged();
+ } else {
+ propertyBuilder_.setMessage(index, value);
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ public Builder setProperty(
+ int index, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.Builder builderForValue) {
+ if (propertyBuilder_ == null) {
+ ensurePropertyIsMutable();
+ property_.set(index, builderForValue.build());
+ onChanged();
+ } else {
+ propertyBuilder_.setMessage(index, builderForValue.build());
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ public Builder addProperty(com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf value) {
+ if (propertyBuilder_ == null) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ ensurePropertyIsMutable();
+ property_.add(value);
+ onChanged();
+ } else {
+ propertyBuilder_.addMessage(value);
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ public Builder addProperty(
+ int index, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf value) {
+ if (propertyBuilder_ == null) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ ensurePropertyIsMutable();
+ property_.add(index, value);
+ onChanged();
+ } else {
+ propertyBuilder_.addMessage(index, value);
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ public Builder addProperty(
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.Builder builderForValue) {
+ if (propertyBuilder_ == null) {
+ ensurePropertyIsMutable();
+ property_.add(builderForValue.build());
+ onChanged();
+ } else {
+ propertyBuilder_.addMessage(builderForValue.build());
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ public Builder addProperty(
+ int index, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.Builder builderForValue) {
+ if (propertyBuilder_ == null) {
+ ensurePropertyIsMutable();
+ property_.add(index, builderForValue.build());
+ onChanged();
+ } else {
+ propertyBuilder_.addMessage(index, builderForValue.build());
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ public Builder addAllProperty(
+ java.lang.Iterable<? extends com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf> values) {
+ if (propertyBuilder_ == null) {
+ ensurePropertyIsMutable();
+ super.addAll(values, property_);
+ onChanged();
+ } else {
+ propertyBuilder_.addAllMessages(values);
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ public Builder clearProperty() {
+ if (propertyBuilder_ == null) {
+ property_ = java.util.Collections.emptyList();
+ bitField0_ = (bitField0_ & ~0x00000001);
+ onChanged();
+ } else {
+ propertyBuilder_.clear();
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ public Builder removeProperty(int index) {
+ if (propertyBuilder_ == null) {
+ ensurePropertyIsMutable();
+ property_.remove(index);
+ onChanged();
+ } else {
+ propertyBuilder_.remove(index);
+ }
+ return this;
+ }
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.Builder getPropertyBuilder(
+ int index) {
+ return getPropertyFieldBuilder().getBuilder(index);
+ }
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBufOrBuilder getPropertyOrBuilder(
+ int index) {
+ if (propertyBuilder_ == null) {
+ return property_.get(index); } else {
+ return propertyBuilder_.getMessageOrBuilder(index);
+ }
+ }
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ public java.util.List<? extends com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBufOrBuilder>
+ getPropertyOrBuilderList() {
+ if (propertyBuilder_ != null) {
+ return propertyBuilder_.getMessageOrBuilderList();
+ } else {
+ return java.util.Collections.unmodifiableList(property_);
+ }
+ }
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.Builder addPropertyBuilder() {
+ return getPropertyFieldBuilder().addBuilder(
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.getDefaultInstance());
+ }
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.Builder addPropertyBuilder(
+ int index) {
+ return getPropertyFieldBuilder().addBuilder(
+ index, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.getDefaultInstance());
+ }
+ /**
+ * <code>repeated .RamCloudGraph.PropertyProtoBuf property = 1;</code>
+ */
+ public java.util.List<com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.Builder>
+ getPropertyBuilderList() {
+ return getPropertyFieldBuilder().getBuilderList();
+ }
+ private com.google.protobuf.RepeatedFieldBuilder<
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.Builder, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBufOrBuilder>
+ getPropertyFieldBuilder() {
+ if (propertyBuilder_ == null) {
+ propertyBuilder_ = new com.google.protobuf.RepeatedFieldBuilder<
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.Builder, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBufOrBuilder>(
+ property_,
+ ((bitField0_ & 0x00000001) == 0x00000001),
+ getParentForChildren(),
+ isClean());
+ property_ = null;
+ }
+ return propertyBuilder_;
+ }
+
+ // @@protoc_insertion_point(builder_scope:RamCloudGraph.PropertyListProtoBuf)
+ }
+
+ static {
+ defaultInstance = new PropertyListProtoBuf(true);
+ defaultInstance.initFields();
+ }
+
+ // @@protoc_insertion_point(class_scope:RamCloudGraph.PropertyListProtoBuf)
+ }
+
+ public interface PropertyProtoBufOrBuilder
+ extends com.google.protobuf.MessageOrBuilder {
+
+ // required string key = 1;
+ /**
+ * <code>required string key = 1;</code>
+ */
+ boolean hasKey();
+ /**
+ * <code>required string key = 1;</code>
+ */
+ java.lang.String getKey();
+ /**
+ * <code>required string key = 1;</code>
+ */
+ com.google.protobuf.ByteString
+ getKeyBytes();
+
+ // required .RamCloudGraph.PropertyProtoBuf.Type value_type = 2;
+ /**
+ * <code>required .RamCloudGraph.PropertyProtoBuf.Type value_type = 2;</code>
+ */
+ boolean hasValueType();
+ /**
+ * <code>required .RamCloudGraph.PropertyProtoBuf.Type value_type = 2;</code>
+ */
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.Type getValueType();
+
+ // optional string string_value = 3;
+ /**
+ * <code>optional string string_value = 3;</code>
+ */
+ boolean hasStringValue();
+ /**
+ * <code>optional string string_value = 3;</code>
+ */
+ java.lang.String getStringValue();
+ /**
+ * <code>optional string string_value = 3;</code>
+ */
+ com.google.protobuf.ByteString
+ getStringValueBytes();
+
+ // optional int32 int32_value = 4;
+ /**
+ * <code>optional int32 int32_value = 4;</code>
+ */
+ boolean hasInt32Value();
+ /**
+ * <code>optional int32 int32_value = 4;</code>
+ */
+ int getInt32Value();
+
+ // optional int64 int64_value = 5;
+ /**
+ * <code>optional int64 int64_value = 5;</code>
+ */
+ boolean hasInt64Value();
+ /**
+ * <code>optional int64 int64_value = 5;</code>
+ */
+ long getInt64Value();
+
+ // optional double double_value = 6;
+ /**
+ * <code>optional double double_value = 6;</code>
+ */
+ boolean hasDoubleValue();
+ /**
+ * <code>optional double double_value = 6;</code>
+ */
+ double getDoubleValue();
+
+ // optional float float_value = 7;
+ /**
+ * <code>optional float float_value = 7;</code>
+ */
+ boolean hasFloatValue();
+ /**
+ * <code>optional float float_value = 7;</code>
+ */
+ float getFloatValue();
+
+ // optional bool bool_value = 8;
+ /**
+ * <code>optional bool bool_value = 8;</code>
+ */
+ boolean hasBoolValue();
+ /**
+ * <code>optional bool bool_value = 8;</code>
+ */
+ boolean getBoolValue();
+ }
+ /**
+ * Protobuf type {@code RamCloudGraph.PropertyProtoBuf}
+ */
+ public static final class PropertyProtoBuf extends
+ com.google.protobuf.GeneratedMessage
+ implements PropertyProtoBufOrBuilder {
+ // Use PropertyProtoBuf.newBuilder() to construct.
+ private PropertyProtoBuf(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
+ super(builder);
+ this.unknownFields = builder.getUnknownFields();
+ }
+ private PropertyProtoBuf(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }
+
+ private static final PropertyProtoBuf defaultInstance;
+ public static PropertyProtoBuf getDefaultInstance() {
+ return defaultInstance;
+ }
+
+ public PropertyProtoBuf getDefaultInstanceForType() {
+ return defaultInstance;
+ }
+
+ private final com.google.protobuf.UnknownFieldSet unknownFields;
+ @java.lang.Override
+ public final com.google.protobuf.UnknownFieldSet
+ getUnknownFields() {
+ return this.unknownFields;
+ }
+ private PropertyProtoBuf(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ initFields();
+ int mutable_bitField0_ = 0;
+ com.google.protobuf.UnknownFieldSet.Builder unknownFields =
+ com.google.protobuf.UnknownFieldSet.newBuilder();
+ try {
+ boolean done = false;
+ while (!done) {
+ int tag = input.readTag();
+ switch (tag) {
+ case 0:
+ done = true;
+ break;
+ default: {
+ if (!parseUnknownField(input, unknownFields,
+ extensionRegistry, tag)) {
+ done = true;
+ }
+ break;
+ }
+ case 10: {
+ bitField0_ |= 0x00000001;
+ key_ = input.readBytes();
+ break;
+ }
+ case 16: {
+ int rawValue = input.readEnum();
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.Type value = com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.Type.valueOf(rawValue);
+ if (value == null) {
+ unknownFields.mergeVarintField(2, rawValue);
+ } else {
+ bitField0_ |= 0x00000002;
+ valueType_ = value;
+ }
+ break;
+ }
+ case 26: {
+ bitField0_ |= 0x00000004;
+ stringValue_ = input.readBytes();
+ break;
+ }
+ case 32: {
+ bitField0_ |= 0x00000008;
+ int32Value_ = input.readInt32();
+ break;
+ }
+ case 40: {
+ bitField0_ |= 0x00000010;
+ int64Value_ = input.readInt64();
+ break;
+ }
+ case 49: {
+ bitField0_ |= 0x00000020;
+ doubleValue_ = input.readDouble();
+ break;
+ }
+ case 61: {
+ bitField0_ |= 0x00000040;
+ floatValue_ = input.readFloat();
+ break;
+ }
+ case 64: {
+ bitField0_ |= 0x00000080;
+ boolValue_ = input.readBool();
+ break;
+ }
+ }
+ }
+ } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+ throw e.setUnfinishedMessage(this);
+ } catch (java.io.IOException e) {
+ throw new com.google.protobuf.InvalidProtocolBufferException(
+ e.getMessage()).setUnfinishedMessage(this);
+ } finally {
+ this.unknownFields = unknownFields.build();
+ makeExtensionsImmutable();
+ }
+ }
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.internal_static_RamCloudGraph_PropertyProtoBuf_descriptor;
+ }
+
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.internal_static_RamCloudGraph_PropertyProtoBuf_fieldAccessorTable
+ .ensureFieldAccessorsInitialized(
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.class, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.Builder.class);
+ }
+
+ public static com.google.protobuf.Parser<PropertyProtoBuf> PARSER =
+ new com.google.protobuf.AbstractParser<PropertyProtoBuf>() {
+ public PropertyProtoBuf parsePartialFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return new PropertyProtoBuf(input, extensionRegistry);
+ }
+ };
+
+ @java.lang.Override
+ public com.google.protobuf.Parser<PropertyProtoBuf> getParserForType() {
+ return PARSER;
+ }
+
+ /**
+ * Protobuf enum {@code RamCloudGraph.PropertyProtoBuf.Type}
+ */
+ public enum Type
+ implements com.google.protobuf.ProtocolMessageEnum {
+ /**
+ * <code>STRING = 1;</code>
+ */
+ STRING(0, 1),
+ /**
+ * <code>INT32 = 2;</code>
+ */
+ INT32(1, 2),
+ /**
+ * <code>INT64 = 3;</code>
+ */
+ INT64(2, 3),
+ /**
+ * <code>DOUBLE = 4;</code>
+ */
+ DOUBLE(3, 4),
+ /**
+ * <code>FLOAT = 5;</code>
+ */
+ FLOAT(4, 5),
+ /**
+ * <code>BOOL = 6;</code>
+ */
+ BOOL(5, 6),
+ ;
+
+ /**
+ * <code>STRING = 1;</code>
+ */
+ public static final int STRING_VALUE = 1;
+ /**
+ * <code>INT32 = 2;</code>
+ */
+ public static final int INT32_VALUE = 2;
+ /**
+ * <code>INT64 = 3;</code>
+ */
+ public static final int INT64_VALUE = 3;
+ /**
+ * <code>DOUBLE = 4;</code>
+ */
+ public static final int DOUBLE_VALUE = 4;
+ /**
+ * <code>FLOAT = 5;</code>
+ */
+ public static final int FLOAT_VALUE = 5;
+ /**
+ * <code>BOOL = 6;</code>
+ */
+ public static final int BOOL_VALUE = 6;
+
+
+ public final int getNumber() { return value; }
+
+ public static Type valueOf(int value) {
+ switch (value) {
+ case 1: return STRING;
+ case 2: return INT32;
+ case 3: return INT64;
+ case 4: return DOUBLE;
+ case 5: return FLOAT;
+ case 6: return BOOL;
+ default: return null;
+ }
+ }
+
+ public static com.google.protobuf.Internal.EnumLiteMap<Type>
+ internalGetValueMap() {
+ return internalValueMap;
+ }
+ private static com.google.protobuf.Internal.EnumLiteMap<Type>
+ internalValueMap =
+ new com.google.protobuf.Internal.EnumLiteMap<Type>() {
+ public Type findValueByNumber(int number) {
+ return Type.valueOf(number);
+ }
+ };
+
+ public final com.google.protobuf.Descriptors.EnumValueDescriptor
+ getValueDescriptor() {
+ return getDescriptor().getValues().get(index);
+ }
+ public final com.google.protobuf.Descriptors.EnumDescriptor
+ getDescriptorForType() {
+ return getDescriptor();
+ }
+ public static final com.google.protobuf.Descriptors.EnumDescriptor
+ getDescriptor() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.getDescriptor().getEnumTypes().get(0);
+ }
+
+ private static final Type[] VALUES = values();
+
+ public static Type valueOf(
+ com.google.protobuf.Descriptors.EnumValueDescriptor desc) {
+ if (desc.getType() != getDescriptor()) {
+ throw new java.lang.IllegalArgumentException(
+ "EnumValueDescriptor is not for this type.");
+ }
+ return VALUES[desc.getIndex()];
+ }
+
+ private final int index;
+ private final int value;
+
+ private Type(int index, int value) {
+ this.index = index;
+ this.value = value;
+ }
+
+ // @@protoc_insertion_point(enum_scope:RamCloudGraph.PropertyProtoBuf.Type)
+ }
+
+ private int bitField0_;
+ // required string key = 1;
+ public static final int KEY_FIELD_NUMBER = 1;
+ private java.lang.Object key_;
+ /**
+ * <code>required string key = 1;</code>
+ */
+ public boolean hasKey() {
+ return ((bitField0_ & 0x00000001) == 0x00000001);
+ }
+ /**
+ * <code>required string key = 1;</code>
+ */
+ public java.lang.String getKey() {
+ java.lang.Object ref = key_;
+ if (ref instanceof java.lang.String) {
+ return (java.lang.String) ref;
+ } else {
+ com.google.protobuf.ByteString bs =
+ (com.google.protobuf.ByteString) ref;
+ java.lang.String s = bs.toStringUtf8();
+ if (bs.isValidUtf8()) {
+ key_ = s;
+ }
+ return s;
+ }
+ }
+ /**
+ * <code>required string key = 1;</code>
+ */
+ public com.google.protobuf.ByteString
+ getKeyBytes() {
+ java.lang.Object ref = key_;
+ if (ref instanceof java.lang.String) {
+ com.google.protobuf.ByteString b =
+ com.google.protobuf.ByteString.copyFromUtf8(
+ (java.lang.String) ref);
+ key_ = b;
+ return b;
+ } else {
+ return (com.google.protobuf.ByteString) ref;
+ }
+ }
+
+ // required .RamCloudGraph.PropertyProtoBuf.Type value_type = 2;
+ public static final int VALUE_TYPE_FIELD_NUMBER = 2;
+ private com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.Type valueType_;
+ /**
+ * <code>required .RamCloudGraph.PropertyProtoBuf.Type value_type = 2;</code>
+ */
+ public boolean hasValueType() {
+ return ((bitField0_ & 0x00000002) == 0x00000002);
+ }
+ /**
+ * <code>required .RamCloudGraph.PropertyProtoBuf.Type value_type = 2;</code>
+ */
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.Type getValueType() {
+ return valueType_;
+ }
+
+ // optional string string_value = 3;
+ public static final int STRING_VALUE_FIELD_NUMBER = 3;
+ private java.lang.Object stringValue_;
+ /**
+ * <code>optional string string_value = 3;</code>
+ */
+ public boolean hasStringValue() {
+ return ((bitField0_ & 0x00000004) == 0x00000004);
+ }
+ /**
+ * <code>optional string string_value = 3;</code>
+ */
+ public java.lang.String getStringValue() {
+ java.lang.Object ref = stringValue_;
+ if (ref instanceof java.lang.String) {
+ return (java.lang.String) ref;
+ } else {
+ com.google.protobuf.ByteString bs =
+ (com.google.protobuf.ByteString) ref;
+ java.lang.String s = bs.toStringUtf8();
+ if (bs.isValidUtf8()) {
+ stringValue_ = s;
+ }
+ return s;
+ }
+ }
+ /**
+ * <code>optional string string_value = 3;</code>
+ */
+ public com.google.protobuf.ByteString
+ getStringValueBytes() {
+ java.lang.Object ref = stringValue_;
+ if (ref instanceof java.lang.String) {
+ com.google.protobuf.ByteString b =
+ com.google.protobuf.ByteString.copyFromUtf8(
+ (java.lang.String) ref);
+ stringValue_ = b;
+ return b;
+ } else {
+ return (com.google.protobuf.ByteString) ref;
+ }
+ }
+
+ // optional int32 int32_value = 4;
+ public static final int INT32_VALUE_FIELD_NUMBER = 4;
+ private int int32Value_;
+ /**
+ * <code>optional int32 int32_value = 4;</code>
+ */
+ public boolean hasInt32Value() {
+ return ((bitField0_ & 0x00000008) == 0x00000008);
+ }
+ /**
+ * <code>optional int32 int32_value = 4;</code>
+ */
+ public int getInt32Value() {
+ return int32Value_;
+ }
+
+ // optional int64 int64_value = 5;
+ public static final int INT64_VALUE_FIELD_NUMBER = 5;
+ private long int64Value_;
+ /**
+ * <code>optional int64 int64_value = 5;</code>
+ */
+ public boolean hasInt64Value() {
+ return ((bitField0_ & 0x00000010) == 0x00000010);
+ }
+ /**
+ * <code>optional int64 int64_value = 5;</code>
+ */
+ public long getInt64Value() {
+ return int64Value_;
+ }
+
+ // optional double double_value = 6;
+ public static final int DOUBLE_VALUE_FIELD_NUMBER = 6;
+ private double doubleValue_;
+ /**
+ * <code>optional double double_value = 6;</code>
+ */
+ public boolean hasDoubleValue() {
+ return ((bitField0_ & 0x00000020) == 0x00000020);
+ }
+ /**
+ * <code>optional double double_value = 6;</code>
+ */
+ public double getDoubleValue() {
+ return doubleValue_;
+ }
+
+ // optional float float_value = 7;
+ public static final int FLOAT_VALUE_FIELD_NUMBER = 7;
+ private float floatValue_;
+ /**
+ * <code>optional float float_value = 7;</code>
+ */
+ public boolean hasFloatValue() {
+ return ((bitField0_ & 0x00000040) == 0x00000040);
+ }
+ /**
+ * <code>optional float float_value = 7;</code>
+ */
+ public float getFloatValue() {
+ return floatValue_;
+ }
+
+ // optional bool bool_value = 8;
+ public static final int BOOL_VALUE_FIELD_NUMBER = 8;
+ private boolean boolValue_;
+ /**
+ * <code>optional bool bool_value = 8;</code>
+ */
+ public boolean hasBoolValue() {
+ return ((bitField0_ & 0x00000080) == 0x00000080);
+ }
+ /**
+ * <code>optional bool bool_value = 8;</code>
+ */
+ public boolean getBoolValue() {
+ return boolValue_;
+ }
+
+ private void initFields() {
+ key_ = "";
+ valueType_ = com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.Type.STRING;
+ stringValue_ = "";
+ int32Value_ = 0;
+ int64Value_ = 0L;
+ doubleValue_ = 0D;
+ floatValue_ = 0F;
+ boolValue_ = false;
+ }
+ private byte memoizedIsInitialized = -1;
+ public final boolean isInitialized() {
+ byte isInitialized = memoizedIsInitialized;
+ if (isInitialized != -1) return isInitialized == 1;
+
+ if (!hasKey()) {
+ memoizedIsInitialized = 0;
+ return false;
+ }
+ if (!hasValueType()) {
+ memoizedIsInitialized = 0;
+ return false;
+ }
+ memoizedIsInitialized = 1;
+ return true;
+ }
+
+ public void writeTo(com.google.protobuf.CodedOutputStream output)
+ throws java.io.IOException {
+ getSerializedSize();
+ if (((bitField0_ & 0x00000001) == 0x00000001)) {
+ output.writeBytes(1, getKeyBytes());
+ }
+ if (((bitField0_ & 0x00000002) == 0x00000002)) {
+ output.writeEnum(2, valueType_.getNumber());
+ }
+ if (((bitField0_ & 0x00000004) == 0x00000004)) {
+ output.writeBytes(3, getStringValueBytes());
+ }
+ if (((bitField0_ & 0x00000008) == 0x00000008)) {
+ output.writeInt32(4, int32Value_);
+ }
+ if (((bitField0_ & 0x00000010) == 0x00000010)) {
+ output.writeInt64(5, int64Value_);
+ }
+ if (((bitField0_ & 0x00000020) == 0x00000020)) {
+ output.writeDouble(6, doubleValue_);
+ }
+ if (((bitField0_ & 0x00000040) == 0x00000040)) {
+ output.writeFloat(7, floatValue_);
+ }
+ if (((bitField0_ & 0x00000080) == 0x00000080)) {
+ output.writeBool(8, boolValue_);
+ }
+ getUnknownFields().writeTo(output);
+ }
+
+ private int memoizedSerializedSize = -1;
+ public int getSerializedSize() {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (((bitField0_ & 0x00000001) == 0x00000001)) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeBytesSize(1, getKeyBytes());
+ }
+ if (((bitField0_ & 0x00000002) == 0x00000002)) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeEnumSize(2, valueType_.getNumber());
+ }
+ if (((bitField0_ & 0x00000004) == 0x00000004)) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeBytesSize(3, getStringValueBytes());
+ }
+ if (((bitField0_ & 0x00000008) == 0x00000008)) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeInt32Size(4, int32Value_);
+ }
+ if (((bitField0_ & 0x00000010) == 0x00000010)) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeInt64Size(5, int64Value_);
+ }
+ if (((bitField0_ & 0x00000020) == 0x00000020)) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeDoubleSize(6, doubleValue_);
+ }
+ if (((bitField0_ & 0x00000040) == 0x00000040)) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeFloatSize(7, floatValue_);
+ }
+ if (((bitField0_ & 0x00000080) == 0x00000080)) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeBoolSize(8, boolValue_);
+ }
+ size += getUnknownFields().getSerializedSize();
+ memoizedSerializedSize = size;
+ return size;
+ }
+
+ private static final long serialVersionUID = 0L;
+ @java.lang.Override
+ protected java.lang.Object writeReplace()
+ throws java.io.ObjectStreamException {
+ return super.writeReplace();
+ }
+
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf parseFrom(
+ com.google.protobuf.ByteString data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf parseFrom(
+ com.google.protobuf.ByteString data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf parseFrom(byte[] data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf parseFrom(
+ byte[] data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf parseFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf parseFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input, extensionRegistry);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf parseDelimitedFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return PARSER.parseDelimitedFrom(input);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf parseDelimitedFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return PARSER.parseDelimitedFrom(input, extensionRegistry);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf parseFrom(
+ com.google.protobuf.CodedInputStream input)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf parseFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input, extensionRegistry);
+ }
+
+ public static Builder newBuilder() { return Builder.create(); }
+ public Builder newBuilderForType() { return newBuilder(); }
+ public static Builder newBuilder(com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf prototype) {
+ return newBuilder().mergeFrom(prototype);
+ }
+ public Builder toBuilder() { return newBuilder(this); }
+
+ @java.lang.Override
+ protected Builder newBuilderForType(
+ com.google.protobuf.GeneratedMessage.BuilderParent parent) {
+ Builder builder = new Builder(parent);
+ return builder;
+ }
+ /**
+ * Protobuf type {@code RamCloudGraph.PropertyProtoBuf}
+ */
+ public static final class Builder extends
+ com.google.protobuf.GeneratedMessage.Builder<Builder>
+ implements com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBufOrBuilder {
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.internal_static_RamCloudGraph_PropertyProtoBuf_descriptor;
+ }
+
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.internal_static_RamCloudGraph_PropertyProtoBuf_fieldAccessorTable
+ .ensureFieldAccessorsInitialized(
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.class, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.Builder.class);
+ }
+
+ // Construct using com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.newBuilder()
+ private Builder() {
+ maybeForceBuilderInitialization();
+ }
+
+ private Builder(
+ com.google.protobuf.GeneratedMessage.BuilderParent parent) {
+ super(parent);
+ maybeForceBuilderInitialization();
+ }
+ private void maybeForceBuilderInitialization() {
+ if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
+ }
+ }
+ private static Builder create() {
+ return new Builder();
+ }
+
+ public Builder clear() {
+ super.clear();
+ key_ = "";
+ bitField0_ = (bitField0_ & ~0x00000001);
+ valueType_ = com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.Type.STRING;
+ bitField0_ = (bitField0_ & ~0x00000002);
+ stringValue_ = "";
+ bitField0_ = (bitField0_ & ~0x00000004);
+ int32Value_ = 0;
+ bitField0_ = (bitField0_ & ~0x00000008);
+ int64Value_ = 0L;
+ bitField0_ = (bitField0_ & ~0x00000010);
+ doubleValue_ = 0D;
+ bitField0_ = (bitField0_ & ~0x00000020);
+ floatValue_ = 0F;
+ bitField0_ = (bitField0_ & ~0x00000040);
+ boolValue_ = false;
+ bitField0_ = (bitField0_ & ~0x00000080);
+ return this;
+ }
+
+ public Builder clone() {
+ return create().mergeFrom(buildPartial());
+ }
+
+ public com.google.protobuf.Descriptors.Descriptor
+ getDescriptorForType() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.internal_static_RamCloudGraph_PropertyProtoBuf_descriptor;
+ }
+
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf getDefaultInstanceForType() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.getDefaultInstance();
+ }
+
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf build() {
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf result = buildPartial();
+ if (!result.isInitialized()) {
+ throw newUninitializedMessageException(result);
+ }
+ return result;
+ }
+
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf buildPartial() {
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf result = new com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf(this);
+ int from_bitField0_ = bitField0_;
+ int to_bitField0_ = 0;
+ if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
+ to_bitField0_ |= 0x00000001;
+ }
+ result.key_ = key_;
+ if (((from_bitField0_ & 0x00000002) == 0x00000002)) {
+ to_bitField0_ |= 0x00000002;
+ }
+ result.valueType_ = valueType_;
+ if (((from_bitField0_ & 0x00000004) == 0x00000004)) {
+ to_bitField0_ |= 0x00000004;
+ }
+ result.stringValue_ = stringValue_;
+ if (((from_bitField0_ & 0x00000008) == 0x00000008)) {
+ to_bitField0_ |= 0x00000008;
+ }
+ result.int32Value_ = int32Value_;
+ if (((from_bitField0_ & 0x00000010) == 0x00000010)) {
+ to_bitField0_ |= 0x00000010;
+ }
+ result.int64Value_ = int64Value_;
+ if (((from_bitField0_ & 0x00000020) == 0x00000020)) {
+ to_bitField0_ |= 0x00000020;
+ }
+ result.doubleValue_ = doubleValue_;
+ if (((from_bitField0_ & 0x00000040) == 0x00000040)) {
+ to_bitField0_ |= 0x00000040;
+ }
+ result.floatValue_ = floatValue_;
+ if (((from_bitField0_ & 0x00000080) == 0x00000080)) {
+ to_bitField0_ |= 0x00000080;
+ }
+ result.boolValue_ = boolValue_;
+ result.bitField0_ = to_bitField0_;
+ onBuilt();
+ return result;
+ }
+
+ public Builder mergeFrom(com.google.protobuf.Message other) {
+ if (other instanceof com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf) {
+ return mergeFrom((com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf)other);
+ } else {
+ super.mergeFrom(other);
+ return this;
+ }
+ }
+
+ public Builder mergeFrom(com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf other) {
+ if (other == com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.getDefaultInstance()) return this;
+ if (other.hasKey()) {
+ bitField0_ |= 0x00000001;
+ key_ = other.key_;
+ onChanged();
+ }
+ if (other.hasValueType()) {
+ setValueType(other.getValueType());
+ }
+ if (other.hasStringValue()) {
+ bitField0_ |= 0x00000004;
+ stringValue_ = other.stringValue_;
+ onChanged();
+ }
+ if (other.hasInt32Value()) {
+ setInt32Value(other.getInt32Value());
+ }
+ if (other.hasInt64Value()) {
+ setInt64Value(other.getInt64Value());
+ }
+ if (other.hasDoubleValue()) {
+ setDoubleValue(other.getDoubleValue());
+ }
+ if (other.hasFloatValue()) {
+ setFloatValue(other.getFloatValue());
+ }
+ if (other.hasBoolValue()) {
+ setBoolValue(other.getBoolValue());
+ }
+ this.mergeUnknownFields(other.getUnknownFields());
+ return this;
+ }
+
+ public final boolean isInitialized() {
+ if (!hasKey()) {
+
+ return false;
+ }
+ if (!hasValueType()) {
+
+ return false;
+ }
+ return true;
+ }
+
+ public Builder mergeFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf parsedMessage = null;
+ try {
+ parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
+ } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+ parsedMessage = (com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf) e.getUnfinishedMessage();
+ throw e;
+ } finally {
+ if (parsedMessage != null) {
+ mergeFrom(parsedMessage);
+ }
+ }
+ return this;
+ }
+ private int bitField0_;
+
+ // required string key = 1;
+ private java.lang.Object key_ = "";
+ /**
+ * <code>required string key = 1;</code>
+ */
+ public boolean hasKey() {
+ return ((bitField0_ & 0x00000001) == 0x00000001);
+ }
+ /**
+ * <code>required string key = 1;</code>
+ */
+ public java.lang.String getKey() {
+ java.lang.Object ref = key_;
+ if (!(ref instanceof java.lang.String)) {
+ java.lang.String s = ((com.google.protobuf.ByteString) ref)
+ .toStringUtf8();
+ key_ = s;
+ return s;
+ } else {
+ return (java.lang.String) ref;
+ }
+ }
+ /**
+ * <code>required string key = 1;</code>
+ */
+ public com.google.protobuf.ByteString
+ getKeyBytes() {
+ java.lang.Object ref = key_;
+ if (ref instanceof String) {
+ com.google.protobuf.ByteString b =
+ com.google.protobuf.ByteString.copyFromUtf8(
+ (java.lang.String) ref);
+ key_ = b;
+ return b;
+ } else {
+ return (com.google.protobuf.ByteString) ref;
+ }
+ }
+ /**
+ * <code>required string key = 1;</code>
+ */
+ public Builder setKey(
+ java.lang.String value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ bitField0_ |= 0x00000001;
+ key_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>required string key = 1;</code>
+ */
+ public Builder clearKey() {
+ bitField0_ = (bitField0_ & ~0x00000001);
+ key_ = getDefaultInstance().getKey();
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>required string key = 1;</code>
+ */
+ public Builder setKeyBytes(
+ com.google.protobuf.ByteString value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ bitField0_ |= 0x00000001;
+ key_ = value;
+ onChanged();
+ return this;
+ }
+
+ // required .RamCloudGraph.PropertyProtoBuf.Type value_type = 2;
+ private com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.Type valueType_ = com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.Type.STRING;
+ /**
+ * <code>required .RamCloudGraph.PropertyProtoBuf.Type value_type = 2;</code>
+ */
+ public boolean hasValueType() {
+ return ((bitField0_ & 0x00000002) == 0x00000002);
+ }
+ /**
+ * <code>required .RamCloudGraph.PropertyProtoBuf.Type value_type = 2;</code>
+ */
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.Type getValueType() {
+ return valueType_;
+ }
+ /**
+ * <code>required .RamCloudGraph.PropertyProtoBuf.Type value_type = 2;</code>
+ */
+ public Builder setValueType(com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.Type value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ bitField0_ |= 0x00000002;
+ valueType_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>required .RamCloudGraph.PropertyProtoBuf.Type value_type = 2;</code>
+ */
+ public Builder clearValueType() {
+ bitField0_ = (bitField0_ & ~0x00000002);
+ valueType_ = com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.PropertyProtoBuf.Type.STRING;
+ onChanged();
+ return this;
+ }
+
+ // optional string string_value = 3;
+ private java.lang.Object stringValue_ = "";
+ /**
+ * <code>optional string string_value = 3;</code>
+ */
+ public boolean hasStringValue() {
+ return ((bitField0_ & 0x00000004) == 0x00000004);
+ }
+ /**
+ * <code>optional string string_value = 3;</code>
+ */
+ public java.lang.String getStringValue() {
+ java.lang.Object ref = stringValue_;
+ if (!(ref instanceof java.lang.String)) {
+ java.lang.String s = ((com.google.protobuf.ByteString) ref)
+ .toStringUtf8();
+ stringValue_ = s;
+ return s;
+ } else {
+ return (java.lang.String) ref;
+ }
+ }
+ /**
+ * <code>optional string string_value = 3;</code>
+ */
+ public com.google.protobuf.ByteString
+ getStringValueBytes() {
+ java.lang.Object ref = stringValue_;
+ if (ref instanceof String) {
+ com.google.protobuf.ByteString b =
+ com.google.protobuf.ByteString.copyFromUtf8(
+ (java.lang.String) ref);
+ stringValue_ = b;
+ return b;
+ } else {
+ return (com.google.protobuf.ByteString) ref;
+ }
+ }
+ /**
+ * <code>optional string string_value = 3;</code>
+ */
+ public Builder setStringValue(
+ java.lang.String value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ bitField0_ |= 0x00000004;
+ stringValue_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>optional string string_value = 3;</code>
+ */
+ public Builder clearStringValue() {
+ bitField0_ = (bitField0_ & ~0x00000004);
+ stringValue_ = getDefaultInstance().getStringValue();
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>optional string string_value = 3;</code>
+ */
+ public Builder setStringValueBytes(
+ com.google.protobuf.ByteString value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ bitField0_ |= 0x00000004;
+ stringValue_ = value;
+ onChanged();
+ return this;
+ }
+
+ // optional int32 int32_value = 4;
+ private int int32Value_ ;
+ /**
+ * <code>optional int32 int32_value = 4;</code>
+ */
+ public boolean hasInt32Value() {
+ return ((bitField0_ & 0x00000008) == 0x00000008);
+ }
+ /**
+ * <code>optional int32 int32_value = 4;</code>
+ */
+ public int getInt32Value() {
+ return int32Value_;
+ }
+ /**
+ * <code>optional int32 int32_value = 4;</code>
+ */
+ public Builder setInt32Value(int value) {
+ bitField0_ |= 0x00000008;
+ int32Value_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>optional int32 int32_value = 4;</code>
+ */
+ public Builder clearInt32Value() {
+ bitField0_ = (bitField0_ & ~0x00000008);
+ int32Value_ = 0;
+ onChanged();
+ return this;
+ }
+
+ // optional int64 int64_value = 5;
+ private long int64Value_ ;
+ /**
+ * <code>optional int64 int64_value = 5;</code>
+ */
+ public boolean hasInt64Value() {
+ return ((bitField0_ & 0x00000010) == 0x00000010);
+ }
+ /**
+ * <code>optional int64 int64_value = 5;</code>
+ */
+ public long getInt64Value() {
+ return int64Value_;
+ }
+ /**
+ * <code>optional int64 int64_value = 5;</code>
+ */
+ public Builder setInt64Value(long value) {
+ bitField0_ |= 0x00000010;
+ int64Value_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>optional int64 int64_value = 5;</code>
+ */
+ public Builder clearInt64Value() {
+ bitField0_ = (bitField0_ & ~0x00000010);
+ int64Value_ = 0L;
+ onChanged();
+ return this;
+ }
+
+ // optional double double_value = 6;
+ private double doubleValue_ ;
+ /**
+ * <code>optional double double_value = 6;</code>
+ */
+ public boolean hasDoubleValue() {
+ return ((bitField0_ & 0x00000020) == 0x00000020);
+ }
+ /**
+ * <code>optional double double_value = 6;</code>
+ */
+ public double getDoubleValue() {
+ return doubleValue_;
+ }
+ /**
+ * <code>optional double double_value = 6;</code>
+ */
+ public Builder setDoubleValue(double value) {
+ bitField0_ |= 0x00000020;
+ doubleValue_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>optional double double_value = 6;</code>
+ */
+ public Builder clearDoubleValue() {
+ bitField0_ = (bitField0_ & ~0x00000020);
+ doubleValue_ = 0D;
+ onChanged();
+ return this;
+ }
+
+ // optional float float_value = 7;
+ private float floatValue_ ;
+ /**
+ * <code>optional float float_value = 7;</code>
+ */
+ public boolean hasFloatValue() {
+ return ((bitField0_ & 0x00000040) == 0x00000040);
+ }
+ /**
+ * <code>optional float float_value = 7;</code>
+ */
+ public float getFloatValue() {
+ return floatValue_;
+ }
+ /**
+ * <code>optional float float_value = 7;</code>
+ */
+ public Builder setFloatValue(float value) {
+ bitField0_ |= 0x00000040;
+ floatValue_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>optional float float_value = 7;</code>
+ */
+ public Builder clearFloatValue() {
+ bitField0_ = (bitField0_ & ~0x00000040);
+ floatValue_ = 0F;
+ onChanged();
+ return this;
+ }
+
+ // optional bool bool_value = 8;
+ private boolean boolValue_ ;
+ /**
+ * <code>optional bool bool_value = 8;</code>
+ */
+ public boolean hasBoolValue() {
+ return ((bitField0_ & 0x00000080) == 0x00000080);
+ }
+ /**
+ * <code>optional bool bool_value = 8;</code>
+ */
+ public boolean getBoolValue() {
+ return boolValue_;
+ }
+ /**
+ * <code>optional bool bool_value = 8;</code>
+ */
+ public Builder setBoolValue(boolean value) {
+ bitField0_ |= 0x00000080;
+ boolValue_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>optional bool bool_value = 8;</code>
+ */
+ public Builder clearBoolValue() {
+ bitField0_ = (bitField0_ & ~0x00000080);
+ boolValue_ = false;
+ onChanged();
+ return this;
+ }
+
+ // @@protoc_insertion_point(builder_scope:RamCloudGraph.PropertyProtoBuf)
+ }
+
+ static {
+ defaultInstance = new PropertyProtoBuf(true);
+ defaultInstance.initFields();
+ }
+
+ // @@protoc_insertion_point(class_scope:RamCloudGraph.PropertyProtoBuf)
+ }
+
+ public interface IndexBlobOrBuilder
+ extends com.google.protobuf.MessageOrBuilder {
+
+ // repeated int64 vertexId = 1;
+ /**
+ * <code>repeated int64 vertexId = 1;</code>
+ */
+ java.util.List<java.lang.Long> getVertexIdList();
+ /**
+ * <code>repeated int64 vertexId = 1;</code>
+ */
+ int getVertexIdCount();
+ /**
+ * <code>repeated int64 vertexId = 1;</code>
+ */
+ long getVertexId(int index);
+ }
+ /**
+ * Protobuf type {@code RamCloudGraph.IndexBlob}
+ */
+ public static final class IndexBlob extends
+ com.google.protobuf.GeneratedMessage
+ implements IndexBlobOrBuilder {
+ // Use IndexBlob.newBuilder() to construct.
+ private IndexBlob(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
+ super(builder);
+ this.unknownFields = builder.getUnknownFields();
+ }
+ private IndexBlob(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }
+
+ private static final IndexBlob defaultInstance;
+ public static IndexBlob getDefaultInstance() {
+ return defaultInstance;
+ }
+
+ public IndexBlob getDefaultInstanceForType() {
+ return defaultInstance;
+ }
+
+ private final com.google.protobuf.UnknownFieldSet unknownFields;
+ @java.lang.Override
+ public final com.google.protobuf.UnknownFieldSet
+ getUnknownFields() {
+ return this.unknownFields;
+ }
+ private IndexBlob(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ initFields();
+ int mutable_bitField0_ = 0;
+ com.google.protobuf.UnknownFieldSet.Builder unknownFields =
+ com.google.protobuf.UnknownFieldSet.newBuilder();
+ try {
+ boolean done = false;
+ while (!done) {
+ int tag = input.readTag();
+ switch (tag) {
+ case 0:
+ done = true;
+ break;
+ default: {
+ if (!parseUnknownField(input, unknownFields,
+ extensionRegistry, tag)) {
+ done = true;
+ }
+ break;
+ }
+ case 8: {
+ if (!((mutable_bitField0_ & 0x00000001) == 0x00000001)) {
+ vertexId_ = new java.util.ArrayList<java.lang.Long>();
+ mutable_bitField0_ |= 0x00000001;
+ }
+ vertexId_.add(input.readInt64());
+ break;
+ }
+ case 10: {
+ int length = input.readRawVarint32();
+ int limit = input.pushLimit(length);
+ if (!((mutable_bitField0_ & 0x00000001) == 0x00000001) && input.getBytesUntilLimit() > 0) {
+ vertexId_ = new java.util.ArrayList<java.lang.Long>();
+ mutable_bitField0_ |= 0x00000001;
+ }
+ while (input.getBytesUntilLimit() > 0) {
+ vertexId_.add(input.readInt64());
+ }
+ input.popLimit(limit);
+ break;
+ }
+ }
+ }
+ } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+ throw e.setUnfinishedMessage(this);
+ } catch (java.io.IOException e) {
+ throw new com.google.protobuf.InvalidProtocolBufferException(
+ e.getMessage()).setUnfinishedMessage(this);
+ } finally {
+ if (((mutable_bitField0_ & 0x00000001) == 0x00000001)) {
+ vertexId_ = java.util.Collections.unmodifiableList(vertexId_);
+ }
+ this.unknownFields = unknownFields.build();
+ makeExtensionsImmutable();
+ }
+ }
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.internal_static_RamCloudGraph_IndexBlob_descriptor;
+ }
+
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.internal_static_RamCloudGraph_IndexBlob_fieldAccessorTable
+ .ensureFieldAccessorsInitialized(
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob.class, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob.Builder.class);
+ }
+
+ public static com.google.protobuf.Parser<IndexBlob> PARSER =
+ new com.google.protobuf.AbstractParser<IndexBlob>() {
+ public IndexBlob parsePartialFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return new IndexBlob(input, extensionRegistry);
+ }
+ };
+
+ @java.lang.Override
+ public com.google.protobuf.Parser<IndexBlob> getParserForType() {
+ return PARSER;
+ }
+
+ // repeated int64 vertexId = 1;
+ public static final int VERTEXID_FIELD_NUMBER = 1;
+ private java.util.List<java.lang.Long> vertexId_;
+ /**
+ * <code>repeated int64 vertexId = 1;</code>
+ */
+ public java.util.List<java.lang.Long>
+ getVertexIdList() {
+ return vertexId_;
+ }
+ /**
+ * <code>repeated int64 vertexId = 1;</code>
+ */
+ public int getVertexIdCount() {
+ return vertexId_.size();
+ }
+ /**
+ * <code>repeated int64 vertexId = 1;</code>
+ */
+ public long getVertexId(int index) {
+ return vertexId_.get(index);
+ }
+
+ private void initFields() {
+ vertexId_ = java.util.Collections.emptyList();
+ }
+ private byte memoizedIsInitialized = -1;
+ public final boolean isInitialized() {
+ byte isInitialized = memoizedIsInitialized;
+ if (isInitialized != -1) return isInitialized == 1;
+
+ memoizedIsInitialized = 1;
+ return true;
+ }
+
+ public void writeTo(com.google.protobuf.CodedOutputStream output)
+ throws java.io.IOException {
+ getSerializedSize();
+ for (int i = 0; i < vertexId_.size(); i++) {
+ output.writeInt64(1, vertexId_.get(i));
+ }
+ getUnknownFields().writeTo(output);
+ }
+
+ private int memoizedSerializedSize = -1;
+ public int getSerializedSize() {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ {
+ int dataSize = 0;
+ for (int i = 0; i < vertexId_.size(); i++) {
+ dataSize += com.google.protobuf.CodedOutputStream
+ .computeInt64SizeNoTag(vertexId_.get(i));
+ }
+ size += dataSize;
+ size += 1 * getVertexIdList().size();
+ }
+ size += getUnknownFields().getSerializedSize();
+ memoizedSerializedSize = size;
+ return size;
+ }
+
+ private static final long serialVersionUID = 0L;
+ @java.lang.Override
+ protected java.lang.Object writeReplace()
+ throws java.io.ObjectStreamException {
+ return super.writeReplace();
+ }
+
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob parseFrom(
+ com.google.protobuf.ByteString data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob parseFrom(
+ com.google.protobuf.ByteString data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob parseFrom(byte[] data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob parseFrom(
+ byte[] data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob parseFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob parseFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input, extensionRegistry);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob parseDelimitedFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return PARSER.parseDelimitedFrom(input);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob parseDelimitedFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return PARSER.parseDelimitedFrom(input, extensionRegistry);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob parseFrom(
+ com.google.protobuf.CodedInputStream input)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input);
+ }
+ public static com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob parseFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input, extensionRegistry);
+ }
+
+ public static Builder newBuilder() { return Builder.create(); }
+ public Builder newBuilderForType() { return newBuilder(); }
+ public static Builder newBuilder(com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob prototype) {
+ return newBuilder().mergeFrom(prototype);
+ }
+ public Builder toBuilder() { return newBuilder(this); }
+
+ @java.lang.Override
+ protected Builder newBuilderForType(
+ com.google.protobuf.GeneratedMessage.BuilderParent parent) {
+ Builder builder = new Builder(parent);
+ return builder;
+ }
+ /**
+ * Protobuf type {@code RamCloudGraph.IndexBlob}
+ */
+ public static final class Builder extends
+ com.google.protobuf.GeneratedMessage.Builder<Builder>
+ implements com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlobOrBuilder {
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.internal_static_RamCloudGraph_IndexBlob_descriptor;
+ }
+
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.internal_static_RamCloudGraph_IndexBlob_fieldAccessorTable
+ .ensureFieldAccessorsInitialized(
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob.class, com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob.Builder.class);
+ }
+
+ // Construct using com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob.newBuilder()
+ private Builder() {
+ maybeForceBuilderInitialization();
+ }
+
+ private Builder(
+ com.google.protobuf.GeneratedMessage.BuilderParent parent) {
+ super(parent);
+ maybeForceBuilderInitialization();
+ }
+ private void maybeForceBuilderInitialization() {
+ if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
+ }
+ }
+ private static Builder create() {
+ return new Builder();
+ }
+
+ public Builder clear() {
+ super.clear();
+ vertexId_ = java.util.Collections.emptyList();
+ bitField0_ = (bitField0_ & ~0x00000001);
+ return this;
+ }
+
+ public Builder clone() {
+ return create().mergeFrom(buildPartial());
+ }
+
+ public com.google.protobuf.Descriptors.Descriptor
+ getDescriptorForType() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.internal_static_RamCloudGraph_IndexBlob_descriptor;
+ }
+
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob getDefaultInstanceForType() {
+ return com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob.getDefaultInstance();
+ }
+
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob build() {
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob result = buildPartial();
+ if (!result.isInitialized()) {
+ throw newUninitializedMessageException(result);
+ }
+ return result;
+ }
+
+ public com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob buildPartial() {
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob result = new com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob(this);
+ int from_bitField0_ = bitField0_;
+ if (((bitField0_ & 0x00000001) == 0x00000001)) {
+ vertexId_ = java.util.Collections.unmodifiableList(vertexId_);
+ bitField0_ = (bitField0_ & ~0x00000001);
+ }
+ result.vertexId_ = vertexId_;
+ onBuilt();
+ return result;
+ }
+
+ public Builder mergeFrom(com.google.protobuf.Message other) {
+ if (other instanceof com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob) {
+ return mergeFrom((com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob)other);
+ } else {
+ super.mergeFrom(other);
+ return this;
+ }
+ }
+
+ public Builder mergeFrom(com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob other) {
+ if (other == com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob.getDefaultInstance()) return this;
+ if (!other.vertexId_.isEmpty()) {
+ if (vertexId_.isEmpty()) {
+ vertexId_ = other.vertexId_;
+ bitField0_ = (bitField0_ & ~0x00000001);
+ } else {
+ ensureVertexIdIsMutable();
+ vertexId_.addAll(other.vertexId_);
+ }
+ onChanged();
+ }
+ this.mergeUnknownFields(other.getUnknownFields());
+ return this;
+ }
+
+ public final boolean isInitialized() {
+ return true;
+ }
+
+ public Builder mergeFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob parsedMessage = null;
+ try {
+ parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
+ } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+ parsedMessage = (com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob) e.getUnfinishedMessage();
+ throw e;
+ } finally {
+ if (parsedMessage != null) {
+ mergeFrom(parsedMessage);
+ }
+ }
+ return this;
+ }
+ private int bitField0_;
+
+ // repeated int64 vertexId = 1;
+ private java.util.List<java.lang.Long> vertexId_ = java.util.Collections.emptyList();
+ private void ensureVertexIdIsMutable() {
+ if (!((bitField0_ & 0x00000001) == 0x00000001)) {
+ vertexId_ = new java.util.ArrayList<java.lang.Long>(vertexId_);
+ bitField0_ |= 0x00000001;
+ }
+ }
+ /**
+ * <code>repeated int64 vertexId = 1;</code>
+ */
+ public java.util.List<java.lang.Long>
+ getVertexIdList() {
+ return java.util.Collections.unmodifiableList(vertexId_);
+ }
+ /**
+ * <code>repeated int64 vertexId = 1;</code>
+ */
+ public int getVertexIdCount() {
+ return vertexId_.size();
+ }
+ /**
+ * <code>repeated int64 vertexId = 1;</code>
+ */
+ public long getVertexId(int index) {
+ return vertexId_.get(index);
+ }
+ /**
+ * <code>repeated int64 vertexId = 1;</code>
+ */
+ public Builder setVertexId(
+ int index, long value) {
+ ensureVertexIdIsMutable();
+ vertexId_.set(index, value);
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>repeated int64 vertexId = 1;</code>
+ */
+ public Builder addVertexId(long value) {
+ ensureVertexIdIsMutable();
+ vertexId_.add(value);
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>repeated int64 vertexId = 1;</code>
+ */
+ public Builder addAllVertexId(
+ java.lang.Iterable<? extends java.lang.Long> values) {
+ ensureVertexIdIsMutable();
+ super.addAll(values, vertexId_);
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>repeated int64 vertexId = 1;</code>
+ */
+ public Builder clearVertexId() {
+ vertexId_ = java.util.Collections.emptyList();
+ bitField0_ = (bitField0_ & ~0x00000001);
+ onChanged();
+ return this;
+ }
+
+ // @@protoc_insertion_point(builder_scope:RamCloudGraph.IndexBlob)
+ }
+
+ static {
+ defaultInstance = new IndexBlob(true);
+ defaultInstance.initFields();
+ }
+
+ // @@protoc_insertion_point(class_scope:RamCloudGraph.IndexBlob)
+ }
+
+ private static com.google.protobuf.Descriptors.Descriptor
+ internal_static_RamCloudGraph_EdgeListProtoBuf_descriptor;
+ private static
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internal_static_RamCloudGraph_EdgeListProtoBuf_fieldAccessorTable;
+ private static com.google.protobuf.Descriptors.Descriptor
+ internal_static_RamCloudGraph_EdgeProtoBuf_descriptor;
+ private static
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internal_static_RamCloudGraph_EdgeProtoBuf_fieldAccessorTable;
+ private static com.google.protobuf.Descriptors.Descriptor
+ internal_static_RamCloudGraph_PropertyListProtoBuf_descriptor;
+ private static
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internal_static_RamCloudGraph_PropertyListProtoBuf_fieldAccessorTable;
+ private static com.google.protobuf.Descriptors.Descriptor
+ internal_static_RamCloudGraph_PropertyProtoBuf_descriptor;
+ private static
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internal_static_RamCloudGraph_PropertyProtoBuf_fieldAccessorTable;
+ private static com.google.protobuf.Descriptors.Descriptor
+ internal_static_RamCloudGraph_IndexBlob_descriptor;
+ private static
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internal_static_RamCloudGraph_IndexBlob_fieldAccessorTable;
+
+ public static com.google.protobuf.Descriptors.FileDescriptor
+ getDescriptor() {
+ return descriptor;
+ }
+ private static com.google.protobuf.Descriptors.FileDescriptor
+ descriptor;
+ static {
+ java.lang.String[] descriptorData = {
+ "\n\023ramcloudgraph.proto\022\rRamCloudGraph\"=\n\020" +
+ "EdgeListProtoBuf\022)\n\004edge\030\001 \003(\0132\033.RamClou" +
+ "dGraph.EdgeProtoBuf\"C\n\014EdgeProtoBuf\022\022\n\nn" +
+ "eighborId\030\001 \002(\004\022\020\n\010outgoing\030\002 \002(\010\022\r\n\005lab" +
+ "el\030\003 \002(\t\"I\n\024PropertyListProtoBuf\0221\n\010prop" +
+ "erty\030\001 \003(\0132\037.RamCloudGraph.PropertyProto" +
+ "Buf\"\243\002\n\020PropertyProtoBuf\022\013\n\003key\030\001 \002(\t\0228\n" +
+ "\nvalue_type\030\002 \002(\0162$.RamCloudGraph.Proper" +
+ "tyProtoBuf.Type\022\024\n\014string_value\030\003 \001(\t\022\023\n" +
+ "\013int32_value\030\004 \001(\005\022\023\n\013int64_value\030\005 \001(\003\022",
+ "\024\n\014double_value\030\006 \001(\001\022\023\n\013float_value\030\007 \001" +
+ "(\002\022\022\n\nbool_value\030\010 \001(\010\"I\n\004Type\022\n\n\006STRING" +
+ "\020\001\022\t\n\005INT32\020\002\022\t\n\005INT64\020\003\022\n\n\006DOUBLE\020\004\022\t\n\005" +
+ "FLOAT\020\005\022\010\n\004BOOL\020\006\"\035\n\tIndexBlob\022\020\n\010vertex" +
+ "Id\030\001 \003(\003B>\n\'com.tinkerpop.blueprints.imp" +
+ "ls.ramcloudB\023RamCloudGraphProtos"
+ };
+ com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
+ new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
+ public com.google.protobuf.ExtensionRegistry assignDescriptors(
+ com.google.protobuf.Descriptors.FileDescriptor root) {
+ descriptor = root;
+ internal_static_RamCloudGraph_EdgeListProtoBuf_descriptor =
+ getDescriptor().getMessageTypes().get(0);
+ internal_static_RamCloudGraph_EdgeListProtoBuf_fieldAccessorTable = new
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable(
+ internal_static_RamCloudGraph_EdgeListProtoBuf_descriptor,
+ new java.lang.String[] { "Edge", });
+ internal_static_RamCloudGraph_EdgeProtoBuf_descriptor =
+ getDescriptor().getMessageTypes().get(1);
+ internal_static_RamCloudGraph_EdgeProtoBuf_fieldAccessorTable = new
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable(
+ internal_static_RamCloudGraph_EdgeProtoBuf_descriptor,
+ new java.lang.String[] { "NeighborId", "Outgoing", "Label", });
+ internal_static_RamCloudGraph_PropertyListProtoBuf_descriptor =
+ getDescriptor().getMessageTypes().get(2);
+ internal_static_RamCloudGraph_PropertyListProtoBuf_fieldAccessorTable = new
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable(
+ internal_static_RamCloudGraph_PropertyListProtoBuf_descriptor,
+ new java.lang.String[] { "Property", });
+ internal_static_RamCloudGraph_PropertyProtoBuf_descriptor =
+ getDescriptor().getMessageTypes().get(3);
+ internal_static_RamCloudGraph_PropertyProtoBuf_fieldAccessorTable = new
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable(
+ internal_static_RamCloudGraph_PropertyProtoBuf_descriptor,
+ new java.lang.String[] { "Key", "ValueType", "StringValue", "Int32Value", "Int64Value", "DoubleValue", "FloatValue", "BoolValue", });
+ internal_static_RamCloudGraph_IndexBlob_descriptor =
+ getDescriptor().getMessageTypes().get(4);
+ internal_static_RamCloudGraph_IndexBlob_fieldAccessorTable = new
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable(
+ internal_static_RamCloudGraph_IndexBlob_descriptor,
+ new java.lang.String[] { "VertexId", });
+ return null;
+ }
+ };
+ com.google.protobuf.Descriptors.FileDescriptor
+ .internalBuildGeneratedFileFrom(descriptorData,
+ new com.google.protobuf.Descriptors.FileDescriptor[] {
+ }, assigner);
+ }
+
+ // @@protoc_insertion_point(outer_class_scope)
+}
diff --git a/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/RamCloudIndex.java b/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/RamCloudIndex.java
new file mode 100644
index 0000000..0ba951d
--- /dev/null
+++ b/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/RamCloudIndex.java
@@ -0,0 +1,550 @@
+/* Copyright (c) 2013 Stanford University
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.tinkerpop.blueprints.impls.ramcloud;
+
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.protobuf.InvalidProtocolBufferException;
+import com.tinkerpop.blueprints.CloseableIterable;
+import com.tinkerpop.blueprints.Element;
+import com.tinkerpop.blueprints.Index;
+import com.tinkerpop.blueprints.util.ExceptionFactory;
+import com.tinkerpop.blueprints.impls.ramcloud.PerfMon;
+import com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob;
+import com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.IndexBlob.Builder;
+
+import edu.stanford.ramcloud.JRamCloud;
+
+// FIXME Index instance should be representing an Index table, not a IndexTable K-V pair
+public class RamCloudIndex<T extends Element> implements Index<T>, Serializable {
+
+ private final static Logger log = LoggerFactory.getLogger(RamCloudGraph.class);
+ protected RamCloudGraph graph;
+ private long tableId;
+ private String indexName;
+ protected byte[] rcKey;
+ private Class<T> indexClass;
+ // FIXME this should not be defined here
+ private long indexVersion;
+
+// private static final ThreadLocal<Kryo> kryo = new ThreadLocal<Kryo>() {
+// @Override
+// protected Kryo initialValue() {
+// Kryo kryo = new Kryo();
+// kryo.setRegistrationRequired(true);
+// kryo.register(Long.class);
+// kryo.register(String.class);
+// kryo.register(TreeMap.class);
+// kryo.register(ArrayList.class);
+// kryo.setReferences(false);
+// return kryo;
+// }
+// };
+
+
+ public RamCloudIndex(long tableId, String indexName, Object propValue, RamCloudGraph graph, Class<T> indexClass) {
+ this.tableId = tableId;
+ this.graph = graph;
+ this.rcKey = indexToRcKey(indexName, propValue);
+ this.indexName = indexName;
+ this.indexClass = indexClass;
+ }
+
+ public RamCloudIndex(long tableId, byte[] rcKey, RamCloudGraph graph, Class<T> indexClass) {
+ this.tableId = tableId;
+ this.graph = graph;
+ this.rcKey = rcKey;
+ this.indexName = rcKeyToIndexName(rcKey);
+ this.indexClass = indexClass;
+ }
+
+ public boolean exists() {
+ PerfMon pm = PerfMon.getInstance();
+
+ try {
+ JRamCloud.Object vertTableEntry;
+ JRamCloud vertTable = graph.getRcClient();
+
+ //vertTableEntry = graph.getRcClient().read(tableId, rcKey);
+ pm.indexread_start("RamCloudIndex exists()");
+ vertTableEntry = vertTable.read(tableId, rcKey);
+ pm.indexread_end("RamCloudIndex exists()");
+ indexVersion = vertTableEntry.version;
+ return true;
+ } catch (Exception e) {
+ pm.indexread_end("RamCloudIndex exists()");
+ log.debug("IndexTable entry for {} does not exists(): {}@{} [{}]", indexName, new String(rcKey), tableId, this);
+ return false;
+ }
+ }
+
+ public void create() {
+ if (!exists()) {
+ PerfMon pm = PerfMon.getInstance();
+ try {
+ JRamCloud rcClient = graph.getRcClient();
+ JRamCloud.RejectRules rules = rcClient.new RejectRules();
+ rules.setExists();
+
+ //graph.getRcClient().writeRule(tableId, rcKey, ByteBuffer.allocate(0).array(), rules);
+ pm.indexwrite_start("RamCloudIndex create()");
+ rcClient.writeRule(tableId, rcKey, ByteBuffer.allocate(0).array(), rules);
+ pm.indexwrite_end("RamCloudIndex create()");
+ } catch (Exception e) {
+ pm.indexwrite_end("RamCloudIndex create()");
+ log.info(toString() + ": Write create index list: ", e);
+ }
+ }
+ }
+
+ public static byte[] indexToRcKey(String key, Object propValue) {
+ try {
+ String s = key + "=" + propValue;
+ return ByteBuffer.allocate(s.getBytes().length).put(s.getBytes("UTF-8")).array();
+ } catch (UnsupportedEncodingException ex) {
+ log.error("indexToRcKey({}, {}) failed with exception {}", key, propValue, ex);
+ }
+ return null;
+ }
+
+ public static String rcKeyToIndexName(byte[] rcKey) {
+ try {
+ String s = new String(rcKey, "UTF-8");
+ return s.substring(0, s.indexOf('='));
+ } catch (UnsupportedEncodingException ex) {
+ log.error("rcKeyToIndexName({}) failed with exception {}", rcKey, ex);
+ }
+ return null;
+ }
+ public static String rcKeyToPropName(byte[] rcKey) {
+ try {
+ String s = new String(rcKey, "UTF-8");
+ return s.substring(s.indexOf('=')+1);
+ } catch (UnsupportedEncodingException ex) {
+ log.error("rcKeyToPropName({}) failed with exception {}", rcKey, ex);
+ }
+ return null;
+ }
+
+ @Override
+ public String getIndexName() {
+ return this.indexName;
+ }
+
+ @Override
+ public Class<T> getIndexClass() {
+ return this.indexClass;
+ }
+
+ @Override
+ public void put(String key, Object value, T element) {
+ getSetProperty(key, value, element.getId());
+ }
+
+ public void getSetProperty(String key, Object propValue, Object elmId) {
+ if (elmId == null) {
+ // FIXME Throw appropriate Exception
+ log.error("Element Id cannot be null");
+ return;
+ //throw ExceptionFactory.vertexIdCanNotBeNull();
+ //throw ExceptionFactory.edgeIdCanNotBeNull();
+ }
+
+ long startTime = 0;
+ if (graph.measureBPTimeProp == 1) {
+ startTime = System.nanoTime();
+ }
+
+ create();
+
+ // FIXME give more meaningful loop variable
+ for (int i = 0; i < 100; i++) {
+ Map<Object, List<Object>> map = readIndexPropertyMapFromDB();
+ List<Object> values = map.get(propValue);
+ if (values == null) {
+ values = new ArrayList<Object>();
+ map.put(propValue, values);
+ }
+ if (!values.contains(elmId)) {
+ values.add(elmId);
+ }
+
+ //Masa commented out the following measurement b/c Serialization delay is measured in onvertIndexPropertyMapToRcBytes(map)
+ //long serStartTime = System.nanoTime();
+ byte[] rcValue = convertIndexPropertyMapToRcBytes(map);
+ //if(RamCloudGraph.measureSerializeTimeProp == 1) {
+ // long serEndTime = System.nanoTime();
+ // log.error("Performance index kryo serialization [id={}] {} size {}", elmId, serEndTime - serStartTime, rcValue.length);
+ //}
+
+ if (rcValue.length != 0) {
+ if (writeWithRules(rcValue)) {
+ break;
+ } else {
+ log.debug("getSetProperty(String {}, Object {}) cond. write failure RETRYING {}", propValue, elmId, i+1);
+ if (i == 100) {
+ log.error("getSetProperty(String {}, Object {}) cond. write failure Gaveup RETRYING", propValue, elmId);
+ }
+ }
+ }
+ }
+
+ if (graph.measureBPTimeProp == 1) {
+ long endTime = System.nanoTime();
+ log.error("Performance index setProperty total time {}", endTime - startTime);
+ }
+ }
+
+ @Override
+ public CloseableIterable<T> get(String string, Object value) {
+ // FIXME Do we need this implemented
+ throw new RuntimeException("Not implemented yet");
+ //return getElmIdListForPropValue(value);
+ }
+
+ @Override
+ public CloseableIterable<T> query(String string, Object o) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public long count(String key, Object value) {
+ Map<Object, List<Object>> map = readIndexPropertyMapFromDB();
+ List<Object> values = map.get(value);
+ if (null == values) {
+ return 0;
+ } else {
+ return values.size();
+ }
+ }
+
+ @Override
+ public void remove(String propName, Object propValue, T element) {
+
+ if (propName == null) {
+ throw ExceptionFactory.propertyKeyCanNotBeNull();
+ }
+
+ if (propName.equals("")) {
+ throw ExceptionFactory.propertyKeyCanNotBeEmpty();
+ }
+
+ if (propName.equals("id")) {
+ throw ExceptionFactory.propertyKeyIdIsReserved();
+ }
+
+ if (!propName.equals(indexName)) {
+ log.error("Index name mismatch indexName:{}, remove({},{},...). SOMETHING IS WRONG", indexName, propName, propValue);
+ }
+
+ // FIXME better loop variable name
+ final int MAX_RETRYS = 100;
+ for (int i = 0; i < MAX_RETRYS; ++i) {
+ Map<Object, List<Object>> map = readIndexPropertyMapFromDB();
+
+ if (map.containsKey(propValue)) {
+ List<Object> idList = map.get(propValue);
+ if (null != idList) {
+ idList.remove(element.getId());
+ if (idList.isEmpty()) {
+ log.debug("remove({},{},...) called, and list became empty.", propName, propValue);
+ map.remove(propValue);
+ }
+ }
+ } else {
+ // propValue not found
+ log.warn("remove({},{},...) called on '{}' index table, but was not found on index. SOMETHING MAY BE WRONG", propName, propValue, this.indexName);
+ // no change to DB so exit now
+ return;
+ }
+ //long startTime = System.nanoTime();
+ //if(RamCloudGraph.measureSerializeTimeProp == 1) {
+ // pm.ser_start("SC");
+ //}
+ byte[] rcValue = convertIndexPropertyMapToRcBytes(map);
+ //if(RamCloudGraph.measureSerializeTimeProp == 1) {
+ // pm.ser_end("SC");
+ //long endTime = System.nanoTime();
+ //pm.ser_add(endTime - startTime);
+ //log.error("Performance index kryo serialization for removal key {} {} size {}", element, endTime - startTime, rcValue.length);
+ //}
+
+ if (rcValue.length == 0) {
+ return;
+ }
+
+ if (writeWithRules(rcValue)) {
+ break;
+ } else {
+ log.debug("remove({}, {}, T element) write failure RETRYING {}", propName, propValue, (i + 1));
+ if (i + 1 == MAX_RETRYS) {
+ log.error("remove({}, {}, T element) write failed completely. gave up RETRYING", propName, propValue);
+ }
+ }
+ }
+
+ }
+
+ public void removeElement(T element) {
+ removeElement(this.tableId, element, this.graph);
+ }
+
+ // FIXME this methods should not be defined here
+ public <T extends Element> void removeElement(long tableId, T element, RamCloudGraph graph) {
+ JRamCloud.TableEnumerator tableEnum = graph.getRcClient().new TableEnumerator(tableId);
+
+ while (tableEnum.hasNext()) {
+ JRamCloud.Object tableEntry = tableEnum.next();
+ Map<Object, List<Object>> indexValMap = convertRcBytesToIndexPropertyMap(tableEntry.value);
+
+ boolean madeChange = false;
+ Iterator<Map.Entry<Object, List<Object>>> indexValMapIt = indexValMap.entrySet().iterator();
+ while (indexValMapIt.hasNext()) {
+ Map.Entry<Object, List<Object>> entry = indexValMapIt.next();
+ List<Object> idList = entry.getValue();
+ madeChange |= idList.remove(element.getId());
+ if (idList.isEmpty()) {
+ madeChange = true;
+ indexValMapIt.remove();
+ }
+ }
+ if (madeChange == false) {
+ continue;
+ }
+
+ byte[] rcValue = convertIndexPropertyMapToRcBytes(indexValMap);
+ if (rcValue.length == 0) {
+ // nothing to write
+ continue;
+ }
+ if (writeWithRules(tableId, tableEntry.key, rcValue, tableEntry.version, graph)) {
+ // cond. write success
+ continue;
+ } else {
+ // cond. write failure
+ log.debug("removeElement({}, {}, ...) cond. key/value write failure RETRYING", tableId, element );
+ // FIXME Dirty hack
+ final int RETRY_MAX = 100;
+ for (int retry = RETRY_MAX; retry >= 0; --retry) {
+ RamCloudKeyIndex idx = new RamCloudKeyIndex(tableId, tableEntry.key, graph, element.getClass());
+ Map<Object, List<Object>> rereadMap = idx.readIndexPropertyMapFromDB();
+
+ boolean madeChangeOnRetry = false;
+ Iterator<Map.Entry<Object, List<Object>>> rereadIndexValMapIt = rereadMap.entrySet().iterator();
+ while (rereadIndexValMapIt.hasNext()) {
+ Map.Entry<Object, List<Object>> entry = rereadIndexValMapIt.next();
+ List<Object> idList = entry.getValue();
+ madeChangeOnRetry |= idList.remove(element.getId());
+ if (idList.isEmpty()) {
+ madeChangeOnRetry = true;
+ rereadIndexValMapIt.remove();
+ }
+ }
+ if (madeChangeOnRetry == false) {
+ log.debug("removeElement({}, {}, ...) no more write required. SOMETHING MAY BE WRONG", tableId, element);
+ break;
+ }
+
+ if (idx.writeWithRules(convertIndexPropertyMapToRcBytes(rereadMap))) {
+ log.debug("removeElement({}, {}, ...) cond. key/value {} write failure RETRYING {}", tableId, element, rereadMap, RETRY_MAX - retry);
+ // cond. re-write success
+ break;
+ }
+ if (retry == 0) {
+ log.error("removeElement({}, {}, ...) cond. write failed completely. Gave up RETRYING", tableId, element);
+ // XXX may be we should throw some kind of exception here?
+ }
+ }
+ }
+ }
+ }
+
+ public Map<Object, List<Object>> readIndexPropertyMapFromDB() {
+ //log.debug("getIndexPropertyMap() ");
+ JRamCloud.Object propTableEntry;
+ long startTime = 0;
+ PerfMon pm = PerfMon.getInstance();
+
+ try {
+ JRamCloud vertTable = graph.getRcClient();
+ if (graph.measureRcTimeProp == 1) {
+ startTime = System.nanoTime();
+ }
+ //propTableEntry = graph.getRcClient().read(tableId, rcKey);
+ pm.indexread_start("RamCloudIndex readIndexPropertyMapFromDB()");
+ propTableEntry = vertTable.read(tableId, rcKey);
+ pm.indexread_end("RamCloudIndex readIndexPropertyMapFromDB()");
+ if (graph.measureRcTimeProp == 1) {
+ long endTime = System.nanoTime();
+ log.error("Performance readIndexPropertyMapFromDB(indexName {}) read time {}", indexName, endTime - startTime);
+ }
+ indexVersion = propTableEntry.version;
+ } catch (Exception e) {
+ pm.indexread_end("RamCloudIndex readIndexPropertyMapFromDB()");
+ indexVersion = 0;
+ if (graph.measureRcTimeProp == 1) {
+ long endTime = System.nanoTime();
+ log.error("Performance readIndexPropertyMapFromDB(indexName {}) exception read time {}", indexName, endTime - startTime);
+ }
+ log.warn("readIndexPropertyMapFromDB() Element does not have a index property table entry! tableId :" + tableId + " indexName : " + indexName + " ", e);
+ return null;
+ }
+
+ return convertRcBytesToIndexPropertyMap(propTableEntry.value);
+ }
+
+ public Map<Object, List<Object>> convertRcBytesToIndexPropertyMap(byte[] byteArray) {
+ if (byteArray == null) {
+ log.error("Got a null byteArray argument");
+ return null;
+ } else if (byteArray.length != 0) {
+ PerfMon pm = PerfMon.getInstance();
+ long startTime = 0;
+ if(RamCloudGraph.measureSerializeTimeProp == 1) {
+ startTime = System.nanoTime();
+ }
+ pm.indexdeser_start("RamCloudIndex convertRcBytesToIndexPropertyMap()");
+ IndexBlob blob;
+ TreeMap<Object, List<Object>> map = new TreeMap<Object, List<Object>>();
+ try {
+ blob = IndexBlob.parseFrom(byteArray);
+ List const_list = blob.getVertexIdList();
+ ArrayList list = new ArrayList<>(const_list);
+// ByteBufferInput input = new ByteBufferInput(byteArray);
+// ArrayList list = kryo.get().readObject(input, ArrayList.class);
+ map.put(rcKeyToPropName(rcKey), list);
+ } catch (InvalidProtocolBufferException e) {
+ log.error("{" + toString() + "}: Read malformed edge list: ", e);
+ } finally {
+ pm.indexdeser_end("RamCloudIndex convertRcBytesToIndexPropertyMap()");
+ }
+ if(RamCloudGraph.measureSerializeTimeProp == 1) {
+ long endTime = System.nanoTime();
+ log.error("Performance index kryo deserialization [id=N/A] {} size {}", endTime - startTime, byteArray.length);
+ }
+ return map;
+ } else {
+ return new TreeMap<Object, List<Object>>();
+ }
+ }
+
+ public static byte[] convertIndexPropertyMapToRcBytes(Map<Object, List<Object>> map) {
+ PerfMon pm = PerfMon.getInstance();
+ long startTime = 0;
+ if(RamCloudGraph.measureSerializeTimeProp == 1) {
+ startTime = System.nanoTime();
+ }
+ byte[] bytes;
+
+ pm.indexser_start("RamCloudIndex convertIndexPropertyMapToRcBytes()");
+ Builder builder = IndexBlob.newBuilder();
+ if ( map.values().size() != 0 ) {
+ List<Long> vtxIds = (List)map.values().iterator().next();
+ builder.addAllVertexId(vtxIds);
+ }
+ IndexBlob blob = builder.build();
+ bytes = blob.toByteArray();
+// ByteBufferOutput output = new ByteBufferOutput(1024*1024);
+// if ( map.values().size() == 0 ) {
+// kryo.get().writeObject(output, new ArrayList<Object>());
+// } else {
+// kryo.get().writeObject(output, vtxIds);
+// }
+// bytes = output.toBytes();
+ pm.indexser_end("RamCloudIndex convertIndexPropertyMapToRcBytes()");
+ if(RamCloudGraph.measureSerializeTimeProp == 1) {
+ long endTime = System.nanoTime();
+ log.error("Performance index ProtoBuff serialization {}, size={}", endTime - startTime, bytes);
+ }
+ return bytes;
+ }
+
+ protected boolean writeWithRules(byte[] rcValue) {
+ return writeWithRules(this.tableId, this.rcKey, rcValue, this.indexVersion, this.graph);
+ }
+
+ private static boolean writeWithRules(long tableId, byte[] rcKey, byte[] rcValue, long expectedVersion, RamCloudGraph graph) {
+ JRamCloud.RejectRules rules = graph.getRcClient().new RejectRules();
+
+ if (expectedVersion == 0) {
+ rules.setExists();
+ } else {
+ rules.setNeVersion(expectedVersion);
+ }
+
+ PerfMon pm = PerfMon.getInstance();
+ try {
+ JRamCloud vertTable = graph.getRcClient();
+ pm.indexwrite_start("RamCloudIndex writeWithRules()");
+ vertTable.writeRule(tableId, rcKey, rcValue, rules);
+ pm.indexwrite_end("RamCloudIndex writeWithRules()");
+ } catch (Exception e) {
+ pm.indexwrite_end("RamCloudIndex writeWithRules()");
+ pm.indexwrite_condfail("RamCloudIndex writeWithRules()");
+ log.debug("Cond. Write index property: {} failed {} expected version: {}", rcKeyToIndexName(rcKey), e, expectedVersion);
+ return false;
+ }
+ return true;
+ }
+
+ public List<Object> getElmIdListForPropValue(Object propValue) {
+ Map<Object, List<Object>> map = readIndexPropertyMapFromDB();
+ if (map == null) {
+ log.debug("IndexPropertyMap was null. {} : {}", indexName, propValue);
+ return null;
+ }
+ return map.get(propValue);
+ }
+
+ public Set<Object> getIndexPropertyKeys() {
+ Map<Object, List<Object>> map = readIndexPropertyMapFromDB();
+ return map.keySet();
+ }
+
+ public <T> T removeIndexProperty(String key) {
+ for (int i = 0; i < 100; ++i) {
+ Map<Object, List<Object>> map = readIndexPropertyMapFromDB();
+ T retVal = (T) map.remove(key);
+ byte[] rcValue = convertIndexPropertyMapToRcBytes(map);
+ if (rcValue.length != 0) {
+ if (writeWithRules(rcValue)) {
+ return retVal;
+ } else {
+ log.debug("removeIndexProperty({}) cond. key/value write failure RETRYING {}", tableId, (i + 1));
+ }
+ }
+ }
+ log.error("removeIndexProperty({}) cond. key/value write failure gave up RETRYING", tableId);
+ // XXX ?Is this correct
+ return null;
+ }
+
+ public void removeIndex() {
+ log.info("Removing Index: {} was version {} [{}]", indexName, indexVersion, this);
+ graph.getRcClient().remove(tableId, rcKey);
+ }
+}
diff --git a/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/RamCloudKeyIndex.java b/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/RamCloudKeyIndex.java
new file mode 100644
index 0000000..0127a62
--- /dev/null
+++ b/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/RamCloudKeyIndex.java
@@ -0,0 +1,63 @@
+/* Copyright (c) 2013 Stanford University
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.tinkerpop.blueprints.impls.ramcloud;
+
+import java.io.Serializable;
+import java.util.Set;
+
+import com.tinkerpop.blueprints.Element;
+
+public class RamCloudKeyIndex<T extends RamCloudElement> extends RamCloudIndex<T> implements Serializable {
+ public RamCloudKeyIndex(long tableId, String indexName, Object propValue, RamCloudGraph graph, Class<T> indexClass) {
+ super(tableId, indexName, propValue, graph, indexClass);
+ }
+
+ public RamCloudKeyIndex(long tableId, byte[] rcKey, RamCloudGraph graph, Class<T> indexClass) {
+ super(tableId, rcKey, graph, indexClass);
+ }
+
+ public boolean autoUpdate(final String key, final Object newValue, final Object oldValue, final T element) {
+ if (graph.indexedKeys.contains(key)) {
+ if (oldValue != null) {
+ this.remove(key, oldValue, element);
+ }
+ this.put(key, newValue, element);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public void autoRemove(final String key, final Object oldValue, final T element) {
+ if (graph.indexedKeys.contains(key)) {
+ this.remove(key, oldValue, element);
+ }
+ }
+
+ public long reIndexElements(final RamCloudGraph graph, final Iterable<? extends Element> elements, final Set<String> keys) {
+ long counter = 0;
+ for (final Element element : elements) {
+ for (final String key : keys) {
+ final Object value = element.removeProperty(key);
+ if (null != value) {
+ counter++;
+ element.setProperty(key, value);
+ }
+ }
+ }
+ return counter;
+ }
+}
diff --git a/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/RamCloudVertex.java b/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/RamCloudVertex.java
new file mode 100644
index 0000000..421db77
--- /dev/null
+++ b/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/RamCloudVertex.java
@@ -0,0 +1,513 @@
+/* Copyright (c) 2013 Stanford University
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.tinkerpop.blueprints.impls.ramcloud;
+
+import java.io.Serializable;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.protobuf.InvalidProtocolBufferException;
+import com.tinkerpop.blueprints.Direction;
+import com.tinkerpop.blueprints.Edge;
+import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.blueprints.VertexQuery;
+import com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeListProtoBuf;
+import com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraphProtos.EdgeProtoBuf;
+import com.tinkerpop.blueprints.util.DefaultVertexQuery;
+import com.tinkerpop.blueprints.util.ExceptionFactory;
+import com.tinkerpop.blueprints.impls.ramcloud.PerfMon;
+
+import edu.stanford.ramcloud.JRamCloud;
+import edu.stanford.ramcloud.JRamCloud.MultiWriteObject;
+import edu.stanford.ramcloud.JRamCloud.RejectRules;
+import edu.stanford.ramcloud.JRamCloud.WrongVersionException;
+
+public class RamCloudVertex extends RamCloudElement implements Vertex, Serializable {
+
+ private final static Logger log = LoggerFactory.getLogger(RamCloudGraph.class);
+ private static final long serialVersionUID = 7526472295622776147L;
+ protected long id;
+ protected byte[] rcKey;
+ private RamCloudGraph graph;
+
+ private Versioned<EdgeListProtoBuf> cachedAdjEdgeList;
+
+ public RamCloudVertex(long id, RamCloudGraph graph) {
+ super(idToRcKey(id), graph.vertPropTableId, graph);
+
+ this.id = id;
+ this.rcKey = idToRcKey(id);
+ this.graph = graph;
+ this.cachedAdjEdgeList = null;
+ }
+
+ public RamCloudVertex(byte[] rcKey, RamCloudGraph graph) {
+ super(rcKey, graph.vertPropTableId, graph);
+
+ this.id = rcKeyToId(rcKey);
+ this.rcKey = rcKey;
+ this.graph = graph;
+ this.cachedAdjEdgeList = null;
+ }
+
+
+ /*
+ * Vertex interface implementation
+ */
+ @Override
+ public Edge addEdge(String label, Vertex inVertex) {
+ return graph.addEdge(null, this, inVertex, label);
+ }
+
+ @Override
+ public Iterable<Edge> getEdges(Direction direction, String... labels) {
+ return new ArrayList<Edge>(getEdgeList(direction, labels));
+ }
+
+ @Override
+ public Iterable<Vertex> getVertices(Direction direction, String... labels) {
+ List<RamCloudEdge> edges = getEdgeList(direction, labels);
+ List<Vertex> neighbors = new LinkedList<Vertex>();
+ for (RamCloudEdge edge : edges) {
+ neighbors.add(edge.getNeighbor(this));
+ }
+ return neighbors;
+ }
+
+ @Override
+ public VertexQuery query() {
+ return new DefaultVertexQuery(this);
+ }
+
+ /*
+ * RamCloudElement overridden methods
+ */
+ @Override
+ public Object getId() {
+ return id;
+ }
+
+ @Override
+ public void remove() {
+ Set<RamCloudEdge> edges = getEdgeSet();
+
+ // neighbor vertex -> List of Edges to remove
+ Map<RamCloudVertex, List<RamCloudEdge>> vertexToEdgesMap = new HashMap<RamCloudVertex, List<RamCloudEdge>>( edges.size() );
+
+ // Batch edges together by neighbor vertex
+ for (RamCloudEdge edge : edges) {
+ RamCloudVertex neighbor = (RamCloudVertex) edge.getNeighbor(this);
+ List<RamCloudEdge> edgeList = vertexToEdgesMap.get(neighbor);
+
+ if (edgeList == null) {
+ edgeList = new LinkedList<RamCloudEdge>();
+ }
+
+ edgeList.add(edge);
+ vertexToEdgesMap.put(neighbor, edgeList);
+ }
+
+ // Remove batches of edges at a time by neighbor vertex
+ for (Entry<RamCloudVertex, List<RamCloudEdge>> entry : vertexToEdgesMap.entrySet()) {
+ // Skip over loopback edges to ourself
+ if (!entry.getKey().equals(this)) {
+ entry.getKey().removeEdgesFromAdjList(entry.getValue());
+ }
+
+ // Remove this batch of edges from the edge property table
+ for (RamCloudEdge edge : entry.getValue()) {
+ edge.removeProperties();
+ }
+ }
+
+ Map<String,Object> props = this.getPropertyMap();
+ for( Map.Entry<String,Object> entry : props.entrySet() ) {
+ if ( !graph.indexedKeys.contains(entry.getKey() ) ) continue;
+ RamCloudKeyIndex keyIndex = new RamCloudKeyIndex(graph.kidxVertTableId, entry.getKey(), entry.getValue(), graph, Vertex.class);
+ keyIndex.remove(entry.getKey(), entry.getValue(), this);
+ }
+
+ // Remove ourselves entirely from the vertex table
+ graph.getRcClient().remove(graph.vertTableId, rcKey);
+
+ super.remove();
+ }
+
+ /*
+ * Object overridden methods
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ RamCloudVertex other = (RamCloudVertex) obj;
+ return (id == other.id);
+ }
+
+ @Override
+ public int hashCode() {
+ return Long.valueOf(id).hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "RamCloudVertex [id=" + id + "]";
+ }
+
+ /*
+ * RamCloudVertex specific methods
+ */
+ private static byte[] idToRcKey(long id) {
+ return ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN).putLong(id).array();
+ }
+
+ private static long rcKeyToId(byte[] rcKey) {
+ return ByteBuffer.wrap(rcKey).order(ByteOrder.LITTLE_ENDIAN).getLong();
+ }
+
+ boolean addEdgeToAdjList(RamCloudEdge edge) {
+ List<RamCloudEdge> edgesToAdd = new ArrayList<RamCloudEdge>(1);
+ edgesToAdd.add(edge);
+ return addEdgesToAdjList(edgesToAdd);
+ }
+ boolean removeEdgeFromAdjList(RamCloudEdge edge) {
+ List<RamCloudEdge> edgesToRemove = new ArrayList<RamCloudEdge>(1);
+ edgesToRemove.add(edge);
+ return removeEdgesFromAdjList(edgesToRemove);
+ }
+
+ private boolean addEdgesToAdjList(List<RamCloudEdge> edgesToAdd) {
+ return updateEdgeAdjList(edgesToAdd, true);
+ }
+ private boolean removeEdgesFromAdjList(List<RamCloudEdge> edgesToAdd) {
+ return updateEdgeAdjList(edgesToAdd, false);
+ }
+
+ /** Conditionally update Adj. Edge List
+ * @return true if EdgeAdjList was logically modified.(Cache update does not imply true return)
+ */
+ private boolean updateEdgeAdjList(List<RamCloudEdge> edgesToModify, boolean add) {
+ PerfMon pm = PerfMon.getInstance();
+ JRamCloud rcClient = graph.getRcClient();
+ final int MAX_RETRIES = 100;
+ for (int retry = 1 ; retry <= MAX_RETRIES ; ++retry ) {
+ Set<RamCloudEdge> edges;
+ long expected_version = 0L;
+ if ( this.cachedAdjEdgeList == null ) {
+ edges = new HashSet<RamCloudEdge>();
+ } else {
+ expected_version = this.cachedAdjEdgeList.getVersion();
+ if ( expected_version == 0L && add == false ) {
+ updateCachedAdjEdgeList();
+ expected_version = this.cachedAdjEdgeList.getVersion();
+ }
+ edges = buildEdgeSetFromProtobuf(this.cachedAdjEdgeList.getValue(), Direction.BOTH);
+ }
+ if ( expected_version == 0L && add == false ) {
+ updateCachedAdjEdgeList();
+ expected_version = this.cachedAdjEdgeList.getVersion();
+ edges = buildEdgeSetFromProtobuf(this.cachedAdjEdgeList.getValue(), Direction.BOTH);
+ }
+ //log.debug( (add?"Adding":"Removing") + " edges to: {"+ edges+ "}");
+
+ try {
+ if ( add ) {
+ if (edges.addAll(edgesToModify) == false) {
+ log.warn("{}: There aren't any changes to edges ({})", this, edgesToModify);
+ return false;
+ }
+ } else {
+ if (edges.removeAll(edgesToModify) == false) {
+ log.warn("{}: There aren't any changes to edges ({})", this, edgesToModify);
+ return false;
+ }
+ }
+
+ EdgeListProtoBuf edgeList = buildProtoBufFromEdgeSet(edges);
+ JRamCloud.RejectRules rules = rcClient.new RejectRules();
+ if ( expected_version == 0L ) {
+ rules.setExists();
+ } else {
+ rules.setNeVersion(expected_version);
+ }
+ pm.write_start("RAMCloudVertex updateEdgeAdjList()");
+ long updated_version = rcClient.writeRule(graph.vertTableId, rcKey, edgeList.toByteArray(), rules);
+ pm.write_end("RAMCloudVertex updateEdgeAdjList()");
+ this.cachedAdjEdgeList.setValue(edgeList, updated_version);
+ return true;
+ } catch (UnsupportedOperationException e) {
+ pm.write_end("RAMCloudVertex updateEdgeAdjList()");
+ pm.write_condfail("RAMCloudVertex updateEdgeAdjList()");
+ log.error("{" + toString() + "}: Failed to modify a set of edges ({" + edgesToModify + "}): ", e);
+ return false;
+ } catch (ClassCastException e) {
+ pm.write_end("RAMCloudVertex updateEdgeAdjList()");
+ pm.write_condfail("RAMCloudVertex updateEdgeAdjList()");
+ log.error("{" + toString() + "}: Failed to modify a set of edges ({" + edgesToModify + "}): ", e);
+ return false;
+ } catch (NullPointerException e) {
+ pm.write_end("RAMCloudVertex updateEdgeAdjList()");
+ pm.write_condfail("RAMCloudVertex updateEdgeAdjList()");
+ log.error("{" + toString() + "}: Failed to modify a set of edges ({" + edgesToModify + "}): ", e);
+ return false;
+ } catch (Exception e) {
+ pm.write_end("RAMCloudVertex updateEdgeAdjList()");
+ pm.write_condfail("RAMCloudVertex updateEdgeAdjList()");
+ // FIXME Workaround for native method exception declaration bug
+ if ( e instanceof WrongVersionException ) {
+ log.debug("Conditional Updating EdgeList failed for {} RETRYING {}", this, retry);
+ //log.debug("Conditional Updating EdgeList failed for {} modifing {} RETRYING [{}]", this, edgesToModify, retry);
+ updateCachedAdjEdgeList();
+ } else {
+ log.debug("Cond. Write to modify adj edge list failed, exception thrown", e);
+ updateCachedAdjEdgeList();
+ }
+ }
+ }
+ log.error("Conditional Updating EdgeList failed for {} gave up RETRYING", this);
+ return false;
+ }
+
+ /** Get all adj.edge list
+ * Method is exposed to package namespace to do Vertex removal efficiently;
+ */
+ Set<RamCloudEdge> getEdgeSet() {
+ return getVersionedEdgeSet(Direction.BOTH).getValue();
+ }
+
+ private Versioned<EdgeListProtoBuf> updateCachedAdjEdgeList() {
+ JRamCloud.Object vertTableEntry;
+ EdgeListProtoBuf edgeList;
+
+ PerfMon pm = PerfMon.getInstance();
+ try {
+ JRamCloud vertTable = graph.getRcClient();
+ pm.read_start("RamCloudVertex updateCachedAdjEdgeList()");
+ vertTableEntry = vertTable.read(graph.vertTableId, rcKey);
+ pm.read_end("RamCloudVertex updateCachedAdjEdgeList()");
+ } catch (Exception e) {
+ pm.read_end("RamCloudVertex updateCachedAdjEdgeList()");
+ log.error("{" + toString() + "}: Error reading vertex table entry: ", e);
+ return null;
+ }
+
+ try {
+ pm.protodeser_start("RamCloudVertex updateCachedAdjEdgeList()");
+ edgeList = EdgeListProtoBuf.parseFrom(vertTableEntry.value);
+ Versioned<EdgeListProtoBuf> updatedEdgeList = new Versioned<EdgeListProtoBuf>(edgeList, vertTableEntry.version);
+ this.cachedAdjEdgeList = updatedEdgeList;
+ pm.protodeser_end("RamCloudVertex updateCachedAdjEdgeList()");
+ return updatedEdgeList;
+ } catch (InvalidProtocolBufferException e) {
+ pm.protodeser_end("RamCloudVertex updateCachedAdjEdgeList()");
+ log.error("{" + toString() + "}: Read malformed edge list: ", e);
+ return null;
+ }
+ }
+
+ private Versioned<Set<RamCloudEdge>> getVersionedEdgeSet(Direction direction, String... labels) {
+ Versioned<EdgeListProtoBuf> cachedEdgeList = updateCachedAdjEdgeList();
+ return new Versioned<Set<RamCloudEdge>>(buildEdgeSetFromProtobuf(cachedEdgeList.getValue(), direction, labels), cachedEdgeList.getVersion() );
+ }
+
+ private Set<RamCloudEdge> buildEdgeSetFromProtobuf(EdgeListProtoBuf edgeList,
+ Direction direction, String... labels) {
+ PerfMon pm = PerfMon.getInstance();
+ long startTime = 0;
+ if(RamCloudGraph.measureSerializeTimeProp == 1) {
+ startTime = System.nanoTime();
+ }
+ pm.protodeser_start("RamCloudVertex buildEdgeSetFromProtobuf()");
+ Set<RamCloudEdge> edgeSet = new HashSet<RamCloudEdge>( edgeList.getEdgeCount() );
+ for (EdgeProtoBuf edge : edgeList.getEdgeList()) {
+ if ((direction.equals(Direction.BOTH) || (edge.getOutgoing() ^ direction.equals(Direction.IN)))
+ && (labels.length == 0 || Arrays.asList(labels).contains(edge.getLabel()))) {
+ RamCloudVertex neighbor = new RamCloudVertex(edge.getNeighborId(), graph);
+ if (edge.getOutgoing()) {
+ edgeSet.add(new RamCloudEdge(this, neighbor, edge.getLabel(), graph));
+ } else {
+ edgeSet.add(new RamCloudEdge(neighbor, this, edge.getLabel(), graph));
+ }
+ }
+ }
+ pm.protodeser_end("RamCloudVertex buildEdgeSetFromProtobuf()");
+ if(RamCloudGraph.measureSerializeTimeProp == 1) {
+ long endTime = System.nanoTime();
+ log.error("Performance buildEdgeSetFromProtobuf key {}, {}, size={}", this, endTime - startTime, edgeList.getSerializedSize());
+ }
+ return edgeSet;
+ }
+
+
+
+ private EdgeListProtoBuf buildProtoBufFromEdgeSet(Set<RamCloudEdge> edgeSet) {
+ PerfMon pm = PerfMon.getInstance();
+ long startTime = 0;
+ if(RamCloudGraph.measureSerializeTimeProp == 1) {
+ startTime = System.nanoTime();
+ }
+
+ pm.protoser_start("RamCloudVertex buildProtoBufFromEdgeSet()");
+
+ EdgeListProtoBuf.Builder edgeListBuilder = EdgeListProtoBuf.newBuilder();
+ EdgeProtoBuf.Builder edgeBuilder = EdgeProtoBuf.newBuilder();
+
+ for (Edge edge : edgeSet) {
+ if (edge.getVertex(Direction.OUT).equals(this) || edge.getVertex(Direction.IN).equals(this)) {
+ if (edge.getVertex(Direction.OUT).equals(edge.getVertex(Direction.IN))) {
+ edgeBuilder.setNeighborId(id);
+ edgeBuilder.setOutgoing(true);
+ edgeBuilder.setLabel(edge.getLabel());
+ edgeListBuilder.addEdge(edgeBuilder.build());
+
+ edgeBuilder.setOutgoing(false);
+ edgeListBuilder.addEdge(edgeBuilder.build());
+ } else {
+ if (edge.getVertex(Direction.OUT).equals(this)) {
+ edgeBuilder.setNeighborId((Long) edge.getVertex(Direction.IN).getId());
+ edgeBuilder.setOutgoing(true);
+ edgeBuilder.setLabel(edge.getLabel());
+ edgeListBuilder.addEdge(edgeBuilder.build());
+ } else {
+ edgeBuilder.setNeighborId((Long) edge.getVertex(Direction.OUT).getId());
+ edgeBuilder.setOutgoing(false);
+ edgeBuilder.setLabel(edge.getLabel());
+ edgeListBuilder.addEdge(edgeBuilder.build());
+ }
+ }
+ } else {
+ log.warn("{}: Tried to add an edge unowned by this vertex ({})", this, edge);
+ }
+ }
+
+ EdgeListProtoBuf buf = edgeListBuilder.build();
+ pm.protoser_end("RamCloudVertex buildProtoBufFromEdgeSet");
+ if(RamCloudGraph.measureSerializeTimeProp == 1) {
+ long endTime = System.nanoTime();
+ log.error("Performance buildProtoBufFromEdgeSet key {}, {}, size={}", this, endTime - startTime, buf.getSerializedSize());
+ }
+ return buf;
+ }
+
+ @Deprecated
+ private List<RamCloudEdge> getEdgeList() {
+ return getEdgeList(Direction.BOTH);
+ }
+
+ private List<RamCloudEdge> getEdgeList(Direction direction, String... labels) {
+
+ Versioned<EdgeListProtoBuf> cachedEdgeList = updateCachedAdjEdgeList();
+ PerfMon pm = PerfMon.getInstance();
+ pm.protodeser_start("RamCloudVertex getEdgeList()");
+
+ List<RamCloudEdge> edgeList = new ArrayList<RamCloudEdge>(cachedEdgeList.getValue().getEdgeCount());
+
+ for (EdgeProtoBuf edge : cachedEdgeList.getValue().getEdgeList()) {
+ if ((direction.equals(Direction.BOTH) || (edge.getOutgoing() ^ direction.equals(Direction.IN)))
+ && (labels.length == 0 || Arrays.asList(labels).contains(edge.getLabel()))) {
+ RamCloudVertex neighbor = new RamCloudVertex(edge.getNeighborId(), graph);
+ if (edge.getOutgoing()) {
+ edgeList.add(new RamCloudEdge(this, neighbor, edge.getLabel(), graph));
+ } else {
+ edgeList.add(new RamCloudEdge(neighbor, this, edge.getLabel(), graph));
+ }
+ }
+ }
+ pm.protodeser_end("RamCloudVertex getEdgeList()");
+
+ return edgeList;
+ }
+
+ protected boolean exists() {
+ boolean vertTableEntryExists = false;
+ boolean vertPropTableEntryExists = false;
+
+ PerfMon pm = PerfMon.getInstance();
+ JRamCloud vertTable = graph.getRcClient();
+ try {
+ pm.read_start("RamCloudVertex exists()");
+ vertTable.read(graph.vertTableId, rcKey);
+ pm.read_end("RamCloudVertex exists()");
+ vertTableEntryExists = true;
+ } catch (Exception e) {
+ // Vertex table entry does not exist
+ pm.read_end("RamCloudVertex exists()");
+ }
+
+ try {
+ pm.read_start("RamCloudVertex exists()");
+ vertTable.read(graph.vertPropTableId, rcKey);
+ pm.read_end("RamCloudVertex exists()");
+ vertPropTableEntryExists = true;
+ } catch (Exception e) {
+ // Vertex property table entry does not exist
+ pm.read_end("RamCloudVertex exists()");
+ }
+
+ if (vertTableEntryExists && vertPropTableEntryExists) {
+ return true;
+ } else if (!vertTableEntryExists && !vertPropTableEntryExists) {
+ return false;
+ } else {
+ log.warn("{}: Detected RamCloudGraph inconsistency: vertTableEntryExists={}, vertPropTableEntryExists={}.", this, vertTableEntryExists, vertPropTableEntryExists);
+ return true;
+ }
+ }
+
+ protected void create() throws IllegalArgumentException {
+ // TODO: Existence check costs extra (presently 2 reads), could use option to turn on/off
+ if (!exists()) {
+ PerfMon pm = PerfMon.getInstance();
+ JRamCloud vertTable = graph.getRcClient();
+ MultiWriteObject[] mwo = new MultiWriteObject[2];
+ mwo[0] = new MultiWriteObject(graph.vertTableId, rcKey, ByteBuffer.allocate(0).array(), null);
+ mwo[1] = new MultiWriteObject(graph.vertPropTableId, rcKey, ByteBuffer.allocate(0).array(), null);
+ pm.multiwrite_start("RamCloudVertex create()");
+ vertTable.multiWrite(mwo);
+ pm.multiwrite_end("RamCloudVertex create()");
+ } else {
+ throw ExceptionFactory.vertexWithIdAlreadyExists(id);
+ }
+ }
+
+ public void debugPrintEdgeList() {
+ List<RamCloudEdge> edgeList = getEdgeList();
+
+ log.debug("{}: Debug Printing Edge List...", this);
+ for (RamCloudEdge edge : edgeList) {
+ System.out.println(edge.toString());
+ }
+ }
+}
diff --git a/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/Versioned.java b/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/Versioned.java
new file mode 100644
index 0000000..e944c62
--- /dev/null
+++ b/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/Versioned.java
@@ -0,0 +1,41 @@
+/* Copyright (c) 2013 Stanford University
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.tinkerpop.blueprints.impls.ramcloud;
+
+public class Versioned<T> {
+ private T value;
+ private long version;
+
+ public Versioned(T value) {
+ this(value, 0L);
+ }
+
+ public Versioned(T value, long version) {
+ this.value = value;
+ this.version = version;
+ }
+
+ public T getValue() {
+ return value;
+ }
+ public long getVersion() {
+ return version;
+ }
+ public void setValue(T value, long version) {
+ this.value = value;
+ this.version = version;
+ }
+}
diff --git a/src/main/java/com/tinkerpop/rexster/config/RamCloudGraphConfiguration.java b/src/main/java/com/tinkerpop/rexster/config/RamCloudGraphConfiguration.java
new file mode 100644
index 0000000..fad056e
--- /dev/null
+++ b/src/main/java/com/tinkerpop/rexster/config/RamCloudGraphConfiguration.java
@@ -0,0 +1,30 @@
+/* Copyright (c) 2013 Stanford University
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package com.tinkerpop.rexster.config;
+
+import com.tinkerpop.blueprints.Graph;
+import com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraph;
+import com.tinkerpop.rexster.config.GraphConfiguration;
+import org.apache.commons.configuration.Configuration;
+
+
+public class RamCloudGraphConfiguration implements GraphConfiguration {
+
+ public Graph configureGraphInstance(final Configuration properties) throws GraphConfigurationException {
+ return new RamCloudGraph("fast+udp:host=127.0.0.1,port=12246");
+ }
+
+}
diff --git a/src/main/java/edu/stanford/ramcloud/JRamCloud.java b/src/main/java/edu/stanford/ramcloud/JRamCloud.java
new file mode 100755
index 0000000..fef2b12
--- /dev/null
+++ b/src/main/java/edu/stanford/ramcloud/JRamCloud.java
@@ -0,0 +1,430 @@
+/* Copyright (c) 2013 Stanford University
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package edu.stanford.ramcloud;
+
+/*
+ * This class provides Java bindings for RAMCloud. Right now it is a rather
+ * simple subset of what RamCloud.h defines.
+ *
+ * Running ``javah'' on this file will generate a C header file with the
+ * appropriate JNI function definitions. The glue interfacing to the C++
+ * RAMCloud library can be found in JRamCloud.cc.
+ *
+ * For JNI information, the IBM tutorials and Android developer docs are much
+ * better than Sun's at giving an overall intro:
+ * http://www.ibm.com/developerworks/java/tutorials/j-jni/section4.html
+ * http://developer.android.com/training/articles/perf-jni.html
+ */
+public class JRamCloud {
+ static {
+ System.loadLibrary("edu_stanford_ramcloud_JRamCloud");
+ }
+
+ /// Pointer to the underlying C++ RAMCloud object associated with this
+ /// object.
+ private long ramcloudObjectPointer = 0;
+
+ /**
+ * See src/RejectRules.h.
+ */
+ public class RejectRules {
+ private long givenVersion;
+ private boolean doesntExist;
+ private boolean exists;
+ private boolean versionLeGiven;
+ private boolean versionNeGiven;
+
+ public RejectRules() {
+ this.givenVersion = -1;
+ this.exists = this.doesntExist = this.versionLeGiven = this.versionNeGiven = false;
+ }
+
+ public void setLeVersion(long version) {
+ setVersion(version);
+ this.versionLeGiven = true;
+ }
+
+ public void setExists() {
+ this.exists = true;
+ }
+
+ public void setDoesntExists() {
+ this.doesntExist = true;
+ }
+
+ public void setNeVersion(long version) {
+ setVersion(version);
+ this.versionNeGiven = true;
+ }
+
+ private void setVersion(long version) {
+ this.givenVersion = version;
+ }
+ }
+
+ public static class multiReadObject {
+ long tableId;
+ byte[] key;
+
+ public multiReadObject(long _tableId, byte[] _key){
+ tableId = _tableId;
+ key = _key;
+ }
+ }
+
+ public static class MultiWriteObject {
+ long tableId;
+ byte[] key;
+ byte[] value;
+ RejectRules rules;
+
+ public MultiWriteObject(long tableId, byte[] key, byte[] value, RejectRules rules) {
+ this.tableId = tableId;
+ this.key = key;
+ this.value = value;
+ this.rules = rules;
+ }
+ }
+
+ public class MultiWriteRspObject {
+ private int status;
+ private long version;
+
+ public MultiWriteRspObject(int status, long version) {
+ this.status = status;
+ this.version = version;
+ }
+ public int getStatus() {
+ return status;
+ }
+
+ public long getVersion() {
+ return version;
+ }
+ }
+
+ /**
+ * This class is returned by Read operations. It encapsulates the entire
+ * object, including the key, value, and version.
+ *
+ * It mostly exists because Java doesn't support primitive out parameters
+ * or multiple return values, and we don't know the object's size ahead of
+ * time, so passing in a fixed-length array would be problematic.
+ */
+ public class Object {
+ Object(byte[] _key, byte[] _value, long _version)
+ {
+ key = _key;
+ value = _value;
+ version = _version;
+ }
+
+ public String
+ getKey()
+ {
+ return new String(key);
+ }
+
+ public String
+ getValue()
+ {
+ return new String(value);
+ }
+
+ final public byte[] key;
+ final public byte[] value;
+ final public long version;
+ }
+
+ public class TableEnumerator {
+ private long tableEnumeratorObjectPointer = 0;
+ private long ramCloudObjectPointer = 0;
+
+ public TableEnumerator(long tableId)
+ {
+ ramCloudObjectPointer = ramcloudObjectPointer;
+ tableEnumeratorObjectPointer = init(tableId);
+ }
+
+ private native long init(long tableId);
+ public native boolean hasNext();
+ public native Object next();
+ }
+
+ /**
+ * Connect to the RAMCloud cluster specified by the given coordinator's
+ * service locator string. This causes the JNI code to instantiate the
+ * underlying RamCloud C++ object.
+ */
+ public
+ JRamCloud(String coordinatorLocator)
+ {
+ ramcloudObjectPointer = connect(coordinatorLocator);
+ }
+
+ /**
+ * Disconnect from the RAMCloud cluster. This causes the JNI code to
+ * destroy the underlying RamCloud C++ object.
+ */
+ public void
+ disconnect()
+ {
+ if (ramcloudObjectPointer != 0) {
+ disconnect(ramcloudObjectPointer);
+ ramcloudObjectPointer = 0;
+ }
+ }
+
+ /**
+ * This method is called by the garbage collector before destroying the
+ * object. The user really should have called disconnect, but in case
+ * they did not, be sure to clean up after them.
+ */
+ public void
+ finalize()
+ {
+ System.err.println("warning: JRamCloud::disconnect() was not called " +
+ "prior to the finalizer. You should disconnect " +
+ "your JRamCloud object when you're done with it.");
+ disconnect();
+ }
+
+ /**
+ * Convenience read() wrapper that take a String key argument.
+ */
+ public Object
+ read(long tableId, String key)
+ {
+ return read(tableId, key.getBytes());
+ }
+
+ /**
+ * Convenience read() wrapper that take a String key argument.
+ */
+ public Object
+ read(long tableId, String key, RejectRules rules)
+ {
+ return read(tableId, key.getBytes(), rules);
+ }
+
+ /**
+ * Convenience remove() wrapper that take a String key argument.
+ */
+ public long
+ remove(long tableId, String key)
+ {
+ return remove(tableId, key.getBytes());
+ }
+
+ /**
+ * Convenience remove() wrapper that take a String key argument.
+ */
+ public long
+ remove(long tableId, String key, RejectRules rules)
+ {
+ return remove(tableId, key.getBytes(), rules);
+ }
+
+ /**
+ * Convenience write() wrapper that take String key and value arguments.
+ */
+ public long
+ write(long tableId, String key, String value)
+ {
+ return write(tableId, key.getBytes(), value.getBytes());
+ }
+
+ /**
+ * Convenience write() wrapper that take String key and value arguments.
+ */
+ public long
+ write(long tableId, String key, String value, RejectRules rules)
+ {
+ return write(tableId, key.getBytes(), value.getBytes(), rules);
+ }
+
+ /**
+ * Convenience write() wrapper that takes a String key and a byte[] value
+ * argument.
+ */
+ public long
+ write(long tableId, String key, byte[] value)
+ {
+ return write(tableId, key.getBytes(), value);
+ }
+
+ /**
+ * Convenience write() wrapper that takes a String key and a byte[] value
+ * argument.
+ */
+ public long
+ write(long tableId, String key, byte[] value, RejectRules rules)
+ {
+ return write(tableId, key.getBytes(), value, rules);
+ }
+
+ private static native long connect(String coordinatorLocator);
+ private static native void disconnect(long ramcloudObjectPointer);
+
+ public native long createTable(String name);
+ public native long createTable(String name, int serverSpan);
+ public native void dropTable(String name);
+ public native long getTableId(String name);
+ public native Object read(long tableId, byte[] key);
+ public native Object read(long tableId, byte[] key, RejectRules rules);
+ public native Object[] multiRead(multiReadObject[] mread);
+ public native long remove(long tableId, byte[] key);
+ public native long remove(long tableId, byte[] key, RejectRules rules);
+ public native long write(long tableId, byte[] key, byte[] value);
+ public native long write(long tableId, byte[] key, byte[] value, RejectRules rules);
+ public native long writeRule(long tableId, byte[] key, byte[] value, RejectRules rules);
+ public native MultiWriteRspObject[] multiWrite(MultiWriteObject[] mwrite);
+
+ /*
+ * The following exceptions may be thrown by the JNI functions:
+ */
+
+ public class TableDoesntExistException extends Exception {
+ public TableDoesntExistException(String message)
+ {
+ super(message);
+ }
+ }
+
+ public class ObjectDoesntExistException extends Exception {
+ public ObjectDoesntExistException(String message)
+ {
+ super(message);
+ }
+ }
+
+ public class ObjectExistsException extends Exception {
+ public ObjectExistsException(String message)
+ {
+ super(message);
+ }
+ }
+
+ public class WrongVersionException extends Exception {
+ public WrongVersionException(String message)
+ {
+ super(message);
+ }
+ }
+
+ public class InvalidObjectException extends Exception {
+ public InvalidObjectException(String message) {
+ super(message);
+ }
+ }
+
+ public class RejectRulesException extends Exception {
+ public RejectRulesException(String message) {
+ super(message);
+ }
+ }
+
+ /**
+ * A simple end-to-end test of the java bindings.
+ */
+ public static void
+ main(String argv[])
+ {
+ JRamCloud ramcloud = new JRamCloud(argv[0]);
+ long tableId = ramcloud.createTable("hi");
+ System.out.println("created table, id = " + tableId);
+ long tableId2 = ramcloud.getTableId("hi");
+ System.out.println("getTableId says tableId = " + tableId2);
+
+ System.out.println("wrote obj version = " +
+ ramcloud.write(tableId, "thisIsTheKey", "thisIsTheValue"));
+
+ JRamCloud.Object o = ramcloud.read(tableId, "thisIsTheKey");
+ System.out.println("read object: key = [" + o.getKey() + "], value = ["
+ + o.getValue() + "], version = " + o.version);
+
+ ramcloud.remove(tableId, "thisIsTheKey");
+
+ try {
+ ramcloud.read(tableId, "thisIsTheKey");
+ System.out.println("Error: shouldn't have read successfully!");
+ } catch (Exception e) {
+ // OK
+ }
+
+ ramcloud.write(tableId, "thisIsTheKey", "thisIsTheValue");
+
+ long before = System.nanoTime();
+ for (int i = 0; i < 1000; i++) {
+ JRamCloud.Object unused = ramcloud.read(tableId, "thisIsTheKey");
+ }
+ long after = System.nanoTime();
+ System.out.println("Avg read latency: " +
+ ((double)(after - before) / 1000 / 1000) + " usec");
+
+ // multiRead test
+ long tableId4 = ramcloud.createTable("table4");
+ System.out.println("table4 id " + tableId4);
+ ramcloud.write(tableId4, "object1-1", "value:1-1");
+ ramcloud.write(tableId4, "object1-2", "value:1-2");
+ ramcloud.write(tableId4, "object1-3", "value:1-3");
+ long tableId5 = ramcloud.createTable("table5");
+ System.out.println("table5 id " + tableId5);
+ ramcloud.write(tableId5, "object2-1", "value:2-1");
+ long tableId6 = ramcloud.createTable("table6");
+ ramcloud.write(tableId6, "object3-1", "value:3-1");
+ ramcloud.write(tableId6, "object3-2", "value:3-2");
+
+ multiReadObject mread[] = new multiReadObject[2];
+ //for (int k = 0; k < 2000; k++) {
+ mread[0] = new multiReadObject(tableId4, "object1-1".getBytes());
+ mread[1] = new multiReadObject(tableId5, "object2-1".getBytes());
+ JRamCloud.Object out[] = ramcloud.multiRead(mread);
+ for (int i = 0 ; i < 2 ; i++){
+ System.out.println("multi read object: key = [" + out[i].getKey() + "], value = ["
+ + out[i].getValue() + "]");
+ //}
+ }
+ MultiWriteObject mwrite[] = new MultiWriteObject[2];
+ for (int i = 0; i < 1000; i++) {
+ String key1 = "key1" + new Integer(i).toString();
+ String key2 = "key2" + new Integer(i).toString();
+
+ mwrite[0] = new MultiWriteObject(tableId4, key1.getBytes(), "v0-value".getBytes(), null);
+ mwrite[1] = new MultiWriteObject(tableId5, key2.getBytes(), "v1".getBytes(), null);
+ MultiWriteRspObject[] rsp = ramcloud.multiWrite(mwrite);
+ if (rsp != null) {
+ for (int j = 0; j < rsp.length; j++) {
+ System.out.println("multi write rsp(" + j + ") status:version " + rsp[j].getStatus() + ":" + rsp[j].getVersion());
+ }
+ }
+ }
+ for (int i = 0; i < 1000; i++) {
+ String key1 = "key1" + new Integer(i).toString();
+ String key2 = "key2" + new Integer(i).toString();
+ mread[0] = new multiReadObject(tableId4, key1.getBytes());
+ mread[1] = new multiReadObject(tableId5, key2.getBytes());
+ out = ramcloud.multiRead(mread);
+ for (int j = 0; j < 2; j++) {
+ System.out.println("multi read object: key = [" + out[j].getKey() + "], value = [" + out[j].getValue() + "]");
+ }
+ }
+ ramcloud.dropTable("table4");
+ ramcloud.dropTable("table5");
+ ramcloud.dropTable("table6");
+ ramcloud.disconnect();
+ }
+}
diff --git a/src/main/java/net/onrc/onos/datagrid/HazelcastDatagrid.java b/src/main/java/net/onrc/onos/datagrid/HazelcastDatagrid.java
index 45995bf..13a0157 100644
--- a/src/main/java/net/onrc/onos/datagrid/HazelcastDatagrid.java
+++ b/src/main/java/net/onrc/onos/datagrid/HazelcastDatagrid.java
@@ -19,8 +19,10 @@
import net.onrc.onos.datagrid.web.DatagridWebRoutable;
import net.onrc.onos.ofcontroller.flowmanager.IFlowEventHandlerService;
import net.onrc.onos.ofcontroller.flowmanager.PerformanceMonitor.Measurement;
-import net.onrc.onos.ofcontroller.proxyarp.ArpMessage;
-import net.onrc.onos.ofcontroller.proxyarp.IArpEventHandler;
+import net.onrc.onos.ofcontroller.proxyarp.ArpReplyNotification;
+import net.onrc.onos.ofcontroller.proxyarp.IArpReplyEventHandler;
+import net.onrc.onos.ofcontroller.proxyarp.IPacketOutEventHandler;
+import net.onrc.onos.ofcontroller.proxyarp.PacketOutNotification;
import net.onrc.onos.ofcontroller.topology.TopologyElement;
import net.onrc.onos.ofcontroller.util.Dpid;
import net.onrc.onos.ofcontroller.util.FlowEntry;
@@ -33,9 +35,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.esotericsoftware.kryo2.Kryo;
-import com.esotericsoftware.kryo2.io.Input;
-import com.esotericsoftware.kryo2.io.Output;
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
import com.hazelcast.config.Config;
import com.hazelcast.config.FileSystemXmlConfig;
import com.hazelcast.core.EntryEvent;
@@ -96,12 +98,18 @@
private MapTopologyListener mapTopologyListener = null;
private String mapTopologyListenerId = null;
- // State related to the ARP map
- protected static final String arpMapName = "arpMap";
- private IMap<ArpMessage, byte[]> arpMap = null;
- private List<IArpEventHandler> arpEventHandlers = new ArrayList<IArpEventHandler>();
+ // State related to the packet out map
+ protected static final String packetOutMapName = "packetOutMap";
+ private IMap<PacketOutNotification, byte[]> packetOutMap = null;
+ private List<IPacketOutEventHandler> packetOutEventHandlers = new ArrayList<IPacketOutEventHandler>();
+
private final byte[] dummyByte = {0};
+ // State related to the ARP reply map
+ protected static final String arpReplyMapName = "arpReplyMap";
+ private IMap<ArpReplyNotification, byte[]> arpReplyMap = null;
+ private List<IArpReplyEventHandler> arpReplyEventHandlers = new ArrayList<IArpReplyEventHandler>();
+
/**
* Class for receiving notifications for Flow state.
*
@@ -502,35 +510,23 @@
}
/**
- * Class for receiving notifications for ARP requests.
+ * Class for receiving notifications for sending packet-outs.
*
* The datagrid map is:
- * - Key: Request ID (String)
- * - Value: ARP request packet (byte[])
+ * - Key: Packet-out to send (PacketOutNotification)
+ * - Value: dummy value (we only need the key) (byte[])
*/
- class ArpMapListener implements EntryListener<ArpMessage, byte[]> {
+ class PacketOutMapListener implements EntryListener<PacketOutNotification, byte[]> {
/**
* Receive a notification that an entry is added.
*
* @param event the notification event for the entry.
*/
@Override
- public void entryAdded(EntryEvent<ArpMessage, byte[]> event) {
- for (IArpEventHandler arpEventHandler : arpEventHandlers) {
- arpEventHandler.arpRequestNotification(event.getKey());
+ public void entryAdded(EntryEvent<PacketOutNotification, byte[]> event) {
+ for (IPacketOutEventHandler packetOutEventHandler : packetOutEventHandlers) {
+ packetOutEventHandler.packetOutNotification(event.getKey());
}
-
- //
- // Decode the value and deliver the notification
- //
- /*
- Kryo kryo = kryoFactory.newKryo();
- Input input = new Input(valueBytes);
- TopologyElement topologyElement =
- kryo.readObject(input, TopologyElement.class);
- kryoFactory.deleteKryo(kryo);
- flowEventHandlerService.notificationRecvTopologyElementAdded(topologyElement);
- */
}
/**
@@ -539,7 +535,7 @@
* @param event the notification event for the entry.
*/
@Override
- public void entryRemoved(EntryEvent<ArpMessage, byte[]> event) {
+ public void entryRemoved(EntryEvent<PacketOutNotification, byte[]> event) {
// Not used
}
@@ -549,7 +545,7 @@
* @param event the notification event for the entry.
*/
@Override
- public void entryUpdated(EntryEvent<ArpMessage, byte[]> event) {
+ public void entryUpdated(EntryEvent<PacketOutNotification, byte[]> event) {
// Not used
}
@@ -559,12 +555,41 @@
* @param event the notification event for the entry.
*/
@Override
- public void entryEvicted(EntryEvent<ArpMessage, byte[]> event) {
+ public void entryEvicted(EntryEvent<PacketOutNotification, byte[]> event) {
// Not used
}
}
/**
+ * Class for receiving notifications for sending packet-outs.
+ *
+ * The datagrid map is:
+ * - Key: Packet-out to send (PacketOutNotification)
+ * - Value: dummy value (we only need the key) (byte[])
+ */
+ class ArpReplyMapListener implements EntryListener<ArpReplyNotification, byte[]> {
+ /**
+ * Receive a notification that an entry is added.
+ *
+ * @param event the notification event for the entry.
+ */
+ @Override
+ public void entryAdded(EntryEvent<ArpReplyNotification, byte[]> event) {
+ for (IArpReplyEventHandler arpReplyEventHandler : arpReplyEventHandlers) {
+ arpReplyEventHandler.arpReplyEvent(event.getKey());
+ }
+ }
+
+ // These methods aren't used for ARP replies
+ @Override
+ public void entryRemoved(EntryEvent<ArpReplyNotification, byte[]> event) {}
+ @Override
+ public void entryUpdated(EntryEvent<ArpReplyNotification, byte[]> event) {}
+ @Override
+ public void entryEvicted(EntryEvent<ArpReplyNotification, byte[]> event) {}
+ }
+
+ /**
* Initialize the Hazelcast Datagrid operation.
*
* @param conf the configuration filename.
@@ -680,8 +705,11 @@
restApi.addRestletRoutable(new DatagridWebRoutable());
- arpMap = hazelcastInstance.getMap(arpMapName);
- arpMap.addEntryListener(new ArpMapListener(), true);
+ packetOutMap = hazelcastInstance.getMap(packetOutMapName);
+ packetOutMap.addEntryListener(new PacketOutMapListener(), true);
+
+ arpReplyMap = hazelcastInstance.getMap(arpReplyMapName);
+ arpReplyMap.addEntryListener(new ArpReplyMapListener(), true);
}
/**
@@ -762,15 +790,27 @@
}
@Override
- public void registerArpEventHandler(IArpEventHandler arpEventHandler) {
- if (arpEventHandler != null) {
- arpEventHandlers.add(arpEventHandler);
+ public void registerPacketOutEventHandler(IPacketOutEventHandler packetOutEventHandler) {
+ if (packetOutEventHandler != null) {
+ packetOutEventHandlers.add(packetOutEventHandler);
}
}
@Override
- public void deregisterArpEventHandler(IArpEventHandler arpEventHandler) {
- arpEventHandlers.remove(arpEventHandler);
+ public void deregisterPacketOutEventHandler(IPacketOutEventHandler packetOutEventHandler) {
+ packetOutEventHandlers.remove(packetOutEventHandler);
+ }
+
+ @Override
+ public void registerArpReplyEventHandler(IArpReplyEventHandler arpReplyEventHandler) {
+ if (arpReplyEventHandler != null) {
+ arpReplyEventHandlers.add(arpReplyEventHandler);
+ }
+ }
+
+ @Override
+ public void deregisterArpReplyEventHandler(IArpReplyEventHandler arpReplyEventHandler) {
+ arpReplyEventHandlers.remove(arpReplyEventHandler);
}
/**
@@ -1317,8 +1357,12 @@
}
@Override
- public void sendArpRequest(ArpMessage arpMessage) {
- //log.debug("ARP bytes: {}", HexString.toHexString(arpRequest));
- arpMap.putAsync(arpMessage, dummyByte, 1L, TimeUnit.MILLISECONDS);
+ public void sendPacketOutNotification(PacketOutNotification packetOutNotification) {
+ packetOutMap.putAsync(packetOutNotification, dummyByte, 1L, TimeUnit.MILLISECONDS);
}
+
+ @Override
+ public void sendArpReplyNotification(ArpReplyNotification arpReply) {
+ arpReplyMap.putAsync(arpReply, dummyByte, 1L, TimeUnit.MILLISECONDS);
+ }
}
diff --git a/src/main/java/net/onrc/onos/datagrid/IDatagridService.java b/src/main/java/net/onrc/onos/datagrid/IDatagridService.java
index a855798..80d1781 100644
--- a/src/main/java/net/onrc/onos/datagrid/IDatagridService.java
+++ b/src/main/java/net/onrc/onos/datagrid/IDatagridService.java
@@ -4,8 +4,10 @@
import net.floodlightcontroller.core.module.IFloodlightService;
import net.onrc.onos.ofcontroller.flowmanager.IFlowEventHandlerService;
-import net.onrc.onos.ofcontroller.proxyarp.ArpMessage;
-import net.onrc.onos.ofcontroller.proxyarp.IArpEventHandler;
+import net.onrc.onos.ofcontroller.proxyarp.ArpReplyNotification;
+import net.onrc.onos.ofcontroller.proxyarp.IArpReplyEventHandler;
+import net.onrc.onos.ofcontroller.proxyarp.IPacketOutEventHandler;
+import net.onrc.onos.ofcontroller.proxyarp.PacketOutNotification;
import net.onrc.onos.ofcontroller.topology.TopologyElement;
import net.onrc.onos.ofcontroller.util.Dpid;
import net.onrc.onos.ofcontroller.util.FlowEntry;
@@ -40,18 +42,32 @@
void deregisterFlowEventHandlerService(IFlowEventHandlerService flowEventHandlerService);
/**
- * Register event handler for ARP events.
+ * Register event handler for packet-out events.
*
- * @param arpEventHandler The ARP event handler to register.
+ * @param packetOutEventHandler The packet-out event handler to register.
*/
- public void registerArpEventHandler(IArpEventHandler arpEventHandler);
+ public void registerPacketOutEventHandler(IPacketOutEventHandler packetOutEventHandler);
/**
- * De-register event handler service for ARP events.
+ * Deregister event handler service for packet-out events.
*
- * @param arpEventHandler The ARP event handler to de-register.
+ * @param packetOutEventHandler The packet-out event handler to deregister.
*/
- public void deregisterArpEventHandler(IArpEventHandler arpEventHandler);
+ public void deregisterPacketOutEventHandler(IPacketOutEventHandler packetOutEventHandler);
+
+ /**
+ * Register event handler for ARP reply events.
+ *
+ * @param packetOutEventHandler The ARP reply event handler to register.
+ */
+ public void registerArpReplyEventHandler(IArpReplyEventHandler arpReplyEventHandler);
+
+ /**
+ * Deregister event handler service for ARP reply events.
+ *
+ * @param packetOutEventHandler The ARP reply event handler to deregister.
+ */
+ public void deregisterArpReplyEventHandler(IArpReplyEventHandler arpReplyEventHandler);
/**
* Get all Flows that are currently in the datagrid.
@@ -240,8 +256,21 @@
void notificationSendAllTopologyElementsRemoved();
/**
- * Send an ARP request to other ONOS instances
- * @param arpRequest The request packet to send
+ * Send a packet-out notification to other ONOS instances. This informs
+ * other instances that they should send this packet out some of the ports
+ * they control. Not all notifications are applicable to all instances
+ * (i.e. some notifications specify a single port to send the packet out),
+ * so each instance must determine whether it needs to take action when it
+ * receives the notification.
+ *
+ * @param packetOutNotification The packet notification to send
*/
- public void sendArpRequest(ArpMessage arpMessage);
+ public void sendPacketOutNotification(PacketOutNotification packetOutNotification);
+
+ /**
+ * Send notification to other ONOS instances that an ARP reply has been
+ * received.
+ * @param arpReply The notification of the ARP reply
+ */
+ public void sendArpReplyNotification(ArpReplyNotification arpReply);
}
diff --git a/src/main/java/net/onrc/onos/graph/GraphDBConnection.java b/src/main/java/net/onrc/onos/graph/GraphDBConnection.java
index 16869c5..b504c4b 100644
--- a/src/main/java/net/onrc/onos/graph/GraphDBConnection.java
+++ b/src/main/java/net/onrc/onos/graph/GraphDBConnection.java
@@ -11,6 +11,8 @@
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.util.wrappers.event.EventTransactionalGraph;
import com.tinkerpop.frames.FramedGraph;
+import com.tinkerpop.frames.FramedGraphFactory;
+import com.tinkerpop.frames.modules.gremlingroovy.GremlinGroovyModule;
public class GraphDBConnection implements IDBConnection {
public enum Transaction {
@@ -33,6 +35,7 @@
.getLogger(GraphDBConnection.class);
private static GraphDBConnection singleton = new GraphDBConnection();
private static TitanGraph graph;
+ private static FramedGraphFactory factory;
private static FramedGraph<TitanGraph> fg;
private static EventTransactionalGraph<TitanGraph> eg;
private static String configFile;
@@ -86,7 +89,9 @@
graph.createKeyIndex("ipv4_address", Vertex.class);
}
graph.commit();
- fg = new FramedGraph<TitanGraph>(graph);
+ // Make sure you reuse the factory when creating new framed graphs
+ factory = new FramedGraphFactory(new GremlinGroovyModule());
+ fg = factory.create(graph);
eg = new EventTransactionalGraph<TitanGraph>(graph);
}
return singleton;
@@ -97,7 +102,12 @@
*/
@Override
public FramedGraph<TitanGraph> getFramedGraph() {
- return fg;
+ if (isValid()) {
+ return fg;
+ } else {
+ log.error("New FramedGraph failed");
+ return null;
+ }
}
/**
diff --git a/src/main/java/net/onrc/onos/graph/LocalTopologyEventListener.java b/src/main/java/net/onrc/onos/graph/LocalTopologyEventListener.java
index 27de2c0..72227d5 100644
--- a/src/main/java/net/onrc/onos/graph/LocalTopologyEventListener.java
+++ b/src/main/java/net/onrc/onos/graph/LocalTopologyEventListener.java
@@ -11,16 +11,14 @@
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex;
-import com.tinkerpop.blueprints.impls.ramcloud.*;
-import java.util.Map;
public class LocalTopologyEventListener implements LocalGraphChangedListener {
-
+
protected final static Logger log = LoggerFactory.getLogger(LocalTopologyEventListener.class);
protected static DBConnection conn;
-
+
public LocalTopologyEventListener(DBConnection conn) {
- LocalTopologyEventListener.conn = conn;
+ LocalTopologyEventListener.conn = conn;
}
@Override
@@ -38,8 +36,7 @@
}
@Override
- //public void edgeRemoved(Edge e, Map<String, Object> arg1) {
- public void edgeRemoved(Edge e) {
+ public void edgeRemoved(Edge e, Map<String, Object> arg1) {
// TODO Auto-generated method stub
// Fire NetMapEvents (LinkRemoved, FlowEntryRemoved, HostRemoved, PortRemoved)
TitanEdge edge = (TitanEdge) e;
@@ -77,15 +74,14 @@
}
@Override
- //public void vertexRemoved(Vertex vertex, Map<String, Object> arg1) {
- public void vertexRemoved(Vertex vertex) {
+ public void vertexRemoved(Vertex vertex, Map<String, Object> arg1) {
// TODO Auto-generated method stub
- // Generate NetMapEvents
+ // Generate NetMapEvents
String type = (String) vertex.getProperty("type");
log.debug("TopologyEvents: Received vertex removed event: {}",vertex);
if (type.equals("port")) {
// port is removed...lets fire reconcile here directly for now
-
+
IPortObject src_port = (IPortObject) conn.getFramedGraph().frame(vertex, IPortObject.class);
log.debug("TopologyEvents: Port removed: {}:{}",src_port.getSwitch().getDPID(),src_port.getNumber());
@@ -101,21 +97,14 @@
public void edgePropertyChanged(Edge arg0, String arg1, Object arg2,
Object arg3) {
// TODO Auto-generated method stub
-
+
}
@Override
public void vertexPropertyChanged(Vertex arg0, String arg1, Object arg2,
Object arg3) {
// TODO Auto-generated method stub
-
+
}
- public void vertexRemoved(Vertex vertex, Map<String, Object> props) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
-
- public void edgeRemoved(Edge edge, Map<String, Object> props) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
}
diff --git a/src/main/java/net/onrc/onos/graph/RamCloudDBConnection.java b/src/main/java/net/onrc/onos/graph/RamCloudDBConnection.java
index 17067b4..547da44 100644
--- a/src/main/java/net/onrc/onos/graph/RamCloudDBConnection.java
+++ b/src/main/java/net/onrc/onos/graph/RamCloudDBConnection.java
@@ -24,15 +24,9 @@
private FramedGraph<RamCloudGraph> fg;
private static Logger log = LoggerFactory.getLogger(RamCloudDBConnection.class);
- //private static final ThreadLocal<RamCloudGraph> RamCloudThreadLocal = new ThreadLocal<RamCloudGraph>();
-
public RamCloudDBConnection(final String dbConfigFile) {
- //final String coordinatorURL = open(getConfiguration(new File(dbConfigFile)));
- //System.out.println("coordinatorURL "+ coordinatorURL);
- //graph = new RamCloudGraph(coordinatorURL);
- //graph = RamCloudThreadLocal.get();
- //System.out.println("ThreadId = " + Thread.currentThread().getId() + " graph = " + graph);
- graph = new RamCloudGraph("fast+udp:host=10.0.0.144,port=12246");
+ final String coordinatorURL = open(getConfiguration(new File(dbConfigFile)));
+ graph = new RamCloudGraph(coordinatorURL);
Set<String> s = graph.getIndexedKeys(Vertex.class);
if (!s.contains("dpid")) {
graph.createKeyIndex("dpid", Vertex.class);
@@ -120,11 +114,13 @@
}
}
- private String open(final Configuration configuration) {
- final String coordinatorURL = configuration.getString("ramcloud.coordinator", null);
- if (coordinatorURL == null) {
- throw new RuntimeException("Configuration must contain a valid 'coordinatorURL' setting");
- }
- return coordinatorURL;
- }
+ private String open(final Configuration configuration) {
+ final String coordinatorIp = configuration.getString("ramcloud.coordinatorIp", null);
+ final String coordinatorPort = configuration.getString("ramcloud.coordinatorPort", null);
+ final String coordinatorURL = coordinatorIp + "," + coordinatorPort;
+ if (coordinatorURL == null) {
+ throw new RuntimeException("Configuration must contain a valid 'coordinatorURL' setting");
+ }
+ return coordinatorURL;
+ }
}
diff --git a/src/main/java/net/onrc/onos/graph/web/TopoDevicesResource.java b/src/main/java/net/onrc/onos/graph/web/TopoDevicesResource.java
index 10e250e..4f4abba 100644
--- a/src/main/java/net/onrc/onos/graph/web/TopoDevicesResource.java
+++ b/src/main/java/net/onrc/onos/graph/web/TopoDevicesResource.java
@@ -13,7 +13,7 @@
@Get("json")
public Iterator<IDeviceObject> retrieve() {
- DBOperation op = GraphDBManager.getDBOperation("ramcloud", "/tmp/ramcloudconf");
+ DBOperation op = GraphDBManager.getDBOperation("ramcloud", "/tmp/ramcloud.conf");
return op.getDevices().iterator();
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/bgproute/BgpRoute.java b/src/main/java/net/onrc/onos/ofcontroller/bgproute/BgpRoute.java
index 3ff6058..4f6c310 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/bgproute/BgpRoute.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/bgproute/BgpRoute.java
@@ -41,7 +41,6 @@
import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryService;
import net.onrc.onos.ofcontroller.proxyarp.BgpProxyArpManager;
import net.onrc.onos.ofcontroller.proxyarp.IArpRequester;
-import net.onrc.onos.ofcontroller.proxyarp.IProxyArpService;
import net.onrc.onos.ofcontroller.topology.ITopologyNetService;
import net.onrc.onos.ofcontroller.topology.Topology;
import net.onrc.onos.ofcontroller.topology.TopologyManager;
@@ -78,8 +77,7 @@
public class BgpRoute implements IFloodlightModule, IBgpRouteService,
ITopologyListener, IArpRequester,
- IOFSwitchListener, IConfigInfoService,
- IProxyArpService {
+ IOFSwitchListener, IConfigInfoService {
private final static Logger log = LoggerFactory.getLogger(BgpRoute.class);
@@ -1019,12 +1017,12 @@
}
OFMatch matchLLDP = new OFMatch();
- matchLLDP.setDataLayerType((short)0x8942);
+ matchLLDP.setDataLayerType((short)0x88cc);
matchLLDP.setWildcards(matchLLDP.getWildcards() & ~ OFMatch.OFPFW_DL_TYPE);
fmLLDP.setMatch(matchLLDP);
OFMatch matchBDDP = new OFMatch();
- matchBDDP.setDataLayerType((short)0x88cc);
+ matchBDDP.setDataLayerType((short)0x8942);
matchBDDP.setWildcards(matchBDDP.getWildcards() & ~ OFMatch.OFPFW_DL_TYPE);
fmBDDP.setMatch(matchBDDP);
@@ -1287,27 +1285,4 @@
public short getVlan() {
return vlan;
}
-
- /*
- * TODO This is a hack to get the REST API to work for ProxyArpManager.
- * The REST API is currently tied to the Floodlight module system and we
- * need to separate it to allow ONOS modules to use it. For now we will
- * proxy calls through to the ProxyArpManager (which is not a Floodlight
- * module) through this class which is a module.
- */
- @Override
- public MACAddress getMacAddress(InetAddress ipAddress) {
- return proxyArp.getMacAddress(ipAddress);
- }
-
- @Override
- public void sendArpRequest(InetAddress ipAddress, IArpRequester requester,
- boolean retry) {
- proxyArp.sendArpRequest(ipAddress, requester, retry);
- }
-
- @Override
- public List<String> getMappings() {
- return proxyArp.getMappings();
- }
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/bgproute/RestClient.java b/src/main/java/net/onrc/onos/ofcontroller/bgproute/RestClient.java
index a9f2abe..9606d24 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/bgproute/RestClient.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/bgproute/RestClient.java
@@ -35,7 +35,7 @@
log.warn("The content received from {} is not json", str);
}
- BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
+ BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
String line;
while ((line = br.readLine()) != null) {
response.append(line);
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java b/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
index 8dd2f16..36729a6 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
@@ -40,7 +40,7 @@
public boolean deactivateSwitch(String dpid);
/*
* Update the port details
- */
+ */
public boolean updatePort(String dpid, short port, int state, String desc);
/*
* Associate a port on switch
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/internal/DeviceStorageImpl.java b/src/main/java/net/onrc/onos/ofcontroller/core/internal/DeviceStorageImpl.java
index ddc7527..6fcbb29 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/internal/DeviceStorageImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/internal/DeviceStorageImpl.java
@@ -25,7 +25,6 @@
import com.thinkaurelius.titan.core.TitanException;
/**
* This is the class for storing the information of devices into CassandraDB
- *
* @author Pankaj
*/
public class DeviceStorageImpl implements IDeviceStorage {
@@ -39,10 +38,9 @@
@Override
public void init(final String dbStore, final String conf) {
try {
- ope = GraphDBManager.getDBOperation("ramcloud", "/tmp/ramcloudconf");
- //ope = GraphDBManager.getDBOperation(dbStore, conf);
+ ope = GraphDBManager.getDBOperation("ramcloud", "/tmp/ramcloud.conf");
} catch (Exception e) {
- log.error(e.getMessage());
+ log.error("Couldn't open graph operation", e);
}
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImpl.java b/src/main/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImpl.java
index 37ab9fb..b43c58a 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImpl.java
@@ -33,8 +33,7 @@
*/
@Override
public void init(final String dbStore, final String conf) {
- //this.dbop = GraphDBManager.getDBOperation(dbStore, conf);
- this.dbop = GraphDBManager.getDBOperation("ramcloud", "/tmp/ramcloudconf");
+ this.dbop = GraphDBManager.getDBOperation("ramcloud", "/tmp/ramcloud.conf");
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java b/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java
index 0dcf4297..ab73961 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java
@@ -38,8 +38,7 @@
*/
@Override
public void init(final String dbStore, final String conf) {
- op = GraphDBManager.getDBOperation("ramcloud", "/tmp/ramcloudconf");
- //op = GraphDBManager.getDBOperation(dbStore, conf);
+ op = GraphDBManager.getDBOperation("ramcloud", "/tmp/ramcloud.conf");
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/internal/TopoLinkServiceImpl.java b/src/main/java/net/onrc/onos/ofcontroller/core/internal/TopoLinkServiceImpl.java
index 24392df..99a2eb1 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/internal/TopoLinkServiceImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/internal/TopoLinkServiceImpl.java
@@ -77,7 +77,7 @@
}
- private class ExtractLink implements PipeFunction<PathPipe<Vertex>, Link> {
+ private static class ExtractLink implements PipeFunction<PathPipe<Vertex>, Link> {
@Override
public Link compute(PathPipe<Vertex> pipe) {
long s_dpid = 0;
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/internal/TopoSwitchServiceImpl.java b/src/main/java/net/onrc/onos/ofcontroller/core/internal/TopoSwitchServiceImpl.java
index f417d96..df5ab70 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/internal/TopoSwitchServiceImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/internal/TopoSwitchServiceImpl.java
@@ -15,8 +15,7 @@
protected final static Logger log = LoggerFactory.getLogger(TopoSwitchServiceImpl.class);
public TopoSwitchServiceImpl(final String dbStore, String conf) {
- op = GraphDBManager.getDBOperation("ramcloud", "/tmp/ramcloudconf");
- //op = GraphDBManager.getDBOperation(dbStore, conf);;
+ op = GraphDBManager.getDBOperation("ramcloud", "/tmp/ramcloud.conf");
}
public TopoSwitchServiceImpl() {
diff --git a/src/main/java/net/onrc/onos/ofcontroller/floodlightlistener/NetworkGraphPublisher.java b/src/main/java/net/onrc/onos/ofcontroller/floodlightlistener/NetworkGraphPublisher.java
index 0d352f8..98b80e6 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/floodlightlistener/NetworkGraphPublisher.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/floodlightlistener/NetworkGraphPublisher.java
@@ -20,6 +20,7 @@
import net.floodlightcontroller.devicemanager.IDeviceListener;
import net.floodlightcontroller.routing.Link;
import net.floodlightcontroller.threadpool.IThreadPoolService;
+import net.floodlightcontroller.util.MACAddress;
import net.onrc.onos.graph.DBOperation;
import net.onrc.onos.graph.DBConnection;
import net.onrc.onos.graph.GraphDBManager;
@@ -38,7 +39,7 @@
import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryListener;
import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryService;
import net.onrc.onos.ofcontroller.linkdiscovery.LinkInfo;
-import net.onrc.onos.ofcontroller.proxyarp.ArpMessage;
+import net.onrc.onos.ofcontroller.proxyarp.ArpReplyNotification;
import net.onrc.onos.ofcontroller.topology.TopologyElement;
import net.onrc.onos.registry.controller.IControllerRegistryService;
import net.onrc.onos.registry.controller.IControllerRegistryService.ControlChangeCallback;
@@ -67,7 +68,7 @@
//protected IDeviceService deviceService;
protected IControllerRegistryService registryService;
protected DBOperation op;
-
+
protected static final String DBConfigFile = "dbconf";
protected static final String GraphDBStore = "graph_db_store";
protected static final String CleanupEnabled = "EnableCleanup";
@@ -90,7 +91,7 @@
Thread.currentThread().setName("SwitchCleanup@" + old);
try {
log.debug("Running cleanup thread");
- op = GraphDBManager.getDBOperation("ramcloud", "/tmp/ramcloudconf");
+ op = GraphDBManager.getDBOperation("ramcloud", "/tmp/ramcloud.conf");
switchCleanup();
}
catch (Exception e) {
@@ -396,8 +397,9 @@
log.debug("{}:deviceAdded(): Adding device {}",this.getClass(),device.getMACAddressString());
devStore.addDevice(device);
for (int intIpv4Address : device.getIPv4Addresses()) {
- datagridService.sendArpRequest(
- ArpMessage.newReply(InetAddresses.fromInteger(intIpv4Address)));
+ datagridService.sendArpReplyNotification(new ArpReplyNotification(
+ InetAddresses.fromInteger(intIpv4Address),
+ MACAddress.valueOf(device.getMACAddress())));
}
}
@@ -458,13 +460,11 @@
Map<String, String> configMap = context.getConfigParams(this);
String conf = configMap.get(DBConfigFile);
String dbStore = configMap.get(GraphDBStore);
- System.out.println("conf" + conf + "dbStore" + dbStore);
- op = GraphDBManager.getDBOperation("ramcloud", "/tmp/ramcloudconf");
- //op = GraphDBManager.getDBOperation(dbStore, conf);
+ op = GraphDBManager.getDBOperation("ramcloud", "/tmp/ramcloud.conf");
if (op == null) {
System.out.println("publisher op is null");
}
-
+
floodlightProvider =
context.getServiceImpl(IFloodlightProviderService.class);
//deviceService = context.getServiceImpl(IDeviceService.class);
@@ -475,13 +475,13 @@
devStore = new DeviceStorageImpl();
devStore.init(dbStore, conf);
-
+
swStore = new SwitchStorageImpl();
swStore.init(dbStore, conf);
-
+
linkStore = new LinkStorageImpl();
linkStore.init(dbStore, conf);
-
+
log.debug("Initializing NetworkGraphPublisher module with {}", conf);
}
@@ -496,10 +496,9 @@
linkDiscovery.addListener(this);
log.debug("Adding EventListener");
- System.out.println("start Up op " + op);
IDBConnection conn = op.getDBConnection();
conn.addEventListener(new LocalTopologyEventListener((DBConnection) conn));
- // Setup the Cleanup task.
+ // Setup the Cleanup task.
if (cleanupNeeded == null || !cleanupNeeded.equals("False")) {
ScheduledExecutorService ses = threadPool.getScheduledExecutor();
cleanupTask = new SingletonTask(ses, new SwitchCleanup());
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/ApplnObjectType.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/ApplnObjectType.java
new file mode 100644
index 0000000..8cb1316
--- /dev/null
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/ApplnObjectType.java
@@ -0,0 +1,16 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package net.onrc.onos.ofcontroller.flowmanager;
+
+/**
+ *
+ * @author nickkaranatsios
+ */
+public enum ApplnObjectType {
+ FLOWPATH,
+ FLOWENTRY,
+ UNKNOWN
+}
+
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/DBOperationType.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/DBOperationType.java
new file mode 100644
index 0000000..e0de595
--- /dev/null
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/DBOperationType.java
@@ -0,0 +1,18 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package net.onrc.onos.ofcontroller.flowmanager;
+
+/**
+ *
+ * @author nickkaranatsios
+ */
+public enum DBOperationType {
+ ADD,
+ UPDATE,
+ QUERY,
+ REMOVE,
+ INVALID
+}
+
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowDatabaseOperation.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowDatabaseOperation.java
old mode 100644
new mode 100755
index c75657b..d8e50fc
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowDatabaseOperation.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowDatabaseOperation.java
@@ -1,5 +1,6 @@
package net.onrc.onos.ofcontroller.flowmanager;
+import com.tinkerpop.blueprints.Direction;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
@@ -32,6 +33,257 @@
private static final boolean measureONOSFlowEntryTimeProp = Long.valueOf(System.getProperty("benchmark.measureONOSFlowEntry", "0")) != 0;
/**
+ * Add a flow by batching all flow path properties and flow entries together.
+ * This is done for performance reasons.
+ *
+ * @param dbHandler the Graph Database handler to use.
+ * @param flowPath the Flow Path to install.
+ * @return true on success, otherwise false.
+ */
+ static boolean addFlowFast(DBOperation dbHandler, FlowPath flowPath) {
+ IFlowPath flowPathObj;
+ FlowPathProperty flowProp = new FlowPathProperty();
+ FlowEntity flowPathEntity = new FlowEntity();
+ boolean flowPathUpdate = false;
+
+ flowPathObj = dbHandler.searchFlowPath(flowPath.flowId()); // getVertices("flow_id")
+ if (flowPathObj == null) {
+ try {
+ flowPathEntity.operationBegin(DBOperationType.ADD.toString());
+ flowPathObj = dbHandler.newFlowPath();
+ } catch (Exception e) {
+ flowPathObj = null;
+ StringWriter sw = new StringWriter();
+ e.printStackTrace(new PrintWriter(sw));
+ log.error(":addFlow FlowId:{} failed: {}", flowPath.flowId(), sw.toString());
+ }
+ flowPathEntity.setProperty("user_state", "FP_USER_ADD");
+ flowProp.setFlowPathUserState("FP_USER_ADD");
+ } else {
+ flowPathUpdate = true;
+ // Remove the old Flow Entries (this is special for RAMCloud)
+ for (IFlowEntry flowEntryObj : flowPathObj.getFlowEntries()) { // get.@Adjacency("flow", IN)
+ flowPathEntity.operationBegin(DBOperationType.REMOVE.toString());
+ dbHandler.removeFlowEntry(flowEntryObj); // removeVertex()
+ flowPathEntity.operationEnd(DBOperationType.REMOVE.toString());
+ }
+ flowPathEntity.operationBegin(DBOperationType.UPDATE.toString());
+ flowPathEntity.setProperty("user_state", "FP_USER_ADD");
+ flowProp.setFlowPathUserState("FP_USER_MODIFY");
+ }
+ if (flowPathObj == null) {
+ log.error(":addFlow FlowId:{} failed: Flow object not created", flowPath.flowId());
+ dbHandler.rollback();
+ return false;
+ }
+
+ flowPathEntity.setProperty("flow_id", flowPath.flowId().toString());
+ // Set the Flow key
+ flowProp.setFlowId(flowPath.flowId().toString());
+
+ // Set the Flow attributes
+ flowPathEntity.setProperty("installer_id", flowPath.installerId().toString());
+ flowProp.setInstallerId(flowPath.installerId().toString());
+
+ flowPathEntity.setProperty("flow_path_type", flowPath.flowPathType().toString());
+ flowProp.setFlowPathType(flowPath.flowPathType().toString());
+
+ flowPathEntity.setProperty("user_state", flowPath.flowPathUserState().toString());
+ flowProp.setFlowPathUserState(flowPath.flowPathUserState().toString());
+
+
+ flowPathEntity.setProperty("flow_path_flags", flowPath.flowPathFlags().flags());
+ flowProp.setFlowPathFlags(flowPath.flowPathFlags().flags());
+
+ flowPathEntity.setProperty("idle_timeout", flowPath.idleTimeout());
+ flowProp.setIdleTimeout(flowPath.idleTimeout());
+
+ flowPathEntity.setProperty("hard_timeout", flowPath.hardTimeout());
+ flowProp.setHardTimeout(flowPath.hardTimeout());
+
+ flowPathEntity.setProperty("src_switch", flowPath.dataPath().srcPort().dpid().toString());
+ flowProp.setSrcSwitch(flowPath.dataPath().srcPort().dpid().toString());
+
+ flowPathEntity.setProperty("src_port", flowPath.dataPath().srcPort().port().value());
+ flowProp.setSrcPort(flowPath.dataPath().srcPort().port().value());
+
+ flowPathEntity.setProperty("dst_switch", flowPath.dataPath().dstPort().dpid().toString());
+ flowProp.setDstSwitch(flowPath.dataPath().dstPort().dpid().toString());
+
+ flowPathEntity.setProperty("dst_port", flowPath.dataPath().dstPort().port().value());
+ flowProp.setDstPort(flowPath.dataPath().dstPort().port().value());
+
+ if (flowPath.flowEntryMatch().matchSrcMac()) {
+ flowPathEntity.setProperty("matchSrcMac",flowPath.flowEntryMatch().srcMac().toString());
+ flowProp.setMatchSrcMac(flowPath.flowEntryMatch().srcMac().toString());
+ }
+ if (flowPath.flowEntryMatch().matchDstMac()) {
+ flowPathEntity.setProperty("matchDstMac", flowPath.flowEntryMatch().dstMac().toString());
+ flowProp.setMatchDstMac(flowPath.flowEntryMatch().dstMac().toString());
+ }
+ if (flowPath.flowEntryMatch().matchEthernetFrameType()) {
+ flowPathEntity.setProperty("matchEthernetFrameType", flowPath.flowEntryMatch().ethernetFrameType());
+ flowProp.setMatchEthernetFrameType(flowPath.flowEntryMatch().ethernetFrameType());
+ }
+ if (flowPath.flowEntryMatch().matchVlanId()) {
+ flowPathEntity.setProperty("matchVlanId", flowPath.flowEntryMatch().vlanId());
+ flowProp.setMatchVlanId(flowPath.flowEntryMatch().vlanId());
+ }
+ if (flowPath.flowEntryMatch().matchVlanPriority()) {
+ flowPathEntity.setProperty("matchVlanPriority", flowPath.flowEntryMatch().vlanPriority());
+ flowProp.setMatchVlanPriority(flowPath.flowEntryMatch().vlanPriority());
+ }
+ if (flowPath.flowEntryMatch().matchSrcIPv4Net()) {
+ flowPathEntity.setProperty("matchSrcIPv4Net", flowPath.flowEntryMatch().srcIPv4Net().toString());
+ flowProp.setMatchSrcIPv4Net(flowPath.flowEntryMatch().srcIPv4Net().toString());
+ }
+ if (flowPath.flowEntryMatch().matchDstIPv4Net()) {
+ flowPathEntity.setProperty("matchDstIPv4Net", flowPath.flowEntryMatch().dstIPv4Net().toString());
+ flowProp.setMatchDstIPv4Net(flowPath.flowEntryMatch().dstIPv4Net().toString());
+ }
+ if (flowPath.flowEntryMatch().matchIpProto()) {
+ flowPathEntity.setProperty("matchIpProto", flowPath.flowEntryMatch().ipProto());
+ flowProp.setMatchIpProto(flowPath.flowEntryMatch().ipProto());
+ }
+ if (flowPath.flowEntryMatch().matchIpToS()) {
+ flowPathEntity.setProperty("matchIpToS", flowPath.flowEntryMatch().ipToS());
+ flowProp.setMatchIpToS(flowPath.flowEntryMatch().ipToS());
+ }
+ if (flowPath.flowEntryMatch().matchSrcTcpUdpPort()) {
+ flowPathEntity.setProperty("matchSrcTcpUdpPort", flowPath.flowEntryMatch().srcTcpUdpPort());
+ flowProp.setMatchSrcTcpUdpPort(flowPath.flowEntryMatch().srcTcpUdpPort());
+ }
+ if (flowPath.flowEntryMatch().matchDstTcpUdpPort()) {
+ flowPathEntity.setProperty("matchDstTcpUdpPort", flowPath.flowEntryMatch().dstTcpUdpPort());
+ flowProp.setMatchDstTcpUdpPort(flowPath.flowEntryMatch().dstTcpUdpPort());
+ }
+ if (! flowPath.flowEntryActions().actions().isEmpty()) {
+ flowPathEntity.setProperty("actions", flowPath.flowEntryActions().toString());
+ flowProp.setActions(flowPath.flowEntryActions().toString());
+ }
+ flowPathEntity.setProperty("data_path_summary", flowPath.dataPath().dataPathSummary());
+ flowProp.setDataPathSummary(flowPath.dataPath().dataPathSummary());
+
+ flowProp.commitProperties(dbHandler, flowPathObj);
+
+ //
+ // Flow Entries:
+ // flowPath.dataPath().flowEntries()
+ //
+ for (FlowEntry flowEntry : flowPath.dataPath().flowEntries()) {
+ if (flowEntry.flowEntryUserState() == FlowEntryUserState.FE_USER_DELETE)
+ continue; // Skip: all Flow Entries were deleted earlier
+
+ IFlowEntry iFlowEntry;
+ FlowEntryProperty flowEntryProp = new FlowEntryProperty();
+ FlowEntity flowEntryEntity = new FlowEntity();
+ boolean updateFlowEntry = false;
+
+ try {
+ iFlowEntry = dbHandler.searchFlowEntry(flowEntry.flowEntryId()); // getVertices()
+ if (iFlowEntry != null) {
+ updateFlowEntry = true;
+ flowEntryEntity.operationBegin(DBOperationType.UPDATE.toString());
+ flowEntryEntity.setProperty("user_state", "FE_USER_MODIFY");
+ flowEntryProp.setUserState("FE_USER_MODIFY");
+ } else {
+ flowEntryEntity.operationBegin(DBOperationType.ADD.toString());
+ flowEntryEntity.setProperty("user_state", "FE_USER_ADD");
+ flowEntryProp.setUserState("FE_USER_ADD");
+ flowEntryEntity.addEdge(flowPathObj, Direction.OUT, "flow");
+ }
+ } catch (Exception e) {
+ // TODO do we really need to catch this exception.
+ }
+
+ flowEntryEntity.setProperty("flow_id", flowEntry.flowEntryId().toString());
+ // Set the Flow Entry key
+ flowEntryEntity.setProperty("flow_entry_id", flowEntry.flowEntryId().toString());
+
+ flowEntryEntity.setProperty("type", "flow_entry");
+
+ // Set the Flow Entry Edges
+ ISwitchObject sw = dbHandler.searchSwitch(flowEntry.dpid().toString()); // toshi memo: getVertices()
+
+ flowEntryEntity.setProperty("idle_timeout", flowEntry.idleTimeout());
+
+ flowEntryEntity.setProperty("hard_timeout", flowEntry.hardTimeout());
+
+ flowEntryEntity.setProperty("switch_dpid", flowEntry.dpid().toString());
+
+ flowEntryEntity.addEdge(sw, Direction.OUT, "switch");
+ if (flowEntry.flowEntryMatch().matchInPort()) {
+ IPortObject inport = dbHandler.searchPort(flowEntry.dpid().toString(), flowEntry.flowEntryMatch().inPort().value()); // toshi memo: getVertices()
+
+ flowEntryEntity.setProperty("matchInPort", flowEntry.flowEntryMatch().inPort().value());
+ flowEntryEntity.addEdge(inport, Direction.OUT, "inport");
+ }
+
+ // Set the Flow Entry attributes
+ if (flowEntry.flowEntryMatch().matchSrcMac()) {
+ flowEntryEntity.setProperty("matchSrcMac", flowEntry.flowEntryMatch().srcMac().toString());
+ }
+ if (flowEntry.flowEntryMatch().matchDstMac()) {
+ flowEntryEntity.setProperty("matchDstMac", flowEntry.flowEntryMatch().dstMac().toString());
+ }
+ if (flowEntry.flowEntryMatch().matchEthernetFrameType()) {
+ flowEntryEntity.setProperty("matchEthernetFrameType", flowEntry.flowEntryMatch().ethernetFrameType());
+ }
+ if (flowEntry.flowEntryMatch().matchVlanId()) {
+ flowEntryEntity.setProperty("matchVlanId", flowEntry.flowEntryMatch().vlanId());
+ }
+ if (flowEntry.flowEntryMatch().matchVlanPriority()) {
+ flowEntryEntity.setProperty("matchVlanPriority", flowEntry.flowEntryMatch().vlanPriority());
+ }
+ if (flowEntry.flowEntryMatch().matchSrcIPv4Net()) {
+ flowEntryEntity.setProperty("matchSrcIPv4Net", flowEntry.flowEntryMatch().srcIPv4Net().toString());
+ }
+ if (flowEntry.flowEntryMatch().matchDstIPv4Net()) {
+ flowEntryEntity.setProperty("matchDstIPv4Net", flowEntry.flowEntryMatch().dstIPv4Net().toString());
+ }
+ if (flowEntry.flowEntryMatch().matchIpProto()) {
+ flowEntryEntity.setProperty("matchIpProto", flowEntry.flowEntryMatch().ipProto());
+ }
+ if (flowEntry.flowEntryMatch().matchIpToS()) {
+ flowEntryEntity.setProperty("matchIpToS", flowEntry.flowEntryMatch().ipToS());
+ }
+ if (flowEntry.flowEntryMatch().matchSrcTcpUdpPort()) {
+ flowEntryEntity.setProperty("matchSrcTcpUdpPort", flowEntry.flowEntryMatch().srcTcpUdpPort());
+ }
+ if (flowEntry.flowEntryMatch().matchDstTcpUdpPort()) {
+ flowEntryEntity.setProperty("matchDstTcpUdpPort", flowEntry.flowEntryMatch().dstTcpUdpPort());
+ }
+
+ for (FlowEntryAction fa : flowEntry.flowEntryActions().actions()) {
+ if (fa.actionOutput() != null) {
+ IPortObject outport = dbHandler.searchPort(flowEntry.dpid().toString(), fa.actionOutput().port().value()); // toshi memo: getVertices()
+ flowEntryEntity.setProperty("actionOutputPort", fa.actionOutput().port().value());
+ flowEntryEntity.addEdge(outport, Direction.OUT, "outport");
+ }
+ }
+ if (! flowEntry.flowEntryActions().isEmpty()) {
+ flowEntryEntity.setProperty("actions", flowEntry.flowEntryActions().toString());
+ }
+
+ flowEntryEntity.setProperty("switch_state", flowEntry.flowEntrySwitchState().toString());
+ if (updateFlowEntry) {
+ flowEntryEntity.operationEnd(DBOperationType.UPDATE.toString());
+ } else {
+ flowEntryEntity.operationEnd(DBOperationType.ADD.toString());
+ }
+ flowPathEntity.append(flowEntryEntity);
+ }
+
+ if (flowPathUpdate) {
+ flowPathEntity.operationEnd(DBOperationType.UPDATE.toString());
+ } else {
+ flowPathEntity.operationEnd(DBOperationType.ADD.toString());
+ }
+ flowPathEntity.persist(dbHandler);
+ return true;
+ }
+
+ /**
* Add a flow.
*
* @param dbHandler the Graph Database handler to use.
@@ -39,311 +291,11 @@
* @return true on success, otherwise false.
*/
static boolean addFlow(DBOperation dbHandler, FlowPath flowPath) {
- IFlowPath flowObj = null;
- boolean found = false;
- long startAddFlow = 0;
- long endAddFlow = 0;
- long endSearchExistingFlowPathTime = 0;
- long startCreateNewFlowPathTime = 0;
- long endCreateNewFlowPathTime = 0;
- long startFollowExistingFlowEntries = 0;
- long endFollowExistingFlowEntries = 0;
- long accTimeRemovingFlowEntriesFromFlowPath = 0;
- long accTimeRemovingFlowEntriesFromDB = 0;
- long startSettingFlowPathProps = 0;
- long endSettingFlowPathProps = 0;
- int numPropsSet = 0;
- long accTimeAddFlowEntries = 0;
- int numNewFlowEntries = 0;
- LinkedList<long[]> flowEntryTimes = new LinkedList<>();
- PerfMon pm = PerfMon.getInstance();
-
- pm.addflowpath_start();
- try {
- if ( measureONOSFlowTimeProp ) {
- startAddFlow = System.nanoTime();
- }
- flowObj = dbHandler.searchFlowPath(flowPath.flowId());
- if ( measureONOSFlowTimeProp ) {
- endSearchExistingFlowPathTime = System.nanoTime();
- }
- if (flowObj != null) {
- found = true;
- } else {
- if ( measureONOSFlowTimeProp ) {
- startCreateNewFlowPathTime = System.nanoTime();
- }
- flowObj = dbHandler.newFlowPath();
- if ( measureONOSFlowTimeProp ) {
- endCreateNewFlowPathTime = System.nanoTime();
- }
- }
- } catch (Exception e) {
- dbHandler.rollback();
-
- StringWriter sw = new StringWriter();
- e.printStackTrace(new PrintWriter(sw));
- String stacktrace = sw.toString();
-
- log.error(":addFlow FlowId:{} failed: {}",
- flowPath.flowId(),
- stacktrace);
- return false;
- }
- if (flowObj == null) {
- log.error(":addFlow FlowId:{} failed: Flow object not created",
- flowPath.flowId());
- dbHandler.rollback();
- return false;
- }
-
- //
- // Remove the old Flow Entries
- //
- if (found) {
- if ( measureONOSFlowTimeProp ) {
- startFollowExistingFlowEntries = System.nanoTime();
- }
- Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries();
- if ( measureONOSFlowTimeProp ) {
- endFollowExistingFlowEntries = System.nanoTime();
- }
- LinkedList<IFlowEntry> deleteFlowEntries =
- new LinkedList<IFlowEntry>();
- for (IFlowEntry flowEntryObj : flowEntries)
- deleteFlowEntries.add(flowEntryObj);
- if( measureONOSFlowTimeProp ) {
- for (IFlowEntry flowEntryObj : deleteFlowEntries) {
- long start = System.nanoTime();
- flowObj.removeFlowEntry(flowEntryObj);
- accTimeRemovingFlowEntriesFromFlowPath += System.nanoTime() - start;
- start = System.nanoTime();
- dbHandler.removeFlowEntry(flowEntryObj);
- accTimeRemovingFlowEntriesFromDB += System.nanoTime() - start;
- }
- } else {
- for (IFlowEntry flowEntryObj : deleteFlowEntries) {
- flowObj.removeFlowEntry(flowEntryObj);
- dbHandler.removeFlowEntry(flowEntryObj);
- }
- }
- }
-
- if ( measureONOSFlowTimeProp ) {
- startSettingFlowPathProps = System.nanoTime();
- }
-
- FlowPathProperty flowProp = new FlowPathProperty(dbHandler, flowObj);
-
- //
- // Set the Flow key:
- // - flowId
- //
- flowProp.setFlowId(flowPath.flowId().toString());
- if ( measureONOSFlowTimeProp ) {
- numPropsSet += 1;
- }
-
- //
- // Set the Flow attributes:
- // - flowPath.installerId()
- // - flowPath.flowPathType()
- // - flowPath.flowPathUserState()
- // - flowPath.flowPathFlags()
- // - flowPath.idleTimeout()
- // - flowPath.hardTimeout()
- // - flowPath.dataPath().srcPort()
- // - flowPath.dataPath().dstPort()
- // - flowPath.matchSrcMac()
- // - flowPath.matchDstMac()
- // - flowPath.matchEthernetFrameType()
- // - flowPath.matchVlanId()
- // - flowPath.matchVlanPriority()
- // - flowPath.matchSrcIPv4Net()
- // - flowPath.matchDstIPv4Net()
- // - flowPath.matchIpProto()
- // - flowPath.matchIpToS()
- // - flowPath.matchSrcTcpUdpPort()
- // - flowPath.matchDstTcpUdpPort()
- // - flowPath.flowEntryActions()
- //
- flowProp.setInstallerId(flowPath.installerId().toString());
- flowProp.setFlowPathType(flowPath.flowPathType().toString());
- flowProp.setFlowPathUserState(flowPath.flowPathUserState().toString());
- flowProp.setFlowPathFlags(flowPath.flowPathFlags().flags());
- flowProp.setIdleTimeout(flowPath.idleTimeout());
- flowProp.setHardTimeout(flowPath.hardTimeout());
- flowProp.setSrcSwitch(flowPath.dataPath().srcPort().dpid().toString());
- flowProp.setSrcPort(flowPath.dataPath().srcPort().port().value());
- flowProp.setDstSwitch(flowPath.dataPath().dstPort().dpid().toString());
- flowProp.setDstPort(flowPath.dataPath().dstPort().port().value());
- if ( measureONOSFlowTimeProp ) {
- numPropsSet += 10;
- }
-
- if (flowPath.flowEntryMatch().matchSrcMac()) {
- flowProp.setMatchSrcMac(flowPath.flowEntryMatch().srcMac().toString());
- if ( measureONOSFlowTimeProp ) {
- ++numPropsSet;
- }
- }
- if (flowPath.flowEntryMatch().matchDstMac()) {
- flowProp.setMatchDstMac(flowPath.flowEntryMatch().dstMac().toString());
- if ( measureONOSFlowTimeProp ) {
- ++numPropsSet;
- }
- }
- if (flowPath.flowEntryMatch().matchEthernetFrameType()) {
- flowProp.setMatchEthernetFrameType(flowPath.flowEntryMatch().ethernetFrameType());
- if ( measureONOSFlowTimeProp ) {
- ++numPropsSet;
- }
- }
- if (flowPath.flowEntryMatch().matchVlanId()) {
- flowProp.setMatchVlanId(flowPath.flowEntryMatch().vlanId());
- if ( measureONOSFlowTimeProp ) {
- ++numPropsSet;
- }
- }
- if (flowPath.flowEntryMatch().matchVlanPriority()) {
- flowProp.setMatchVlanPriority(flowPath.flowEntryMatch().vlanPriority());
- if ( measureONOSFlowTimeProp ) {
- ++numPropsSet;
- }
- }
- if (flowPath.flowEntryMatch().matchSrcIPv4Net()) {
- flowProp.setMatchSrcIPv4Net(flowPath.flowEntryMatch().srcIPv4Net().toString());
- if ( measureONOSFlowTimeProp ) {
- ++numPropsSet;
- }
- }
- if (flowPath.flowEntryMatch().matchDstIPv4Net()) {
- flowProp.setMatchDstIPv4Net(flowPath.flowEntryMatch().dstIPv4Net().toString());
- if ( measureONOSFlowTimeProp ) {
- ++numPropsSet;
- }
- }
- if (flowPath.flowEntryMatch().matchIpProto()) {
- flowProp.setMatchIpProto(flowPath.flowEntryMatch().ipProto());
- if ( measureONOSFlowTimeProp ) {
- ++numPropsSet;
- }
- }
- if (flowPath.flowEntryMatch().matchIpToS()) {
- flowProp.setMatchIpToS(flowPath.flowEntryMatch().ipToS());
- if ( measureONOSFlowTimeProp ) {
- ++numPropsSet;
- }
- }
- if (flowPath.flowEntryMatch().matchSrcTcpUdpPort()) {
- flowProp.setMatchSrcTcpUdpPort(flowPath.flowEntryMatch().srcTcpUdpPort());
- if ( measureONOSFlowTimeProp ) {
- ++numPropsSet;
- }
- }
- if (flowPath.flowEntryMatch().matchDstTcpUdpPort()) {
- flowProp.setMatchDstTcpUdpPort(flowPath.flowEntryMatch().dstTcpUdpPort());
- if ( measureONOSFlowTimeProp ) {
- ++numPropsSet;
- }
- }
- if (! flowPath.flowEntryActions().actions().isEmpty()) {
- flowProp.setActions(flowPath.flowEntryActions().toString());
- if ( measureONOSFlowTimeProp ) {
- ++numPropsSet;
- }
- }
- flowProp.setDataPathSummary(flowPath.dataPath().dataPathSummary());
- if ( measureONOSFlowTimeProp ) {
- ++numPropsSet;
- }
-
- if (found)
- flowProp.setFlowPathUserState("FP_USER_MODIFY");
- else
- flowProp.setFlowPathUserState("FP_USER_ADD");
-
- flowProp.commitProperties();
-
- if ( measureONOSFlowTimeProp ) {
- ++numPropsSet;
- }
-
- if ( measureONOSFlowTimeProp ) {
- endSettingFlowPathProps = System.nanoTime();
- }
- pm.addflowpath_end();
- // Flow edges:
- // HeadFE
-
-
- //
- // Flow Entries:
- // flowPath.dataPath().flowEntries()
- //
- pm.addflowentry_start();
- for (FlowEntry flowEntry : flowPath.dataPath().flowEntries()) {
- if (flowEntry.flowEntryUserState() == FlowEntryUserState.FE_USER_DELETE)
- continue; // Skip: all Flow Entries were deleted earlier
-
- pm.addflowentry_incr();
-
- long startAddFlowEntry = 0, endAddFlowEntry;
- if( measureONOSFlowTimeProp ) {
- startAddFlowEntry = System.nanoTime();
- }
- IFlowEntry iFlowEntry = addFlowEntry(dbHandler, flowObj, flowEntry);
- if( measureONOSFlowTimeProp ) {
- endAddFlowEntry = System.nanoTime();
- accTimeAddFlowEntries += endAddFlowEntry - startAddFlowEntry;
-
- flowEntryTimes.addLast( new long[]{flowEntry.flowId().value(), endAddFlowEntry - startAddFlowEntry} );
- }
- if ( iFlowEntry == null) {
- dbHandler.rollback();
- return false;
- }
- }
- pm.addflowentry_end();
- dbHandler.commit();
-
-
- if ( measureONOSFlowTimeProp ) {
- endAddFlow = System.nanoTime();
-
- log.error("Performance addFlow(_,{}) -- "
- + "GrandTotal: {} "
- + "only FlowPathTotal: {} "
- + "searchExistingFlowPath: {} "
- + "createNewFlowPathTime: {}"
- + "followExistingFlowEntries: {} "
- + "accTimeRemovingFlowEntriesFromFlowPath: {} "
- + "accTimeRemovingFlowEntriesFromDB: {} "
- + "settingFlowPathProps: {} #Props: {} "
- + "accFlowEntries: {} #FEs: {}",
- flowPath.flowId(),
- (endAddFlow - startAddFlow),
- (endSettingFlowPathProps - startAddFlow),
- (endSearchExistingFlowPathTime - startAddFlow),
- (endCreateNewFlowPathTime - startCreateNewFlowPathTime),
- (endFollowExistingFlowEntries - startFollowExistingFlowEntries),
- (accTimeRemovingFlowEntriesFromFlowPath),
- (accTimeRemovingFlowEntriesFromDB),
- (endSettingFlowPathProps - startSettingFlowPathProps), numPropsSet,
- accTimeAddFlowEntries, numNewFlowEntries
- );
-
- // Each FlowEntries
- final String strFlowId = flowPath.flowId().toString();
- for ( long[] idFE_Time : flowEntryTimes ) {
- log.error("Performance addFlowEntry(_,{},{})@addFlow -- FlowEntryTotal: {}",
- strFlowId,
- "0x" + Long.toHexString(idFE_Time[0]),
- idFE_Time[1]);
- }
- }
-
- return true;
+ PerfMon pm = PerfMon.getInstance();
+ pm.addflowpath_start();
+ boolean retValue = addFlowFast(dbHandler, flowPath);
+ pm.addflowpath_end();
+ return retValue;
}
/**
@@ -429,7 +381,7 @@
startSetProperties = System.nanoTime();
}
- FlowEntryProperty flowProp = new FlowEntryProperty(dbHandler, flowEntryObj);
+ FlowEntryProperty flowProp = new FlowEntryProperty();
//
// Set the Flow Entry key:
@@ -620,7 +572,7 @@
if (measureONOSFlowEntryTimeProp) {
numProperties += 2;
}
- flowProp.commitProperties();
+ flowProp.commitProperties(dbHandler, flowEntryObj);
//
// TODO: Take care of the FlowEntryErrorState.
//
@@ -635,7 +587,7 @@
if (measureONOSFlowEntryTimeProp) {
startAddEdgeBetweenFlowPath = System.nanoTime();
}
- flowObj.addFlowEntry(flowEntryObj);
+ //flowObj.addFlowEntry(flowEntryObj);
flowEntryObj.setFlow(flowObj);
if (measureONOSFlowEntryTimeProp) {
endAddEdgeBetweenFlowPath = System.nanoTime();
@@ -723,6 +675,7 @@
for (IFlowPath flowPathObj : allFlowPaths) {
if (flowPathObj == null)
continue;
+
deleteIFlowPath(dbHandler, flowPathObj);
}
dbHandler.commit();
@@ -754,10 +707,15 @@
deleteIFlowPath(dbHandler, flowObj);
dbHandler.commit();
-
return true;
}
+ /**
+ * Delete a previously added flow.
+ * @note You need to call commit after calling this method.
+ * @param dbHandler the Graph Database handler to use.
+ * @param flowObj IFlowPath object to delete.
+ */
private static void deleteIFlowPath(DBOperation dbHandler, IFlowPath flowObj) {
//
// Remove all Flow Entries
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEntity.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEntity.java
new file mode 100644
index 0000000..ff890b6
--- /dev/null
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEntity.java
@@ -0,0 +1,252 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package net.onrc.onos.ofcontroller.flowmanager;
+
+import com.tinkerpop.blueprints.Direction;
+import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.blueprints.Edge;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import net.onrc.onos.graph.DBOperation;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IBaseObject;
+import com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraph;
+import com.tinkerpop.blueprints.impls.ramcloud.RamCloudVertex;
+import java.util.List;
+import java.util.Set;
+
+/**
+ *
+ * @author nickkaranatsios
+ */
+public class FlowEntity implements FlowEntityManager {
+ private String primaryKey;
+ // TODO: Should remove since not implemented.
+ private Class<?> hasMany;
+ private Collection<?> many = new ArrayList<>();
+ private Map<String, Object> properties;
+ private Map<String, Map<String, Object>> operations = new HashMap<>();
+ private ArrayList<Object> children = new ArrayList<>();
+ private ArrayList<Object> edges = new ArrayList<>();
+ private int opCount;
+ public Direction dir;
+
+ public FlowEntity() {
+ opCount = 0;
+ }
+
+ private class EntityEdge {
+ private Object src;
+ private Object dst;
+ private Direction dir;
+ private String label;
+ private DBOperationType op;
+
+ public EntityEdge(Object src, Object dst, DBOperationType op, Direction dir, String label) {
+ this.src = src;
+ this.dst = dst;
+ this.dir = dir;
+ this.label = label;
+ this.op = op;
+ }
+
+ public EntityEdge(Object src, Object dst, String label) {
+ this.src = src;
+ this.dst = dst;
+ this.label = label;
+ }
+
+ @Override
+ public String toString() {
+ return "EntityEdge: " + src + " " + dst + " " + label;
+ }
+ }
+
+ private class RamCloudEdgeEntity implements Edge {
+ private Vertex src;
+ private Vertex dst;
+ private Direction direction;
+ private String label;
+
+ public RamCloudEdgeEntity(Vertex src, Vertex dst, Direction direction, String label) {
+ this.src = src;
+ this.dst = dst;
+ this.direction = direction;
+ this.label = label;
+ }
+
+ @Override
+ public Vertex getVertex(com.tinkerpop.blueprints.Direction dir) throws IllegalArgumentException {
+ if (dir == Direction.IN) {
+ return dst;
+ } else if (dir == Direction.OUT) {
+ return src;
+ }
+ return null;
+ }
+
+ @Override
+ public String getLabel() {
+ return this.label;
+ }
+
+ @Override
+ public <T> T getProperty(String key) {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public Set<String> getPropertyKeys() {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public void setProperty(String key, Object value) {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public <T> T removeProperty(String key) {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public Object getId() {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ }
+
+ @Override
+ public void setPrimaryKey(String key) {
+ primaryKey = key;
+ }
+
+ @Override
+ public String getPrimaryKey() {
+ return primaryKey;
+ }
+
+ @Override
+ public void hasMany(Class<?> cClass) {
+ hasMany = cClass;
+ }
+
+ @Override
+ public void operationBegin(String opName) {
+ properties = new HashMap<>();
+ operations.put(getOpKey(opName), properties);
+ opCount++;
+ }
+
+ @Override
+ public void operationEnd(String opName) {
+ // TODO: This method is implemented in case we need to reset any variables.
+ /*
+ String opKey = getOpKey(opName);
+ if (operations.containsKey(opKey)) {
+ System.out.println(operations);
+ }
+ */
+ }
+
+
+ private String getOpKey(String opName) {
+ return opName + new Integer(opCount).toString();
+
+ }
+
+ @Override
+ public void setProperty(String propertyName, Object value) {
+ properties.put(propertyName, value);
+ }
+
+ @Override
+ public FlowEntityManager append(Object entity) {
+ children.add(entity);
+ return this;
+ }
+
+ @Override
+ public Object getProperty(String propertyName) {
+ if (properties.containsKey(propertyName)) {
+ return properties.get(propertyName);
+ }
+ return null;
+ }
+
+ @Override
+ public void persist(DBOperation dbHandler) {
+ // get a hold of all the flow entries for the current flowpath.
+ if (children.size() > 0) {
+ int noOfChildren = children.size();
+ if (noOfChildren > 0) {
+ // construct a list of null ids for creating vertices for all
+ // flow entries.
+ ArrayList<Object> ids = new ArrayList<>(noOfChildren);
+ // set properties
+ Map<RamCloudVertex, Map<String, Object>> propertiesToSet = new HashMap<>();
+
+ RamCloudGraph graph = (RamCloudGraph)dbHandler.getDBConnection().getFramedGraph().getBaseGraph();
+ for (int i = 0; i < noOfChildren; i++) {
+ ids.add(null);
+ }
+ List<RamCloudVertex> addedVertices = graph.addVertices(ids);
+ //Iterable<Vertex> vertices = dbHandler.setVertices(ids);
+ //Iterator vi = vertices.iterator();
+ // get source and destination edge match vertex v construct list
+ // of edges
+ ArrayList<Edge> edgesToSet = new ArrayList<>();
+ for (int i = 0; i < noOfChildren; i++) {
+ FlowEntity childEntity = (FlowEntity)children.get(i);
+ Vertex srcVertex = addedVertices.get(i);
+ propertiesToSet.put((RamCloudVertex)srcVertex, childEntity.properties);
+
+ if (srcVertex == null) continue;
+ for (int j = 0; j < childEntity.edges.size(); j++) {
+ EntityEdge edge = (EntityEdge) childEntity.edges.get(j);
+ edgesToSet.add(new RamCloudEdgeEntity(srcVertex, ((IBaseObject) edge.dst).asVertex(), edge.dir, edge.label));
+ }
+ }
+ graph.addEdges(edgesToSet);
+ graph.setProperties(propertiesToSet);
+ }
+ }
+ }
+
+ private Vertex getVertexEdge(Iterator vi, int idx) {
+ int i = 0;
+ while (vi.hasNext()) {
+ Vertex v = (Vertex)vi.next();
+ if (i == idx) {
+ return v;
+ }
+ i++;
+ }
+ return null;
+ }
+
+ @Override
+ public Map<String, Object> getProperties() {
+ return properties;
+ }
+
+ @Override
+ public void addEdge(Object dst, Direction dir, String label) {
+ edges.add(new EntityEdge(this, dst, DBOperationType.ADD, dir, label));
+ }
+
+ @Override
+ public void removeEdge(Object src, Object dst, Direction dir, String label) {
+ edges.add(new EntityEdge(src, dst, DBOperationType.REMOVE, dir, label));
+ }
+}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEntityManager.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEntityManager.java
new file mode 100644
index 0000000..38e694b
--- /dev/null
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEntityManager.java
@@ -0,0 +1,29 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package net.onrc.onos.ofcontroller.flowmanager;
+
+import com.tinkerpop.blueprints.Direction;
+import java.util.Map;
+import net.onrc.onos.graph.DBOperation;
+
+/**
+ *
+ * @author nickkaranatsios
+ */
+public interface FlowEntityManager {
+ public void setPrimaryKey(String key);
+ public String getPrimaryKey();
+ public void hasMany(Class<?> cClass);
+ public void operationBegin(String opName);
+ public void operationEnd(String opName);
+ public void setProperty(String propertyName, Object value);
+ public Object getProperty(String propertyName);
+ public Map<String, Object> getProperties();
+ public FlowEntityManager append(Object entity);
+ public void addEdge(Object dst, Direction dir, String label);
+ public void removeEdge(Object src, Object dst, Direction dir, String label);
+ public void persist(DBOperation dbHandler);
+}
+
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEntryProperty.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEntryProperty.java
index 7b17aaa..b45f8ff 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEntryProperty.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEntryProperty.java
@@ -8,13 +8,6 @@
public class FlowEntryProperty {
private Map<String, Object> map = new HashMap<>();
- private DBOperation dbhandler;
- private IFlowEntry flowEntry;
-
- public FlowEntryProperty(DBOperation dbHandler, IFlowEntry flowEntry) {
- this.dbhandler = dbHandler;
- this.flowEntry = flowEntry;
- }
public void setFlowId(String value) {
map.put("flow_id", value);
@@ -144,7 +137,7 @@
*
* @param dbhandler
*/
- public void commitProperties() {
- dbhandler.setVertexProperties(flowEntry.asVertex() ,map);
+ public void commitProperties(DBOperation dbhandler, IFlowEntry flowEntry) {
+ dbhandler.setVertexProperties(flowEntry.asVertex(), map);
}
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEventHandler.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEventHandler.java
index ba1e448..1705569 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEventHandler.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowEventHandler.java
@@ -39,7 +39,7 @@
import net.onrc.onos.ofcontroller.util.Port;
import net.onrc.onos.ofcontroller.util.serializers.KryoFactory;
-import com.esotericsoftware.kryo2.Kryo;
+import com.esotericsoftware.kryo.Kryo;
import com.tinkerpop.blueprints.impls.ramcloud.PerfMon;
import org.slf4j.Logger;
@@ -475,6 +475,10 @@
for (FlowPath flowPath : flowPaths) {
boolean isInstalled = true;
+
+ if (flowPath.flowEntries().isEmpty()) {
+ continue;
+ }
//
// Check whether all Flow Entries have been installed
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
index 791008d..de847de 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
@@ -41,7 +41,8 @@
import net.onrc.onos.ofcontroller.util.serializers.KryoFactory;
import com.thinkaurelius.titan.core.TitanException;
-import com.esotericsoftware.kryo2.Kryo;
+
+import com.esotericsoftware.kryo.Kryo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -87,12 +88,8 @@
*/
@Override
public void init(final String dbStore, final String conf) {
- dbHandlerApi = GraphDBManager.getDBOperation("ramcloud", "/tmp/ramcloudconf");
- dbHandlerInner = GraphDBManager.getDBOperation("ramcloud", "/tmp/ramcloudconf");
-
- //dbHandlerApi = GraphDBManager.getDBOperation(dbStore, conf);
- //dbHandlerInner = GraphDBManager.getDBOperation(dbStore, conf);
-
+ dbHandlerApi = GraphDBManager.getDBOperation("ramcloud", "/tmp/ramcloud.conf");
+ dbHandlerInner = GraphDBManager.getDBOperation("ramcloud", "/tmp/ramcloud.conf");
}
/**
@@ -477,6 +474,11 @@
if (srcDpid.value() != sw.getId())
return;
deleteFlow(flowPath.flowId());
+
+ // Send flow deleted notification to the Forwarding module
+ // TODO This is a quick fix for flow-removed notifications. We
+ // should think more about the design of these notifications.
+ notificationFlowPathRemoved(flowPath);
}
/**
@@ -549,6 +551,20 @@
}
/**
+ * Generate a notification that a FlowPath has been removed from the
+ * network. This means we've received an expiry message for the flow
+ * from the switch, and send flowmods to remove any remaining parts of
+ * the path.
+ *
+ * @param flowPath FlowPath object that was removed from the network.
+ */
+ void notificationFlowPathRemoved(FlowPath flowPath) {
+ if (forwardingService != null) {
+ forwardingService.flowRemoved(flowPath);
+ }
+ }
+
+ /**
* Push modified Flow-related state as appropriate.
*
* @param modifiedFlowPaths the collection of modified Flow Paths.
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowPathProperty.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowPathProperty.java
index c6a2b98..21db7bc 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowPathProperty.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowPathProperty.java
@@ -8,13 +8,6 @@
public class FlowPathProperty {
private Map<String, Object> map = new HashMap<>();
- private DBOperation dbhandler;
- private IFlowPath flowPath;
-
- public FlowPathProperty(DBOperation dbHandler, IFlowPath flowPath) {
- this.dbhandler = dbHandler;
- this.flowPath = flowPath;
- }
public void setType(String typeStr) {
map.put("type", typeStr);
@@ -120,7 +113,7 @@
*
* @param dbhandler
*/
- public void commitProperties() {
+ public void commitProperties(DBOperation dbhandler, IFlowPath flowPath) {
dbhandler.setVertexProperties(flowPath.asVertex() ,map);
}
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowprogrammer/FlowProgrammer.java b/src/main/java/net/onrc/onos/ofcontroller/flowprogrammer/FlowProgrammer.java
index e94d948..4915cc7 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowprogrammer/FlowProgrammer.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowprogrammer/FlowProgrammer.java
@@ -44,7 +44,7 @@
IOFSwitchListener {
// flag to enable FlowSynchronizer
private static final boolean enableFlowSync = true;
- protected static Logger log = LoggerFactory.getLogger(FlowProgrammer.class);
+ protected static final Logger log = LoggerFactory.getLogger(FlowProgrammer.class);
protected volatile IFloodlightProviderService floodlightProvider;
protected volatile IControllerRegistryService registryService;
protected volatile IRestApiService restApi;
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowprogrammer/FlowSynchronizer.java b/src/main/java/net/onrc/onos/ofcontroller/flowprogrammer/FlowSynchronizer.java
index 949cc7b..bd98527 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowprogrammer/FlowSynchronizer.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowprogrammer/FlowSynchronizer.java
@@ -50,8 +50,9 @@
private Map<IOFSwitch, FutureTask<SyncResult>> switchThreads;
public FlowSynchronizer() {
- dbHandler = GraphDBManager.getDBOperation("ramcloud", "/tmp/ramcloudconf");
- switchThreads = new HashMap<IOFSwitch, FutureTask<SyncResult>>(); }
+ dbHandler = GraphDBManager.getDBOperation("ramcloud", "/tmp/ramcloud.conf");
+ switchThreads = new HashMap<IOFSwitch, FutureTask<SyncResult>>();
+ }
@Override
public Future<SyncResult> synchronize(IOFSwitch sw) {
@@ -102,6 +103,10 @@
Set<FlowEntryWrapper> graphEntries = getFlowEntriesFromGraph();
long step1 = System.nanoTime();
Set<FlowEntryWrapper> switchEntries = getFlowEntriesFromSwitch();
+ if (switchEntries == null) {
+ log.debug("getFlowEntriesFromSwitch() failed");
+ return null;
+ }
long step2 = System.nanoTime();
SyncResult result = compare(graphEntries, switchEntries);
long step3 = System.nanoTime();
@@ -216,12 +221,15 @@
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
+ return null;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
+ return null;
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
+ return null;
}
Set<FlowEntryWrapper> results = new HashSet<FlowEntryWrapper>();
@@ -337,7 +345,7 @@
*/
@Override
public boolean equals(Object obj){
- if(obj.getClass() == this.getClass()) {
+ if(obj != null && obj.getClass() == this.getClass()) {
FlowEntryWrapper entry = (FlowEntryWrapper) obj;
// TODO: we need to actually compare the match + actions
return this.flowEntryId.equals(entry.flowEntryId);
diff --git a/src/main/java/net/onrc/onos/ofcontroller/forwarding/Forwarding.java b/src/main/java/net/onrc/onos/ofcontroller/forwarding/Forwarding.java
index 85d122d..882d5fa 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/forwarding/Forwarding.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/forwarding/Forwarding.java
@@ -1,6 +1,5 @@
package net.onrc.onos.ofcontroller.forwarding;
-import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -16,7 +15,6 @@
import net.floodlightcontroller.core.module.IFloodlightModule;
import net.floodlightcontroller.core.module.IFloodlightService;
import net.floodlightcontroller.packet.Ethernet;
-import net.floodlightcontroller.packet.IPv4;
import net.floodlightcontroller.util.MACAddress;
import net.onrc.onos.datagrid.IDatagridService;
import net.onrc.onos.ofcontroller.core.IDeviceStorage;
@@ -27,11 +25,13 @@
import net.onrc.onos.ofcontroller.devicemanager.IOnosDeviceService;
import net.onrc.onos.ofcontroller.flowmanager.IFlowService;
import net.onrc.onos.ofcontroller.flowprogrammer.IFlowPusherService;
-import net.onrc.onos.ofcontroller.proxyarp.ArpMessage;
+import net.onrc.onos.ofcontroller.proxyarp.BroadcastPacketOutNotification;
+import net.onrc.onos.ofcontroller.proxyarp.IProxyArpService;
import net.onrc.onos.ofcontroller.topology.TopologyManager;
import net.onrc.onos.ofcontroller.util.CallerId;
import net.onrc.onos.ofcontroller.util.DataPath;
import net.onrc.onos.ofcontroller.util.Dpid;
+import net.onrc.onos.ofcontroller.util.FlowEntry;
import net.onrc.onos.ofcontroller.util.FlowEntryMatch;
import net.onrc.onos.ofcontroller.util.FlowId;
import net.onrc.onos.ofcontroller.util.FlowPath;
@@ -53,7 +53,6 @@
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.ListMultimap;
-import com.google.common.net.InetAddresses;
public class Forwarding implements IOFMessageListener, IFloodlightModule,
IForwardingService {
@@ -61,8 +60,8 @@
private final int IDLE_TIMEOUT = 5; // seconds
private final int HARD_TIMEOUT = 0; // seconds
-
- private final int PATH_PUSHED_TIMEOUT = 3000; // milliseconds
+
+ private final CallerId callerId = new CallerId("Forwarding");
private IFloodlightProviderService floodlightProvider;
private IFlowService flowService;
@@ -72,7 +71,6 @@
private IDeviceStorage deviceStorage;
private TopologyManager topologyService;
- //private Map<Path, Long> pendingFlows;
// TODO it seems there is a Guava collection that will time out entries.
// We should see if this will work here.
private Map<Path, PushedFlow> pendingFlows;
@@ -92,31 +90,18 @@
private class PushedFlow {
public final long flowId;
- private final long pushedTime;
- public short firstHopOutPort = OFPort.OFPP_NONE.getValue();
+ public boolean installed = false;
public PushedFlow(long flowId) {
this.flowId = flowId;
- pushedTime = System.currentTimeMillis();
- }
-
- public boolean isExpired() {
- return (System.currentTimeMillis() - pushedTime) > PATH_PUSHED_TIMEOUT;
}
}
private final class Path {
- public final SwitchPort srcPort;
- public final SwitchPort dstPort;
public final MACAddress srcMac;
public final MACAddress dstMac;
- public Path(SwitchPort src, SwitchPort dst,
- MACAddress srcMac, MACAddress dstMac) {
- srcPort = new SwitchPort(new Dpid(src.dpid().value()),
- new Port(src.port().value()));
- dstPort = new SwitchPort(new Dpid(dst.dpid().value()),
- new Port(dst.port().value()));
+ public Path(MACAddress srcMac, MACAddress dstMac) {
this.srcMac = srcMac;
this.dstMac = dstMac;
}
@@ -128,17 +113,13 @@
}
Path otherPath = (Path) other;
- return srcPort.equals(otherPath.srcPort) &&
- dstPort.equals(otherPath.dstPort) &&
- srcMac.equals(otherPath.srcMac) &&
+ return srcMac.equals(otherPath.srcMac) &&
dstMac.equals(otherPath.dstMac);
}
@Override
public int hashCode() {
int hash = 17;
- hash = 31 * hash + srcPort.hashCode();
- hash = 31 * hash + dstPort.hashCode();
hash = 31 * hash + srcMac.hashCode();
hash = 31 * hash + dstMac.hashCode();
return hash;
@@ -146,8 +127,7 @@
@Override
public String toString() {
- return "(" + srcMac + " at " + srcPort + ") => ("
- + dstPort + " at " + dstMac + ")";
+ return "(" + srcMac + ") => (" + dstMac + ")";
}
}
@@ -175,6 +155,9 @@
dependencies.add(IFlowService.class);
dependencies.add(IFlowPusherService.class);
dependencies.add(IOnosDeviceService.class);
+ // We don't use the IProxyArpService directly, but reactive forwarding
+ // requires it to be loaded and answering ARP requests
+ dependencies.add(IProxyArpService.class);
return dependencies;
}
@@ -187,12 +170,8 @@
datagrid = context.getServiceImpl(IDatagridService.class);
floodlightProvider.addOFMessageListener(OFType.PACKET_IN, this);
-
- //pendingFlows = new ConcurrentHashMap<Path, Long>();
+
pendingFlows = new HashMap<Path, PushedFlow>();
- //waitingPackets = Multimaps.synchronizedSetMultimap(
- //HashMultimap.<Long, PacketToPush>create());
- //waitingPackets = HashMultimap.create();
waitingPackets = LinkedListMultimap.create();
deviceStorage = new DeviceStorageImpl();
@@ -242,7 +221,6 @@
if (eth.isBroadcast() || eth.isMulticast()) {
handleBroadcast(sw, pi, eth);
- //return Command.CONTINUE;
}
else {
// Unicast
@@ -256,24 +234,9 @@
if (log.isTraceEnabled()) {
log.trace("Sending broadcast packet to other ONOS instances");
}
-
- IPv4 ipv4Packet = (IPv4) eth.getPayload();
-
- // TODO We'll put the destination address here, because the current
- // architecture needs an address. Addresses are only used for replies
- // however, which don't apply to non-ARP packets. The ArpMessage class
- // has become a bit too overloaded and should be refactored to
- // handle all use cases nicely.
- InetAddress targetAddress =
- InetAddresses.fromInteger(ipv4Packet.getDestinationAddress());
-
- // Piggy-back on the ARP mechanism to broadcast this packet out the
- // edge. Luckily the ARP module doesn't check that the packet is
- // actually ARP before broadcasting, so we can trick it into sending
- // our non-ARP packets.
- // TODO This should be refactored later to account for the new use case.
- datagrid.sendArpRequest(ArpMessage.newRequest(targetAddress, eth.serialize(),
- -1L, (short)-1, sw.getId(), pi.getInPort()));
+
+ datagrid.sendPacketOutNotification(new BroadcastPacketOutNotification(
+ eth.serialize(), sw.getId(), pi.getInPort()));
}
private void handlePacketIn(IOFSwitch sw, OFPacketIn pi, Ethernet eth) {
@@ -303,7 +266,6 @@
long destinationDpid = HexString.toLong(switchObject.getDPID());
// TODO SwitchPort, Dpid and Port should probably be immutable
- // (also, are Dpid and Port are even necessary?)
SwitchPort srcSwitchPort = new SwitchPort(
new Dpid(sw.getId()), new Port(pi.getInPort()));
SwitchPort dstSwitchPort = new SwitchPort(
@@ -312,26 +274,50 @@
MACAddress srcMacAddress = MACAddress.valueOf(eth.getSourceMACAddress());
MACAddress dstMacAddress = MACAddress.valueOf(eth.getDestinationMACAddress());
-
FlowPath flowPath, reverseFlowPath;
- Path pathspec = new Path(srcSwitchPort, dstSwitchPort,
- srcMacAddress, dstMacAddress);
+ Path pathspec = new Path(srcMacAddress, dstMacAddress);
// TODO check concurrency
synchronized (lock) {
PushedFlow existingFlow = pendingFlows.get(pathspec);
- //Long existingFlowId = pendingFlows.get(pathspec);
-
- if (existingFlow != null && !existingFlow.isExpired()) {
+
+ if (existingFlow != null) {
+ // We've already installed a flow for this pair of MAC addresses
log.debug("Found existing flow {}",
HexString.toHexString(existingFlow.flowId));
OFPacketOut po = constructPacketOut(pi, sw);
- if (existingFlow.firstHopOutPort != OFPort.OFPP_NONE.getValue()) {
+ // Find the correct port here. We just assume the PI is from
+ // the first hop switch, but this is definitely not always
+ // the case. We'll have to retrieve the flow from HZ every time
+ // because it could change (be rerouted) sometimes.
+ if (existingFlow.installed) {
// Flow has been sent to the switches so it is safe to
// send a packet out now
- sendPacketOut(sw, po, existingFlow.firstHopOutPort);
+ FlowPath flow = datagrid.getFlow(new FlowId(existingFlow.flowId));
+ FlowEntry flowEntryForThisSwitch = null;
+
+ if (flow != null) {
+ for (FlowEntry flowEntry : flow.flowEntries()) {
+ if (flowEntry.dpid().equals(new Dpid(sw.getId()))) {
+ flowEntryForThisSwitch = flowEntry;
+ break;
+ }
+ }
+ }
+
+ if (flowEntryForThisSwitch == null) {
+ // If we don't find a flow entry for that switch, then we're
+ // in the middle of a rerouting (or something's gone wrong).
+ // This packet will be dropped as a victim of the rerouting.
+ log.debug("Dropping packet on flow {} between {}-{}, flow path {}",
+ new Object[] {new FlowId(existingFlow.flowId),
+ srcMacAddress, dstMacAddress, flow});
+ }
+ else {
+ sendPacketOut(sw, po, flowEntryForThisSwitch.outPort().value());
+ }
}
else {
// Flow has not yet been sent to switches so save the
@@ -341,21 +327,16 @@
}
return;
}
-
- //log.debug("Couldn't match {} in {}", pathspec, pendingFlows);
-
+
log.debug("Adding new flow between {} at {} and {} at {}",
new Object[]{srcMacAddress, srcSwitchPort, dstMacAddress, dstSwitchPort});
-
- CallerId callerId = new CallerId("Forwarding");
-
DataPath datapath = new DataPath();
datapath.setSrcPort(srcSwitchPort);
datapath.setDstPort(dstSwitchPort);
flowPath = new FlowPath();
- flowPath.setInstallerId(callerId);
+ flowPath.setInstallerId(new CallerId(callerId));
flowPath.setFlowPathType(FlowPathType.FP_TYPE_SHORTEST_PATH);
flowPath.setFlowPathUserState(FlowPathUserState.FP_USER_ADD);
@@ -375,7 +356,7 @@
// TODO implement copy constructor for FlowPath
reverseFlowPath = new FlowPath();
- reverseFlowPath.setInstallerId(callerId);
+ reverseFlowPath.setInstallerId(new CallerId(callerId));
reverseFlowPath.setFlowPathType(FlowPathType.FP_TYPE_SHORTEST_PATH);
reverseFlowPath.setFlowPathUserState(FlowPathUserState.FP_USER_ADD);
reverseFlowPath.setIdleTimeout(IDLE_TIMEOUT);
@@ -387,9 +368,7 @@
reverseFlowPath.flowEntryMatch().enableEthernetFrameType(Ethernet.TYPE_IPv4);
reverseFlowPath.setDataPath(reverseDataPath);
reverseFlowPath.dataPath().srcPort().dpid().toString();
-
- // TODO what happens if no path exists? cleanup
-
+
FlowId flowId = new FlowId(flowService.getNextFlowEntryId());
FlowId reverseFlowId = new FlowId(flowService.getNextFlowEntryId());
@@ -397,50 +376,23 @@
reverseFlowPath.setFlowId(reverseFlowId);
OFPacketOut po = constructPacketOut(pi, sw);
- Path reversePathSpec = new Path(dstSwitchPort, srcSwitchPort,
- dstMacAddress, srcMacAddress);
+ Path reversePathSpec = new Path(dstMacAddress, srcMacAddress);
// Add to waiting lists
- //pendingFlows.put(pathspec, flowId.value());
- //pendingFlows.put(reversePathSpec, reverseFlowId.value());
pendingFlows.put(pathspec, new PushedFlow(flowId.value()));
pendingFlows.put(reversePathSpec, new PushedFlow(reverseFlowId.value()));
waitingPackets.put(flowId.value(), new PacketToPush(po, sw.getId()));
}
+ log.debug("Adding reverse {} to {} flowid {}", new Object[] {
+ dstMacAddress, srcMacAddress, reverseFlowPath.flowId()});
flowService.addFlow(reverseFlowPath);
+ log.debug("Adding forward {} to {} flowid {}", new Object[] {
+ srcMacAddress, dstMacAddress, flowPath.flowId()});
flowService.addFlow(flowPath);
}
-
- /*
- private boolean flowExists(SwitchPort srcPort, MACAddress srcMac,
- SwitchPort dstPort, MACAddress dstMac) {
- for (FlowPath flow : datagridService.getAllFlows()) {
- FlowEntryMatch match = flow.flowEntryMatch();
- // TODO implement FlowEntryMatch.equals();
- // This is painful to do properly without support in the FlowEntryMatch
- boolean same = true;
- if (!match.srcMac().equals(srcMac) ||
- !match.dstMac().equals(dstMac)) {
- same = false;
- }
- if (!flow.dataPath().srcPort().equals(srcPort) ||
- !flow.dataPath().dstPort().equals(dstPort)) {
- same = false;
- }
-
- if (same) {
- log.debug("found flow entry that's the same {}-{}:::{}-{}",
- new Object[] {srcPort, srcMac, dstPort, dstMac});
- return true;
- }
- }
-
- return false;
- }
- */
private OFPacketOut constructPacketOut(OFPacketIn pi, IOFSwitch sw) {
OFPacketOut po = new OFPacketOut();
@@ -467,36 +419,64 @@
flowInstalled(flowPath);
}
}
+
+ @Override
+ public void flowRemoved(FlowPath removedFlowPath) {
+ if (!removedFlowPath.installerId().equals(callerId)) {
+ // Not our flow path, ignore
+ return;
+ }
+
+ MACAddress srcMacAddress = removedFlowPath.flowEntryMatch().srcMac();
+ MACAddress dstMacAddress = removedFlowPath.flowEntryMatch().dstMac();
+
+ Path removedPath = new Path(srcMacAddress, dstMacAddress);
+
+ synchronized (lock) {
+ pendingFlows.remove(removedPath);
+
+ // There *shouldn't* be any packets queued if the flow has
+ // just been removed.
+ List<PacketToPush> packets =
+ waitingPackets.removeAll(removedFlowPath.flowId().value());
+ if (!packets.isEmpty()) {
+ log.warn("Removed flow {} has packets queued",
+ removedFlowPath.flowId());
+ }
+ }
+ }
private void flowInstalled(FlowPath installedFlowPath) {
long flowId = installedFlowPath.flowId().value();
+ if (!installedFlowPath.installerId().equals(callerId)) {
+ // Not our flow path, ignore
+ return;
+ }
+
+ // TODO waiting packets should time out. We could request a path that
+ // can't be installed right now because of a network partition. The path
+ // may eventually be installed, but we may have received thousands of
+ // packets in the meantime and probably don't want to send very old packets.
short outPort =
installedFlowPath.flowEntries().get(0).outPort().value();
MACAddress srcMacAddress = installedFlowPath.flowEntryMatch().srcMac();
MACAddress dstMacAddress = installedFlowPath.flowEntryMatch().dstMac();
- if (srcMacAddress == null || dstMacAddress == null) {
- // Not our flow path, ignore
- return;
- }
-
Collection<PacketToPush> packets;
synchronized (lock) {
- log.debug("Flow {} has been installed, sending queued packets",
- installedFlowPath.flowId());
-
packets = waitingPackets.removeAll(flowId);
+ log.debug("Flow {} has been installed, sending {} queued packets",
+ installedFlowPath.flowId(), packets.size());
+
// remove pending flows entry
- Path installedPath = new Path(installedFlowPath.dataPath().srcPort(),
- installedFlowPath.dataPath().dstPort(),
- srcMacAddress, dstMacAddress);
- //pendingFlows.remove(pathToRemove);
+ Path installedPath = new Path(srcMacAddress, dstMacAddress);
PushedFlow existingFlow = pendingFlows.get(installedPath);
- if (existingFlow != null)
- existingFlow.firstHopOutPort = outPort;
+ if (existingFlow != null) {
+ existingFlow.installed = true;
+ }
}
for (PacketToPush packet : packets) {
@@ -514,4 +494,5 @@
flowPusher.add(sw, po);
}
+
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/forwarding/IForwardingService.java b/src/main/java/net/onrc/onos/ofcontroller/forwarding/IForwardingService.java
index e5bd714..0e0d1da 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/forwarding/IForwardingService.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/forwarding/IForwardingService.java
@@ -22,4 +22,12 @@
* been installed in the network.
*/
public void flowsInstalled(Collection<FlowPath> installedFlowPaths);
+
+ /**
+ * Notify the Forwarding module that a flow has expired and been
+ * removed from the network.
+ *
+ * @param removedFlowPath The FlowPath that was removed
+ */
+ public void flowRemoved(FlowPath removedFlowPath);
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/proxyarp/ArpMessage.java b/src/main/java/net/onrc/onos/ofcontroller/proxyarp/ArpMessage.java
deleted file mode 100644
index 44b9ea0..0000000
--- a/src/main/java/net/onrc/onos/ofcontroller/proxyarp/ArpMessage.java
+++ /dev/null
@@ -1,135 +0,0 @@
-package net.onrc.onos.ofcontroller.proxyarp;
-
-import java.io.Serializable;
-import java.net.InetAddress;
-import net.floodlightcontroller.util.MACAddress;
-
-// TODO This is getting very messy!!! Needs refactoring
-public class ArpMessage implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private final Type type;
- private final InetAddress forAddress;
- private final byte[] packetData;
-
- // ARP reply message needs MAC info
- private final MACAddress mac;
- // Only send the ARP request message to the device attachment needs the
- // attachment switch and port.
- private final long outSwitch;
- private final short outPort;
-
- private final long inSwitch;
- private final short inPort;
-
- public enum Type {
- REQUEST,
- REPLY
- }
-
- private ArpMessage(Type type, InetAddress address, byte[] eth,
- long outSwitch, short outPort, long inSwitch, short inPort) {
- this.type = type;
- this.forAddress = address;
- this.packetData = eth;
- this.mac = null;
- this.outSwitch = -1;
- this.outPort = -1;
- this.inSwitch = inSwitch;
- this.inPort = inPort;
- }
-
- private ArpMessage(Type type, InetAddress address) {
- this.type = type;
- this.forAddress = address;
- this.packetData = null;
- this.mac = null;
- this.outSwitch = -1;
- this.outPort = -1;
-
- this.inSwitch = -1;
- this.inPort = -1;
- }
- // the ARP reply message with MAC
- private ArpMessage(Type type, InetAddress address, MACAddress mac) {
- this.type = type;
- this.forAddress = address;
- this.packetData = null;
- this.mac = mac;
- this.outSwitch = -1;
- this.outPort = -1;
-
- this.inSwitch = -1;
- this.inPort = -1;
- }
-
- // construct ARP request message with attachment switch and port
- private ArpMessage(Type type, InetAddress address, byte[] arpRequest,
- long outSwitch, short outPort) {
- this.type = type;
- this.forAddress = address;
- this.packetData = arpRequest;
- this.mac = null;
- this.outSwitch = outSwitch;
- this.outPort = outPort;
-
- this.inSwitch = -1;
- this.inPort = -1;
- }
-
- // TODO Awful quick fix - caller has to supply dummy outSwitch and outPort
- public static ArpMessage newRequest(InetAddress forAddress, byte[] arpRequest,
- long outSwitch, short outPort, long inSwitch, short inPort) {
- return new ArpMessage(Type.REQUEST, forAddress, arpRequest,
- outSwitch, outPort, inSwitch, inPort);
- }
-
- public static ArpMessage newReply(InetAddress forAddress) {
- return new ArpMessage(Type.REPLY, forAddress);
- }
-
- //ARP reply message with MAC
- public static ArpMessage newReply(InetAddress forAddress, MACAddress mac) {
- return new ArpMessage(Type.REPLY, forAddress, mac);
- }
-
- //ARP request message with attachment switch and port
- public static ArpMessage newRequest(InetAddress forAddress,
- byte[] arpRequest, long outSwitch, short outPort ) {
- return new ArpMessage(Type.REQUEST, forAddress, arpRequest, outSwitch,
- outPort);
- }
-
- public Type getType() {
- return type;
- }
-
- public InetAddress getAddress() {
- return forAddress;
- }
-
- public byte[] getPacket() {
- return packetData;
- }
-
- public MACAddress getMAC() {
- return mac;
- }
-
- public long getOutSwitch() {
- return outSwitch;
- }
-
- public short getOutPort() {
- return outPort;
- }
-
- public long getInSwitch() {
- return inSwitch;
- }
-
- public short getInPort() {
- return inPort;
- }
-}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/proxyarp/ArpReplyNotification.java b/src/main/java/net/onrc/onos/ofcontroller/proxyarp/ArpReplyNotification.java
new file mode 100644
index 0000000..a8afc55
--- /dev/null
+++ b/src/main/java/net/onrc/onos/ofcontroller/proxyarp/ArpReplyNotification.java
@@ -0,0 +1,28 @@
+package net.onrc.onos.ofcontroller.proxyarp;
+
+import java.io.Serializable;
+import java.net.InetAddress;
+
+import net.floodlightcontroller.util.MACAddress;
+
+public class ArpReplyNotification implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private InetAddress targetAddress;
+ private MACAddress targetMacAddress;
+
+ public ArpReplyNotification(InetAddress targetAddress, MACAddress targetMacAddress) {
+ this.targetAddress = targetAddress;
+ this.targetMacAddress = targetMacAddress;
+ }
+
+ public InetAddress getTargetAddress() {
+ return targetAddress;
+ }
+
+ public MACAddress getTargetMacAddress() {
+ return targetMacAddress;
+ }
+
+}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/proxyarp/BroadcastPacketOutNotification.java b/src/main/java/net/onrc/onos/ofcontroller/proxyarp/BroadcastPacketOutNotification.java
new file mode 100644
index 0000000..73d2163
--- /dev/null
+++ b/src/main/java/net/onrc/onos/ofcontroller/proxyarp/BroadcastPacketOutNotification.java
@@ -0,0 +1,34 @@
+package net.onrc.onos.ofcontroller.proxyarp;
+
+/**
+ * Notification to all ONOS instances to broadcast this packet out the edge of
+ * the network. The edge is defined as any port that doesn't have a link to
+ * another switch. The one exception is the port that the packet was received
+ * on.
+ *
+ */
+public class BroadcastPacketOutNotification extends
+ PacketOutNotification {
+
+ private static final long serialVersionUID = 1L;
+
+ private final long inSwitch;
+ private final short inPort;
+
+ public BroadcastPacketOutNotification(byte[] packet, long inSwitch,
+ short inPort) {
+ super(packet);
+
+ this.inSwitch = inSwitch;
+ this.inPort = inPort;
+ }
+
+ public long getInSwitch() {
+ return inSwitch;
+ }
+
+ public short getInPort() {
+ return inPort;
+ }
+
+}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/proxyarp/IArpEventHandler.java b/src/main/java/net/onrc/onos/ofcontroller/proxyarp/IArpEventHandler.java
deleted file mode 100644
index 4ec32ec..0000000
--- a/src/main/java/net/onrc/onos/ofcontroller/proxyarp/IArpEventHandler.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package net.onrc.onos.ofcontroller.proxyarp;
-
-public interface IArpEventHandler {
-
- /**
- * Notify the ARP event handler that an ARP request has been received.
- * @param id The string ID of the ARP request
- * @param arpRequest The ARP request packet
- */
- public void arpRequestNotification(ArpMessage arpMessage);
-}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/proxyarp/IArpReplyEventHandler.java b/src/main/java/net/onrc/onos/ofcontroller/proxyarp/IArpReplyEventHandler.java
new file mode 100644
index 0000000..75f1d5d
--- /dev/null
+++ b/src/main/java/net/onrc/onos/ofcontroller/proxyarp/IArpReplyEventHandler.java
@@ -0,0 +1,5 @@
+package net.onrc.onos.ofcontroller.proxyarp;
+
+public interface IArpReplyEventHandler {
+ public void arpReplyEvent(ArpReplyNotification arpReply);
+}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/proxyarp/IPacketOutEventHandler.java b/src/main/java/net/onrc/onos/ofcontroller/proxyarp/IPacketOutEventHandler.java
new file mode 100644
index 0000000..86b3728
--- /dev/null
+++ b/src/main/java/net/onrc/onos/ofcontroller/proxyarp/IPacketOutEventHandler.java
@@ -0,0 +1,18 @@
+package net.onrc.onos.ofcontroller.proxyarp;
+
+/**
+ * Classes may implement this interface if they wish to subscribe to
+ * packet out notifications from the datagrid service. Packet out notifications
+ * are used to direct other ONOS instances to send packets out particular
+ * ports under their control.
+ *
+ */
+public interface IPacketOutEventHandler {
+
+ /**
+ * Notify the packet out event handler that an packet out notification has
+ * been received.
+ * @param packetOutNotification An object describing the notification
+ */
+ public void packetOutNotification(PacketOutNotification packetOutNotification);
+}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/proxyarp/PacketOutNotification.java b/src/main/java/net/onrc/onos/ofcontroller/proxyarp/PacketOutNotification.java
new file mode 100644
index 0000000..3d37d25
--- /dev/null
+++ b/src/main/java/net/onrc/onos/ofcontroller/proxyarp/PacketOutNotification.java
@@ -0,0 +1,21 @@
+package net.onrc.onos.ofcontroller.proxyarp;
+
+import java.io.Serializable;
+
+/**
+ * A PacketOutNotification contains data sent between ONOS instances that
+ * directs other instances to send a packet out a set of ports.
+ * This is an abstract base class that will be subclassed by specific
+ * types of notifications.
+ *
+ */
+public abstract class PacketOutNotification implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ protected final byte[] packet;
+
+ public PacketOutNotification(byte[] packet) {
+ this.packet = packet;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/proxyarp/ProxyArpManager.java b/src/main/java/net/onrc/onos/ofcontroller/proxyarp/ProxyArpManager.java
index 2b4b0b1..f5fee45 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/proxyarp/ProxyArpManager.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/proxyarp/ProxyArpManager.java
@@ -37,6 +37,7 @@
import net.onrc.onos.ofcontroller.core.config.IConfigInfoService;
import net.onrc.onos.ofcontroller.core.internal.DeviceStorageImpl;
import net.onrc.onos.ofcontroller.core.internal.TopoSwitchServiceImpl;
+import net.onrc.onos.ofcontroller.flowprogrammer.IFlowPusherService;
import net.onrc.onos.ofcontroller.util.Dpid;
import net.onrc.onos.ofcontroller.util.Port;
import net.onrc.onos.ofcontroller.util.SwitchPort;
@@ -58,7 +59,8 @@
import com.google.common.net.InetAddresses;
public class ProxyArpManager implements IProxyArpService, IOFMessageListener,
- IArpEventHandler, IFloodlightModule {
+ IPacketOutEventHandler, IArpReplyEventHandler,
+ IFloodlightModule {
private final static Logger log = LoggerFactory.getLogger(ProxyArpManager.class);
private final long ARP_TIMER_PERIOD = 100; //ms
@@ -70,6 +72,7 @@
private IDatagridService datagrid;
private IConfigInfoService configService;
private IRestApiService restApi;
+ private IFlowPusherService flowPusher;
private IDeviceStorage deviceStorage;
private volatile ITopoSwitchService topoSwitchService;
@@ -153,6 +156,7 @@
dependencies.add(IRestApiService.class);
dependencies.add(IDatagridService.class);
dependencies.add(IConfigInfoService.class);
+ dependencies.add(IFlowPusherService.class);
return dependencies;
}
@@ -164,6 +168,7 @@
this.datagrid = context.getServiceImpl(IDatagridService.class);
this.configService = context.getServiceImpl(IConfigInfoService.class);
this.restApi = context.getServiceImpl(IRestApiService.class);
+ this.flowPusher = context.getServiceImpl(IFlowPusherService.class);
//arpCache = new ArpCache();
@@ -181,7 +186,8 @@
restApi.addRestletRoutable(new ArpWebRoutable());
floodlightProvider.addOFMessageListener(OFType.PACKET_IN, this);
- datagrid.registerArpEventHandler(this);
+ datagrid.registerPacketOutEventHandler(this);
+ datagrid.registerArpReplyEventHandler(this);
deviceStorage = new DeviceStorageImpl();
deviceStorage.init("","");
@@ -290,8 +296,10 @@
handleArpRequest(sw, pi, arp, eth);
}
else if (arp.getOpCode() == ARP.OP_REPLY) {
- handleArpReply(sw, pi, arp);
- sendToOtherNodesReply(eth, pi);
+ // For replies we simply send a notification via Hazelcast
+ sendArpReplyNotification(eth, pi);
+
+ //handleArpReply(sw, pi, arp);
}
// Stop ARP packets here
@@ -345,7 +353,9 @@
}
// We don't know the device so broadcast the request out
- sendToOtherNodes(eth, sw.getId(), pi);
+ datagrid.sendPacketOutNotification(
+ new BroadcastPacketOutNotification(eth.serialize(),
+ sw.getId(), pi.getInPort()));
}
else {
// Even if the device exists in our database, we do not reply to
@@ -362,7 +372,6 @@
// sendArpReply(arp, sw.getId(), pi.getInPort(), macAddress);
- log.trace("Checking the device info from DB is still valid or not");
Iterable<IPortObject> outPorts = targetDevice.getAttachedPorts();
if (!outPorts.iterator().hasNext()){
@@ -371,19 +380,26 @@
" - broadcasting", macAddress);
}
- sendToOtherNodes(eth, sw.getId(), pi);
+ datagrid.sendPacketOutNotification(
+ new BroadcastPacketOutNotification(eth.serialize(),
+ sw.getId(), pi.getInPort()));
}
else {
for (IPortObject portObject : outPorts) {
- long outSwitch = 0;
- short outPort = 0;
+ //long outSwitch = 0;
+ //short outPort = 0;
+ /*
if (!portObject.getLinkedPorts().iterator().hasNext()) {
outPort = portObject.getNumber();
+ }*/
+ if (portObject.getLinkedPorts().iterator().hasNext()) {
+ continue;
}
+ short outPort = portObject.getNumber();
ISwitchObject outSwitchObject = portObject.getSwitch();
- outSwitch = HexString.toLong(outSwitchObject.getDPID());
+ long outSwitch = HexString.toLong(outSwitchObject.getDPID());
if (log.isTraceEnabled()) {
log.trace("Probing device {} on port {}/{}",
@@ -391,7 +407,9 @@
HexString.toHexString(outSwitch), outPort});
}
- sendToOtherNodes(eth, pi, outSwitch, outPort);
+ datagrid.sendPacketOutNotification(
+ new SinglePacketOutNotification(eth.serialize(),
+ outSwitch, outPort));
}
}
}
@@ -517,50 +535,7 @@
}
}
- private void sendToOtherNodes(Ethernet eth, long inSwitchId, OFPacketIn pi) {
- ARP arp = (ARP) eth.getPayload();
-
- if (log.isTraceEnabled()) {
- log.trace("Sending ARP request for {} to other ONOS instances",
- inetAddressToString(arp.getTargetProtocolAddress()));
- }
-
- InetAddress targetAddress;
- try {
- targetAddress = InetAddress.getByAddress(arp.getTargetProtocolAddress());
- } catch (UnknownHostException e) {
- log.error("Unknown host", e);
- return;
- }
-
- datagrid.sendArpRequest(ArpMessage.newRequest(targetAddress, eth.serialize(),
- -1L, (short)-1, inSwitchId, pi.getInPort()));
- }
-
- //hazelcast to other ONOS instances to send the ARP packet out on outPort of outSwitch
- private void sendToOtherNodes(Ethernet eth, OFPacketIn pi, long outSwitch, short outPort) {
- ARP arp = (ARP) eth.getPayload();
-
- if (log.isTraceEnabled()) {
- log.trace("Sending ARP request for {} to other ONOS instances with outSwitch {} ",
- inetAddressToString(arp.getTargetProtocolAddress()), String.valueOf(outSwitch));
- }
-
- InetAddress targetAddress;
- try {
- targetAddress = InetAddress.getByAddress(arp.getTargetProtocolAddress());
- } catch (UnknownHostException e) {
- log.error("Unknown host", e);
- return;
- }
-
- datagrid.sendArpRequest(ArpMessage.newRequest(targetAddress, eth.serialize(), outSwitch, outPort));
- //datagrid.sendArpRequest(ArpMessage.newRequest(targetAddress, eth.serialize()));
-
-
- }
-
- private void sendToOtherNodesReply(Ethernet eth, OFPacketIn pi) {
+ private void sendArpReplyNotification(Ethernet eth, OFPacketIn pi) {
ARP arp = (ARP) eth.getPayload();
if (log.isTraceEnabled()) {
@@ -577,12 +552,14 @@
log.error("Unknown host", e);
return;
}
-
- datagrid.sendArpRequest(ArpMessage.newReply(targetAddress, mac));
- //datagrid.sendArpReply(ArpMessage.newRequest(targetAddress, eth.serialize()));
-
+
+ datagrid.sendArpReplyNotification(new ArpReplyNotification(targetAddress, mac));
}
+ // This remains from the older single-instance ARP code. It used Floodlight
+ // APIs to find the edge of the network, but only worked on a single instance.
+ // We now do this using ONOS network graph APIs.
+ @Deprecated
private void broadcastArpRequestOutEdge(byte[] arpRequest, long inSwitch, short inPort) {
for (IOFSwitch sw : floodlightProvider.getSwitches().values()){
Collection<Short> enabledPorts = sw.getEnabledPortNumbers();
@@ -673,12 +650,7 @@
po.setLengthU(OFPacketOut.MINIMUM_LENGTH + actionsLength
+ arpRequest.length);
- try {
- sw.write(po, null);
- sw.flush();
- } catch (IOException e) {
- log.error("Failure writing packet out to switch", e);
- }
+ flowPusher.add(sw, po);
}
if (log.isTraceEnabled()) {
@@ -712,12 +684,7 @@
return;
}
- try {
- sw.write(po, null);
- sw.flush();
- } catch (IOException e) {
- log.error("Failure writing packet out to switch", e);
- }
+ flowPusher.add(sw, po);
}
private void sendArpReply(ARP arpRequest, long dpid, short port, MACAddress targetMac) {
@@ -740,7 +707,6 @@
.setTargetProtocolAddress(arpRequest.getSenderProtocolAddress());
-
Ethernet eth = new Ethernet();
eth.setDestinationMACAddress(arpRequest.getSenderHardwareAddress())
.setSourceMACAddress(targetMac.toBytes())
@@ -775,12 +741,7 @@
return;
}
- try {
- sw.write(msgList, null);
- sw.flush();
- } catch (IOException e) {
- log.error("Failure writing packet out to switch", e);
- }
+ flowPusher.add(sw, po);
}
private String inetAddressToString(byte[] bytes) {
@@ -820,9 +781,6 @@
}
/*
- * IArpEventHandler methods
- */
-
@Override
public void arpRequestNotification(ArpMessage arpMessage) {
log.debug("Received ARP notification from other instances");
@@ -844,6 +802,7 @@
break;
}
}
+ */
private void sendArpReplyToWaitingRequesters(InetAddress address, MACAddress mac) {
log.debug("Sending ARP reply for {} to requesters",
@@ -876,4 +835,33 @@
request.dispatchReply(address, mac);
}
}
+
+ @Override
+ public void arpReplyEvent(ArpReplyNotification arpReply) {
+ log.debug("Received ARP reply notification for {}",
+ arpReply.getTargetAddress());
+ sendArpReplyToWaitingRequesters(arpReply.getTargetAddress(),
+ arpReply.getTargetMacAddress());
+ }
+
+ @Override
+ public void packetOutNotification(
+ PacketOutNotification packetOutNotification) {
+
+ if (packetOutNotification instanceof SinglePacketOutNotification) {
+ SinglePacketOutNotification notification =
+ (SinglePacketOutNotification) packetOutNotification;
+ sendArpRequestOutPort(notification.packet, notification.getOutSwitch(),
+ notification.getOutPort());
+ }
+ else if (packetOutNotification instanceof BroadcastPacketOutNotification) {
+ BroadcastPacketOutNotification notification =
+ (BroadcastPacketOutNotification) packetOutNotification;
+ broadcastArpRequestOutMyEdge(notification.packet,
+ notification.getInSwitch(), notification.getInPort());
+ }
+ else {
+ log.warn("Unknown packet out notification received");
+ }
+ }
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/proxyarp/SinglePacketOutNotification.java b/src/main/java/net/onrc/onos/ofcontroller/proxyarp/SinglePacketOutNotification.java
new file mode 100644
index 0000000..1919d87
--- /dev/null
+++ b/src/main/java/net/onrc/onos/ofcontroller/proxyarp/SinglePacketOutNotification.java
@@ -0,0 +1,30 @@
+package net.onrc.onos.ofcontroller.proxyarp;
+
+/**
+ * Notification to another ONOS instance to send a packet out a single port.
+ *
+ */
+public class SinglePacketOutNotification extends PacketOutNotification {
+
+ private static final long serialVersionUID = 1L;
+
+ private final long outSwitch;
+ private final short outPort;
+
+ public SinglePacketOutNotification(byte[] packet, long outSwitch,
+ short outPort) {
+ super(packet);
+
+ this.outSwitch = outSwitch;
+ this.outPort = outPort;
+ }
+
+ public long getOutSwitch() {
+ return outSwitch;
+ }
+
+ public short getOutPort() {
+ return outPort;
+ }
+
+}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/topology/TopologyManager.java b/src/main/java/net/onrc/onos/ofcontroller/topology/TopologyManager.java
index a074d19..f326f4c 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/topology/TopologyManager.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/topology/TopologyManager.java
@@ -74,14 +74,13 @@
/**
* Init the module.
- * @param
+ *
* @param config the database configuration file to use for
* the initialization.
*/
public void init(final String dbStore, String config) {
try {
- dbHandler = GraphDBManager.getDBOperation("ramcloud", "/tmp/ramcloudconf");
- //dbHandler = GraphDBManager.getDBOperation(dbStore, config);
+ dbHandler = GraphDBManager.getDBOperation("ramcloud", "/tmp/ramcloud.conf");
} catch (Exception e) {
log.error(e.getMessage());
}
@@ -220,7 +219,7 @@
*/
@Override
public void dropTopology(Topology topology) {
- topology = null;
+ // nothing to do
}
/**
diff --git a/src/main/java/net/onrc/onos/ofcontroller/util/CallerId.java b/src/main/java/net/onrc/onos/ofcontroller/util/CallerId.java
index 0607533..a0217d4 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/util/CallerId.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/util/CallerId.java
@@ -12,6 +12,15 @@
* Default constructor.
*/
public CallerId() {}
+
+ /**
+ * Copy constructor
+ * @param otherCallerId
+ */
+ public CallerId(CallerId otherCallerId) {
+ // Note: make a full copy if we change value to a mutable type
+ value = otherCallerId.value;
+ }
/**
* Constructor from a string value.
@@ -49,4 +58,20 @@
public String toString() {
return value;
}
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof CallerId)) {
+ return false;
+ }
+
+ CallerId otherCallerId = (CallerId) other;
+
+ return value.equals(otherCallerId.value);
+ }
+
+ @Override
+ public int hashCode() {
+ return value.hashCode();
+ }
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/util/Dpid.java b/src/main/java/net/onrc/onos/ofcontroller/util/Dpid.java
index bd91daa..81223d2 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/util/Dpid.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/util/Dpid.java
@@ -13,7 +13,7 @@
@JsonDeserialize(using=DpidDeserializer.class)
@JsonSerialize(using=DpidSerializer.class)
public class Dpid {
- static public long UNKNOWN = 0;
+ static public final long UNKNOWN = 0;
private long value;
diff --git a/src/main/java/net/onrc/onos/ofcontroller/util/serializers/KryoFactory.java b/src/main/java/net/onrc/onos/ofcontroller/util/serializers/KryoFactory.java
index 1355fe0..5998dcd 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/util/serializers/KryoFactory.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/util/serializers/KryoFactory.java
@@ -4,7 +4,6 @@
import java.util.TreeMap;
import net.floodlightcontroller.util.MACAddress;
-import net.onrc.onos.ofcontroller.proxyarp.ArpMessage;
import net.onrc.onos.ofcontroller.topology.TopologyElement;
import net.onrc.onos.ofcontroller.util.CallerId;
import net.onrc.onos.ofcontroller.util.DataPath;
@@ -31,7 +30,7 @@
import net.onrc.onos.ofcontroller.util.Switch;
import net.onrc.onos.ofcontroller.util.SwitchPort;
-import com.esotericsoftware.kryo2.Kryo;
+import com.esotericsoftware.kryo.Kryo;
/**
* Class factory for allocating Kryo instances for
@@ -152,9 +151,6 @@
kryo.register(TopologyElement.class);
kryo.register(TopologyElement.Type.class);
kryo.register(TreeMap.class);
-
- //ARP message
- kryo.register(ArpMessage.class);
return kryo;
}
diff --git a/src/main/protobuf/ramcloudgraph.proto b/src/main/protobuf/ramcloudgraph.proto
new file mode 100644
index 0000000..abd270d
--- /dev/null
+++ b/src/main/protobuf/ramcloudgraph.proto
@@ -0,0 +1,37 @@
+package RamCloudGraph;
+
+option java_package = "com.tinkerpop.blueprints.impls.ramcloud";
+option java_outer_classname = "RamCloudGraphProtos";
+
+message EdgeListProtoBuf {
+ repeated EdgeProtoBuf edge = 1;
+}
+
+message EdgeProtoBuf {
+ required uint64 neighborId = 1;
+ required bool outgoing = 2;
+ required string label = 3;
+}
+
+message PropertyListProtoBuf {
+ repeated PropertyProtoBuf property = 1;
+}
+
+message PropertyProtoBuf {
+ enum Type { STRING = 1; INT32 = 2; INT64 = 3; DOUBLE = 4; FLOAT = 5; BOOL = 6; }
+
+ required string key = 1;
+
+ required Type value_type = 2;
+
+ optional string string_value = 3;
+ optional int32 int32_value = 4;
+ optional int64 int64_value = 5;
+ optional double double_value = 6;
+ optional float float_value = 7;
+ optional bool bool_value = 8;
+}
+
+message IndexBlob {
+ repeated int64 vertexId = 1;
+}
diff --git a/start-cassandra.sh b/start-cassandra.sh
index 426fa60..3e9a8d2 100755
--- a/start-cassandra.sh
+++ b/start-cassandra.sh
@@ -3,7 +3,7 @@
# Set paths
ONOS_HOME=`dirname $0`
CASSANDRA_DIR=${HOME}/apache-cassandra-1.2.4
-LOGDIR=${ONOS_HOME}/ONOS/onos-logs
+LOGDIR=${ONOS_HOME}/onos-logs
CASSANDRA_LOG=${LOGDIR}/cassandara.`hostname`.log
function lotate {
diff --git a/start-onos-embedded.sh b/start-onos-embedded.sh
index 5202daf..7bd0b97 100755
--- a/start-onos-embedded.sh
+++ b/start-onos-embedded.sh
@@ -91,6 +91,7 @@
<logger name="org" level="WARN"/>
<logger name="LogService" level="WARN"/> <!-- Restlet access logging -->
<logger name="net.floodlightcontroller.logging" level="WARN"/>
+<logger name="com.thinkaurelius.titan" level="INFO"/>
<root level="DEBUG">
<appender-ref ref="FILE" />
diff --git a/start-onos-jacoco.sh b/start-onos-jacoco.sh
index 2d1adf4..b721e9e 100755
--- a/start-onos-jacoco.sh
+++ b/start-onos-jacoco.sh
@@ -97,6 +97,7 @@
<logger name="org" level="WARN"/>
<logger name="LogService" level="WARN"/> <!-- Restlet access logging -->
<logger name="net.floodlightcontroller.logging" level="WARN"/>
+<logger name="com.thinkaurelius.titan" level="INFO"/>
<root level="DEBUG">
<appender-ref ref="FILE" />
diff --git a/start-onos.sh b/start-onos.sh
index a1eedcd..f369cf2 100755
--- a/start-onos.sh
+++ b/start-onos.sh
@@ -21,7 +21,7 @@
## If you want JaCoCo Code Coverage reports... uncomment line below
#JVM_OPTS="$JVM_OPTS -javaagent:${ONOS_HOME}/lib/jacocoagent.jar=dumponexit=true,output=file,destfile=${LOGDIR}/jacoco.exec"
JVM_OPTS="$JVM_OPTS -server -d64"
-#JVM_OPTS="$JVM_OPTS -server -d64 -XX:+UnlockCommercialFeatures -XX:+FlightRecorder"
+#JVM_OPTS="$JVM_OPTS -XX:+TieredCompilation -XX:InitialCodeCacheSize=512m -XX:ReservedCodeCacheSize=512m"
JVM_OPTS="$JVM_OPTS -Xmx4g -Xms4g -Xmn800m"
#JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m"
#JVM_OPTS="$JVM_OPTS -Xmx1g -Xms1g -Xmn800m"
@@ -103,6 +103,7 @@
<logger name="org" level="WARN"/>
<logger name="LogService" level="WARN"/> <!-- Restlet access logging -->
<logger name="net.floodlightcontroller.logging" level="WARN"/>
+<logger name="com.thinkaurelius.titan" level="INFO"/>
<root level="DEBUG">
<appender-ref ref="FILE" />
@@ -119,9 +120,6 @@
echo $ONOS_HOME
cd ${ONOS_HOME}
pwd
- echo "${MVN} exec:exec -Dexec.executable=\"java\" -Dexec.args=\"${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ${ONOS_PROPS}\""
-
- #${MVN} exec:exec -Dexec.executable="java" -Dexec.args="${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ${ONOS_PROPS}" > ${LOGDIR}/onos.`hostname`.stdout 2>${LOGDIR}/onos.`hostname`.stderr &
java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp ${JAVA_CP} ${MAIN_CLASS} -cf ${ONOS_PROPS} > ${LOGDIR}/onos.`hostname`.stdout 2>${LOGDIR}/onos.`hostname`.stderr &
echo "Waiting for ONOS to start..."
diff --git a/start-ramcloud.sh b/start-ramcloud-coordinator.sh
similarity index 60%
rename from start-ramcloud.sh
rename to start-ramcloud-coordinator.sh
index 161dc62..6a4232e 100755
--- a/start-ramcloud.sh
+++ b/start-ramcloud-coordinator.sh
@@ -1,12 +1,15 @@
#!/bin/bash
+export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${HOME}/ramcloud/bindings/java/edu/stanford/ramcloud:${HOME}/ramcloud/obj.blueprint-java
+
# Set paths
ONOS_HOME=`dirname $0`
RAMCLOUD_DIR=${HOME}/ramcloud
-LOGDIR=${ONOS_HOME}/ONOS/onos-logs
-RAMCLOUD_LOG=${LOGDIR}/ramcloud.`hostname`.log
-RAMCLOUD_COORDINATOR="fast+udp:host=10.128.4.104,port=12246"
-RAMCLOUD_SERVER="fast+udp:host=10.128.100.35,port=12242"
+LOGDIR=${ONOS_HOME}/onos-logs
+RAMCLOUD_LOG=${LOGDIR}/ramcloud.coordinator.`hostname`.log
+coordinatorip=`grep coordinatorIp ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3`
+coordinatorport=`grep coordinatorPort ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3`
+RAMCLOUD_COORDINATOR=`echo $coordinatorip","$coordinatorport`
function lotate {
logfile=$1
@@ -31,14 +34,13 @@
fi
# Run ramcloud
- echo "Starting ramcloud"
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${HOME}/ramcloud/bindings/java/edu/stanford/ramcloud:${HOME}/ramcloud/obj.blueprint-java
- $RAMCLOUD_DIR/obj/server -M -r 0 -L $RAMCLOUD_SERVER -C $RAMCLOUD_COORDINATOR > $RAMCLOUD_LOG 2>&1 &
+ echo "Starting ramcloud coordinator"
+ $RAMCLOUD_DIR/obj.blueprint-java/coordinator -L $RAMCLOUD_COORDINATOR > $RAMCLOUD_LOG 2>&1 &
}
function stop {
# Kill the existing processes
- capid=`ps -edalf |grep ramcloud |grep obj/server | awk '{print $4}'`
+ capid=`pgrep coordinator | awk '{print $1}'`
pids="$capid"
for p in ${pids}; do
if [ x$p != "x" ]; then
@@ -70,8 +72,8 @@
# deldb
# ;;
status)
- n=`ps -edalf |grep ramcloud |grep obj/server | wc -l`
- echo "$n ramcloud server running"
+ n=`pgrep -f obj.blueprint-java/coordinator | wc -l`
+ echo "$n ramcloud coordinator is running"
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
diff --git a/start-ramcloud-server.sh b/start-ramcloud-server.sh
new file mode 100755
index 0000000..a644837
--- /dev/null
+++ b/start-ramcloud-server.sh
@@ -0,0 +1,85 @@
+#!/bin/bash
+
+ulimit -c unlimited
+export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${HOME}/ramcloud/bindings/java/edu/stanford/ramcloud:${HOME}/ramcloud/obj.blueprint-java
+
+# Set paths
+ONOS_HOME=`dirname $0`
+RAMCLOUD_DIR=${HOME}/ramcloud
+LOGDIR=${ONOS_HOME}/onos-logs
+RAMCLOUD_LOG=${LOGDIR}/ramcloud.server.`hostname`.log
+coordinatorip=`grep coordinatorIp ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3`
+coordinatorport=`grep coordinatorPort ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3`
+RAMCLOUD_COORDINATOR=`echo $coordinatorip","$coordinatorport`
+serverip=`grep serverIp ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3`
+serverport=`grep serverPort ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3`
+RAMCLOUD_SERVER=`echo $serverip","$serverport`
+
+function lotate {
+ logfile=$1
+ nr_max=${2:-10}
+ if [ -f $logfile ]; then
+ for i in `seq $(expr $nr_max - 1) -1 1`; do
+ if [ -f ${logfile}.${i} ]; then
+ mv -f ${logfile}.${i} ${logfile}.`expr $i + 1`
+ fi
+ done
+ mv $logfile $logfile.1
+ fi
+}
+
+function start {
+ if [ ! -d ${LOGDIR} ]; then
+ mkdir -p ${LOGDIR}
+ fi
+ echo "rotate log: $log"
+ if [ -f $RAMCLOUD_LOG ]; then
+ lotate $RAMCLOUD_LOG
+ fi
+
+ # Run ramcloud
+ echo "Starting ramcloud"
+ $RAMCLOUD_DIR/obj.blueprint-java/server -M -L $RAMCLOUD_SERVER -C $RAMCLOUD_COORDINATOR --detectFailures 0 > $RAMCLOUD_LOG 2>&1 &
+}
+
+function stop {
+ # Kill the existing processes
+ capid=`pgrep -f obj.blueprint-java/server | awk '{print $1}'`
+ pids="$capid"
+ for p in ${pids}; do
+ if [ x$p != "x" ]; then
+ kill -KILL $p
+ echo "Killed existing prosess (pid: $p)"
+ fi
+ done
+}
+
+function deldb {
+# # Delete the berkeley db database
+ if [ -d "/tmp/ramcloud.conf" ]; then
+ echo "deleting berkeley db dir"
+ sudo rm -rf /tmp/ramcloud.conf
+ fi
+}
+
+case "$1" in
+ start)
+ deldb
+ cp $ONOS_HOME/conf/ramcloud.conf /tmp
+ stop
+ start
+ ;;
+ stop)
+ stop
+ ;;
+# deldb)
+# deldb
+# ;;
+ status)
+ n=`pgrep -f obj.blueprint-java/server | wc -l`
+ echo "$n ramcloud server running"
+ ;;
+ *)
+ echo "Usage: $0 {start|stop|restart|status}"
+ exit 1
+esac
diff --git a/start-rest.sh b/start-rest.sh
index 910eb41..94bbd46 100755
--- a/start-rest.sh
+++ b/start-rest.sh
@@ -57,6 +57,10 @@
function start {
lotate $REST_LOG 10
cd $WEBDIR
+ # Make log dir for iperf log files
+ if [ ! -d log ]; then
+ mkdir log
+ fi
$restscript > $REST_LOG 2>&1 &
}
diff --git a/test-network/mininet/dev_network_edge.py b/test-network/mininet/dev_network_edge.py
index 29be6ad..acc5d0d 100755
--- a/test-network/mininet/dev_network_edge.py
+++ b/test-network/mininet/dev_network_edge.py
@@ -113,7 +113,6 @@
# controllers.append(rc)
#net.controllers=controllers
- net.build()
host = []
for i in range (NR_NODES):
diff --git a/test-network/mininet/dev_network_edge_2.py b/test-network/mininet/dev_network_edge_2.py
index 50dc00c..553b376 100755
--- a/test-network/mininet/dev_network_edge_2.py
+++ b/test-network/mininet/dev_network_edge_2.py
@@ -113,7 +113,6 @@
# controllers.append(rc)
#net.controllers=controllers
- net.build()
host = []
for i in range (NR_NODES):
diff --git a/web/js/onos-topology.js b/web/js/onos-topology.js
index 3772127..d086f6a 100644
--- a/web/js/onos-topology.js
+++ b/web/js/onos-topology.js
@@ -222,8 +222,23 @@
return changed
}
+ function nr_active_sw(){
+ var n=0;
+ var nodes = force.nodes();
+ for(var i=0;i<nodes.length;i++){
+ if(nodes[i].group!=0)
+ n++;
+ };
+ return n;
+ }
+
function draw(force, path, circle, text){
force.stop();
+ svg.append("svg:text")
+ .attr("x", 50)
+ .attr("y", 20)
+ .text(function(){return "Switch: " + force.nodes().length + " (Active: " + nr_active_sw() + ")/ Link: " + force.links().length});
+
path.enter().append("svg:path")
.attr("class", function(d) { return "link"; })
.attr("marker-end", function(d) {
diff --git a/web/onos-topology.html b/web/onos-topology.html
index 5834521..b4e5097 100644
--- a/web/onos-topology.html
+++ b/web/onos-topology.html
@@ -43,7 +43,7 @@
<path d="M0,-5L10,0L0,5" fill="red" stroke="red"/>
</marker>
</defs>
-<h1>ONOS Sprint 4 Demo GUI</h1>
+<h1>ONOS Simple Topology GUI</h1>
<h2>Controller Status</h2>
<div id="servers"></div>
<div id="onos-status"></div>
diff --git a/web/topology_rest.py b/web/topology_rest.py
index 38dba5d..0b0ab01 100755
--- a/web/topology_rest.py
+++ b/web/topology_rest.py
@@ -8,8 +8,8 @@
import io
import time
import random
-
import re
+from urllib2 import Request, urlopen, URLError, HTTPError
from flask import Flask, json, Response, render_template, make_response, request
@@ -114,132 +114,131 @@
## Proxy ##
@app.route("/proxy/gui/link/<cmd>/<src_dpid>/<src_port>/<dst_dpid>/<dst_port>")
def proxy_link_change(cmd, src_dpid, src_port, dst_dpid, dst_port):
+ url = "%s/gui/link/%s/%s/%s/%s/%s" % (ONOS_GUI3_CONTROL_HOST, cmd, src_dpid, src_port, dst_dpid, dst_port)
try:
- command = "curl -s %s/gui/link/%s/%s/%s/%s/%s" % (ONOS_GUI3_CONTROL_HOST, cmd, src_dpid, src_port, dst_dpid, dst_port)
- print command
- result = os.popen(command).read()
+ response = urlopen(url)
+ result = response.read()
except:
- print "REST IF has issue"
- exit
+ result = ""
+ print "REST IF has issue %s" % url
resp = Response(result, status=200, mimetype='application/json')
return resp
@app.route("/proxy/gui/switchctrl/<cmd>")
def proxy_switch_controller_setting(cmd):
+ url = "%s/gui/switchctrl/%s" % (ONOS_GUI3_CONTROL_HOST, cmd)
try:
- command = "curl -s %s/gui/switchctrl/%s" % (ONOS_GUI3_CONTROL_HOST, cmd)
- print command
- result = os.popen(command).read()
+ response = urlopen(url)
+ result = response.read()
except:
- print "REST IF has issue"
- exit
+ result = ""
+ print "REST IF has issue %s" % url
resp = Response(result, status=200, mimetype='application/json')
return resp
@app.route("/proxy/gui/switch/<cmd>/<dpid>")
def proxy_switch_status_change(cmd, dpid):
+ url = "%s/gui/switch/%s/%s" % (ONOS_GUI3_CONTROL_HOST, cmd, dpid)
try:
- command = "curl -s %s/gui/switch/%s/%s" % (ONOS_GUI3_CONTROL_HOST, cmd, dpid)
- print command
- result = os.popen(command).read()
+ response = urlopen(url)
+ result = response.read()
except:
- print "REST IF has issue"
- exit
+ result = ""
+ print "REST IF has issue %s" % url
resp = Response(result, status=200, mimetype='application/json')
return resp
@app.route("/proxy/gui/controller/<cmd>/<controller_name>")
def proxy_controller_status_change(cmd, controller_name):
+ url = "%s/gui/controller/%s/%s" % (ONOS_GUI3_CONTROL_HOST, cmd, controller_name)
try:
- command = "curl -s %s/gui/controller/%s/%s" % (ONOS_GUI3_CONTROL_HOST, cmd, controller_name)
- print command
- result = os.popen(command).read()
+ response = urlopen(url)
+ result = response.read()
except:
- print "REST IF has issue"
- exit
-
+ result = ""
+ print "REST IF has issue %s" % url
+
resp = Response(result, status=200, mimetype='application/json')
return resp
@app.route("/proxy/gui/addflow/<src_dpid>/<src_port>/<dst_dpid>/<dst_port>/<srcMAC>/<dstMAC>")
def proxy_add_flow(src_dpid, src_port, dst_dpid, dst_port, srcMAC, dstMAC):
try:
- command = "curl -s %s/gui/addflow/%s/%s/%s/%s/%s/%s" % (ONOS_GUI3_CONTROL_HOST, src_dpid, src_port, dst_dpid, dst_port, srcMAC, dstMAC)
- print command
- result = os.popen(command).read()
+ url = "%s/gui/addflow/%s/%s/%s/%s/%s/%s" % (ONOS_GUI3_CONTROL_HOST, src_dpid, src_port, dst_dpid, dst_port, srcMAC, dstMAC)
+ #print "proxy gui addflow " + url
+ (code, result) = get_json(url)
except:
- print "REST IF has issue"
- exit
+ print "REST IF has issue %s" % url
+ print "Result %s" % result
+ exit()
resp = Response(result, status=200, mimetype='application/json')
return resp
@app.route("/proxy/gui/delflow/<flow_id>")
def proxy_del_flow(flow_id):
+ url = "%s/gui/delflow/%s" % (ONOS_GUI3_CONTROL_HOST, flow_id)
try:
- command = "curl -s %s/gui/delflow/%s" % (ONOS_GUI3_CONTROL_HOST, flow_id)
- print command
- result = os.popen(command).read()
+ response = urlopen(url)
+ result = response.read()
except:
- print "REST IF has issue"
- exit
+ result = ""
+ print "REST IF has issue %s" % url
resp = Response(result, status=200, mimetype='application/json')
return resp
@app.route("/proxy/gui/iperf/start/<flow_id>/<duration>/<samples>")
def proxy_iperf_start(flow_id,duration,samples):
+ url = "%s/gui/iperf/start/%s/%s/%s" % (ONOS_GUI3_CONTROL_HOST, flow_id, duration, samples)
try:
- command = "curl -m 40 -s %s/gui/iperf/start/%s/%s/%s" % (ONOS_GUI3_CONTROL_HOST, flow_id, duration, samples)
- print command
- result = os.popen(command).read()
+ response = urlopen(url)
+ result = response.read()
except:
- print "REST IF has issue"
- exit
+ result = ""
+ print "REST IF has issue %s" % url
resp = Response(result, status=200, mimetype='application/json')
return resp
@app.route("/proxy/gui/iperf/rate/<flow_id>")
def proxy_iperf_rate(flow_id):
+ url = "%s/gui/iperf/rate/%s" % (ONOS_GUI3_CONTROL_HOST, flow_id)
try:
- command = "curl -s %s/gui/iperf/rate/%s" % (ONOS_GUI3_CONTROL_HOST, flow_id)
- print command
- result = os.popen(command).read()
+ response = urlopen(url)
+ result = response.read()
except:
- print "REST IF has issue"
- exit
+ result = ""
+ print "REST IF has issue %s" % url
resp = Response(result, status=200, mimetype='application/json')
return resp
@app.route("/proxy/gui/reset")
def proxy_gui_reset():
- result = ""
+ url = "%s/gui/reset" % (ONOS_GUI3_CONTROL_HOST)
try:
- command = "curl -m 300 -s %s/gui/reset" % (ONOS_GUI3_CONTROL_HOST)
- print command
- result = os.popen(command).read()
+ response = urlopen(url)
+ result = response.read()
except:
- print "REST IF has issue"
- exit
+ result = ""
+ print "REST IF has issue %s" % url
resp = Response(result, status=200, mimetype='application/json')
return resp
@app.route("/proxy/gui/scale")
def proxy_gui_scale():
- result = ""
+ url = "%s/gui/scale" % (ONOS_GUI3_CONTROL_HOST)
try:
- command = "curl -m 300 -s %s/gui/scale" % (ONOS_GUI3_CONTROL_HOST)
- print command
- result = os.popen(command).read()
+ response = urlopen(url)
+ result = response.read()
except:
- print "REST IF has issue"
- exit
+ result = ""
+ print "REST IF has issue %s" % url
resp = Response(result, status=200, mimetype='application/json')
return resp
@@ -247,19 +246,20 @@
###### ONOS REST API ##############################
## Worker Func ###
def get_json(url):
- code = 200
+ code = 200;
try:
- command = "curl -m 60 -s %s" % (url)
- result = os.popen(command).read()
- parsedResult = json.loads(result)
- if type(parsedResult) == 'dict' and parsedResult.has_key('code'):
- print "REST %s returned code %s" % (command, parsedResult['code'])
- code=500
- except:
- print "REST IF %s has issue" % command
+ response = urlopen(url)
+ except URLError, e:
+ print "get_json: REST IF %s has issue. Reason: %s" % (url, e.reason)
result = ""
- code = 500
+ return (500, result)
+ except HTTPError, e:
+ print "get_json: REST IF %s has issue. Code %s" % (url, e.code)
+ result = ""
+ return (e.code, result)
+ result = response.read()
+# parsedResult = json.loads(result)
return (code, result)
def pick_host():
@@ -354,14 +354,13 @@
@app.route('/topology', methods=['GET'])
def topology_for_gui():
try:
- command = "curl -s \'http://%s:%s/wm/onos/topology/switches/all/json\'" % (RestIP, RestPort)
- result = os.popen(command).read()
+ url="http://%s:%s/wm/onos/topology/switches/all/json" % (RestIP, RestPort)
+ (code, result) = get_json(url)
parsedResult = json.loads(result)
except:
- log_error("REST IF has issue: %s" % command)
+ log_error("REST IF has issue: %s" % url)
log_error("%s" % result)
return
-# sys.exit(0)
topo = {}
switches = []
@@ -382,11 +381,11 @@
switches.append(sw)
try:
- command = "curl -s \'http://%s:%s/wm/onos/registry/switches/json\'" % (RestIP, RestPort)
- result = os.popen(command).read()
+ url="http://%s:%s/wm/onos/registry/switches/json" % (RestIP, RestPort)
+ (code, result) = get_json(url)
parsedResult = json.loads(result)
except:
- log_error("REST IF has issue: %s" % command)
+ log_error("REST IF has issue: %s" % url)
log_error("%s" % result)
for key in parsedResult:
@@ -397,35 +396,12 @@
if switches[sw_id]['group'] != 0:
switches[sw_id]['group'] = controllers.index(ctrl) + 1
-# try:
-# v1 = "00:00:00:00:00:0a:0d:00"
-# v1 = "00:00:00:00:00:0d:00:d1"
-# p1=1
-# v2 = "00:00:00:00:00:0b:0d:03"
-# v2 = "00:00:00:00:00:0d:00:d3"
-# p2=1
-# command = "curl -s http://%s:%s/wm/onos/topology/route/%s/%s/%s/%s/json" % (RestIP, RestPort, v1, p1, v2, p2)
-# result = os.popen(command).read()
-# parsedResult = json.loads(result)
-# except:
-# log_error("No route")
-# parsedResult = {}
-
- #path = []
- #if parsedResult.has_key('flowEntries'):
- # flowEntries= parsedResult['flowEntries']
- # for i, v in enumerate(flowEntries):
- # if i < len(flowEntries) - 1:
- # sdpid= flowEntries[i]['dpid']['value']
- # ddpid = flowEntries[i+1]['dpid']['value']
- # path.append( (sdpid, ddpid))
-
try:
- command = "curl -s \'http://%s:%s/wm/onos/topology/links/json\'" % (RestIP, RestPort)
- result = os.popen(command).read()
+ url = "http://%s:%s/wm/onos/topology/links/json" % (RestIP, RestPort)
+ (code, result) = get_json(url)
parsedResult = json.loads(result)
except:
- log_error("REST IF has issue: %s" % command)
+ log_error("REST IF has issue: %s" % url)
log_error("%s" % result)
return
# sys.exit(0)
@@ -457,19 +433,16 @@
resp = Response(js, status=200, mimetype='application/json')
return resp
-#@app.route("/wm/floodlight/topology/toporoute/00:00:00:00:00:a1/2/00:00:00:00:00:c1/3/json")
-#@app.route("/wm/floodlight/topology/toporoute/<srcdpid>/<srcport>/<destdpid>/<destport>/json")
@app.route("/wm/floodlight/topology/toporoute/<v1>/<p1>/<v2>/<p2>/json")
def shortest_path(v1, p1, v2, p2):
try:
- command = "curl -s \'http://%s:%s/wm/onos/topology/switches/all/json\'" % (RestIP, RestPort)
- result = os.popen(command).read()
+ url = "http://%s:%s/wm/onos/topology/switches/all/json" % (RestIP, RestPort)
+ (code, result) = get_json(url)
parsedResult = json.loads(result)
except:
log_error("REST IF has issue: %s" % command)
log_error("%s" % result)
return
-# sys.exit(0)
topo = {}
switches = []
@@ -494,30 +467,28 @@
switches.append(sw)
try:
- command = "curl -s http://%s:%s/wm/onos/topology/route/%s/%s/%s/%s/json" % (RestIP, RestPort, v1, p1, v2, p2)
- result = os.popen(command).read()
+ url = "http://%s:%s/wm/onos/topology/route/%s/%s/%s/%s/json" % (RestIP, RestPort, v1, p1, v2, p2)
+ (code, result) = get_json(url)
parsedResult = json.loads(result)
except:
log_error("No route")
parsedResult = []
-# exit(1)
path = [];
for i, v in enumerate(parsedResult):
if i < len(parsedResult) - 1:
- sdpid= parsedResult[i]['switch']
- ddpid = parsedResult[i+1]['switch']
+ sdpid= parsedResult['flowEntries'][i]['dpid']['value']
+ ddpid= parsedResult['flowEntries'][i+1]['dpid']['value']
path.append( (sdpid, ddpid))
try:
- command = "curl -s \'http://%s:%s/wm/onos/topology/links/json\'" % (RestIP, RestPort)
- result = os.popen(command).read()
+ url = "http://%s:%s/wm/onos/topology/links/json" % (RestIP, RestPort)
+ (code, result) = get_json(url)
parsedResult = json.loads(result)
except:
log_error("REST IF has issue: %s" % command)
log_error("%s" % result)
return
-# sys.exit(0)
for v in parsedResult:
link = {}
@@ -548,13 +519,11 @@
@app.route("/wm/floodlight/core/controller/switches/json")
def query_switch():
try:
- command = "curl -s \'http://%s:%s/wm/onos/topology/switches/all/json\'" % (RestIP, RestPort)
-# http://localhost:8080/wm/onos/topology/switches/active/json
- print command
- result = os.popen(command).read()
+ url = "http://%s:%s/wm/onos/topology/switches/all/json" % (RestIP, RestPort)
+ (code, result) = get_json(url)
parsedResult = json.loads(result)
except:
- log_error("REST IF has issue: %s" % command)
+ log_error("REST IF has issue: %s" % url)
log_error("%s" % result)
return
# sys.exit(0)
@@ -577,49 +546,6 @@
resp = Response(js, status=200, mimetype='application/json')
return resp
-@app.route("/wm/floodlight/device/")
-def devices():
- try:
- command = "curl -s http://%s:%s/graphs/%s/vertices\?key=type\&value=device" % (RestIP, RestPort, DBName)
- result = os.popen(command).read()
- parsedResult = json.loads(result)['results']
- except:
- log_error("REST IF has issue: %s" % command)
- log_error("%s" % result)
- return
-# sys.exit(0)
-
- devices = []
- for v in parsedResult:
- dl_addr = v['dl_addr']
- nw_addr = v['nw_addr']
- vertex = v['_id']
- mac = []
- mac.append(dl_addr)
- ip = []
- ip.append(nw_addr)
- device = {}
- device['entryClass']="DefaultEntryClass"
- device['mac']=mac
- device['ipv4']=ip
- device['vlan']=[]
- device['lastSeen']=0
- attachpoints =[]
-
- port, dpid = deviceV_to_attachpoint(vertex)
- attachpoint = {}
- attachpoint['port']=port
- attachpoint['switchDPID']=dpid
- attachpoints.append(attachpoint)
- device['attachmentPoint']=attachpoints
- devices.append(device)
-
- js = json.dumps(devices)
- resp = Response(js, status=200, mimetype='application/json')
- return resp
-
-#{"entityClass":"DefaultEntityClass","mac":["7c:d1:c3:e0:8c:a3"],"ipv4":["192.168.2.102","10.1.10.35"],"vlan":[],"attachmentPoint":[{"port":13,"switchDPID":"00:01:00:12:e2:78:32:44","errorStatus":null}],"lastSeen":1357333593496}
-
## return fake stat for now
@app.route("/wm/floodlight/core/switch/<switchId>/<statType>/json")
def switch_stat(switchId, statType):
@@ -638,68 +564,19 @@
resp = Response(js, status=200, mimetype='application/json')
return resp
-
-@app.route("/wm/onos/linkdiscovery/links/json")
-def query_links():
- try:
- command = 'curl -s http://%s:%s/graphs/%s/vertices?key=type\&value=port' % (RestIP, RestPort, DBName)
- print command
- result = os.popen(command).read()
- parsedResult = json.loads(result)['results']
- except:
- log_error("REST IF has issue: %s" % command)
- log_error("%s" % result)
- return
-# sys.exit(0)
-
- debug("query_links %s" % command)
-# pp.pprint(parsedResult)
- sport = []
- links = []
- for v in parsedResult:
- srcport = v['_id']
- try:
- command = "curl -s http://%s:%s/graphs/%s/vertices/%d/out?_label=link" % (RestIP, RestPort, DBName, srcport)
- print command
- result = os.popen(command).read()
- linkResults = json.loads(result)['results']
- except:
- log_error("REST IF has issue: %s" % command)
- log_error("%s" % result)
- return
-# sys.exit(0)
-
- for p in linkResults:
- if p.has_key('type') and p['type'] == "port":
- dstport = p['_id']
- (sport, sdpid) = portV_to_port_dpid(srcport)
- (dport, ddpid) = portV_to_port_dpid(dstport)
- link = {}
- link["src-switch"]=sdpid
- link["src-port"]=sport
- link["src-port-state"]=0
- link["dst-switch"]=ddpid
- link["dst-port"]=dport
- link["dst-port-state"]=0
- link["type"]="internal"
- links.append(link)
-
-# pp.pprint(links)
- js = json.dumps(links)
- resp = Response(js, status=200, mimetype='application/json')
- return resp
-
@app.route("/controller_status")
def controller_status():
-# onos_check="ssh -i ~/.ssh/onlabkey.pem %s ONOS/start-onos.sh status | awk '{print $1}'"
- onos_check="cd; onos status | grep %s | awk '{print $2}'"
- #cassandra_check="ssh -i ~/.ssh/onlabkey.pem %s ONOS/start-cassandra.sh status"
+ url= "http://%s:%d/wm/onos/registry/controllers/json" % (RestIP, RestPort)
+ (code, result) = get_json(url)
+ parsedResult = json.loads(result)
cont_status=[]
for i in controllers:
status={}
- onos=os.popen(onos_check % i).read()[:-1]
-# onos=os.popen(onos_check % (i, i.lower())).read()[:-1]
+ if i in parsedResult:
+ onos=1
+ else:
+ onos=0
status["name"]=i
status["onos"]=onos
status["cassandra"]=0
@@ -709,6 +586,7 @@
resp = Response(js, status=200, mimetype='application/json')
return resp
+
### Command ###
@app.route("/gui/controller/<cmd>/<controller_name>")
def controller_status_change(cmd, controller_name):
@@ -989,17 +867,16 @@
#http://localhost:9000/gui/iperf/start/<flow_id>/<duration>
@app.route("/gui/iperf/start/<flow_id>/<duration>/<samples>")
def iperf_start(flow_id,duration,samples):
+ url = "http://%s:%s/wm/onos/flows/get/%s/json" % (RestIP, RestPort, flow_id)
try:
- command = "curl -s \'http://%s:%s/wm/onos/flows/get/%s/json\'" % (RestIP, RestPort, flow_id)
- print command
- result = os.popen(command).read()
+ response = urlopen(url)
+ result = response.read()
if len(result) == 0:
print "No Flow found"
return "Flow %s not found" % (flow_id);
except:
- print "REST IF has issue"
- return "REST IF has issue"
- exit
+ print "REST IF has issue %s" % url
+ return "REST IF has issue %s" % url
parsedResult = json.loads(result)
@@ -1054,15 +931,14 @@
#http://localhost:9000/gui/iperf/rate/<flow_id>
@app.route("/gui/iperf/rate/<flow_id>")
def iperf_rate(flow_id):
+ url = "http://%s:%s/wm/onos/flows/get/%s/json" % (RestIP, RestPort, flow_id)
try:
- command = "curl -s \'http://%s:%s/wm/onos/flows/get/%s/json\'" % (RestIP, RestPort, flow_id)
- print command
- result = os.popen(command).read()
+ response = urlopen(url)
+ result = response.read()
if len(result) == 0:
- resp = Response(result, status=400, mimetype='text/html')
- return "no such iperf flow (flowid %s)" % flow_id;
+ return "no such iperf flow (flowid %s)" % flow_id
except:
- print "REST IF has issue"
+ print "REST IF has issue %s" % url
exit
parsedResult = json.loads(result)
@@ -1082,12 +958,13 @@
else:
host = controllers[hostid-1]
+ url="http://%s:%s/log/iperfsvr_%s.out" % (host, 9000, flow_id)
try:
- command = "curl -s http://%s:%s/log/iperfsvr_%s.out" % (host, 9000, flow_id)
- print command
- result = os.popen(command).read()
+ response = urlopen(url)
+ result = response.read()
except:
- exit
+ print "REST IF has issue %s" % url
+ return
if re.match("Cannot", result):
resp = Response(result, status=400, mimetype='text/html')
@@ -1101,25 +978,24 @@
read_config()
read_link_def()
if len(sys.argv) > 1 and sys.argv[1] == "-d":
-# add_flow("00:00:00:00:00:00:02:02", 1, "00:00:00:00:00:00:03:02", 1, "00:00:00:00:02:02", "00:00:00:00:03:0c")
-# link_change("up", "00:00:00:00:ba:5e:ba:11", 1, "00:00:00:00:00:00:00:00", 1)
-# link_change("down", "00:00:20:4e:7f:51:8a:35", 1, "00:00:00:00:00:00:00:00", 1)
-# link_change("up", "00:00:00:00:00:00:02:03", 1, "00:00:00:00:00:00:00:00", 1)
-# link_change("down", "00:00:00:00:00:00:07:12", 1, "00:00:00:00:00:00:00:00", 1)
-# print "-- query all switches --"
-# query_switch()
-# print "-- query topo --"
-# topology_for_gui()
-# link_change(1,2,3,4)
- print "-- query all links --"
-# query_links()
-# print "-- query all devices --"
-# devices()
-# iperf_start(1,10,15)
-# iperf_rate(1)
-# switches()
-# add_flow(1,2,3,4,5,6)
- reset_demo()
+ # for debugging
+ #add_flow("00:00:00:00:00:00:02:02", 1, "00:00:00:00:00:00:03:02", 1, "00:00:00:00:02:02", "00:00:00:00:03:0c")
+ #proxy_link_change("up", "00:00:00:00:ba:5e:ba:11", 1, "00:00:00:00:00:00:00:00", 1)
+ #proxy_link_change("down", "00:00:20:4e:7f:51:8a:35", 1, "00:00:00:00:00:00:00:00", 1)
+ #proxy_link_change("up", "00:00:00:00:00:00:02:03", 1, "00:00:00:00:00:00:00:00", 1)
+ #proxy_link_change("down", "00:00:00:00:00:00:07:12", 1, "00:00:00:00:00:00:00:00", 1)
+ #print "-- query all switches --"
+ #query_switch()
+ #print "-- query topo --"
+ #topology_for_gui()
+ ##print "-- query all links --"
+ ##query_links()
+ #print "-- query all devices --"
+ #devices()
+ #links()
+ #switches()
+ #reset_demo()
+ pass
else:
app.debug = True
app.run(threaded=True, host="0.0.0.0", port=9000)