-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add dependency injection, refactor static classes #45
Conversation
added dependency injection using Guice changed dependency off commands from peer to application made Client non-static made Server non-static changed some classes to accept dependencies through constructor
|
||
@Override | ||
public void stop() { | ||
server.leave(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure if this is the right way to dispose the server
|
||
public PeerBuilder() { | ||
Server.serverRun(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this because starting a server should not be done within a factory class. Starting the server is now being done in org.tron.example.Tron.run()
@@ -57,6 +59,8 @@ | |||
private byte[] lastHash; | |||
private byte[] currentHash; | |||
|
|||
private Client client; | |||
|
|||
/** | |||
* create new blockchain | |||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if it is possible to inject the database when initializing the Blockchain for the first time from this constructor:
public Blockchain(String address, String type) {
Doing so would avoid making the Blockchain responsible for setting the database connection, which to me isn't an intuitive responsibility of this class.
Doing so would mean the logic for deciding whether to load an existing or create a new blockchain would have to change to some other way.
I wonder if if(blockDB.getData(LAST_HASH) != null) { ... }
is sufficient for this purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialize the database when the program starts.
Solution A:
// Initialize on the outside
DB blockDB = new DB();
// Incoming through formal parameters
Blockchain blockchain = new Blockchain(blockDB);
XmThLtmnNLD/Insalk6y8GlKPwfVllFPqFPLUNgwkuQgBPZ2/dm975bMPJVVNSxK VIECNCdVCDTtalpHu/ieMM/a9d1bvhZIao4JwGnrGHcEkVli5l8OsIzkz61fgy7G jZRmEq8HZuscQritqUsvxSju6tYKSVjzCsGUyD/9T6tC2GrFxdrC/Iw+5jzd+JEa keG1pyXQLNVMqj1lhsF09m/M3G6540/uZLCBYLERleZScrMoyJT9WqNd86oRvvav eveTMObaQkCUNG+SCdQ7bnWT73v34JGxzdr2fMEfnAkP9PBHDD+cZEjxg0iVLpc= =5qRR -----END PGP SIGNATURE----- Merge pull request #45 from Rovak/app-di Add dependency injection, refactor static classes
What does this PR do?
Why are these changes required?
This PR has been tested by: