You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2010/11/04 18:25:45 UTC
svn commit: r1031089 - in /activemq/activemq-apollo/trunk:
apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/ConfigStore.scala
apollo-scala/pom.xml
apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/BrokerSummaryDTO.scaml
Author: chirino
Date: Thu Nov 4 17:25:45 2010
New Revision: 1031089
URL: http://svn.apache.org/viewvc?rev=1031089&view=rev
Log:
Fixing broken scaml template and fixing config store auto reloading.
Modified:
activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/ConfigStore.scala
activemq/activemq-apollo/trunk/apollo-scala/pom.xml
activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/BrokerSummaryDTO.scaml
Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/ConfigStore.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/ConfigStore.scala?rev=1031089&r1=1031088&r2=1031089&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/ConfigStore.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/ConfigStore.scala Thu Nov 4 17:25:45 2010
@@ -30,6 +30,7 @@ import XmlCodec._
import org.apache.activemq.apollo.util._
import scala.util.continuations._
import org.fusesource.hawtdispatch.DispatchQueue
+import java.util.Arrays
object ConfigStore {
@@ -80,10 +81,10 @@ class FileConfigStore extends ConfigStor
object StoredBrokerModel {
def apply(config:BrokerDTO) = {
val data = marshall(config)
- new StoredBrokerModel(config.id, config.rev, data, Hasher.JENKINS.hash(data, data.length))
+ new StoredBrokerModel(config.id, config.rev, data, 0)
}
}
- case class StoredBrokerModel(id:String, rev:Int, data:Array[Byte], hash:Int)
+ case class StoredBrokerModel(id:String, rev:Int, data:Array[Byte], lastModified:Long)
var file:File = new File("activemq.xml")
@volatile
@@ -112,48 +113,48 @@ class FileConfigStore extends ConfigStor
def startup(onCompleted:Runnable) = {
- file = file.getCanonicalFile;
- file.getParentFile.mkdir
- // Find the latest rev
- val files = file.getParentFile.listFiles
- val regex = (Pattern.quote(file.getName+".")+"""(\d)$""").r
- var revs:List[Int] = Nil
- if( files!=null ) {
- for( file <- files) {
- file.getName match {
- case regex(ver)=>
- revs ::= Integer.parseInt(ver)
- case _ =>
- }
+ file = file.getCanonicalFile;
+ file.getParentFile.mkdir
+ // Find the latest rev
+ val files = file.getParentFile.listFiles
+ val regex = (Pattern.quote(file.getName+".")+"""(\d)$""").r
+ var revs:List[Int] = Nil
+ if( files!=null ) {
+ for( file <- files) {
+ file.getName match {
+ case regex(ver)=>
+ revs ::= Integer.parseInt(ver)
+ case _ =>
}
}
- revs = revs.sortWith((x,y)=> x < y)
+ }
+ revs = revs.sortWith((x,y)=> x < y)
- val last = revs.lastOption.map{ rev=>
- read(rev, fileRev(rev))
- } match {
- case None =>
- if( !file.exists ) {
- if( readOnly ) {
- throw new Exception("file does not exsit: "+file)
- } else {
- write(StoredBrokerModel(defaultConfig(1)))
- }
+ val last = revs.lastOption.map{ rev=>
+ read(rev, fileRev(rev))
+ } match {
+ case None =>
+ if( !file.exists ) {
+ if( readOnly ) {
+ throw new Exception("file does not exsit: "+file)
} else {
- if( readOnly ) {
- read(1, file)
- } else {
- write(read(1, file))
- }
+ write(StoredBrokerModel(defaultConfig(1)))
}
- case Some(x)=> x
- }
+ } else {
+ if( readOnly ) {
+ read(1, file)
+ } else {
+ write(read(1, file))
+ }
+ }
+ case Some(x)=> x
+ }
- dispatchQueue {
- latest = last
- schedualNextUpdateCheck
- onCompleted.run
- }
+ dispatchQueue {
+ latest = last
+ schedualNextUpdateCheck
+ onCompleted.run
+ }
}
@@ -193,18 +194,24 @@ class FileConfigStore extends ConfigStor
private def schedualNextUpdateCheck:Unit = dispatchQueue.after(1, TimeUnit.SECONDS) {
if( serviceState.isStarted ) {
- val latestHash = latest.hash+1
+ val lastModified = latest.lastModified
+ val latestData = latest.data
val nextRev = latest.rev+1
ioWorker {
try {
- val config = read(nextRev, file)
- if (latestHash != config.hash) {
- // TODO: do this in the controller so that it
- // has a chance to update the runtime too.
- val c = unmarshall(config.data)
- c.rev = config.rev
- dispatchQueue {
- putBroker(c)
+ val l = file.lastModified
+ if( l != lastModified ) {
+ val config = read(nextRev, file)
+ if ( !Arrays.equals(latestData, config.data) ) {
+ val c = unmarshall(config.data)
+ c.rev = config.rev
+ dispatchQueue {
+ putBroker(c)
+ }
+ } else {
+ dispatchQueue {
+ latest = StoredBrokerModel(latest.id, latest.rev, latest.data, l)
+ }
}
}
schedualNextUpdateCheck
@@ -226,18 +233,17 @@ class FileConfigStore extends ConfigStor
config
}
- private def read(rev:Int, file: File): StoredBrokerModel = {
+ private def read(rev:Int, file: File) ={
val data = IOHelper.readBytes(file)
val config = unmarshall(data) // validates the xml
- val hash = Hasher.JENKINS.hash(data, data.length)
- StoredBrokerModel(config.id, rev, data, hash)
+ StoredBrokerModel(config.id, rev, data, file.lastModified)
}
private def write(config:StoredBrokerModel) = {
// write to the files..
IOHelper.writeBinaryFile(file, config.data)
IOHelper.writeBinaryFile(fileRev(config.rev), config.data)
- config
+ StoredBrokerModel(config.id, config.rev, config.data, file.lastModified)
}
def unmarshall(in:Array[Byte], evalProps:Boolean=false) = {
Modified: activemq/activemq-apollo/trunk/apollo-scala/pom.xml
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-scala/pom.xml?rev=1031089&r1=1031088&r2=1031089&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-scala/pom.xml (original)
+++ activemq/activemq-apollo/trunk/apollo-scala/pom.xml Thu Nov 4 17:25:45 2010
@@ -93,7 +93,7 @@
<jvmArg>-Xss8m</jvmArg>
</jvmArgs>
<args>
- <arg>-optimise</arg>
+ <!-- <arg>-optimise</arg> -->
<arg>-deprecation</arg>
<arg>-P:continuations:enable</arg>
</args>
Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/BrokerSummaryDTO.scaml
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/BrokerSummaryDTO.scaml?rev=1031089&r1=1031088&r2=1031089&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/BrokerSummaryDTO.scaml (original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/BrokerSummaryDTO.scaml Thu Nov 4 17:25:45 2010
@@ -13,10 +13,10 @@
-# See the License for the specific language governing permissions and
-# limitations under the License.
+- val helper = new org.apache.activemq.apollo.web.resources.ViewHelper
+- import helper._
+
.breadcumbs
%a(href={strip_resolve(".")}) Back
--# - import it._
--# - val helper = new org.apache.activemq.apollo.web.resources.ViewHelper
--# - import helper._
.clear
\ No newline at end of file