Skip to content

Commit

Permalink
test net code release
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanYip committed Jul 4, 2018
1 parent 7583230 commit caac285
Show file tree
Hide file tree
Showing 521 changed files with 44,973 additions and 15,267 deletions.
518 changes: 302 additions & 216 deletions build.gradle

Large diffs are not rendered by default.

File renamed without changes.
5 changes: 0 additions & 5 deletions src/main/java/org/gsc/common/app/ApplicationFactory.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
/*
* gsc-core is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gsc-core is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.gsc.common.app;

import org.gsc.config.Args;
import org.gsc.db.Manager;
import org.gsc.service.Service;
import org.springframework.context.ApplicationContext;

public interface Application {

void setOptions(Args args);

void init(Args args, ApplicationContext ctx);

void initServices(Args args);

void startup();

void shutdown();

void startServices();

void shutdownServices();

void addService(Service service);

Manager getDbManager();
}
/*
* java-gsc is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* java-gsc is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.gsc.common.application;

import org.gsc.core.config.args.Args;
import org.gsc.core.db.BlockStore;
import org.gsc.core.db.Manager;
import org.gsc.core.net.node.Node;

public interface Application {

void setOptions(Args args);

void init(Args args);

void initServices(Args args);

void startup();

void shutdown();

void startServices();

void shutdownServices();

Node getP2pNode();

BlockStore getBlockStoreS();

void addService(Service service);

Manager getDbManager();
}
50 changes: 50 additions & 0 deletions src/main/java/org/gsc/common/application/ApplicationFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* java-gsc is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* java-gsc is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.gsc.common.application;

import com.google.inject.Guice;
import com.google.inject.Injector;
import org.springframework.context.ApplicationContext;

public class ApplicationFactory {

/**
* Build a Guice instance.
*
* @return Guice
*/
public Injector buildGuice() {
return Guice.createInjector(
new Module());
}

/**
* Build a new application.
*/
public Application build() {
return new ApplicationImpl();
}

/**
* Build a new cli application.
*/
//public CliApplication buildCli() {
// return new CliApplication(buildGuice());
public static Application create(ApplicationContext ctx) {
return ctx.getBean(ApplicationImpl.class);
//return new ApplicationImpl();
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
package org.gsc.common.app;
package org.gsc.common.application;

import lombok.extern.slf4j.Slf4j;
import org.gsc.config.Args;
import org.gsc.core.sync.ChainController;
import org.gsc.core.sync.ChainControllerImpl;
import org.gsc.db.BlockStore;
import org.gsc.db.Manager;
import org.gsc.db.UndoStore;
import org.gsc.service.NetService;
import org.gsc.service.Service;
import org.gsc.service.ServiceContainer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.gsc.core.config.args.Args;
import org.gsc.core.db.BlockStore;
import org.gsc.core.db.Manager;
import org.gsc.core.db.RevokingStore;
import org.gsc.core.net.node.Node;
import org.gsc.core.net.node.NodeDelegate;
import org.gsc.core.net.node.NodeDelegateImpl;
import org.gsc.core.net.node.NodeImpl;

@Slf4j
@Component
public class ApplicationImpl implements Application {

@Autowired
private NetService p2pNode;
private NodeImpl p2pNode;

private BlockStore blockStoreDb;
private ServiceContainer services;
private ChainController controller;
private NodeDelegate nodeDelegate;

@Autowired
private Manager dbManager;
Expand All @@ -43,13 +41,13 @@ public void setOptions(Args args) {

@Override
@Autowired
public void init(Args args, ApplicationContext ctx) {
public void init(Args args) {
//p2pNode = new NodeImpl();
//p2pNode = ctx.getBean(NodeImpl.class);
// dbManager.init();
blockStoreDb = dbManager.getBlockStore();
services = new ServiceContainer();
controller = ctx.getBean(ChainControllerImpl.class);
nodeDelegate = new NodeDelegateImpl(dbManager);
}

@Override
Expand All @@ -66,15 +64,15 @@ public void initServices(Args args) {
* start up the app.
*/
public void startup() {
p2pNode.setChainController(controller);
p2pNode.setNodeDelegate(nodeDelegate);
resetP2PNode();
}

@Override
public void shutdown() {
System.err.println("******** begin to shutdown ********");
synchronized (UndoStore.getInstance()) {
closeUndoStore();
synchronized (RevokingStore.getInstance()) {
closeRevokingStore();
closeAllStore();
}
closeConnection();
Expand All @@ -91,10 +89,12 @@ public void shutdownServices() {
services.stop();
}

public NetService getP2pNode() {
@Override
public Node getP2pNode() {
return p2pNode;
}

@Override
public BlockStore getBlockStoreS() {
return blockStoreDb;
}
Expand Down Expand Up @@ -123,7 +123,8 @@ private void closeConnection() {
}
}

private void closeUndoStore() { UndoStore.getInstance().shutdown();
private void closeRevokingStore() {
RevokingStore.getInstance().shutdown();
}

private void closeAllStore() {
Expand Down
78 changes: 78 additions & 0 deletions src/main/java/org/gsc/common/application/CliApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* java-gsc is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* java-gsc is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.gsc.common.application;

import org.gsc.core.config.args.Args;
import org.gsc.core.db.BlockStore;
import org.gsc.core.db.Manager;
import org.gsc.core.net.node.Node;

public class CliApplication implements Application {

@Override
public void setOptions(Args args) {

}

@Override
public void init( Args args) {

}

@Override
public void initServices(Args args) {

}

@Override
public void startup() {

}

@Override
public void shutdown() {

}

@Override
public void startServices() {

}

@Override
public void shutdownServices() {

}

@Override
public Node getP2pNode() {
return null;
}

@Override
public BlockStore getBlockStoreS() {
return null;
}

@Override
public void addService(Service service) {

}

@Override
public Manager getDbManager() {
return null;
}
}
61 changes: 61 additions & 0 deletions src/main/java/org/gsc/common/application/Module.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* java-gsc is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* java-gsc is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.gsc.common.application;

import static org.gsc.core.Constant.BLOCK_DB_NAME;
import static org.gsc.core.Constant.TRANSACTION_DB_NAME;

import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import javax.inject.Named;
import org.gsc.core.Constant;
import org.gsc.common.storage.leveldb.LevelDbDataSourceImpl;
import org.gsc.core.config.args.Args;

public class Module extends AbstractModule {

@Override
protected void configure() {

}

/**
* build transaction database.
*/
@Provides
@Singleton
@Named("transaction")
public LevelDbDataSourceImpl buildTransactionDb() {
LevelDbDataSourceImpl db = new LevelDbDataSourceImpl(Args.getInstance().getOutputDirectory(),
Constant.TRANSACTION_DB_NAME);
db.initDB();
return db;
}

/**
* build block database.
*/
@Provides
@Singleton
@Named("block")
public LevelDbDataSourceImpl buildBlockDb() {
LevelDbDataSourceImpl db = new LevelDbDataSourceImpl(Args.getInstance().getOutputDirectory(),
Constant.BLOCK_DB_NAME);
db.initDB();
return db;
}
}
Loading

0 comments on commit caac285

Please sign in to comment.