|
| 1 | +# Realtime Mysql Framework |
| 2 | +This is a java framework which provides you to handle the changes in your database at realtime. |
| 3 | + |
| 4 | +## How it works |
| 5 | +The framework has a server that listens to the changes in the general log file of the mysql and fires the listener associated with the updated. |
| 6 | + |
| 7 | +The framework provides an interface with functions such as onUpdate, onSelect etc... You can override these functions to handle the changes and register the implemented interface with the framework. The framework will automatically call the function associated with the update. |
| 8 | + |
| 9 | +## Usage |
| 10 | +- Initialize the Mysql data directory |
| 11 | + ```console |
| 12 | + foo@bar:~$ mysqld --initialize --data-dir="datadirectory" |
| 13 | + ``` |
| 14 | +- Start the mysql daemon(mysql server) |
| 15 | + ```console |
| 16 | + foo@bar:~$ filename="your log file name for mysql" |
| 17 | + foo@bar:~$ datadir="your mysql data directory" |
| 18 | + foo@bar:~$ mysqld --datadir="$datadir" --general-log --general-log-file="$filename" |
| 19 | + ``` |
| 20 | +- Start the Realtime Server provided and pass the general log file location as the parameter. Example: `java Server general_log_file_name` |
| 21 | + ```console |
| 22 | + foo@bar:~$ cd ./generated |
| 23 | + foo@bar:~$ file="$datadir/$filename" |
| 24 | + foo@bar:~$ java Server "$file" || kill -term `pidof mysqld` |
| 25 | + ``` |
| 26 | +- Import the ServerConnect java file in your program and implement the interface DatabaseEventListener. `See Demo.java` |
| 27 | + ```java |
| 28 | + import com.pranay.realtimedatabase.DatabaseEventListener; |
| 29 | + import com.pranay.realtimedatabase.ServerConnect; |
| 30 | + . |
| 31 | + . |
| 32 | + . |
| 33 | + ServerConnect conn = new ServerConnect(); |
| 34 | + conn.setDatabaseChangeEventListener(new DatabaseEventListener() {...} ); |
| 35 | + conn.startDatabaseChangeListenerService(); |
| 36 | + ``` |
| 37 | +## QuickStart |
| 38 | +I have provided some quickstart bash scripts to start the realtime server as well as mysql server with general logging enabled. |
| 39 | +- Launch the `quickstart.sh` and follow the steps |
| 40 | + |
| 41 | +### Other Scripts |
| 42 | +- *compile.sh* Compile all the java files |
| 43 | +- *runserver.sh* Start the realtime server |
0 commit comments