GithubHelp home page GithubHelp logo

sahataba / swatch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from parsleysoftware/swatch

0.0 0.0 0.0 22 KB

A Scala wrapper around the Java 7 WatchService

License: Apache License 2.0

Scala 100.00%

swatch's Introduction

Swatch is an (hopefully) very simple wrapper around the Java 7 WatchService API.

Binaries are available on Bintray.

Usage is pretty straightforward:

import com.mirkocaserta.swatch.Swatch._

watch("plugins", Seq(Create, Modify, Delete), println, true)

This registers a WatchService on the plugins directory and its subdirectories (because of the true value being passed to the recursive argument). The WatchService will then watch for creation, modification and deletion of files. Notifications will get sent to the println function.

If you want to (and you sure will) customize your notifications listener, it's as easy as defining a function such as:

import com.mirkocaserta.swatch.Swatch._

val listener = (event: SwatchEvent)  {
  println(s"got an event: $event")

  event match {
    case Create(path)  println(s"a file was created with path '$path'")
    case Modify(path)  println(s"a file was modified with path '$path'")
    case Delete(path)  println(s"a file was deleted with path '$path'")
  }
}

watch("plugins", Seq(Create, Modify, Delete), listener, true)

An actor wrapper is also provided. Usage looks like this:

import akka.actor.{Props, ActorSystem}
import com.mirkocaserta.swatch.Swatch._
import com.mirkocaserta.swatch.SwatchActor

val swatch = system.actorOf(Props[SwatchActor])
swatch ! Watch("plugins", Seq(Create, Modify, Delete), true)

Your sending actor will then start receiving SwatchEvent messages. You can optionally specify a different actor to be notified of SwatchEvents, via the optional listener parameter.

If you need further info, take a look at the scaladocs in the source code. I've tried to make it as estensive as possible.

swatch's People

Contributors

asazernik avatar mcaserta avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.