Giter Club home page Giter Club logo

singleton-configuration-manager-example's Introduction

Singleton Configuration Manager Example

This is the Configuration Manager class I've written a long time ago to use as a general config manager in my projects. It is a simple Gang-Of-Four Singleton design pattern. With this simple class, you can use the properties file and access it with this single singleton configuration manager.

TOC

1- Properties File
2- Setting Up The Environmental Variable
3- States Of The ConfigManager

Properties File

There are two locations that properties file can be located;

1- Properties file can be either on the base dir, or if you are using a build tool like maven, it can be in the resource directory (which is: src/main/resources).

2- If an environmental variable is defined, then the value of the env-variable will be the location of the properties file.

The logic is simple, the program first checks whether an environmental variable is defined. If so, it will check if there is a file on the value of the environmental variable which is actually the location of the directory. If there is the file, then config-manager is going to use it, if not, it will System.exit(1).

If the environmental variable is not set, the config-manager will check the base dir, or the base resource directory to check whether if there is a properties file. If it is in there, it will use it, if not, again, it will System.exit(1).

The name of the properties file is hardcoded inside the ConfigManager class.

Go back to TOC

Setting Up The Environmental Variable

You can set up the environmental variable in windows as below;

Setting-Up-Environmental-Variable

If the env-variable is set, then inside the Config static class which is inside the ConfigManager, you can hardcode the name of the environmental variable.

Go back to TOC

States Of The ConfigManager

1- Environmental Variable Set But There Is No Properties File In The Target Directory

Env-Is-Set-But-No-Props-File-In-Target-Dir

2- Environmental Variable Set And There Is Properties File In The Target Directory

Env-Is-Set-But-Props-File-In-Target-Dir

3- Environmental Variable Is Not Set And There Is Properties File In The Base Dir

Env-Is-Not-Set-But-Props-File-In-Base-Dir

4- Environmental Variable Is Not Set And No Properties File In The Base Dir

Env-Is-Not-Set-And-No-Props-File-In-Base-Dir

Go back to TOC

singleton-configuration-manager-example's People

Contributors

bzdgn avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

kprabhatgit

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.