Giter Site home page Giter Site logo

mjfryc / mjaron-jregistry Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 509 KB

[Draft] Key-value settings for java applications. Thread-safe, with plans to edit it via web browser.

License: MIT License

Java 89.10% HTML 10.90%
settings properties-api java options

mjaron-jregistry's Introduction

This is draft only!

mjaron-jregistry

Key-value settings for java (and Android) applications.

The idea is to preview and sometimes modify variables in Java application via web browser. In future there will be posibility to decide which variable should be persistent and which runtime only.

mjaron-jregistry-screen-0

Tasks

  • Property types:
    • Nodes
    • Strings
    • Integers
    • Booleans
  • Possibility to define default values if properties are not set in storage
  • Create type value restrictions (enumerations)
  • Make it thread-safe
  • Create transactions with critical section.
  • Create persistent storage root
  • Create possibility to edit properties via web browser
    • options tree view
    • Create actions which may be triggered with html button
    • Create some options visualizers
    • Add file management

Demo code

package pl.mjaron.jregistry;

import pl.mjaron.jregistry.core.IPropertyVisitor;
import pl.mjaron.jregistry.core.MemoryStorage;
import pl.mjaron.jregistry.core.ReentrantSection;

import java.io.PrintStream;

/**
 * This is sample registry implementation.
 */
class Registry {
    Node root = new Node(new MemoryStorage(), new ReentrantSection());
    public Node fish = new Node(root, "fish");
    public IntProperty FISH_AGE = new IntProperty(fish, "age").setValue(28);
    public StrProperty name = new StrProperty(fish, "what").setDefault("Fish");
    public StrProperty surname = new StrProperty(fish, "name").setValue("Jessica");
    public StrProperty myEnum = new StrProperty(fish, "enum")
            .addEnum("a")
            .addEnum("b")
            .addEnum("c")
            .setEnumOnly(true) // If setting value other than added enum - a RuntimeException will be thrown.
            .setValue("b");
    public IntProperty myDigitEnum = new IntProperty(fish, "enum-d").setEnumOnly(true).addEnum(4).addEnum(6).addEnum(8);
}

public class Sample {

    static Registry R = new Registry();

    public static void main(String[] args) throws InterruptedException {
        PrintStream o = System.out;
        R.myDigitEnum.setValue(4);
        o.println("All properties:");
        R.root.accept(new IPropertyVisitor.PrintingVisitor());

        R.root.getCriticalSection().withLock(() -> {
            System.out.println("I am secure here!");
            return null;
        });

        Thread thr = new Thread(() -> {
            String someOperationResult = R.FISH_AGE.getCriticalSection().withLock(() -> {
                // All operations inside lock will be called atomically.
                Thread.sleep(10000);
                return R.FISH_AGE.getName();
            });
            System.out.println("someOperationResult: " + someOperationResult);
        });
        thr.start();;

        Thread.sleep(100);
        R.FISH_AGE.getValue();

        o.println();
        o.println("Fish age is: " + R.FISH_AGE.getValue());
    }

}

mjaron-jregistry's People

Contributors

mjfryc avatar

Stargazers

 avatar

Watchers

 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.