Permalink
Browse files

Fixed the multi menu stuff and other minor tweaks

  • Loading branch information...
1 parent 6613322 commit 58ee9a05a3804009ae0750c2ba82c6bf0ca65ce8 @dpp dpp committed Mar 9, 2011
@@ -35,6 +35,13 @@ object LAScheduler extends Loggable {
@volatile var maxThreadPoolSize = threadPoolSize * 25
+ /**
+ * If it's Full, then create a ArrayBlockingQueue
+ * otherwith create a LinkedBlockingQueue. Default
+ * to Full(200000)
+ */
+ @volatile var blockingQueueSize: Box[Int] = Full(200000)
+
@volatile
var createExecutor: () => ILAExecute = () => {
new ILAExecute {
@@ -45,7 +52,11 @@ object LAScheduler extends Loggable {
maxThreadPoolSize,
60,
TimeUnit.SECONDS,
- new LinkedBlockingQueue)
+ blockingQueueSize match {
+ case Full(x) =>
+ new ArrayBlockingQueue(x)
+ case _ => new LinkedBlockingQueue
+ })
def execute(f: () => Unit): Unit =
es.execute(new Runnable{def run() {
@@ -47,13 +47,24 @@ sealed trait Schedule extends Loggable {
@volatile var threadPoolSize = 16 // issue 194
@volatile var maxThreadPoolSize = threadPoolSize * 25
+
+ /**
+ * If it's Full, then create a ArrayBlockingQueue
+ * otherwith create a LinkedBlockingQueue. Default
+ * to Full(200000)
+ */
+ @volatile var blockingQueueSize: Box[Int] = Full(200000)
@volatile var buildExecutor: () => ThreadPoolExecutor =
() => new ThreadPoolExecutor(threadPoolSize,
maxThreadPoolSize,
60,
TimeUnit.SECONDS,
- new LinkedBlockingQueue)
+ blockingQueueSize match {
+ case Full(x) =>
+ new ArrayBlockingQueue(x)
+ case _ => new LinkedBlockingQueue
+ })
@@ -63,7 +63,6 @@ object LdapSpec extends Specification("LDAP Specification") {
// because we don't want it using current directory under SBT
workingDir match {
case Full(d) =>
- println("ApacheDS Working dir = " + d)
val dir = new java.io.File(d)
dir.mkdirs
service.setWorkingDirectory(dir)
@@ -93,7 +92,6 @@ object LdapSpec extends Specification("LDAP Specification") {
// Inject the root entry if it does not already exist
if ( !service.getAdminSession().exists(partition.getSuffixDn)) {
- println("Adding root entry")
val rootEntry = service.newEntry(new LdapDN(ROOT_DN))
rootEntry.add( "objectClass", "top", "domain", "extensibleObject" );
rootEntry.add( "dc", "ldap" );
@@ -104,7 +102,6 @@ object LdapSpec extends Specification("LDAP Specification") {
ldap.start()
- println("Started LDAP server on port " + service_port)
}) must not(throwAn[Exception]).orSkipExample
}
@@ -142,7 +139,6 @@ object LdapSpec extends Specification("LDAP Specification") {
doAfterSpec {
ldap.stop()
service.shutdown()
- println("Stopped server")
// Clean up the working directory
def deleteTree(f : File) {
@@ -154,18 +150,15 @@ object LdapSpec extends Specification("LDAP Specification") {
}
tryo {
- println("Cleaning LDAP work directory")
workingDir.foreach { dir =>
deleteTree(new File(dir))
}
- println("LDAP work directory removed")
}
}
def addTestData() {
val username = new LdapDN("cn=Test User," + ROOT_DN)
if (! service.getAdminSession().exists(username)) {
- println(" Adding test user : " + username)
// Add a test user. This will be used for searching and binding
val entry = service.newEntry(username)
entry.add("objectClass", "person", "organizationalPerson")
@@ -43,18 +43,6 @@ object MapperSpec extends Specification("Mapper Specification") {
// DbProviders.asList
def providers = DbProviders.H2MemoryProvider :: DbProviders.DerbyProvider :: Nil
- /*
- private def logDBStuff(log: DBLog, len: Long) {
- println(" in log stuff "+log.getClass.getName)
- log match {
- case null =>
- case _ => println(log.allEntries)
- }
- }
-
- DB.addLogFunc(logDBStuff)
- */
-
def dbSetup() {
Schemifier.destroyTables_!!(ignoreLogger _, SampleModel, SampleTag, Dog, User, Mixer, Dog2)
Schemifier.schemify(true, ignoreLogger _, SampleModel, SampleTag, User, Dog, Mixer, Dog2)
@@ -145,7 +145,6 @@ object MongoFieldSpec extends Specification("MongoField Specification") with Mon
/*
"convert to JsExp" in {
mandatory.set(example)
- //println(mandatory.asJs)
mandatory.asJs mustEqual jsexp
}*/
@@ -168,7 +167,6 @@ object MongoFieldSpec extends Specification("MongoField Specification") with Mon
val session = new LiftSession("", randomString(20), Empty)
S.initIfUninitted(session) {
val formXml = mandatory.toForm
- //println(formXml)
formXml must notBeEmpty
formXml foreach { f =>
f.toString must beMatching(fp)
@@ -59,7 +59,6 @@ object JObjectParser {
case fields => JObject(fields)
}
case x => {
- println("match error (serialize): "+x.getClass+" "+x.toString)
JNothing
}
}
@@ -114,7 +113,7 @@ object JObjectParser {
case JString(null) => "null"
case JString(s) if (ObjectId.isValid(s)) => new ObjectId(s)
case JString(s) => s
- case _ => println("match error (renderValue): "+jv.getClass); ""
+ case _ => ""
}
// FIXME: This is not ideal.
@@ -46,9 +46,9 @@ object Comet extends DispatchSnippet with LazyLoggable {
private def buildComet(kids: NodeSeq) : NodeSeq = {
val theType: Box[String] = S.attr.~("type").map(_.text)
- val name: Box[String] = S.attr.~("name").map(_.text) orElse
- S.attr.~("metaname").map(_.text).flatMap(S.param) orElse
- S.attr.~("randomname").map(ignore => Helpers.nextFuncName)
+ val name: Box[String] = S.currentAttr("name") or
+ S.currentAttr("metaname").flatMap(S.param) or
+ S.currentAttr("randomname").map(ignore => Helpers.nextFuncName)
(for {ctx <- S.session} yield {
@@ -1167,7 +1167,6 @@ class Req(val path: ParsePath,
}
final case class RewriteRequest(path: ParsePath, requestType: RequestType, httpRequest: HTTPRequest)
-final case class RewriteResponse(path: ParsePath, params: Map[String, String], stopRewriting: Boolean)
/**
* The representation of an URI path
@@ -1180,6 +1179,10 @@ case class ParsePath(partPath: List[String], suffix: String, absolute: Boolean,
else partPath
}
+final case class RewriteResponse(path: ParsePath,
+ params: Map[String, String],
+ stopRewriting: Boolean)
+
/**
* Maintains the context of resolving the URL when cookies are disabled from container. It maintains
* low coupling such as code within request processing is not aware of the actual response that
@@ -1190,6 +1193,10 @@ object RewriteResponse {
def apply(path: List[String]) = new RewriteResponse(ParsePath(path, "", true, false), Map.empty, false)
+ def apply(path: List[String], stopRewriting: Boolean) =
+ new RewriteResponse(ParsePath(path, "", true, false),
+ Map.empty, stopRewriting)
+
def apply(path: List[String], suffix: String) = new RewriteResponse(ParsePath(path, suffix, true, false), Map.empty, false)
def apply(path: ParsePath, params: Map[String, String]) = new RewriteResponse(path, params, false)
@@ -37,10 +37,16 @@ trait Loc[T] {
def overrideValue: Box[T] = Empty
- object requestValue extends RequestVar[Box[T]](Empty) {
+ object requestValue extends RequestVar[Box[T]](defaultRequestValue) {
override val __nameSalt = randomString(10)
}
+ /**
+ * Override this if the default request value should
+ * be something other than Empty
+ */
+ protected def defaultRequestValue: Box[T] = Empty
+
/**
* When the menu item is displayed, what CSS class do we add to the
* node?
@@ -311,13 +317,14 @@ trait Loc[T] {
}
def doesMatch_?(req: Req): Boolean = {
- if (link.isDefinedAt(req)) {
+ (if (link.isDefinedAt(req)) {
link(req) match {
case Full(x) if testAllParams(allParams, req) => x
case Full(x) => false
case x => x.openOr(false)
}
- } else false
+ } else false) && currentValue.isDefined
+ // the loc only matches if we've got a current value
}
def breadCrumbs: List[Loc[_]] = _menu.breadCrumbs ::: List(this)
@@ -406,13 +413,13 @@ object Loc {
def apply(name: String, link: Link[Unit], text: LinkText[Unit], params: LocParam[Unit]*): Loc[Unit] = UnitLoc(name, link, text, params.toList)
def apply(name: String, link: Link[Unit], text: LinkText[Unit], params: List[LocParam[Unit]]): Loc[Unit] = UnitLoc(name, link, text, params)
- private case class UnitLoc(
+ private final case class UnitLoc(
override val name: String,
override val link: Link[Unit],
override val text: LinkText[Unit],
override val params: List[LocParam[Unit]]
) extends Loc[Unit] {
- override val defaultValue: Box[Unit] = Full(())
+ override def defaultValue: Box[Unit] = Full(())
init()
}
@@ -712,8 +719,8 @@ object Loc {
}
}
- @deprecated def alwaysTrue(a: Req) = true
- @deprecated def retString(toRet: String)(other: Seq[(String, String)]) = Full(toRet)
+ // @deprecated def alwaysTrue(a: Req) = true
+ // @deprecated def retString(toRet: String)(other: Seq[(String, String)]) = Full(toRet)
implicit def strToFailMsg(in: => String): FailMsg = () => {
RedirectWithState(
@@ -68,9 +68,10 @@ object LocPath {
new NormalLocPath(in)
}
-object * extends LocPath {
+case object * extends LocPath {
def pathItem = "star"
def wildcard_? = true
+ override def toString() = "WildcardLocPath()"
}
final case class NormalLocPath(pathItem: String) extends LocPath {
@@ -168,6 +169,8 @@ object Menu extends MenuSingleton {
*/
lazy val toLoc: Loc[T] = new Loc[T] with ParamExtractor[String, T] {
import scala.xml._
+
+ def headMatch: Boolean = ParamMenuable.this.headMatch
// the name of the page
def name = ParamMenuable.this.name
@@ -283,7 +286,10 @@ object Menu extends MenuSingleton {
lazy val toLoc: Loc[T] = new Loc[T] with ParamExtractor[List[String], T] {
// the name of the page
def name = ParamsMenuable.this.name
-
+
+ def headMatch: Boolean = ParamsMenuable.this.headMatch
+
+
// the default parameters (used for generating the menu listing)
def defaultValue = Empty
@@ -374,13 +380,14 @@ object Menu extends MenuSingleton {
/**
* Rewrite the request and emit the type-safe parameter
*/
- override val rewrite: LocRewrite =
- Full(NamedPF("Param Rewrite") {
+ override lazy val rewrite: LocRewrite =
+ Full(NamedPF(locPath.toString) {
case RewriteRequest(ParsePath(ExtractSan(path, param),
_, _,_), _, _) => {
- RewriteResponse(path) -> param
+ RewriteResponse(path, true) -> param
}})
+ def headMatch: Boolean
/**
* Given an incoming request path, match the path and
@@ -393,14 +400,22 @@ object Menu extends MenuSingleton {
import scala.collection.mutable._
val retPath = new ListBuffer[String]()
val retParams = new ListBuffer[String]()
+ var gotStar = false
@tailrec
def doExtract(op: List[String], mp: List[LocPath]): Boolean =
(op, mp) match {
- case (op, Nil) => retParams ++= op; true
+ case (Nil, Nil) => true
+ case (o :: Nil, Nil) => {
+ retParams += o
+ headMatch || !gotStar
+ }
+
+ case (op, Nil) => retParams ++= op; headMatch
case (Nil, _) => false
case (o :: _, NormalLocPath(str) :: _) if o != str => false
case (o :: os, * :: ms) => {
+ gotStar = true
retParams += o
retPath += *.pathItem
doExtract(os, ms)
@@ -411,10 +426,11 @@ object Menu extends MenuSingleton {
}
}
- if (doExtract(org, locPath))
- Full(retPath.toList -> retParams.toList)
- else
+ if (doExtract(org, locPath)) {
+ Full((retPath.toList, retParams.toList))
+ } else {
Empty
+ }
}
}

0 comments on commit 58ee9a0

Please sign in to comment.