Giter VIP home page Giter VIP logo

shoebox's Introduction

ShoeBox

ShoeBox is a Kotlin library for object persistence that supports the observer pattern so your code can be notified immediately when stored data is changed.

Motivation

While it is a standalone library, ShoeBox was created as a persistence layer for Kweb applications, motivated by the lack of a simple persistence mechanism that supports the observer pattern. The idea is to create a "bridge" library between Shoebox and Kweb that will allow "binding" of UI components to persistent state, also known as the data mapper pattern. Here is a video illustrating this idea for TornadoFX on Android.

To emphasize, however, Shoebox doesn't depend on Kweb and should be useful for many other things.

Features

  • Functionality similar to MutableMap
  • Add listeners for object addition, deletion, and modification
  • Fairly comprehensive unit tests
  • Lightweight, pulls in very few dependencies
  • Materialized views
    • Efficiently retrieve objects by any specified key derived from the object
    • Similar to database indexes, but also supporting the observer pattern
  • Currently data is stored as uncompressed files, serialized to JSON

Limitations

  • Not very space efficient for small objects as files take up at least 4K on many filesystems
  • Data isn't currently compressed
  • Directories can't be shared between different Shoebox instances, although this is planned
    • Once this is supported we can use shared filesystems to scale horizontally, limited only by the filesystem
  • Doesn't implement the MutableMap interface
    • Even though the semantics are very similar to MutableMap, it isn't currently implemented because we wanted to avoid loading all data into memory.
    • This is probably solvable through custom implementations of MutableSet, MutableEntry and other interfaces, and will probably be done before 1.0 is released.

Adding to your project

Shoebox can be added easily to your Maven or Gradle project through Jitpack:

Release

As of release 0.4.0 Shoebox uses Kotlin Serialization, so you will also need to add the serialization plugin to your project.

Simple Usage Example

fun main() {
    val dir = Files.createTempDirectory("sb-")
    val userStore = shoebox(dir.resolve("users"), User.serializer())
    val usersByEmail = userStore.view("usersByEmail", User::email)
    val usersByGender = userStore.view("usersByGender", User::gender)

    userStore["ian"] = User("Ian Clarke", "male", "[email protected]")
    userStore["fred"] = User("Fred Smith", "male", "[email protected]")
    userStore["sue"] = User("Sue Smith", "female", "[email protected]")

    println(usersByEmail["[email protected]"])   // [User(name=Ian Clarke, gender=male, [email protected])]
    println(usersByGender["male"])          // [User(name=Ian Clarke, gender=male, [email protected]),
                                            // User(name=Fred Smith, gender=male, [email protected])]
    // note: view["xx]" returns a set of values
    usersByGender.onAdd("male") { kv ->
        println("${kv.key} became male")
    }
    usersByGender.onRemove("male") { kv ->
        println("${kv.key} ceased to be male")
    }

    userStore["fred"] = userStore["fred"]!!.copy(gender = "female") // Prints "fred ceased to be male"
}

@Serializable data class User(val name : String, val gender : String, val email : String)

Documentation

shoebox's People

Contributors

sanity avatar spaceopen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

shoebox's Issues

Listen to filesystem events to support multiple Stores for a shared directory

Currently only one Store instance can listen to a given directory at a time (although it isn't currently enforced through locking, although it should be).

However, through the Java WatchService it should be able to listen for file modifications caused by other Store instances, possibly running in a different JVM or even on a different server (using a shared filesystem like Amazon's EFS).

Unfortunately this is complicated by the fact that WatchService doesn't work reliably across platforms. There are workarounds like this Mac specific library, so they will need to be used on platforms where WatchService isn't reliable.

Note: Should verify that Amazon's EFS supports realtime file modification notification before we recommend this use-case.

Create Shoebox backend using scalable AWS services

Currently, with just filesystem and memory back-ends, Shoebox cannot scale beyond a single server.

This limitation could be removed through integration with scalable AWS backend services, for example, SimpleDB could be used as a key-value store, and pub/sub messaging to handle realtime modification events.

This should allow Shoebox to scale almost indefinitely.

Licensing?

Just noticed that there is no license in this repo. Should it be under the LGPL v3 like kweb-core, or did you have different plans for it?

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.