This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.Source | |
import java.io.FileWriter | |
object ManagedDemo extends App{ | |
import Managed._ | |
import Managed.{managed => ®} | |
for ( | |
fw <- ®(new FileWriter("target/test-out.txt")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.actor.{ ActorRef, Terminated, AllForOneStrategy, Actor, Props, ActorSystem } | |
import org.apache.camel.builder.RouteBuilder | |
import org.apache.camel.impl.DefaultMessage | |
import org.apache.camel.{ Exchange, Processor} | |
import org.apache.camel.spi.Synchronization | |
import akka.camel.{Message, Failure, CamelExtension} | |
import akka.dispatch.Await | |
object CamelRoutes extends App{ | |
val system = ActorSystem("Test") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private[camel] case class RegisterProducer(actorRef: ActorRef, endpointUri: String) | |
/** | |
* Watches the end of life of <code>Producer</code>s. | |
* Removes a <code>Producer</code> from the <code>ProducerRegistry</code> when it is <code>Terminated</code>, | |
* which in turn stops the <code>SendProcessor</code>. | |
*/ | |
private[camel] class CamelProducerIdempotentRegistry(camelContext: CamelContext) extends Actor { | |
private val camelObjects = new HashMap[ActorRef, (Endpoint,SendProcessor)]() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object ErrorUtils{ | |
/** | |
* Executes a block and returns the result wrapped by Right class, or exception wrapped by Left class. | |
*/ | |
def either[T](block:() => T) : Either[Throwable,T] = try {Right(block())} catch {case e => Left(e)} | |
/** | |
* Executes all blocks in order and collects exceptions. It guarantees to execute all blocks, even if some of them fail. | |
* It throws a BlockException, if any number of blocks fail. BlockException contains a list of thrown exceptions. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.mockito.Mockito._ | |
import org.scalatest.mock.MockitoSugar | |
import org.mockito.Matchers | |
object MockitoFun1 extends App with MockitoSugar{ | |
trait X{ | |
def x | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package akka.camel | |
import akka.actor._ | |
import org.scalatest.FlatSpec | |
import org.scalatest.matchers.ShouldMatchers | |
import org.scalatest.mock.MockitoSugar | |
import org.mockito.Mockito._ | |
import org.mockito.Matchers.{eq => the, any} | |
class ConsumerScalaTest extends FlatSpec with ShouldMatchers with MockitoSugar{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val f = new FileWriter("some/file/name.txt") | |
f.write("My string I want to save") | |
f.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"My string I want to save".saveAs("some/file/name.txt") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit def toRichString(s:String) : RichString = new RichString(s) | |
class RichString(s: String){ | |
def saveAs(fileName: String) = write(fileName, s) | |
private[this] def write(fileName: String, content: String) { | |
val f = new FileWriter(fileName) | |
f.write(content) | |
f.close() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Camel{ | |
lazy val context = new DefaultCamelContext | |
def addRoute(routeBuilder: RouteBuilder) {context addRoutes routeBuilder} | |
def start { context start } | |
} | |
trait Consum{ self: Actor => | |
val camel = Camel | |
val consumer = self | |
def from(route:String) = camel.addRoute(new RouteBuilder(){ |