Skip to content
Browse files

first scala stuff

  • Loading branch information...
1 parent db5d12e commit 85f23b76ce5d49e2a4c4f674ab3ebe0d248b0a88 @ticktock committed
Showing with 144 additions and 3 deletions.
  1. +61 −3 pom.xml
  2. +83 −0 src/main/scala/org/apache/activemq/store/cassandra/CassandraClient.scala
View
64 pom.xml
@@ -78,6 +78,58 @@
</testResources>
<plugins>
<plugin>
+ <groupId>org.scala-tools</groupId>
+ <artifactId>maven-scala-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>scala-compile-first</id>
+ <phase>process-resources</phase>
+ <goals>
+ <goal>add-source</goal>
+ <goal>compile</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>scala-test-compile</id>
+ <phase>process-test-resources</phase>
+ <goals>
+ <goal>testCompile</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <!-- no luck <vscaladocVersion>1.1</vscaladocVersion> -->
+ <scalaVersion>${scala.version}</scalaVersion>
+ </configuration>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.scala-lang</groupId>
+ <artifactId>scala-library</artifactId>
+ <version>${scala.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.scala-lang</groupId>
+ <artifactId>scala-compiler</artifactId>
+ <version>${scala.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
@@ -113,6 +165,12 @@
<dependencies>
<dependency>
+ <groupId>org.scala-lang</groupId>
+ <artifactId>scala-library</artifactId>
+ <version>${scala.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-core</artifactId>
<version>${activemq.version}</version>
@@ -139,9 +197,9 @@
</dependency>
<dependency>
- <groupId>org.scala-lang</groupId>
- <artifactId>scala-library</artifactId>
- <version>${scala.version}</version>
+ <groupId>com.shorrockin</groupId>
+ <artifactId>cascal</artifactId>
+ <version>1.2-SNAPSHOT</version>
</dependency>
View
83 src/main/scala/org/apache/activemq/store/cassandra/CassandraClient.scala
@@ -0,0 +1,83 @@
+package org.apache.activemq.store.cassandra.scala
+
+import com.shorrockin.cascal.session._
+import reflect.BeanProperty
+import org.apache.activemq.store.cassandra.{*}
+import org.apache.activemq.store.cassandra.scala.*
+
+class CassandraClient() {
+ @BeanProperty var cassandraHost: String = _
+ @BeanProperty var cassandraPort: int = _
+ @BeanProperty var cassandraTimeout: int = _
+
+
+
+ protected var pool: SessionPool = null
+
+ def start() = {
+ val params = new PoolParams(20, ExhaustionPolicy.Fail, 500L, 6, 2)
+ var hosts = Host(cassandraHost, cassandraPort, cassandraTimeout) :: Nil
+ pool = new SessionPool(hosts, params, Consistency.Quorum)
+ }
+
+ def stop() = {
+ pool.close
+ }
+
+ protected def withSession[E](block: Session => E): E = {
+ val session = pool.checkout
+ try {
+ block(session)
+ } finally {
+ pool.checkin(session)
+ }
+ }
+
+ def getDestinationCount(): int = {
+ withSession {
+ session =>
+ session.get(
+ KEYSPACE \ BROKER_FAMILY \ BROKER_KEY \ BROKER_DESTINATION_COUNT
+ )
+ match {
+ case Some(x) =>
+ val rc: = x.value
+ rc.key = id
+ Some(rc)
+ case None =>
+ None
+ }
+ }
+ }
+
+}
+
+object CassandraClient {
+ object Id {
+ val KEYSPACE = "MessageStore"
+ val BROKER_FAMILY = "Broker"
+ val BROKER_KEY = "Broker"
+ val BROKER_DESTINATION_COUNT = "destination-count"
+
+ val DESTINATIONS_FAMILY = "Destinations"
+ val DESTINATION_IS_TOPIC_COLUMN = "isTopic"
+ val DESTINATION_MAX_STORE_SEQUENCE_COLUMN = "max-store-sequence"
+ val DESTINATION_MAX_BROKER_SEQUENCE_COLUMN = "max-broker-sequence"
+ val DESTINATION_QUEUE_SIZE_COLUMN = "queue-size"
+
+
+ val MESSAGES_FAMILY = "Messages"
+
+ val MESSAGE_TO_STORE_ID_FAMILY = "MessageIdToStoreId"
+
+ val STORE_IDS_IN_USE_FAMILY = "StoreIdsInUse"
+
+
+ val SUBSCRIPTIONS_FAMILY = "Subscriptions"
+ val SUBSCRIPTIONS_SELECTOR_SUBCOLUMN = "selector"
+ val SUBSCRIPTIONS_LAST_ACK_SUBCOLUMN = "lastMessageAck"
+ val SUBSCRIPTIONS_SUB_DESTINATION_SUBCOLUMN = "subscribedDestination";
+
+ }
+
+}

0 comments on commit 85f23b7

Please sign in to comment.
Something went wrong with that request. Please try again.